Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-11571] Don't scan module folders of a maven project.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Nov 14, 2011
1 parent 7e67de5 commit ccc8720
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/hudson/plugins/tasks/TasksPublisher.java
Expand Up @@ -10,6 +10,7 @@
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.HealthAwarePublisher;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.analysis.util.StringPluginLogger;
import hudson.plugins.tasks.parser.TasksParserResult;
import hudson.plugins.tasks.parser.WorkspaceScanner;

Expand Down Expand Up @@ -201,9 +202,12 @@ public Action getProjectAction(final AbstractProject<?, ?> project) {
protected BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger logger) throws InterruptedException, IOException {
TasksParserResult project;
logger.log("Scanning workspace files for tasks...");
new StringPluginLogger("");
WorkspaceScanner scanner = new WorkspaceScanner(StringUtils.defaultIfEmpty(getPattern(), DEFAULT_PATTERN),
getExcludePattern(), getDefaultEncoding(), high, normal, low, ignoreCase, shouldDetectModules());
project = build.getWorkspace().act(scanner);

logger.logLines(project.getLogMessages());
logger.log(String.format("Found %d open tasks.", project.getNumberOfAnnotations()));

TasksResult result = new TasksResult(build, getDefaultEncoding(), project, high, normal, low);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/hudson/plugins/tasks/TasksReporter.java
Expand Up @@ -198,9 +198,13 @@ protected boolean acceptGoal(final String goal) {
public TasksParserResult perform(final MavenBuildProxy build, final MavenProject pom, final MojoInfo mojo, final PluginLogger logger) throws InterruptedException, IOException {
FilePath basedir = new FilePath(pom.getBasedir());
logger.log(String.format("Scanning folder '%s' for tasks ... ", basedir));
WorkspaceScanner workspaceScanner = new WorkspaceScanner(StringUtils.defaultIfEmpty(pattern, DEFAULT_PATTERN),
excludePattern, getDefaultEncoding(), high, normal, low, ignoreCase, pom.getName());

WorkspaceScanner workspaceScanner = new WorkspaceScanner(
StringUtils.defaultIfEmpty(pattern, DEFAULT_PATTERN),
excludePattern, getDefaultEncoding(), high, normal, low, ignoreCase, pom.getName(),
pom.getModules());
TasksParserResult project = basedir.act(workspaceScanner);
logger.logLines(project.getLogMessages());
logger.log(String.format("Found %d open tasks.", project.getNumberOfAnnotations()));

return project;
Expand Down
65 changes: 64 additions & 1 deletion src/main/java/hudson/plugins/tasks/parser/WorkspaceScanner.java
Expand Up @@ -7,12 +7,14 @@
import hudson.plugins.analysis.util.ModuleDetector;
import hudson.plugins.analysis.util.NullModuleDetector;
import hudson.plugins.analysis.util.PackageDetectors;
import hudson.plugins.analysis.util.StringPluginLogger;
import hudson.remoting.VirtualChannel;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.tools.ant.types.FileSet;
Expand All @@ -29,7 +31,7 @@ public class WorkspaceScanner implements FileCallable<TasksParserResult> {
/** Ant file-set pattern to define the files to scan. */
private final String filePattern;
/** Ant file-set pattern to define the files to exclude from scan. */
private final String excludeFilePattern;
private String excludeFilePattern;
/** The maven module. If <code>null</code>, then the scanner tries to guess it (freestyle project). */
private String moduleName;
/** Tag identifiers indicating high priority. */
Expand All @@ -47,6 +49,8 @@ public class WorkspaceScanner implements FileCallable<TasksParserResult> {
/** Determines whether module names should be derived from Maven or Ant. */
private final boolean shouldDetectModules;

private transient StringPluginLogger stringLogger;

/**
* Creates a new instance of <code>WorkspaceScanner</code>.
*
Expand Down Expand Up @@ -81,6 +85,19 @@ public WorkspaceScanner(final String filePattern, final String excludeFilePatter
}
// CHECKSTYLE:ON

/**
* Logs the specified message.
*
* @param message the message
*/
protected void log(final String message) {
if (stringLogger == null) {
stringLogger = new StringPluginLogger("TASKS");
}
stringLogger.log(message);
}


/**
* Creates a new instance of <code>WorkspaceScanner</code>.
*
Expand All @@ -106,10 +123,48 @@ public WorkspaceScanner(final String filePattern, final String excludeFilePatter
final String high, final String normal, final String low, final boolean caseSensitive,
final String moduleName) {
this(filePattern, excludeFilePattern, defaultEncoding, high, normal, low, caseSensitive, false);

this.moduleName = moduleName;
}
// CHECKSTYLE:ON

/**
* Creates a new instance of <code>WorkspaceScanner</code>.
* @param logger
*
* @param filePattern
* ant file-set pattern to scan for files
* @param excludeFilePattern
* ant file-set pattern to exclude from scan
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param high
* tag identifiers indicating high priority
* @param normal
* tag identifiers indicating normal priority
* @param low
* tag identifiers indicating low priority
* @param caseSensitive
* determines whether the scanner should work case sensitive
* @param moduleName
* the maven module name
*/
// CHECKSTYLE:OFF
public WorkspaceScanner(final String filePattern, final String excludeFilePattern, final String defaultEncoding,
final String high, final String normal, final String low, final boolean caseSensitive,
final String moduleName, final List<String> modules) {
this(filePattern, excludeFilePattern, defaultEncoding, high, normal, low, caseSensitive, moduleName);

StringBuilder excludes = new StringBuilder(excludeFilePattern);
for (String folder : modules) {
if (StringUtils.isNotBlank(excludes.toString())) {
excludes.append(", ");
}
excludes.append("**/" + folder);
}
this.excludeFilePattern = excludes.toString();
}

/**
* Sets the prefix to the specified value.
*
Expand All @@ -135,6 +190,7 @@ public TasksParserResult invoke(final File workspace, final VirtualChannel chann
TaskScanner taskScanner = new TaskScanner(high, normal, low, ignoreCase);
TasksParserResult result = new TasksParserResult(files.length);
ModuleDetector moduleDetector = createModuleDetector(workspace);
log("Found " + files.length + " files to scan for tasks");
for (String fileName : files) {
try {
File originalFile = new File(workspace, fileName);
Expand Down Expand Up @@ -167,6 +223,10 @@ public TasksParserResult invoke(final File workspace, final VirtualChannel chann
}
result.addModule(moduleName);

if (stringLogger != null) {
result.setLog(stringLogger.toString());
}

return result;
}

Expand Down Expand Up @@ -203,6 +263,9 @@ private String[] findFiles(final File workspaceRoot) {
fileSet.setExcludes(excludeFilePattern);
}

log("Scanning folder '" + workspaceRoot + "' for files matching the pattern '" + filePattern
+ "' - excludes: " + excludeFilePattern);

return fileSet.getDirectoryScanner(project).getIncludedFiles();
}
}

0 comments on commit ccc8720

Please sign in to comment.