Skip to content

Commit 94561ac

Browse files
rudsbergdnestoro
authored andcommitted
SBOM: fix issue with unresolved artifact
1 parent ccb7f0d commit 94561ac

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Set<ArtifactAdapter> getArtifactAdapters() throws Exception {
112112
return artifactsWithPackageNameMappings;
113113
}
114114

115-
private Optional<ArtifactAdapter> resolvePackageNamesFromArtifact(Artifact artifact) throws ArtifactResolutionException, IOException {
115+
private Optional<ArtifactAdapter> resolvePackageNamesFromArtifact(Artifact artifact) throws IOException {
116116
File artifactFile = artifact.getFile();
117117
if (artifactFile != null && artifactFile.exists()) {
118118
return resolvePackageNamesFromArtifactFile(artifactFile, ArtifactAdapter.fromMavenArtifact(artifact));
@@ -124,7 +124,13 @@ private Optional<ArtifactAdapter> resolvePackageNamesFromArtifact(Artifact artif
124124
.setArtifact(sourceArtifact)
125125
.setRepositories(remoteRepositories);
126126

127-
ArtifactResult result = repositorySystem.resolveArtifact(repositorySystemSession, request);
127+
ArtifactResult result;
128+
try {
129+
result = repositorySystem.resolveArtifact(repositorySystemSession, request);
130+
} catch (ArtifactResolutionException e) {
131+
return Optional.empty();
132+
}
133+
128134
if (result != null && result.getArtifact() != null && result.getArtifact().getFile() != null) {
129135
File sourceFile = result.getArtifact().getFile();
130136
return resolvePackageNamesFromArtifactFile(sourceFile, ArtifactAdapter.fromEclipseArtifact(result.getArtifact()));

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,17 @@ private static void deleteFileIfExists(Path sbomPath) {
237237
private void augmentSBOM(Path baseSBOMPath, Set<ArtifactAdapter> artifacts) throws IOException {
238238
JSONObject sbomJson = new JSONObject(Files.readString(baseSBOMPath));
239239

240-
JSONArray componentsArray = sbomJson.optJSONArray("components");
241-
if (componentsArray == null) {
242-
throw new RuntimeException(String.format("SBOM generated by %s:%s contained no components.", Plugin.groupId, Plugin.artifactId));
243-
}
244-
245-
/* Augment the "components" */
246-
componentsArray.forEach(componentNode -> augmentComponentNode((JSONObject) componentNode, artifacts));
247-
248240
/* Augment the main component in "metadata/component" */
249241
JSONObject metadataNode = sbomJson.optJSONObject("metadata");
250242
if (metadataNode != null && metadataNode.has("component")) {
251243
augmentComponentNode(metadataNode.getJSONObject("component"), artifacts);
252244
}
253245

246+
JSONArray componentsArray = sbomJson.optJSONArray("components");
247+
if (componentsArray != null) {
248+
componentsArray.forEach(componentNode -> augmentComponentNode((JSONObject) componentNode, artifacts));
249+
}
250+
254251
/* Save the augmented SBOM back to the file */
255252
Files.writeString(baseSBOMPath, sbomJson.toString(2));
256253
}

0 commit comments

Comments
 (0)