diff --git a/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher.java b/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher.java index c0b715e70..cf849cb27 100644 --- a/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher.java +++ b/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher.java @@ -7,12 +7,14 @@ import hudson.model.StreamBuildListener; import hudson.model.TaskListener; import hudson.plugins.tasks.TasksPublisher; +import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.jenkinsci.plugins.pipeline.maven.MavenPublisher; import org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor; import org.jenkinsci.plugins.pipeline.maven.util.XmlUtils; import org.jenkinsci.plugins.workflow.steps.StepContext; import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; import org.w3c.dom.Element; import java.io.IOException; @@ -33,6 +35,38 @@ public class TasksScannerPublisher extends MavenPublisher { private static final long serialVersionUID = 1L; + /** + * Coma separated high priority task identifiers + * + * @see TasksPublisher#getHigh() + */ + private String highPriorityTaskIdentifiers = ""; + /** + * @see TasksPublisher#getNormal() + */ + private String normalPriorityTaskIdentifiers = ""; + /** + * @see TasksPublisher#getLow() + */ + private String lowPriorityTaskIdentifiers = ""; + /** + * @see TasksPublisher#getIgnoreCase() + */ + private boolean ignoreCase = false; + /** + * @see TasksPublisher#getPattern() + */ + private String pattern = ""; + /** + * @see TasksPublisher#getExcludePattern() + */ + private String excludePattern = ""; + + /** + * @see TasksPublisher#getAsRegexp() + */ + private boolean asRegexp = false; + @DataBoundConstructor public TasksScannerPublisher() { @@ -102,10 +136,15 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE } TasksPublisher tasksPublisher = new TasksPublisher(); - String pattern = XmlUtils.join(sourceDirectoriesPatterns, ","); + String pattern = StringUtils.isEmpty(this.pattern)? XmlUtils.join(sourceDirectoriesPatterns, ",") : this.pattern; tasksPublisher.setPattern(pattern); - tasksPublisher.setHigh("FIXME"); - tasksPublisher.setNormal("TODO"); + tasksPublisher.setExcludePattern(StringUtils.trimToNull(this.excludePattern)); + + tasksPublisher.setHigh(StringUtils.defaultIfEmpty(this.highPriorityTaskIdentifiers, "FIXME")); + tasksPublisher.setNormal(StringUtils.defaultIfEmpty(this.normalPriorityTaskIdentifiers, "TODO")); + tasksPublisher.setLow(StringUtils.trimToNull(this.lowPriorityTaskIdentifiers)); + tasksPublisher.setIgnoreCase(this.ignoreCase); + tasksPublisher.setAsRegexp(this.asRegexp); try { tasksPublisher.perform(run, workspace, launcher, listener); @@ -115,6 +154,69 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE } } + public String getHighPriorityTaskIdentifiers() { + return highPriorityTaskIdentifiers; + } + + @DataBoundSetter + public void setHighPriorityTaskIdentifiers(String highPriorityTaskIdentifiers) { + this.highPriorityTaskIdentifiers = highPriorityTaskIdentifiers; + } + + public String getNormalPriorityTaskIdentifiers() { + return normalPriorityTaskIdentifiers; + } + + @DataBoundSetter + public void setNormalPriorityTaskIdentifiers(String normalPriorityTaskIdentifiers) { + this.normalPriorityTaskIdentifiers = normalPriorityTaskIdentifiers; + } + + public String getLowPriorityTaskIdentifiers() { + return lowPriorityTaskIdentifiers; + } + + @DataBoundSetter + public void setLowPriorityTaskIdentifiers(String lowPriorityTaskIdentifiers) { + this.lowPriorityTaskIdentifiers = lowPriorityTaskIdentifiers; + } + + public boolean isIgnoreCase() { + return ignoreCase; + } + + @DataBoundSetter + public void setIgnoreCase(boolean ignoreCase) { + this.ignoreCase = ignoreCase; + } + + public String getPattern() { + return pattern; + } + + @DataBoundSetter + public void setPattern(String pattern) { + this.pattern = pattern; + } + + public String getExcludePattern() { + return excludePattern; + } + + @DataBoundSetter + public void setExcludePattern(String excludePattern) { + this.excludePattern = excludePattern; + } + + public boolean isAsRegexp() { + return asRegexp; + } + + @DataBoundSetter + public void setAsRegexp(boolean asRegexp) { + this.asRegexp = asRegexp; + } + @Symbol("openTasksPublisher") @Extension public static class DescriptorImpl extends MavenPublisher.DescriptorImpl { diff --git a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/config.jelly b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/config.jelly index 3ca3bd145..cfe480982 100644 --- a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/config.jelly +++ b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/config.jelly @@ -32,4 +32,38 @@ THE SOFTWARE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-asRegexp.html b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-asRegexp.html new file mode 100644 index 000000000..16f640995 --- /dev/null +++ b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-asRegexp.html @@ -0,0 +1,3 @@ +
+ Use task identifiers as regular expressions. +
\ No newline at end of file diff --git a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-disabled.html b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-disabled.html index 52b4a966e..e604b3f16 100644 --- a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-disabled.html +++ b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-disabled.html @@ -1,3 +1,3 @@
- Skip the publishing of Task Scanner reports.
+ Skip the publishing of Task Scanner reports.
\ No newline at end of file diff --git a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-excludePattern.html b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-excludePattern.html new file mode 100644 index 000000000..c06891b1f --- /dev/null +++ b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-excludePattern.html @@ -0,0 +1,3 @@ +
+ Ant style pattern of exclude source code. +
\ No newline at end of file diff --git a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-highPriorityTaskIdentifiers.html b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-highPriorityTaskIdentifiers.html new file mode 100644 index 000000000..cc45d550c --- /dev/null +++ b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-highPriorityTaskIdentifiers.html @@ -0,0 +1,3 @@ +
+ Coma separated list of high priority task identifiers. +
\ No newline at end of file diff --git a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-ignoreCase.html b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-ignoreCase.html new file mode 100644 index 000000000..0a2afe500 --- /dev/null +++ b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-ignoreCase.html @@ -0,0 +1,3 @@ +
+ Ignore case when scanning task identifiers. +
\ No newline at end of file diff --git a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-lowPriorityTaskIdentifiers.html b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-lowPriorityTaskIdentifiers.html new file mode 100644 index 000000000..5737e7f2f --- /dev/null +++ b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-lowPriorityTaskIdentifiers.html @@ -0,0 +1,3 @@ +
+ Coma separated list of low priority task identifiers. +
\ No newline at end of file diff --git a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-normalPriorityTaskIdentifiers.html b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-normalPriorityTaskIdentifiers.html new file mode 100644 index 000000000..e32f9032b --- /dev/null +++ b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-normalPriorityTaskIdentifiers.html @@ -0,0 +1,3 @@ +
+ Coma separated list of normal priority task identifiers. +
\ No newline at end of file diff --git a/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-pattern.html b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-pattern.html new file mode 100644 index 000000000..10550c897 --- /dev/null +++ b/jenkins-plugin/src/main/resources/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher/help-pattern.html @@ -0,0 +1,3 @@ +
+ Ant style pattern of the source code to scan for task identifiers. +
\ No newline at end of file diff --git a/jenkins-plugin/src/test/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepOnMasterTest.java b/jenkins-plugin/src/test/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepOnMasterTest.java index b5d425a1d..763d459a8 100644 --- a/jenkins-plugin/src/test/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepOnMasterTest.java +++ b/jenkins-plugin/src/test/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepOnMasterTest.java @@ -260,6 +260,37 @@ private void maven_build_jar_project_on_master_with_disabled_publisher_param_suc } } + @Test + public void maven_build_jar_project_on_master_with_open_task_scanner_config_succeeds() throws Exception { + + MavenPublisher.DescriptorImpl descriptor = new TasksScannerPublisher.DescriptorImpl(); + String displayName = descriptor.getDisplayName(); + + Symbol symbolAnnotation = descriptor.getClass().getAnnotation(Symbol.class); + String[] symbols = symbolAnnotation.value(); + assertThat(new String[]{"openTasksPublisher"}, is(symbols)); + + loadMavenJarProjectInGitRepo(this.gitRepoRule); + + String pipelineScript = "node('master') {\n" + + " git($/" + gitRepoRule.toString() + "/$)\n" + + " withMaven(options:[openTasksPublisher(" + + " disabled:false, " + + " pattern:'src/main/java', excludePattern:'a/path'," + + " ignoreCase:true, asRegexp:false, " + + " lowPriorityTaskIdentifiers:'minor', normalPriorityTaskIdentifiers:'todo', highPriorityTaskIdentifiers:'fixme')]) {\n" + + " sh 'mvn package verify'\n" + + " }\n" + + "}"; + + WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "build-on-master-openTasksPublisher-publisher-config"); + pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true)); + WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0)); + + String message = "[withMaven] Skip '" + displayName + "' disabled by configuration"; + jenkinsRule.assertLogNotContains(message, build); + } + @Test public void maven_build_maven_jar_with_flatten_pom_project_on_master_succeeds() throws Exception { loadMavenJarWithFlattenPomProjectInGitRepo(this.gitRepoRule);