Skip to content

Commit

Permalink
SDevtools: spport pulling in the complete platform catalog from a sin…
Browse files Browse the repository at this point in the history
…gle member bom
  • Loading branch information
aloubyansky committed Jun 18, 2021
1 parent 9c1c33e commit 45fa3f1
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -115,11 +116,41 @@ public static ExtensionCatalog resolvePlatformDescriptorDirectly(String bomGroup
throw new RuntimeException("Failed to resolve the default platform JSON descriptor", e);
}
}
ExtensionCatalog catalog;
try {
return JsonCatalogMapperHelper.deserialize(platformJson, JsonExtensionCatalog.class);
catalog = JsonCatalogMapperHelper.deserialize(platformJson, JsonExtensionCatalog.class);
} catch (IOException e) {
throw new RuntimeException("Failed to deserialize extension catalog " + platformJson, e);
}
Map<String, Object> md = catalog.getMetadata();
if (md != null) {
Object o = md.get("platform-release");
if (o instanceof Map) {
Object members = ((Map<?, ?>) o).get("members");
if (members instanceof Collection) {
final Collection<?> memberList = (Collection<?>) members;
final List<ExtensionCatalog> catalogs = new ArrayList<>(memberList.size());
for (Object m : memberList) {
if (m instanceof String && !catalog.getId().equals(m)) {
try {
final ArtifactCoords coords = ArtifactCoords.fromString((String) m);
catalogCoords = new DefaultArtifact(coords.getGroupId(), coords.getArtifactId(),
coords.getClassifier(), coords.getType(), coords.getVersion());
log.debug("Resolving platform descriptor %s", catalogCoords);
final Path jsonPath = artifactResolver.resolve(catalogCoords).getArtifact().getFile().toPath();
catalogs.add(JsonCatalogMapperHelper.deserialize(jsonPath, JsonExtensionCatalog.class));
} catch (Exception e) {
log.warn("Failed to resolve member catalog " + m, e);
}
} else {
catalogs.add(catalog);
}
}
catalog = JsonCatalogMerger.merge(catalogs);
}
}
}
return catalog;
}

public static ExtensionCatalog mergePlatforms(List<ArtifactCoords> platforms, MavenArtifactResolver artifactResolver) {
Expand Down

0 comments on commit 45fa3f1

Please sign in to comment.