Repository navigation
feat(codegen-spring): write Java generators through the code writer - #636
Merged
Merged
Conversation
…e writer (W-JV-3) SpringControllerGenerator writes through SpringJavaWriter, a JavaWriter adding continuation lines and indented case bodies. Each member of the generated controller comes from its own protected write* method. SpringGeneratorSupport's cross-field validator members and annotation import lists go through the writer too, and both files leave the layout ratchet's allowlist. Output is unchanged on 1,512 controllers from every fixture model except for sorted imports and no blank line after the class opener; the six golden controllers are regenerated. DTO and value-object output is byte-identical.
… code through the code writer (W-JV-4) SpringDtoGenerator, SpringValueObjectGenerator, Fr019SharedEnum, SpringRecordBuilder and SpringTypeMapper's enum declaration write through SpringJavaWriter, each piece from a protected method. Output changes in layout only (sorted imports, blank-line cleanups), checked on every fixture model in two wire/API configurations; the inline-enum-names golden takes the one blank-line change.
…rt code through the code writer (W-JV-4) Each piece comes from a protected method; the output loses only the blank line after the class or interface opener, checked on every fixture model in two wire/API configurations.
…iter (W-JV-4) The strict and lenient tiers, each mapper and each coercion helper come from protected methods taking the writer. Output changes in layout only: sorted imports, no blank after the class opener, a blank after the leading comment; checked on every fixture model.
… and render helper through the code writer (W-JV-5) Each emitted member comes from a protected method taking the writer, and SpringNaming.packageHeader goes. The allowlist output is byte-identical; the other two change in layout only, checked on every fixture model.
…tests through the code writer (W-JV-5) Each member comes from a method taking the writer. Output changes in layout only, checked on every fixture model; the witness-key collision message lists its pairs on one line.
…ough the code writer (W-JV-5) The signature text is byte-identical on every fixture model.
…ugh the code writer (W-JV-5) The older direct writers take their indentation unit from WriterOptions, and the writer classes join the Java engine surface so an ejected generator imports them. Output changes in layout only, checked on every fixture model. The layout ratchet's unconverted list is empty.
…n fingerprint The Java PATCH class loses the blank after its opener (the code-writer conversion), and the Python filter allowlist picks up a docstring change already on main. The JVM project's .metaobjects gets the same .gitignore as its sibling: the run fingerprint the Maven plugin stores there names absolute paths and is documented as not committed.
Every worktree and lane builds the same unreleased version, so installing it into a shared repository (~/.m2, or the ~/.m2-ci that ci-local.sh installed into) replaced what other checkouts resolved under that number, and they tested code they did not have. - The java and kotlin conformance gates are one reactor build each (-pl ... -am test) with fully qualified -Dtest names, and the full reactor runs clean verify. Nothing installs. - The out-of-reactor JVM integration modules, the one step that needs installed artifacts, install into the run's private repository: a small head under $DEV_SCRATCH in front of the shared cache, chained read-only with maven.repo.local.tail, so no per-run copy of the dependency cache is made. ci-local.sh deletes the head on exit (trap). - scripts/lib/maven-private-repo.sh holds that setup, and integration-test.sh and fatjar-smoke.sh use it when run alone. regen-showcase.ts keeps the inherited tail. - Hosted workflows pass METAOBJECTS_CI_M2_RUN_REPO=~/.m2/repository: the runner is ephemeral, and setup-java's cache keeps what it downloads. - RELEASING-java's smoke build is mvn clean verify.
…anges; one pre-existing eject-rule conflict left for a decision.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
JavaWriter. A newSpringJavaWriteradds the continuation-line andcase-body layouts. Each generated member comes from its own protectedwrite*method, so an owned copy overrides one method instead of editing string builders.SpringNaming.packageHeaderis removed, andCodeWriter,JavaWriter,WriterOptionsandSpringJavaWriterjoin the Java eject engine surface. The layout ratchet's unconverted list is empty.// GENERATEDcomment. The witness-key collision error lists its colliding pairs on one line separated by;. Regenerating an adopter's Java code shows these diffs once. The showcase output and the golden fixtures underserver/java/codegen-spring/src/test/resources/golden/are regenerated to match.scripts/ci-local.shruns the reactor asmvn verifyormvn testand installs nothing. The one step that needs installed jars, the out-of-reactor JVM integration modules, installs into a per-run private repository (scripts/lib/maven-private-repo.sh) that sits in front of a read-only shared cache. The showcase regen and the smoke scripts follow the same rule, andscripts/test-ci-lane-selection.shcopies the helper into its test repository. The CI workflows setMETAOBJECTS_CI_M2_RUN_REPOfor hosted runners. The CHANGELOG,docs/RELEASING*.md,docs/ports/java.md,docs/features/own-your-codegen.mdand ADR-0063 are updated to match.Validation
Risk Assessment
✅ Low: The two review fixes hold: renderer imports now print verbatim, deduplicated and sorted, and the renderer source splits on CRLF. Both have behavioural tests. The rest is a layout-only refactor onto the code writer (documented in CHANGELOG with golden output updated) and CI scripts that keep Maven installs out of the shared repository.
Testing
Baseline ci-local --affected passed at target commit; not re-run since no source or test files changed in this turn. Drove the real JUnitRequirementTestsGenerator on the worked-example fixture in three modes (wildcard/same-named statics renderer, CRLF renderer, no renderer) through a disposable driver. All three generate, emit no CR, and compile under javac -Xlint:all -Werror. Both review fixes reproduce as generation failures on their pre-fix commits and pass at HEAD. Focused surefire class: 35/35 pass. Only observation: default output blank-line layout changed vs base (info, no action). Evidence in the evidence directory; scratch driver removed; no background processes started.
Evidence: Live run transcript: generator on worked-example fixture, pre-fix vs HEAD, javac results
Evidence: Generated test file, wildcard and same-named static imports (HEAD)
Evidence: Generated test file, CRLF renderer source (HEAD)
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (2) ✅
server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/JUnitRequirementTestsGenerator.java:327- Renderer-supplied imports now go through JavaWriter.use()/useStatic(), which key on the simple name and throw WriterException(IMPORT_CONFLICT) when two different qualified names share one. The RenderedTest contract only says imports are 'names to import', and the old code printed each as a plainimport X;. A project renderer that returns two wildcard imports (e.g.java.util.*andjava.io.*, simple name*), or two static imports of the same member name from different classes (legal Java overloads), generated fine before and now aborts generation with IMPORT_CONFLICT. Same-site siblings: the static-import branch at line 326 has the same failure forstatic a.B.*+static c.D.*. Smallest fix: write renderer imports verbatim (collect into a set and emit as raw lines, or catch the conflict and fall back to a verbatim import), or narrow the documented contract to exact single-type imports and say so in RenderedTest.🔧 Fix applied.
2 warnings still open:
server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/JUnitRequirementTestsGenerator.java:327- Renderer-supplied imports now go through JavaWriter.use()/useStatic(), which key on the simple name and throw WriterException(IMPORT_CONFLICT) when two different qualified names share one. The RenderedTest contract only says imports are 'names to import', and the old code printed each as a plainimport X;. A project renderer that returns two wildcard imports (e.g.java.util.*andjava.io.*, simple name*), or two static imports of the same member name from different classes (legal Java overloads), generated fine before and now aborts generation with IMPORT_CONFLICT. Same-site siblings: the static-import branch at line 326 has the same failure forstatic a.B.*+static c.D.*. Smallest fix: write renderer imports verbatim (collect into a set and emit as raw lines, or catch the conflict and fall back to a verbatim import), or narrow the documented contract to exact single-type imports and say so in RenderedTest.server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/JUnitRequirementTestsGenerator.java:327- Renderer source lines now go through CodeWriter.line()/put(), which throws WriterException(NEWLINE_IN_LINE) on any \r. Line 327 splits the renderer's source on "\n" only. A project renderer whose source() uses CRLF line endings (e.g. a template read from a Windows-edited resource file) leaves a trailing \r on every line, so generation now aborts. The old indent() path copied those lines through unchanged. Concrete trace: source "@test\r\nvoid x() {}" splits to ["@test\r", "void x() {}"], and line("@test\r") throws. This sits in the same renderer-source path the review-1 fix touched; the fix round did not introduce it, the original conversion did. The sibling site is writeCommentLines (same file), which already splits on "\r\n|\r|\n". Smallest fix: split the renderer source with the same regex, so a CRLF source generates with LF endings.🔧 Fix applied.
✅ Re-checked - no issues remain.
server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/JUnitRequirementTestsGenerator.java- Default (no renderer) requirement-test output layout changed vs base eadf39e: blank-line placement moved (blank line now after the header comments, one fewer blank line before the class body). Content and compilation unchanged. Adopters regenerating requirement tests see a one-time cosmetic diff. Expected side effect of writing through SpringJavaWriter; no action proposed.scripts/ci-local.sh --affected --strict-toolchainscd server/java && mvn -o -q -pl codegen-spring -am -Dtest=JUnitRequirementTestsGeneratorTest -Dsurefire.failIfNoSpecifiedTests=false test(exit 0; surefire: 35 run, 0 failures, 0 errors)Live driver (disposable, in scratch, removed after): real JUnitRequirementTestsGenerator from codegen-spring target/classes, run on fixtures/requirement-test-identity-conformance/worked-example/input with renderer = Wildcard, Crlf, or noneFail-before reproduction: base commit generator and intermediate commits 57d7999aa7 (pre review-1) and 62412b6b87 (pre review-2) compiled alongside, run through the same driver: 57d7999aa7 Wildcard -> ERR_WRITER_IMPORT_CONFLICT; 62412b6b87 Crlf -> ERR_WRITER_NEWLINE_IN_LINEjavac -proc:none -Xlint:all -Werror on every generated output tree plus a witness class (exit 0 for HEAD in all three renderer modes); CR byte count in generated test (0 at HEAD, 6 at base for Crlf)Diff of default-path generated output, base vs HEAD (blank-line placement only)server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/SpringTypeMapper.java:431- SpringTypeMapper.writeEnumDeclaration (engine, stays packaged) writes emitted enum text, which the own-your-codegen engine rule says must be handed over ('Anything that returns emitted text is handed over'). Pre-existing as enumDeclaration; this change only moved it to CodeWriter. Resolving means moving it into a copied emitter and updating dto/value-object/Fr019SharedEnum eject sets, a code-design call.🔧 **Lint** - 1 issue found → auto-fixed ✅
🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.