|
1 |
| -## Hacking on Serverless Workflow Java SDK in Gitpod |
| 1 | +# Contributing |
2 | 2 |
|
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. |
4 | 4 |
|
5 |
| -[](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, Make, Bash. |
| 10 | +2. **Clone** the repo and create a branch: `git checkout -b my-fix`. |
| 11 | +3. **Install the repo’s pre-commit hook:** `make hooks` (one-time). |
| 12 | +4. **Commit normally.** The pre-commit hook will auto-format Java files and **add license headers**, restage the changes, and let the commit proceed. |
| 13 | +5. **Before pushing:** `make check` to run Spotless + Checkstyle locally. |
| 14 | +6. **Open a PR** with a clear title and description. |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Project Conventions |
| 19 | + |
| 20 | +### Java, Maven, and modules |
| 21 | + |
| 22 | +* This is a **multi-module Maven** project. |
| 23 | +* **Java 17** is the baseline. |
| 24 | +* Build with `mvn -B verify` (CI runs with `-DskipTests` selectively when needed). |
| 25 | + |
| 26 | +### Formatting and License Headers |
| 27 | + |
| 28 | +We use **Spotless** (Maven) to: |
| 29 | + |
| 30 | +* Format Java with **google-java-format**. |
| 31 | +* Insert/normalize **license headers** from `config/license-header.txt`. |
| 32 | + |
| 33 | +> **Do not** hand-format files or hand-edit headers; let Spotless do it. The pre-commit hook runs `spotless:apply` for staged Java files. |
| 34 | +
|
| 35 | +Spotless is configured in the **parent POM** and resolves the header file using: |
| 36 | + |
| 37 | +``` |
| 38 | +${maven.multiModuleProjectDirectory}/config/license-header.txt |
| 39 | +``` |
| 40 | + |
| 41 | +so children modules pick up the root header correctly. |
| 42 | + |
| 43 | +### Checkstyle |
| 44 | + |
| 45 | +We keep **Checkstyle** to enforce additional rules. CI fails if formatting or style checks fail. |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## Developer Setup |
| 50 | + |
| 51 | +### Prerequisites |
| 52 | + |
| 53 | +* **JDK 17+** |
| 54 | +* **Maven 3.8+** |
| 55 | +* **Git**, **Make**, **Bash** |
| 56 | +* Optional IDE plugins: |
| 57 | + |
| 58 | + * IntelliJ: *Google Java Format* plugin (for local editing experience). Spotless remains the source of truth. |
| 59 | + |
| 60 | +### Install the Git Hooks (one-time) |
| 61 | + |
| 62 | +```bash |
| 63 | +make hooks |
| 64 | +``` |
| 65 | + |
| 66 | +This calls `scripts/install-git-hooks.sh` which sets `core.hooksPath` to `.githooks` and marks hooks executable. |
| 67 | + |
| 68 | +### Pre-commit Hook Behavior |
| 69 | + |
| 70 | +* Runs only on **staged** `*.java` files. |
| 71 | +* Temporarily stashes unstaged edits (to avoid committing them), runs Spotless, **re-stages** formatted files, then restores the stash. |
| 72 | +* If it reformats something, your commit still proceeds with the updated index. |
| 73 | + |
| 74 | +If something goes wrong: |
| 75 | + |
| 76 | +* Run `make format` to apply formatting to the whole repo. |
| 77 | +* Stage changes and commit again. |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## Make Targets |
| 82 | + |
| 83 | +Common tasks are wrapped in a Makefile: |
| 84 | + |
| 85 | +```text |
| 86 | +make hooks # Install/enable repo-local git hooks |
| 87 | +make format # Spotless apply (format + license headers) |
| 88 | +make check # Spotless check + Checkstyle check |
| 89 | +make verify # mvn verify (full build) |
| 90 | +make ci # CI checks (Spotless + Checkstyle, no tests) |
| 91 | +make clean # mvn clean |
| 92 | +``` |
| 93 | + |
| 94 | +> If `make` complains about a “missing separator”, ensure each command line under a target starts with a **TAB**. |
| 95 | +
|
| 96 | +--- |
| 97 | + |
| 98 | +## Testing |
| 99 | + |
| 100 | +* **Unit tests:** `mvn -q test` or `mvn verify`. |
| 101 | +* **Integration tests (if defined):** Use the dedicated Maven profile exposed by the module, e.g. `-Pintegration-tests`. |
| 102 | +* Prefer fast, deterministic tests. Avoid time-sensitive sleeps; use time abstractions or awaitility-style utilities. |
| 103 | + |
| 104 | +### Test Guidelines |
| 105 | + |
| 106 | +* Use clear, behavior-driven names: `methodName_shouldDoX_whenY`. |
| 107 | +* Keep one logical assertion per test (or one behavior per test). |
| 108 | +* Mock only external dependencies; don’t over-mock domain logic. |
| 109 | +* Make tests independent; no ordering assumptions. |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +## Commit & PR Guidelines |
| 114 | + |
| 115 | +### Branching |
| 116 | + |
| 117 | +* Use short, descriptive names: `fix/formatter`, `feat/http-call`, `docs/contributing`. |
| 118 | + |
| 119 | +### Commit messages |
| 120 | + |
| 121 | +* Keep messages clear and imperative: `Fix header resolution for child modules`. |
| 122 | +* Conventional Commits are welcome (`feat:`, `fix:`, `docs:`, `test:`, `refactor:`). Example: `feat: add A2A call task support`. |
| 123 | + |
| 124 | +### Pull Requests |
| 125 | + |
| 126 | +* Describe the **problem**, the **solution**, and any **trade-offs**. |
| 127 | +* Include before/after snippets or screenshots when relevant. |
| 128 | +* Link related issues. |
| 129 | +* Check the box: |
| 130 | + |
| 131 | + * [ ] `make check` passes locally |
| 132 | + * [ ] Unit/integration tests updated |
| 133 | + * [ ] Public API changes documented/Javadoc updated |
| 134 | + * [ ] No unrelated formatting churn (Spotless should keep this minimal) |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## Code Style & Design Notes |
| 139 | + |
| 140 | +* **Immutability first:** prefer `final` fields and defensive copies. |
| 141 | +* **Null-safety:** use `Objects.requireNonNull` at boundaries; consider `Optional` for truly optional returns (don’t use it for fields/params). |
| 142 | +* **Exceptions:** throw specific exceptions; include actionable messages; don’t swallow errors. |
| 143 | +* **Logging:** use SLF4J; no `System.out.println`; keep logs structured and at appropriate levels. |
| 144 | +* **APIs:** document with Javadoc; avoid breaking changes to public APIs unless necessary and called out in release notes. |
| 145 | +* **Generics & type-safety:** prefer precise types over `Object`; isolate unchecked casts. |
| 146 | +* **Performance:** avoid premature optimization; measure first; add micro-benchmarks (JMH) when optimizing hot paths. |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +## License Headers |
| 151 | + |
| 152 | +* Header template lives at: `config/license-header.txt` (root). |
| 153 | +* Spotless inserts or normalizes it automatically. |
| 154 | +* If the copyright line needs updates, edit the template and run `make format`. |
| 155 | + |
| 156 | +--- |
| 157 | + |
| 158 | +## CI |
| 159 | + |
| 160 | +* CI runs `spotless:check` and `checkstyle:check` to ensure consistent formatting and style. |
| 161 | +* Builds fail if formatting or headers drift. Run `make format` locally to fix. |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## Troubleshooting |
| 166 | + |
| 167 | +* **Hook didn’t run?** Did you run `make hooks` after cloning? Check `git config --get core.hooksPath` prints `.githooks`. |
| 168 | +* **Header file not found?** Ensure Spotless uses the root path via `${maven.multiModuleProjectDirectory}/config/license-header.txt`. |
| 169 | +* **Formatting conflicts with unstaged edits?** The hook stashes them. If a conflict occurs, complete the merge in your working copy, then `git add` and commit again. |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## Questions |
| 174 | + |
| 175 | +Open a discussion or issue on the repository. Thanks for contributing! 🎉 |
0 commit comments