@@ -77,6 +77,8 @@ public abstract class AbstractLocalClusterFactory<S extends LocalClusterSpec, H
7777 private static final String TESTS_CLUSTER_FIPS_JAR_PATH_SYSPROP = "tests.cluster.fips.jars.path" ;
7878 private static final String TESTS_CLUSTER_DEBUG_ENABLED_SYSPROP = "tests.cluster.debug.enabled" ;
7979 private static final String ENABLE_DEBUG_JVM_ARGS = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=" ;
80+ private static final String ENTITLEMENT_POLICY_YAML = "entitlement-policy.yaml" ;
81+ private static final String PLUGIN_DESCRIPTOR_PROPERTIES = "plugin-descriptor.properties" ;
8082
8183 private final DistributionResolver distributionResolver ;
8284
@@ -660,7 +662,7 @@ private void installPlugins() {
660662 .findFirst ()
661663 .map (path -> {
662664 DefaultPluginInstallSpec installSpec = plugin .getValue ();
663- // Path the plugin archive with configured overrides if necessary
665+ // Patch the plugin archive with configured overrides if necessary
664666 if (installSpec .entitlementsOverride != null || installSpec .propertiesOverride != null ) {
665667 Path target ;
666668 try {
@@ -671,13 +673,13 @@ private void installPlugins() {
671673 ArchivePatcher patcher = new ArchivePatcher (path , target );
672674 if (installSpec .entitlementsOverride != null ) {
673675 patcher .override (
674- "entitlement-policy.yaml" ,
676+ ENTITLEMENT_POLICY_YAML ,
675677 original -> installSpec .entitlementsOverride .apply (original ).asStream ()
676678 );
677679 }
678680 if (installSpec .propertiesOverride != null ) {
679681 patcher .override (
680- "plugin-descriptor.properties" ,
682+ PLUGIN_DESCRIPTOR_PROPERTIES ,
681683 original -> installSpec .propertiesOverride .apply (original ).asStream ()
682684 );
683685 }
@@ -727,11 +729,11 @@ private void installModules() {
727729 .map (Path ::of )
728730 .toList ();
729731
730- spec .getModules ().forEach (module -> installModule (module , modulePaths ));
732+ spec .getModules ().forEach (( module , spec ) -> installModule (module , spec , modulePaths ));
731733 }
732734 }
733735
734- private void installModule (String moduleName , List <Path > modulePaths ) {
736+ private void installModule (String moduleName , DefaultPluginInstallSpec installSpec , List <Path > modulePaths ) {
735737 Path destination = distributionDir .resolve ("modules" ).resolve (moduleName );
736738 if (Files .notExists (destination )) {
737739 Path modulePath = modulePaths .stream ().filter (path -> path .endsWith (moduleName )).findFirst ().orElseThrow (() -> {
@@ -741,7 +743,7 @@ private void installModule(String moduleName, List<Path> modulePaths) {
741743 ? "project(xpackModule('" + moduleName .substring (7 ) + "'))"
742744 : "project(':modules:" + moduleName + "')" ;
743745
744- throw new RuntimeException (
746+ return new RuntimeException (
745747 "Unable to locate module '"
746748 + moduleName
747749 + "'. Ensure you've added the following to the build script for project '"
@@ -756,20 +758,34 @@ private void installModule(String moduleName, List<Path> modulePaths) {
756758 });
757759
758760 IOUtils .syncWithCopy (modulePath , destination );
761+ try {
762+ if (installSpec .entitlementsOverride != null ) {
763+ Path entitlementsFile = modulePath .resolve (ENTITLEMENT_POLICY_YAML );
764+ String original = Files .exists (entitlementsFile ) ? Files .readString (entitlementsFile ) : "" ;
765+ Path target = destination .resolve (ENTITLEMENT_POLICY_YAML );
766+ installSpec .entitlementsOverride .apply (original ).writeTo (target );
767+ }
768+ if (installSpec .propertiesOverride != null ) {
769+ Path propertiesFiles = modulePath .resolve (PLUGIN_DESCRIPTOR_PROPERTIES );
770+ String original = Files .exists (propertiesFiles ) ? Files .readString (propertiesFiles ) : "" ;
771+ Path target = destination .resolve (PLUGIN_DESCRIPTOR_PROPERTIES );
772+ installSpec .propertiesOverride .apply (original ).writeTo (target );
773+ }
774+ } catch (IOException e ) {
775+ throw new UncheckedIOException ("Error patching module '" + moduleName + "'" , e );
776+ }
759777
760- // Install any extended plugins
778+ // Install any extended modules
761779 Properties pluginProperties = new Properties ();
762780 try (
763- InputStream in = new BufferedInputStream (
764- new FileInputStream (modulePath .resolve ("plugin-descriptor.properties" ).toFile ())
765- )
781+ InputStream in = new BufferedInputStream (new FileInputStream (modulePath .resolve (PLUGIN_DESCRIPTOR_PROPERTIES ).toFile ()))
766782 ) {
767783 pluginProperties .load (in );
768784 String extendedProperty = pluginProperties .getProperty ("extended.plugins" );
769785 if (extendedProperty != null ) {
770- String [] extendedPlugins = extendedProperty .split ("," );
771- for (String plugin : extendedPlugins ) {
772- installModule (plugin , modulePaths );
786+ String [] extendedModules = extendedProperty .split ("," );
787+ for (String module : extendedModules ) {
788+ installModule (module , new DefaultPluginInstallSpec () , modulePaths );
773789 }
774790 }
775791 } catch (IOException e ) {
0 commit comments