Skip to content

Commit dd38a9f

Browse files
Use Spoteless for header checking and code-formatting (#721)
* Changing formatter plugin, add license check, add formatters githooks Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Add a meaningful CONTRIB.md Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Remove Makefile, make spotless format and add headers on mvn clean Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> --------- Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
1 parent 9890014 commit dd38a9f

File tree

14 files changed

+244
-87
lines changed

14 files changed

+244
-87
lines changed

.github/workflows/maven-verify.yml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,45 @@ name: sdk-java Verify
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [ main ]
76
pull_request:
8-
branches:
9-
- main
7+
branches: [ main ]
108

119
jobs:
12-
build:
10+
lint:
11+
name: Lint (Spotless + Checkstyle)
1312
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout sdk-java
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: 17
22+
cache: maven
23+
24+
- name: Spotless + Checkstyle (fail fast)
25+
run: mvn -B -DskipTests spotless:check checkstyle:check
1426

27+
build:
28+
name: Build & Verify
29+
needs: lint
30+
runs-on: ubuntu-latest
1531
steps:
16-
# 1. Checkout this repo
1732
- name: Checkout sdk-java
1833
uses: actions/checkout@v4
1934

20-
# 2. Set up JDK 17 for both builds
2135
- name: Set up JDK 17
2236
uses: actions/setup-java@v4
2337
with:
2438
distribution: temurin
2539
java-version: 17
26-
cache: 'maven'
40+
cache: maven
2741

28-
# 3. Verify the main sdk-java project, excluding the two agentic modules
29-
- name: Verify with Maven
42+
- name: Verify with Maven (core)
3043
run: |
31-
mvn -B -f pom.xml clean install verify -am
44+
mvn -B -f pom.xml clean verify
3245
33-
# 4. Verify examples
34-
- name: Verify Examples with Maven
35-
run: |
36-
mvn -B -f examples/pom.xml clean install verify
46+
# TODO: run examples once we fix the close issue

CONTRIBUTING.md

Lines changed: 132 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,134 @@
1-
## Hacking on Serverless Workflow Java SDK in Gitpod
1+
# Contributing
22

3-
If you have a web browser, you can get a fully pre-configured development environment in one click:
3+
Thanks for helping improve this project! This guide explains the local dev setup, the formatting/licensing workflow, testing, and how to propose changes.
44

5-
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/serverlessworkflow/sdk-java)
5+
---
6+
7+
## TL;DR (Fast path)
8+
9+
1. **Install prerequisites:** JDK 17+, Maven 3.8+, Git.
10+
2. **Clone** the repo and create a branch: `git checkout -b my-fix`.
11+
3. **Build locally:** run `mvn clean install` from the repo root. Spotless will **apply formatting and license headers** during the build.
12+
4. **Before pushing:** run `mvn -DskipTests spotless:check checkstyle:check`.
13+
5. **Open a PR** with a clear title and description.
14+
15+
---
16+
17+
## Project Conventions
18+
19+
### Java, Maven, and modules
20+
21+
* This is a **multi-module Maven** project.
22+
* **Java 17** is the baseline.
23+
* Build with `mvn -B verify` (CI runs with `-DskipTests` selectively when needed).
24+
25+
### Formatting and License Headers
26+
27+
We use **Spotless** (Maven) to:
28+
29+
* Format Java with **google-java-format**.
30+
* Insert/normalize **license headers** (the header content is defined **inline** in the parent POM’s `<licenseHeader>` configuration).
31+
32+
> **Do not** hand-format files or hand-edit headers; let Spotless do it. Running `mvn clean install` locally will mutate sources to match the standard.
33+
34+
### Checkstyle
35+
36+
We keep **Checkstyle** to enforce additional rules. CI fails if formatting or style checks fail.
37+
38+
---
39+
40+
## Developer Setup
41+
42+
### Prerequisites
43+
44+
* **JDK 17+**
45+
* **Maven 3.8+**
46+
* **Git**
47+
* Optional IDE plugins:
48+
49+
* IntelliJ: *Google Java Format* plugin (for local editing experience). Spotless remains the source of truth.
50+
51+
### Local build & formatting
52+
53+
* Run `mvn clean install` from the repo root. During the build, Spotless **applies** formatting and license headers.
54+
* Before pushing, run `mvn -DskipTests spotless:check checkstyle:check` to ensure CI will pass.
55+
56+
---
57+
58+
## Testing
59+
60+
* **Unit tests:** `mvn -q test` or `mvn verify`.
61+
* **Integration tests (if defined):** Use the dedicated Maven profile exposed by the module, e.g. `-Pintegration-tests`.
62+
* Prefer fast, deterministic tests. Avoid time-sensitive sleeps; use time abstractions or awaitility-style utilities.
63+
64+
### Test Guidelines
65+
66+
* Use clear, behavior-driven names: `methodName_shouldDoX_whenY`.
67+
* Keep one logical assertion per test (or one behavior per test).
68+
* Mock only external dependencies; don’t over-mock domain logic.
69+
* Make tests independent; no ordering assumptions.
70+
71+
---
72+
73+
## Commit & PR Guidelines
74+
75+
### Branching
76+
77+
* Use short, descriptive names: `fix/formatter`, `feat/http-call`, `docs/contributing`.
78+
79+
### Commit messages
80+
81+
* Keep messages clear and imperative: `Fix header resolution for child modules`.
82+
* Conventional Commits are welcome (`feat:`, `fix:`, `docs:`, `test:`, `refactor:`). Example: `feat: add A2A call task support`.
83+
84+
### Pull Requests
85+
86+
* Describe the **problem**, the **solution**, and any **trade-offs**.
87+
* Include before/after snippets or screenshots when relevant.
88+
* Link related issues.
89+
* Check the box:
90+
91+
* [ ] `mvn -DskipTests spotless:check checkstyle:check` passes locally
92+
* [ ] Unit/integration tests updated
93+
* [ ] Public API changes documented/Javadoc updated
94+
* [ ] No unrelated formatting churn (Spotless should keep this minimal)
95+
96+
---
97+
98+
## Code Style & Design Notes
99+
100+
* **Immutability first:** prefer `final` fields and defensive copies.
101+
* **Null-safety:** use `Objects.requireNonNull` at boundaries; consider `Optional` for truly optional returns (don’t use it for fields/params).
102+
* **Exceptions:** throw specific exceptions; include actionable messages; don’t swallow errors.
103+
* **Logging:** use SLF4J; no `System.out.println`; keep logs structured and at appropriate levels.
104+
* **APIs:** document with Javadoc; avoid breaking changes to public APIs unless necessary and called out in release notes.
105+
* **Generics & type-safety:** prefer precise types over `Object`; isolate unchecked casts.
106+
* **Performance:** avoid premature optimization; measure first; add micro-benchmarks (JMH) when optimizing hot paths.
107+
108+
---
109+
110+
## License Headers
111+
112+
* The license header is defined **inline** in the parent POM under Spotless’ `<licenseHeader>`.
113+
* To update it, edit the parent POM and run `mvn spotless:apply` to propagate changes.
114+
115+
---
116+
117+
## CI
118+
119+
* CI runs `spotless:check` and `checkstyle:check` to ensure consistent formatting and style.
120+
* Builds fail if formatting or headers drift. Run `mvn spotless:apply` locally to fix.
121+
122+
---
123+
124+
## Troubleshooting
125+
126+
* **Spotless changed files during build?** That’s expected locally. Review `git status`, then stage and commit the updates.
127+
* **CI red on formatting?** Run `mvn spotless:apply` locally, commit, and push.
128+
* **Running only a submodule?** Prefer `mvn -pl <module> -am …` from the repo root so parent config (Spotless/Checkstyle) is applied consistently.
129+
130+
---
131+
132+
## Questions
133+
134+
Open a discussion or issue on the repository. Thanks for contributing! 🎉

