2020import org .elasticsearch .gradle .testclusters .ElasticsearchCluster ;
2121import org .elasticsearch .gradle .testclusters .TestClustersPlugin ;
2222import org .elasticsearch .gradle .util .GradleUtils ;
23+ import org .gradle .api .Action ;
24+ import org .gradle .api .GradleException ;
25+ import org .gradle .api .Named ;
2326import org .gradle .api .NamedDomainObjectContainer ;
2427import org .gradle .api .Plugin ;
2528import org .gradle .api .Project ;
2629
30+ import java .util .HashMap ;
2731import java .util .Optional ;
2832
2933/**
@@ -47,6 +51,23 @@ public void apply(Project project) {
4751 project .getConfigurations ().getByName ("testImplementation" ).getDependencies ().clear ();
4852 var extension = project .getExtensions ().getByType (PluginPropertiesExtension .class );
4953
54+ extension .getExtendedPluginsContainer ().whenObjectAdded ((Action <Named >) named -> {
55+ if (ExtendedPluginInternal .class .isAssignableFrom (named .getClass ()) == false ) {
56+ throw new GradleException (
57+ "Using `extendedPlugins` is not supported for internal plugins. Use `extendedPluginProjects` instead."
58+ );
59+ }
60+ });
61+ NamedDomainObjectContainer <ExtendedPluginInternal > container = project .container (
62+ ExtendedPluginInternal .class ,
63+ name -> new ExtendedPluginInternal (name )
64+ );
65+ container .whenObjectAdded (
66+ internal -> extension .getExtendedPluginsContainer ().add (internal )
67+ );
68+
69+ HashMap <String , String > value = new HashMap <>();
70+ extension .getExtensions ().add ("extendedPluginProjects" , container );
5071 // We've ported this from multiple build scripts where we see this pattern into
5172 // an extension method as a first step of consolidation.
5273 // We might want to port this into a general pattern later on.
@@ -86,11 +107,12 @@ public void doCall() {
86107 NamedDomainObjectContainer <ElasticsearchCluster > testClusters = (NamedDomainObjectContainer <ElasticsearchCluster >) project
87108 .getExtensions ()
88109 .getByName (TestClustersPlugin .EXTENSION_NAME );
89- p . getExtensions (). getByType ( PluginPropertiesExtension . class ) .getExtendedPlugins ().forEach (pluginName -> {
110+ extension .getExtendedPlugins ().forEach (pluginName -> {
90111 // Auto add any dependent modules
91- findModulePath (project , pluginName ).ifPresent (
92- path -> testClusters .configureEach (elasticsearchCluster -> elasticsearchCluster .module (path ))
93- );
112+ findModulePath (project , pluginName ).ifPresent (path -> {
113+ System .out .println ("module name:" + pluginName + " path: '" + path + "'" );
114+ testClusters .configureEach (elasticsearchCluster -> elasticsearchCluster .module (path ));
115+ });
94116 });
95117 });
96118 }
@@ -129,4 +151,20 @@ protected static void addNoticeGeneration(final Project project, PluginPropertie
129151 bundleSpec .from (generateNotice );
130152 }
131153 }
154+
155+ public static class ExtendedPluginInternal extends PluginPropertiesExtension .ExtendedPlugin {
156+ String projectPath ;
157+
158+ public ExtendedPluginInternal (String name ) {
159+ super (name );
160+ }
161+
162+ public String getProjectPath () {
163+ return projectPath ;
164+ }
165+
166+ public void setProjectPath (String projectPath ) {
167+ this .projectPath = projectPath ;
168+ }
169+ }
132170}
0 commit comments