Skip to content

Commit 322dfd6

Browse files
committed
Only create SBOM for Oracle GraalVM
1 parent d0581ed commit 322dfd6

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public abstract class AbstractNativeImageMojo extends AbstractNativeMojo {
8787
protected static final String NATIVE_IMAGE_META_INF = "META-INF/native-image";
8888
protected static final String NATIVE_IMAGE_PROPERTIES_FILENAME = "native-image.properties";
8989
protected static final String NATIVE_IMAGE_DRY_RUN = "nativeDryRun";
90+
private String nativeImageVersionInformation = null;
9091

9192
@Parameter(defaultValue = "${plugin}", readonly = true) // Maven 3 only
9293
protected PluginDescriptor plugin;
@@ -437,6 +438,21 @@ protected void checkRequiredVersionIfNeeded() throws MojoExecutionException {
437438
if (requiredVersion == null) {
438439
return;
439440
}
441+
NativeImageUtils.checkVersion(requiredVersion, getVersionInformation());
442+
}
443+
444+
protected boolean isOracleGraalVM() throws MojoExecutionException {
445+
return getVersionInformation().contains("Oracle GraalVM");
446+
}
447+
448+
/**
449+
* Returns the output of calling "native-image --version".
450+
*/
451+
protected String getVersionInformation() throws MojoExecutionException {
452+
if (nativeImageVersionInformation != null) {
453+
return nativeImageVersionInformation;
454+
}
455+
440456
Path nativeImageExecutable = NativeImageConfigurationUtils.getNativeImage(logger);
441457
try {
442458
ProcessBuilder processBuilder = new ProcessBuilder(nativeImageExecutable.toString());
@@ -447,12 +463,11 @@ protected void checkRequiredVersionIfNeeded() throws MojoExecutionException {
447463
throw new MojoExecutionException("Execution of " + commandString + " returned non-zero result");
448464
}
449465
InputStream inputStream = versionCheckProcess.getInputStream();
450-
String versionToCheck = new BufferedReader(
466+
nativeImageVersionInformation = new BufferedReader(
451467
new InputStreamReader(inputStream, StandardCharsets.UTF_8))
452468
.lines()
453469
.collect(Collectors.joining("\n"));
454-
NativeImageUtils.checkVersion(requiredVersion, versionToCheck);
455-
470+
return nativeImageVersionInformation;
456471
} catch (IOException | InterruptedException e) {
457472
throw new MojoExecutionException("Checking GraalVM version with " + nativeImageExecutable + " failed", e);
458473
}

native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeCompileNoForkMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void execute() throws MojoExecutionException {
106106
maybeSetMainClassFromPlugin(this::consumeConfigurationNodeValue, "org.apache.maven.plugins:maven-jar-plugin", "archive", "manifest", "mainClass");
107107
maybeAddGeneratedResourcesConfig(buildArgs);
108108

109-
if (enableSBOM) {
109+
if (isOracleGraalVM() && enableSBOM) {
110110
var generator = new SBOMGenerator(mavenProject, mavenSession, pluginManager, repositorySystem, mainClass, logger);
111111
generator.generate();
112112
}

native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/SBOMGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@
6868
* <p>
6969
* Approach:
7070
* 1. The cyclonedx-maven-plugin creates a baseline SBOM.
71-
* 2. The components of the baseline SBOM are updated with additional metadata, most importantly being the set of package
72-
* names associated with the component (see {@link AddedComponentFields} for all additional metadata).
71+
* 2. The components of the baseline SBOM (referred to as the "base" SBOM) are updated with additional metadata,
72+
* most importantly being the set of package names associated with the component (see {@link AddedComponentFields}
73+
* for all additional metadata).
7374
* 3. The SBOM is stored at a known location.
7475
* 4. Native Image processes the SBOM and removes unreachable components and unnecessary dependencies.
7576
* <p>
@@ -89,7 +90,7 @@ final public class SBOMGenerator {
8990
private final Logger logger;
9091

9192
private static final String cycloneDXPluginName = "cyclonedx-maven-plugin";
92-
private static final String SBOM_NAME = "WIP_SBOM";
93+
private static final String SBOM_NAME = "base_sbom";
9394
private static final String FILE_FORMAT = "json";
9495

9596
private static final class AddedComponentFields {

0 commit comments

Comments
 (0)