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 Feb 10, 2023
1 parent b697cb2 commit b156dcd
Show file tree
Hide file tree
Showing 3 changed files with 38 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 @@ -70,6 +70,10 @@ This option is useful for Windows users where they are restricted to maximum dir
(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
33 changes: 32 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: 'extraOptions', args: 1, required: false, 'Extra arguments to pass ' \
+ 'for Checkstyle execution (optional, ex: -Dprop=true)')
}
Expand Down Expand Up @@ -263,7 +265,12 @@ def generateCheckstyleReport(cfg) {
def allowExcludes = cfg.allowExcludes
def listOfProjectsFile = new File(cfg.listOfProjects)
def projects = listOfProjectsFile.readLines()
<<<<<<< Upstream, based on 3ff9dd2b52ce8c6cec57a8ba16e7610f34cf65c8
def extraOptions = cfg.extraOptions
=======
def continueOnError = cfg.continueOnError
def extraRegressionOptions = cfg.extraRegressionOptions
>>>>>>> 5d2f864 Pull #747: adds continueOnError property to diff.groovy

projects.each {
project ->
Expand Down Expand Up @@ -299,7 +306,12 @@ def generateCheckstyleReport(cfg) {
excludes: excludes,
checkstyleConfig: checkstyleConfig,
saveDir: saveDir,
<<<<<<< Upstream, based on 3ff9dd2b52ce8c6cec57a8ba16e7610f34cf65c8
extraOptions: extraOptions,
=======
continueOnError: continueOnError,
extraRegressionOptions: extraRegressionOptions,
>>>>>>> 5d2f864 Pull #747: adds continueOnError property to diff.groovy
]

runCliExecution(allJar, mainClassOptions)
Expand Down Expand Up @@ -653,7 +665,7 @@ def runCliExecution(allJar, mainClassOptions) {
cliCommand = cliCommand + mainClassOptions.extraOptions
}

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

Expand Down Expand Up @@ -684,6 +696,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 @@ -742,6 +765,7 @@ class Config {
def shortFilePaths
def listOfProjects
def mode
def continueOnError

def baseBranch
def patchBranch
Expand Down Expand Up @@ -770,7 +794,12 @@ class Config {

shortFilePaths = cliOptions.shortFilePaths
listOfProjects = cliOptions.listOfProjects
<<<<<<< Upstream, based on 3ff9dd2b52ce8c6cec57a8ba16e7610f34cf65c8
extraOptions = cliOptions.extraOptions
=======
extraRegressionOptions = cliOptions.extraRegressionOptions
continueOnError = cliOptions.continueOnError
>>>>>>> 5d2f864 Pull #747: adds continueOnError property to diff.groovy

checkstyleVersion = cliOptions.checkstyleVersion
allowExcludes = cliOptions.allowExcludes
Expand Down Expand Up @@ -822,6 +851,7 @@ class Config {
destDir: tmpMasterReportsDir,
extraOptions: extraOptions,
allowExcludes:allowExcludes,
continueOnError:continueOnError,
]
}

Expand All @@ -834,6 +864,7 @@ class Config {
destDir: tmpPatchReportsDir,
extraOptions: extraOptions,
allowExcludes: allowExcludes,
continueOnError:continueOnError,
]
}

Expand Down

0 comments on commit b156dcd

Please sign in to comment.