diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java index af94c3c574f0c..708766eca7fc5 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java @@ -3,13 +3,10 @@ import static io.quarkus.devtools.project.CodestartResourceLoadersBuilder.codestartLoadersBuilder; import static org.fusesource.jansi.Ansi.ansi; -import java.io.BufferedWriter; import java.io.File; import java.io.IOException; -import java.io.StringWriter; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -50,7 +47,6 @@ import io.quarkus.registry.ExtensionCatalogResolver; import io.quarkus.registry.RegistryResolutionException; import io.quarkus.registry.catalog.ExtensionCatalog; -import io.quarkus.registry.catalog.Platform; import io.quarkus.registry.catalog.PlatformCatalog; /** @@ -345,45 +341,8 @@ static ExtensionCatalog resolveExtensionsCatalog(String groupId, String artifact throw new MojoExecutionException( "No platforms are available. Please make sure your .quarkus/config.yaml configuration includes proper extensions registry configuration"); } - ArtifactCoords matchedBom = null; - List matchedBoms = null; - for (Platform p : platformsCatalog.getPlatforms()) { - final ArtifactCoords bom = p.getBom(); - if (version != null && !bom.getVersion().equals(version)) { - continue; - } - if (artifactId != null && !bom.getArtifactId().equals(artifactId)) { - continue; - } - if (groupId != null && !bom.getGroupId().equals(groupId)) { - continue; - } - if (matchedBom != null) { - if (matchedBoms == null) { - matchedBoms = new ArrayList<>(); - matchedBoms.add(matchedBom); - } - matchedBoms.add(bom); - } else { - matchedBom = bom; - } - } - if (matchedBoms != null) { - StringWriter buf = new StringWriter(); - buf.append("Multiple platforms were matching the requested platform BOM coordinates "); - buf.append(groupId == null ? "*" : groupId).append(':'); - buf.append(artifactId == null ? "*" : artifactId).append(':'); - buf.append(version == null ? "*" : version).append(": "); - try (BufferedWriter writer = new BufferedWriter(buf)) { - for (ArtifactCoords bom : matchedBoms) { - writer.newLine(); - writer.append("- ").append(bom.toString()); - } - } catch (IOException e) { - // - } - throw new MojoExecutionException(buf.toString()); - } + final ArtifactCoords matchedBom = QuarkusProjectMojoBase.getSingleMatchingBom(groupId, artifactId, version, + platformsCatalog); return catalogResolver.resolveExtensionCatalog(Arrays.asList(matchedBom)); } catch (RegistryResolutionException e) { throw new MojoExecutionException("Failed to resolve the extensions catalog", e); diff --git a/devtools/maven/src/main/java/io/quarkus/maven/ListUpdatesMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/ListUpdatesMojo.java deleted file mode 100644 index eee1e9f479c49..0000000000000 --- a/devtools/maven/src/main/java/io/quarkus/maven/ListUpdatesMojo.java +++ /dev/null @@ -1,93 +0,0 @@ -package io.quarkus.maven; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; - -import io.quarkus.devtools.messagewriter.MessageWriter; -import io.quarkus.devtools.project.QuarkusProject; -import io.quarkus.registry.Constants; -import io.quarkus.registry.RegistryResolutionException; -import io.quarkus.registry.catalog.Platform; -import io.quarkus.registry.catalog.PlatformCatalog; - -/** - * List updates available for the project - */ -@Mojo(name = "list-updates", requiresProject = false) -public class ListUpdatesMojo extends QuarkusProjectMojoBase { - - /** - * List the already installed extensions - */ - @Parameter(property = "installed", defaultValue = "false") - protected boolean installed; - - @Override - public void doExecute(final QuarkusProject quarkusProject, final MessageWriter log) throws MojoExecutionException { - - final PlatformCatalog catalog; - try { - catalog = getExtensionCatalogResolver().resolvePlatformCatalog(); - } catch (RegistryResolutionException e) { - throw new MojoExecutionException("Failed to resolve the Quarkus platform catalog", e); - } - final List platforms = catalog == null ? Collections.emptyList() : catalog.getPlatforms(); - if (platforms.isEmpty()) { - return; - } - List latestList = new ArrayList<>(platforms.size()); - for (Platform p : platforms) { - final ArtifactCoords bom = p.getBom(); - latestList.add(bom); - } - - final List platformJsons = getImportedPlatforms(); - final List importedPlatformBoms = new ArrayList<>(platformJsons.size()); - for (ArtifactCoords descriptor : platformJsons) { - final ArtifactCoords importedBom = new ArtifactCoords(descriptor.getGroupId(), - descriptor.getArtifactId().substring(0, - descriptor.getArtifactId().length() - Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX.length()), - null, "pom", descriptor.getVersion()); - if (!latestList.remove(importedBom)) { - importedPlatformBoms.add(importedBom); - } - } - - final Map latest = new HashMap<>(platforms.size()); - for (ArtifactCoords latestBom : latestList) { - latest.put(latestBom.getKey(), latestBom.getVersion()); - } - - log.info("Available Quarkus platform updates:"); - final StringBuilder buf = new StringBuilder(0); - for (ArtifactCoords importedBom : importedPlatformBoms) { - final ArtifactKey key = importedBom.getKey(); - final String update = latest.get(key); - if (update == null || importedBom.getVersion().equals(update)) { - continue; - } - buf.setLength(0); - buf.append(key.getGroupId()).append(':').append(key.getArtifactId()); - for (int i = buf.length(); i < 45; ++i) { - buf.append(' '); - } - buf.append(importedBom.getVersion()); - for (int i = buf.length(); i < 60; ++i) { - buf.append(' '); - } - buf.append(" -> ").append(update); - log.info(buf.toString()); - } - - if (buf.length() == 0) { - log.info("No updates yet, ping @gsmet"); - } - } -} diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java index ba3d3c82f3ad9..19d3b2e5f5657 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java @@ -40,6 +40,9 @@ import io.quarkus.registry.RegistryResolutionException; import io.quarkus.registry.catalog.ExtensionCatalog; import io.quarkus.registry.catalog.Platform; +import io.quarkus.registry.catalog.PlatformCatalog; +import io.quarkus.registry.catalog.PlatformRelease; +import io.quarkus.registry.catalog.PlatformStream; public abstract class QuarkusProjectMojoBase extends AbstractMojo { @@ -139,47 +142,13 @@ protected List getImportedPlatforms() throws MojoExecutionExcept if (bomGroupId == null) { bomGroupId = ToolsConstants.DEFAULT_PLATFORM_BOM_GROUP_ID; } - final ExtensionCatalogResolver catalogResolver = getExtensionCatalogResolver(); ArtifactCoords platformBom = null; - List matches = null; try { - for (Platform p : catalogResolver.resolvePlatformCatalog().getPlatforms()) { - final ArtifactCoords bom = p.getBom(); - if (bomGroupId != null && !bom.getGroupId().equals(bomGroupId)) { - continue; - } - if (bomArtifactId != null && !bom.getArtifactId().equals(bomArtifactId)) { - continue; - } - if (bomVersion != null && !bom.getVersion().equals(bomVersion)) { - continue; - } - if (platformBom == null) { - platformBom = bom; - } else { - if (matches == null) { - matches = new ArrayList<>(); - matches.add(platformBom); - } - matches.add(bom); - } - } + platformBom = getSingleMatchingBom(bomGroupId, bomArtifactId, bomVersion, + getExtensionCatalogResolver().resolvePlatformCatalog()); } catch (RegistryResolutionException e) { throw new MojoExecutionException("Failed to resolve the catalog of Quarkus platforms", e); } - if (matches != null) { - final StringWriter buf = new StringWriter(); - buf.append("Found multiple platforms matching the provided arguments: "); - try (BufferedWriter writer = new BufferedWriter(buf)) { - for (ArtifactCoords coords : matches) { - writer.newLine(); - writer.append("- ").append(coords.toString()); - } - } catch (IOException e) { - buf.append(matches.toString()); - } - throw new MojoExecutionException(buf.toString()); - } return importedPlatforms = Collections.singletonList(platformBom); } importedPlatforms = collectImportedPlatforms(); @@ -247,4 +216,59 @@ private Artifact projectArtifact() { project.getVersion()) : projectArtifact; } + + static ArtifactCoords getSingleMatchingBom(String bomGroupId, String bomArtifactId, String bomVersion, + PlatformCatalog platformCatalog) throws MojoExecutionException { + if (bomGroupId == null && bomArtifactId == null && bomVersion == null) { + return null; + } + if (bomGroupId == null) { + bomGroupId = ToolsConstants.DEFAULT_PLATFORM_BOM_GROUP_ID; + } + ArtifactCoords platformBom = null; + List matches = null; + for (Platform p : platformCatalog.getPlatforms()) { + if (bomGroupId != null && !p.getPlatformKey().equals(bomGroupId)) { + continue; + } + for (PlatformStream s : p.getStreams()) { + for (PlatformRelease r : s.getReleases()) { + for (ArtifactCoords bom : r.getMemberBoms()) { + if (bomArtifactId != null && !bom.getArtifactId().equals(bomArtifactId)) { + continue; + } + if (bomVersion != null && !bom.getVersion().equals(bomVersion)) { + continue; + } + if (platformBom == null) { + platformBom = bom; + } else { + if (matches == null) { + matches = new ArrayList<>(); + matches.add(platformBom); + } + matches.add(bom); + } + } + } + } + } + if (matches != null) { + StringWriter buf = new StringWriter(); + buf.append("Multiple platforms were matching the requested platform BOM coordinates "); + buf.append(bomGroupId == null ? "*" : bomGroupId).append(':'); + buf.append(bomArtifactId == null ? "*" : bomArtifactId).append(':'); + buf.append(bomVersion == null ? "*" : bomVersion).append(": "); + try (BufferedWriter writer = new BufferedWriter(buf)) { + for (ArtifactCoords bom : matches) { + writer.newLine(); + writer.append("- ").append(bom.toString()); + } + } catch (IOException e) { + // + } + throw new MojoExecutionException(buf.toString()); + } + return platformBom; + } } diff --git a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/RegistryClientTestHelper.java b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/RegistryClientTestHelper.java index a339ed45d0da3..d190c07285143 100644 --- a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/RegistryClientTestHelper.java +++ b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/RegistryClientTestHelper.java @@ -5,6 +5,8 @@ import io.quarkus.registry.catalog.json.JsonCatalogMapperHelper; import io.quarkus.registry.catalog.json.JsonPlatform; import io.quarkus.registry.catalog.json.JsonPlatformCatalog; +import io.quarkus.registry.catalog.json.JsonPlatformRelease; +import io.quarkus.registry.catalog.json.JsonPlatformStream; import io.quarkus.registry.config.RegistriesConfigLocator; import io.quarkus.registry.config.json.JsonRegistriesConfig; import io.quarkus.registry.config.json.JsonRegistryConfig; @@ -19,6 +21,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.util.Collections; import java.util.Properties; public class RegistryClientTestHelper { @@ -64,11 +67,16 @@ private static void generatePlatformCatalog(final Path groupIdDir) { } final ArtifactCoords bom = new ArtifactCoords("io.quarkus", "quarkus-bom", null, "pom", projectVersion); final JsonPlatformCatalog platforms = new JsonPlatformCatalog(); - platforms.setDefaultPlatform(bom); final JsonPlatform platform = new JsonPlatform(); platforms.addPlatform(platform); - platform.setBom(bom); - platform.setQuarkusCoreVersion(projectVersion); + platform.setPlatformKey(bom.getGroupId()); + final JsonPlatformStream stream = new JsonPlatformStream(); + platform.setStreams(Collections.singletonList(stream)); + stream.setId(projectVersion); + final JsonPlatformRelease release = new JsonPlatformRelease(); + stream.setReleases(Collections.singletonList(release)); + release.setMemberBoms(Collections.singletonList(bom)); + release.setQuarkusCoreVersion(projectVersion); try { JsonCatalogMapperHelper.serialize(platforms, platformsPath); Files.copy(platformsPath, versionedPlatformsPath, StandardCopyOption.REPLACE_EXISTING); 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 e3ac2da89374a..c3bb2099a9ded 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 @@ -4,10 +4,11 @@ import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; import io.quarkus.devtools.messagewriter.MessageWriter; import io.quarkus.maven.ArtifactCoords; -import io.quarkus.maven.ArtifactKey; import io.quarkus.registry.catalog.ExtensionCatalog; import io.quarkus.registry.catalog.Platform; import io.quarkus.registry.catalog.PlatformCatalog; +import io.quarkus.registry.catalog.PlatformRelease; +import io.quarkus.registry.catalog.PlatformStream; import io.quarkus.registry.catalog.json.JsonCatalogMerger; import io.quarkus.registry.catalog.json.JsonPlatformCatalog; import io.quarkus.registry.client.RegistryClientFactory; @@ -214,7 +215,6 @@ public PlatformCatalog resolvePlatformCatalog() throws RegistryResolutionExcepti } public PlatformCatalog resolvePlatformCatalog(String quarkusVersion) throws RegistryResolutionException { - final Set collectedPlatformKeys = new HashSet<>(); List catalogs = new ArrayList<>(registries.size()); for (RegistryExtensionResolver qer : registries) { @@ -233,12 +233,10 @@ public PlatformCatalog resolvePlatformCatalog(String quarkusVersion) throws Regi final JsonPlatformCatalog result = new JsonPlatformCatalog(); - result.setDefaultPlatform(catalogs.get(0).getDefaultPlatform()); - final List collectedPlatforms = new ArrayList<>(); result.setPlatforms(collectedPlatforms); - collectedPlatformKeys.clear(); + final Set collectedPlatformKeys = new HashSet<>(); for (PlatformCatalog c : catalogs) { collectPlatforms(c, collectedPlatforms, collectedPlatformKeys); } @@ -247,9 +245,9 @@ public PlatformCatalog resolvePlatformCatalog(String quarkusVersion) throws Regi } private void collectPlatforms(PlatformCatalog catalog, List collectedPlatforms, - Set collectedPlatformKeys) { + Set collectedPlatformKeys) { for (Platform p : catalog.getPlatforms()) { - if (collectedPlatformKeys.add(p.getBom().getKey())) { + if (collectedPlatformKeys.add(p.getPlatformKey())) { collectedPlatforms.add(p); } } @@ -274,8 +272,17 @@ public ExtensionCatalog resolveExtensionCatalog() throws RegistryResolutionExcep if (pc == null) { continue; } - for (Platform p : pc.getPlatforms()) { - final ExtensionCatalog ec = registry.resolvePlatformExtensions(p.getBom()); + final Platform platform = pc.getRecommendedPlatform(); + if (platform == null) { + continue; + } + final PlatformStream stream = platform.getRecommendedStream(); + if (stream == null) { + continue; + } + final PlatformRelease release = stream.getRecommendedRelease(); + for (ArtifactCoords bom : release.getMemberBoms()) { + final ExtensionCatalog ec = registry.resolvePlatformExtensions(bom); catalogs.add(ec); platformDescrMap.put(ec.getBom().getGroupId() + ":" + ec.getBom().getArtifactId(), ec); @@ -340,25 +347,31 @@ public ExtensionCatalog resolveExtensionCatalog(String quarkusCoreVersion) throw // on the same quarkus version then we don't need to execute extra requests to align the platforms // on the common quarkus version if (registriesTotal == 1) { - final PlatformCatalog platformsCatalog = registries.get(0).resolvePlatformCatalog(); - final List platforms = platformsCatalog == null ? Collections.emptyList() - : platformsCatalog.getPlatforms(); - if (platforms.isEmpty()) { + final PlatformCatalog platformCatalog = registries.get(0).resolvePlatformCatalog(); + final Platform recommendedPlatform = platformCatalog == null ? null : platformCatalog.getRecommendedPlatform(); + if (recommendedPlatform == null) { // TODO this should be allowed throw new RegistryResolutionException( "Registry " + registries.get(0).getId() + " does not provide any platform"); } - String commonQuarkusVersion = quarkusCoreVersion = platforms.get(0).getQuarkusCoreVersion(); - Platform defaultPlatform = null; + PlatformRelease release = recommendedPlatform.getRecommendedStream().getRecommendedRelease(); + List recommendedReleases = new ArrayList<>(1); + recommendedReleases.add(release); + String commonQuarkusVersion = quarkusCoreVersion = release.getQuarkusCoreVersion(); int i = 1; - while (i < platforms.size()) { - final Platform p = platforms.get(i++); - if (defaultPlatform == null && p.getBom().equals(platformsCatalog.getDefaultPlatform())) { - defaultPlatform = p; - quarkusCoreVersion = p.getQuarkusCoreVersion(); - } - if (commonQuarkusVersion != null && !commonQuarkusVersion.equals(p.getQuarkusCoreVersion())) { - commonQuarkusVersion = null; + while (i < platformCatalog.getPlatforms().size() && commonQuarkusVersion != null) { + final Platform p = platformCatalog.getPlatforms().get(i++); + for (PlatformStream s : p.getStreams()) { + for (PlatformRelease r : s.getReleases()) { + if (!r.getQuarkusCoreVersion().equals(commonQuarkusVersion)) { + commonQuarkusVersion = null; + break; + } + recommendedReleases.add(r); + } + if (commonQuarkusVersion == null) { + break; + } } } if (commonQuarkusVersion != null) { @@ -367,12 +380,15 @@ public ExtensionCatalog resolveExtensionCatalog(String quarkusCoreVersion) throw registriesByQuarkusCore.put(commonQuarkusVersion, Arrays.asList(mainRegistry)); extensionCatalogs = new ArrayList<>(); i = 0; - while (i < platforms.size()) { - extensionCatalogs.add(mainRegistry.resolvePlatformExtensions(platforms.get(i++).getBom())); + while (i < recommendedReleases.size()) { + for (ArtifactCoords bom : recommendedReleases.get(i++).getMemberBoms()) { + extensionCatalogs.add(mainRegistry.resolvePlatformExtensions(bom)); + } } } } else { - quarkusCoreVersion = registries.get(0).resolveDefaultPlatform().getQuarkusCoreVersion(); + quarkusCoreVersion = registries.get(0).resolveRecommendedPlatform().getRecommendedStream() + .getRecommendedRelease().getQuarkusCoreVersion(); } } @@ -500,14 +516,19 @@ private void collectPlatforms(String quarkusCoreVersion, continue; } for (Platform p : platforms) { - final String upstreamQuarkusCoreVersion = p.getUpstreamQuarkusCoreVersion(); - if (upstreamQuarkusCoreVersion != null - && !registriesByQuarkusCore.containsKey(upstreamQuarkusCoreVersion)) { - upstreamQuarkusVersions.add(upstreamQuarkusCoreVersion); - } - final ExtensionCatalog catalog = registry.resolvePlatformExtensions(p.getBom()); - if (catalog != null) { - extensionCatalogs.add(catalog); + for (PlatformStream s : p.getStreams()) { + final PlatformRelease r = s.getRecommendedRelease(); + final String upstreamQuarkusCoreVersion = r.getUpstreamQuarkusCoreVersion(); + if (upstreamQuarkusCoreVersion != null + && !registriesByQuarkusCore.containsKey(upstreamQuarkusCoreVersion)) { + upstreamQuarkusVersions.add(upstreamQuarkusCoreVersion); + } + for (ArtifactCoords bom : r.getMemberBoms()) { + final ExtensionCatalog catalog = registry.resolvePlatformExtensions(bom); + if (catalog != null) { + extensionCatalogs.add(catalog); + } + } } } } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/RegistryExtensionResolver.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/RegistryExtensionResolver.java index 6727b1b08f45f..ff35d59f96891 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/RegistryExtensionResolver.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/RegistryExtensionResolver.java @@ -8,7 +8,6 @@ import io.quarkus.registry.client.RegistryClient; import io.quarkus.registry.config.RegistryConfig; import io.quarkus.registry.util.GlobUtil; -import java.util.Iterator; import java.util.Objects; import java.util.regex.Pattern; @@ -64,22 +63,8 @@ PlatformCatalog resolvePlatformCatalog(String quarkusCoreVersion) throws Registr return extensionResolver.resolvePlatforms(quarkusCoreVersion); } - Platform resolveDefaultPlatform() throws RegistryResolutionException { - final PlatformCatalog platformsCatalog = resolvePlatformCatalog(); - final ArtifactCoords defaultCoords = platformsCatalog.getDefaultPlatform(); - for (Platform p : platformsCatalog.getPlatforms()) { - if (defaultCoords.equals(p.getBom())) { - return p; - } - } - final StringBuilder buf = new StringBuilder(); - buf.append("Failed to locate the default platform ").append(defaultCoords).append(" in the catalog of "); - final Iterator i = platformsCatalog.getPlatforms().iterator(); - buf.append(i.next().getBom()); - while (i.hasNext()) { - buf.append(", ").append(i.next().getBom()); - } - throw new RegistryResolutionException(buf.toString()); + Platform resolveRecommendedPlatform() throws RegistryResolutionException { + return resolvePlatformCatalog().getRecommendedPlatform(); } ExtensionCatalog resolveNonPlatformExtensions(String quarkusCoreVersion) throws RegistryResolutionException { diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/Platform.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/Platform.java index 99ade7d77a364..2d9046ee4db7a 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/Platform.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/Platform.java @@ -1,12 +1,25 @@ package io.quarkus.registry.catalog; -import io.quarkus.maven.ArtifactCoords; +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.List; +import java.util.Map; public interface Platform { - ArtifactCoords getBom(); + String getPlatformKey(); - String getQuarkusCoreVersion(); + String getName(); - String getUpstreamQuarkusCoreVersion(); + List getStreams(); + + Map getMetadata(); + + @JsonIgnore + default PlatformStream getRecommendedStream() { + final List streams = getStreams(); + if (streams.isEmpty()) { + throw new RuntimeException("Platform " + getPlatformKey() + " does not include any stream"); + } + return streams.get(0); + } } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformCatalog.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformCatalog.java index 30954d3da4dbf..adfeefd42102e 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformCatalog.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformCatalog.java @@ -1,11 +1,18 @@ package io.quarkus.registry.catalog; -import io.quarkus.maven.ArtifactCoords; +import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.List; +import java.util.Map; public interface PlatformCatalog { List getPlatforms(); - ArtifactCoords getDefaultPlatform(); + Map getMetadata(); + + @JsonIgnore + default Platform getRecommendedPlatform() { + final List platforms = getPlatforms(); + return platforms.isEmpty() ? null : platforms.get(0); + } } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformRelease.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformRelease.java new file mode 100644 index 0000000000000..694ec556949ee --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformRelease.java @@ -0,0 +1,21 @@ +package io.quarkus.registry.catalog; + +import io.quarkus.maven.ArtifactCoords; +import java.util.Collection; +import java.util.Map; + +/** + * Platform release + */ +public interface PlatformRelease { + + PlatformReleaseVersion getVersion(); + + Collection getMemberBoms(); + + String getQuarkusCoreVersion(); + + String getUpstreamQuarkusCoreVersion(); + + Map getMetadata(); +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformReleaseVersion.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformReleaseVersion.java new file mode 100644 index 0000000000000..48723191e8380 --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformReleaseVersion.java @@ -0,0 +1,5 @@ +package io.quarkus.registry.catalog; + +public interface PlatformReleaseVersion extends Comparable { + +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformStack.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformStack.java new file mode 100644 index 0000000000000..4696e7c32a05c --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformStack.java @@ -0,0 +1,14 @@ +package io.quarkus.registry.catalog; + +import java.util.Collection; + +public interface PlatformStack { + + String getPlatformKey(); + + String getPlatformName(); + + Collection getStreams(); + + PlatformStream getStream(String streamId); +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformStream.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformStream.java new file mode 100644 index 0000000000000..05c737770c36f --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/PlatformStream.java @@ -0,0 +1,25 @@ +package io.quarkus.registry.catalog; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.List; +import java.util.Map; + +public interface PlatformStream { + + String getId(); + + String getName(); + + List getReleases(); + + Map getMetadata(); + + @JsonIgnore + default PlatformRelease getRecommendedRelease() { + final List releases = getReleases(); + if (releases.isEmpty()) { + throw new RuntimeException("Stream " + getId() + " does not include any release"); + } + return releases.get(0); + } +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonCategory.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonCategory.java index 154e5f502e311..c9cc1bc48d74e 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonCategory.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonCategory.java @@ -6,7 +6,7 @@ import java.util.Map; import java.util.Objects; -@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class JsonCategory implements Category { protected String id; diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonEntityWithAnySupport.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonEntityWithAnySupport.java new file mode 100644 index 0000000000000..d43f773818aff --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonEntityWithAnySupport.java @@ -0,0 +1,29 @@ +package io.quarkus.registry.catalog.json; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +abstract class JsonEntityWithAnySupport { + + private Map metadata; + + @JsonAnyGetter + public Map getMetadata() { + return metadata == null ? Collections.emptyMap() : metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + @JsonAnySetter + public void setAny(String name, Object value) { + if (metadata == null) { + metadata = new HashMap<>(); + } + metadata.put(name, value); + } +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonExtension.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonExtension.java index e91b4c64ae190..15aeed9ac2b02 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonExtension.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonExtension.java @@ -12,7 +12,7 @@ import java.util.Map; import java.util.Objects; -@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class JsonExtension implements Extension { private String name; diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonExtensionCatalog.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonExtensionCatalog.java index b043090ef12cb..c27bbf795c6c5 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonExtensionCatalog.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonExtensionCatalog.java @@ -11,7 +11,7 @@ import java.util.List; import java.util.Map; -@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class JsonExtensionCatalog extends JsonExtensionOrigin implements ExtensionCatalog { private String quarkusCore; diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatform.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatform.java index ba29ca4e5eb04..552d94fefb692 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatform.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatform.java @@ -1,52 +1,49 @@ package io.quarkus.registry.catalog.json; import com.fasterxml.jackson.annotation.JsonInclude; -import io.quarkus.maven.ArtifactCoords; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.quarkus.registry.catalog.Platform; -import java.util.Objects; +import io.quarkus.registry.catalog.PlatformStream; +import java.util.Collections; +import java.util.List; -@JsonInclude(JsonInclude.Include.NON_NULL) -public class JsonPlatform implements Platform { +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class JsonPlatform extends JsonEntityWithAnySupport implements Platform { - public static JsonPlatform of(ArtifactCoords bom) { - JsonPlatform p = new JsonPlatform(); - p.setBom(Objects.requireNonNull(bom, "bom can't be null")); - return p; - } - - private ArtifactCoords bom; - private String quarkusCore; - private String upstreamQuarkusCore; + private String platformKey; + private String name; + private List streams; @Override - public ArtifactCoords getBom() { - return bom; + public String getPlatformKey() { + return platformKey; } - public void setBom(ArtifactCoords bom) { - this.bom = bom; + public void setPlatformKey(String platformKey) { + this.platformKey = platformKey; } @Override - public String getQuarkusCoreVersion() { - return quarkusCore; + public String getName() { + return name; } - public void setQuarkusCoreVersion(String quarkusCore) { - this.quarkusCore = quarkusCore; + public void setName(String name) { + this.name = name; } @Override - public String getUpstreamQuarkusCoreVersion() { - return upstreamQuarkusCore; + @JsonDeserialize(contentAs = JsonPlatformStream.class) + public List getStreams() { + return streams == null ? Collections.emptyList() : streams; } - public void setUpstreamQuarkusCoreVersion(String upstreamQuarkusCore) { - this.upstreamQuarkusCore = upstreamQuarkusCore; + public void setStreams(List streams) { + this.streams = streams; } @Override public String toString() { - return "[platform " + bom + ", quarkus-core=" + quarkusCore + ", upstream-quarkus-core=" + upstreamQuarkusCore + "]"; + return platformKey + streams; } } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformCatalog.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformCatalog.java index 988993193c515..bc46be3b48643 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformCatalog.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformCatalog.java @@ -2,18 +2,16 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import io.quarkus.maven.ArtifactCoords; import io.quarkus.registry.catalog.Platform; import io.quarkus.registry.catalog.PlatformCatalog; import java.util.ArrayList; import java.util.Collections; import java.util.List; -@JsonInclude(JsonInclude.Include.NON_NULL) -public class JsonPlatformCatalog implements PlatformCatalog { +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class JsonPlatformCatalog extends JsonEntityWithAnySupport implements PlatformCatalog { private List platforms; - private ArtifactCoords defaultPlatform; @Override @JsonDeserialize(contentAs = JsonPlatform.class) @@ -31,13 +29,4 @@ public void addPlatform(Platform platform) { } platforms.add(platform); } - - @Override - public ArtifactCoords getDefaultPlatform() { - return defaultPlatform; - } - - public void setDefaultPlatform(ArtifactCoords defaultPlatform) { - this.defaultPlatform = defaultPlatform; - } } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformRelease.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformRelease.java new file mode 100644 index 0000000000000..3ed0c7711c7ef --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformRelease.java @@ -0,0 +1,62 @@ +package io.quarkus.registry.catalog.json; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import io.quarkus.maven.ArtifactCoords; +import io.quarkus.registry.catalog.PlatformRelease; +import io.quarkus.registry.catalog.PlatformReleaseVersion; +import java.util.Collection; +import java.util.Collections; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class JsonPlatformRelease extends JsonEntityWithAnySupport implements PlatformRelease { + + private PlatformReleaseVersion version; + private Collection memberBoms; + private String quarkusCoreVersion; + private String upstreamQuarkusCoreVersion; + + @Override + @JsonDeserialize(as = JsonPlatformReleaseVersion.class) + @JsonSerialize(as = JsonPlatformReleaseVersion.class) + public PlatformReleaseVersion getVersion() { + return version; + } + + public void setVersion(PlatformReleaseVersion version) { + this.version = version; + } + + @Override + public Collection getMemberBoms() { + return memberBoms == null ? Collections.emptyList() : memberBoms; + } + + public void setMemberBoms(Collection memberBoms) { + this.memberBoms = memberBoms; + } + + @Override + public String getQuarkusCoreVersion() { + return quarkusCoreVersion; + } + + public void setQuarkusCoreVersion(String quarkusCoreVersion) { + this.quarkusCoreVersion = quarkusCoreVersion; + } + + @Override + public String getUpstreamQuarkusCoreVersion() { + return upstreamQuarkusCoreVersion; + } + + public void setUpstreamQuarkusCoreVersion(String quarkusCoreVersion) { + this.upstreamQuarkusCoreVersion = quarkusCoreVersion; + } + + @Override + public String toString() { + return version.toString() + memberBoms; + } +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformReleaseVersion.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformReleaseVersion.java new file mode 100644 index 0000000000000..4fe0925af62f0 --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformReleaseVersion.java @@ -0,0 +1,59 @@ +package io.quarkus.registry.catalog.json; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import io.quarkus.registry.catalog.PlatformReleaseVersion; +import java.util.Objects; + +@JsonSerialize(using = JsonPlatformReleaseVersionSerializer.class) +@JsonDeserialize(using = JsonPlatformReleaseVersionDeserializer.class) +public class JsonPlatformReleaseVersion implements PlatformReleaseVersion { + + public static JsonPlatformReleaseVersion fromString(String s) { + return new JsonPlatformReleaseVersion(s); + } + + private final String version; + + private JsonPlatformReleaseVersion(String version) { + this.version = Objects.requireNonNull(version); + } + + @Override + public int compareTo(PlatformReleaseVersion o) { + if (o instanceof JsonPlatformReleaseVersion) { + return version.compareTo(((JsonPlatformReleaseVersion) o).version); + } + return 0; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + JsonPlatformReleaseVersion other = (JsonPlatformReleaseVersion) obj; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + @Override + public String toString() { + return version; + } +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformReleaseVersionDeserializer.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformReleaseVersionDeserializer.java new file mode 100644 index 0000000000000..13ba950a8e5bb --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformReleaseVersionDeserializer.java @@ -0,0 +1,17 @@ +package io.quarkus.registry.catalog.json; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import java.io.IOException; + +public class JsonPlatformReleaseVersionDeserializer extends JsonDeserializer { + + @Override + public JsonPlatformReleaseVersion deserialize(JsonParser p, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + return JsonPlatformReleaseVersion.fromString(p.getText()); + } + +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformReleaseVersionSerializer.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformReleaseVersionSerializer.java new file mode 100644 index 0000000000000..50791e6855222 --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformReleaseVersionSerializer.java @@ -0,0 +1,15 @@ +package io.quarkus.registry.catalog.json; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; + +public class JsonPlatformReleaseVersionSerializer extends JsonSerializer { + + @Override + public void serialize(JsonPlatformReleaseVersion value, JsonGenerator gen, SerializerProvider serializers) + throws IOException { + gen.writeString(value.toString()); + } +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformStream.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformStream.java new file mode 100644 index 0000000000000..cc4eea44ac49c --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/catalog/json/JsonPlatformStream.java @@ -0,0 +1,49 @@ +package io.quarkus.registry.catalog.json; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.quarkus.registry.catalog.PlatformRelease; +import io.quarkus.registry.catalog.PlatformStream; +import java.util.Collections; +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class JsonPlatformStream extends JsonEntityWithAnySupport implements PlatformStream { + + private String id; + private String name; + private List releases; + + @Override + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + @JsonDeserialize(contentAs = JsonPlatformRelease.class) + public List getReleases() { + return releases == null ? Collections.emptyList() : releases; + } + + public void setReleases(List releases) { + this.releases = releases; + } + + @Override + public String toString() { + return id + releases; + } +}