-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom external references (#428)
* Add support for custom external references (#421) Signed-off-by: Volkan Yazıcı <volkan@yazi.ci>
- Loading branch information
Showing
6 changed files
with
207 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/org/cyclonedx/maven/ExternalReferenceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.cyclonedx.maven; | ||
|
||
import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder; | ||
import io.takari.maven.testing.executor.MavenVersions; | ||
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; | ||
|
||
/** | ||
* Verifies external references are populated as expected. | ||
*/ | ||
@RunWith(MavenJUnitTestRunner.class) | ||
@MavenVersions({"3.6.3"}) | ||
public class ExternalReferenceTest extends BaseMavenVerifier { | ||
|
||
public ExternalReferenceTest(MavenRuntimeBuilder runtimeBuilder) throws Exception { | ||
super(runtimeBuilder); | ||
} | ||
|
||
@Test | ||
public void testAddedExternalReferences() throws Exception { | ||
|
||
// Create the verifier | ||
File projDir = resources.getBasedir("external-reference"); | ||
verifier | ||
.forProject(projDir) | ||
.withCliOption("-Dcyclonedx-maven-plugin.version=" + getCurrentVersion()) | ||
.withCliOption("-X") | ||
.withCliOption("-B") | ||
.execute("clean", "verify") | ||
.assertErrorFreeLog(); | ||
|
||
// Verify parent metadata | ||
assertExternalReferences( | ||
new File(projDir, "target/bom.json"), | ||
"$.metadata.component.externalReferences[?(@.type=='chat')].url", | ||
Collections.singleton("https://acme.com/parent")); | ||
|
||
// Verify child metadata | ||
assertExternalReferences( | ||
new File(projDir, "child/target/bom.json"), | ||
"$.metadata.component.externalReferences[?(@.type=='chat')].url", | ||
Arrays.asList("https://acme.com/parent", "https://acme.com/child")); | ||
|
||
} | ||
|
||
private static void assertExternalReferences(File bomFile, String jsonPath, Iterable<Object> expectedValues) throws IOException { | ||
byte[] bomJsonBytes = Files.readAllBytes(bomFile.toPath()); | ||
String bomJson = new String(bomJsonBytes, StandardCharsets.UTF_8); | ||
assertThatJson(bomJson) | ||
.inPath(jsonPath) | ||
.isArray() | ||
.containsOnlyOnceElementsOf(expectedValues); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.acme</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>child</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.cyclonedx</groupId> | ||
<artifactId>cyclonedx-maven-plugin</artifactId> | ||
<version>${cyclonedx-maven-plugin.version}</version> | ||
<configuration> | ||
<externalReferences combine.children="append"> | ||
<externalReference> | ||
<type>CHAT</type> | ||
<url>https://acme.com/child</url> | ||
</externalReference> | ||
</externalReferences> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.acme</groupId> | ||
<artifactId>parent</artifactId> | ||
<packaging>pom</packaging> | ||
<version>${revision}</version> | ||
|
||
<licenses> | ||
<license> | ||
<name>Apache-2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
</license> | ||
</licenses> | ||
|
||
<properties> | ||
<revision>1.0.0</revision> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
|
||
<modules> | ||
<module>child</module> | ||
</modules> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.cyclonedx</groupId> | ||
<artifactId>cyclonedx-maven-plugin</artifactId> | ||
<version>${cyclonedx-maven-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>generate-sbom</id> | ||
<goals> | ||
<goal>makeAggregateBom</goal> | ||
</goals> | ||
<phase>verify</phase> | ||
<configuration> | ||
<outputFormat>json</outputFormat> | ||
<externalReferences> | ||
<externalReference> | ||
<type>CHAT</type> | ||
<url>https://acme.com/parent</url> | ||
</externalReference> | ||
</externalReferences> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |