diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 3c82ad9f..55193963 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -19,11 +19,11 @@ jobs: path: ~/.m2/repository key: maven-cache-${{ hashFiles('**/pom.xml') }} - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v3 with: distribution: corretto - java-version: 17 + java-version: 21 - name: Build with Maven run: mvn -e --no-transfer-progress install diff --git a/config/checkstyle.properties b/config/checkstyle.properties index b71118aa..818a4271 100644 --- a/config/checkstyle.properties +++ b/config/checkstyle.properties @@ -4,3 +4,4 @@ checkstyle.header.file=https://raw.githubusercontent.com/checkstyle/checkstyle/m checkstyle.regexp.header.file=https://raw.githubusercontent.com/checkstyle/checkstyle/master/config/java-regexp.header checkstyle.importcontrol.file=config/import-control.xml checkstyle.importcontroltest.file=config/import-control-test.xml +checkstyle.java.version=21 diff --git a/pom.xml b/pom.xml index bd96bc25..c50aaf5f 100644 --- a/pom.xml +++ b/pom.xml @@ -33,10 +33,10 @@ UTF-8 - 10.4 + 13.3.0 3.2.0 - 17 - 17 + 21 + 21 5.9.1 @@ -116,7 +116,7 @@ false true - https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-${checkstyle.version}/config/checkstyle_checks.xml + https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-${checkstyle.version}/config/checkstyle-checks.xml config/checkstyle.properties true diff --git a/src/main/java/com/github/checkstyle/generatepatchfile/GeneratePatchFile.java b/src/main/java/com/github/checkstyle/generatepatchfile/GeneratePatchFile.java index 2fb87987..3c3ae0cd 100644 --- a/src/main/java/com/github/checkstyle/generatepatchfile/GeneratePatchFile.java +++ b/src/main/java/com/github/checkstyle/generatepatchfile/GeneratePatchFile.java @@ -142,8 +142,8 @@ public GeneratePatchFile(String repoPath, String testerPath, .readEnvironment().findGitDir().build(); git = new Git(repository); } - catch (IOException ex) { - ex.printStackTrace(); + catch (IOException exception) { + exception.printStackTrace(); } diffReportDirName = new File(".").getAbsoluteFile().getParent() + "/DiffReport"; } @@ -406,8 +406,8 @@ private void generateSummaryIndexHtml() { out.write("\n"); } - catch (IOException ex) { - ex.printStackTrace(); + catch (IOException exception) { + exception.printStackTrace(); } } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/JavaPatchFilterElement.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/JavaPatchFilterElement.java index b3ce06ca..9aa5f3c4 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/JavaPatchFilterElement.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/JavaPatchFilterElement.java @@ -185,7 +185,7 @@ public boolean accept(TreeWalkerAuditEvent event) { * @return true if it is matching */ private boolean isFileNameMatching(TreeWalkerAuditEvent event) { - String eventFileName = event.getFileName(); + String eventFileName = event.fileName(); boolean result = eventFileName != null; if (result) { @@ -225,7 +225,7 @@ private boolean isNeverSuppressCheck(TreeWalkerAuditEvent event) { */ private boolean isLineMatching(TreeWalkerAuditEvent event) { boolean result = false; - if (event.getViolation() != null) { + if (event.violation() != null) { result = lineMatching(event.getLine()); } return result; @@ -337,7 +337,7 @@ private static boolean containsShortName(Set checkNameSet, } private static String getCheckName(TreeWalkerAuditEvent event) { - final String[] checkNames = event.getViolation().getSourceName().split("\\."); + final String[] checkNames = event.violation().getSourceName().split("\\."); return checkNames[checkNames.length - 1]; } @@ -352,7 +352,7 @@ private static String getCheckShortName(TreeWalkerAuditEvent event) { * @return DetailAST event's corresponding ast node */ private static DetailAST getEventAst(TreeWalkerAuditEvent event) { - DetailAST curNode = event.getRootAst(); + DetailAST curNode = event.rootAst(); DetailAST eventAst = null; while (curNode != null) { if (isMatchingAst(curNode, event)) { diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionJavaPatchFilter.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionJavaPatchFilter.java index 3aedaac8..3e30a904 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionJavaPatchFilter.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionJavaPatchFilter.java @@ -38,10 +38,8 @@ import com.puppycrawl.tools.checkstyle.utils.FilterUtil; /** - *

* Filter {@code SuppressionJavaPatchFilter} rejects audit events for Check violations * according to a patch file. - *

