-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #307, addresses cyclic dependencies created by self references
Signed-off-by: Kevin Conner <[email protected]>
- Loading branch information
Showing
6 changed files
with
303 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package org.cyclonedx.maven; | ||
|
||
import java.io.File; | ||
import java.util.Set; | ||
|
||
import static org.cyclonedx.maven.TestUtils.getComponentNode; | ||
import static org.cyclonedx.maven.TestUtils.getDependencyNode; | ||
import static org.cyclonedx.maven.TestUtils.getDependencyReferences; | ||
import static org.cyclonedx.maven.TestUtils.readXML; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder; | ||
import io.takari.maven.testing.executor.MavenVersions; | ||
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner; | ||
|
||
/** | ||
* Test for cyclic dependencies on the same project | ||
*/ | ||
@RunWith(MavenJUnitTestRunner.class) | ||
@MavenVersions({"3.8.7"}) | ||
public class CyclicTest extends BaseMavenVerifier { | ||
private static final String CYCLIC_A_DEPENDENCY = "pkg:maven/com.example.cyclic/[email protected]?type=jar"; | ||
private static final String CYCLIC_A_DEPENDENCY_CLASSIFIER_1 = "pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_1&type=jar"; | ||
private static final String CYCLIC_A_DEPENDENCY_CLASSIFIER_2 = "pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_2&type=jar"; | ||
private static final String CYCLIC_A_DEPENDENCY_CLASSIFIER_3 = "pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_3&type=jar"; | ||
|
||
public CyclicTest(MavenRuntimeBuilder runtimeBuilder) throws Exception { | ||
super(runtimeBuilder); | ||
} | ||
|
||
@Test | ||
public void testCyclicDependency() throws Exception { | ||
cleanAndBuild("cyclic", null); | ||
File projDir = null; | ||
try { | ||
projDir = mvnBuild("cyclic", new String[]{"package"}, null, new String[] {"profile"}); | ||
} catch (final Exception ex) { | ||
fail("Failed to generate SBOM", ex); | ||
} | ||
|
||
final Document bom = readXML(new File(projDir, "target/bom.xml")); | ||
|
||
final NodeList componentsList = bom.getElementsByTagName("components"); | ||
assertEquals("Expected a single components element", 1, componentsList.getLength()); | ||
final Node components = componentsList.item(0); | ||
|
||
final NodeList dependenciesList = bom.getElementsByTagName("dependencies"); | ||
assertEquals("Expected a single dependencies element", 1, dependenciesList.getLength()); | ||
final Node dependencies = dependenciesList.item(0); | ||
|
||
// BOM should contain pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_1&type=jar | ||
final Node cyclicAClassifier1ComponentNode = getComponentNode(components, CYCLIC_A_DEPENDENCY_CLASSIFIER_1); | ||
assertNotNull("Missing cyclic_A:classifier_1:1.0.0 component", cyclicAClassifier1ComponentNode); | ||
|
||
// BOM should contain pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_2&type=jar | ||
final Node cyclicAClassifier2ComponentNode = getComponentNode(components, CYCLIC_A_DEPENDENCY_CLASSIFIER_2); | ||
assertNotNull("Missing cyclic_A:classifier_2:1.0.0 component", cyclicAClassifier2ComponentNode); | ||
|
||
// BOM should contain pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_3&type=jar | ||
final Node cyclicAClassifier3ComponentNode = getComponentNode(components, CYCLIC_A_DEPENDENCY_CLASSIFIER_3); | ||
assertNotNull("Missing cyclic_A:classifier_3:1.0.0 component", cyclicAClassifier3ComponentNode); | ||
|
||
/* | ||
<dependency ref="pkg:maven/com.example.cyclic/[email protected]?type=jar"> | ||
<dependency ref="pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_1&type=jar"/> | ||
<dependency ref="pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_2&type=jar"/> | ||
<dependency ref="pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_3&type=jar"/> | ||
</dependency> | ||
*/ | ||
final Node cyclicADependencyNode = getDependencyNode(dependencies, CYCLIC_A_DEPENDENCY); | ||
assertNotNull("Missing cyclic_A:1.0.0 dependency", cyclicADependencyNode); | ||
Set<String> cyclicADependencies = getDependencyReferences(cyclicADependencyNode); | ||
assertEquals("Invalid dependency count for cyclic_A:1.0.0", 3, cyclicADependencies.size()); | ||
assertTrue("Missing cyclic_A:classifier_1:1.0.0 dependency for cyclic_A:1.0.0", cyclicADependencies.contains(CYCLIC_A_DEPENDENCY_CLASSIFIER_1)); | ||
assertTrue("Missing cyclic_A:classifier_2:1.0.0 dependency for cyclic_A:1.0.0", cyclicADependencies.contains(CYCLIC_A_DEPENDENCY_CLASSIFIER_2)); | ||
assertTrue("Missing cyclic_A:classifier_3:1.0.0 dependency for cyclic_A:1.0.0", cyclicADependencies.contains(CYCLIC_A_DEPENDENCY_CLASSIFIER_3)); | ||
|
||
/* | ||
<dependency ref="pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_1&type=jar"/> | ||
*/ | ||
final Node cyclicAClassifier1DependencyNode = getDependencyNode(dependencies, CYCLIC_A_DEPENDENCY_CLASSIFIER_1); | ||
assertNotNull("Missing cyclic_A:classifier_1:1.0.0 dependency", cyclicAClassifier1DependencyNode); | ||
Set<String> cyclicAClassifier1Dependencies = getDependencyReferences(cyclicAClassifier1DependencyNode); | ||
assertEquals("Invalid dependency count for cyclic_A:classifier_1:1.0.0", 0, cyclicAClassifier1Dependencies.size()); | ||
|
||
/* | ||
<dependency ref="pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_2&type=jar"/> | ||
*/ | ||
final Node cyclicAClassifier2DependencyNode = getDependencyNode(dependencies, CYCLIC_A_DEPENDENCY_CLASSIFIER_2); | ||
assertNotNull("Missing cyclic_A:classifier_2:1.0.0 dependency", cyclicAClassifier2DependencyNode); | ||
Set<String> cyclicAClassifier2Dependencies = getDependencyReferences(cyclicAClassifier2DependencyNode); | ||
assertEquals("Invalid dependency count for cyclic_A:classifier_2:1.0.0", 0, cyclicAClassifier2Dependencies.size()); | ||
|
||
/* | ||
<dependency ref="pkg:maven/com.example.cyclic/[email protected]?classifier=classifier_3&type=jar"/> | ||
*/ | ||
final Node cyclicAClassifier3DependencyNode = getDependencyNode(dependencies, CYCLIC_A_DEPENDENCY_CLASSIFIER_3); | ||
assertNotNull("Missing cyclic_A:classifier_3:1.0.0 dependency", cyclicAClassifier3DependencyNode); | ||
Set<String> cyclicAClassifier3Dependencies = getDependencyReferences(cyclicAClassifier3DependencyNode); | ||
assertEquals("Invalid dependency count for cyclic_A:classifier_3:1.0.0", 0, cyclicAClassifier3Dependencies.size()); | ||
} | ||
} |
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,150 @@ | ||
<?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.example.cyclic</groupId> | ||
<artifactId>cyclic_A</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<name>Cyclic Dependency A</name> | ||
|
||
<profiles> | ||
<profile> | ||
<id>profile</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.example.cyclic</groupId> | ||
<artifactId>cyclic_A</artifactId> | ||
<version>1.0.0</version> | ||
<classifier>classifier_1</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.example.cyclic</groupId> | ||
<artifactId>cyclic_A</artifactId> | ||
<version>1.0.0</version> | ||
<classifier>classifier_2</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.example.cyclic</groupId> | ||
<artifactId>cyclic_A</artifactId> | ||
<version>1.0.0</version> | ||
<classifier>classifier_3</classifier> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.cyclonedx</groupId> | ||
<artifactId>cyclonedx-maven-plugin</artifactId> | ||
<version>${current.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>makeAggregateBom</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<projectType>library</projectType> | ||
<schemaVersion>1.4</schemaVersion> | ||
<includeBomSerialNumber>true</includeBomSerialNumber> | ||
<includeCompileScope>true</includeCompileScope> | ||
<includeProvidedScope>true</includeProvidedScope> | ||
<includeRuntimeScope>true</includeRuntimeScope> | ||
<includeSystemScope>true</includeSystemScope> | ||
<includeTestScope>false</includeTestScope> | ||
<includeLicenseText>false</includeLicenseText> | ||
<outputFormat>xml</outputFormat> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.3.0</version> | ||
<executions> | ||
<execution> | ||
<id>classifier_1</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>classifier_1</classifier> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>classifier_2</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>classifier_2</classifier> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>classifier_3</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>classifier_3</classifier> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<executions> | ||
<execution> | ||
<id>classifier_1</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>install-file</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>classifier_1</classifier> | ||
<file>${project.build.directory}/cyclic_A-1.0.0-classifier_1.jar</file> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>classifier_2</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>install-file</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>classifier_2</classifier> | ||
<file>${project.build.directory}/cyclic_A-1.0.0-classifier_2.jar</file> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>classifier_3</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>install-file</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>classifier_3</classifier> | ||
<file>${project.build.directory}/cyclic_A-1.0.0-classifier_3.jar</file> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |