@@ -73,6 +73,8 @@ public abstract class AbstractLocalClusterFactory<S extends LocalClusterSpec, H
7373 private static final String TESTS_CLUSTER_FIPS_JAR_PATH_SYSPROP = "tests.cluster.fips.jars.path" ;
7474 private static final String TESTS_CLUSTER_DEBUG_ENABLED_SYSPROP = "tests.cluster.debug.enabled" ;
7575 private static final String ENABLE_DEBUG_JVM_ARGS = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=" ;
76+ private static final String ENTITLEMENT_POLICY_YAML = "entitlement-policy.yaml" ;
77+ private static final String PLUGIN_DESCRIPTOR_PROPERTIES = "plugin-descriptor.properties" ;
7678
7779 private final DistributionResolver distributionResolver ;
7880
@@ -611,7 +613,7 @@ private void installPlugins() {
611613 .findFirst ()
612614 .map (path -> {
613615 DefaultPluginInstallSpec installSpec = plugin .getValue ();
614- // Path the plugin archive with configured overrides if necessary
616+ // Patch the plugin archive with configured overrides if necessary
615617 if (installSpec .entitlementsOverride != null || installSpec .propertiesOverride != null ) {
616618 Path target ;
617619 try {
@@ -622,13 +624,13 @@ private void installPlugins() {
622624 ArchivePatcher patcher = new ArchivePatcher (path , target );
623625 if (installSpec .entitlementsOverride != null ) {
624626 patcher .override (
625- "entitlement-policy.yaml" ,
627+ ENTITLEMENT_POLICY_YAML ,
626628 original -> installSpec .entitlementsOverride .apply (original ).asStream ()
627629 );
628630 }
629631 if (installSpec .propertiesOverride != null ) {
630632 patcher .override (
631- "plugin-descriptor.properties" ,
633+ PLUGIN_DESCRIPTOR_PROPERTIES ,
632634 original -> installSpec .propertiesOverride .apply (original ).asStream ()
633635 );
634636 }
@@ -678,11 +680,11 @@ private void installModules() {
678680 .map (Path ::of )
679681 .toList ();
680682
681- spec .getModules ().forEach (module -> installModule (module , modulePaths ));
683+ spec .getModules ().forEach (( module , spec ) -> installModule (module , spec , modulePaths ));
682684 }
683685 }
684686
685- private void installModule (String moduleName , List <Path > modulePaths ) {
687+ private void installModule (String moduleName , DefaultPluginInstallSpec installSpec , List <Path > modulePaths ) {
686688 Path destination = distributionDir .resolve ("modules" ).resolve (moduleName );
687689 if (Files .notExists (destination )) {
688690 Path modulePath = modulePaths .stream ().filter (path -> path .endsWith (moduleName )).findFirst ().orElseThrow (() -> {
@@ -692,7 +694,7 @@ private void installModule(String moduleName, List<Path> modulePaths) {
692694 ? "project(xpackModule('" + moduleName .substring (7 ) + "'))"
693695 : "project(':modules:" + moduleName + "')" ;
694696
695- throw new RuntimeException (
697+ return new RuntimeException (
696698 "Unable to locate module '"
697699 + moduleName
698700 + "'. Ensure you've added the following to the build script for project '"
@@ -707,20 +709,34 @@ private void installModule(String moduleName, List<Path> modulePaths) {
707709 });
708710
709711 IOUtils .syncWithCopy (modulePath , destination );
712+ try {
713+ if (installSpec .entitlementsOverride != null ) {
714+ Path entitlementsFile = modulePath .resolve (ENTITLEMENT_POLICY_YAML );
715+ String original = Files .exists (entitlementsFile ) ? Files .readString (entitlementsFile ) : "" ;
716+ Path target = destination .resolve (ENTITLEMENT_POLICY_YAML );
717+ installSpec .entitlementsOverride .apply (original ).writeTo (target );
718+ }
719+ if (installSpec .propertiesOverride != null ) {
720+ Path propertiesFiles = modulePath .resolve (PLUGIN_DESCRIPTOR_PROPERTIES );
721+ String original = Files .exists (propertiesFiles ) ? Files .readString (propertiesFiles ) : "" ;
722+ Path target = destination .resolve (PLUGIN_DESCRIPTOR_PROPERTIES );
723+ installSpec .propertiesOverride .apply (original ).writeTo (target );
724+ }
725+ } catch (IOException e ) {
726+ throw new UncheckedIOException ("Error patching module '" + moduleName + "'" , e );
727+ }
710728
711- // Install any extended plugins
729+ // Install any extended modules
712730 Properties pluginProperties = new Properties ();
713731 try (
714- InputStream in = new BufferedInputStream (
715- new FileInputStream (modulePath .resolve ("plugin-descriptor.properties" ).toFile ())
716- )
732+ InputStream in = new BufferedInputStream (new FileInputStream (modulePath .resolve (PLUGIN_DESCRIPTOR_PROPERTIES ).toFile ()))
717733 ) {
718734 pluginProperties .load (in );
719735 String extendedProperty = pluginProperties .getProperty ("extended.plugins" );
720736 if (extendedProperty != null ) {
721- String [] extendedPlugins = extendedProperty .split ("," );
722- for (String plugin : extendedPlugins ) {
723- installModule (plugin , modulePaths );
737+ String [] extendedModules = extendedProperty .split ("," );
738+ for (String module : extendedModules ) {
739+ installModule (module , new DefaultPluginInstallSpec () , modulePaths );
724740 }
725741 }
726742 } catch (IOException e ) {
0 commit comments