Allow to map a Dependency BOM

This commit allows a BOM to be overridden using a dependency mapping.

Closes gh-1155
This commit is contained in:
Stephane Nicoll
2020-11-30 09:30:50 +01:00
parent 58220dcb1c
commit e77aca2211
8 changed files with 111 additions and 54 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,7 +84,8 @@ public class DependencyManagementBuildCustomizer implements BuildCustomizer<Buil
}
private Stream<Dependency> mapDependencies(Build build) {
return build.dependencies().ids().map((id) -> this.metadata.getDependencies().get(id)).filter(Objects::nonNull);
return build.dependencies().ids().map((id) -> this.metadata.getDependencies().get(id)).filter(Objects::nonNull)
.map((dependency) -> dependency.resolve(this.description.getPlatformVersion()));
}
private void resolveBom(Map<String, BillOfMaterials> boms, String bomId, Version requestedVersion) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,6 +51,22 @@ class DependencyManagementBuildCustomizerTests {
assertThat(build.boms().items()).hasSize(2);
}
@Test
void contributeBomFromMapping() {
Dependency dependency = Dependency.withId("foo");
dependency.getMappings()
.add(Dependency.Mapping.create("[2.4.0,2.5.0-M1)", null, null, null, null, "foo-bom", null));
BillOfMaterials bom = BillOfMaterials.create("com.example", "foo-bom", "1.0.0");
bom.getAdditionalBoms().add("bar-bom");
BillOfMaterials additionalBom = BillOfMaterials.create("com.example", "bar-bom", "1.1.0");
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo-bom", bom)
.addBom("bar-bom", additionalBom).addDependencyGroup("test", dependency).build();
Build build = createBuild(metadata);
build.dependencies().add(dependency.getId());
customizeBuild(build, metadata);
assertThat(build.boms().items()).hasSize(2);
}
@Test
void contributeRepositories() { // ProjectRequestTests#resolveAdditionalRepositories
Dependency dependency = Dependency.withId("foo");
@@ -70,12 +86,12 @@ class DependencyManagementBuildCustomizerTests {
}
private MavenBuild createBuild(InitializrMetadata metadata) {
return new MavenBuild(new MetadataBuildItemResolver(metadata, Version.parse("2.0.0.RELEASE")));
return new MavenBuild(new MetadataBuildItemResolver(metadata, Version.parse("2.4.0")));
}
private void customizeBuild(Build build, InitializrMetadata metadata) {
MutableProjectDescription description = new MutableProjectDescription();
description.setPlatformVersion(Version.parse("2.0.0.RELEASE"));
description.setPlatformVersion(Version.parse("2.4.0"));
new DependencyManagementBuildCustomizer(description, metadata).customize(build);
}