Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-44386] Add configuration options to the OpenTasksPublisher
  • Loading branch information
Cyrille Le Clerc committed May 20, 2017
1 parent ab71092 commit dfec45a
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 4 deletions.
Expand Up @@ -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;
Expand All @@ -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() {

Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
Expand Up @@ -32,4 +32,38 @@ THE SOFTWARE.
<option value="true">True</option>
</select>
</f:entry>

<f:section title="${%Source Code}">
<f:entry title="Pattern" field="pattern">
<f:textbox/>
</f:entry>
<f:entry title="Exclude Pattern" field="excludePattern">
<f:textbox/>
</f:entry>
</f:section>

<f:section title="${%Task Identifiers}">
<f:entry title="High Priority Tasks" field="highPriorityTaskIdentifiers">
<f:textbox/>
</f:entry>
<f:entry title="Normal Priority Tasks" field="normalPriorityTaskIdentifiers">
<f:textbox/>
</f:entry>
<f:entry title="Low Priority Tasks" field="lowPriorityTaskIdentifiers">
<f:textbox/>
</f:entry>
<f:entry title="${%Ignore Case}" field="ignoreCase">
<select name="ignoreCase">
<option value="false">False</option>
<option value="true">True</option>
</select>
</f:entry>
<f:entry title="${%As Regexp}" field="asRegexp">
<select name="asRegexp">
<option value="false">False</option>
<option value="true">True</option>
</select>
</f:entry>
</f:section>

</j:jelly>
@@ -0,0 +1,3 @@
<div>
Use task identifiers as regular expressions.
</div>
@@ -1,3 +1,3 @@
<div>
Skip the publishing of Task Scanner reports.<br/>
Skip the publishing of Task Scanner reports.
</div>
@@ -0,0 +1,3 @@
<div>
Ant style pattern of exclude source code.
</div>
@@ -0,0 +1,3 @@
<div>
Coma separated list of high priority task identifiers.
</div>
@@ -0,0 +1,3 @@
<div>
Ignore case when scanning task identifiers.
</div>
@@ -0,0 +1,3 @@
<div>
Coma separated list of low priority task identifiers.
</div>
@@ -0,0 +1,3 @@
<div>
Coma separated list of normal priority task identifiers.
</div>
@@ -0,0 +1,3 @@
<div>
Ant style pattern of the source code to scan for task identifiers.
</div>
Expand Up @@ -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);
Expand Down

0 comments on commit dfec45a

Please sign in to comment.