@@ -74,6 +74,8 @@ def getCliOptions(args) {
74
74
+ ' as a shorter version to prevent long paths. (optional, default is false)' )
75
75
m(longOpt : ' mode' , args : 1 , required : false , argName : ' mode' , ' The mode of the tool:' \
76
76
+ ' \' 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)' )
77
79
xo(longOpt : ' extraRegressionOptions' , args : 1 , required : false , ' Extra arguments to pass ' \
78
80
+ ' for Checkstyle Regression run (optional, ex: -Dprop=true)' )
79
81
}
@@ -263,6 +265,7 @@ def generateCheckstyleReport(cfg) {
263
265
def allowExcludes = cfg. allowExcludes
264
266
def listOfProjectsFile = new File (cfg. listOfProjects)
265
267
def projects = listOfProjectsFile. readLines()
268
+ def continueOnError = cfg. continueOnError
266
269
def extraRegressionOptions = cfg. extraRegressionOptions
267
270
268
271
projects. each {
@@ -299,6 +302,7 @@ def generateCheckstyleReport(cfg) {
299
302
excludes : excludes,
300
303
checkstyleConfig : checkstyleConfig,
301
304
saveDir : saveDir,
305
+ continueOnError : continueOnError,
302
306
extraRegressionOptions : extraRegressionOptions
303
307
]
304
308
@@ -652,7 +656,7 @@ def runCliExecution(allJar, mainClassOptions) {
652
656
cliCommand = cliCommand + mainClassOptions. extraRegressionOptions
653
657
}
654
658
655
- executeCmd (cliCommand)
659
+ executeCliCmd (cliCommand, mainClassOptions . continueOnError )
656
660
println " Running Checkstyle CLI on ${ mainClassOptions.srcDir} - finished"
657
661
}
658
662
@@ -683,6 +687,17 @@ def executeCmd(cmd, dir = new File("").absoluteFile) {
683
687
}
684
688
}
685
689
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
+
686
701
def getOsSpecificCmd (cmd ) {
687
702
def osSpecificCmd
688
703
if (System . properties[' os.name' ]. toLowerCase(). contains(' windows' )) {
@@ -741,6 +756,7 @@ class Config {
741
756
def shortFilePaths
742
757
def listOfProjects
743
758
def mode
759
+ def continueOnError
744
760
745
761
def baseBranch
746
762
def patchBranch
@@ -770,6 +786,7 @@ class Config {
770
786
shortFilePaths = cliOptions. shortFilePaths
771
787
listOfProjects = cliOptions. listOfProjects
772
788
extraRegressionOptions = cliOptions. extraRegressionOptions
789
+ continueOnError = cliOptions. continueOnError
773
790
774
791
checkstyleVersion = cliOptions. checkstyleVersion
775
792
allowExcludes = cliOptions. allowExcludes
0 commit comments