Federico Mariani created CAMEL-23276:
----------------------------------------

             Summary: Allow JBang plugins to customize Run command before 
CamelContext is built
                 Key: CAMEL-23276
                 URL: https://issues.apache.org/jira/browse/CAMEL-23276
             Project: Camel
          Issue Type: New Feature
          Components: camel-jbang
    Affects Versions: 4.18.1
            Reporter: Federico Mariani


Third-party JBang plugins that register beans via _ContextServicePlugin.load()_ 
may need to prepare the environment (system properties, config directories) 
based on the file arguments passed to camel run. 
Currently, the only way to do this is by subclassing Run (e.g., camel forage 
run), but since Camel 4.18.1, plugins can auto-discover dependencies via 
PluginExporter, making the subcommand unnecessary for most use cases. 
However, there is no plugin hook that runs after file arguments are parsed but 
before main.run() triggers camelContext.build() → ContextServicePlugin.load().

This gap means plugins cannot:
- Derive a config directory from file arguments (e.g., camel run test/* → set a 
config dir to test/)
- Set system properties that influence bean factory configuration at load() time
- React to the --dev flag before the CamelContext is built (related: 
CAMEL-23252)

*Proposal:* Add a PluginRunCustomizer interface to the Plugin SPI, consulted by 
Run.doCall() after file arguments are resolved but before main.run():

{code:java}
  public interface PluginRunCustomizer {
      /**
       * Called after the Run command has resolved file arguments and configured
       * dependencies, but before KameletMain.run() builds the CamelContext.
       *
       * @param main  the KameletMain instance (for adding initial properties)
       * @param files the resolved file arguments passed to the run command
       */
      void beforeRun(KameletMain main, List<String> files);
  }
{code}

Plugins would expose this via _Plugin.getRunCustomizer()_ (similar to 
Plugin.getExporter()). The Run command would call all active plugin customizers 
after dependency resolution:

{code:java}
  // In Run.doCall(), after addDependencies() and before runKameletMain():
  if (!skipPlugins) {
      for (PluginRunCustomizer customizer : pluginRunCustomizers) {
          customizer.beforeRun(main, files);
      }
  }
{code}

This would allow Forage to move _ForageRun.resolveConfigDir()_ and 
_doAddInitialProperty()_ logic into the plugin customizer, making camel forage 
run unnecessary, camel run would work identically.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to