Use exclusiveContent gradle feature for jdk and distro downloads (#53358)
The jdk and distribution download plugins create fake ivy repositories, and use group based repository filtering to ensure no other artifacts try to resolve against the fake repos. Currently this works by adding a blanket exclude to all repositories for the given group name. This commit changes to using the new exclusiveContent feature in Gradle to do the exclusion.
This commit is contained in:
parent
d8e70d4688
commit
4301c35783
|
@ -183,24 +183,21 @@ public class DistributionDownloadPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addIvyRepo(Project project, String name, String url, String group) {
|
private static void addIvyRepo(Project project, String name, String url, String group) {
|
||||||
project.getRepositories().ivy(ivyRepo -> {
|
IvyArtifactRepository ivyRepo = project.getRepositories().ivy(repo -> {
|
||||||
ivyRepo.setName(name);
|
repo.setName(name);
|
||||||
ivyRepo.setUrl(url);
|
repo.setUrl(url);
|
||||||
ivyRepo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
|
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
|
||||||
// this header is not a credential but we hack the capability to send this header to avoid polluting our download stats
|
// this header is not a credential but we hack the capability to send this header to avoid polluting our download stats
|
||||||
ivyRepo.credentials(HttpHeaderCredentials.class, creds -> {
|
repo.credentials(HttpHeaderCredentials.class, creds -> {
|
||||||
creds.setName("X-Elastic-No-KPI");
|
creds.setName("X-Elastic-No-KPI");
|
||||||
creds.setValue("1");
|
creds.setValue("1");
|
||||||
});
|
});
|
||||||
ivyRepo.getAuthentication().create("header", HttpHeaderAuthentication.class);
|
repo.getAuthentication().create("header", HttpHeaderAuthentication.class);
|
||||||
ivyRepo.patternLayout(layout -> layout.artifact("/downloads/elasticsearch/[module]-[revision](-[classifier]).[ext]"));
|
repo.patternLayout(layout -> layout.artifact("/downloads/elasticsearch/[module]-[revision](-[classifier]).[ext]"));
|
||||||
ivyRepo.content(content -> content.includeGroup(group));
|
|
||||||
});
|
});
|
||||||
project.getRepositories().all(repo -> {
|
project.getRepositories().exclusiveContent(exclusiveContentRepository -> {
|
||||||
if (repo.getName().equals(name) == false) {
|
exclusiveContentRepository.filter(config -> config.includeGroup(group));
|
||||||
// all other repos should ignore the special group name
|
exclusiveContentRepository.forRepositories(ivyRepo);
|
||||||
repo.content(content -> content.excludeGroup(group));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,16 +79,6 @@ public class JdkDownloadPlugin implements Plugin<Project> {
|
||||||
setupRootJdkDownload(project.getRootProject(), jdk);
|
setupRootJdkDownload(project.getRootProject(), jdk);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// all other repos should ignore the special jdk artifacts
|
|
||||||
project.getRootProject().getRepositories().all(repo -> {
|
|
||||||
if (repo.getName().startsWith(REPO_NAME_PREFIX) == false) {
|
|
||||||
repo.content(content -> {
|
|
||||||
content.excludeGroup("adoptopenjdk");
|
|
||||||
content.excludeGroup("openjdk");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -145,13 +135,16 @@ public class JdkDownloadPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the repository if we haven't already
|
// Define the repository if we haven't already
|
||||||
if (rootProject.getRepositories().findByName(repoName) == null) {
|
if (repositories.findByName(repoName) == null) {
|
||||||
repositories.ivy(ivyRepo -> {
|
IvyArtifactRepository ivyRepo = repositories.ivy(repo -> {
|
||||||
ivyRepo.setName(repoName);
|
repo.setName(repoName);
|
||||||
ivyRepo.setUrl(repoUrl);
|
repo.setUrl(repoUrl);
|
||||||
ivyRepo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
|
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
|
||||||
ivyRepo.patternLayout(layout -> layout.artifact(artifactPattern));
|
repo.patternLayout(layout -> layout.artifact(artifactPattern));
|
||||||
ivyRepo.content(content -> content.includeGroup(jdk.getVendor()));
|
});
|
||||||
|
repositories.exclusiveContent(exclusiveContentRepository -> {
|
||||||
|
exclusiveContentRepository.forRepositories(ivyRepo);
|
||||||
|
exclusiveContentRepository.filter(config -> config.includeGroup(groupName(jdk)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +254,11 @@ public class JdkDownloadPlugin implements Plugin<Project> {
|
||||||
: jdk.getPlatform();
|
: jdk.getPlatform();
|
||||||
String extension = jdk.getPlatform().equals("windows") ? "zip" : "tar.gz";
|
String extension = jdk.getPlatform().equals("windows") ? "zip" : "tar.gz";
|
||||||
|
|
||||||
return jdk.getVendor() + ":" + platformDep + ":" + jdk.getBaseVersion() + "@" + extension;
|
return groupName(jdk) + ":" + platformDep + ":" + jdk.getBaseVersion() + "@" + extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String groupName(Jdk jdk) {
|
||||||
|
return jdk.getVendor() + "_" + jdk.getMajor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String configName(String... parts) {
|
private static String configName(String... parts) {
|
||||||
|
|
Loading…
Reference in New Issue