Skip to content
Permalink
Browse files

[FIXED JENKINS-11571] Don't scan module folders of a maven project.

  • Loading branch information...
uhafner committed Nov 14, 2011
1 parent 7e67de5 commit ccc87206205bbe9998214de4e59a4f08d634fa01
@@ -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;

@@ -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);
@@ -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;
@@ -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;
@@ -29,7 +31,7 @@
/** 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. */
@@ -47,6 +49,8 @@
/** 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>.
*
@@ -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>.
*
@@ -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.
*
@@ -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);
@@ -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;
}

@@ -203,6 +263,9 @@ private ModuleDetector createModuleDetector(final File workspace) {
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.
You can’t perform that action at this time.