This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git
commit 8df89485dee0352d3c3b1a8b08587e686629f40d Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Tue Nov 17 05:45:29 2026 +0000 Simplify redundant code --- .../org/apache/maven/plugins/checkstyle/CheckstyleReport.java | 2 +- .../maven/plugins/checkstyle/CheckstyleReportRenderer.java | 10 +++++----- .../maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java | 8 ++++---- .../plugins/checkstyle/exec/DefaultCheckstyleExecutor.java | 2 +- .../java/org/apache/maven/plugins/checkstyle/RuleUtilTest.java | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java index 48b118d..ff1997b 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java @@ -125,7 +125,7 @@ public class CheckstyleReport extends AbstractCheckstyleReport { } } - return ((includeResources && hasResources(resources)) || (includeTestResources && hasResources(testResources))); + return (includeResources && hasResources(resources)) || (includeTestResources && hasResources(testResources)); } /** diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportRenderer.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportRenderer.java index 1149a2e..487ed6d 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportRenderer.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportRenderer.java @@ -422,7 +422,7 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer { // Sort the files before writing them to the report List<String> fileList = new ArrayList<>(results.getFiles().keySet()); - Collections.sort(fileList); + fileList.sort(null); for (String filename : fileList) { List<AuditEvent> violations = results.getFileViolations(filename); @@ -464,7 +464,7 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer { // Sort the files before writing their details to the report List<String> fileList = new ArrayList<>(results.getFiles().keySet()); - Collections.sort(fileList); + fileList.sort(null); for (String file : fileList) { List<AuditEvent> violations = results.getFileViolations(file); @@ -593,7 +593,7 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer { private String getCheckstyleVersion() { Package checkstyleApiPackage = Configuration.class.getPackage(); - return (checkstyleApiPackage == null) ? null : checkstyleApiPackage.getImplementationVersion(); + return checkstyleApiPackage == null ? null : checkstyleApiPackage.getImplementationVersion(); } private List<ConfReference> sortConfiguration(CheckstyleResults results) { @@ -601,7 +601,7 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer { sortConfiguration(result, checkstyleConfig, null, results); - Collections.sort(result); + result.sort(null); return result; } @@ -672,7 +672,7 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer { if (compare == 0) { compare = configuration.getName().compareTo(o.configuration.getName()); } - return (compare == 0) ? (o.count - count) : compare; + return compare == 0 ? (o.count - count) : compare; } } diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java index ce6978f..6f4549e 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java @@ -593,7 +593,7 @@ public class CheckstyleViolationCheckMojo extends AbstractMojo { printViolations(violationsList); String msg = "You have " + violationCount + " Checkstyle violation" - + ((violationCount > 1 || violationCount == 0) ? "s" : "") + "."; + + (violationCount > 1 || violationCount == 0 ? "s" : "") + "."; if (violationCount > maxAllowedViolations) { if (failOnViolation) { @@ -683,8 +683,8 @@ public class CheckstyleViolationCheckMojo extends AbstractMojo { } if (ignored > 0) { - getLog().info("Ignored " + ignored + " error" + ((ignored > 1L) ? "s" : "") + ", " + countedViolations - + " violation" + ((countedViolations > 1) ? "s" : "") + " remaining."); + getLog().info("Ignored " + ignored + " error" + (ignored > 1L ? "s" : "") + ", " + countedViolations + + " violation" + (countedViolations > 1 ? "s" : "") + " remaining."); } return countedViolations; @@ -706,7 +706,7 @@ public class CheckstyleViolationCheckMojo extends AbstractMojo { "%s:[%s%s] (%s) %s: %s", violation.getFile(), violation.getLine(), - (Violation.NO_COLUMN.equals(violation.getColumn())) ? "" : (',' + violation.getColumn()), + Violation.NO_COLUMN.equals(violation.getColumn()) ? "" : (',' + violation.getColumn()), violation.getCategory(), violation.getRuleName(), violation.getMessage()); diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java index 4353ecb..08f28f5 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java @@ -363,7 +363,7 @@ public class DefaultCheckstyleExecutor implements CheckstyleExecutor { private String getCheckstyleVersion() { Package checkstyleApiPackage = Configuration.class.getPackage(); - return (checkstyleApiPackage == null) ? null : checkstyleApiPackage.getImplementationVersion(); + return checkstyleApiPackage == null ? null : checkstyleApiPackage.getImplementationVersion(); } private Properties getOverridingProperties(CheckstyleExecutorRequest request) throws CheckstyleExecutorException { diff --git a/src/test/java/org/apache/maven/plugins/checkstyle/RuleUtilTest.java b/src/test/java/org/apache/maven/plugins/checkstyle/RuleUtilTest.java index 2753883..d083f05 100644 --- a/src/test/java/org/apache/maven/plugins/checkstyle/RuleUtilTest.java +++ b/src/test/java/org/apache/maven/plugins/checkstyle/RuleUtilTest.java @@ -66,14 +66,14 @@ public class RuleUtilTest { assertEquals( i == j, matcher.match(eventSrcName), - spec + " should" + ((i == j) ? " " : " not ") + "match " + eventSrcName); + spec + " should" + (i == j ? " " : " not ") + "match " + eventSrcName); } } } @Test public void testMatcherWithBlankStrings() { - String[] specs = (" ,,foo, ").split(","); + String[] specs = " ,,foo, ".split(","); List<RuleUtil.Matcher> matchers = RuleUtil.parseMatchers(specs);
