Skip to content

Commit 4bd5f49

Browse files
author
Vincent Potucek
committed
PoC: Add rewrite support for errorprone.refasterrules
1 parent fd9b551 commit 4bd5f49

File tree

127 files changed

+404
-112
lines changed

Some content is hidden

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

127 files changed

+404
-112
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,10 @@ runs:
6666
using: "composite"
6767
steps:
6868
- name: Run JUnit Tests (${{ inputs.test-task }})
69-
# Gradle flags
70-
# --build-cache: Let Gradle restore the build cache
71-
# --no-scan: Don't attempt to publish the scan yet. We want to archive it first.
72-
# --continue: Keep running even if a test fails
73-
# -PcommitId Prevent the Git SHA being written into the jar files (which breaks caching)
7469
shell: bash
7570
id: run-tests
7671
env:
77-
TIMEOUT_MINUTES: ${{ inputs.timeout-minutes}}
72+
TIMEOUT_MINUTES: ${{ inputs.timeout-minutes }}
7873
TEST_CATALOG: ${{ inputs.test-catalog-path }}
7974
TEST_TASK: ${{ inputs.test-task }}
8075
TEST_RETRIES: ${{ inputs.test-retries }}
@@ -86,7 +81,7 @@ runs:
8681
run: |
8782
set +e
8883
./.github/scripts/thread-dump.sh &
89-
timeout ${TIMEOUT_MINUTES}m ./gradlew --build-cache --continue --no-scan \
84+
timeout ${TIMEOUT_MINUTES}m ./gradlew $TEST_TASK --build-cache --continue --no-scan \
9085
-PtestLoggingEvents=started,passed,skipped,failed \
9186
-PmaxParallelForks=4 \
9287
-PmaxTestRetries=$TEST_RETRIES -PmaxTestRetryFailures=10 \
@@ -97,7 +92,6 @@ runs:
9792
-Pkafka.cluster.test.repeat=$TEST_REPEAT \
9893
-Pkafka.test.verbose=$TEST_VERBOSE \
9994
-PcommitId=xxxxxxxxxxxxxxxx \
100-
$TEST_TASK
10195
exitcode="$?"
10296
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
10397
- name: Archive build scan (${{ inputs.test-task }})

.github/workflows/build.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
uses: actions/checkout@v4
122122
with:
123123
persist-credentials: false
124-
ref: ${{ github.sha }} # this is the default, just being explicit.
124+
ref: ${{ github.sha }} # this is the default, just being explicit.
125125
- name: Setup Python
126126
uses: ./.github/actions/setup-python
127127
- name: Setup Gradle
@@ -134,13 +134,8 @@ jobs:
134134
- name: Compile and validate
135135
env:
136136
SCAN_ARG: ${{ inputs.is-public-fork && '--no-scan' || '--scan' }}
137-
# Gradle flags
138-
# --build-cache: Let Gradle restore the build cache
139-
# --info: For now, we'll generate lots of logs while setting up the GH Actions
140-
# --scan: Publish the build scan. This will only work on PRs from apache/kafka and trunk
141-
# --no-scan: For public fork PRs, we won't attempt to publish the scan
142137
run: |
143-
./gradlew --build-cache --info $SCAN_ARG check releaseTarGz -x test
138+
./gradlew check rewriteDryRun --build-cache --info $SCAN_ARG releaseTarGz
144139
- name: Archive check reports
145140
if: always()
146141
uses: actions/upload-artifact@v4

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,23 @@ 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.
208218
You can run spotbugs using:
209219

210-
./gradlew spotbugsMain spotbugsTest -x test
220+
./gradlew spotbugsMain spotbugsTest
211221

212222
The spotbugs warnings will be found in `reports/spotbugs/main.html` and `reports/spotbugs/test.html` files in the subproject build
213223
directories. Use -PxmlSpotBugsReport=true to generate an XML report instead of an HTML one.

build.gradle

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
import com.github.spotbugs.snom.SpotBugsTask
1617
import org.ajoberstar.grgit.Grgit
1718
import java.nio.charset.StandardCharsets
1819

@@ -29,20 +30,28 @@ buildscript {
2930
}
3031

3132
plugins {
32-
id 'com.github.ben-manes.versions' version '0.48.0'
33-
id 'idea'
34-
id 'jacoco'
35-
id 'java-library'
36-
id 'org.owasp.dependencycheck' version '8.2.1'
37-
id 'org.nosphere.apache.rat' version "0.8.1"
33+
// active
34+
id "com.github.ben-manes.versions" version "0.48.0"
35+
id "idea"
3836
id "io.swagger.core.v3.swagger-gradle-plugin" version "${swaggerVersion}"
37+
id "jacoco"
38+
id "java-library"
39+
id "org.nosphere.apache.rat" version "0.8.1"
40+
id "org.owasp.dependencycheck" version "8.2.1"
41+
// passive
42+
id "com.diffplug.spotless" version "7.2.1" apply false
43+
id "org.openrewrite.rewrite" version "7.12.1" apply false
3944

40-
id "com.github.spotbugs" version '6.0.25' apply false
41-
id 'org.scoverage' version '8.0.3' apply false
42-
id 'com.gradleup.shadow' version '8.3.6' apply false
43-
id 'com.diffplug.spotless' version "6.25.0"
45+
id "com.github.spotbugs" version "6.0.25" apply false
46+
id "com.gradleup.shadow" version "8.3.6" apply false
47+
id "org.scoverage" version "8.0.3" apply false
4448
}
4549

