Skip to content

Commit

Permalink
Support for platform streams in the registry client
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed May 25, 2021
1 parent 950286b commit 8324e61
Show file tree
Hide file tree
Showing 23 changed files with 480 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<ArtifactCoords> 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);
Expand Down
93 changes: 0 additions & 93 deletions devtools/maven/src/main/java/io/quarkus/maven/ListUpdatesMojo.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -139,47 +142,13 @@ protected List<ArtifactCoords> getImportedPlatforms() throws MojoExecutionExcept
if (bomGroupId == null) {
bomGroupId = ToolsConstants.DEFAULT_PLATFORM_BOM_GROUP_ID;
}
final ExtensionCatalogResolver catalogResolver = getExtensionCatalogResolver();
ArtifactCoords platformBom = null;
List<ArtifactCoords> 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();
Expand Down Expand Up @@ -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<ArtifactCoords> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 8324e61

Please sign in to comment.