Skip to content

Commit

Permalink
fix Maven project building request with packaging #272
Browse files Browse the repository at this point in the history
Signed-off-by: Hervé Boutemy <hboutemy@apache.org>
  • Loading branch information
hboutemy committed Feb 13, 2023
1 parent a4aaa85 commit 41bccb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private void extractComponentMetadata(MavenProject project, Component component,
private MavenProject getEffectiveMavenProject(final Artifact artifact) throws ProjectBuildingException {
final Artifact pomArtifact = repositorySystem.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
final ProjectBuildingResult build = mavenProjectBuilder.build(pomArtifact,
session.getProjectBuildingRequest().setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL)
session.getProjectBuildingRequest().setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL).setProcessPlugins(false)
);
return build.getProject();
}
Expand Down
46 changes: 5 additions & 41 deletions src/test/java/org/cyclonedx/maven/BundleDependencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,10 @@
@MavenVersions({"3.6.3"})
public class BundleDependencyTest extends BaseMavenVerifier {

private final static String WARN = "[WARNING] Unable to create Maven project for org.xerial.snappy:snappy-java:jar:1.1.8.4 from repository.";

public BundleDependencyTest(MavenRuntimeBuilder runtimeBuilder) throws Exception {
super(runtimeBuilder);
}

@Test
public void testBundleDependency() throws Exception {
File projDir = resources.getBasedir("bundle");

verifier
.forProject(projDir)
.withCliOption("-Dcurrent.version=" + getCurrentVersion()) // inject cyclonedx-maven-plugin version
.withCliOption("-B")
.execute("clean", "verify")
.assertErrorFreeLog()
.assertLogText(WARN);
// data expected from the MavenProject building is missing (was present in cyclonedx-maven-plugin 2.7.3, before https://github.com/CycloneDX/cyclonedx-maven-plugin/commit/374b3c53cbd28ffa7941d0aa7741f5b2405d83e4):
/*
"publisher" : "xerial.org",
"description" : "snappy-java: A fast compression/decompression library",
"licenses" : [
{
"license" : {
"id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0"
}
}
],
"externalReferences" : [
{
"type" : "website",
"url" : "https://github.com/xerial/snappy-java"
},
{
"type" : "vcs",
"url" : "https://github.com/xerial/snappy-java"
}
],
*/
}

@Test
public void testBundleDependencyDebug() throws Exception {
File projDir = resources.getBasedir("bundle");
Expand All @@ -71,9 +33,11 @@ public void testBundleDependencyDebug() throws Exception {
.forProject(projDir)
.withCliOption("-Dcurrent.version=" + getCurrentVersion()) // inject cyclonedx-maven-plugin version
.withCliOption("-B")
.withCliOption("-X") // debug, will print the full stacktrace with error message
.withCliOption("-X") // debug, will print the full stacktrace with error message if there is any model building issue
.execute("clean", "verify")
.assertLogText(WARN)
.assertLogText("[ERROR] Unknown packaging: bundle @ line 6, column 16");
.assertErrorFreeLog();

String bomContents = fileRead(new File(projDir, "target/bom.json"), true);
assertTrue(bomContents.contains("\"description\" : \"snappy-java: A fast compression/decompression library\""));
}
}

0 comments on commit 41bccb4

Please sign in to comment.