Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[JENKINS-9090] Added project configuration option to activate
scanning of workspace for build.xml and pom.xml files to detect
the module names of warnings.
  • Loading branch information
uhafner committed Apr 7, 2011
1 parent 7b17d83 commit ebfde8b48b4fb9e1dd550217350df7f522553b29
Showing with 29 additions and 9 deletions.
  1. +9 −6 src/main/java/hudson/plugins/tasks/TasksPublisher.java
  2. +20 −3 src/main/java/hudson/plugins/tasks/parser/WorkspaceScanner.java
@@ -94,6 +94,10 @@ public class TasksPublisher extends HealthAwarePublisher {
* annotation threshold
* @param failedNewLow
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param shouldDetectModules
* determines whether module names should be derived from Maven POM or Ant build files
* @param high
* tag identifiers indicating high priority
* @param normal
@@ -104,8 +108,6 @@ public class TasksPublisher extends HealthAwarePublisher {
* if case should be ignored during matching
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
*/
// CHECKSTYLE:OFF
@SuppressWarnings("PMD.ExcessiveParameterList")
@@ -116,15 +118,15 @@ public TasksPublisher(final String healthy, final String unHealthy, final String
final String unstableNewAll, final String unstableNewHigh, final String unstableNewNormal, final String unstableNewLow,
final String failedTotalAll, final String failedTotalHigh, final String failedTotalNormal, final String failedTotalLow,
final String failedNewAll, final String failedNewHigh, final String failedNewNormal, final String failedNewLow,
final boolean canRunOnFailed,
final boolean canRunOnFailed, final boolean shouldDetectModules,
final String high, final String normal, final String low, final boolean ignoreCase,
final String pattern, final String excludePattern) {
super(healthy, unHealthy, thresholdLimit, defaultEncoding, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, "TASKS");
canRunOnFailed, shouldDetectModules, "TASKS");
this.pattern = pattern;
this.excludePattern = excludePattern;
this.high = high;
@@ -199,8 +201,9 @@ 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...");
project = build.getWorkspace().act(
new WorkspaceScanner(StringUtils.defaultIfEmpty(getPattern(), DEFAULT_PATTERN), getExcludePattern(), getDefaultEncoding(), high, normal, low, ignoreCase));
WorkspaceScanner scanner = new WorkspaceScanner(StringUtils.defaultIfEmpty(getPattern(),
DEFAULT_PATTERN), getExcludePattern(), getDefaultEncoding(), high, normal, low, ignoreCase, shouldDetectModules());
project = build.getWorkspace().act(scanner);

TasksResult result = new TasksResult(build, getDefaultEncoding(), project, high, normal, low);
build.getActions().add(new TasksResultAction(build, this, result));
@@ -5,6 +5,7 @@
import hudson.plugins.analysis.util.ContextHashCode;
import hudson.plugins.analysis.util.EncodingValidator;
import hudson.plugins.analysis.util.ModuleDetector;
import hudson.plugins.analysis.util.NullModuleDetector;
import hudson.plugins.analysis.util.PackageDetectors;
import hudson.remoting.VirtualChannel;

@@ -43,6 +44,8 @@ public class WorkspaceScanner implements FileCallable<TasksParserResult> {
private String prefix;
/** The default encoding to be used when reading and parsing files. */
private final String defaultEncoding;
/** Determines whether module names should be derived from Maven or Ant. */
private final boolean shouldDetectModules;

/**
* Creates a new instance of <code>WorkspaceScanner</code>.
@@ -61,17 +64,22 @@ public class WorkspaceScanner implements FileCallable<TasksParserResult> {
* tag identifiers indicating low priority
* @param ignoreCase
* if case should be ignored during matching
* @param shouldDetectModules
* determines whether module names should be derived from Maven POM or Ant build files
*/
// CHECKSTYLE:OFF
public WorkspaceScanner(final String filePattern, final String excludeFilePattern, final String defaultEncoding,
final String high, final String normal, final String low, final boolean ignoreCase) {
final String high, final String normal, final String low, final boolean ignoreCase, final boolean shouldDetectModules) {
this.filePattern = filePattern;
this.excludeFilePattern = excludeFilePattern;
this.defaultEncoding = defaultEncoding;
this.high = high;
this.normal = normal;
this.low = low;
this.ignoreCase = ignoreCase;
this.shouldDetectModules = shouldDetectModules;
}
// CHECKSTYLE:ON

/**
* Creates a new instance of <code>WorkspaceScanner</code>.
@@ -97,7 +105,7 @@ public WorkspaceScanner(final String filePattern, final String excludeFilePatter
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) {
this(filePattern, excludeFilePattern, defaultEncoding, high, normal, low, caseSensitive);
this(filePattern, excludeFilePattern, defaultEncoding, high, normal, low, caseSensitive, false);
this.moduleName = moduleName;
}
// CHECKSTYLE:ON
@@ -126,7 +134,7 @@ public TasksParserResult invoke(final File workspace, final VirtualChannel chann

TaskScanner taskScanner = new TaskScanner(high, normal, low, ignoreCase);
TasksParserResult javaProject = new TasksParserResult(files.length);
ModuleDetector moduleDetector = new ModuleDetector(workspace);
ModuleDetector moduleDetector = createModuleDetector(workspace);
for (String fileName : files) {
File originalFile = new File(workspace, fileName);
Collection<Task> tasks = taskScanner.scan(new InputStreamReader(new FilePath(originalFile).read(),
@@ -154,6 +162,15 @@ public TasksParserResult invoke(final File workspace, final VirtualChannel chann
return javaProject;
}

private ModuleDetector createModuleDetector(final File workspace) {
if (shouldDetectModules) {
return new ModuleDetector(workspace);
}
else {
return new NullModuleDetector();
}
}

/**
* Returns an array with the filenames of the files that have been found in
* the workspace.

0 comments on commit ebfde8b

Please sign in to comment.