Skip to content

Commit

Permalink
Improve testcluster distribution artifact handling (elastic#38933)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mark-vieira committed Feb 15, 2019
1 parent a6ebaf7 commit d7d7659
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 81 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.component.ComponentArtifactIdentifier;
import org.gradle.api.execution.TaskActionListener;
import org.gradle.api.execution.TaskExecutionListener;
import org.gradle.api.file.FileTree;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.plugins.ExtraPropertiesExtension;
import org.gradle.api.tasks.Sync;
import org.gradle.api.tasks.TaskState;

import java.io.File;
Expand All @@ -39,6 +42,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -87,6 +91,20 @@ public void apply(Project project) {
"Internal helper configuration used by cluster configuration to download " +
"ES distributions and plugins."
);
helperConfiguration.getIncoming().afterResolve(resolvableDependencies -> {
Set<ComponentArtifactIdentifier> nonZipComponents = resolvableDependencies.getArtifacts()
.getArtifacts()
.stream()
.filter(artifact -> artifact.getFile().getName().endsWith(".zip") == false)
.map(artifact -> artifact.getId())
.collect(Collectors.toSet());

if(nonZipComponents.isEmpty() == false) {
throw new IllegalStateException("Dependencies with non-zip artifacts found in configuration '" +
TestClustersPlugin.HELPER_CONFIGURATION_NAME + "': " + nonZipComponents
);
}
});

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

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

static File getTestClustersBuildDir(Project project) {
return new File(project.getRootProject().getBuildDir(), "testclusters");
static File getTestClustersConfigurationExtractDir(Project project) {
return new File(project.getRootProject().getBuildDir(), "testclusters/extract");
}

/**
Expand Down

0 comments on commit d7d7659

Please sign in to comment.