50+
apply from: "$rootDir/gradle/.qa/checkstyle.gradle"
51+
apply from: "$rootDir/gradle/.qa/rewrite.gradle"
52+
apply from: "$rootDir/gradle/.qa/spotbugs.gradle"
53+
apply from: "$rootDir/gradle/.qa/spotless.gradle"
54+
4655
ext {
4756
gradleVersion = versions.gradle
4857
minClientJavaVersion = 11
@@ -157,7 +166,7 @@ ext {
157166
libs.log4j2Api,
158167
libs.log4j2Core
159168
]
160-
169+
161170
}
162171

163172
allprojects {
@@ -312,8 +321,6 @@ subprojects {
312321
task allDepInsight(type: DependencyInsightReportTask) {showingAllVariants = false} doLast {}
313322

314323
apply plugin: 'java-library'
315-
apply plugin: 'checkstyle'
316-
apply plugin: "com.github.spotbugs"
317324

318325
// We use the shadow plugin for the jmh-benchmarks module and the `-all` jar can get pretty large, so
319326
// don't publish it
@@ -749,32 +756,7 @@ subprojects {
749756
}
750757
}
751758

752-
checkstyle {
753-
configDirectory = rootProject.layout.projectDirectory.dir("checkstyle")
754-
configProperties = checkstyleConfigProperties("import-control.xml")
755-
toolVersion = versions.checkstyle
756-
}
757-
758-
configure(checkstyleMain) {
759-
group = 'Verification'
760-
description = 'Run checkstyle on all main Java sources'
761-
}
762-
763-
configure(checkstyleTest) {
764-
group = 'Verification'
765-
description = 'Run checkstyle on all test Java sources'
766-
}
767-
768-
test.dependsOn('checkstyleMain', 'checkstyleTest')
769-
770-
spotbugs {
771-
toolVersion = versions.spotbugs
772-
excludeFilter = file("$rootDir/gradle/spotbugs-exclude.xml")
773-
ignoreFailures = false
774-
}
775-
test.dependsOn('spotbugsMain')
776-
777-
tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
759+
tasks.withType(SpotBugsTask).configureEach { // move to spotbugs.gradle
778760
reports.configure {
779761
// Continue supporting `xmlFindBugsReport` for compatibility
780762
xml.enabled(project.hasProperty('xmlSpotBugsReport') || project.hasProperty('xmlFindBugsReport'))
@@ -816,20 +798,6 @@ subprojects {
816798
skipProjects = [ ":jmh-benchmarks", ":trogdor" ]
817799
skipConfigurations = [ "zinc" ]
818800
}
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-
}
827-
}
828-
829-
gradle.taskGraph.whenReady { taskGraph ->
830-
taskGraph.getAllTasks().findAll { it.name.contains('spotbugsScoverage') || it.name.contains('spotbugsTest') }.each { task ->
831-
task.enabled = false
832-
}
833801
}
834802

835803
def fineTuneEclipseClasspathFile(eclipse, project) {
@@ -2812,14 +2780,6 @@ project(':streams:streams-scala') {
28122780
dependsOn 'copyDependantLibs'
28132781
}
28142782

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-
}
28232783
}
28242784

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

clients/src/main/java/org/apache/kafka/clients/ClusterConnectionStates.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ private void clearAddresses() {
555555
addresses = Collections.emptyList();
556556
}
557557

558+
@Override
558559
public String toString() {
559560
return "NodeConnectionState(" +
560561
"state=" + state + ", " +

clients/src/main/java/org/apache/kafka/clients/admin/AlterConfigsOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class AlterConfigsOptions extends AbstractOptions<AlterConfigsOptions> {
3232
*
3333
*/
3434
// This method is retained to keep binary compatibility with 0.11
35+
@Override
3536
public AlterConfigsOptions timeoutMs(Integer timeoutMs) {
3637
this.timeoutMs = timeoutMs;
3738
return this;

clients/src/main/java/org/apache/kafka/clients/admin/ConfigEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ public boolean equals(Object o) {
154154
Objects.equals(this.value, that.value) &&
155155
this.isSensitive == that.isSensitive &&
156156
this.isReadOnly == that.isReadOnly &&
157-
Objects.equals(this.source, that.source) &&
157+
this.source == that.source &&
158158
Objects.equals(this.synonyms, that.synonyms) &&
159-
Objects.equals(this.type, that.type) &&
159+
this.type == that.type &&
160160
Objects.equals(this.documentation, that.documentation);
161161
}
162162

clients/src/main/java/org/apache/kafka/clients/admin/CreateAclsOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class CreateAclsOptions extends AbstractOptions<CreateAclsOptions> {
3030
*
3131
*/
3232
// This method is retained to keep binary compatibility with 0.11
33+
@Override
3334
public CreateAclsOptions timeoutMs(Integer timeoutMs) {
3435
this.timeoutMs = timeoutMs;
3536
return this;

clients/src/main/java/org/apache/kafka/clients/admin/CreateTopicsOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class CreateTopicsOptions extends AbstractOptions<CreateTopicsOptions> {
3333
*
3434
*/
3535
// This method is retained to keep binary compatibility with 0.11
36+
@Override
3637
public CreateTopicsOptions timeoutMs(Integer timeoutMs) {
3738
this.timeoutMs = timeoutMs;
3839
return this;

clients/src/main/java/org/apache/kafka/clients/admin/DeleteAclsOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class DeleteAclsOptions extends AbstractOptions<DeleteAclsOptions> {
3030
*
3131
*/
3232
// This method is retained to keep binary compatibility with 0.11
33+
@Override
3334
public DeleteAclsOptions timeoutMs(Integer timeoutMs) {
3435
this.timeoutMs = timeoutMs;
3536
return this;

0 commit comments

Comments
 (0)