@@ -93,9 +93,10 @@ final public class SBOMGenerator {
9393 private final String mainClass ;
9494 private final Logger logger ;
9595
96- private static final String cycloneDXPluginName = "cyclonedx-maven-plugin" ;
97- private static final String SBOM_NAME = "base_sbom" ;
98- private static final String FILE_FORMAT = "json" ;
96+ private static final String SBOM_FILE_FORMAT = "json" ;
97+ private static final String SBOM_FILENAME_WITHOUT_EXTENSION = "base_sbom" ;
98+ private static final String SBOM_FILENAME = SBOM_FILENAME_WITHOUT_EXTENSION + "." + SBOM_FILE_FORMAT ;
99+ private final String outputDirectory ;
99100
100101 private static final class AddedComponentFields {
101102 /**
@@ -114,6 +115,23 @@ private static final class AddedComponentFields {
114115 static final String prunable = "prunable" ;
115116 }
116117
118+ /**
119+ * The external plugin used to generate the baseline SBOM.
120+ */
121+ private static final class Plugin {
122+ static final String artifactId = "cyclonedx-maven-plugin" ;
123+ static final String groupId = "org.cyclonedx" ;
124+ static final String version = "2.8.1" ;
125+ static final String goal = "makeAggregateBom" ;
126+
127+ private static final class Configuration {
128+ static final String outputFormat = SBOM_FILE_FORMAT ;
129+ static final String outputName = SBOM_FILENAME_WITHOUT_EXTENSION ;
130+ static final String skipNotDeployed = "false" ;
131+ static final String schemaVersion = "1.5" ;
132+ }
133+ }
134+
117135 public SBOMGenerator (
118136 MavenProject mavenProject ,
119137 MavenSession mavenSession ,
@@ -127,15 +145,16 @@ public SBOMGenerator(
127145 this .repositorySystem = repositorySystem ;
128146 this .mainClass = mainClass ;
129147 this .logger = logger ;
148+ this .outputDirectory = mavenProject .getBuild ().getDirectory ();
130149 }
131150
132151 /**
133152 * Checks if the JDK version supports augmented SBOMs.
134153 *
135154 * @param detectedJdkVersion the JDK version used.
136155 * @param throwErrorIfNotSupported if true, then an error is thrown if the check failed.
137- * @return true if the JDK version supports the flag, otherwise false (if {@param throwErrorIfNotSupported} is false).
138- * @throws IllegalArgumentException when {@param throwErrorIfNotSupported} is true and the version check failed.
156+ * @return true if the JDK version supports the flag, otherwise false (if throwErrorIfNotSupported is false).
157+ * @throws IllegalArgumentException when throwErrorIfNotSupported is true and the version check failed.
139158 */
140159 public static boolean checkAugmentedSBOMSupportedByJDKVersion (int detectedJdkVersion , boolean throwErrorIfNotSupported ) throws IllegalArgumentException {
141160 if (detectedJdkVersion < SBOMGenerator .requiredNativeImageVersion ) {
@@ -155,24 +174,24 @@ public static boolean checkAugmentedSBOMSupportedByJDKVersion(int detectedJdkVer
155174 * @throws MojoExecutionException if SBOM creation fails.
156175 */
157176 public void generate () throws MojoExecutionException {
158- String outputDirectory = mavenProject .getBuild ().getDirectory ();
159- Path sbomPath = Paths .get (outputDirectory , SBOM_NAME + "." + FILE_FORMAT );
177+ Path sbomPath = Paths .get (outputDirectory , SBOM_FILENAME );
160178 try {
161- /* Suppress the output from the cyclonedx-maven- plugin. */
179+ /* Suppress the output from the plugin. */
162180 int loggingLevel = logger .getThreshold ();
163181 logger .setThreshold (Logger .LEVEL_DISABLED );
164182 executeMojo (
165183 plugin (
166- groupId ("org.cyclonedx" ),
167- artifactId (cycloneDXPluginName ),
168- version ("2.8.1" )
184+ groupId (Plugin . groupId ),
185+ artifactId (Plugin . artifactId ),
186+ version (Plugin . version )
169187 ),
170- goal ("makeAggregateBom" ),
188+ goal (Plugin . goal ),
171189 configuration (
172- element (name ("outputFormat" ), FILE_FORMAT ),
173- element (name ("outputName" ), SBOM_NAME ),
190+ element (name ("outputFormat" ), Plugin . Configuration . outputFormat ),
191+ element (name ("outputName" ), Plugin . Configuration . outputName ),
174192 element (name ("outputDirectory" ), outputDirectory ),
175- element (name ("skipNotDeployed" ), "false" )
193+ element (name ("skipNotDeployed" ), Plugin .Configuration .skipNotDeployed ),
194+ element (name ("schemaVersion" ), Plugin .Configuration .schemaVersion )
176195 ),
177196 executionEnvironment (mavenProject , mavenSession , pluginManager )
178197 );
@@ -225,7 +244,7 @@ private void augmentSBOM(Path baseSBOMPath, Set<ArtifactAdapter> artifacts) thro
225244
226245 ArrayNode componentsArray = (ArrayNode ) sbomJson .get ("components" );
227246 if (componentsArray == null ) {
228- throw new RuntimeException (String .format ("SBOM generated by %s contained no components." , cycloneDXPluginName ));
247+ throw new RuntimeException (String .format ("SBOM generated by %s:%s contained no components." , Plugin . groupId , Plugin . artifactId ));
229248 }
230249
231250 /* Augment the "components" */
0 commit comments