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

Support resolving platform catalog for any known stream #26631

Merged
merged 1 commit into from Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,7 +39,7 @@ protected static String[] split(String str, String[] parts) {
protected GACTV(String[] parts) {
groupId = parts[0];
artifactId = parts[1];
classifier = parts[2];
classifier = parts[2] == null ? DEFAULT_CLASSIFIER : parts[2];
type = parts[3] == null ? TYPE_JAR : parts[3];
version = parts[4];
}
Expand All @@ -54,17 +54,17 @@ public GACTV(ArtifactKey key, String version) {
}

public GACTV(String groupId, String artifactId, String version) {
this(groupId, artifactId, "", TYPE_JAR, version);
this(groupId, artifactId, DEFAULT_CLASSIFIER, TYPE_JAR, version);
}

public GACTV(String groupId, String artifactId, String type, String version) {
this(groupId, artifactId, "", type, version);
this(groupId, artifactId, DEFAULT_CLASSIFIER, type, version);
}

public GACTV(String groupId, String artifactId, String classifier, String type, String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.classifier = classifier == null ? "" : classifier;
this.classifier = classifier == null ? DEFAULT_CLASSIFIER : classifier;
this.type = type == null ? TYPE_JAR : type;
this.version = version;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ protected static String[] split(String str, String[] parts) {
protected ArtifactCoords(String[] parts) {
groupId = parts[0];
artifactId = parts[1];
classifier = parts[2];
classifier = parts[2] == null ? DEFAULT_CLASSIFIER : parts[2];
type = parts[3] == null ? TYPE_JAR : parts[3];
version = parts[4];
}
Expand All @@ -49,17 +49,17 @@ public ArtifactCoords(ArtifactKey key, String version) {
}

public ArtifactCoords(String groupId, String artifactId, String version) {
this(groupId, artifactId, "", TYPE_JAR, version);
this(groupId, artifactId, DEFAULT_CLASSIFIER, TYPE_JAR, version);
}

public ArtifactCoords(String groupId, String artifactId, String type, String version) {
this(groupId, artifactId, "", type, version);
this(groupId, artifactId, DEFAULT_CLASSIFIER, type, version);
}

public ArtifactCoords(String groupId, String artifactId, String classifier, String type, String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.classifier = classifier == null ? "" : classifier;
this.classifier = classifier == null ? DEFAULT_CLASSIFIER : classifier;
this.type = type == null ? TYPE_JAR : type;
this.version = version;
}
Expand Down
Expand Up @@ -24,7 +24,7 @@ public ArtifactKey(String[] parts) {
this.classifier = parts[2];
}
if (parts.length <= 3 || parts[3] == null) {
this.type = "jar";
this.type = ArtifactCoords.TYPE_JAR;
} else {
this.type = parts[3];
}
Expand Down
Expand Up @@ -376,6 +376,7 @@ private void configure(Path registryDir) {
} else {
final Path platformsDir = getRegistryPlatformsDir(registryDir);
final Map<String, PlatformCatalog.Mutable> platformsByQuarkusVersion = new HashMap<>();
final PlatformCatalog.Mutable allPlatforms = PlatformCatalog.builder();
if (platformCatalog != null) {
persistPlatformCatalog(platformCatalog.build(), platformsDir);
for (Platform p : platformCatalog.getPlatforms()) {
Expand All @@ -389,19 +390,8 @@ private void configure(Path registryDir) {
final PlatformCatalog.Mutable c = platformsByQuarkusVersion.computeIfAbsent(
r.getQuarkusCoreVersion(),
v -> PlatformCatalog.builder());
Platform.Mutable platform = (Platform.Mutable) c.getPlatform(p.getPlatformKey());
if (platform == null) {
platform = Platform.builder()
.setPlatformKey(p.getPlatformKey());
c.addPlatform(platform);
}
PlatformStream.Mutable stream = (PlatformStream.Mutable) platform.getStream(s.getId());
if (stream == null) {
stream = PlatformStream.builder()
.setId(s.getId());
platform.addStream(stream);
}
stream.addRelease(r);
addPlatformRelease(p, s, r, c);
addPlatformRelease(p, s, r, allPlatforms);
}
}
}
Expand All @@ -419,19 +409,8 @@ private void configure(Path registryDir) {
final PlatformCatalog.Mutable c = platformsByQuarkusVersion.computeIfAbsent(
r.getQuarkusCoreVersion(),
v -> PlatformCatalog.builder());
Platform.Mutable platform = (Platform.Mutable) c.getPlatform(p.getPlatformKey());
if (platform == null) {
platform = Platform.builder();
platform.setPlatformKey(p.getPlatformKey());
c.addPlatform(platform);
}
PlatformStream.Mutable stream = (PlatformStream.Mutable) platform.getStream(s.getId());
if (stream == null) {
stream = PlatformStream.builder();
stream.setId(s.getId());
platform.addStream(stream);
}
stream.addRelease(r);
addPlatformRelease(p, s, r, c);
addPlatformRelease(p, s, r, allPlatforms);
}
}
}
Expand All @@ -441,6 +420,8 @@ private void configure(Path registryDir) {
persistPlatformCatalog(entry.getValue().build(), platformsDir.resolve(entry.getKey()));
}

persistPlatformCatalog(allPlatforms.build(), platformsDir.resolve(Constants.QUARKUS_VERSION_CLASSIFIER_ALL));

if (memberCatalogs != null && !memberCatalogs.isEmpty()) {
platformConfig.setExtensionCatalogsIncluded(true);
}
Expand Down Expand Up @@ -480,6 +461,23 @@ private void configure(Path registryDir) {
}
}

protected void addPlatformRelease(Platform platform, PlatformStream stream, PlatformRelease release,
final PlatformCatalog.Mutable catalog) {
Platform.Mutable mp = (Platform.Mutable) catalog.getPlatform(platform.getPlatformKey());
if (mp == null) {
mp = Platform.builder()
.setPlatformKey(platform.getPlatformKey());
catalog.addPlatform(mp);
}
PlatformStream.Mutable ms = (PlatformStream.Mutable) mp.getStream(stream.getId());
if (ms == null) {
ms = PlatformStream.builder()
.setId(stream.getId());
mp.addStream(ms);
}
ms.addRelease(release);
}

private ArtifactCoords getRegistryNonPlatformCatalogArtifact() {
return new ArtifactCoords(registryGroupId, Constants.DEFAULT_REGISTRY_NON_PLATFORM_EXTENSIONS_CATALOG_ARTIFACT_ID,
null, "json", Constants.DEFAULT_REGISTRY_ARTIFACT_VERSION);
Expand All @@ -504,6 +502,28 @@ public TestPlatformCatalogStreamBuilder newStream(String id) {
return new TestPlatformCatalogStreamBuilder(this, stream);
}

public TestPlatformCatalogStreamBuilder newArchivedStream(String id) {

if (registry.archivedPlatformCatalog == null) {
registry.archivedPlatformCatalog = PlatformCatalog.builder();
}

Platform.Mutable archivedPlatform = (Platform.Mutable) registry.archivedPlatformCatalog
.getPlatform(platform.getPlatformKey());
if (archivedPlatform == null) {
archivedPlatform = Platform.builder()
.setPlatformKey(platform.getPlatformKey());
registry.archivedPlatformCatalog.addPlatform(archivedPlatform);
}

PlatformStream.Mutable archivedStream = (PlatformStream.Mutable) archivedPlatform.getStream(id);
if (archivedStream == null) {
archivedStream = PlatformStream.builder().setId(id);
archivedPlatform.addStream(archivedStream);
}
return new TestPlatformCatalogStreamBuilder(this, archivedStream);
}

public TestRegistryBuilder registry() {
return registry;
}
Expand Down
@@ -0,0 +1,61 @@
package io.quarkus.devtools.project.create;

import io.quarkus.devtools.testing.registry.client.TestRegistryClientBuilder;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.registry.catalog.PlatformStreamCoords;
import java.nio.file.Path;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class ArchivedStreamTest extends MultiplePlatformBomsTestBase {

private static final String PLATFORM_KEY = "io.test.platform";

@BeforeAll
public static void setup() throws Exception {
TestRegistryClientBuilder.newInstance()
//.debug()
.baseDir(configDir())
// registry
.newRegistry("registry.test.io")
// platform key
.newPlatform(PLATFORM_KEY)
.newStream("1.0")
// 1.0.4 release
.newRelease("1.1.1")
.quarkusVersion("1.1.1")
// default bom including quarkus-core + essential metadata
.addCoreMember().release()
// foo platform member
.newMember("acme-a-bom").addExtension("ext-a").release()
.stream().platform()
.newArchivedStream("0.5")
.newArchivedRelease("0.5.1")
.quarkusVersion("0.5.1")
// default bom including quarkus-core + essential metadata
.addCoreMember().release()
// foo platform member
.newMember("acme-a-bom").addExtension("ext-a").release()
.registry()
.clientBuilder()
.build();

enableRegistryClient();
}

protected String getMainPlatformKey() {
return PLATFORM_KEY;
}

@Test
public void createUsingStream2_0() throws Exception {
final Path projectDir = newProjectDir("created-using-archive-stream-0.5");
createProject(projectDir, new PlatformStreamCoords(null, "0.5"), List.of("ext-a"));

assertModel(projectDir,
List.of(mainPlatformBom(), platformMemberBomCoords("acme-a-bom")),
List.of(new ArtifactCoords("io.test.platform", "ext-a", null)),
"0.5.1");
}
}
Expand Up @@ -15,6 +15,8 @@ public interface Constants {
String PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX = "-quarkus-platform-descriptor";
String PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX = "-quarkus-platform-properties";

String QUARKUS_VERSION_CLASSIFIER_ALL = "all";

String JSON = "json";

String LAST_UPDATED = "last-updated";
Expand Down