Class ConfigMerger

java.lang.Object
org.apache.tika.pipes.core.config.ConfigMerger

public class ConfigMerger extends Object
Utility for merging configuration overrides with existing Tika JSON configuration.

This class centralizes the config generation logic that was previously duplicated in:

  • PipesForkParser.generateJsonConfig()
  • TikaServerProcess.createDefaultConfig() and ensureServerComponents()
  • TikaAsyncCLI.PluginsWriter and ensurePluginRoots()

Key design decisions:

Example usage:

 ConfigOverrides overrides = ConfigOverrides.builder()
     .addFetcher("my-fetcher", "file-system-fetcher",
         Map.of("basePath", "/tmp/input"))
     .setPipesConfig(4, null)
     .setEmitStrategy(EmitStrategy.PASSBACK_ALL)
     .build();

 MergedConfig merged = ConfigMerger.merge(existingConfigPath, overrides);
 TikaJsonConfig tikaJsonConfig = merged.load();
 PipesParser.load(tikaJsonConfig, PipesConfig.load(tikaJsonConfig));
 
  • Field Details

    • GENERATED_FETCHER_PREFIX

      public static final String GENERATED_FETCHER_PREFIX
      Ids for host components the caller did not name (PipesForkParser's fetcher, for one). They live in the reserved namespace like every other host-wired component: the UUID makes them unguessable, but that is not the same as being unnameable.
      See Also:
    • GENERATED_EMITTER_PREFIX

      public static final String GENERATED_EMITTER_PREFIX
      See Also:
  • Method Details

    • mergeOrCreate

      public static ConfigMerger.MergeResult mergeOrCreate(Path existingConfig, ConfigOverrides overrides) throws IOException
      Merges overrides with an existing config, or creates a new config if none exists.

      For fetchers and emitters without explicit IDs in the overrides, UUID-based names are generated to avoid conflicts with user-configured components.

      Parameters:
      existingConfig - path to existing config (may be null)
      overrides - the overrides to apply
      Returns:
      MergeResult containing path to merged config and generated fetcher ID
      Throws:
      IOException - if file operations fail
    • merge

      public static ConfigMerger.MergedConfig merge(Path existingConfig, ConfigOverrides overrides) throws IOException
      Parameters:
      existingConfig - path to existing config (may be null)
      overrides - the overrides to apply
      Returns:
      the merged config JSON, env references unresolved, and the generated ids
      Throws:
      IOException - if the existing config can't be read