[
https://issues.apache.org/jira/browse/CAMEL-21208?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18068914#comment-18068914
]
Guillaume Nodet commented on CAMEL-21208:
-----------------------------------------
The PR https://github.com/apache/camel/pull/22200 introduces FreeMarker
templates for the complex code generation cases (POM files, Dockerfiles,
README, main class sources) where the old approach used
StringBuilder/replaceAll/replaceFirst and was hard to maintain.
However, camel-jbang also has simpler .tmpl template files used by the Bind
command (pipe.yaml.tmpl, step-*.yaml.tmpl, endpoint-*.yaml.tmpl,
error-handler-*.yaml.tmpl) and the Init command's simple scaffolding templates
(java, yaml, xml, kamelets). These only need basic placeholder substitution and
currently use raw text loading with String.replace().
It could make sense in a follow-up to unify all template processing under
FreeMarker for consistency, so there is a single mechanism across the codebase.
The TemplateProvider interface used by the Bind command would need to be
refactored to use FreeMarker's model-based approach instead of returning raw
InputStreams. This is not urgent since the simple templates work fine as-is,
but having one template engine everywhere would reduce cognitive overhead for
contributors.
_Claude Code on behalf of Guillaume Nodet_
> camel-jbang: use a template engine for code generation
> ------------------------------------------------------
>
> Key: CAMEL-21208
> URL: https://issues.apache.org/jira/browse/CAMEL-21208
> Project: Camel
> Issue Type: Improvement
> Components: camel-jbang
> Affects Versions: 4.7.0, 4.8.0
> Reporter: Otavio Rodolfo Piske
> Priority: Major
>
> We have several places were we [create the export files by
> code|https://github.com/apache/camel/blob/main/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java#L1265-L1281].
> Not only this bug-prone, but this is also [extremely hard to read, test,
> maintain and
> evolve|https://sonarcloud.io/project/issues?directories=dsl%2Fcamel-jbang%2Fcamel-jbang-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fcamel%2Fdsl%2Fjbang%2Fcore%2Fcommands&issueStatuses=OPEN%2CCONFIRMED&id=apache_camel&open=AX4xQ6i72wn0z3gD8D78].
> The code on Camel JBang is full of code like this.
> Using a template engine allow us to separate the template source, from the
> text/code generation logic, resulting in a code that is easier to maintain.
> We should pick a template engine, convert the all that code to the
> appropriate format and cleanup the code generation.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)