Skip to content

Commit d4f8cc7

Browse files
authored
docs: add CLAUDE.md documenting project structure and tests (#65)
Documents the plugin's internal structure, what each unit test in RequirementsToolTaskTest validates, and how the test fixtures (src/test/resources and tests/fixtures/test_project) relate to the code, including how to manually validate/regenerate expected output. Closes #57 Signed-off-by: Jimisola Laursen <jimisola@jimisola.com>
1 parent 2093941 commit d4f8cc7

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

‎CLAUDE.md‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# CLAUDE.md
2+
3+
This file orients contributors and AI agents working in this repository.
4+
5+
## What this project is
6+
7+
A Gradle plugin (`io.github.reqstool.gradle-plugin`) for
8+
[reqstool](https://github.com/reqstool/reqstool-client). It collects `@Requirements` and
9+
`@SVCs` annotations emitted by the reqstool annotation processor during compilation,
10+
combines them with a dataset (`requirements.yml`, etc.) and test result XML files, and
11+
packages everything into a `<name>-<version>-reqstool.zip` artifact that the reqstool CLI
12+
can analyze. Requires Java 21+.
13+
14+
See `README.md` for the user-facing configuration reference (extension properties, task
15+
behavior, JUnit 5 parameterized test setup) and `CONTRIBUTING.md` for setup/DCO/commit
16+
conventions. This file focuses on internal structure, tests, and fixtures.
17+
18+
## Project structure
19+
20+
```
21+
src/main/java/io/github/reqstool/gradle/
22+
RequirementsToolPlugin.java # registers the assembleRequirements task, wires
23+
# compileJava/build dependencies, configures publishing
24+
RequirementsToolTask.java # core logic: combine/merge annotation YAML, assemble zip
25+
RequirementsToolExtension.java # DSL + zero-config defaults
26+
27+
src/test/java/io/github/reqstool/gradle/
28+
RequirementsToolTaskTest.java # unit tests (see below)
29+
30+
src/test/resources/{yml,zip}/ # tracked reference fixtures (see "Fixtures" below)
31+
32+
tests/fixtures/test_project/ # standalone Gradle project for manual end-to-end validation
33+
34+
docs/modules/ROOT/ # Antora documentation source (published to reqstool.github.io)
35+
```
36+
37+
The main task is `assembleRequirements` (group `build`). When the `java` plugin is applied,
38+
the plugin auto-wires it to depend on `compileJava` and every non-main source set's compile
39+
task, and makes `build` finalized by `assembleRequirements`.
40+
41+
## Running tests
42+
43+
```bash
44+
./gradlew test # unit tests only
45+
./gradlew build # compile, test, assemble plugin jar
46+
./gradlew format # apply io.spring.javaformat formatting
47+
```
48+
49+
## Unit tests — `RequirementsToolTaskTest`
50+
51+
Uses `ProjectBuilder` with a `@TempDir` project directory and builds YAML in-memory via
52+
Jackson (`ObjectMapper` + `YAMLFactory`) — it does **not** read from `src/test/resources`.
53+
54+
| Test | Validates |
55+
|---|---|
56+
| `testCombineOutput_bothEmpty` / `_withImplementations` / `_withTests` / `_withBoth` | `combineOutput()` produces a `requirement_annotations` node with `implementations`/`tests` keys present only when non-empty |
57+
| `testTaskConfiguration` | Extension defaults (`outputDirectory`, `datasetPath`, `skip`, `skipAssembleZipArtifact`, etc.) flow correctly into task properties |
58+
| `testSkipExecution` | `skip = true` causes `task.execute()` to no-op without throwing |
59+
| `testMergeTestNodes_mergesTwoFiles` | `mergeTestNodes()` unions SVC entries from multiple source-set `annotations.yml` files, merging arrays for keys present in both (e.g. `SVC_001` ends up with entries from both files) |
60+
| `testSetSvcsAnnotationsFilesMarksExplicit` | Setting `svcsAnnotationsFiles` explicitly marks the extension as no longer using auto-discovery |
61+
| `testDeprecatedSvcsAnnotationsFileSetter` | The deprecated singular `setSvcsAnnotationsFile()` still works and delegates to `svcsAnnotationsFiles` |
62+
| `testMissingRequirementsFile` | `task.execute()` throws an exception whose message mentions `requirements.yml` when the dataset directory doesn't contain it |
63+
64+
## Fixtures
65+
66+
### `src/test/resources/{yml,zip}/`
67+
68+
Tracked example files showing the shape of annotation YAML (`requirements_annotations.yml`,
69+
`svcs_annotations.yml`, `combined_annotations.yml`, following the reqstool
70+
`annotations.schema.json`) and of an assembled zip's contents (`zip/` — dataset YAML files,
71+
combined `annotations.yml`, `surefire-reports/`, `failsafe-reports/`).
72+
73+
**These are not currently loaded by `RequirementsToolTaskTest`** (which builds its test data
74+
inline) — treat them as reference examples of expected file formats, not as golden files
75+
with an automated regeneration step.
76+
77+
### `tests/fixtures/test_project/` — manual end-to-end validation
78+
79+
A minimal real Gradle project (`mypackage`) with three source sets, each producing one
80+
annotation that must survive the full pipeline:
81+
82+
| Source set | Directory | Produces |
83+
|---|---|---|
84+
| `main` | `src/main/java` | `@Requirements` on `Hello.hello()` → `REQ_001` |
85+
| `test` | `src/test/java` | `@SVCs` on `HelloTest.testHello()` → `SVC_001` |
86+
| `integrationTest` | `src/integration-test/java` | `@SVCs` on `HelloIT.testHelloIntegration()` → `SVC_002` |
87+
88+
Only source files, `build.gradle`, `settings.gradle`, and `docs/reqstool/*.yml` are tracked
89+
in git; `build/` and `.gradle/` are local build output and are gitignored.
90+
91+
To validate (or to regenerate/inspect expected output after an intentional change to plugin
92+
behavior), run from `tests/fixtures/test_project/`:
93+
94+
```bash
95+
gradle build
96+
ls build/reqstool/mypackage-0.1.0-reqstool.zip
97+
unzip -l build/reqstool/mypackage-0.1.0-reqstool.zip
98+
grep "SVC_" build/reqstool/annotations.yml # expect both SVC_001 and SVC_002
99+
```
100+
101+
Optionally, extract the zip and run `reqstool status local -p <extracted-dir>` (requires
102+
`pip install reqstool`) — expect `REQ_001` implemented and `SVC_001`/`SVC_002` both covered.
103+
See `tests/fixtures/test_project/README.md` for full expected output.

0 commit comments

Comments
 (0)