Distribution download plugin cleanup (#43461)

This commit addresses some post-review comments.

relates #43247
This commit is contained in:
Ryan Ernst 2019-06-24 09:34:32 -07:00
parent 5eb044e635
commit 97cd417829
2 changed files with 25 additions and 22 deletions

View File

@ -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<Project> {
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<Project> {
@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<Project> {
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<File> archiveGetter = downloadConfig::getSingleFile;
String extractDir = rootProject.getBuildDir().toPath().resolve("elasticsearch-distros").resolve(extractedConfigName).toString();
TaskProvider<Copy> extractTask = rootProject.getTasks().register(extractTaskName, Copy.class, copyTask -> {
copyTask.dependsOn(downloadConfig);
copyTask.doFirst(t -> rootProject.delete(extractDir));
copyTask.into(extractDir);
copyTask.from((Callable<FileTree>)() -> {
TaskProvider<Sync> extractTask = rootProject.getTasks().register(extractTaskName, Sync.class, syncTask -> {
syncTask.dependsOn(downloadConfig);
syncTask.into(extractDir);
syncTask.from((Callable<FileTree>)() -> {
File archiveFile = archiveGetter.get();
String archivePath = archiveFile.toString();
if (archivePath.endsWith(".zip")) {
@ -155,12 +157,12 @@ public class DistributionDownloadPlugin implements Plugin<Project> {
});
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<Project> {
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;
}

View File

@ -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> flavor;
private final Property<Boolean> 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() {