diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java index bdf3f6f86f61d..64ae6a2224ef2 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java @@ -182,8 +182,8 @@ private List computeRequiredExtensions(ExtensionCatalog catalog, @SuppressWarnings("unchecked") private List getExtensionOrigins(ExtensionCatalog extensionCatalog, List extensionsToAdd) throws QuarkusCommandException { - final ElementCatalog ec = (ElementCatalog) extensionCatalog.getMetadata() - .get("element-catalog"); + final ElementCatalog ec = ElementCatalogBuilder.getElementCatalog(extensionCatalog, + ExtensionCatalog.class); if (ec == null) { return Collections.emptyList(); } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/platform/tools/ToolsUtils.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/platform/tools/ToolsUtils.java index 8e2fc59613cf6..9e0348c1201df 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/platform/tools/ToolsUtils.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/platform/tools/ToolsUtils.java @@ -7,13 +7,17 @@ import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; import io.quarkus.devtools.messagewriter.MessageWriter; import io.quarkus.maven.ArtifactCoords; +import io.quarkus.registry.PlatformStackIndex; import io.quarkus.registry.catalog.ExtensionCatalog; import io.quarkus.registry.catalog.json.JsonCatalogMapperHelper; import io.quarkus.registry.catalog.json.JsonCatalogMerger; import io.quarkus.registry.catalog.json.JsonExtensionCatalog; +import io.quarkus.registry.union.ElementCatalogBuilder; +import io.quarkus.registry.union.ElementCatalogBuilder.UnionBuilder; 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; @@ -115,11 +119,54 @@ 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 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 catalogs = new ArrayList<>(memberList.size()); + final ElementCatalogBuilder elementsBuilder = ElementCatalogBuilder.newInstance(); + final UnionBuilder union = elementsBuilder + .getOrCreateUnion(PlatformStackIndex.initial()); + + for (Object m : memberList) { + if (!(m instanceof String)) { + continue; + } + final ExtensionCatalog memberCatalog; + if (catalog.getId().equals(m)) { + memberCatalog = catalog; + } else { + 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(); + memberCatalog = JsonCatalogMapperHelper.deserialize(jsonPath, + JsonExtensionCatalog.class); + } catch (Exception e) { + log.warn("Failed to resolve member catalog " + m, e); + continue; + } + } + catalogs.add(memberCatalog); + ElementCatalogBuilder.addUnionMember(union, memberCatalog); + } + catalog = JsonCatalogMerger.merge(catalogs); + ElementCatalogBuilder.setElementCatalog(catalog, elementsBuilder.build()); + } + } + } + return catalog; } public static ExtensionCatalog mergePlatforms(List platforms, MavenArtifactResolver artifactResolver) { diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/ExtensionCatalogResolver.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/ExtensionCatalogResolver.java index 121ce08b79f07..d2a8183e6bd43 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/ExtensionCatalogResolver.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/ExtensionCatalogResolver.java @@ -19,9 +19,7 @@ import io.quarkus.registry.config.RegistriesConfig; import io.quarkus.registry.config.RegistriesConfigLocator; import io.quarkus.registry.config.RegistryConfig; -import io.quarkus.registry.union.ElementCatalog; import io.quarkus.registry.union.ElementCatalogBuilder; -import io.quarkus.registry.union.ElementCatalogBuilder.MemberBuilder; import io.quarkus.registry.union.ElementCatalogBuilder.UnionBuilder; import java.io.File; import java.net.URL; @@ -280,7 +278,7 @@ public ExtensionCatalog resolveExtensionCatalog() throws RegistryResolutionExcep for (ArtifactCoords bom : release.getMemberBoms()) { final ExtensionCatalog ec = registry.resolvePlatformExtensions(bom); catalogs.add(ec); - addUnion(union, ec); + ElementCatalogBuilder.addUnionMember(union, ec); } final Map> registriesByQuarkusCore = new HashMap<>(2); @@ -298,10 +296,7 @@ public ExtensionCatalog resolveExtensionCatalog() throws RegistryResolutionExcep } final ExtensionCatalog catalog = JsonCatalogMerger.merge(catalogs); - final ElementCatalog elements = catalogBuilder.build(); - if (!elements.isEmpty()) { - catalog.getMetadata().put("element-catalog", elements); - } + ElementCatalogBuilder.setElementCatalog(catalog, catalogBuilder.build()); return catalog; } @@ -476,7 +471,7 @@ public ExtensionCatalog resolveExtensionCatalog(StreamCoords streamCoords) throw for (ArtifactCoords bom : release.getMemberBoms()) { final ExtensionCatalog ec = registry.resolvePlatformExtensions(bom); catalogs.add(ec); - addUnion(union, ec); + ElementCatalogBuilder.addUnionMember(union, ec); } final Map> registriesByQuarkusCore = new HashMap<>(2); @@ -490,11 +485,7 @@ public ExtensionCatalog resolveExtensionCatalog(StreamCoords streamCoords) throw appendNonPlatformExtensions(registriesByQuarkusCore, union, catalogs); final ExtensionCatalog catalog = JsonCatalogMerger.merge(catalogs); - - final ElementCatalog elements = catalogBuilder.build(); - if (!elements.isEmpty()) { - catalog.getMetadata().put("element-catalog", elements); - } + ElementCatalogBuilder.setElementCatalog(catalog, catalogBuilder.build()); return catalog; } @@ -505,14 +496,6 @@ private void ensureRegistriesConfigured() throws RegistryResolutionException { } } - private void addUnion(final UnionBuilder union, final ExtensionCatalog ec) { - final MemberBuilder builder = union.getOrCreateMember( - ec.getId(), ec.getBom().getVersion(), ec); - ec.getExtensions() - .forEach(e -> builder - .addElement(e.getArtifact().getGroupId() + ":" + e.getArtifact().getArtifactId())); - } - public ExtensionCatalog resolveExtensionCatalog(Collection platforms) throws RegistryResolutionException { if (platforms.isEmpty()) { @@ -587,7 +570,8 @@ private void appendNonPlatformExtensions( if (nonPlatformCatalog != null) { extensionCatalogs.add(nonPlatformCatalog); if (union != null) { - addUnion(union, nonPlatformCatalog); + final UnionBuilder union1 = union; + ElementCatalogBuilder.addUnionMember(union1, nonPlatformCatalog); } } } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/PlatformStackIndex.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/PlatformStackIndex.java index 59c25284b7b9c..4ea9c74bc9494 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/PlatformStackIndex.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/PlatformStackIndex.java @@ -2,9 +2,9 @@ import io.quarkus.registry.union.UnionVersion; -class PlatformStackIndex implements UnionVersion { +public class PlatformStackIndex implements UnionVersion { - static PlatformStackIndex initial() { + public static PlatformStackIndex initial() { return new PlatformStackIndex(0, 0, 0); } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/union/ElementCatalogBuilder.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/union/ElementCatalogBuilder.java index 43f3fefb61a55..0ae02049675f9 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/union/ElementCatalogBuilder.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/union/ElementCatalogBuilder.java @@ -1,5 +1,6 @@ package io.quarkus.registry.union; +import io.quarkus.registry.catalog.ExtensionCatalog; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collection; @@ -367,4 +368,21 @@ public static List getMembersForElements(ElementCatalog elementCatalog return Collections.emptyList(); } + public static void addUnionMember(final UnionBuilder union, final ExtensionCatalog ec) { + final MemberBuilder builder = union.getOrCreateMember( + ec.getId(), ec.getBom().getVersion(), ec); + ec.getExtensions() + .forEach(e -> builder + .addElement(e.getArtifact().getGroupId() + ":" + e.getArtifact().getArtifactId())); + } + + public static void setElementCatalog(ExtensionCatalog extCatalog, ElementCatalog elemCatalog) { + if (!elemCatalog.isEmpty()) { + extCatalog.getMetadata().put("element-catalog", elemCatalog); + } + } + + public static ElementCatalog getElementCatalog(ExtensionCatalog extCatalog, Class t) { + return (ElementCatalog) extCatalog.getMetadata().get("element-catalog"); + } }