Add <type>zip</type> to Elasticsearch dist in dependencies bom
Fixes gh-28725
This commit is contained in:
parent
c4e2252c6d
commit
f2b959b0a5
|
|
@ -301,22 +301,28 @@ public class BomExtension {
|
|||
if (args instanceof Object[] && ((Object[]) args).length == 1) {
|
||||
Object arg = ((Object[]) args)[0];
|
||||
if (arg instanceof Closure) {
|
||||
ExclusionHandler exclusionHandler = new ExclusionHandler();
|
||||
ConfigureUtil.configure((Closure<?>) arg, exclusionHandler);
|
||||
return new Module(name, exclusionHandler.exclusions);
|
||||
ModuleHandler moduleHandler = new ModuleHandler();
|
||||
ConfigureUtil.configure((Closure<?>) arg, moduleHandler);
|
||||
return new Module(name, moduleHandler.type, moduleHandler.exclusions);
|
||||
}
|
||||
}
|
||||
throw new InvalidUserDataException("Invalid exclusion configuration for module '" + name + "'");
|
||||
throw new InvalidUserDataException("Invalid configuration for module '" + name + "'");
|
||||
}
|
||||
|
||||
public class ExclusionHandler {
|
||||
public class ModuleHandler {
|
||||
|
||||
private final List<Exclusion> exclusions = new ArrayList<>();
|
||||
|
||||
private String type;
|
||||
|
||||
public void exclude(Map<String, String> exclusion) {
|
||||
this.exclusions.add(new Exclusion(exclusion.get("group"), exclusion.get("module")));
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
package org.springframework.boot.build.bom;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import groovy.util.Node;
|
||||
|
|
@ -34,6 +36,7 @@ import org.gradle.api.publish.maven.MavenPublication;
|
|||
import org.springframework.boot.build.DeployedPlugin;
|
||||
import org.springframework.boot.build.MavenRepositoryPlugin;
|
||||
import org.springframework.boot.build.bom.Library.Group;
|
||||
import org.springframework.boot.build.bom.Library.Module;
|
||||
import org.springframework.boot.build.bom.bomr.UpgradeBom;
|
||||
|
||||
/**
|
||||
|
|
@ -108,6 +111,7 @@ public class BomPlugin implements Plugin<Project> {
|
|||
addPropertiesBeforeDependencyManagement(projectNode, properties);
|
||||
replaceVersionsWithVersionPropertyReferences(dependencyManagement);
|
||||
addExclusionsToManagedDependencies(dependencyManagement);
|
||||
addTypesToManagedDependencies(dependencyManagement);
|
||||
}
|
||||
else {
|
||||
projectNode.children().add(properties);
|
||||
|
|
@ -160,6 +164,30 @@ public class BomPlugin implements Plugin<Project> {
|
|||
}
|
||||
}
|
||||
|
||||
private void addTypesToManagedDependencies(Node dependencyManagement) {
|
||||
Node dependencies = findChild(dependencyManagement, "dependencies");
|
||||
if (dependencies != null) {
|
||||
for (Node dependency : findChildren(dependencies, "dependency")) {
|
||||
String groupId = findChild(dependency, "groupId").text();
|
||||
String artifactId = findChild(dependency, "artifactId").text();
|
||||
Set<String> types = this.bom.getLibraries().stream()
|
||||
.flatMap((library) -> library.getGroups().stream())
|
||||
.filter((group) -> group.getId().equals(groupId))
|
||||
.flatMap((group) -> group.getModules().stream())
|
||||
.filter((module) -> module.getName().equals(artifactId)).map(Module::getType)
|
||||
.filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
if (types.size() > 1) {
|
||||
throw new IllegalStateException(
|
||||
"Multiple types for " + groupId + ":" + artifactId + ": " + types);
|
||||
}
|
||||
if (types.size() == 1) {
|
||||
String type = types.iterator().next();
|
||||
dependency.appendNode("type", type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addPluginManagement(Node projectNode) {
|
||||
for (Library library : this.bom.getLibraries()) {
|
||||
for (Group group : library.getGroups()) {
|
||||
|
|
|
|||
|
|
@ -187,14 +187,25 @@ public class Library {
|
|||
|
||||
private final String name;
|
||||
|
||||
private final String type;
|
||||
|
||||
private final List<Exclusion> exclusions;
|
||||
|
||||
public Module(String name) {
|
||||
this(name, Collections.emptyList());
|
||||
}
|
||||
|
||||
public Module(String name, String type) {
|
||||
this(name, type, Collections.emptyList());
|
||||
}
|
||||
|
||||
public Module(String name, List<Exclusion> exclusions) {
|
||||
this(name, null, exclusions);
|
||||
}
|
||||
|
||||
public Module(String name, String type, List<Exclusion> exclusions) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.exclusions = exclusions;
|
||||
}
|
||||
|
||||
|
|
@ -202,6 +213,10 @@ public class Library {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public List<Exclusion> getExclusions() {
|
||||
return this.exclusions;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,6 +170,36 @@ class BomPluginIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void moduleTypesAreIncludedInDependencyManagementOfGeneratedPom() throws IOException {
|
||||
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
|
||||
out.println("plugins {");
|
||||
out.println(" id 'org.springframework.boot.bom'");
|
||||
out.println("}");
|
||||
out.println("bom {");
|
||||
out.println(" library('Elasticsearch', '7.15.2') {");
|
||||
out.println(" group('org.elasticsearch.distribution.integ-test-zip') {");
|
||||
out.println(" modules = [");
|
||||
out.println(" 'elasticsearch' {");
|
||||
out.println(" type = 'zip'");
|
||||
out.println(" }");
|
||||
out.println(" ]");
|
||||
out.println(" }");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
}
|
||||
generatePom((pom) -> {
|
||||
assertThat(pom).textAtPath("//properties/elasticsearch.version").isEqualTo("7.15.2");
|
||||
NodeAssert dependency = pom.nodeAtPath("//dependencyManagement/dependencies/dependency");
|
||||
assertThat(dependency).textAtPath("groupId").isEqualTo("org.elasticsearch.distribution.integ-test-zip");
|
||||
assertThat(dependency).textAtPath("artifactId").isEqualTo("elasticsearch");
|
||||
assertThat(dependency).textAtPath("version").isEqualTo("${elasticsearch.version}");
|
||||
assertThat(dependency).textAtPath("scope").isNullOrEmpty();
|
||||
assertThat(dependency).textAtPath("type").isEqualTo("zip");
|
||||
assertThat(dependency).nodeAtPath("exclusions").isNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void libraryNamedSpringBootHasNoVersionProperty() throws IOException {
|
||||
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
|
||||
|
|
|
|||
|
|
@ -290,7 +290,9 @@ bom {
|
|||
}
|
||||
group("org.elasticsearch.distribution.integ-test-zip") {
|
||||
modules = [
|
||||
"elasticsearch"
|
||||
"elasticsearch" {
|
||||
type = 'zip'
|
||||
}
|
||||
]
|
||||
}
|
||||
group("org.elasticsearch.plugin") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue