Skip to content

Commit

Permalink
distribution-intake external reference is more accurate
Browse files Browse the repository at this point in the history
this fixes #245

Signed-off-by: Hervé Boutemy <hboutemy@apache.org>
  • Loading branch information
hboutemy committed Mar 20, 2024
1 parent fa5541d commit d001542
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/cyclonedx/maven/DefaultModelConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ private void extractComponentMetadata(MavenProject project, Component component,
if (project.getDistributionManagement() != null) {
addExternalReference(ExternalReference.Type.DISTRIBUTION, project.getDistributionManagement().getDownloadUrl(), component);
if (project.getDistributionManagement().getRepository() != null) {
addExternalReference(ExternalReference.Type.DISTRIBUTION, project.getDistributionManagement().getRepository().getUrl(), component);
ExternalReference.Type type =
(schemaVersion.getVersion() < 1.5) ? ExternalReference.Type.DISTRIBUTION : ExternalReference.Type.DISTRIBUTION_INTAKE;
addExternalReference(type, project.getDistributionManagement().getRepository().getUrl(), component);
}
}
if (project.getIssueManagement() != null) {
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/cyclonedx/maven/ExternalReferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,23 @@ private static void verifyParentExternalReferences(File projDir) {
assertExternalReferences(bomJsonFile, "chat", "url", singleton("https://acme.com/parent"));
assertExternalReferences(bomJsonFile, "website", "url", singleton("https://cyclonedx.org/acme"));
assertExternalReferences(bomJsonFile, "vcs", "url", singleton("https://github.com/CycloneDX/cyclonedx-maven-plugin.git"));
verifyCommonExternalReferences(bomJsonFile);
verifyCommonExternalReferences(bomJsonFile, false);
}

private static void verifyChildExternalReferences(File projDir) {
File bomJsonFile = new File(projDir, "child/target/bom.json");
assertExternalReferences(bomJsonFile, "chat", "url", asList("https://acme.com/parent", "https://acme.com/child"));
assertExternalReferences(bomJsonFile, "website", "url", singleton("https://cyclonedx.org/acme/child"));
assertExternalReferences(bomJsonFile, "vcs", "url", singleton("https://github.com/CycloneDX/cyclonedx-maven-plugin.git/child"));
verifyCommonExternalReferences(bomJsonFile);
verifyCommonExternalReferences(bomJsonFile, true);
}

private static void verifyCommonExternalReferences(File bomJsonFile) {
private static void verifyCommonExternalReferences(File bomJsonFile, boolean child) {
assertExternalReferences(bomJsonFile, "chat", "comment", singleton("optional comment"));
assertExternalReferences(bomJsonFile, "release-notes", "url", singleton("https://github.com/CycloneDX/cyclonedx-maven-plugin/releases"));
assertExternalReferences(bomJsonFile, "build-system", "url", singleton("https://github.com/CycloneDX/cyclonedx-maven-plugin/actions"));
assertExternalReferences(bomJsonFile, "distribution", "url", singleton("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"));
// CycloneDX 1.4 supports distribution only, 1.5 replaces with distribution-intake
assertExternalReferences(bomJsonFile, child ? "distribution" : "distribution-intake", "url", singleton("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"));
assertExternalReferences(bomJsonFile, "issue-tracker", "url", singleton("https://github.com/CycloneDX/cyclonedx-maven-plugin/issues"));
assertExternalReferences(bomJsonFile, "mailing-list", "url", singleton("https://dev.ml.cyclonedx.org/archive"));
}
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/external-reference/child/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<artifactId>cyclonedx-maven-plugin</artifactId>
<version>${cyclonedx-maven-plugin.version}</version>
<configuration>
<schemaVersion>1.4</schemaVersion>
<externalReferences combine.children="append">
<externalReference>
<type>CHAT</type>
Expand Down

0 comments on commit d001542

Please sign in to comment.