Skip to content

Commit

Permalink
Include relevant upstream catalogs even if their versions aren't reco…
Browse files Browse the repository at this point in the history
…mmended for new projects

Deprecated io.quarkus.maven.StreamCoords in favor of io.quarkus.registry.catalog.PlatformStreamCoords
  • Loading branch information
aloubyansky committed Sep 3, 2021
1 parent a127414 commit 9df8576
Show file tree
Hide file tree
Showing 11 changed files with 539 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import io.quarkus.cli.Version;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.maven.StreamCoords;
import io.quarkus.platform.tools.ToolsConstants;
import io.quarkus.registry.catalog.PlatformStreamCoords;
import picocli.CommandLine;
import picocli.CommandLine.Model.CommandSpec;

public class TargetQuarkusVersionGroup {
final static String FULL_EXAMPLE = ToolsConstants.DEFAULT_PLATFORM_BOM_GROUP_ID + ":"
+ ToolsConstants.DEFAULT_PLATFORM_BOM_ARTIFACT_ID + ":2.2.0.Final";
StreamCoords streamCoords = null;
PlatformStreamCoords streamCoords = null;
String validStream = null;

ArtifactCoords platformBom = null;
Expand All @@ -25,7 +25,7 @@ void setStream(String stream) {
stream = stream.trim();
if (!stream.isEmpty()) {
try {
streamCoords = StreamCoords.fromString(stream);
streamCoords = PlatformStreamCoords.fromString(stream);
validStream = stream;
} catch (IllegalArgumentException iex) {
throw new CommandLine.ParameterException(spec.commandLine(),
Expand Down Expand Up @@ -94,7 +94,7 @@ public boolean isStreamSpecified() {
return streamCoords != null;
}

public StreamCoords getStream() {
public PlatformStreamCoords getStream() {
return streamCoords;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ private ExtensionCatalog deserializeExtensionCatalog(Path p) throws RegistryReso
public PlatformCatalog resolvePlatforms(String quarkusVersion) throws RegistryResolutionException {
final Path json = TestRegistryClientBuilder.getRegistryPlatformsCatalogPath(registryDir, quarkusVersion);
log.debug("%s resolvePlatforms %s", config.getId(), json);
if (!Files.exists(json)) {
return null;
}
try {
return JsonCatalogMapperHelper.deserialize(json, JsonPlatformCatalog.class);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static class TestRegistryBuilder {
private JsonRegistryQuarkusVersionsConfig quarkusVersions;
private boolean external;
private PlatformCatalog platformCatalog;
private JsonPlatformCatalog archivedPlatformCatalog;

private List<TestPlatformCatalogMemberBuilder> memberCatalogs;
private List<TestNonPlatformCatalogBuilder> nonPlatformCatalogs;
Expand Down Expand Up @@ -221,37 +222,72 @@ private void configure(Path registryDir) {
platformConfig
.setArtifact(new ArtifactCoords(registryGroupId, Constants.DEFAULT_REGISTRY_PLATFORMS_CATALOG_ARTIFACT_ID,
null, "json", Constants.DEFAULT_REGISTRY_ARTIFACT_VERSION));
if (platformCatalog == null) {
if (platformCatalog == null && archivedPlatformCatalog == null) {
platformConfig.setDisabled(true);
} else {
final Path platformsDir = getRegistryPlatformsDir(registryDir);
persistPlatformCatalog(platformCatalog, platformsDir);
final Map<String, JsonPlatformCatalog> platformsByQuarkusVersion = new HashMap<>();
for (Platform p : platformCatalog.getPlatforms()) {
for (PlatformStream s : p.getStreams()) {
for (PlatformRelease r : s.getReleases()) {
if (r.getQuarkusCoreVersion() == null) {
throw new IllegalStateException("Quarkus version has not be configured for platform release "
+ p.getPlatformKey() + ":" + s.getId() + ":" + r.getVersion());
}
final JsonPlatformCatalog c = platformsByQuarkusVersion.computeIfAbsent(r.getQuarkusCoreVersion(),
v -> new JsonPlatformCatalog());
JsonPlatform platform = (JsonPlatform) c.getPlatform(p.getPlatformKey());
if (platform == null) {
platform = new JsonPlatform();
platform.setPlatformKey(p.getPlatformKey());
c.addPlatform(platform);
if (platformCatalog != null) {
persistPlatformCatalog(platformCatalog, platformsDir);
for (Platform p : platformCatalog.getPlatforms()) {
for (PlatformStream s : p.getStreams()) {
for (PlatformRelease r : s.getReleases()) {
if (r.getQuarkusCoreVersion() == null) {
throw new IllegalStateException(
"Quarkus version has not be configured for platform release "
+ p.getPlatformKey() + ":" + s.getId() + ":" + r.getVersion());
}
final JsonPlatformCatalog c = platformsByQuarkusVersion.computeIfAbsent(
r.getQuarkusCoreVersion(),
v -> new JsonPlatformCatalog());
JsonPlatform platform = (JsonPlatform) c.getPlatform(p.getPlatformKey());
if (platform == null) {
platform = new JsonPlatform();
platform.setPlatformKey(p.getPlatformKey());
c.addPlatform(platform);
}
JsonPlatformStream stream = (JsonPlatformStream) platform.getStream(s.getId());
if (stream == null) {
stream = new JsonPlatformStream();
stream.setId(s.getId());
platform.addStream(stream);
}
stream.addRelease(r);
}
JsonPlatformStream stream = (JsonPlatformStream) platform.getStream(s.getId());
if (stream == null) {
stream = new JsonPlatformStream();
stream.setId(s.getId());
platform.addStream(stream);
}
}
}

if (archivedPlatformCatalog != null) {
for (Platform p : archivedPlatformCatalog.getPlatforms()) {
for (PlatformStream s : p.getStreams()) {
for (PlatformRelease r : s.getReleases()) {
if (r.getQuarkusCoreVersion() == null) {
throw new IllegalStateException(
"Quarkus version has not be configured for platform release "
+ p.getPlatformKey() + ":" + s.getId() + ":" + r.getVersion());
}
final JsonPlatformCatalog c = platformsByQuarkusVersion.computeIfAbsent(
r.getQuarkusCoreVersion(),
v -> new JsonPlatformCatalog());
JsonPlatform platform = (JsonPlatform) c.getPlatform(p.getPlatformKey());
if (platform == null) {
platform = new JsonPlatform();
platform.setPlatformKey(p.getPlatformKey());
c.addPlatform(platform);
}
JsonPlatformStream stream = (JsonPlatformStream) platform.getStream(s.getId());
if (stream == null) {
stream = new JsonPlatformStream();
stream.setId(s.getId());
platform.addStream(stream);
}
stream.addRelease(r);
}
stream.addRelease(r);
}
}
}

for (Map.Entry<String, JsonPlatformCatalog> entry : platformsByQuarkusVersion.entrySet()) {
persistPlatformCatalog(entry.getValue(), platformsDir.resolve(entry.getKey()));
}
Expand Down Expand Up @@ -339,6 +375,33 @@ public TestPlatformCatalogReleaseBuilder newRelease(String version) {
return new TestPlatformCatalogReleaseBuilder(this, release);
}

public TestPlatformCatalogReleaseBuilder newArchivedRelease(String version) {
final JsonPlatformRelease release = new JsonPlatformRelease();
release.setVersion(JsonPlatformReleaseVersion.fromString(version));

if (platform.registry.archivedPlatformCatalog == null) {
platform.registry.archivedPlatformCatalog = new JsonPlatformCatalog();
}

JsonPlatform archivedPlatform = (JsonPlatform) platform.registry.archivedPlatformCatalog
.getPlatform(platform.platform.getPlatformKey());
if (archivedPlatform == null) {
archivedPlatform = new JsonPlatform();
archivedPlatform.setPlatformKey(platform.platform.getPlatformKey());
platform.registry.archivedPlatformCatalog.addPlatform(archivedPlatform);
}

JsonPlatformStream archivedStream = (JsonPlatformStream) archivedPlatform.getStream(stream.getId());
if (archivedStream == null) {
archivedStream = new JsonPlatformStream();
archivedStream.setId(stream.getId());
archivedPlatform.addStream(archivedStream);
}

archivedStream.addRelease(release);
return new TestPlatformCatalogReleaseBuilder(this, release);
}

public TestPlatformCatalogPlatformBuilder platform() {
return platform;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.testing.registry.client.TestRegistryClientBuilder;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.registry.RegistryResolutionException;
import io.quarkus.registry.catalog.PlatformStreamCoords;
import io.quarkus.registry.config.RegistriesConfigLocator;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -89,7 +91,7 @@ protected QuarkusCommandOutcome addExtensions(Path projectDir, List<String> exte

protected QuarkusCommandOutcome createProject(Path projectDir, List<String> extensions)
throws Exception {
return createProject(projectDir, null, extensions);
return createProject(projectDir, (String) null, extensions);
}

protected QuarkusCommandOutcome createProject(Path projectDir, String quarkusVersion, List<String> extensions)
Expand All @@ -103,6 +105,17 @@ protected QuarkusCommandOutcome createProject(Path projectDir, String quarkusVer
.execute();
}

protected QuarkusCommandOutcome createProject(Path projectDir, PlatformStreamCoords stream, List<String> extensions)
throws Exception {
return new CreateProject(
getQuarkusProject(projectDir, stream))
.groupId("org.acme")
.artifactId("acme-app")
.version("0.0.1-SNAPSHOT")
.extensions(new HashSet<>(extensions))
.execute();
}

protected List<ArtifactCoords> toPlatformExtensionCoords(String... artifactIds) {
return toPlatformExtensionCoords(Arrays.asList(artifactIds));
}
Expand Down Expand Up @@ -171,6 +184,12 @@ protected QuarkusProject getQuarkusProject(Path projectDir, String quarkusVersio
return QuarkusProjectHelper.getProject(projectDir, BuildTool.MAVEN, quarkusVersion);
}

protected QuarkusProject getQuarkusProject(Path projectDir, PlatformStreamCoords stream)
throws RegistryResolutionException {
return QuarkusProjectHelper.getProject(projectDir,
QuarkusProjectHelper.getCatalogResolver().resolveExtensionCatalog(stream), BuildTool.MAVEN);
}

static Path newProjectDir(String name) {
Path projectDir = getProjectDir(name);
if (Files.exists(projectDir)) {
Expand Down
Loading

0 comments on commit 9df8576

Please sign in to comment.