Skip to content

Conversation

@qxo
Copy link

@qxo qxo commented Sep 19, 2020

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:

  • Make sure there is a JIRA issue filed
    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.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MCHECKSTYLE-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MCHECKSTYLE-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (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.

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
@qxo
Copy link
Author

qxo commented Sep 19, 2020

mvn -Prun-its clean verify failed on my PC because my network issue:

javax.net.ssl.SSLException: Connection reset
    at sun.security.ssl.Alert.createSSLException (Alert.java:127)
    at sun.security.ssl.TransportContext.fatal (TransportContext.java:321)
    at sun.security.ssl.TransportContext.fatal (TransportContext.java:264)
    at sun.security.ssl.TransportContext.fatal (TransportContext.java:259)
    at sun.security.ssl.SSLTransport.decode (SSLTransport.java:137)
    at sun.security.ssl.SSLSocketImpl.decode (SSLSocketImpl.java:1152)

@elharo elharo changed the title support ${config_loc} on checkstyle xml [MCHECKSTYLE-397] support ${config_loc} on checkstyle xml Nov 25, 2020
Copy link
Contributor

@elharo elharo left a 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.

@lrozenblyum
Copy link

lrozenblyum commented Jul 22, 2022

@bmarwell @elharo it's really a nice feature to have in the plug-in.
Currently enabling suppressions for a Maven multi-module project is much more complex than it could be.
${config_loc} support should enable seamless experience for Checkstyle users.

So could I for example continue work on this feature if it has chances for merge?
As I understand this pull request remarks should be solved?

@jira-importer
Copy link

Resolve #309

@slachiewicz slachiewicz requested a review from Copilot November 8, 2025 20:42
Copy link

Copilot AI left a 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_loc property
  • 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( '/' );
Copy link

Copilot AI Nov 8, 2025

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.

Suggested change
final int idx = configLocation.lastIndexOf( '/' );
final int idx = Math.max(configLocation.lastIndexOf('/'), configLocation.lastIndexOf('\\'));

Copilot uses AI. Check for mistakes.
Comment on lines +590 to +598
final int idx = configLocation.lastIndexOf( '/' );
final String configLoc;
if ( idx == -1 )
{
configLoc = "";
}
else
{
configLoc = configLocation.substring( 0, idx );
Copy link

Copilot AI Nov 8, 2025

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) { ... }.

Suggested change
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 = "";

Copilot uses AI. Check for mistakes.
}

//${config_loc} for the origin dir of the configLocation, just like eclipsecs
// so we config such as `${config_loc}/checkstyle-suppressions.xml`
Copy link

Copilot AI Nov 8, 2025

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".

Suggested change
// so we config such as `${config_loc}/checkstyle-suppressions.xml`
// so we can configure paths such as `${config_loc}/checkstyle-suppressions.xml`

Copilot uses AI. Check for mistakes.
Comment on lines +587 to +588
//${config_loc} for the origin dir of the configLocation, just like eclipsecs
// so we config such as `${config_loc}/checkstyle-suppressions.xml`
Copy link

Copilot AI Nov 8, 2025

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."

Suggested change
//${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.
*/

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants