Skip to content

Commit 9222db1

Browse files
author
Vincent Potucek
committed
Add rewrite support for errorprone.refasterrules.FileRulesRecipes
1 parent fba01c4 commit 9222db1

File tree

4 files changed

+92
-24
lines changed

4 files changed

+92
-24
lines changed

.github/actions/run-gradle/action.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ runs:
7474
shell: bash
7575
id: run-tests
7676
env:
77-
TIMEOUT_MINUTES: ${{ inputs.timeout-minutes}}
77+
TIMEOUT_MINUTES: ${{ inputs.timeout-minutes }}
7878
TEST_CATALOG: ${{ inputs.test-catalog-path }}
7979
TEST_TASK: ${{ inputs.test-task }}
8080
TEST_RETRIES: ${{ inputs.test-retries }}
@@ -86,7 +86,7 @@ runs:
8686
run: |
8787
set +e
8888
./.github/scripts/thread-dump.sh &
89-
timeout ${TIMEOUT_MINUTES}m ./gradlew --build-cache --continue --no-scan \
89+
timeout ${TIMEOUT_MINUTES}m ./gradlew $TEST_TASK --build-cache --continue --no-scan \
9090
-PtestLoggingEvents=started,passed,skipped,failed \
9191
-PmaxParallelForks=4 \
9292
-PmaxTestRetries=$TEST_RETRIES -PmaxTestRetryFailures=10 \
@@ -97,7 +97,6 @@ runs:
9797
-Pkafka.cluster.test.repeat=$TEST_REPEAT \
9898
-Pkafka.test.verbose=$TEST_VERBOSE \
9999
-PcommitId=xxxxxxxxxxxxxxxx \
100-
$TEST_TASK
101100
exitcode="$?"
102101
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
103102
- name: Archive build scan (${{ inputs.test-task }})
@@ -108,3 +107,27 @@ runs:
108107
path: ~/.gradle/build-scan-data
109108
compression-level: 9
110109
if-no-files-found: ignore
110+
- name: Run spotlessCheck (${{ inputs.test-task }})
111+
shell: bash
112+
id: run-spotlessCheck
113+
env:
114+
TIMEOUT_MINUTES: ${{ inputs.timeout-minutes }}
115+
run: |
116+
set +e
117+
./.github/scripts/thread-dump.sh &
118+
timeout ${TIMEOUT_MINUTES}m ./gradlew spotlessCheck --build-cache --continue --no-scan \
119+
-PmaxParallelForks=4 \
120+
exitcode="$?"
121+
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
122+
- name: Run rewriteDryRun (${{ inputs.test-task }})
123+
shell: bash
124+
id: run-rewriteDryRun
125+
env:
126+
TIMEOUT_MINUTES: ${{ inputs.timeout-minutes }}
127+
run: |
128+
set +e
129+
./.github/scripts/thread-dump.sh &
130+
timeout ${TIMEOUT_MINUTES}m ./gradlew rewriteDryRun --build-cache --continue --no-scan \
131+
-PmaxParallelForks=4 \
132+
exitcode="$?"
133+
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ jobs:
220220
uses: ./.github/actions/run-gradle
221221
with:
222222
test-task: test
223-
timeout-minutes: 180 # 3 hours
223+
timeout-minutes: 240 # 4 H (test & spotless & rewrite)
224224
test-catalog-path: ${{ steps.load-test-catalog.outputs.download-path }}/combined-test-catalog.txt
225225
build-scan-artifact-name: build-scan-${{ env.job-variation }}
226226
run-new-tests: ${{ matrix.run-new }}

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,17 @@ For experiments (or regression testing purposes) add `-PcheckstyleVersion=X.y.z`
201201
#### Spotless ####
202202
The import order is a part of static check. please call `spotlessApply` to optimize the imports of Java codes before filing pull request.
203203

