Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knrc maven optionality #2

Open
wants to merge 1 commit into
base: maven_optionality
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/it/makeAggregateBom/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void assertBomFiles(String path, boolean aggregate) {
String analysis = aggregate ? "makeAggregateBom" : "makeBom"
assert bomFileXml.text.contains('<property name="maven.goal">' + analysis + '</property>')
assert bomFileXml.text.contains('<property name="maven.scopes">compile,provided,runtime,system</property>')
assert bomFileXml.text.contains('<property name="maven.optional">true</property>')
assert !bomFileXml.text.contains('<property name="maven.optional.unused">')
assert bomFileJson.text.contains('"name" : "maven.goal",')
assert bomFileJson.text.contains('"value" : "' + analysis + '"')
assert bomFileJson.text.contains('"name" : "maven.scopes",')
Expand Down
2 changes: 1 addition & 1 deletion src/it/makeBom/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ assert bomFileJson.exists()

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

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

// Reproducible Builds
assert !bomFileJson.text.contains('"serialNumber"')
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public abstract class BaseCycloneDxMojo extends AbstractMojo {
private String[] excludeTypes;

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

metadata.addProperty(newProperty("maven.optional", Boolean.toString(!detectUnusedForOptionalScope)));
if (detectUnusedForOptionalScope) {
metadata.addProperty(newProperty("maven.optional.unused", Boolean.toString(detectUnusedForOptionalScope)));
}
}

final Component rootComponent = metadata.getComponent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;

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

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

public Issue314Test(MavenRuntimeBuilder runtimeBuilder) throws Exception {
public Issue314OptionalTest(MavenRuntimeBuilder runtimeBuilder) throws Exception {
super(runtimeBuilder);
}

Expand Down Expand Up @@ -77,6 +77,7 @@ public void testBytecodeDependencyTree() throws Exception {
/**
* Validate the maven optional components.
* - com.example.issue_314:dependency_C:1.0.0 and com.example.issue_314:dependency_D:1.0.0 *should* be marked as optional
* because dependency_A declares dependency_C as optional, which depends on dependency_D
*/
@Test
public void testMavenOptionalDependencyTree() throws Exception {
Expand Down
18 changes: 0 additions & 18 deletions src/test/resources/issue-314/dependency_A/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
<artifactId>dependency_A</artifactId>

<name>Dependency A</name>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<dependencies>
<dependency>
<groupId>com.example.issue_314</groupId>
Expand Down Expand Up @@ -50,18 +44,6 @@
</goals>
</execution>
</executions>
<configuration>
<projectType>library</projectType>
<schemaVersion>1.4</schemaVersion>
<includeBomSerialNumber>true</includeBomSerialNumber>
<includeCompileScope>true</includeCompileScope>
<includeProvidedScope>true</includeProvidedScope>
<includeRuntimeScope>false</includeRuntimeScope>
<includeSystemScope>false</includeSystemScope>
<includeTestScope>false</includeTestScope>
<includeLicenseText>false</includeLicenseText>
<outputFormat>xml</outputFormat>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
5 changes: 0 additions & 5 deletions src/test/resources/issue-314/dependency_B/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@
<artifactId>dependency_B</artifactId>

<name>Dependency B</name>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
</project>
5 changes: 0 additions & 5 deletions src/test/resources/issue-314/dependency_C/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@

<name>Dependency C</name>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<dependencies>
<dependency>
<groupId>com.example.issue_314</groupId>
Expand Down
5 changes: 0 additions & 5 deletions src/test/resources/issue-314/dependency_D/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@
<artifactId>dependency_D</artifactId>

<name>Dependency D</name>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
</project>
2 changes: 2 additions & 0 deletions src/test/resources/issue-314/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
</modules>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Expand Down