examples/events/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
</parent>
99
<name>Serverless Workflow :: Examples :: Events</name>
1010
<artifactId>serverlessworkflow-examples-events</artifactId>
11+
12+
<properties>
13+
<mainClass>events.EventExample</mainClass>
14+
</properties>
15+
16+
1117
<dependencies>
1218
<dependency>
1319
<groupId>io.serverlessworkflow</groupId>
@@ -18,4 +24,12 @@
1824
<artifactId>slf4j-simple</artifactId>
1925
</dependency>
2026
</dependencies>
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.codehaus.mojo</groupId>
31+
<artifactId>exec-maven-plugin</artifactId>
32+
</plugin>
33+
</plugins>
34+
</build>
2135
</project>

examples/simpleGet/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
</parent>
99
<artifactId>serverlessworkflow-examples-simpleGet</artifactId>
1010
<name>Serverless Workflow :: Examples :: SimpleGet</name>
11+
12+
<properties>
13+
<mainClass>io.serverlessworkflow.impl.BlockingExample</mainClass>
14+
</properties>
15+
1116
<dependencies>
1217
<dependency>
1318
<groupId>io.serverlessworkflow</groupId>
@@ -30,4 +35,15 @@
3035
<artifactId>slf4j-simple</artifactId>
3136
</dependency>
3237
</dependencies>
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.codehaus.mojo</groupId>
42+
<artifactId>exec-maven-plugin</artifactId>
43+
<configuration>
44+
<mainClass>${mainClass}</mainClass>
45+
</configuration>
46+
</plugin>
47+
</plugins>
48+
</build>
3349
</project>

