Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devtools: support pulling in the complete platform catalog from a single member bom #18011

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -182,8 +182,8 @@ private List<Extension> computeRequiredExtensions(ExtensionCatalog catalog,
@SuppressWarnings("unchecked")
private List<ExtensionCatalog> getExtensionOrigins(ExtensionCatalog extensionCatalog, List<Extension> extensionsToAdd)
throws QuarkusCommandException {
final ElementCatalog<ExtensionCatalog> ec = (ElementCatalog<ExtensionCatalog>) extensionCatalog.getMetadata()
.get("element-catalog");
final ElementCatalog<ExtensionCatalog> ec = ElementCatalogBuilder.getElementCatalog(extensionCatalog,
ExtensionCatalog.class);
if (ec == null) {
return Collections.emptyList();
}
Original file line number Diff line number Diff line change
@@ -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<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());
final ElementCatalogBuilder<ExtensionCatalog> elementsBuilder = ElementCatalogBuilder.newInstance();
final UnionBuilder<ExtensionCatalog> 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<ArtifactCoords> platforms, MavenArtifactResolver artifactResolver) {
Original file line number Diff line number Diff line change
@@ -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<String, List<RegistryExtensionResolver>> registriesByQuarkusCore = new HashMap<>(2);
@@ -298,10 +296,7 @@ public ExtensionCatalog resolveExtensionCatalog() throws RegistryResolutionExcep
}

final ExtensionCatalog catalog = JsonCatalogMerger.merge(catalogs);
final ElementCatalog<ExtensionCatalog> 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<String, List<RegistryExtensionResolver>> 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<ExtensionCatalog> 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<ExtensionCatalog> union, final ExtensionCatalog ec) {
final MemberBuilder<ExtensionCatalog> 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<ArtifactCoords> 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<ExtensionCatalog> union1 = union;
ElementCatalogBuilder.addUnionMember(union1, nonPlatformCatalog);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

Original file line number Diff line number Diff line change
@@ -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 <T> List<T> getMembersForElements(ElementCatalog<T> elementCatalog
return Collections.emptyList();
}

public static void addUnionMember(final UnionBuilder<ExtensionCatalog> union, final ExtensionCatalog ec) {
final MemberBuilder<ExtensionCatalog> 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 <T> ElementCatalog<T> getElementCatalog(ExtensionCatalog extCatalog, Class<T> t) {
return (ElementCatalog<T>) extCatalog.getMetadata().get("element-catalog");
}
}