Skip to content
This repository was archived by the owner on Jan 27, 2019. It is now read-only.

Commit 5759c0d

Browse files
committed
Using hash in order to remove duplicated dsl
1 parent 7ce7c5b commit 5759c0d

File tree

4 files changed

+94
-10
lines changed

4 files changed

+94
-10
lines changed

jenkinslint-jobdsl-core/src/main/groovy/org/v1v/jenkins/jobdsl/jenkinslint/FileSetAnalyzer.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FileSetAnalyzer {
4747
private WildcardPattern includesPattern
4848
private WildcardPattern excludesPattern
4949

50-
private final items = []
50+
private final items = [:]
5151

5252
void analyze(List rules) {
5353
assert baseDirectory
@@ -82,7 +82,7 @@ class FileSetAnalyzer {
8282

8383
rules.each { rule ->
8484
items.each { item ->
85-
println "${rule} - ${rule.isDefect(item)}"
85+
println "${item.name} - ${rule} - ${rule.isDefect(item)}"
8686
}
8787
}
8888
}
@@ -93,14 +93,14 @@ class FileSetAnalyzer {
9393
*/
9494
void addItem(Item item) {
9595
assert item != null
96-
items << item
96+
items.put(item.name, item)
9797
}
9898

9999
/**
100100
* @return a List of Rule objects. The returned List is immutable.
101101
*/
102102
List getItems() {
103-
items.asImmutable()
103+
items.values().toArray()
104104
}
105105

106106
protected boolean matches(File sourceFile) {

jenkinslint-jobdsl-core/src/main/groovy/org/v1v/jenkins/jobdsl/jenkinslint/JenkinsLintRunner.groovy

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ class JenkinsLintRunner {
1717

1818
fileSetAnalyzer.analyze(ruleSet.getRules())
1919

20-
fileSetAnalyzer.getItems().each {
21-
println it.name
22-
}
23-
2420
def resultsMessage = "JenkinsLint completed: ${elapsedTime}ms"
2521
println resultsMessage
2622
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.v1v.jenkins.jobdsl.jenkinslint.ant
2+
3+
import org.apache.tools.ant.BuildException
4+
import org.apache.tools.ant.Task
5+
import org.apache.tools.ant.types.FileSet
6+
import org.v1v.jenkins.jobdsl.jenkinslint.JenkinsLintRunner
7+
8+
import java.util.logging.Logger
9+
10+
/**
11+
* Ant Task for running JenkinsLint.
12+
* At least one nested <code>fileset</code> element is required, and is used to specify the source files
13+
* to be analyzed. This is the standard Ant <i>FileSet</i>, and is quite powerful and flexible.
14+
* See the <i>Apache Ant Manual</i> for more information on <i>FileSets</i>.
15+
* <p/>
16+
*
17+
* @see "http://ant.apache.org/manual/index.html"
18+
*
19+
* @author Victor Martinez
20+
*/
21+
class JenkinsLintTask extends Task {
22+
23+
/*
24+
private static final LOG = Logger.getLogger(JenkinsLintTask)
25+
26+
String excludeBaseline
27+
28+
protected List fileSets = []
29+
protected ruleSet
30+
31+
private final resourceFactory = new DefaultResourceFactory()
32+
33+
// Abstract creation of the CodeNarcRunner instance to allow substitution of test spy for unit tests
34+
protected createJenkinsLintRunner = {
35+
if (excludeBaseline) {
36+
LOG.info("Loading baseline violations from [$excludeBaseline]")
37+
def resource = resourceFactory.getResource(excludeBaseline)
38+
def resultsProcessor = new BaselineResultsProcessor(resource)
39+
return new JenkinsLintRunner(resultsProcessor:resultsProcessor)
40+
}
41+
return new JenkinsLintRunner()
42+
}
43+
44+
void execute() throws BuildException {
45+
assert ruleSetFiles
46+
assert fileSets
47+
48+
def sourceAnalyzer = createSourceAnalyzer()
49+
def codeNarcRunner = createJenkinsLintRunner()
50+
codeNarcRunner.ruleSetFiles = ruleSetFiles
51+
codeNarcRunner.reportWriters = reportWriters
52+
codeNarcRunner.sourceAnalyzer = sourceAnalyzer
53+
54+
def results = codeNarcRunner.execute()
55+
56+
checkMaxViolations(results)
57+
}
58+
59+
void addFileset(FileSet fileSet) {
60+
assert fileSet
61+
this.fileSets << fileSet
62+
}
63+
64+
protected SourceAnalyzer createSourceAnalyzer() {
65+
new AntFileSetSourceAnalyzer(getProject(), fileSets)
66+
67+
}
68+
69+
private void checkMaxViolations(Results results) {
70+
def p1 = results.getNumberOfViolationsWithPriority(1, true)
71+
def p2 = results.getNumberOfViolationsWithPriority(2, true)
72+
def p3 = results.getNumberOfViolationsWithPriority(3, true)
73+
def countsText = "(p1=$p1; p2=$p2; p3=$p3)"
74+
75+
checkMaxViolationForPriority(1, p1, countsText)
76+
checkMaxViolationForPriority(2, p2, countsText)
77+
checkMaxViolationForPriority(3, p3, countsText)
78+
}
79+
80+
private void checkMaxViolationForPriority(int priority, int count, String countsText) {
81+
if (count > this."maxPriority${priority}Violations") {
82+
throw new BuildException("Exceeded maximum number of priority ${priority} violations: " + countsText)
83+
}
84+
}
85+
*/
86+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
job ('blabla') {
2-
label 'blabla'
1+
[1,2,3,4,5,6].each {
2+
job ("blabla${it}") {
3+
label 'blabla'
4+
}
35
}

0 commit comments

Comments
 (0)