From 97cd417829cdf43ed83583e2a8dce68285a7043c Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 24 Jun 2019 09:34:32 -0700 Subject: [PATCH] Distribution download plugin cleanup (#43461) This commit addresses some post-review comments. relates #43247 --- .../gradle/DistributionDownloadPlugin.java | 28 ++++++++++--------- .../gradle/ElasticsearchDistribution.java | 19 +++++++------ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java index 4bdac54982d..28748c00f46 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java @@ -35,7 +35,7 @@ import org.gradle.api.artifacts.repositories.IvyArtifactRepository; import org.gradle.api.credentials.HttpHeaderCredentials; import org.gradle.api.file.FileTree; import org.gradle.api.plugins.ExtraPropertiesExtension; -import org.gradle.api.tasks.Copy; +import org.gradle.api.tasks.Sync; import org.gradle.api.tasks.TaskProvider; import org.gradle.authentication.http.HttpHeaderAuthentication; @@ -54,7 +54,7 @@ import java.util.function.Supplier; */ public class DistributionDownloadPlugin implements Plugin { - private static final String FAKE_GROUP = "elasticsearch-distribution"; + private static final String FAKE_IVY_GROUP = "elasticsearch-distribution"; private static final String DOWNLOAD_REPO_NAME = "elasticsearch-downloads"; private BwcVersions bwcVersions; @@ -62,7 +62,11 @@ public class DistributionDownloadPlugin implements Plugin { @Override public void apply(Project project) { - distributionsContainer = project.container(ElasticsearchDistribution.class, name -> new ElasticsearchDistribution(name, project)); + distributionsContainer = project.container(ElasticsearchDistribution.class, name -> { + Configuration fileConfiguration = project.getConfigurations().create("es_distro_file_" + name); + Configuration extractedConfiguration = project.getConfigurations().create("es_distro_extracted_" + name); + return new ElasticsearchDistribution(name, project.getObjects(), fileConfiguration, extractedConfiguration); + }); project.getExtensions().add("elasticsearch_distributions", distributionsContainer); setupDownloadServiceRepo(project); @@ -112,18 +116,16 @@ public class DistributionDownloadPlugin implements Plugin { String extractedConfigName = "extracted_" + downloadConfigName; final Configuration downloadConfig = configurations.create(downloadConfigName); configurations.create(extractedConfigName); - Object distroDep = dependencyNotation(rootProject, distribution); - rootProject.getDependencies().add(downloadConfigName, distroDep); + rootProject.getDependencies().add(downloadConfigName, dependencyNotation(rootProject, distribution)); // add task for extraction, delaying resolving config until runtime if (distribution.getType() == Type.ARCHIVE || distribution.getType() == Type.INTEG_TEST_ZIP) { Supplier archiveGetter = downloadConfig::getSingleFile; String extractDir = rootProject.getBuildDir().toPath().resolve("elasticsearch-distros").resolve(extractedConfigName).toString(); - TaskProvider extractTask = rootProject.getTasks().register(extractTaskName, Copy.class, copyTask -> { - copyTask.dependsOn(downloadConfig); - copyTask.doFirst(t -> rootProject.delete(extractDir)); - copyTask.into(extractDir); - copyTask.from((Callable)() -> { + TaskProvider extractTask = rootProject.getTasks().register(extractTaskName, Sync.class, syncTask -> { + syncTask.dependsOn(downloadConfig); + syncTask.into(extractDir); + syncTask.from((Callable)() -> { File archiveFile = archiveGetter.get(); String archivePath = archiveFile.toString(); if (archivePath.endsWith(".zip")) { @@ -155,12 +157,12 @@ public class DistributionDownloadPlugin implements Plugin { }); ivyRepo.getAuthentication().create("header", HttpHeaderAuthentication.class); ivyRepo.patternLayout(layout -> layout.artifact("/downloads/elasticsearch/[module]-[revision](-[classifier]).[ext]")); - ivyRepo.content(content -> content.includeGroup(FAKE_GROUP)); + ivyRepo.content(content -> content.includeGroup(FAKE_IVY_GROUP)); }); project.getRepositories().all(repo -> { if (repo.getName().equals(DOWNLOAD_REPO_NAME) == false) { // all other repos should ignore the special group name - repo.content(content -> content.excludeGroup(FAKE_GROUP)); + repo.content(content -> content.excludeGroup(FAKE_IVY_GROUP)); } }); // TODO: need maven repo just for integ-test-zip, but only in external cases @@ -199,7 +201,7 @@ public class DistributionDownloadPlugin implements Plugin { extension = distribution.getPlatform() == Platform.WINDOWS ? "zip" : "tar.gz"; classifier = distribution.getPlatform() + "-" + classifier; } - return FAKE_GROUP + ":elasticsearch" + (distribution.getFlavor() == Flavor.OSS ? "-oss:" : ":") + return FAKE_IVY_GROUP + ":elasticsearch" + (distribution.getFlavor() == Flavor.OSS ? "-oss:" : ":") + distribution.getVersion() + ":" + classifier + "@" + extension; } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchDistribution.java b/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchDistribution.java index 5d667c40987..ac18209a433 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchDistribution.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchDistribution.java @@ -20,8 +20,8 @@ package org.elasticsearch.gradle; import org.gradle.api.Buildable; -import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; +import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.Property; import org.gradle.api.tasks.TaskDependency; @@ -107,17 +107,18 @@ public class ElasticsearchDistribution implements Buildable { private final Property flavor; private final Property bundledJdk; - ElasticsearchDistribution(String name, Project project) { + ElasticsearchDistribution(String name, ObjectFactory objectFactory, Configuration fileConfiguration, + Configuration extractedConfiguration) { this.name = name; - this.configuration = project.getConfigurations().create("es_distro_file_" + name); - this.version = project.getObjects().property(Version.class); + this.configuration = fileConfiguration; + this.version = objectFactory.property(Version.class); this.version.convention(Version.fromString(VersionProperties.getElasticsearch())); - this.type = project.getObjects().property(Type.class); + this.type = objectFactory.property(Type.class); this.type.convention(Type.ARCHIVE); - this.platform = project.getObjects().property(Platform.class); - this.flavor = project.getObjects().property(Flavor.class); - this.bundledJdk = project.getObjects().property(Boolean.class); - this.extracted = new Extracted(project.getConfigurations().create("es_distro_extracted_" + name)); + this.platform = objectFactory.property(Platform.class); + this.flavor = objectFactory.property(Flavor.class); + this.bundledJdk = objectFactory.property(Boolean.class); + this.extracted = new Extracted(extractedConfiguration); } public String getName() {