Skip to content

Commit c6dba1b

Browse files
authored
chore: apply checkstyle to build-tools as well (#82)
* chore: apply checkstyle to build-tools as well * chore: fix checkstyle errors
1 parent 83c3fad commit c6dba1b

8 files changed

Lines changed: 105 additions & 41 deletions

File tree

pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
<pmd.version>7.15.0</pmd.version> <!-- pmd version used for tests -->
4343
<surefire.version>3.5.3</surefire.version>
4444
<junit.version>5.13.3</junit.version>
45+
<checkstyle.plugin.version>3.6.0</checkstyle.plugin.version>
46+
<checkstyle.version>10.26.1</checkstyle.version>
4547

4648
<central-publishing.waitMaxTime>10800</central-publishing.waitMaxTime> <!-- 10800s = 180min = 3h -->
4749
</properties>
@@ -198,6 +200,35 @@
198200
<artifactId>central-publishing-maven-plugin</artifactId>
199201
<version>0.8.0</version>
200202
</plugin>
203+
<plugin>
204+
<groupId>org.apache.maven.plugins</groupId>
205+
<artifactId>maven-checkstyle-plugin</artifactId>
206+
<version>${checkstyle.plugin.version}</version>
207+
<executions>
208+
<execution>
209+
<id>checkstyle-check</id>
210+
<phase>verify</phase>
211+
<goals>
212+
<goal>check</goal>
213+
</goals>
214+
</execution>
215+
</executions>
216+
<dependencies>
217+
<dependency>
218+
<groupId>com.puppycrawl.tools</groupId>
219+
<artifactId>checkstyle</artifactId>
220+
<version>${checkstyle.version}</version>
221+
</dependency>
222+
</dependencies>
223+
<configuration>
224+
<configLocation>${project.basedir}/src/main/resources/net/sourceforge/pmd/pmd-checkstyle-config.xml</configLocation>
225+
<suppressionsLocation>${project.basedir}/src/main/resources/net/sourceforge/pmd/pmd-checkstyle-suppressions.xml</suppressionsLocation>
226+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
227+
<excludeGeneratedSources>true</excludeGeneratedSources>
228+
<includes>**/*.java,**/*.kt</includes>
229+
<resourceIncludes>**/*.properties,**/*.less</resourceIncludes>
230+
</configuration>
231+
</plugin>
201232
</plugins>
202233
</pluginManagement>
203234
<plugins>
@@ -271,6 +302,11 @@
271302
</execution>
272303
</executions>
273304
</plugin>
305+
<plugin>
306+
<groupId>org.apache.maven.plugins</groupId>
307+
<artifactId>maven-checkstyle-plugin</artifactId>
308+
<!-- configuration is in plugin management section -->
309+
</plugin>
274310
<plugin>
275311
<groupId>org.sonatype.central</groupId>
276312
<artifactId>central-publishing-maven-plugin</artifactId>

src/main/java/net/sourceforge/pmd/buildtools/surefire/AccumulatingConsoleReporter.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AccumulatingConsoleReporter extends StatelessTestsetInfoConsoleReportEvent
2828

2929
private final boolean showSkippedTests;
3030

31-
public AccumulatingConsoleReporter(ConsoleLogger logger, boolean showSuccessfulTests, boolean showFailedTests, boolean showSkippedTests) {
31+
AccumulatingConsoleReporter(ConsoleLogger logger, boolean showSuccessfulTests, boolean showFailedTests, boolean showSkippedTests) {
3232
super(logger);
3333
this.showSuccessfulTests = showSuccessfulTests;
3434
this.showFailedTests = showFailedTests;
@@ -213,18 +213,20 @@ private static String getTestCaseName(WrappedReportEntry entry, String testSetNa
213213
private static void accumulateTestSetStats(TestSetStats accumulated, Collection<WrappedReportEntry> reportEntries) {
214214
for (WrappedReportEntry entry : reportEntries) {
215215
switch (entry.getReportEntryType()) {
216-
case SUCCESS:
217-
accumulated.testSucceeded(entry);
218-
break;
219-
case SKIPPED:
220-
accumulated.testSkipped(entry);
221-
break;
222-
case FAILURE:
223-
accumulated.testFailure(entry);
224-
break;
225-
case ERROR:
226-
accumulated.testError(entry);
227-
break;
216+
case SUCCESS:
217+
accumulated.testSucceeded(entry);
218+
break;
219+
case SKIPPED:
220+
accumulated.testSkipped(entry);
221+
break;
222+
case FAILURE:
223+
accumulated.testFailure(entry);
224+
break;
225+
case ERROR:
226+
accumulated.testError(entry);
227+
break;
228+
default:
229+
throw new IllegalStateException("Unknown report entry type: " + entry.getReportEntryType());
228230
}
229231
}
230232
}

src/main/java/net/sourceforge/pmd/buildtools/surefire/junit/JUnitPlatformProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
15
package net.sourceforge.pmd.buildtools.surefire.junit;
26

37
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;

src/main/java/net/sourceforge/pmd/buildtools/surefire/junit/RootContainer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
15
package net.sourceforge.pmd.buildtools.surefire.junit;
26

37
import org.junit.platform.engine.UniqueId;
@@ -7,7 +11,7 @@ class RootContainer {
711
private final TestIdentifier testIdentifier;
812
private boolean hasTests = false;
913

10-
public RootContainer(TestIdentifier testIdentifier) {
14+
RootContainer(TestIdentifier testIdentifier) {
1115
this.testIdentifier = testIdentifier;
1216
}
1317

src/main/java/net/sourceforge/pmd/buildtools/surefire/junit/TestExecutionListener.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
15
package net.sourceforge.pmd.buildtools.surefire.junit;
26

37
import java.lang.management.ManagementFactory;
@@ -30,7 +34,7 @@ class TestExecutionListener implements org.junit.platform.launcher.TestExecution
3034

3135
private final TestReportListener<TestOutputReportEntry> testReportListener;
3236

33-
public TestExecutionListener(TestReportListener<TestOutputReportEntry> testReportListener) {
37+
TestExecutionListener(TestReportListener<TestOutputReportEntry> testReportListener) {
3438
this.testReportListener = testReportListener;
3539
}
3640

@@ -90,19 +94,21 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
9094

9195
determineRootContainer(testIdentifier).ifPresent(RootContainer::markHasAtLeastOneTest);
9296
switch (testExecutionResult.getStatus()) {
93-
case SUCCESSFUL:
94-
testReportListener.testSucceeded(reportEntry);
95-
break;
96-
case FAILED:
97-
if (isAssertionError) {
98-
testReportListener.testFailed(reportEntry);
99-
} else {
100-
testReportListener.testError(reportEntry);
101-
}
102-
break;
103-
case ABORTED:
104-
testReportListener.testAssumptionFailure(reportEntry);
105-
break;
97+
case SUCCESSFUL:
98+
testReportListener.testSucceeded(reportEntry);
99+
break;
100+
case FAILED:
101+
if (isAssertionError) {
102+
testReportListener.testFailed(reportEntry);
103+
} else {
104+
testReportListener.testError(reportEntry);
105+
}
106+
break;
107+
case ABORTED:
108+
testReportListener.testAssumptionFailure(reportEntry);
109+
break;
110+
default:
111+
throw new IllegalStateException("Unknown execution result status: " + testExecutionResult.getStatus());
106112
}
107113
}
108114
}

src/test/java/net/sourceforge/pmd/buildtools/surefire/AccumulatingConsoleReporterTest.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class AccumulatingConsoleReporterTest {
2525

2626
private MockedConsoleLogger logger;
2727
private AccumulatingConsoleReporter reporter;
28+
2829
@BeforeEach
2930
void setup() {
3031
logger = new MockedConsoleLogger();
@@ -172,13 +173,13 @@ void junitSuiteReport() {
172173
reporter.testSetCompleted(testSuiteReport, EMPTY_STATS, EMPTY);
173174

174175
logger.assertInfo(
175-
"Running net.sourceforge.pmd.test.Suite" + NL +
176-
" Running net.sourceforge.pmd.test.Simple1" + NL +
177-
" └─ ✘ testFailMethod" + NL +
178-
" Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.122 s <<< FAILURE! -- in net.sourceforge.pmd.test.Simple1" + NL +
179-
" Running net.sourceforge.pmd.test.Simple2" + NL +
180-
" Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.124 s -- in net.sourceforge.pmd.test.Simple2" + NL +
181-
"Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.371 s <<< FAILURE! -- in net.sourceforge.pmd.test.Suite" + NL
176+
"Running net.sourceforge.pmd.test.Suite" + NL
177+
+ " Running net.sourceforge.pmd.test.Simple1" + NL
178+
+ " └─ ✘ testFailMethod" + NL
179+
+ " Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.122 s <<< FAILURE! -- in net.sourceforge.pmd.test.Simple1" + NL
180+
+ " Running net.sourceforge.pmd.test.Simple2" + NL
181+
+ " Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.124 s -- in net.sourceforge.pmd.test.Simple2" + NL
182+
+ "Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.371 s <<< FAILURE! -- in net.sourceforge.pmd.test.Suite" + NL
182183
);
183184
}
184185

@@ -192,8 +193,8 @@ void failForEmptyTestSet() {
192193
reporter.testSetCompleted(wrappedReportEntry, EMPTY_STATS, EMPTY);
193194

194195
logger.assertInfo(
195-
"Running net.sourceforge.pmd.test.Simple" + NL +
196-
"Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.123 s -- in net.sourceforge.pmd.test.Simple" + NL
196+
"Running net.sourceforge.pmd.test.Simple" + NL
197+
+ "Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.123 s -- in net.sourceforge.pmd.test.Simple" + NL
197198
);
198199
logger.assertError(
199200
"No tests were executed! Test class: net.sourceforge.pmd.test.Simple" + NL
@@ -203,12 +204,15 @@ void failForEmptyTestSet() {
203204
private SimpleReportEntry createTestSet(String className) {
204205
return createTestSet(className, null);
205206
}
207+
206208
private SimpleReportEntry createTestSet(String className, String sourceText) {
207209
return new SimpleReportEntry(RunMode.NORMAL_RUN, testRunId++, className, sourceText, null, null);
208210
}
211+
209212
private SimpleReportEntry createTestCase(SimpleReportEntry testSet, String methodName) {
210213
return new SimpleReportEntry(RunMode.NORMAL_RUN, testRunId++, testSet.getSourceName(), null, methodName, null);
211214
}
215+
212216
private SimpleReportEntry createTestCaseKotest(SimpleReportEntry testSet, String sourceText) {
213217
return new SimpleReportEntry(RunMode.NORMAL_RUN, testRunId++, testSet.getSourceName(), sourceText, null, null);
214218
}

src/test/java/net/sourceforge/pmd/buildtools/surefire/MockedConsoleLogger.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
15
package net.sourceforge.pmd.buildtools.surefire;
26

37
import static org.hamcrest.MatcherAssert.assertThat;

src/test/java/net/sourceforge/pmd/buildtools/surefire/junit/TestExecutionListenerTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
15
package net.sourceforge.pmd.buildtools.surefire.junit;
26

37
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -297,28 +301,28 @@ private static class MyTestDescriptor implements TestDescriptor {
297301
private final UniqueId uniqueId;
298302
private final TestSource source;
299303

300-
public MyTestDescriptor(String testClass) {
304+
MyTestDescriptor(String testClass) {
301305
this.testClass = testClass;
302306
this.type = Type.CONTAINER;
303307
this.uniqueId = UniqueId.forEngine("jupiter").append("class", testClass);
304308
this.source = ClassSource.from(testClass);
305309
}
306310

307-
public MyTestDescriptor(UniqueId uniqueId, String testClass) {
311+
MyTestDescriptor(UniqueId uniqueId, String testClass) {
308312
this.testClass = testClass;
309313
this.type = Type.CONTAINER;
310314
this.uniqueId = uniqueId;
311315
this.source = ClassSource.from(testClass);
312316
}
313317

314-
public MyTestDescriptor(String testClass, String testMethod) {
318+
MyTestDescriptor(String testClass, String testMethod) {
315319
this.testClass = testClass;
316320
this.type = Type.TEST;
317321
this.uniqueId = UniqueId.forEngine("jupiter").append("class", testClass).append("method", testMethod);
318322
this.source = MethodSource.from(testClass, testMethod);
319323
}
320324

321-
public MyTestDescriptor(String testClass, String[] testMethods, boolean isTest) {
325+
MyTestDescriptor(String testClass, String[] testMethods, boolean isTest) {
322326
this.testClass = testClass;
323327
this.type = isTest ? Type.TEST : Type.CONTAINER;
324328
UniqueId uniqueId = UniqueId.forEngine("jupiter").append("class", testClass);

0 commit comments

Comments
 (0)