204-
./gradlew spotlessApply
204+
`./gradlew spotlessApply`
205+
206+
#### Rewrite
207+
The build system incorporates [Moderne](https://moderne.io/) rewrite capabilities for automated code transformations.
208+
209+
- **Convention** (e.g., JUnit's naming rules)
210+
- **Refactor** safely (e.g., rename methods, migrate APIs)
211+
- **Modernize** (e.g., Java 8 → Java 17 features)
212+
- **Patterns** (e.g., replace `Vector` with `ArrayList`)
213+
214+
`./gradlew rewriteRun`
205215

206216
#### Spotbugs ####
207217
Spotbugs uses static analysis to look for bugs in the code.

build.gradle

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,58 @@ plugins {
4141
id 'org.scoverage' version '8.0.3' apply false
4242
id 'com.gradleup.shadow' version '8.3.6' apply false
4343
id 'com.diffplug.spotless' version "6.25.0"
44+
id "org.openrewrite.rewrite" version "7.12.1"
45+
}
46+
47+
spotless {
48+
java {
49+
targetExclude('**/generated/**/*.java','**/generated-test/**/*.java')
50+
importOrder('kafka', 'org.apache.kafka', 'com', 'net', 'org', 'java', 'javax', '', '\\#')
51+
//licenseHeaderFile("$rootDir/checkstyle/java.header", 'package') todo apply me
52+
}
53+
scala {
54+
scalafmt("$versions.scalafmt").configFile("$rootDir/checkstyle/.scalafmt.conf").scalaMajorVersion(versions.baseScala)
55+
//licenseHeaderFile("$rootDir/checkstyle/java.header", 'package') todo apply me
56+
}
57+
}
58+
59+
rewrite {
60+
activeRecipe(
61+
"org.openrewrite.java.RemoveUnusedImports",
62+
"org.openrewrite.staticanalysis.NoFinalizer",
63+
"org.openrewrite.staticanalysis.RemoveUnusedLocalVariables",
64+
"org.openrewrite.staticanalysis.RemoveUnusedPrivateFields",
65+
"tech.picnic.errorprone.refasterrules.FileRulesRecipes",
66+
//"org.openrewrite.gradle.GradleBestPractices",
67+
//"org.openrewrite.java.format.RemoveTrailingWhitespace",
68+
//"org.openrewrite.java.migrate.UpgradeToJava17",
69+
//"org.openrewrite.java.recipes.JavaRecipeBestPractices",
70+
//"org.openrewrite.java.recipes.RecipeNullabilityBestPractices",
71+
//"org.openrewrite.java.recipes.RecipeTestingBestPractices",
72+
//"org.openrewrite.staticanalysis.CodeCleanup",
73+
//"org.openrewrite.staticanalysis.EqualsAvoidsNull",
74+
//"org.openrewrite.staticanalysis.JavaApiBestPractices",
75+
//"org.openrewrite.staticanalysis.MissingOverrideAnnotation",
76+
//"org.openrewrite.staticanalysis.ModifierOrder",
77+
//"org.openrewrite.staticanalysis.RemoveCallsToSystemGc",
78+
//"org.openrewrite.staticanalysis.RemoveUnneededAssertion",
79+
//"org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods",
80+
//"org.openrewrite.staticanalysis.StringLiteralEquality",
81+
//"org.openrewrite.staticanalysis.UnnecessaryParentheses",
82+
//"org.openrewrite.staticanalysis.UnnecessaryThrows",
83+
//"org.openrewrite.text.EndOfLineAtEndOfFile",
84+
//"tech.picnic.errorprone.refasterrules.CollectionRulesRecipes",
85+
//"tech.picnic.errorprone.refasterrules.NullRulesRecipes",
86+
//"tech.picnic.errorprone.refasterrules.StreamRulesRecipes",
87+
//"tech.picnic.errorprone.refasterrules.StringRulesRecipes",
88+
)
89+
exportDatatables = true
90+
exclusions.add("**.GarbageCollectedMemoryPoolTest.java")
91+
failOnDryRunResults = true
92+
}
93+
94+
dependencies {
95+
rewrite("org.openrewrite.recipe:rewrite-third-party:0.24.3", "org.openrewrite.recipe:rewrite-static-analysis:2.13.0")
4496
}
4597

4698
ext {
@@ -157,7 +209,7 @@ ext {
157209
libs.log4j2Api,
158210
libs.log4j2Core
159211
]
160-
212+
161213
}
162214

163215
allprojects {
@@ -551,7 +603,7 @@ subprojects {
551603
maxFailures = userMaxTestRetryFailures
552604
}
553605
}
554-
606+
555607
finalizedBy("copyTestXml")
556608
}
557609

@@ -816,14 +868,6 @@ subprojects {
816868
skipProjects = [ ":jmh-benchmarks", ":trogdor" ]
817869
skipConfigurations = [ "zinc" ]
818870
}
819-
apply plugin: 'com.diffplug.spotless'
820-
spotless {
821-
java {
822-
targetExclude('**/generated/**/*.java','**/generated-test/**/*.java')
823-
importOrder('kafka', 'org.apache.kafka', 'com', 'net', 'org', 'java', 'javax', '', '\\#')
824-
removeUnusedImports()
825-
}
826-
}
827871
}
828872

829873
gradle.taskGraph.whenReady { taskGraph ->
@@ -2811,15 +2855,6 @@ project(':streams:streams-scala') {
28112855
jar {
28122856
dependsOn 'copyDependantLibs'
28132857
}
2814-
2815-
apply plugin: 'com.diffplug.spotless'
2816-
spotless {
2817-
scala {
2818-
target '**/*.scala'
2819-
scalafmt("$versions.scalafmt").configFile('../../checkstyle/.scalafmt.conf').scalaMajorVersion(versions.baseScala)
2820-
licenseHeaderFile '../../checkstyle/java.header', 'package'
2821-
}
2822-
}
28232858
}
28242859

28252860
project(':streams:integration-tests') {

0 commit comments

Comments
 (0)