davsclaus opened a new pull request, #27122:
URL: https://github.com/apache/camel/pull/27122

   _Claude Code on behalf of davsclaus_
   
   JIRA: [CAMEL-25148](https://issues.apache.org/jira/browse/CAMEL-25148)
   
   ## Why
   
   Camel can read XML and YAML routes into the model, and write the model as 
Java (`LwModelToJavaDumper`), but it could not read Java DSL source without 
compiling the `RouteBuilder` and running `configure()`. That needs the 
project's full classpath, may download dependencies, takes seconds and runs the 
project's code. Tools fell back on pattern matching on string literals. The 
project overview, the TUI and AI prompts are examples: they missed constants, 
nesting, error paths and the endpoint DSL.
   
   ## What
   
   **`LwJavaParser` in `camel-java-io`** reads a `RouteBuilder`, a 
`LambdaRouteBuilder` or a snippet into the model in milliseconds, without 
compiling it. It reads the source as text, then **replays** each chain of calls 
against Camel's own DSL. So `end()`, blocks, expression clauses and ids behave 
as in a compiled route, for every EIP, with no mapping table to keep in step 
with the model.
   
   - **Nothing of the project runs or is loaded.**
     - A class of the project becomes an empty stub with its name.
     - Lambdas and `new` objects become placeholders.
     - Values the parser can't work out are kept as `?{source}` and reported 
with their line (`JavaParseResult.unresolved()`).
   - **Worked out from the source:**
     - constants, concatenation and arithmetic;
     - `String.format`, `fromF`/`toF`/`simpleF` and `Foo.class.getName()`;
     - static imports and inherited constants;
     - `for`/`if`/`try` blocks.
   - **Normalized to what XML and YAML have:** expression clauses become their 
language, and `Class` options also get their name.
   - **Plugs:**
     - `EndpointDslResolver`: the endpoint DSL. By default it reverses the 
rules the endpoint DSL is generated with, checked against every factory.
     - `ConstantResolver`: constants of classes the parser can't see.
   
   **Security** (`design/java-dsl-parser.adoc`):
   - Only Camel's model and builder DSL is ever called, and never with a 
`CamelContext`.
   - The reachable builder methods are pinned by a test, so a new DSL method 
fails the build until it's reviewed.
   - Constants are read only from Camel and a few JDK classes.
   - Only exceptions are created.
   - The work is bounded: at most 1,000 stubs, 100 levels of nesting and 2 MB 
of source. `parse()` never throws, and it's fuzz tested.
   
   **camel-jbang-core:** the project overview behind `camel overview`, the MCP 
project overview tool and the TUI now reads Java routes with the parser, with:
   - a catalog-based endpoint DSL resolver;
   - a constant resolver for the project's other files, and the catalog's 
component header constants and enum values.
   
   The AI summary now keeps the description of a route without an id; a colon 
in its key made it get lost.
   
   **TUI:**
   - Java routes without a `routeId` are matched to the ids Camel gave them at 
runtime, by their `from` endpoint.
   - The Architecture's *Flow* panel lists each route in flow order, with the 
routes and remote systems it hands off to.
   - A route's diagram keeps its label and group in the title.
   
   ## Tests
   
   - **Round trips:** the XML test routes of camel-xml-io, camel-core and 
camel-java-io are dumped as Java, read back and dumped again, with the known 
gaps listed with their reason. camel-spring-xml's test routes hold a floor. The 
dumper's golden Java files read back exactly.
   - **Corpora:**
     - camel-core's and camel-endpointdsl's test sources, as a report.
     - Any directory with `-Dcamel.java.in.corpus=dir,...`. With the catalog 
plugs, about 8,400 sources and 18,000 routes were read this way:
       - components' tests: 2,109 of 4,722 sources read completely, 10,220 
routes, about 5 s;
       - the camel-spring-boot and camel-quarkus repositories;
       - the three example repositories.
   
       What's left unresolved is mostly by design: lambdas, objects, runtime 
test fixtures.
   - **Security:** the pinned surface, the context and constant rules, the 
limits, and a fuzz test.
   - **Local runs:** camel-java-io 163, camel-jbang-core 1,302 and 
camel-jbang-plugin-tui 1,414 tests pass.
   
   ## Related
   
   - [CAMEL-25157](https://issues.apache.org/jira/browse/CAMEL-25157): 
`LwModelToJavaDumper` writes invalid Java for some routes. The round-trip test 
found these.
   - [CAMEL-25161](https://issues.apache.org/jira/browse/CAMEL-25161): AI 
labels for the decision points of a route.
   - [CAMEL-25166](https://issues.apache.org/jira/browse/CAMEL-25166): findings 
for a Camel 5 Java DSL, from this work.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to