-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #273: converts diff.groovy to use Checkstyle's CLI #747
Conversation
.ci/travis.sh
Outdated
@@ -90,7 +90,7 @@ checkstyle-tester-diff-groovy-regression-single) | |||
export MAVEN_OPTS="-Xmx2048m" | |||
groovy ./diff.groovy --listOfProjects projects-to-test-on.properties \ | |||
-pc ../../../checkstyle-tester/diff-groovy-regression-config.xml \ | |||
-r ../../checkstyle -xm "-Dcheckstyle.failsOnError=false" \ | |||
-r ../../checkstyle \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLI doesn't have anything similar. It seems we need to build something into groovy.
If this is true, and Checkstyle reported any violations or errors, the build fails immediately after running Checkstyle
The only way we have to determine if any violations/errors are reported from the CLI is the exit code. ( https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/Main.java#L415 ) We just have to be careful on other exit codes ( https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/Main.java#L85-L89 )
Anything else requires adding custom modules to listen for violations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the reverse option, continueOnError
. It is inverted because we need the default to be false
so when we use the option, it is enabled. It follows the POM's default value which was failsOnError = true
so continueOnError = false
by default.
checkstyle-tester/diff.groovy
Outdated
@@ -74,8 +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\')') | |||
xm(longOpt: 'extraMvnRegressionOptions', args: 1, required: false, 'Extra arguments to pass to Maven' \ | |||
+ 'for Checkstyle Regression run (optional, ex: -Dmaven.prop=true)') | |||
xo(longOpt: 'extraRegressionOptions', args: 1, required: false, 'Extra arguments to pass ' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took xm
as extraMvn
so I changed this to xo
to mean extraOptions
since this is not passed to any maven now.
checkstyle-tester/diff.groovy
Outdated
executeCmd("git checkout $cfg.branch", cfg.localGitRepo) | ||
executeCmd("git log -1 --pretty=MSG:%s%nSHA-1:%H", cfg.localGitRepo) | ||
executeCmd("mvn -e --no-transfer-progress --batch-mode -Pno-validations clean install", | ||
executeCmd("mvn -e --no-transfer-progress --batch-mode -Pno-validations clean package -Passembly -Dassembly.skipAssembly=true -Dmaven.test.skip=true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial done of #591 .
<checkstyle-plugin.version>3.1.1</checkstyle-plugin.version> | ||
<checkstyle.version>0.0-SNAPSHOT</checkstyle.version> | ||
<sevntu-checkstyle.version>1.44.1</sevntu-checkstyle.version> | ||
<checkstyle.config.location>https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml</checkstyle.config.location> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This config is never really used as shown in #745
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<checkstyle-plugin.version>3.1.1</checkstyle-plugin.version> | ||
<checkstyle.version>0.0-SNAPSHOT</checkstyle.version> | ||
<sevntu-checkstyle.version>1.44.1</sevntu-checkstyle.version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sevntu support is completely removed until #340 / #604 . We only supported single mode runs anyways, never supported differences since the sevntu version was never changed.
There is https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/sevntu_launch_diff.sh which I have maintained.
checkstyle-tester/diff.groovy
Outdated
|
||
println "Running Checkstyle CLI on $srcDir ... with excludes {$excludes}" | ||
def cliCommand = "java -jar $allJar -c $checkstyleConfig $srcDir -f xml -o " + | ||
getOsSpecificPath("$saveDir", "checkstyle-result.xml") + " -e .git -e .hg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the benefits of using the CLI is we now pull in all files and not just .java
. Because of this we have to exclude .git
and .hg
from erroneously processing them. TreeWalker
will still trim to work only on Java files.
These have to be made more direct paths since this are not absolutely relative to the current working directory. We may want to consider picocli's file arguments for command line especially if we have a lot of excludes if it can bypass any limitation issues.
A command may be invoked with the @file argument, like this:
java MyCommand @/home/foo/args
@rnveach , please create PR to main repo to use your branch and validate and action is working to generate diff report. |
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
items:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items
ac4361b
to
78a613a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if CI is green in this repo and it it works well in main repo CI - ok to merge.
9365bd0
to
d5364f5
Compare
allowExcludes:allowExcludes, | ||
continueOnError:continueOnError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed a bug in continueOnError
, where if new option is not listed in these areas, then we cannot reference them in the main execution as we pull them in from here.
Without listed them here, doing cfg.[option]
in main code always returned null
and it would not fail anywhere since we were treating it as a boolean. It would just never get enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items:
if (!extraMvnRegressionOptions.startsWith("-")) { | ||
mvnSite = mvnSite + "-" | ||
println "Running Checkstyle CLI on ${mainClassOptions.srcDir} ... with excludes {${mainClassOptions.excludes}}" | ||
def cliCommand = "java -jar $allJar -c ${mainClassOptions.checkstyleConfig} " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't help but feel that StringBuilder would be faster/easier to read/use less memory, especially with a bunch of excludes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want me to switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind performance is not an issue here as it is one time execution. Better to keep code easy to read. I don't mind any approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a big deal, but we certainly run this more than once (twice for each project). I was thinking more for readability since +
at the end of the line bugs me. I will leave it up to @rnveach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to disable trailing "+" rule.
I always thought about groovy as Java script abilities, to write in pure Java but as script. All scripts grows and grow up in applications, so being plain java is good for them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a rule, this is required by the interpreter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romani Please see the message I posted for you at checkstyle/checkstyle#12725 (comment) . This is groovy itself, and not a style rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sad, but ok, lets follow interpreter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we test failure at checkstyle/checkstyle#12576, i.e. throw an exception in a check? We need to make sure that we can still fail CI in all cases, too.
It depends on what scenario you are looking for. Using https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/Main.java#L135 I did confirm locally that removing
With output:
|
All our This will have to be removed, but there is the one config I pointed out to that uses It looks like Example run: https://github.com/checkstyle/checkstyle/actions/runs/4152812321/jobs/7184025441#step:5:320 |
@nrmancuso , @rnveach , is there easy way to finish this PR ? |
The only easy way is to complete everything needed for the transfer ( #747 (comment) ). This is the only PR in this repo I was working on for this issue. |
Issue #273
Supplemental Checkstyle PR: checkstyle/checkstyle#12576