Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #711 from daspilker/JENKINS-30543
[JENKINS-30543] added support for regular expression option for Task Scanner plugin
  • Loading branch information
daspilker committed Jan 2, 2016
2 parents 5a8a554 + c99904c commit f50edd8
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/Home.md
Expand Up @@ -50,6 +50,11 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
* Enhanced support for the
[Flexible Publish Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Flexible+Publish+Plugin)
([JENKINS-30010](https://issues.jenkins-ci.org/browse/JENKINS-30010))
* Enhanced support for the [Task Scanner Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Task+Scanner+Plugin)
([JENKINS-30543](https://issues.jenkins-ci.org/browse/JENKINS-30543))
* Support for the older versions of the
[Task Scanner Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Task+Scanner+Plugin) is deprecated, see
[Migration](Migration#migrating-to-142)
* Changed the DSL syntax for `flexiblePublish`, see [Migration](Migration#migrating-to-142)
* Check DSL scripts for existence
([JENKINS-30541](https://issues.jenkins-ci.org/browse/JENKINS-30541))
Expand Down
6 changes: 6 additions & 0 deletions docs/Migration.md
@@ -1,5 +1,11 @@
## Migrating to 1.42

### Task Scanner

Support for versions older than 4.41 of the
[Task Scanner Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Task+Scanner+Plugin) is
[[deprecated|Deprecation-Policy]] and will be removed.

### PostBuildScript

Support for versions older than 0.17 of the
Expand Down
Expand Up @@ -1258,17 +1258,22 @@ class PublisherContext extends AbstractExtensibleContext {
*/
@RequiresPlugin(id = 'tasks')
void tasks(String pattern, excludePattern = '', high = '', normal = '', low = '', ignoreCase = false,
@DslContext(StaticAnalysisContext) Closure staticAnalysisClosure = null) {
StaticAnalysisContext staticAnalysisContext = new StaticAnalysisContext()
ContextHelper.executeInContext(staticAnalysisClosure, staticAnalysisContext)
@DslContext(TaskScannerContext) Closure closure = null) {
jobManagement.logPluginDeprecationWarning('tasks', '4.41')

TaskScannerContext context = new TaskScannerContext(jobManagement)
ContextHelper.executeInContext(closure, context)

publisherNodes << new NodeBuilder().'hudson.plugins.tasks.TasksPublisher' {
addStaticAnalysisContextAndPattern(delegate, staticAnalysisContext, pattern)
addStaticAnalysisContextAndPattern(delegate, context, pattern)
delegate.high(high)
delegate.normal(normal)
delegate.low(low)
delegate.ignoreCase(ignoreCase)
delegate.excludePattern(excludePattern)
if (!jobManagement.getPluginVersion('tasks')?.isOlderThan(new VersionNumber('4.41'))) {
asRegexp(context.regularExpression)
}
}
}

Expand Down
@@ -0,0 +1,24 @@
package javaposse.jobdsl.dsl.helpers.publisher

import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.RequiresPlugin

class TaskScannerContext extends StaticAnalysisContext {
protected final JobManagement jobManagement

boolean regularExpression

TaskScannerContext(JobManagement jobManagement) {
this.jobManagement = jobManagement
}

/**
* If set, treats the tag identifiers as regular expression.
*
* @since 1.42
*/
@RequiresPlugin(id = 'tasks', minimumVersion = '4.41')
void regularExpression(boolean regularExpression = true) {
this.regularExpression = regularExpression
}
}
@@ -1,5 +1,6 @@
package javaposse.jobdsl.dsl.helpers.publisher

import hudson.util.VersionNumber
import javaposse.jobdsl.dsl.Item
import javaposse.jobdsl.dsl.JobManagement
import spock.lang.Specification
Expand Down Expand Up @@ -44,7 +45,8 @@ class StaticAnalysisPublisherContextSpec extends Specification {
'checkstyle' | [:] | 'checkstyle'
'jshint' | [:] | 'jshint-checkstyle'
'dry' | [highThreshold: 50, normalThreshold: 25] | 'dry'
'tasks' | [excludePattern: '', high: '', normal: '', low: '', ignoreCase: false] | 'tasks'
'tasks' | [excludePattern: '', high: '', normal: '', low: '', ignoreCase: false,
asRegexp: false] | 'tasks'
}

def 'add warnings with default values'() {
Expand Down Expand Up @@ -136,7 +138,8 @@ class StaticAnalysisPublisherContextSpec extends Specification {
[highThreshold: 60, normalThreshold: 37]
'tasks' | 'hudson.plugins.tasks.TasksPublisher' |
['**/*.xml', 'FIXME', 'TODO', 'LOW', true] |
[excludePattern: '**/*.xml', high: 'FIXME', normal: 'TODO', low: 'LOW', ignoreCase: true]
[excludePattern: '**/*.xml', high: 'FIXME', normal: 'TODO', low: 'LOW', ignoreCase: true,
asRegexp: false]
}

def 'add warnings with all values'() {
Expand Down Expand Up @@ -285,6 +288,97 @@ class StaticAnalysisPublisherContextSpec extends Specification {
1 * jobManagement.requirePlugin('analysis-collector')
}

def 'task scanner with minimal options and older plugin version'() {
setup:
jobManagement.getPluginVersion('tasks') >> new VersionNumber('4.40')

when:
context.tasks('foo')

then:
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
children().size() == 17
pattern[0].value() == 'foo'
high[0].value().empty
normal[0].value().empty
low[0].value().empty
ignoreCase[0].value() == false
excludePattern[0].value().empty
healthy[0].value() == null
unHealthy[0].value() == null
thresholdLimit[0].value() == 'low'
defaultEncoding[0].value().empty
thresholds[0].value().empty
canRunOnFailed[0].value() == false
useStableBuildAsReference[0].value() == false
useDeltaValues[0].value() == false
shouldDetectModules[0].value() == false
dontComputeNew[0].value() == true
doNotResolveRelativePaths[0].value() == true
}
}

def 'task scanner with minimal options'() {
when:
context.tasks('foo')

then:
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
children().size() == 18
pattern[0].value() == 'foo'
high[0].value().empty
normal[0].value().empty
low[0].value().empty
ignoreCase[0].value() == false
excludePattern[0].value().empty
healthy[0].value() == null
unHealthy[0].value() == null
thresholdLimit[0].value() == 'low'
defaultEncoding[0].value().empty
thresholds[0].value().empty
canRunOnFailed[0].value() == false
useStableBuildAsReference[0].value() == false
useDeltaValues[0].value() == false
shouldDetectModules[0].value() == false
dontComputeNew[0].value() == true
doNotResolveRelativePaths[0].value() == true
asRegexp[0].value() == false
}
}

def 'task scanner with extra options'() {
when:
context.tasks('foo', 'bar', 'one', 'two', 'three', true) {
regularExpression()
}

then:
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
children().size() == 18
pattern[0].value() == 'foo'
high[0].value() == 'one'
normal[0].value() == 'two'
low[0].value() == 'three'
ignoreCase[0].value() == true
excludePattern[0].value() == 'bar'
healthy[0].value() == null
unHealthy[0].value() == null
thresholdLimit[0].value() == 'low'
defaultEncoding[0].value().empty
thresholds[0].value().empty
canRunOnFailed[0].value() == false
useStableBuildAsReference[0].value() == false
useDeltaValues[0].value() == false
shouldDetectModules[0].value() == false
dontComputeNew[0].value() == true
doNotResolveRelativePaths[0].value() == true
asRegexp[0].value() == true
}
}

private static void assertValues(Map map, baseNode, List notCheckedNodes = [], Map extraNodes = [:]) {
(map + extraNodes).each { String key, expectedValue ->
def nodeList = baseNode[key]
Expand Down

0 comments on commit f50edd8

Please sign in to comment.