Skip to content

Commit

Permalink
Basic changes to integrate the new platform model based on the decomp…
Browse files Browse the repository at this point in the history
…osed 'universe' BOM
  • Loading branch information
aloubyansky committed May 16, 2021
1 parent 861ace7 commit 994b99f
Show file tree
Hide file tree
Showing 37 changed files with 1,551 additions and 53 deletions.
2 changes: 1 addition & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/Create.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static class TargetBuildTool {
boolean gradle = false;

@CommandLine.Option(names = {
"--grade-kotlin-dsl" }, order = 7, description = "Create a Gradle Kotlin DSL project.")
"--gradle-kotlin-dsl" }, order = 7, description = "Create a Gradle Kotlin DSL project.")
boolean gradleKotlinDsl = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ static QuarkusProject getQuarkusProject(BuildTool buildTool, Path projectRoot) {
}

private static QuarkusProject getNonMavenProject(Path projectRoot, BuildTool buildTool) {
return QuarkusProjectHelper.getProject(projectRoot, buildTool,
QuarkusCliVersion.version());
return QuarkusProjectHelper.getProject(projectRoot, buildTool, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ String getBuildGradlePath() {
return BUILD_GRADLE_PATH;
}

@Override
protected boolean importBom(ArtifactCoords coords) {
return importBomInModel(getModel(), coords);
}

@Override
protected boolean addDependency(ArtifactCoords coords, boolean managed) {
return addDependencyInModel(getModel(), coords, managed);
Expand All @@ -35,6 +40,12 @@ public BuildTool getBuildTool() {
return BuildTool.GRADLE;
}

static boolean importBomInModel(Model model, ArtifactCoords coords) {
return addDependencyInModel(model,
String.format(" implementation enforcedPlatform(%s)%n",
createDependencyCoordinatesString(coords, false, '\'')));
}

static boolean addDependencyInModel(Model model, ArtifactCoords coords, boolean managed) {
return addDependencyInModel(model,
String.format(" implementation %s%n", createDependencyCoordinatesString(coords, managed, '\'')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ String getBuildGradlePath() {
return BUILD_GRADLE_PATH;
}

@Override
protected boolean importBom(ArtifactCoords coords) {
return importBomInModel(getModel(), coords);
}

@Override
protected boolean addDependency(ArtifactCoords coords, boolean managed) {
return addDependencyInModel(getModel(), coords, managed);
Expand All @@ -35,6 +40,12 @@ public BuildTool getBuildTool() {
return BuildTool.GRADLE_KOTLIN_DSL;
}

static boolean importBomInModel(Model model, ArtifactCoords coords) {
return addDependencyInModel(model,
String.format(" implementation enforcedPlatform(%s)%n",
createDependencyCoordinatesString(coords, false, '\'')));
}

static boolean addDependencyInModel(Model model, ArtifactCoords coords, boolean managed) {
return addDependencyInModel(model,
String.format(" implementation(%s)%n", createDependencyCoordinatesString(coords, managed, '"')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
import org.gradle.tooling.provider.model.ParameterizedToolingModelBuilder;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.bootstrap.model.PlatformReleases;
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.resolver.model.ArtifactCoords;
import io.quarkus.bootstrap.resolver.model.Dependency;
import io.quarkus.bootstrap.resolver.model.ModelParameter;
Expand Down Expand Up @@ -132,14 +134,18 @@ private Map<String, String> resolvePlatformProperties(Project project,
final Configuration boms = project.getConfigurations()
.detachedConfiguration(deploymentDeps.toArray(new org.gradle.api.artifacts.Dependency[0]));
final Map<String, String> platformProps = new HashMap<>();
final Set<AppArtifactKey> descriptorKeys = new HashSet<>(4);
final Set<AppArtifactKey> propertyKeys = new HashSet<>(2);
final Set<AppArtifactCoords> descriptorCoords = new HashSet<>(4);
final Set<AppArtifactCoords> propertyCoords = new HashSet<>(2);
// platform BOMs by platform keys (groupId)
final Map<String, Collection<AppArtifactCoords>> importedPlatforms = new HashMap<>();
final PlatformReleases platformReleases = new PlatformReleases();
boms.getResolutionStrategy().eachDependency(d -> {
final String group = d.getTarget().getGroup();
final String name = d.getTarget().getName();
if (name.endsWith(BootstrapConstants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX)) {
descriptorKeys.add(new AppArtifactKey(group,
descriptorCoords.add(new AppArtifactCoords(group,
name.substring(0, name.length() - BootstrapConstants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX.length()),
null, "pom",
d.getTarget().getVersion()));
} else if (name.endsWith(BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX)) {
final DefaultDependencyArtifact dep = new DefaultDependencyArtifact();
Expand All @@ -151,6 +157,9 @@ private Map<String, String> resolvePlatformProperties(Project project,
group, name, d.getTarget().getVersion(), null);
gradleDep.addArtifact(dep);

final String bomArtifactId = name.substring(0,
name.length() - BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX.length());

for (ResolvedArtifact a : project.getConfigurations().detachedConfiguration(gradleDep)
.getResolvedConfiguration().getResolvedArtifacts()) {
if (a.getName().equals(name)) {
Expand All @@ -163,26 +172,31 @@ private Map<String, String> resolvePlatformProperties(Project project,
for (Map.Entry<?, ?> prop : props.entrySet()) {
final String propName = String.valueOf(prop.getKey());
if (propName.startsWith(BootstrapConstants.PLATFORM_PROPERTY_PREFIX)) {
platformProps.put(propName, String.valueOf(prop.getValue()));
if (PlatformReleases.isPlatformReleaseInfo(propName)) {
platformReleases.addPlatformRelease(propName, String.valueOf(prop.getValue()));
} else {
platformProps.put(propName, String.valueOf(prop.getValue()));
}
}
}
break;
}
}
propertyKeys.add(new AppArtifactKey(group,
name.substring(0, name.length() - BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX.length()),
d.getTarget().getVersion()));
final AppArtifactCoords bomCoords = new AppArtifactCoords(group, bomArtifactId, null, "pom",
d.getTarget().getVersion());
importedPlatforms.computeIfAbsent(group, g -> new ArrayList<>()).add(bomCoords);
propertyCoords.add(bomCoords);
}

});
boms.getResolvedConfiguration();
if (!descriptorKeys.containsAll(propertyKeys)) {
if (!descriptorCoords.containsAll(propertyCoords)) {
final StringBuilder buf = new StringBuilder();
buf.append(
"The Quarkus platform properties applied to the project are missing the corresponding Quarkus platform BOM imports:");
final int l = buf.length();
for (AppArtifactKey key : propertyKeys) {
if (!descriptorKeys.contains(key)) {
for (AppArtifactCoords key : propertyCoords) {
if (!descriptorCoords.contains(key)) {
if (l - buf.length() < 0) {
buf.append(',');
}
Expand All @@ -191,6 +205,11 @@ private Map<String, String> resolvePlatformProperties(Project project,
}
throw new GradleException(buf.toString());
}
try {
platformReleases.assertAligned(importedPlatforms);
} catch (AppModelResolverException e) {
throw new GradleException("Failed to create the Quarkus Application Model: " + e.getMessage(), e);
}
return platformProps;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.quarkus.bootstrap.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class PlatformInfo {

private final String key;
private final List<PlatformStreamInfo> streams = new ArrayList<>(1); // most of the time there will be only one

public PlatformInfo(String key) {
this.key = key;
}

public String getPlatformKey() {
return key;
}

public boolean isAligned(Collection<AppArtifactCoords> importedBoms) {
if (streams.isEmpty()) {
return true;
}
if (streams.size() > 1) {
return false;
}
return streams.get(0).isAligned(importedBoms);
}

public List<List<String>> getPossibleAlignments(Collection<AppArtifactCoords> importedPlatformBoms) {
if (streams.size() > 1) {
final StringBuilder buf = new StringBuilder();
buf.append("Imported BOMs ");
final Iterator<AppArtifactCoords> it = importedPlatformBoms.iterator();
if (it.hasNext()) {
buf.append(it.next());
while (it.hasNext()) {
buf.append(", ").append(it.next());
}
}
buf.append(" belong to different platform streams ").append(streams.get(0));
for (int i = 1; i < streams.size(); ++i) {
buf.append(", ").append(streams.get(i));
}
throw new RuntimeException(buf.append(" while only one stream per platform is allowed.").toString());
}
return streams.get(0).getPossibleAlignemnts(importedPlatformBoms);
}

PlatformStreamInfo getOrCreateStream(String stream) {
PlatformStreamInfo s = getStream(stream);
if (s == null) {
s = new PlatformStreamInfo(stream);
streams.add(s);
}
return s;
}

Collection<PlatformStreamInfo> getStreams() {
return streams;
}

PlatformStreamInfo getStream(String stream) {
for (PlatformStreamInfo s : streams) {
if (s.getId().equals(stream)) {
return s;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package io.quarkus.bootstrap.model;

import java.util.ArrayList;
import java.util.List;

/**
* Platform release info that is encoded into a property in a platform properties artifact
* following the format {@code platform.release-info@<platform-key>$<stream>#<version>=<bom-coords>(,<bom-coords>)}
*/
public class PlatformReleaseInfo {

private final String platformKey;
private final String stream;
private final String version;
private final List<AppArtifactCoords> boms;

PlatformReleaseInfo(String platformKey, String stream, String version, String boms) {
this.platformKey = platformKey;
this.stream = stream;
this.version = version;
final String[] bomCoords = boms.split(",");
this.boms = new ArrayList<>(bomCoords.length);
for (String s : bomCoords) {
this.boms.add(AppArtifactCoords.fromString(s));
}
}

/**
* The platform key. Could be the {@code groupId} of the stack, e.g. {@code io.quarkus.platform}
*
* @return platform key
*/
public String getPlatformKey() {
return platformKey;
}

/**
* Platform stream. Could be the {@code major.minor} part of the platform release version.
*
* @return platform stream
*/
public String getStream() {
return stream;
}

/**
* The version of the platform in a stream. Ideally, the micro version to make the comparisons easier.
*
* @return version in the stream
*/
public String getVersion() {
return version;
}

/**
* Member BOM coordinates.
*
* @return member BOM coordinates
*/
public List<AppArtifactCoords> getBoms() {
return boms;
}

String getPropertyName() {
final StringBuilder buf = new StringBuilder();
buf.append(PlatformReleases.PROPERTY_PREFIX).append(platformKey).append(PlatformReleases.PLATFORM_KEY_STREAM_SEPARATOR)
.append(stream)
.append(PlatformReleases.STREAM_VERSION_SEPARATOR).append(version);
return buf.toString();
}

String getPropertyValue() {
final StringBuilder buf = new StringBuilder();
final List<AppArtifactCoords> boms = getBoms();
if (!boms.isEmpty()) {
buf.append(boms.get(0).toString());
for (int i = 1; i < boms.size(); ++i) {
buf.append(',').append(boms.get(i));
}
}
return buf.toString();
}

public String toString() {
return getPropertyName() + '=' + getPropertyValue();
}
}
Loading

0 comments on commit 994b99f

Please sign in to comment.