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

   ## Summary
   
   The blog [Extending Apache Camel Simple with Your Own 
Functions](https://camel.apache.org/blog/2026/09/camel-simple-customfunction/) 
shows a custom `SimpleFunction` in Java run with `camel run route.camel.yaml 
MaskEmailFunction.java`. For low-code users the natural variants are the same 
class as a `.groovy` file, or an inline Groovy bean in the YAML file, edited 
with `camel run --dev`. None of these worked end to end (verified on 
4.23.0-SNAPSHOT, see 
[CAMEL-24873](https://issues.apache.org/jira/browse/CAMEL-24873)):
   
   - **camel-jbang**: `camel run` now adds `camel-groovy` when a `.groovy` file 
is given, so the file is compiled without `--dep=camel-groovy` (before it was 
silently ignored). The dependency is written to the run settings, so `camel 
export` includes it.
   - **camel-groovy**: `DefaultGroovyScriptCompiler` runs the registered 
`CompilePostProcessor`s on a compiled class that has class-level annotations, 
with a new instance of it — the same mechanism `JavaRoutesBuilderLoader` uses 
for `.java` sources, with the processors `camel-kamelet-main` registers in 
`AnnotationDependencyInjection`. So `@BindToRegistry`, `@Converter` and the 
Spring/Quarkus annotations work in a `.groovy` file, and a reload in dev mode 
binds the bean again. Plain classes and scripts are not instantiated.
   - **camel-core-languages**: in the `dev` profile 
`MiscExpressionBuilder.customFunction` resolves the function again per 
evaluation. `DefaultSimpleFunctionRegistry` already re-looked-up the registry 
in dev mode (CAMEL-24486), but the simple language expression cache kept the 
adapter with the first bean, so an edited `SimpleFunction` bean never took 
effect until a restart.
   
   ## Verified with the Camel CLI
   
   | | before | after |
   |---|---|---|
   | `camel run route.camel.yaml MaskEmailFunction.groovy` | `Unknown function: 
maskEmail` (file not compiled) | works |
   | same with `--dev`, edit the `.groovy` file | – | recompiled, rebound, next 
message uses the edit |
   | inline `scriptLanguage: groovy` bean returning `[...] as SimpleFunction`, 
`--dev`, edit the script | routes reload, function keeps old behaviour | next 
message uses the edit |
   
   ## Tests
   
   - `GroovyCompilePostProcessorTest` (camel-groovy): a `@BindToRegistry` 
groovy class is handed to the post-processor with an instance and usable as 
`${maskEmail(${body})}`; a plain groovy class is not instantiated.
   - `SimpleCustomFunctionDevReloadTest` (camel-core): replacing the 
`SimpleFunction` bean in the dev profile takes effect for `${greet(${body})}` 
and `${body} ~> ${greet}` (fails without the fix).
   - Doc example validators (`EipDocExamplesTest`, `CatalogDocExamplesTest`, 
`DocExamplesXmlSchemaTest`, `DocExamplesJavaImportsTest`) pass on the new 
examples.
   
   ## Docs
   
   - simple-advanced: "Custom functions in Groovy with Camel CLI" (`.groovy` 
file and inline YAML groovy bean, dev reload)
   - camel-jbang beans page: "Using Groovy source files" (with the note that a 
`- beans:` `type` cannot refer to a Groovy class, as beans are created before 
the groovy compile)
   - groovy-language: post-processors paragraph
   - 4.23 upgrade guide entries for camel-groovy and camel-jbang
   
   Follow-up for local models (syntax primer and answer checks for `$init{ 
}init$`, `~:=`, `~>`): 
[CAMEL-24874](https://issues.apache.org/jira/browse/CAMEL-24874).
   
   _Claude Code on behalf of davsclaus_
   
   🤖 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