* * @since 8.34 */ @@ -108,6 +106,7 @@ public class SuppressionJavaPatchFilter extends AutomaticBean implements * Setter to specify the location of the patch file. * * @param fileName name of the patch file. + * @since 8.34 */ public void setFile(String fileName) { file = fileName; @@ -117,6 +116,7 @@ public void setFile(String fileName) { * Setter to control if only consider added lines in file. * * @param strategy tells if only consider added lines is add, should be added or changed. + * @since 8.34 */ public void setStrategy(String strategy) { this.strategy = Strategy.valueOf(strategy.toUpperCase()); @@ -131,6 +131,8 @@ public void setStrategy(String strategy) { * to their parent abstract nodes * to get their child nodes, * split by comma + * + * @since 8.34 */ public void setCheckNamesForContextStrategyByTokenOrParentSet( String checkNamesForContextStrategyByTokenOrParentSet) { @@ -148,6 +150,7 @@ public void setCheckNamesForContextStrategyByTokenOrParentSet( * to their ancestor abstract nodes * to get their child nodes, * split by comma + * @since 8.34 */ public void setCheckNamesForContextStrategyByTokenOrAncestorSet( String checkNamesForContextStrategyByTokenOrAncestorSet) { @@ -161,6 +164,7 @@ public void setCheckNamesForContextStrategyByTokenOrAncestorSet( * * @param supportContextStrategyChecks string has user defined checks that support * context strategy + * @since 8.34 */ public void setSupportContextStrategyChecks(String supportContextStrategyChecks) { final String[] checksArray = supportContextStrategyChecks.split(COMMA); @@ -173,6 +177,7 @@ public void setSupportContextStrategyChecks(String supportContextStrategyChecks) * * @param neverSuppressedChecks string has user defined Checks to never suppress * if files are touched, split by comma + * @since 8.34 */ public void setNeverSuppressedChecks(String neverSuppressedChecks) { final String[] checksArray = neverSuppressedChecks.split(COMMA); @@ -186,6 +191,7 @@ public void setNeverSuppressedChecks(String neverSuppressedChecks) { * and file is not found, the filter accept all audit events. * * @param optional tells if config file existence is optional. + * @since 8.34 */ public void setOptional(boolean optional) { this.optional = optional; diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilter.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilter.java index 10d22662..e7f007ac 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilter.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilter.java @@ -38,10 +38,8 @@ import com.puppycrawl.tools.checkstyle.utils.FilterUtil; /** - *

* Filter {@code SuppressionFilter} rejects audit events for Check violations according to a * patch file. - *

* * @since 8.34 */ @@ -87,6 +85,7 @@ public class SuppressionPatchFilter extends AutomaticBean * Setter to specify the location of the patch file. * * @param fileName name of the patch file. + * @since 8.34 */ public void setFile(String fileName) { file = fileName; @@ -96,6 +95,7 @@ public void setFile(String fileName) { * Setter to control if only consider added lines in file. * * @param strategy tells if only consider added lines is add, should be added or changed. + * @since 8.34 */ public void setStrategy(String strategy) { this.strategy = Strategy.valueOf(strategy.toUpperCase()); @@ -106,6 +106,7 @@ public void setStrategy(String strategy) { * * @param neverSuppressedChecks string has user defined Checks to never suppress * if files are touched, split by comma + * @since 8.34 */ public void setNeverSuppressedChecks(String neverSuppressedChecks) { final String[] checksArray = neverSuppressedChecks.split(COMMA); @@ -119,6 +120,7 @@ public void setNeverSuppressedChecks(String neverSuppressedChecks) { * and file is not found, the filter accept all audit events. * * @param optional tells if config file existence is optional. + * @since 8.34 */ public void setOptional(boolean optional) { this.optional = optional; diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilterElement.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilterElement.java index 68deacf0..0a423a66 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilterElement.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilterElement.java @@ -110,8 +110,8 @@ private static boolean isTreeWalkerChecksMatching(AuditEvent event) { } return result; } - catch (ClassNotFoundException ex) { - throw new IllegalStateException("Class " + sourceName + " not found", ex); + catch (ClassNotFoundException exception) { + throw new IllegalStateException("Class " + sourceName + " not found", exception); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionJavaPatchFilterTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionJavaPatchFilterTest.java index 8df78a8b..d3cf88bd 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionJavaPatchFilterTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionJavaPatchFilterTest.java @@ -34,7 +34,7 @@ protected String getPatchFileLocation() { } @Override - protected String getPackageLocation() { + public String getPackageLocation() { return "com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/"; } @@ -56,14 +56,12 @@ public void testNonExistentPatchFileWithFalseOptional() throws Exception { try { testByConfig("Optional/false/defaultContextConfig.xml"); } - catch (CheckstyleException ex) { - assertEquals("cannot initialize module TreeWalker - " - + "cannot initialize module " - + "com.puppycrawl.tools.checkstyle.filters.SuppressionJavaPatchFilter " - + "- an error occurred when loading patch file " - + getPatchFileLocation() + "Optional/false//defaultContext.patch", - ex.getMessage(), - "Invalid error message"); + catch (CheckstyleException exception) { + assertEquals( + "cannot initialize module TreeWalker - cannot initialize module " + + "com.puppycrawl.tools.checkstyle.filters.SuppressionJavaPatchFilter", + exception.getMessage() + ); } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilterTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilterTest.java index 7dc1fa03..69983491 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilterTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionPatchFilterTest.java @@ -30,7 +30,7 @@ protected String getPatchFileLocation() { } @Override - protected String getPackageLocation() { + public String getPackageLocation() { return "com/puppycrawl/tools/checkstyle/filters/suppressionpatchfilter/"; } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/jgit/GitDiffOnOpenSourceTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/jgit/GitDiffOnOpenSourceTest.java index ee3190cb..f3f6a9f7 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/jgit/GitDiffOnOpenSourceTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/jgit/GitDiffOnOpenSourceTest.java @@ -36,7 +36,7 @@ public class GitDiffOnOpenSourceTest extends AbstractModuleTestSupport { @Override - protected String getPackageLocation() { + public String getPackageLocation() { return "com/puppycrawl/tools/checkstyle/filters/"; } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/Regexp/context/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/Regexp/context/expected.txt index de031c81..200cd42d 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/Regexp/context/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/Regexp/context/expected.txt @@ -1 +1 @@ -Test.java:0: Required pattern '// This code is copyrighted\n// \(c\) MyCompany' missing in file. \ No newline at end of file +Test.java:1: Required pattern '// This code is copyrighted\n// \(c\) MyCompany' missing in file. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/context/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/context/expected.txt index 4ba166b3..2357589c 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/context/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/context/expected.txt @@ -1 +1 @@ -Test.java:7:5: All overloaded methods should be placed next to each other. Placing non-overloaded methods in between overloaded methods with the same type is a violation. Previous overloaded method located at line '5'. \ No newline at end of file +Test.java:7:5: All overloaded methods should be placed next to each other. Previous overloaded method located at line '5'. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/newline/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/newline/expected.txt index 2b648be0..354d334e 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/newline/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/newline/expected.txt @@ -1 +1 @@ -Test.java:15:5: All overloaded methods should be placed next to each other. Placing non-overloaded methods in between overloaded methods with the same type is a violation. Previous overloaded method located at line '13'. \ No newline at end of file +Test.java:15:5: All overloaded methods should be placed next to each other. Previous overloaded method located at line '13'. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/patchedline/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/patchedline/expected.txt index 2b648be0..354d334e 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/patchedline/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/coding/OverloadMethodsDeclarationOrder/patchedline/expected.txt @@ -1 +1 @@ -Test.java:15:5: All overloaded methods should be placed next to each other. Placing non-overloaded methods in between overloaded methods with the same type is a violation. Previous overloaded method located at line '13'. \ No newline at end of file +Test.java:15:5: All overloaded methods should be placed next to each other. Previous overloaded method located at line '13'. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/context/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/context/expected.txt index e418bb8b..73b57d58 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/context/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/context/expected.txt @@ -1 +1 @@ -Test.java:7:

tag should be preceded with an empty line. \ No newline at end of file +Test.java:7:4:

tag should be preceded with an empty line. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/newline/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/newline/expected.txt index 5bebc583..77aad652 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/newline/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/newline/expected.txt @@ -1 +1 @@ -Test.java:8:

tag should be preceded with an empty line. \ No newline at end of file +Test.java:8:4:

tag should be preceded with an empty line. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/patchedline/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/patchedline/expected.txt index 5bebc583..77aad652 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/patchedline/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/JavadocParagraph/patchedline/expected.txt @@ -1 +1 @@ -Test.java:8:

tag should be preceded with an empty line. \ No newline at end of file +Test.java:8:4:

tag should be preceded with an empty line. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/context/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/context/expected.txt index 8b972476..4a6574c5 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/context/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/context/expected.txt @@ -1 +1 @@ -Test.java:4: Summary javadoc is missing. \ No newline at end of file +Test.java:4:8: Summary javadoc is missing. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/newline/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/newline/expected.txt index 532db954..157e2383 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/newline/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/newline/expected.txt @@ -1 +1 @@ -Test.java:9: Summary javadoc is missing. \ No newline at end of file +Test.java:9:8: Summary javadoc is missing. diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/patchedline/expected.txt b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/patchedline/expected.txt index 8b972476..4a6574c5 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/patchedline/expected.txt +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/filters/suppressionjavapatchfilter/javadoc/SummaryJavadocCheck/patchedline/expected.txt @@ -1 +1 @@ -Test.java:4: Summary javadoc is missing. \ No newline at end of file +Test.java:4:8: Summary javadoc is missing.