Skip to content

Commit ac4361b

Browse files
committed
Pull #747: adds continueOnError property to diff.groovy
1 parent d592884 commit ac4361b

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

.ci/validation.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ checkstyle-tester-diff-groovy-regression-single)
7878
export JDK_JAVA_OPTIONS="-Xmx2048m"
7979
groovy ./diff.groovy --listOfProjects projects-to-test-on.properties \
8080
-pc ../../../checkstyle-tester/diff-groovy-regression-config.xml \
81-
-r ../../checkstyle \
81+
-r ../../checkstyle -ce \
8282
-m single -p master
8383

8484
# Run report with current branch
@@ -88,7 +88,7 @@ checkstyle-tester-diff-groovy-regression-single)
8888
rm -rf reports repositories
8989
groovy ./diff.groovy --listOfProjects projects-to-test-on.properties \
9090
-pc diff-groovy-regression-config.xml -r ../.ci-temp/checkstyle/ \
91-
-m single -p master
91+
-m single -p master -ce
9292

9393
cd ..
9494
# We need to ignore file paths below, since they will be different between reports

checkstyle-tester/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ to Checkstyle during the regression run.
7171
(optional, default is false). This option is
7272
used for files that are not compilable or that Checkstyle cannot parse.
7373

74+
**continueOnError** (ce) - whether to fail or continue the Checkstyle' run when it reports a
75+
non-zero return code.
76+
(optional, default is false)
77+
7478
## Outputs
7579

7680
When the script finishes its work the following directory structure will be created

checkstyle-tester/diff.groovy

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def getCliOptions(args) {
7474
+ ' as a shorter version to prevent long paths. (optional, default is false)')
7575
m(longOpt: 'mode', args: 1, required: false, argName: 'mode', 'The mode of the tool:' \
7676
+ ' \'diff\' or \'single\'. (optional, default is \'diff\')')
77+
ce(longOpt: 'continueOnError', required: false, 'Whether to fail or continue the Checkstyle' \
78+
+ ' run when it reports a non-zero return code. (optional, default is false)')
7779
xo(longOpt: 'extraRegressionOptions', args: 1, required: false, 'Extra arguments to pass ' \
7880
+ 'for Checkstyle Regression run (optional, ex: -Dprop=true)')
7981
}
@@ -263,6 +265,7 @@ def generateCheckstyleReport(cfg) {
263265
def allowExcludes = cfg.allowExcludes
264266
def listOfProjectsFile = new File(cfg.listOfProjects)
265267
def projects = listOfProjectsFile.readLines()
268+
def continueOnError = cfg.continueOnError
266269
def extraRegressionOptions = cfg.extraRegressionOptions
267270

268271
projects.each {
@@ -299,6 +302,7 @@ def generateCheckstyleReport(cfg) {
299302
excludes: excludes,
300303
checkstyleConfig: checkstyleConfig,
301304
saveDir: saveDir,
305+
continueOnError: continueOnError,
302306
extraRegressionOptions: extraRegressionOptions
303307
]
304308

@@ -652,7 +656,7 @@ def runCliExecution(allJar, mainClassOptions) {
652656
cliCommand = cliCommand + mainClassOptions.extraRegressionOptions
653657
}
654658

655-
executeCmd(cliCommand)
659+
executeCliCmd(cliCommand, mainClassOptions.continueOnError)
656660
println "Running Checkstyle CLI on ${mainClassOptions.srcDir} - finished"
657661
}
658662

@@ -683,6 +687,17 @@ def executeCmd(cmd, dir = new File("").absoluteFile) {
683687
}
684688
}
685689

690+
def executeCliCmd(cmd, continueOnError) {
691+
println "Running command: ${cmd}"
692+
def osSpecificCmd = getOsSpecificCmd(cmd)
693+
def proc = osSpecificCmd.execute(null, new File("").absoluteFile)
694+
proc.consumeProcessOutput(System.out, System.err)
695+
proc.waitFor()
696+
if (!continueOnError && proc.exitValue() != 0) {
697+
throw new GroovyRuntimeException("Error: ${proc.err.text}!")
698+
}
699+
}
700+
686701
def getOsSpecificCmd(cmd) {
687702
def osSpecificCmd
688703
if (System.properties['os.name'].toLowerCase().contains('windows')) {
@@ -741,6 +756,7 @@ class Config {
741756
def shortFilePaths
742757
def listOfProjects
743758
def mode
759+
def continueOnError
744760

745761
def baseBranch
746762
def patchBranch
@@ -770,6 +786,7 @@ class Config {
770786
shortFilePaths = cliOptions.shortFilePaths
771787
listOfProjects = cliOptions.listOfProjects
772788
extraRegressionOptions = cliOptions.extraRegressionOptions
789+
continueOnError = cliOptions.continueOnError
773790

774791
checkstyleVersion = cliOptions.checkstyleVersion
775792
allowExcludes = cliOptions.allowExcludes

0 commit comments

Comments
 (0)