@@ -78,6 +78,8 @@ public abstract class AbstractLocalClusterFactory<S extends LocalClusterSpec, H
7878 private static final String TESTS_CLUSTER_FIPS_JAR_PATH_SYSPROP = "tests.cluster.fips.jars.path" ;
7979 private static final String TESTS_CLUSTER_DEBUG_ENABLED_SYSPROP = "tests.cluster.debug.enabled" ;
8080 private static final String ENABLE_DEBUG_JVM_ARGS = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=" ;
81+ private static final String ENTITLEMENT_POLICY_YAML = "entitlement-policy.yaml" ;
82+ private static final String PLUGIN_DESCRIPTOR_PROPERTIES = "plugin-descriptor.properties" ;
8183
8284 private final DistributionResolver distributionResolver ;
8385
@@ -662,7 +664,7 @@ private void installPlugins() {
662664 .findFirst ()
663665 .map (path -> {
664666 DefaultPluginInstallSpec installSpec = plugin .getValue ();
665- // Path the plugin archive with configured overrides if necessary
667+ // Patch the plugin archive with configured overrides if necessary
666668 if (installSpec .entitlementsOverride != null || installSpec .propertiesOverride != null ) {
667669 Path target ;
668670 try {
@@ -673,13 +675,13 @@ private void installPlugins() {
673675 ArchivePatcher patcher = new ArchivePatcher (path , target );
674676 if (installSpec .entitlementsOverride != null ) {
675677 patcher .override (
676- "entitlement-policy.yaml" ,
678+ ENTITLEMENT_POLICY_YAML ,
677679 original -> installSpec .entitlementsOverride .apply (original ).asStream ()
678680 );
679681 }
680682 if (installSpec .propertiesOverride != null ) {
681683 patcher .override (
682- "plugin-descriptor.properties" ,
684+ PLUGIN_DESCRIPTOR_PROPERTIES ,
683685 original -> installSpec .propertiesOverride .apply (original ).asStream ()
684686 );
685687 }
@@ -729,11 +731,11 @@ private void installModules() {
729731 .map (Path ::of )
730732 .toList ();
731733
732- spec .getModules ().forEach (module -> installModule (module , modulePaths ));
734+ spec .getModules ().forEach (( module , spec ) -> installModule (module , spec , modulePaths ));
733735 }
734736 }
735737
736- private void installModule (String moduleName , List <Path > modulePaths ) {
738+ private void installModule (String moduleName , DefaultPluginInstallSpec installSpec , List <Path > modulePaths ) {
737739 Path destination = distributionDir .resolve ("modules" ).resolve (moduleName );
738740 if (Files .notExists (destination )) {
739741 Path modulePath = modulePaths .stream ().filter (path -> path .endsWith (moduleName )).findFirst ().orElseThrow (() -> {
@@ -743,7 +745,7 @@ private void installModule(String moduleName, List<Path> modulePaths) {
743745 ? "project(xpackModule('" + moduleName .substring (7 ) + "'))"
744746 : "project(':modules:" + moduleName + "')" ;
745747
746- throw new RuntimeException (
748+ return new RuntimeException (
747749 "Unable to locate module '"
748750 + moduleName
749751 + "'. Ensure you've added the following to the build script for project '"
@@ -758,20 +760,34 @@ private void installModule(String moduleName, List<Path> modulePaths) {
758760 });
759761
760762 IOUtils .syncWithCopy (modulePath , destination );
763+ try {
764+ if (installSpec .entitlementsOverride != null ) {
765+ Path entitlementsFile = modulePath .resolve (ENTITLEMENT_POLICY_YAML );
766+ String original = Files .exists (entitlementsFile ) ? Files .readString (entitlementsFile ) : "" ;
767+ Path target = destination .resolve (ENTITLEMENT_POLICY_YAML );
768+ installSpec .entitlementsOverride .apply (original ).writeTo (target );
769+ }
770+ if (installSpec .propertiesOverride != null ) {
771+ Path propertiesFiles = modulePath .resolve (PLUGIN_DESCRIPTOR_PROPERTIES );
772+ String original = Files .exists (propertiesFiles ) ? Files .readString (propertiesFiles ) : "" ;
773+ Path target = destination .resolve (PLUGIN_DESCRIPTOR_PROPERTIES );
774+ installSpec .propertiesOverride .apply (original ).writeTo (target );
775+ }
776+ } catch (IOException e ) {
777+ throw new UncheckedIOException ("Error patching module '" + moduleName + "'" , e );
778+ }
761779
762- // Install any extended plugins
780+ // Install any extended modules
763781 Properties pluginProperties = new Properties ();
764782 try (
765- InputStream in = new BufferedInputStream (
766- new FileInputStream (modulePath .resolve ("plugin-descriptor.properties" ).toFile ())
767- )
783+ InputStream in = new BufferedInputStream (new FileInputStream (modulePath .resolve (PLUGIN_DESCRIPTOR_PROPERTIES ).toFile ()))
768784 ) {
769785 pluginProperties .load (in );
770786 String extendedProperty = pluginProperties .getProperty ("extended.plugins" );
771787 if (extendedProperty != null ) {
772- String [] extendedPlugins = extendedProperty .split ("," );
773- for (String plugin : extendedPlugins ) {
774- installModule (plugin , modulePaths );
788+ String [] extendedModules = extendedProperty .split ("," );
789+ for (String module : extendedModules ) {
790+ installModule (module , new DefaultPluginInstallSpec () , modulePaths );
775791 }
776792 }
777793 } catch (IOException e ) {
0 commit comments