diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0f6cea60a25b9..09a6b9d9dc0e7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -139,8 +139,9 @@ jobs: # --info: For now, we'll generate lots of logs while setting up the GH Actions # --scan: Publish the build scan. This will only work on PRs from apache/kafka and trunk # --no-scan: For public fork PRs, we won't attempt to publish the scan - run: | - ./gradlew --build-cache --info $SCAN_ARG check releaseTarGz -x test + run: ./gradlew --build-cache --info $SCAN_ARG check releaseTarGz -x test + - name: Sanity Check + run: ./gradlew --build-cache rewriteDryRun - name: Archive check reports if: always() uses: actions/upload-artifact@v4 diff --git a/README.md b/README.md index 49d1f9fd5cf50..98d0fee7c5344 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,16 @@ The import order is a part of static check. please call `spotlessApply` to optim ./gradlew spotlessApply +#### Rewrite +The build system incorporates [Moderne](https://moderne.io/) rewrite capabilities for automated code transformations. + +- **Convention** (e.g., JUnit's naming rules) +- **Refactor** safely (e.g., rename methods, migrate APIs) +- **Modernize** (e.g., Java 8 → Java 17 features) +- **Patterns** (e.g., replace `Vector` with `ArrayList`) + +`./gradlew rewriteDryRun` + #### Spotbugs #### Spotbugs uses static analysis to look for bugs in the code. You can run spotbugs using: diff --git a/build.gradle b/build.gradle index 5b6714f882294..e065b5a08c63d 100644 --- a/build.gradle +++ b/build.gradle @@ -39,10 +39,13 @@ plugins { id "com.github.spotbugs" version '6.4.4' apply false id 'org.scoverage' version '8.1' apply false + id 'org.openrewrite.rewrite' version '7.22.0' apply false id 'com.gradleup.shadow' version '8.3.9' apply false id 'com.diffplug.spotless' version "8.0.0" } +apply from: "$rootDir/gradle/rewrite.gradle" + ext { minClientJavaVersion = 11 minNonClientJavaVersion = 17 diff --git a/clients/src/main/java/org/apache/kafka/common/requests/ShareAcknowledgeResponse.java b/clients/src/main/java/org/apache/kafka/common/requests/ShareAcknowledgeResponse.java index 33dcc117f2bf3..3c64bb958e59b 100644 --- a/clients/src/main/java/org/apache/kafka/common/requests/ShareAcknowledgeResponse.java +++ b/clients/src/main/java/org/apache/kafka/common/requests/ShareAcknowledgeResponse.java @@ -88,12 +88,6 @@ public static ShareAcknowledgeResponse parse(Readable readable, short version) { ); } - private static boolean matchingTopic(ShareAcknowledgeResponseData.ShareAcknowledgeTopicResponse previousTopic, TopicIdPartition currentTopic) { - if (previousTopic == null) - return false; - return previousTopic.topicId().equals(currentTopic.topicId()); - } - public static ShareAcknowledgeResponseData.PartitionData partitionResponse(TopicIdPartition topicIdPartition, Errors error) { return partitionResponse(topicIdPartition.topicPartition().partition(), error); } diff --git a/config/sanity.yml b/config/sanity.yml new file mode 100644 index 0000000000000..d3bc8802dbe9a --- /dev/null +++ b/config/sanity.yml @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.apache.kafka.openrewrite.SanityCheck +displayName: Apply all common best practices +description: Comprehensive code quality recipe combining modernization, security, and best practices. +recipeList: + - org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods +# - org.openrewrite.staticanalysis.CommonStaticAnalysis # composition for -> NoDoubleBraceInitialization +# - org.openrewrite.staticanalysis.EqualsAvoidsNull +# - org.openrewrite.staticanalysis.InlineVariable +# - org.openrewrite.staticanalysis.NoDoubleBraceInitialization +# - tech.picnic.errorprone.refasterrules.EqualityRulesRecipes +# - tech.picnic.errorprone.refasterrules.NullRulesRecipes +# - tech.picnic.errorprone.refasterrules.StringRulesRecipes +# - tech.picnic.errorprone.refasterrules.TimeRulesRecipes +--- diff --git a/gradle/rewrite.gradle b/gradle/rewrite.gradle new file mode 100644 index 0000000000000..bad6664d7e3f1 --- /dev/null +++ b/gradle/rewrite.gradle @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply plugin: 'org.openrewrite.rewrite' + +dependencies { + rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.23.0') +} + +rewrite { + activeRecipe('org.apache.kafka.openrewrite.SanityCheck') + configFile = project.getRootProject().file("${rootDir}/config/sanity.yml") + setExportDatatables(true) + setFailOnDryRunResults(true) +}