Skip to content

Commit 4301c35

Browse files
committed
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.
1 parent d8e70d4 commit 4301c35

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,21 @@ private void setupRootDownload(Project rootProject, ElasticsearchDistribution di
183183
}
184184

185185
private static void addIvyRepo(Project project, String name, String url, String group) {
186-
project.getRepositories().ivy(ivyRepo -> {
187-
ivyRepo.setName(name);
188-
ivyRepo.setUrl(url);
189-
ivyRepo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
186+
IvyArtifactRepository ivyRepo = project.getRepositories().ivy(repo -> {
187+
repo.setName(name);
188+
repo.setUrl(url);
189+
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
190190
// this header is not a credential but we hack the capability to send this header to avoid polluting our download stats
191-
ivyRepo.credentials(HttpHeaderCredentials.class, creds -> {
191+
repo.credentials(HttpHeaderCredentials.class, creds -> {
192192
creds.setName("X-Elastic-No-KPI");
193193
creds.setValue("1");
194194
});
195-
ivyRepo.getAuthentication().create("header", HttpHeaderAuthentication.class);
196-
ivyRepo.patternLayout(layout -> layout.artifact("/downloads/elasticsearch/[module]-[revision](-[classifier]).[ext]"));
197-
ivyRepo.content(content -> content.includeGroup(group));
195+
repo.getAuthentication().create("header", HttpHeaderAuthentication.class);
196+
repo.patternLayout(layout -> layout.artifact("/downloads/elasticsearch/[module]-[revision](-[classifier]).[ext]"));
198197
});
199-
project.getRepositories().all(repo -> {
200-
if (repo.getName().equals(name) == false) {
201-
// all other repos should ignore the special group name
202-
repo.content(content -> content.excludeGroup(group));
203-
}
198+
project.getRepositories().exclusiveContent(exclusiveContentRepository -> {
199+
exclusiveContentRepository.filter(config -> config.includeGroup(group));
200+
exclusiveContentRepository.forRepositories(ivyRepo);
204201
});
205202
}
206203

buildSrc/src/main/java/org/elasticsearch/gradle/JdkDownloadPlugin.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@ public void apply(Project project) {
7979
setupRootJdkDownload(project.getRootProject(), jdk);
8080
}
8181
});
82-
83-
// all other repos should ignore the special jdk artifacts
84-
project.getRootProject().getRepositories().all(repo -> {
85-
if (repo.getName().startsWith(REPO_NAME_PREFIX) == false) {
86-
repo.content(content -> {
87-
content.excludeGroup("adoptopenjdk");
88-
content.excludeGroup("openjdk");
89-
});
90-
}
91-
});
9282
}
9383

9484
@SuppressWarnings("unchecked")
@@ -145,13 +135,16 @@ private static void setupRootJdkDownload(Project rootProject, Jdk jdk) {
145135
}
146136

147137
// Define the repository if we haven't already
148-
if (rootProject.getRepositories().findByName(repoName) == null) {
149-
repositories.ivy(ivyRepo -> {
150-
ivyRepo.setName(repoName);
151-
ivyRepo.setUrl(repoUrl);
152-
ivyRepo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
153-
ivyRepo.patternLayout(layout -> layout.artifact(artifactPattern));
154-
ivyRepo.content(content -> content.includeGroup(jdk.getVendor()));
138+
if (repositories.findByName(repoName) == null) {
139+
IvyArtifactRepository ivyRepo = repositories.ivy(repo -> {
140+
repo.setName(repoName);
141+
repo.setUrl(repoUrl);
142+
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
143+
repo.patternLayout(layout -> layout.artifact(artifactPattern));
144+
});
145+
repositories.exclusiveContent(exclusiveContentRepository -> {
146+
exclusiveContentRepository.forRepositories(ivyRepo);
147+
exclusiveContentRepository.filter(config -> config.includeGroup(groupName(jdk)));
155148
});
156149
}
157150

@@ -261,7 +254,11 @@ private static String dependencyNotation(Jdk jdk) {
261254
: jdk.getPlatform();
262255
String extension = jdk.getPlatform().equals("windows") ? "zip" : "tar.gz";
263256

264-
return jdk.getVendor() + ":" + platformDep + ":" + jdk.getBaseVersion() + "@" + extension;
257+
return groupName(jdk) + ":" + platformDep + ":" + jdk.getBaseVersion() + "@" + extension;
258+
}
259+
260+
private static String groupName(Jdk jdk) {
261+
return jdk.getVendor() + "_" + jdk.getMajor();
265262
}
266263

267264
private static String configName(String... parts) {

0 commit comments

Comments
 (0)