Allow to override BOM's groupId/artifactId

Closes gh-723
This commit is contained in:
Stephane Nicoll 2018-08-14 11:12:25 +03:00
parent e5f7ef0120
commit fc20447b21
4 changed files with 70 additions and 13 deletions

View File

@ -445,6 +445,8 @@ initializr:
artifactId: acme-foo-dependencies
mappings:
- versionRange: "[1.2.3.RELEASE,1.3.0.RELEASE)"
groupId: com.example.bar
artifactId: acme-foo-bom
version: Arcturus.SR6
- versionRange: "[1.3.0.RELEASE,1.4.0.RELEASE)"
version: Botein.SR7
@ -461,7 +463,8 @@ initializr:
The primary use case here is to map Spring Boot versions to the preferred or supported
versions of the Foo project. You can also see that for the milestone and snapshot BOMs,
additional repositories are declared because those artifacts are not in the default
repository.
repository. Initially the BOM was identified as `com.example.bar:acme-foo-bom` and renamed
as of `Botein` to `com.example.foo:acme-foo-dependencies`.
TIP: We also use the `x` trick in version ranges to avoid updating the range every time
a new Spring Boot 1.5 bug fix release is available

View File

@ -190,8 +190,11 @@ public class BillOfMaterials {
for (Mapping mapping : this.mappings) {
if (mapping.range.match(bootVersion)) {
BillOfMaterials resolvedBom = new BillOfMaterials(this.groupId,
this.artifactId, mapping.version);
BillOfMaterials resolvedBom = new BillOfMaterials(
(mapping.groupId != null) ? mapping.groupId : this.groupId,
(mapping.artifactId != null) ? mapping.artifactId
: this.artifactId,
mapping.version);
resolvedBom.setVersionProperty(this.versionProperty);
resolvedBom.setOrder(this.order);
resolvedBom.repositories.addAll(!mapping.repositories.isEmpty()
@ -233,10 +236,21 @@ public class BillOfMaterials {
/**
* Mapping information.
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class Mapping {
private String versionRange;
/**
* The groupId to use for this mapping or {@code null} to use the default.
*/
private String groupId;
/**
* The artifactId to use for this mapping or {@code null} to use the default.
*/
private String artifactId;
private String version;
private List<String> repositories = new ArrayList<>();
@ -272,10 +286,34 @@ public class BillOfMaterials {
return this.versionRange;
}
public void setVersionRange(String versionRange) {
this.versionRange = versionRange;
}
public String getGroupId() {
return this.groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getArtifactId() {
return this.artifactId;
}
public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
public String getVersion() {
return this.version;
}
public void setVersion(String version) {
this.version = version;
}
public List<String> getRepositories() {
return this.repositories;
}
@ -288,14 +326,6 @@ public class BillOfMaterials {
return this.range;
}
public void setVersionRange(String versionRange) {
this.versionRange = versionRange;
}
public void setVersion(String version) {
this.version = version;
}
public void setRepositories(List<String> repositories) {
this.repositories = repositories;
}
@ -313,6 +343,9 @@ public class BillOfMaterials {
return "Mapping ["
+ ((this.versionRange != null)
? "versionRange=" + this.versionRange + ", " : "")
+ ((this.groupId != null) ? "groupId=" + this.groupId + ", " : "")
+ ((this.artifactId != null) ? "artifactId=" + this.artifactId + ", "
: "")
+ ((this.version != null) ? "version=" + this.version + ", " : "")
+ ((this.repositories != null)
? "repositories=" + this.repositories + ", " : "")

View File

@ -63,6 +63,29 @@ public class BillOfMaterialsTests {
assertThat(resolved.getAdditionalBoms().get(0)).isEqualTo("bom-main");
}
@Test
public void resolveSimpleRangeWithGroupIdArtifactId() {
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
bom.setVersionProperty("bom.version");
bom.getRepositories().add("repo-main");
bom.getAdditionalBoms().add("bom-main");
Mapping mapping = Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0");
mapping.setGroupId("com.example.override");
mapping.setArtifactId("bom-override");
bom.getMappings().add(mapping);
bom.validate();
BillOfMaterials resolved = bom.resolve(Version.parse("1.2.3.RELEASE"));
assertThat(resolved.getGroupId()).isEqualTo("com.example.override");
assertThat(resolved.getArtifactId()).isEqualTo("bom-override");
assertThat(resolved.getVersion()).isEqualTo("1.1.0");
assertThat(resolved.getVersionProperty().toStandardFormat())
.isEqualTo("bom.version");
assertThat(resolved.getRepositories()).hasSize(1);
assertThat(resolved.getRepositories().get(0)).isEqualTo("repo-main");
assertThat(resolved.getAdditionalBoms()).hasSize(1);
assertThat(resolved.getAdditionalBoms().get(0)).isEqualTo("bom-main");
}
@Test
public void resolveRangeOverride() {
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");

View File

@ -106,7 +106,6 @@
"repositories": [
"my-api-repo-1"
],
"additionalBoms": [],
"version": "1.0.0.RELEASE"
},
{
@ -114,7 +113,6 @@
"repositories": [
"my-api-repo-2"
],
"additionalBoms": [],
"version": "2.0.0.RELEASE"
}
]