Skip to content

Commit b33ddf8

Browse files
author
Vincent Potucek
committed
[rewrite] add org.junit.openrewrite.SanityCheck
- https://docs.openrewrite.org/recipes/java/testing/junit/jupiterbestpractices - https://docs.openrewrite.org/recipes/java/migrate/upgradetojava17 Signed-off-by: Vincent Potucek <vpotucek@me.com>
1 parent dbbacd6 commit b33ddf8

File tree

274 files changed

+856
-753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

274 files changed

+856
-753
lines changed

.github/workflows/sanity-check.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Sanity Check 🕊
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- 'releases/**'
7+
paths:
8+
- '.github/**'
9+
pull_request:
10+
paths:
11+
- '.github/**'
12+
permissions: {}
13+
jobs:
14+
validate:
15+
name: Validate 📊
16+
runs-on: ubuntu-latest
17+
permissions:
18+
security-events: write
19+
steps:
20+
- name: Checkout Repository 📥
21+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
22+
with:
23+
persist-credentials: false
24+
- name: Checkstyle ☑️
25+
uses: ./.github/actions/run-gradle
26+
with:
27+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
28+
arguments: checkstyleMain
29+
- name: Spotless ✨
30+
uses: ./.github/actions/run-gradle
31+
with:
32+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
33+
arguments: spotlessCheck
34+
- name: ArchUnit 🏛️
35+
uses: ./.github/actions/run-gradle
36+
with:
37+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
38+
arguments: archUnit
39+
- name: Verify OSGi 🧩
40+
uses: ./.github/actions/run-gradle
41+
with:
42+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
43+
arguments: verifyOSGiTask
44+
- name: Rewrite ⚙️
45+
uses: ./.github/actions/run-gradle
46+
with:
47+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
48+
arguments: rewriteDryRun -Dorg.gradle.jvmargs=-Xmx2G

documentation/src/main/java/example/domain/Person.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ public LocalDate getDateOfBirth() {
5454
public int hashCode() {
5555
final int prime = 31;
5656
int result = 1;
57-
result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
58-
result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
59-
return result;
57+
result = prime * result + (firstName == null ? 0 : firstName.hashCode());
58+
return prime * result + (lastName == null ? 0 : lastName.hashCode());
6059
}
6160

6261
@Override

documentation/src/main/java/example/util/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import org.jspecify.annotations.Nullable;
1616

17-
public class StringUtils {
17+
public final class StringUtils {
1818

1919
public static boolean isPalindrome(@Nullable String candidate) {
2020
int length = requireNonNull(candidate).length();

documentation/src/tools/java/org/junit/api/tools/ApiReportGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
/**
4747
* @since 1.0
4848
*/
49-
class ApiReportGenerator {
49+
final class ApiReportGenerator {
5050

5151
private static final Logger LOGGER = LoggerFactory.getLogger(ApiReportGenerator.class);
5252
private static final String EOL = System.lineSeparator();

gradle/config/rewrite.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
type: specs.openrewrite.org/v1beta/recipe
3+
name: org.junit.openrewrite.SanityCheck
4+
displayName: Apply all common best practices
5+
description: Comprehensive code quality recipe combining modernization, security, and best practices.
6+
recipeList:
7+
- org.openrewrite.java.migrate.UpgradeToJava17
8+
- org.openrewrite.java.testing.junit.JupiterBestPractices # consider; org.openrewrite.java.testing.cleanup.BestPractices
9+
- org.openrewrite.staticanalysis.EqualsAvoidsNull
10+
---

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ commonCustomUserData = { id = "com.gradle.common-custom-user-data-gradle-plugin"
101101
develocity = { id = "com.gradle.develocity", version = "4.2.2" }
102102
download = { id = "de.undercouch.download", version = "5.6.0" }
103103
errorProne = { id = "net.ltgt.errorprone", version = "4.3.0" }
104+
rewrite = { id = "org.openrewrite.rewrite", version = "7.21.0" }
104105
foojayResolver = { id = "org.gradle.toolchains.foojay-resolver", version = "1.0.0" }
105106
gitPublish = { id = "org.ajoberstar.git-publish", version = "5.1.3" }
106107
jmh = { id = "me.champeau.jmh", version = "0.7.3" }

gradle/plugins/common/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ plugins {
77

88
dependencies {
99
implementation("junitbuild.base:dsl-extensions")
10-
implementation(projects.buildParameters)
1110
implementation(projects.backwardCompatibility)
12-
implementation(libs.plugins.kotlin.markerCoordinates)
11+
implementation(projects.buildParameters)
1312
implementation(libs.plugins.bnd.markerCoordinates)
1413
implementation(libs.plugins.commonCustomUserData.markerCoordinates)
1514
implementation(libs.plugins.develocity.markerCoordinates)
1615
implementation(libs.plugins.errorProne.markerCoordinates)
1716
implementation(libs.plugins.foojayResolver.markerCoordinates)
1817
implementation(libs.plugins.jmh.markerCoordinates)
18+
implementation(libs.plugins.kotlin.markerCoordinates)
1919
implementation(libs.plugins.nullaway.markerCoordinates)
20+
implementation(libs.plugins.rewrite.markerCoordinates)
2021
implementation(libs.plugins.shadow.markerCoordinates)
2122
implementation(libs.plugins.spotless.markerCoordinates)
2223
}

gradle/plugins/common/src/main/kotlin/junitbuild.checkstyle-conventions.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ checkstyle {
2121
configDirectory = rootProject.layout.projectDirectory.dir("gradle/config/checkstyle")
2222
}
2323

24-
tasks.check {
25-
dependsOn(tasks.withType<Checkstyle>())
26-
}
24+
//tasks.check { // assuming spotless does the job already, checkstyle is first dedicated redundancy layer.
25+
// dependsOn(tasks.withType<Checkstyle>())
26+
//}

gradle/plugins/common/src/main/kotlin/junitbuild.java-errorprone-conventions.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ tasks.withType<JavaCompile>().configureEach {
4545
error(
4646
"CanonicalAnnotationSyntax",
4747
"IsInstanceLambdaUsage",
48+
"TryWithResourcesVariable",
4849
"PackageLocation",
4950
"RedundantStringConversion",
5051
"RedundantStringEscape",

gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99
id("junitbuild.eclipse-conventions")
1010
id("junitbuild.jacoco-java-conventions")
1111
id("junitbuild.java-errorprone-conventions")
12+
id("junitbuild.rewrite-conventions")
1213
}
1314

1415
val mavenizedProjects: List<Project> by rootProject.extra

0 commit comments

Comments
 (0)