-
Notifications
You must be signed in to change notification settings - Fork 65
[MCHECKSTYLE-397] support ${config_loc} on checkstyle xml #36
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
base: master
Are you sure you want to change the base?
Conversation
we can use config_loc as: ${config_loc}/suppressions.xml.
with this PR, we can use same checkstyle.xml which contains ${config_loc}
for eclipsecs ${config_loc} is a variable of Eclipse and it will refer to the same directory where the checkstyle.xml is present.
ref: https://checkstyle.org/eclipse-cs/#!/properties
|
|
elharo
left a comment
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 could use some tests.
src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
Show resolved
Hide resolved
|
@bmarwell @elharo it's really a nice feature to have in the plug-in. So could I for example continue work on this feature if it has chances for merge? |
|
Resolve #309 |
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.
Pull Request Overview
This PR adds support for the ${config_loc} property in Checkstyle configurations, mirroring the behavior of the Eclipse Checkstyle plugin (eclipsecs). This allows Checkstyle configuration files to reference other resources (like suppression files) relative to the config file's directory.
- Extracts the directory path from the config location and sets it as the
config_locproperty - Enables relative path references in Checkstyle configurations using
${config_loc}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| //${config_loc} for the origin dir of the configLocation, just like eclipsecs | ||
| // so we config such as `${config_loc}/checkstyle-suppressions.xml` | ||
| final String configLocation = request.getConfigLocation(); | ||
| final int idx = configLocation.lastIndexOf( '/' ); |
Copilot
AI
Nov 8, 2025
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.
The code only handles forward slash / as a path separator, but Windows systems use backslash \. This will cause the config_loc property to be incorrectly set on Windows when the config location contains backslashes. Consider using Math.max(configLocation.lastIndexOf('/'), configLocation.lastIndexOf('\\')) to handle both path separators, or use a platform-independent approach.
| final int idx = configLocation.lastIndexOf( '/' ); | |
| final int idx = Math.max(configLocation.lastIndexOf('/'), configLocation.lastIndexOf('\\')); |
| final int idx = configLocation.lastIndexOf( '/' ); | ||
| final String configLoc; | ||
| if ( idx == -1 ) | ||
| { | ||
| configLoc = ""; | ||
| } | ||
| else | ||
| { | ||
| configLoc = configLocation.substring( 0, idx ); |
Copilot
AI
Nov 8, 2025
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.
Potential NullPointerException: The code doesn't check if configLocation is null before calling lastIndexOf(). While getConfigFile() is currently called before this method in getConfiguration(), this creates a fragile implicit dependency. Add a null check to make the code more robust: if (configLocation != null) { ... }.
| final int idx = configLocation.lastIndexOf( '/' ); | |
| final String configLoc; | |
| if ( idx == -1 ) | |
| { | |
| configLoc = ""; | |
| } | |
| else | |
| { | |
| configLoc = configLocation.substring( 0, idx ); | |
| final String configLoc; | |
| if (configLocation != null) | |
| { | |
| final int idx = configLocation.lastIndexOf( '/' ); | |
| if ( idx == -1 ) | |
| { | |
| configLoc = ""; | |
| } | |
| else | |
| { | |
| configLoc = configLocation.substring( 0, idx ); | |
| } | |
| } | |
| else | |
| { | |
| configLoc = ""; |
| } | ||
|
|
||
| //${config_loc} for the origin dir of the configLocation, just like eclipsecs | ||
| // so we config such as `${config_loc}/checkstyle-suppressions.xml` |
Copilot
AI
Nov 8, 2025
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.
Grammatical error in comment: "so we config such as" should be "so we can configure such as" or "allowing configuration such as".
| // so we config such as `${config_loc}/checkstyle-suppressions.xml` | |
| // so we can configure paths such as `${config_loc}/checkstyle-suppressions.xml` |
| //${config_loc} for the origin dir of the configLocation, just like eclipsecs | ||
| // so we config such as `${config_loc}/checkstyle-suppressions.xml` |
Copilot
AI
Nov 8, 2025
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.
The comment should follow standard Java comment conventions. The variable reference ${config_loc} and the purpose of this code would be clearer with improved documentation. Consider: "Sets the config_loc property to the directory portion of configLocation. This allows Checkstyle configurations to reference the config directory using ${config_loc}, similar to Eclipse CS plugin behavior."
| //${config_loc} for the origin dir of the configLocation, just like eclipsecs | |
| // so we config such as `${config_loc}/checkstyle-suppressions.xml` | |
| /* | |
| * Sets the config_loc property to the directory portion of configLocation. | |
| * This allows Checkstyle configurations to reference the config directory using ${config_loc}, | |
| * similar to Eclipse CS plugin behavior. | |
| */ |
we can use config_loc as: ${config_loc}/suppressions.xml.
with this PR, we can use same checkstyle.xml which contains ${config_loc}
for eclipsecs ${config_loc} is a variable of Eclipse and it will refer to the same directory where the checkstyle.xml is present.
ref: https://checkstyle.org/eclipse-cs/#!/properties
https://issues.apache.org/jira/projects/MCHECKSTYLE/issues/MCHECKSTYLE-397
Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MCHECKSTYLE-XXX] - Fixes bug in ApproximateQuantiles,where you replace
MCHECKSTYLE-XXXwith the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean verifyto make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
mvn -Prun-its clean verify).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.