Skip to content

Commit

Permalink
Merge pull request #17865 from phillip-kruger/platform-model-enhancement
Browse files Browse the repository at this point in the history
Make the platform model easier to navigate
  • Loading branch information
aloubyansky authored Jun 14, 2021
2 parents 4794b21 + 4055bac commit fc31727
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Platform> 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)) {
Expand Down Expand Up @@ -478,7 +483,7 @@ private void collectPlatforms(String quarkusCoreVersion,
if (platformCatalog == null) {
continue;
}
final List<Platform> platforms = platformCatalog.getPlatforms();
final Collection<Platform> platforms = platformCatalog.getPlatforms();
if (platforms.isEmpty()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,16 +9,17 @@ public interface Platform {

String getName();

List<PlatformStream> getStreams();
Collection<PlatformStream> getStreams();

Map<String, Object> getMetadata();

@JsonIgnore
PlatformStream getStream(String id);

default PlatformStream getRecommendedStream() {
final List<PlatformStream> streams = getStreams();
final Collection<PlatformStream> streams = getStreams();
if (streams.isEmpty()) {
throw new RuntimeException("Platform " + getPlatformKey() + " does not include any stream");
}
return streams.get(0);
return streams.iterator().next();
}
}
Original file line number Diff line number Diff line change
@@ -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<Platform> getPlatforms();
Collection<Platform> getPlatforms();

Map<String, Object> getMetadata();

@JsonIgnore
Platform getPlatform(String platformId);

default Platform getRecommendedPlatform() {
final List<Platform> platforms = getPlatforms();
return platforms.isEmpty() ? null : platforms.get(0);
final Collection<Platform> platforms = getPlatforms();
return platforms.isEmpty() ? null : platforms.iterator().next();
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,16 +9,17 @@ public interface PlatformStream {

String getName();

List<PlatformRelease> getReleases();
Collection<PlatformRelease> getReleases();

Map<String, Object> getMetadata();

@JsonIgnore
PlatformRelease getRelease(PlatformReleaseVersion version);

default PlatformRelease getRecommendedRelease() {
final List<PlatformRelease> releases = getReleases();
final Collection<PlatformRelease> releases = getReleases();
if (releases.isEmpty()) {
throw new RuntimeException("Stream " + getId() + " does not include any release");
}
return releases.get(0);
return releases.iterator().next();
}
}
Original file line number Diff line number Diff line change
@@ -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<PlatformStream> streams;
private Map<String, PlatformStream> streams;

@Override
public String getPlatformKey() {
Expand All @@ -34,16 +40,32 @@ public void setName(String name) {

@Override
@JsonDeserialize(contentAs = JsonPlatformStream.class)
public List<PlatformStream> getStreams() {
return streams == null ? Collections.emptyList() : streams;
public Collection<PlatformStream> 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<PlatformStream> 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;
}

}
Original file line number Diff line number Diff line change
@@ -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<Platform> platforms;
private Map<String, Platform> platforms;

@Override
@JsonDeserialize(contentAs = JsonPlatform.class)
public List<Platform> getPlatforms() {
return platforms == null ? Collections.emptyList() : platforms;
public Collection<Platform> 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<Platform> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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<PlatformRelease> releases;
private Map<PlatformReleaseVersion, PlatformRelease> releases;

@Override
public String getId() {
Expand All @@ -34,16 +41,32 @@ public void setName(String name) {

@Override
@JsonDeserialize(contentAs = JsonPlatformRelease.class)
public List<PlatformRelease> getReleases() {
return releases == null ? Collections.emptyList() : releases;
public Collection<PlatformRelease> 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<PlatformRelease> 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;
}

}

0 comments on commit fc31727

Please sign in to comment.