This is an automated email from the ASF dual-hosted git repository. maciej pushed a commit to branch java-ci in repository https://gitbox.apache.org/repos/asf/iggy.git
commit e94fa6f4c10221eb3e2134199c4a583d577443f3 Author: Maciej Modzelewski <[email protected]> AuthorDate: Fri Jan 30 16:12:10 2026 +0100 feat(ci,java): add formatting verification for bdd and examples --- .github/actions/java-gradle/post-merge/action.yml | 1 - .github/actions/java-gradle/pre-merge/action.yml | 1 - .github/workflows/_test_bdd.yml | 19 ++++++++ .github/workflows/_test_examples.yml | 7 ++- bdd/java/build.gradle.kts | 13 ++++++ .../org/apache/iggy/bdd/BasicMessagingSteps.java | 50 +++++++++++----------- examples/java/build.gradle.kts | 7 +-- scripts/run-java-examples-from-readme.sh | 4 +- 8 files changed, 70 insertions(+), 32 deletions(-) diff --git a/.github/actions/java-gradle/post-merge/action.yml b/.github/actions/java-gradle/post-merge/action.yml index 9135ebbe6..a18e94673 100644 --- a/.github/actions/java-gradle/post-merge/action.yml +++ b/.github/actions/java-gradle/post-merge/action.yml @@ -35,7 +35,6 @@ runs: with: distribution: "temurin" java-version: "17" - cache: "gradle" - name: Setup Gradle uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 diff --git a/.github/actions/java-gradle/pre-merge/action.yml b/.github/actions/java-gradle/pre-merge/action.yml index b362a8729..079edc35f 100644 --- a/.github/actions/java-gradle/pre-merge/action.yml +++ b/.github/actions/java-gradle/pre-merge/action.yml @@ -31,7 +31,6 @@ runs: with: distribution: "temurin" java-version: "17" - cache: "gradle" - name: Setup Gradle uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 diff --git a/.github/workflows/_test_bdd.yml b/.github/workflows/_test_bdd.yml index dbba0b26d..cafbe0358 100644 --- a/.github/workflows/_test_bdd.yml +++ b/.github/workflows/_test_bdd.yml @@ -84,6 +84,25 @@ jobs: exit 1 fi + - name: Setup Java for BDD Java lint + if: inputs.task == 'bdd-java' + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" + + - name: Setup Gradle for BDD Java lint + if: inputs.task == 'bdd-java' + uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 + with: + gradle-version: "9.2.1" + + - name: Check Java BDD formatting (spotless) + if: inputs.task == 'bdd-java' + run: | + echo "Checking Java BDD formatting..." + cd bdd/java && gradle spotlessCheck + - name: Run BDD tests if: startsWith(inputs.component, 'bdd-') && startsWith(inputs.task, 'bdd-') run: | diff --git a/.github/workflows/_test_examples.yml b/.github/workflows/_test_examples.yml index 492239cf4..d62093636 100644 --- a/.github/workflows/_test_examples.yml +++ b/.github/workflows/_test_examples.yml @@ -79,7 +79,6 @@ jobs: with: distribution: "temurin" java-version: "17" - cache: "gradle" - name: Setup Gradle if: inputs.component == 'examples-suite' && inputs.task == 'examples-java' @@ -156,6 +155,12 @@ jobs: echo "Running Node.js examples tests..." ./scripts/run-node-examples-from-readme.sh + - name: Check Java formatting + if: inputs.component == 'examples-suite' && inputs.task == 'examples-java' + run: | + echo "Checking Java examples formatting..." + cd examples/java && gradle spotlessCheck + - name: Run Java examples if: inputs.component == 'examples-suite' && inputs.task == 'examples-java' run: | diff --git a/bdd/java/build.gradle.kts b/bdd/java/build.gradle.kts index 44a0f2572..78f09eda2 100644 --- a/bdd/java/build.gradle.kts +++ b/bdd/java/build.gradle.kts @@ -19,6 +19,7 @@ plugins { java + id("com.diffplug.spotless") version "8.1.0" } repositories { @@ -33,6 +34,18 @@ dependencies { testImplementation("org.junit.platform:junit-platform-suite:1.11.0") } +spotless { + java { + palantirJavaFormat() + endWithNewline() + trimTrailingWhitespace() + importOrder("", "\n", "javax|java", "\n", "\\#") + removeUnusedImports() + forbidWildcardImports() + formatAnnotations() + } +} + tasks.test { useJUnitPlatform() } diff --git a/bdd/java/src/test/java/org/apache/iggy/bdd/BasicMessagingSteps.java b/bdd/java/src/test/java/org/apache/iggy/bdd/BasicMessagingSteps.java index 334eeef29..0ad53dad0 100644 --- a/bdd/java/src/test/java/org/apache/iggy/bdd/BasicMessagingSteps.java +++ b/bdd/java/src/test/java/org/apache/iggy/bdd/BasicMessagingSteps.java @@ -54,10 +54,8 @@ public class BasicMessagingSteps { context.serverAddr = getenvOrDefault("IGGY_TCP_ADDRESS", "127.0.0.1:8090"); HostPort hostPort = HostPort.parse(context.serverAddr); - IggyTcpClient client = IggyTcpClient.builder() - .host(hostPort.host) - .port(hostPort.port) - .build(); + IggyTcpClient client = + IggyTcpClient.builder().host(hostPort.host).port(hostPort.port).build(); client.connect(); client.system().ping(); @@ -99,14 +97,16 @@ public class BasicMessagingSteps { @When("I create a topic with name {string} in stream {int} with {int} partitions") public void createTopic(String topicName, int streamId, int partitions) { - TopicDetails topic = getClient().topics().createTopic( - (long) streamId, - (long) partitions, - CompressionAlgorithm.None, - BigInteger.ZERO, - BigInteger.ZERO, - Optional.empty(), - topicName); + TopicDetails topic = getClient() + .topics() + .createTopic( + (long) streamId, + (long) partitions, + CompressionAlgorithm.None, + BigInteger.ZERO, + BigInteger.ZERO, + Optional.empty(), + topicName); context.lastTopicId = topic.id(); context.lastTopicName = topic.name(); @@ -136,11 +136,9 @@ public class BasicMessagingSteps { messages.add(Message.of(content)); } - getClient().messages().sendMessages( - (long) streamId, - (long) topicId, - Partitioning.partitionId((long) partitionId), - messages); + getClient() + .messages() + .sendMessages((long) streamId, (long) topicId, Partitioning.partitionId((long) partitionId), messages); if (!messages.isEmpty()) { context.lastSentMessage = "test message " + (messageCount - 1); @@ -154,14 +152,16 @@ public class BasicMessagingSteps { @When("I poll messages from stream {int}, topic {int}, partition {int} starting from offset {int}") public void pollMessages(int streamId, int topicId, int partitionId, int startOffset) { - context.lastPolledMessages = getClient().messages().pollMessages( - (long) streamId, - (long) topicId, - Optional.of((long) partitionId), - 0L, - PollingStrategy.offset(BigInteger.valueOf(startOffset)), - 100L, - true); + context.lastPolledMessages = getClient() + .messages() + .pollMessages( + (long) streamId, + (long) topicId, + Optional.of((long) partitionId), + 0L, + PollingStrategy.offset(BigInteger.valueOf(startOffset)), + 100L, + true); } @Then("I should receive {int} messages") diff --git a/examples/java/build.gradle.kts b/examples/java/build.gradle.kts index 86c563a46..6c37cea60 100644 --- a/examples/java/build.gradle.kts +++ b/examples/java/build.gradle.kts @@ -36,11 +36,12 @@ dependencies { spotless { java { palantirJavaFormat() - removeUnusedImports() - trimTrailingWhitespace() endWithNewline() - formatAnnotations() + trimTrailingWhitespace() importOrder("", "\n", "javax|java", "\n", "\\#") + removeUnusedImports() + forbidWildcardImports() + formatAnnotations() toggleOffOn() } } diff --git a/scripts/run-java-examples-from-readme.sh b/scripts/run-java-examples-from-readme.sh index 22a462f63..bd91d00e0 100755 --- a/scripts/run-java-examples-from-readme.sh +++ b/scripts/run-java-examples-from-readme.sh @@ -1,5 +1,6 @@ #!/bin/bash +# # 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 @@ -16,6 +17,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +# set -euo pipefail @@ -26,7 +28,7 @@ set -euo pipefail # If not provided, uses the default target # # This script scans examples/java/README.md for commands starting with -# `./gradlew` and executes them in order. If any command fails, the script +# `gradle` and executes them in order. If any command fails, the script # stops immediately and prints the relevant iggy-server logs. readonly LOG_FILE="iggy-server.log"
