Skip to content

Commit c76fd03

Browse files
committed
rename maven.optional SBOM property to maven.optional.unused, inserted in SBOM only when activated
1 parent f23deec commit c76fd03

File tree

9 files changed

+13
-41
lines changed

9 files changed

+13
-41
lines changed

src/it/makeAggregateBom/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void assertBomFiles(String path, boolean aggregate) {
88
String analysis = aggregate ? "makeAggregateBom" : "makeBom"
99
assert bomFileXml.text.contains('<property name="maven.goal">' + analysis + '</property>')
1010
assert bomFileXml.text.contains('<property name="maven.scopes">compile,provided,runtime,system</property>')
11-
assert bomFileXml.text.contains('<property name="maven.optional">true</property>')
11+
assert !bomFileXml.text.contains('<property name="maven.optional.unused">')
1212
assert bomFileJson.text.contains('"name" : "maven.goal",')
1313
assert bomFileJson.text.contains('"value" : "' + analysis + '"')
1414
assert bomFileJson.text.contains('"name" : "maven.scopes",')

src/it/makeBom/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ assert bomFileJson.exists()
66

77
assert bomFileXml.text.contains('<reference type="website"><url>https://github.com/CycloneDX/cyclonedx-maven-plugin</url></reference>')
88

9-
assert bomFileXml.text.contains('<property name="maven.optional">true</property>')
9+
assert !bomFileXml.text.contains('<property name="maven.optional.unused">')
1010

1111
// Reproducible Builds
1212
assert !bomFileJson.text.contains('"serialNumber"')

src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ public abstract class BaseCycloneDxMojo extends AbstractMojo {
168168
private String[] excludeTypes;
169169

170170
/**
171-
* Use the original mechanism for determining whether an artifact is OPTIONAL/REQUIRED, relying on bytecode analysis
172-
* of the compiled classes instead of the maven declaration of optional.
171+
* Use the original mechanism for determining whether a component has OPTIONAL or REQUIRED scope,
172+
* relying on bytecode analysis of the compiled classes instead of the Maven dependency declaration of optional.
173173
*
174174
* @since 2.7.9
175175
*/
@@ -290,7 +290,9 @@ public void execute() throws MojoExecutionException {
290290
if (includeTestScope) scopes.add("test");
291291
metadata.addProperty(newProperty("maven.scopes", String.join(",", scopes)));
292292

293-
metadata.addProperty(newProperty("maven.optional", Boolean.toString(!detectUnusedForOptionalScope)));
293+
if (detectUnusedForOptionalScope) {
294+
metadata.addProperty(newProperty("maven.optional.unused", Boolean.toString(detectUnusedForOptionalScope)));
295+
}
294296
}
295297

296298
final Component rootComponent = metadata.getComponent();

src/test/java/org/cyclonedx/maven/Issue314Test.java renamed to src/test/java/org/cyclonedx/maven/Issue314OptionalTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
2424

2525
/**
26-
* Fix BOM handling of conflicting dependency tree graphs
26+
* Test optional detection as Maven dependency optional vs bytecode analysis of unused.
2727
*/
2828
@RunWith(MavenJUnitTestRunner.class)
2929
@MavenVersions({"3.6.3"})
30-
public class Issue314Test extends BaseMavenVerifier {
30+
public class Issue314OptionalTest extends BaseMavenVerifier {
3131

3232
private static final String ISSUE_314_DEPENDENCY_B = "pkg:maven/com.example.issue_314/[email protected]?type=jar";
3333
private static final String ISSUE_314_DEPENDENCY_C = "pkg:maven/com.example.issue_314/[email protected]?type=jar";
3434
private static final String ISSUE_314_DEPENDENCY_D = "pkg:maven/com.example.issue_314/[email protected]?type=jar";
3535

36-
public Issue314Test(MavenRuntimeBuilder runtimeBuilder) throws Exception {
36+
public Issue314OptionalTest(MavenRuntimeBuilder runtimeBuilder) throws Exception {
3737
super(runtimeBuilder);
3838
}
3939

@@ -77,6 +77,7 @@ public void testBytecodeDependencyTree() throws Exception {
7777
/**
7878
* Validate the maven optional components.
7979
* - com.example.issue_314:dependency_C:1.0.0 and com.example.issue_314:dependency_D:1.0.0 *should* be marked as optional
80+
* because dependency_A declares dependency_C as optional, which depends on dependency_D
8081
*/
8182
@Test
8283
public void testMavenOptionalDependencyTree() throws Exception {

src/test/resources/issue-314/dependency_A/pom.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
<artifactId>dependency_A</artifactId>
1515

1616
<name>Dependency A</name>
17-
18-
<properties>
19-
<maven.compiler.target>1.8</maven.compiler.target>
20-
<maven.compiler.source>1.8</maven.compiler.source>
21-
</properties>
22-
2317
<dependencies>
2418
<dependency>
2519
<groupId>com.example.issue_314</groupId>
@@ -50,18 +44,6 @@
5044
</goals>
5145
</execution>
5246
</executions>
53-
<configuration>
54-
<projectType>library</projectType>
55-
<schemaVersion>1.4</schemaVersion>
56-
<includeBomSerialNumber>true</includeBomSerialNumber>
57-
<includeCompileScope>true</includeCompileScope>
58-
<includeProvidedScope>true</includeProvidedScope>
59-
<includeRuntimeScope>false</includeRuntimeScope>
60-
<includeSystemScope>false</includeSystemScope>
61-
<includeTestScope>false</includeTestScope>
62-
<includeLicenseText>false</includeLicenseText>
63-
<outputFormat>xml</outputFormat>
64-
</configuration>
6547
</plugin>
6648
</plugins>
6749
</build>

src/test/resources/issue-314/dependency_B/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,4 @@
1414
<artifactId>dependency_B</artifactId>
1515

1616
<name>Dependency B</name>
17-
18-
<properties>
19-
<maven.compiler.target>1.8</maven.compiler.target>
20-
<maven.compiler.source>1.8</maven.compiler.source>
21-
</properties>
2217
</project>

src/test/resources/issue-314/dependency_C/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515

1616
<name>Dependency C</name>
1717

18-
<properties>
19-
<maven.compiler.target>1.8</maven.compiler.target>
20-
<maven.compiler.source>1.8</maven.compiler.source>
21-
</properties>
22-
2318
<dependencies>
2419
<dependency>
2520
<groupId>com.example.issue_314</groupId>

src/test/resources/issue-314/dependency_D/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,4 @@
1414
<artifactId>dependency_D</artifactId>
1515

1616
<name>Dependency D</name>
17-
18-
<properties>
19-
<maven.compiler.target>1.8</maven.compiler.target>
20-
<maven.compiler.source>1.8</maven.compiler.source>
21-
</properties>
2217
</project>

src/test/resources/issue-314/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
</modules>
2121

2222
<properties>
23+
<maven.compiler.target>1.8</maven.compiler.target>
24+
<maven.compiler.source>1.8</maven.compiler.source>
2325
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2426
</properties>
2527
</project>

0 commit comments

Comments
 (0)