Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Migrate to PMD 7 (#210)
Browse files Browse the repository at this point in the history
* Update Gradle up to 8.7

* Update dependencies

* Migrate to PMD 7
  • Loading branch information
mfvanek authored Apr 3, 2024
1 parent ee2ccaf commit b6f4c4c
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 49 deletions.
22 changes: 14 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ dependencies {
testImplementation("io.netty:netty-all:4.1.108.Final")
}

pitest(libs.pitest.dashboard.reporter)
pitest("it.mulders.stryker:pit-dashboard-reporter:0.2.1")
checkstyle("com.thomasjensen.checkstyle.addons:checkstyle-addons:7.0.1")

errorprone("com.google.errorprone:error_prone_core:2.26.1")
errorprone("jp.skypencil.errorprone.slf4j:errorprone-slf4j:0.1.23")

spotbugsSlf4j(rootProject.libs.slf4j.simple)
spotbugsSlf4j("org.slf4j:slf4j-simple:1.7.36") {
because("to be compatible with Spring Boot 2.7.x")
}
spotbugsPlugins("jp.skypencil.findbugs.slf4j:bug-pattern:1.5.0")
spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.13.0")
spotbugsPlugins("com.mebigfatguy.sb-contrib:sb-contrib:7.6.4")
Expand Down Expand Up @@ -104,12 +106,12 @@ tasks.withType<JavaCompile>().configureEach {
}

jacoco {
toolVersion = libs.versions.jacoco.get()
toolVersion = "0.8.12"
}

tasks {
wrapper {
gradleVersion = "8.5"
gradleVersion = "8.7"
}

test {
Expand Down Expand Up @@ -186,7 +188,7 @@ springBoot {
}

checkstyle {
toolVersion = libs.versions.checkstyle.get()
toolVersion = "10.15.0"
configFile = file("config/checkstyle/checkstyle.xml")
isIgnoreFailures = false
maxWarnings = 0
Expand All @@ -207,7 +209,7 @@ tasks.withType<SpotBugsTask>().configureEach {
}

pmd {
toolVersion = libs.versions.pmd.get()
toolVersion = "7.0.0"
isConsoleOutput = true
ruleSetFiles = files("config/pmd/pmd.xml")
ruleSets = listOf()
Expand All @@ -223,8 +225,8 @@ sonar {

pitest {
verbosity.set("DEFAULT")
junit5PluginVersion.set(libs.versions.pitest.junit5Plugin.get())
pitestVersion.set(libs.versions.pitest.core.get())
junit5PluginVersion.set("1.2.1")
pitestVersion.set("1.15.3")
threads.set(4)
if (System.getenv("STRYKER_DASHBOARD_API_KEY") != null) {
outputFormats.set(setOf("stryker-dashboard"))
Expand Down Expand Up @@ -259,3 +261,7 @@ tasks.named<DependencyUpdatesTask>("dependencyUpdates").configure {
isNonStable(candidate.version)
}
}

lombok {
version = "1.18.32"
}
20 changes: 9 additions & 11 deletions config/pmd/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

<rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod">
<properties>
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration['.*TestBase']"/>
<property name="violationSuppressXPath" value=".[@SimpleName = 'BasePgIndexHealthDemoSpringBootTest']"/>
</properties>
</rule>

<rule ref="category/java/bestpractices.xml/LooseCoupling">
<properties>
<property name="allowedTypes" value="org.springframework.http.HttpHeaders" />
</properties>
</rule>

Expand All @@ -40,7 +46,7 @@
<properties>
<property name="checkSetters" value="false"/>
<property name="violationSuppressXPath"
value="//ClassOrInterfaceBodyDeclaration/Annotation/MarkerAnnotation//Name[@Image='Test']"/>
value=".[pmd-java:hasAnnotation('org.junit.jupiter.api.Test')] | .[pmd-java:hasAnnotation('org.junit.jupiter.params.ParameterizedTest')]"/>
</properties>
</rule>

Expand All @@ -57,12 +63,6 @@
<exclude name="UseUtilityClass"/>
</rule>

<rule ref="category/java/design.xml/AbstractClassWithoutAnyMethod">
<properties>
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration['.*TestBase']"/>
</properties>
</rule>

<rule ref="category/java/documentation.xml">
<exclude name="CommentRequired"/>
<exclude name="CommentSize"/>
Expand All @@ -74,7 +74,5 @@

<rule ref="category/java/security.xml"/>

<rule ref="category/java/errorprone.xml">
<exclude name="DataflowAnomalyAnalysis"/>
</rule>
<rule ref="category/java/errorprone.xml"/>
</ruleset>
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
9 changes: 1 addition & 8 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@ dependencyResolutionManagement {
versionCatalogs {
create("libs") {
library("postgresql", "org.postgresql:postgresql:42.7.3")
version("checkstyle", "10.12.7")
version("pmd", "6.55.0")
version("jacoco", "0.8.11")
library("pitest-dashboard-reporter", "it.mulders.stryker:pit-dashboard-reporter:0.2.1")
version("pitest-junit5Plugin", "1.2.1")
version("pitest-core", "1.15.3")
val springdoc = version("springdoc", "1.7.0")
val springdoc = version("springdoc", "1.8.0")
library("springdoc-openapi-ui", "org.springdoc", "springdoc-openapi-ui")
.versionRef(springdoc)
library("springdoc-openapi-security", "org.springdoc", "springdoc-openapi-security")
.versionRef(springdoc)
library("slf4j-simple", "org.slf4j:slf4j-simple:1.7.36") // to be compatible with Spring Boot 2.7.X
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void actuatorShouldBeRunOnSeparatePort() {
void actuatorEndpointShouldReturnOk(@Nonnull final String endpointName,
@Nonnull final String expectedSubstring,
@Nonnull final String mediaType) {
final var result = actuatorClient.get()
final String result = actuatorClient.get()
.uri(uriBuilder -> uriBuilder
.path(endpointName)
.build())
Expand All @@ -64,7 +64,7 @@ void actuatorEndpointShouldReturnOk(@Nonnull final String endpointName,

@Test
void swaggerUiEndpointShouldReturnFound() {
final var result = actuatorClient.get()
final byte[] result = actuatorClient.get()
.uri(uriBuilder -> uriBuilder
.pathSegment("swagger-ui")
.build())
Expand All @@ -80,7 +80,7 @@ void swaggerUiEndpointShouldReturnFound() {

@Test
void readinessProbeShouldBeCollectedFromApplicationMainPort() {
final var result = webTestClient.get()
final String result = webTestClient.get()
.uri(uriBuilder -> uriBuilder
.pathSegment("readyz")
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DbConfigurationControllerTest extends BasePgIndexHealthDemoSpringBootTest

@Test
void getParamsWithDefaultValuesShouldReturnOk() {
final var result = webTestClient.get()
final PgParam[] result = webTestClient.get()
.uri(uriBuilder -> uriBuilder
.pathSegment("db", "configuration")
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DbHealthControllerTest extends BasePgIndexHealthDemoSpringBootTest {

@Test
void collectHealthDataShouldReturnOk() {
final var result = webTestClient.get()
final String[] result = webTestClient.get()
.uri(uriBuilder -> uriBuilder
.pathSegment("db", "health")
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DbStatisticsControllerMockTest extends BasePgIndexHealthDemoSpringBootTest
void shouldReturnErrorWhenResetStatisticsUnsuccessful(final boolean wait) {
Mockito.when(databaseManagement.resetStatistics())
.thenReturn(Boolean.FALSE);
final var result = webTestClient.post()
final Object result = webTestClient.post()
.uri(uriBuilder -> uriBuilder
.pathSegment("db", "statistics", "reset")
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class DbStatisticsControllerTest extends BasePgIndexHealthDemoSpringBootTest {

@Test
void getLastResetDateShouldNotReturnNull(@Nonnull final CapturedOutput output) {
final var startTestTimestamp = OffsetDateTime.now(clock);
final var result = webTestClient.get()
final OffsetDateTime startTestTimestamp = OffsetDateTime.now(clock);
final OffsetDateTime result = webTestClient.get()
.uri(uriBuilder -> uriBuilder
.pathSegment("db", "statistics", "reset")
.build())
Expand All @@ -45,7 +45,7 @@ void getLastResetDateShouldNotReturnNull(@Nonnull final CapturedOutput output) {
@Test
void doResetWithoutWaitShouldReturnAccepted(@Nonnull final CapturedOutput output) {
final long startTime = System.nanoTime();
final var result = webTestClient.post()
final OffsetDateTime result = webTestClient.post()
.uri(uriBuilder -> uriBuilder
.pathSegment("db", "statistics", "reset")
.build())
Expand All @@ -69,7 +69,7 @@ void doResetWithoutWaitShouldReturnAccepted(@Nonnull final CapturedOutput output
@Test
void doResetWithWaitShouldReturnOk(@Nonnull final CapturedOutput output) {
final long startTime = System.nanoTime();
final var result = webTestClient.post()
final OffsetDateTime result = webTestClient.post()
.uri(uriBuilder -> uriBuilder
.pathSegment("db", "statistics", "reset")
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DefaultControllerTest extends BasePgIndexHealthDemoSpringBootTest {

@Test
void rootPageShouldRedirectToSwaggerUi() {
final var result = webTestClient.get()
final byte[] result = webTestClient.get()
.uri("/")
.accept(MediaType.APPLICATION_JSON)
.exchange()
Expand Down

0 comments on commit b6f4c4c

Please sign in to comment.