Skip to content

Commit

Permalink
SBOM: fallback if augmented SBOM generation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
rudsberg committed Jan 31, 2025
1 parent 3340876 commit 73b8a47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class SBOMFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
buildSucceeded
outputContainsPattern".*CycloneDX SBOM with \\d+ component\\(s\\) is embedded in binary \\(.*?\\) and exported as JSON \\(see build artifacts\\)\\."
outputDoesNotContain "Use '--enable-sbom' to assemble a Software Bill of Materials (SBOM)"
outputDoesNotContain "Could not generate an augmented SBOM"
validateExportedSBOM sbom
!file(String.format("target/%s", SBOMGenerator.SBOM_FILENAME)).exists()
outputContains "Hello, native!"
Expand All @@ -101,6 +102,7 @@ class SBOMFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
buildSucceeded
outputContainsPattern".*CycloneDX SBOM with \\d+ component\\(s\\) is embedded in binary \\(.*?\\)."
outputDoesNotContain "Use '--enable-sbom' to assemble a Software Bill of Materials (SBOM)"
outputDoesNotContain "Could not generate an augmented SBOM"
!file(String.format("target/%s", SBOMGenerator.SBOM_FILENAME)).exists()
outputContains "Hello, native!"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,16 @@ private void generateAugmentedSBOMIfNeeded() throws IllegalArgumentException, Mo
}

var sbomGenerator = new SBOMGenerator(mavenProject, mavenSession, pluginManager, repositorySystem, mainClass, logger);
sbomGenerator.generate();
try {
sbomGenerator.generate();
} catch (MojoExecutionException e) {
/* Only throw exception for users that explicitly opted into using an augmented SBOM. */
if (optionWasSet) {
throw e;
}
logger.warn(String.format("Could not generate an augmented SBOM: %s. Fallback to generating a non-augmented SBOM.",
e.getCause().getMessage()));
}
}

private String consumeConfigurationNodeValue(String pluginKey, String... nodeNames) {
Expand Down

0 comments on commit 73b8a47

Please sign in to comment.