From 4055bac39847d103ee526ac8646f5a1ab06e4881 Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Sun, 13 Jun 2021 08:49:59 +0200 Subject: [PATCH] Make the platform model easier to navigate Signed-off-by: Phillip Kruger --- .../registry/ExtensionCatalogResolver.java | 11 +++++-- .../io/quarkus/registry/catalog/Platform.java | 12 +++---- .../registry/catalog/PlatformCatalog.java | 12 +++---- .../registry/catalog/PlatformStream.java | 12 +++---- .../registry/catalog/json/JsonPlatform.java | 30 +++++++++++++++--- .../catalog/json/JsonPlatformCatalog.java | 28 ++++++++++++----- .../catalog/json/JsonPlatformStream.java | 31 ++++++++++++++++--- 7 files changed, 100 insertions(+), 36 deletions(-) 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 beb20a7b8462c..45bb385a7daf1 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 @@ -27,6 +27,7 @@ import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -326,8 +327,12 @@ public ExtensionCatalog resolveExtensionCatalog(String quarkusCoreVersion) throw recommendedReleases.add(release); String commonQuarkusVersion = quarkusCoreVersion = release.getQuarkusCoreVersion(); int i = 1; - while (i < platformCatalog.getPlatforms().size() && commonQuarkusVersion != null) { - final Platform p = platformCatalog.getPlatforms().get(i++); + Iterator platformsIterator = platformCatalog.getPlatforms().iterator(); + if (platformsIterator.hasNext()) { + platformsIterator.next(); // Skip index 0 + } + while (platformsIterator.hasNext() && commonQuarkusVersion != null) { + final Platform p = platformsIterator.next(); for (PlatformStream s : p.getStreams()) { for (PlatformRelease r : s.getReleases()) { if (!r.getQuarkusCoreVersion().equals(commonQuarkusVersion)) { @@ -478,7 +483,7 @@ private void collectPlatforms(String quarkusCoreVersion, if (platformCatalog == null) { continue; } - final List platforms = platformCatalog.getPlatforms(); + final Collection platforms = platformCatalog.getPlatforms(); if (platforms.isEmpty()) { continue; } 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 2d9046ee4db7a..46c5a9bf7453c 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,7 +1,6 @@ package io.quarkus.registry.catalog; -import com.fasterxml.jackson.annotation.JsonIgnore; -import java.util.List; +import java.util.Collection; import java.util.Map; public interface Platform { @@ -10,16 +9,17 @@ public interface Platform { String getName(); - List getStreams(); + Collection getStreams(); Map getMetadata(); - @JsonIgnore + PlatformStream getStream(String id); + default PlatformStream getRecommendedStream() { - final List streams = getStreams(); + final Collection streams = getStreams(); if (streams.isEmpty()) { throw new RuntimeException("Platform " + getPlatformKey() + " does not include any stream"); } - return streams.get(0); + return streams.iterator().next(); } } 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 adfeefd42102e..e37fd4ce0c2da 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,18 +1,18 @@ package io.quarkus.registry.catalog; -import com.fasterxml.jackson.annotation.JsonIgnore; -import java.util.List; +import java.util.Collection; import java.util.Map; public interface PlatformCatalog { - List getPlatforms(); + Collection getPlatforms(); Map getMetadata(); - @JsonIgnore + Platform getPlatform(String platformId); + default Platform getRecommendedPlatform() { - final List platforms = getPlatforms(); - return platforms.isEmpty() ? null : platforms.get(0); + final Collection platforms = getPlatforms(); + return platforms.isEmpty() ? null : platforms.iterator().next(); } } 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 index 05c737770c36f..441a00e490ffd 100644 --- 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 @@ -1,7 +1,6 @@ package io.quarkus.registry.catalog; -import com.fasterxml.jackson.annotation.JsonIgnore; -import java.util.List; +import java.util.Collection; import java.util.Map; public interface PlatformStream { @@ -10,16 +9,17 @@ public interface PlatformStream { String getName(); - List getReleases(); + Collection getReleases(); Map getMetadata(); - @JsonIgnore + PlatformRelease getRelease(PlatformReleaseVersion version); + default PlatformRelease getRecommendedRelease() { - final List releases = getReleases(); + final Collection releases = getReleases(); if (releases.isEmpty()) { throw new RuntimeException("Stream " + getId() + " does not include any release"); } - return releases.get(0); + return releases.iterator().next(); } } 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 552d94fefb692..dc1c539e843ab 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,18 +1,24 @@ package io.quarkus.registry.catalog.json; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.quarkus.registry.catalog.Platform; import io.quarkus.registry.catalog.PlatformStream; +import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; @JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonIgnoreProperties(value = { "recommendedStream" }) public class JsonPlatform extends JsonEntityWithAnySupport implements Platform { private String platformKey; private String name; - private List streams; + private Map streams; @Override public String getPlatformKey() { @@ -34,16 +40,32 @@ public void setName(String name) { @Override @JsonDeserialize(contentAs = JsonPlatformStream.class) - public List getStreams() { - return streams == null ? Collections.emptyList() : streams; + public Collection getStreams() { + return streams == null ? Collections.emptyList() : streams.values(); + } + + @Override + @JsonIgnore + public PlatformStream getStream(String id) { + return streams == null ? null : streams.get(id); } public void setStreams(List streams) { - this.streams = streams; + for (PlatformStream s : streams) { + addStream(s); + } + } + + public void addStream(PlatformStream stream) { + if (streams == null) { + streams = new LinkedHashMap<>(); + } + streams.put(stream.getId(), stream); } @Override public String toString() { 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 bc46be3b48643..6eb9ff853fe3f 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 @@ -1,32 +1,46 @@ package io.quarkus.registry.catalog.json; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.quarkus.registry.catalog.Platform; import io.quarkus.registry.catalog.PlatformCatalog; -import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; @JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonIgnoreProperties(value = { "recommendedPlatform" }) public class JsonPlatformCatalog extends JsonEntityWithAnySupport implements PlatformCatalog { - private List platforms; + private Map platforms; @Override @JsonDeserialize(contentAs = JsonPlatform.class) - public List getPlatforms() { - return platforms == null ? Collections.emptyList() : platforms; + public Collection getPlatforms() { + return platforms == null ? Collections.emptyList() : platforms.values(); + } + + @Override + @JsonIgnore + public Platform getPlatform(String platformId) { + return platforms == null ? null : platforms.get(platformId); } public void setPlatforms(List platforms) { - this.platforms = platforms; + for (Platform p : platforms) { + addPlatform(p); + } } public void addPlatform(Platform platform) { if (platforms == null) { - platforms = new ArrayList<>(); + platforms = new LinkedHashMap<>(); } - platforms.add(platform); + platforms.put(platform.getPlatformKey(), platform); } + } 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 index cc4eea44ac49c..6eb086b8a4ecd 100644 --- 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 @@ -1,18 +1,25 @@ package io.quarkus.registry.catalog.json; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.quarkus.registry.catalog.PlatformRelease; +import io.quarkus.registry.catalog.PlatformReleaseVersion; import io.quarkus.registry.catalog.PlatformStream; +import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; @JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonIgnoreProperties(value = { "recommendedRelease" }) public class JsonPlatformStream extends JsonEntityWithAnySupport implements PlatformStream { private String id; private String name; - private List releases; + private Map releases; @Override public String getId() { @@ -34,16 +41,32 @@ public void setName(String name) { @Override @JsonDeserialize(contentAs = JsonPlatformRelease.class) - public List getReleases() { - return releases == null ? Collections.emptyList() : releases; + public Collection getReleases() { + return releases == null ? Collections.emptyList() : releases.values(); + } + + @Override + @JsonIgnore + public PlatformRelease getRelease(PlatformReleaseVersion version) { + return releases == null ? null : releases.get(version); } public void setReleases(List releases) { - this.releases = releases; + for (PlatformRelease r : releases) { + addRelease(r); + } + } + + public void addRelease(PlatformRelease platformRelease) { + if (releases == null) { + releases = new LinkedHashMap<>(); + } + releases.put(platformRelease.getVersion(), platformRelease); } @Override public String toString() { return id + releases; } + }