Skip to content

Commit

Permalink
Pull #747: adds continueOnError property to diff.groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Jan 27, 2023
1 parent 1616e8a commit b401951
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .ci/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ checkstyle-tester-diff-groovy-regression-single)
export JDK_JAVA_OPTIONS="-Xmx2048m"
groovy ./diff.groovy --listOfProjects projects-to-test-on.properties \
-pc ../../../checkstyle-tester/diff-groovy-regression-config.xml \
-r ../../checkstyle \
-r ../../checkstyle -ce \
-m single -p master

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

cd ..
# We need to ignore file paths below, since they will be different between reports
Expand Down
4 changes: 4 additions & 0 deletions checkstyle-tester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ to Checkstyle during the regression run.
(optional, default is false). This option is
used for files that are not compilable or that Checkstyle cannot parse.

**continueOnError** (ce) - whether to fail or continue the Checkstyle' run when it reports a
non-zero return code.
(optional, default is false)

## Outputs

When the script finishes its work the following directory structure will be created
Expand Down
19 changes: 18 additions & 1 deletion checkstyle-tester/diff.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def getCliOptions(args) {
+ ' as a shorter version to prevent long paths. (optional, default is false)')
m(longOpt: 'mode', args: 1, required: false, argName: 'mode', 'The mode of the tool:' \
+ ' \'diff\' or \'single\'. (optional, default is \'diff\')')
ce(longOpt: 'continueOnError', required: false, 'Whether to fail or continue the Checkstyle' \
+ ' run when it reports a non-zero return code. (optional, default is false)')
xo(longOpt: 'extraRegressionOptions', args: 1, required: false, 'Extra arguments to pass ' \
+ 'for Checkstyle Regression run (optional, ex: -Dprop=true)')
}
Expand Down Expand Up @@ -263,6 +265,7 @@ def generateCheckstyleReport(cfg) {
def allowExcludes = cfg.allowExcludes
def listOfProjectsFile = new File(cfg.listOfProjects)
def projects = listOfProjectsFile.readLines()
def continueOnError = cfg.continueOnError
def extraRegressionOptions = cfg.extraRegressionOptions

projects.each {
Expand Down Expand Up @@ -299,6 +302,7 @@ def generateCheckstyleReport(cfg) {
excludes: excludes,
checkstyleConfig: checkstyleConfig,
saveDir: saveDir,
continueOnError: continueOnError,
extraRegressionOptions: extraRegressionOptions,
]

Expand Down Expand Up @@ -651,7 +655,7 @@ def runCliExecution(allJar, mainClassOptions) {
cliCommand = cliCommand + mainClassOptions.extraRegressionOptions
}

executeCmd(cliCommand)
executeCliCmd(cliCommand, mainClassOptions.continueOnError)
println "Running Checkstyle CLI on ${mainClassOptions.srcDir} - finished"
}

Expand Down Expand Up @@ -682,6 +686,17 @@ def executeCmd(cmd, dir = new File("").absoluteFile) {
}
}

def executeCliCmd(cmd, continueOnError) {
println "Running command: ${cmd}"
def osSpecificCmd = getOsSpecificCmd(cmd)
def proc = osSpecificCmd.execute(null, new File("").absoluteFile)
proc.consumeProcessOutput(System.out, System.err)
proc.waitFor()
if (!continueOnError && proc.exitValue() != 0) {
throw new GroovyRuntimeException("Error: ${proc.err.text}!")
}
}

def getOsSpecificCmd(cmd) {
def osSpecificCmd
if (System.properties['os.name'].toLowerCase().contains('windows')) {
Expand Down Expand Up @@ -740,6 +755,7 @@ class Config {
def shortFilePaths
def listOfProjects
def mode
def continueOnError

def baseBranch
def patchBranch
Expand Down Expand Up @@ -769,6 +785,7 @@ class Config {
shortFilePaths = cliOptions.shortFilePaths
listOfProjects = cliOptions.listOfProjects
extraRegressionOptions = cliOptions.extraRegressionOptions
continueOnError = cliOptions.continueOnError

checkstyleVersion = cliOptions.checkstyleVersion
allowExcludes = cliOptions.allowExcludes
Expand Down

0 comments on commit b401951

Please sign in to comment.