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

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 ebfde8b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/main/java/hudson/plugins/tasks/TasksPublisher.java
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/hudson/plugins/tasks/parser/WorkspaceScanner.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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>.
Expand All @@ -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>.
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ebfde8b

Please sign in to comment.