Skip to content

feat(codegen-spring): write Java generators through the code writer - #636

Merged
dmealing merged 14 commits into
mainfrom
fm/mo-130-lane-jvm-3-b2
Nov 22, 2026
Merged

dmealing merged 14 commits into
mainfrom
fm/mo-130-lane-jvm-3-b2

Conversation

@dmealing

@dmealing dmealing commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Java generators write through the code writer (ADR-0063). The Spring generators (controller, DTO, value object, shared enum, names, repository, report export, output parser, filter allowlist, render helper, LLM-trace helper, requirement tests) and the codegen-base entity extractor and binding provider now emit through JavaWriter. A new SpringJavaWriter adds the continuation-line and case-body layouts. Each generated member comes from its own protected write* method, so an owned copy overrides one method instead of editing string builders. SpringNaming.packageHeader is removed, and CodeWriter, JavaWriter, WriterOptions and SpringJavaWriter join the Java eject engine surface. The layout ratchet's unconverted list is empty.
  • Generated Java output changes in layout only, plus one message. Imports are sorted, blank lines after class openers and inside nested enums are removed, and parsers gain a blank line after the leading // GENERATED comment. 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 under server/java/codegen-spring/src/test/resources/golden/ are regenerated to match.
  • Java build gates no longer write a shared Maven repository. scripts/ci-local.sh runs the reactor as mvn verify or mvn test and 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, and scripts/test-ci-lane-selection.sh copies the helper into its test repository. The CI workflows set METAOBJECTS_CI_M2_RUN_REPO for hosted runners. The CHANGELOG, docs/RELEASING*.md, docs/ports/java.md, docs/features/own-your-codegen.md and 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.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Project renderer returns wildcard imports (java.util., java.io.) and same-named static members (Math.max, Integer.max): generation succeeds, imports print verbatim once, output compiles with javac -… ✅ pass live req-tests-live/transcript.txt (cur-wildcard; pre1-wildcard fails) and req-tests-live/cur-wildcard-Requirements_acme_shop_Test.java. Driver ran the real JUnitRequirementTestsGenerator on fixtures/requi…
Project renderer source uses CRLF line endings: generation succeeds, no CR reaches the emitted test file, output compiles ✅ pass live req-tests-live/transcript.txt (cur-crlf: CR bytes 0, javac exit 0; pre2-crlf fails) and req-tests-live/cur-crlf-Requirements_acme_shop_Test.java
Default path, no project renderer: requirement tests and witness interface generate and compile with -Xlint:all -Werror; content matches base apart from blank-line layout ✅ pass live req-tests-live/transcript.txt (cur-none, old-none); diff of base vs HEAD output showed only blank-line placement differences
Evidence: Live run transcript: generator on worked-example fixture, pre-fix vs HEAD, javac results
## pre1-wildcard
gen exit: ERR_WRITER_IMPORT_CONFLICT: * is imported from both java.util.* and java.io.*
javac: 
## pre2-crlf
gen exit: ERR_WRITER_NEWLINE_IN_LINE: line text contains a line break; write each line separately or use text(): "@Test
"
javac: 
## pre2-wildcard
gen exit: 
GENERATED OK into <scratch>/runs/pre2-wildcard/out
javac: 
## cur-wildcard
gen exit: 
GENERATED OK into <scratch>/runs/cur-wildcard/out
javac: 
## cur-crlf
gen exit: 
GENERATED OK into <scratch>/runs/cur-crlf/out
javac: 
## cur-none
gen exit: 
GENERATED OK into <scratch>/runs/cur-none/out
javac: 
## old-none
gen exit: 
GENERATED OK into <scratch>/runs/old-none/out
javac: 
pre1-wildcard javac-exit=0
pre2-crlf javac-exit=0
pre2-wildcard javac-exit=0
cur-wildcard javac-exit=0
cur-crlf javac-exit=0
cur-none javac-exit=0
old-none javac-exit=0
Evidence: Generated test file, wildcard and same-named static imports (HEAD)
// GENERATED by metaobjects (requirement-tests). DO NOT EDIT: this file is rewritten whole.
// The witnesses are project-owned, in com.acme.Witnesses.

package com.acme.req;

import static java.lang.Integer.max;
import static java.lang.Math.max;

import java.io.*;
import java.util.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class Requirements_acme_shop_Test {
    private final Requirements_acme_shop_Witnesses witnesses = new com.acme.Witnesses();

    @Test
    void req_acme_shop_Orders_Recorded__object_entity() {
        Assertions.assertTrue(true);
    }

    @Test
    void req_acme_shop_Orders_Refunded() {
        Assertions.assertTrue(true);
    }
}
Evidence: Generated test file, CRLF renderer source (HEAD)
// GENERATED by metaobjects (requirement-tests). DO NOT EDIT: this file is rewritten whole.
// The witnesses are project-owned, in com.acme.Witnesses.

package com.acme.req;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class Requirements_acme_shop_Test {
    private final Requirements_acme_shop_Witnesses witnesses = new com.acme.Witnesses();

    @Test
    void req_acme_shop_Orders_Recorded__object_entity() {
        Assertions.assertTrue(true);
    }

    @Test
    void req_acme_shop_Orders_Refunded() {
        Assertions.assertTrue(true);
    }
}
  • Evidence: focused Maven surefire run, log kept locally
  • Outcome: ⚠️ 1 info across 1 run (10m44s)

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 plain import X;. A project renderer that returns two wildcard imports (e.g. java.util.* and java.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 for static 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 plain import X;. A project renderer that returns two wildcard imports (e.g. java.util.* and java.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 for static 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.

⚠️ **Test** - 1 info
  • ℹ️ 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.
  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Project renderer returns wildcard imports (java.util., java.io.) and same-named static members (Math.max, Integer.max): generation succeeds, imports print verbatim once, output compiles with javac -… ✅ pass live req-tests-live/transcript.txt (cur-wildcard; pre1-wildcard fails) and req-tests-live/cur-wildcard-Requirements_acme_shop_Test.java. Driver ran the real JUnitRequirementTestsGenerator on fixtures/requi…
Project renderer source uses CRLF line endings: generation succeeds, no CR reaches the emitted test file, output compiles ✅ pass live req-tests-live/transcript.txt (cur-crlf: CR bytes 0, javac exit 0; pre2-crlf fails) and req-tests-live/cur-crlf-Requirements_acme_shop_Test.java
Default path, no project renderer: requirement tests and witness interface generate and compile with -Xlint:all -Werror; content matches base apart from blank-line layout ✅ pass live req-tests-live/transcript.txt (cur-none, old-none); diff of base vs HEAD output showed only blank-line placement differences
  • scripts/ci-local.sh --affected --strict-toolchains
  • cd server/java &amp;&amp; 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 none
  • Fail-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_LINE
  • javac -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)
⚠️ **Document** - 1 warning
  • ⚠️ 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 ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

…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.
@dmealing
dmealing merged commit 728f6d3 into main Nov 22, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-130-lane-jvm-3-b2 branch November 22, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant