Skip to content

Commit

Permalink
Merge branch '3.2.x'
Browse files Browse the repository at this point in the history
Closes gh-40551
  • Loading branch information
wilkinsona committed Apr 26, 2024
2 parents 85d9ebc + 0757857 commit 308b0d9
Showing 1 changed file with 15 additions and 11 deletions.
Expand Up @@ -32,12 +32,14 @@
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencyConstraint;
import org.gradle.api.artifacts.DependencyConstraintMetadata;
import org.gradle.api.artifacts.DependencyConstraintSet;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.TaskAction;
import org.gradle.platform.base.Platform;

import org.springframework.boot.build.bom.BomExtension;
import org.springframework.boot.build.bom.BomPlugin;
import org.springframework.boot.build.bom.Library;

/**
Expand All @@ -56,7 +58,9 @@ public class ExtractVersionConstraints extends DefaultTask {

private final Set<VersionProperty> versionProperties = new TreeSet<>();

private final List<String> projectPaths = new ArrayList<>();
private final List<DependencyConstraintSet> dependencyConstraintSets = new ArrayList<>();

private final List<BomExtension> boms = new ArrayList<>();

public ExtractVersionConstraints() {
DependencyHandler dependencies = getProject().getDependencies();
Expand All @@ -68,7 +72,11 @@ public void enforcedPlatform(String projectPath) {
Dependency project = getProject().getDependencies().project(Map.of("path", projectPath));
Dependency dependency = getProject().getDependencies().enforcedPlatform(project);
this.configuration.getDependencies().add(dependency);
this.projectPaths.add(projectPath);
getProject().getPlugins().withType(BomPlugin.class).all((plugin) -> {
this.boms.add(getProject().getExtensions().getByType(BomExtension.class));
this.dependencyConstraintSets
.add(getProject().getConfigurations().getByName("apiElements").getAllDependencyConstraints());
});
}

@Internal
Expand All @@ -89,12 +97,9 @@ public Set<VersionProperty> getVersionProperties() {
@TaskAction
void extractVersionConstraints() {
this.configuration.resolve();
for (String projectPath : this.projectPaths) {
extractVersionProperties(projectPath);
for (DependencyConstraint constraint : getProject().project(projectPath)
.getConfigurations()
.getByName("apiElements")
.getAllDependencyConstraints()) {
this.boms.forEach(this::extractVersionProperties);
for (DependencyConstraintSet constraints : this.dependencyConstraintSets) {
for (DependencyConstraint constraint : constraints) {
this.versionConstraints.put(constraint.getGroup() + ":" + constraint.getName(),
constraint.getVersionConstraint().toString());
this.constrainedVersions.add(new ConstrainedVersion(constraint.getGroup(), constraint.getName(),
Expand All @@ -103,9 +108,8 @@ void extractVersionConstraints() {
}
}

private void extractVersionProperties(String projectPath) {
BomExtension bom = (BomExtension) getProject().project(projectPath).getExtensions().getByName("bom");
for (Library lib : bom.getLibraries()) {
private void extractVersionProperties(BomExtension bomExtension) {
for (Library lib : bomExtension.getLibraries()) {
String versionProperty = lib.getVersionProperty();
if (versionProperty != null) {
this.versionProperties.add(new VersionProperty(lib.getName(), versionProperty));
Expand Down

0 comments on commit 308b0d9

Please sign in to comment.