23
23
import org .elasticsearch .gradle .VersionProperties ;
24
24
import org .elasticsearch .gradle .http .WaitForHttpResource ;
25
25
import org .elasticsearch .gradle .info .BuildParams ;
26
+ import org .elasticsearch .gradle .transform .UnzipTransform ;
26
27
import org .elasticsearch .gradle .util .Pair ;
27
28
import org .gradle .api .Action ;
28
29
import org .gradle .api .Named ;
29
30
import org .gradle .api .NamedDomainObjectContainer ;
30
31
import org .gradle .api .Project ;
31
32
import org .gradle .api .artifacts .Configuration ;
33
+ import org .gradle .api .artifacts .Dependency ;
34
+ import org .gradle .api .artifacts .type .ArtifactTypeDefinition ;
35
+ import org .gradle .api .attributes .Attribute ;
32
36
import org .gradle .api .file .ArchiveOperations ;
37
+ import org .gradle .api .file .ConfigurableFileCollection ;
38
+ import org .gradle .api .file .FileCollection ;
33
39
import org .gradle .api .file .FileSystemOperations ;
34
40
import org .gradle .api .file .FileTree ;
35
41
import org .gradle .api .file .RegularFile ;
42
+ import org .gradle .api .internal .artifacts .ArtifactAttributes ;
36
43
import org .gradle .api .logging .Logger ;
37
44
import org .gradle .api .logging .Logging ;
38
45
import org .gradle .api .provider .Provider ;
64
71
import java .util .Arrays ;
65
72
import java .util .Collection ;
66
73
import java .util .Collections ;
67
- import java .util .Comparator ;
68
74
import java .util .HashMap ;
69
75
import java .util .HashSet ;
70
76
import java .util .LinkedHashMap ;
@@ -126,6 +132,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
126
132
127
133
private final LinkedHashMap <String , Predicate <TestClusterConfiguration >> waitConditions = new LinkedHashMap <>();
128
134
private final Map <String , Configuration > pluginAndModuleConfigurations = new HashMap <>();
135
+ private final ConfigurableFileCollection pluginAndModuleConfiguration ;
129
136
private final List <Provider <File >> plugins = new ArrayList <>();
130
137
private final List <Provider <File >> modules = new ArrayList <>();
131
138
final LazyPropertyMap <String , CharSequence > settings = new LazyPropertyMap <>("Settings" , this );
@@ -161,6 +168,8 @@ public class ElasticsearchNode implements TestClusterConfiguration {
161
168
private String keystorePassword = "" ;
162
169
private boolean preserveDataDir = false ;
163
170
171
+ private Attribute <Boolean > bundleAttribute = Attribute .of ("bundle" , Boolean .class );
172
+
164
173
ElasticsearchNode (
165
174
String clusterName ,
166
175
String path ,
@@ -195,8 +204,10 @@ public class ElasticsearchNode implements TestClusterConfiguration {
195
204
waitConditions .put ("ports files" , this ::checkPortsFilesExistWithDelay );
196
205
defaultConfig .put ("cluster.name" , clusterName );
197
206
207
+ pluginAndModuleConfiguration = project .getObjects ().fileCollection ();
198
208
setTestDistribution (TestDistribution .INTEG_TEST );
199
209
setVersion (VersionProperties .getElasticsearch ());
210
+ configureArtifactTransforms ();
200
211
}
201
212
202
213
@ Input
@@ -281,11 +292,15 @@ Collection<Configuration> getPluginAndModuleConfigurations() {
281
292
// creates a configuration to depend on the given plugin project, then wraps that configuration
282
293
// to grab the zip as a file provider
283
294
private Provider <RegularFile > maybeCreatePluginOrModuleDependency (String path ) {
284
- Configuration configuration = pluginAndModuleConfigurations .computeIfAbsent (
285
- path ,
286
- key -> project .getConfigurations ()
287
- .detachedConfiguration (project .getDependencies ().project (Map .of ("path" , path , "configuration" , "zip" )))
288
- );
295
+ Configuration configuration = pluginAndModuleConfigurations .computeIfAbsent (path , key -> {
296
+ Dependency bundleDependency = this .project .getDependencies ().project (Map .of ("path" , path , "configuration" , "zip" ));
297
+ return project .getConfigurations ().detachedConfiguration (bundleDependency );
298
+ });
299
+
300
+ /**
301
+ * dependencies.create(files(provider { println("provider"); File(".") }))
302
+ *
303
+ * */
289
304
Provider <File > fileProvider = configuration .getElements ()
290
305
.map (
291
306
s -> s .stream ()
@@ -299,6 +314,7 @@ private Provider<RegularFile> maybeCreatePluginOrModuleDependency(String path) {
299
314
@ Override
300
315
public void plugin (Provider <RegularFile > plugin ) {
301
316
checkFrozen ();
317
+ registerExtractedConfig (plugin );
302
318
this .plugins .add (plugin .map (RegularFile ::getAsFile ));
303
319
}
304
320
@@ -310,9 +326,32 @@ public void plugin(String pluginProjectPath) {
310
326
@ Override
311
327
public void module (Provider <RegularFile > module ) {
312
328
checkFrozen ();
329
+ registerExtractedConfig (module );
313
330
this .modules .add (module .map (RegularFile ::getAsFile ));
314
331
}
315
332
333
+ private void registerExtractedConfig (Provider <RegularFile > pluginProvider ) {
334
+ Dependency pluginDependency = this .project .getDependencies ().create (project .files (pluginProvider ));
335
+ Configuration extractedConfig = project .getConfigurations ().detachedConfiguration (pluginDependency );
336
+ extractedConfig .getAttributes ().attribute (ArtifactAttributes .ARTIFACT_FORMAT , ArtifactTypeDefinition .DIRECTORY_TYPE );
337
+ extractedConfig .getAttributes ().attribute (bundleAttribute , true );
338
+ pluginAndModuleConfiguration .from (extractedConfig );
339
+ }
340
+
341
+ private void configureArtifactTransforms () {
342
+ project .getDependencies ().getAttributesSchema ().attribute (bundleAttribute );
343
+ project .getDependencies ().getArtifactTypes ().maybeCreate (ArtifactTypeDefinition .ZIP_TYPE );
344
+ project .getDependencies ().registerTransform (UnzipTransform .class , transformSpec -> {
345
+ transformSpec .getFrom ()
346
+ .attribute (ArtifactAttributes .ARTIFACT_FORMAT , ArtifactTypeDefinition .ZIP_TYPE )
347
+ .attribute (bundleAttribute , true );
348
+ transformSpec .getTo ()
349
+ .attribute (ArtifactAttributes .ARTIFACT_FORMAT , ArtifactTypeDefinition .DIRECTORY_TYPE )
350
+ .attribute (bundleAttribute , true );
351
+ transformSpec .getParameters ().setAsFiletreeOutput (true );
352
+ });
353
+ }
354
+
316
355
@ Override
317
356
public void module (String moduleProjectPath ) {
318
357
module (maybeCreatePluginOrModuleDependency (moduleProjectPath ));
@@ -1325,26 +1364,15 @@ private Path getExtractedDistributionDir() {
1325
1364
return distributions .get (currentDistro ).getExtracted ().getSingleFile ().toPath ();
1326
1365
}
1327
1366
1328
- private List <File > getInstalledFileSet (Action <? super PatternFilterable > filter ) {
1329
- return Stream .concat (plugins .stream ().map (Provider ::get ), modules .stream ().map (Provider ::get ))
1330
- .filter (File ::exists )
1331
- // TODO: We may be able to simplify this with Gradle 5.6
1332
- // https://docs.gradle.org/nightly/release-notes.html#improved-handling-of-zip-archives-on-classpaths
1333
- .map (zipFile -> archiveOperations .zipTree (zipFile ).matching (filter ))
1334
- .flatMap (tree -> tree .getFiles ().stream ())
1335
- .sorted (Comparator .comparing (File ::getName ))
1336
- .collect (Collectors .toList ());
1337
- }
1338
-
1339
1367
@ Classpath
1340
- public List < File > getInstalledClasspath () {
1341
- return getInstalledFileSet ( filter -> filter . include ( "**/* .jar" ));
1368
+ public FileCollection getInstalledClasspath () {
1369
+ return pluginAndModuleConfiguration . filter ( f -> f . isDirectory () == false && f . getName (). endsWith ( " .jar" ));
1342
1370
}
1343
1371
1344
1372
@ InputFiles
1345
1373
@ PathSensitive (PathSensitivity .RELATIVE )
1346
- public List < File > getInstalledFiles () {
1347
- return getInstalledFileSet ( filter -> filter . exclude ( "**/* .jar" ));
1374
+ public FileCollection getInstalledFiles () {
1375
+ return pluginAndModuleConfiguration . filter ( f -> f . isDirectory () == false && f . getName (). endsWith ( " .jar" ) == false );
1348
1376
}
1349
1377
1350
1378
@ Classpath
0 commit comments