CAMEL-21208: Replace manual string-based code generation with FreeMarker templates#22200
CAMEL-21208: Replace manual string-based code generation with FreeMarker templates#22200
Conversation
…ker templates in camel-jbang
- Add FreeMarker 2.3.34 dependency to camel-jbang-core
- Create TemplateHelper utility using square bracket syntax ([=var], [#if]...[/#if])
to avoid conflicts with ${...} (Maven) and <...> (XML) in generated content
- Convert all 23 .tmpl template files to .ftl FreeMarker templates
- Refactor Export*, Run, and Init commands to use TemplateHelper instead of
manual StringBuilder/replaceAll/replaceFirst code generation
- Extract shared helpers (buildRepositoryList, buildDependencyList, formatBuildProperties,
mavenGavComparator) into ExportBaseCommand
- Maintain backward compatibility for catalog-provided templates in ExportSpringBoot
- Remove 4 unreferenced templates (main-docker-*.tmpl, main-jkube-pom.tmpl)
- Keep deprecated bind templates (.tmpl) used by TemplateProvider
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
- Add backward compat check for old .tmpl catalog template name in ExportSpringBoot - Remove dead model variables (CamelVersion, QuarkusManagementPort) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🧪 CI tested the following changed modules:
All tested modules (26 modules)
|
| String ftlName = "Dockerfile" + javaVersion + ".ftl"; | ||
| String context; | ||
| try { | ||
| Map<String, Object> model = new HashMap<>(); |
There was a problem hiding this comment.
can this be extracted to avoid code duplication?
There was a problem hiding this comment.
Claude Code on behalf of Guillaume Nodet
Good catch. Looking at this more carefully — the Dockerfile template rendering now uses FreeMarker through the base class, and the Quarkus override handles the fast-jar vs uber-jar distinction which genuinely needs different logic. So the apparent duplication in Export.java line 311 is the shared base implementation. Will add a clarifying comment.
|
Hey AI agent, please rebase and resolve the conflict |
JIRA: CAMEL-21208
Summary
TemplateHelperutility using FreeMarker's square bracket syntax ([=var],[#if]...[/#if]) to avoid conflicts with${...}(Maven/Camel expressions) and<...>(XML tags) in generated content.tmpltemplate files to.ftlFreeMarker templates with proper directives for conditionals and loopsExportCamelMain,ExportSpringBoot,ExportQuarkus,Export,Run, andInitcommands to useTemplateHelperinstead of manualStringBuilder/replaceAll/replaceFirstcode generationbuildRepositoryList,buildDependencyList,formatBuildProperties,mavenGavComparator) intoExportBaseCommandto eliminate duplicationExportSpringBoot(legacy regex processing path)main-docker-*.tmpl,main-jkube-pom.tmpl).tmpl) used byTemplateProviderMotivation
The existing code generation approach used raw string manipulation (
replaceFirst,replaceAll,StringBuilder.append) to produce POM files, Dockerfiles, README files, and source code. This was:FreeMarker templates make the generated output structure visible and maintainable, with proper control flow (
[#if],[#list]) replacing ad-hoc string manipulation.Test plan