CAMEL-23757: Add Java DSL model writer for full-circle DSL transformation#24031
Draft
davsclaus wants to merge 14 commits into
Draft
CAMEL-23757: Add Java DSL model writer for full-circle DSL transformation#24031davsclaus wants to merge 14 commits into
davsclaus wants to merge 14 commits into
Conversation
…tion Add a new camel-java-io module in core/ that generates fluent Java DSL source code from Camel model definitions. This enables full-circle transformation between XML, YAML, and Java DSL formats. The implementation follows the same code-generation pattern as the existing camel-xml-io and camel-yaml-io modules: - JavaDslModelWriterGeneratorMojo extends ModelWriterGeneratorMojo - Velocity template generates JavaDslModelWriter from model metadata - JavaDslModelWriterSupport provides DSL rendering helpers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
Contributor
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
Contributor
|
🧪 CI tested the following changed modules:
Build reactor — dependencies compiled but only changed modules were tested (8 modules)
|
Reads XML route files from camel-xml-io test resources, converts them to Java DSL via JavaDslModelWriter, wraps in a RouteBuilder class, and compiles with javax.tools.JavaCompiler. 25 of 53 route files compile successfully; 28 known failures are tracked for constructs the writer doesn't yet handle (data formats, load balancer subtypes, process refs, attribute chaining). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…test Add 30 XML route definition files to camel-xml-io test resources covering EIPs that were previously untested: aggregate, claimCheck, delay, doTryCatchFinally, dynamicRouter, enrichAndPollEnrich, idempotentConsumer, multicast, onCompletion, sample, sort, step, stop, threads, throttle, toD, transacted, unmarshal, validate, wireTap, and more. These files expand the compile validation test in camel-java-io from 44 to 83 parameterized tests, improving coverage of the Java DSL model writer across the full EIP catalog. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…let EIPs Add XML test files for the three remaining untested EIPs: - interceptFrom.xml in camel-xml-io (XML round-trip works) - tokenizer.xml in camel-xml-io (langChain4j word tokenizer) - kamelet.xml in camel-java-io (kept separate because the kamelet boolean attribute on RouteDefinition is a runtime transient that breaks XML round-trip in the ModelWriter) Update JavaDslCompileTest to also scan its own test resources directory. The kamelet EIP compiles successfully; interceptFrom and tokenizer are added to known failures (they are RouteBuilder- level methods, not chainable from the route). Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…iscovery Replace the hardcoded instanceof chain in beginStep() with Jandex-derived metadata from ProcessorDefinition method signatures. The Mojo now discovers at code-generation time which parameters each DSL method takes, matches them to Definition class fields, and the Velocity template generates per-EIP dispatch code. This fixes 8 previously failing compile tests (convertBody, convertHeaderTo, convertVariableTo, rollback, barPolicyRoute, enrichAndPollEnrich, routeWithCircuitBreaker, removeHeadersAndProperties). Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…perties, and imports
- Use language("name", "expr") for expression languages without RouteBuilder
helpers (groovy, ognl, juel, mvel, spel, python, hl7terser, wasm)
- Map process(String) to ref field so process("myRef") is generated
- Handle route properties as .routeProperty("key", "value") in writeRoute()
- Add ExchangePattern and Builder.language imports to compile test wrapper
- Add handledAttributes check to doWriteChildList to prevent duplicates
10 more compile tests now pass (62 total, 24 remaining).
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
Detect DataFormatDefinition instances in doWriteChildElement and emit the data format method name (e.g. .json(), .csv(), .hl7()) on DataFormatClause. Data formats without no-arg methods (bindy, flatpack, xmlSecurity) remain as known failures. 7 more compile tests now pass (69 total, 17 remaining). Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…rmDataType - Generalize findRicherOverload to find multi-param overloads (log+LoggingLevel, poll+timeout, transformDataType+fromType) - Add LoggingLevel enum mapping to mapSingleParam - Add long param mapping for poll timeout - Prefer correlationExpression fallback for aggregate over Jandex expression - Use _first boolean flag in template for proper multi-arg comma separation - Add long renderType to Velocity template - Reject richer overloads with duplicate field names Score: 73/86 compile tests passing (85%) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Claus Ibsen <davsclaus@apache.org> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…sts and ExpressionSubElementDefinition - Add classList renderType for exception class arguments in onException/doCatch - Handle ExpressionSubElementDefinition in doWriteChildElement (handled, retryWhile, correlationExpression) - Add Predicate cast for handled/continued/retryWhile to resolve ambiguity with ValueBuilder - Fix classLiteral to use FQN for non-java.lang classes - Fix doWriteStringList to respect handledAttributes Score: 75/86 (87%), 11 known failures remaining. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…va DSL writer Add @DslArg field-level annotation to mark Definition class fields as primary arguments for Java DSL method calls. This replaces ~250 lines of Jandex-based method signature introspection with ~30 lines of annotation-based reflection. Annotate ~30 model Definition classes. Also supports type-level @DslArg(exclude = ...) to suppress inherited annotations for subclasses where the parent's primary arg doesn't apply (e.g., EnrichDefinition extends ExpressionNode but enrich() takes a URI string, not an expression). Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…terns (80/86) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…ull option support Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
Hybrid approach: compact form (e.g., simple("${body}")) when no options,
builder pattern (e.g., expression().simple("${body}").resultTypeName("String").end())
when expression-specific options like resultType, saxon, suppressExceptions are set.
Uses LanguageBuilderFactory methods - no imports needed, all options available.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
… (86/87) Handle interceptFrom, intercept, interceptSendToEndpoint as separate RouteBuilder-level statements. Support inlined error handler with deadLetterChannel/defaultErrorHandler and typed redelivery policy options. Handle batch resequencer config with .batch().size().timeout(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
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.
Summary
core/camel-java-iomodule that generates fluent Java DSL source code from Camel model definitionscamel-xml-ioandcamel-yaml-iomodulesArchitecture
core/camel-xml-iocore/camel-yaml-iocore/camel-java-ioModelWriterYamlModelWriterJavaDslModelWriterBaseWriterYamlModelWriterSupportJavaDslModelWriterSupporto.a.c.xml.outo.a.c.yaml.outo.a.c.java.outXmlModelWriterGeneratorMojoYamlModelWriterGeneratorMojoJavaDslModelWriterGeneratorMojomodel-writer.vmmodel-yaml-writer.vmmodel-java-dsl-writer.vmExample Output
New Files
JavaDslModelWriterGeneratorMojo.java— Mojo extendingModelWriterGeneratorMojofor code generationmodel-java-dsl-writer.vm— Velocity template producing the generatedJavaDslModelWriterclasscore/camel-java-io/— New module withJavaDslModelWriterSupport(DSL rendering helpers) and generatedJavaDslModelWriterTest Plan
mvn clean install -DskipTests)Claude Code on behalf of Claus Ibsen
🤖 Generated with Claude Code