Skip to content

Commit ad012c8

Browse files
authored
Improve testcluster distribution artifact handling (#38933)
This commit moves validation logic for ensuring our testclusters configuration doesn't contain unexpected artifacts into the plugin itself. This change allows us to remove the custom copy task implementation altogether. Additionally, the error message has been improved to display component ids in addition to the artifacts to make it easier to figure out what actual dependency is at fault.
1 parent 5624eee commit ad012c8

File tree

2 files changed

+30
-81
lines changed

2 files changed

+30
-81
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/SyncTestClustersConfiguration.java

Lines changed: 0 additions & 77 deletions
This file was deleted.

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClustersPlugin.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
import org.gradle.api.Project;
2626
import org.gradle.api.Task;
2727
import org.gradle.api.artifacts.Configuration;
28+
import org.gradle.api.artifacts.component.ComponentArtifactIdentifier;
2829
import org.gradle.api.execution.TaskActionListener;
2930
import org.gradle.api.execution.TaskExecutionListener;
31+
import org.gradle.api.file.FileTree;
3032
import org.gradle.api.logging.Logger;
3133
import org.gradle.api.logging.Logging;
3234
import org.gradle.api.plugins.ExtraPropertiesExtension;
35+
import org.gradle.api.tasks.Sync;
3336
import org.gradle.api.tasks.TaskState;
3437

3538
import java.io.File;
@@ -39,6 +42,7 @@
3942
import java.util.List;
4043
import java.util.Map;
4144
import java.util.Set;
45+
import java.util.concurrent.Callable;
4246
import java.util.concurrent.ConcurrentHashMap;
4347
import java.util.concurrent.ExecutorService;
4448
import java.util.concurrent.Executors;
@@ -87,6 +91,20 @@ public void apply(Project project) {
8791
"Internal helper configuration used by cluster configuration to download " +
8892
"ES distributions and plugins."
8993
);
94+
helperConfiguration.getIncoming().afterResolve(resolvableDependencies -> {
95+
Set<ComponentArtifactIdentifier> nonZipComponents = resolvableDependencies.getArtifacts()
96+
.getArtifacts()
97+
.stream()
98+
.filter(artifact -> artifact.getFile().getName().endsWith(".zip") == false)
99+
.map(artifact -> artifact.getId())
100+
.collect(Collectors.toSet());
101+
102+
if(nonZipComponents.isEmpty() == false) {
103+
throw new IllegalStateException("Dependencies with non-zip artifacts found in configuration '" +
104+
TestClustersPlugin.HELPER_CONFIGURATION_NAME + "': " + nonZipComponents
105+
);
106+
}
107+
});
90108

91109
// When running in the Daemon it's possible for this to hold references to past
92110
usedClusters.clear();
@@ -98,7 +116,15 @@ public void apply(Project project) {
98116
// the clusters will look for artifacts there based on the naming conventions.
99117
// Tasks that use a cluster will add this as a dependency automatically so it's guaranteed to run early in
100118
// the build.
101-
rootProject.getTasks().create(SYNC_ARTIFACTS_TASK_NAME, SyncTestClustersConfiguration.class);
119+
rootProject.getTasks().create(SYNC_ARTIFACTS_TASK_NAME, Sync.class, sync -> {
120+
sync.from((Callable<List<FileTree>>) () ->
121+
helperConfiguration.getFiles()
122+
.stream()
123+
.map(project::zipTree)
124+
.collect(Collectors.toList())
125+
);
126+
sync.into(new File(getTestClustersConfigurationExtractDir(project), "zip"));
127+
});
102128

103129
// When we know what tasks will run, we claim the clusters of those task to differentiate between clusters
104130
// that are defined in the build script and the ones that will actually be used in this invocation of gradle
@@ -129,7 +155,7 @@ private NamedDomainObjectContainer<ElasticsearchNode> createTestClustersContaine
129155
project.getPath(),
130156
name,
131157
GradleServicesAdapter.getInstance(project),
132-
SyncTestClustersConfiguration.getTestClustersConfigurationExtractDir(project),
158+
getTestClustersConfigurationExtractDir(project),
133159
new File(project.getBuildDir(), "testclusters")
134160
)
135161
);
@@ -249,8 +275,8 @@ public void beforeExecute(Task task) {}
249275
);
250276
}
251277

252-
static File getTestClustersBuildDir(Project project) {
253-
return new File(project.getRootProject().getBuildDir(), "testclusters");
278+
static File getTestClustersConfigurationExtractDir(Project project) {
279+
return new File(project.getRootProject().getBuildDir(), "testclusters/extract");
254280
}
255281

256282
/**

0 commit comments

Comments
 (0)