From 9365bd04dcd24ae35f5852e56c352531c86144e5 Mon Sep 17 00:00:00 2001 From: rnveach Date: Sat, 31 Dec 2022 16:26:48 -0500 Subject: [PATCH] Pull #747: adds continueOnError property to diff.groovy --- .ci/validation.sh | 4 ++-- checkstyle-tester/README.md | 4 ++++ checkstyle-tester/diff.groovy | 22 +++++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.ci/validation.sh b/.ci/validation.sh index 769e136d..7dbe579e 100755 --- a/.ci/validation.sh +++ b/.ci/validation.sh @@ -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 @@ -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 diff --git a/checkstyle-tester/README.md b/checkstyle-tester/README.md index a0c3a61a..f4d11108 100644 --- a/checkstyle-tester/README.md +++ b/checkstyle-tester/README.md @@ -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 diff --git a/checkstyle-tester/diff.groovy b/checkstyle-tester/diff.groovy index 1335111a..51a463e5 100644 --- a/checkstyle-tester/diff.groovy +++ b/checkstyle-tester/diff.groovy @@ -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)') } @@ -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 { @@ -299,6 +302,7 @@ def generateCheckstyleReport(cfg) { excludes: excludes, checkstyleConfig: checkstyleConfig, saveDir: saveDir, + continueOnError: continueOnError, extraRegressionOptions: extraRegressionOptions, ] @@ -652,7 +656,7 @@ def runCliExecution(allJar, mainClassOptions) { cliCommand = cliCommand + mainClassOptions.extraRegressionOptions } - executeCmd(cliCommand) + executeCliCmd(cliCommand, mainClassOptions.continueOnError) println "Running Checkstyle CLI on ${mainClassOptions.srcDir} - finished" } @@ -683,6 +687,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')) { @@ -741,6 +756,7 @@ class Config { def shortFilePaths def listOfProjects def mode + def continueOnError def baseBranch def patchBranch @@ -770,6 +786,7 @@ class Config { shortFilePaths = cliOptions.shortFilePaths listOfProjects = cliOptions.listOfProjects extraRegressionOptions = cliOptions.extraRegressionOptions + continueOnError = cliOptions.continueOnError checkstyleVersion = cliOptions.checkstyleVersion allowExcludes = cliOptions.allowExcludes @@ -821,6 +838,7 @@ class Config { destDir: tmpMasterReportsDir, extraRegressionOptions: extraRegressionOptions, allowExcludes:allowExcludes, + continueOnError:continueOnError, ] } @@ -833,6 +851,7 @@ class Config { destDir: tmpPatchReportsDir, extraRegressionOptions: extraRegressionOptions, allowExcludes: allowExcludes, + continueOnError:continueOnError, ] } @@ -846,6 +865,7 @@ class Config { shortFilePaths: shortFilePaths, mode: mode, allowExcludes: allowExcludes, + continueOnError:continueOnError, ] } }