experimental/lambda/src/main/java/io/serverlessworkflow/impl/executors/func/JavaForExecutorBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package io.serverlessworkflow.impl.executors.func;
1817

1918
import static io.serverlessworkflow.impl.executors.func.JavaFuncUtils.safeObject;

experimental/lambda/src/main/java/io/serverlessworkflow/impl/executors/func/JavaListenExecutorBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package io.serverlessworkflow.impl.executors.func;
1817

1918
import static io.serverlessworkflow.impl.executors.func.JavaFuncUtils.predObject;

experimental/lambda/src/main/java/io/serverlessworkflow/impl/executors/func/JavaSwitchExecutorBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package io.serverlessworkflow.impl.executors.func;
1817

1918
import static io.serverlessworkflow.impl.executors.func.JavaFuncUtils.predObject;

fluent/agentic/src/test/java/io/serverlessworkflow/fluent/agentic/WorkflowTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package io.serverlessworkflow.fluent.agentic;
1817

1918
import static io.serverlessworkflow.fluent.agentic.Agents.*;

generators/types/pom.xml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,4 @@
1919
</dependency>
2020

2121
</dependencies>
22-
<build>
23-
<plugins>
24-
<plugin>
25-
<groupId>com.spotify.fmt</groupId>
26-
<artifactId>fmt-maven-plugin</artifactId>
27-
<configuration>
28-
<sourceDirectory>src/main/java</sourceDirectory>
29-
<testSourceDirectory>src/test/java</testSourceDirectory>
30-
<verbose>false</verbose>
31-
<filesNamePattern>.*\.java</filesNamePattern>
32-
<skip>false</skip>
33-
<skipSortingImports>false</skipSortingImports>
34-
<style>google</style>
35-
</configuration>
36-
<executions>
37-
<execution>
38-
<goals>
39-
<goal>format</goal>
40-
</goals>
41-
</execution>
42-
</executions>
43-
</plugin>
44-
</plugins>
45-
</build>
4622
</project>

impl/core/src/main/java/io/serverlessworkflow/impl/events/TypeEventRegistration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package io.serverlessworkflow.impl.events;
1817

1918
import io.cloudevents.CloudEvent;

0 commit comments

Comments
 (0)