Skip to content

Commit

Permalink
Keep API for resolution provider
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Nov 9, 2023
1 parent 5fa5f48 commit 3f4f108
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public void apply(Project project) {
* BWC versions are resolved as project to projects under `:distribution:bwc`.
*/
private void registerInternalDistributionResolutions(List<DistributionResolution> resolutions) {
resolutions.add(new DistributionResolution("local-build", (dependencies, distribution) -> {
resolutions.add(new DistributionResolution("local-build", (project, distribution) -> {
if (isCurrentVersion(distribution)) {
// non-external project, so depend on local build
return new ProjectBasedDistributionDependency(
config -> projectDependency(dependencies, distributionProjectPath(distribution), config)
config -> projectDependency(project.getDependencies(), distributionProjectPath(distribution), config)
);
}
return null;
Expand All @@ -90,7 +90,7 @@ private void registerInternalDistributionResolutions(List<DistributionResolution
}
String projectConfig = getProjectConfig(distribution, unreleasedInfo);
return new ProjectBasedDistributionDependency(
(config) -> projectDependency(project, unreleasedInfo.gradleProjectPath(), projectConfig)
(config) -> projectDependency(project.getDependencies(), unreleasedInfo.gradleProjectPath(), projectConfig)
);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ private void setupDistributionContainer(Project project, Property<Boolean> docke
Configuration extractedConfiguration = project.getConfigurations().create(DISTRO_EXTRACTED_CONFIG_PREFIX + name);
extractedConfiguration.getAttributes()
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
DependencyHandler dependencies = project.getDependencies();
return new ElasticsearchDistribution(
name,
project.getObjects(),
dockerAvailability,
project.getObjects().fileCollection().from(fileConfiguration),
project.getObjects().fileCollection().from(extractedConfiguration),
new FinalizeDistributionAction(distributionsResolutionStrategies, dependencies)
new FinalizeDistributionAction(distributionsResolutionStrategies, project)
);
});
project.getExtensions().add(CONTAINER_NAME, distributionsContainer);
Expand Down Expand Up @@ -133,30 +132,31 @@ private static void setupDownloadServiceRepo(Project project) {
addIvyRepo(project, SNAPSHOT_REPO_NAME, "https://snapshots-no-kpi.elastic.co", FAKE_SNAPSHOT_IVY_GROUP);
}

private record FinalizeDistributionAction(List<DistributionResolution> resolutionList, DependencyHandler dependencies)
private record FinalizeDistributionAction(List<DistributionResolution> resolutionList, Project project)
implements
Action<ElasticsearchDistribution> {
@Override

public void execute(ElasticsearchDistribution distro) {
finalizeDistributionDependencies(dependencies, distro);
finalizeDistributionDependencies(project, distro);
}

private void finalizeDistributionDependencies(DependencyHandler dependencies, ElasticsearchDistribution distribution) {
private void finalizeDistributionDependencies(Project project, ElasticsearchDistribution distribution) {
// for the distribution as a file, just depend on the artifact directly
DistributionDependency distributionDependency = resolveDependencyNotation(dependencies, distribution);
dependencies.add(DISTRO_CONFIG_PREFIX + distribution.getName(), distributionDependency.getDefaultNotation());
DistributionDependency distributionDependency = resolveDependencyNotation(project, distribution);
project.getDependencies().add(DISTRO_CONFIG_PREFIX + distribution.getName(), distributionDependency.getDefaultNotation());
// no extraction needed for rpm, deb or docker
if (distribution.getType().shouldExtract()) {
// The extracted configuration depends on the artifact directly but has
// an artifact transform registered to resolve it as an unpacked folder.
dependencies.add(DISTRO_EXTRACTED_CONFIG_PREFIX + distribution.getName(), distributionDependency.getExtractedNotation());
project.getDependencies()
.add(DISTRO_EXTRACTED_CONFIG_PREFIX + distribution.getName(), distributionDependency.getExtractedNotation());
}
}

private DistributionDependency resolveDependencyNotation(DependencyHandler handler, ElasticsearchDistribution distro) {
private DistributionDependency resolveDependencyNotation(Project project, ElasticsearchDistribution distro) {
return resolutionList.stream()
.map(r -> r.getResolver().resolve(handler, distro))
.map(r -> r.getResolver().resolve(project, distro))
.filter(d -> d != null)
.findFirst()
.orElseGet(() -> DistributionDependency.of(dependencyNotation(distro)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@

package org.elasticsearch.gradle;

import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.Project;

public class DistributionResolution {
private Resolver resolver;
private String name;
private final String name;
private int priority;

public DistributionResolution(String name, Resolver resolver) {
this.name = name;
this(name);
this.resolver = resolver;
}

public DistributionResolution(String name) {
this.name = name;
}

public String getName() {
return name;
}
Expand All @@ -41,6 +45,6 @@ public int getPriority() {
}

public interface Resolver {
DistributionDependency resolve(DependencyHandler dependencyHandler, ElasticsearchDistribution distribution);
DistributionDependency resolve(Project project, ElasticsearchDistribution distribution);
}
}

0 comments on commit 3f4f108

Please sign in to comment.