File tree 2 files changed +13
-10
lines changed
native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom
2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ Set<ArtifactAdapter> getArtifactAdapters() throws Exception {
112
112
return artifactsWithPackageNameMappings ;
113
113
}
114
114
115
- private Optional <ArtifactAdapter > resolvePackageNamesFromArtifact (Artifact artifact ) throws ArtifactResolutionException , IOException {
115
+ private Optional <ArtifactAdapter > resolvePackageNamesFromArtifact (Artifact artifact ) throws IOException {
116
116
File artifactFile = artifact .getFile ();
117
117
if (artifactFile != null && artifactFile .exists ()) {
118
118
return resolvePackageNamesFromArtifactFile (artifactFile , ArtifactAdapter .fromMavenArtifact (artifact ));
@@ -124,7 +124,13 @@ private Optional<ArtifactAdapter> resolvePackageNamesFromArtifact(Artifact artif
124
124
.setArtifact (sourceArtifact )
125
125
.setRepositories (remoteRepositories );
126
126
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
+
128
134
if (result != null && result .getArtifact () != null && result .getArtifact ().getFile () != null ) {
129
135
File sourceFile = result .getArtifact ().getFile ();
130
136
return resolvePackageNamesFromArtifactFile (sourceFile , ArtifactAdapter .fromEclipseArtifact (result .getArtifact ()));
Original file line number Diff line number Diff line change @@ -237,20 +237,17 @@ private static void deleteFileIfExists(Path sbomPath) {
237
237
private void augmentSBOM (Path baseSBOMPath , Set <ArtifactAdapter > artifacts ) throws IOException {
238
238
JSONObject sbomJson = new JSONObject (Files .readString (baseSBOMPath ));
239
239
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
-
248
240
/* Augment the main component in "metadata/component" */
249
241
JSONObject metadataNode = sbomJson .optJSONObject ("metadata" );
250
242
if (metadataNode != null && metadataNode .has ("component" )) {
251
243
augmentComponentNode (metadataNode .getJSONObject ("component" ), artifacts );
252
244
}
253
245
246
+ JSONArray componentsArray = sbomJson .optJSONArray ("components" );
247
+ if (componentsArray != null ) {
248
+ componentsArray .forEach (componentNode -> augmentComponentNode ((JSONObject ) componentNode , artifacts ));
249
+ }
250
+
254
251
/* Save the augmented SBOM back to the file */
255
252
Files .writeString (baseSBOMPath , sbomJson .toString (2 ));
256
253
}
You can’t perform that action at this time.
0 commit comments