Skip to content

Commit

Permalink
Merge pull request quarkusio#17252 from aloubyansky/new-platform-model
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky authored May 19, 2021
2 parents cb884e2 + ab6699e commit e1c2ba5
Show file tree
Hide file tree
Showing 69 changed files with 1,669 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@ public class BootstrapConfig {
@ConfigItem(defaultValue = "false")
boolean effectiveModelBuilder;

/**
* Whether to throw an error, warn or silently ignore misaligned platform BOM imports
*/
@ConfigItem(defaultValue = "error")
public MisalignedPlatformImports misalignedPlatformImports;

public enum MisalignedPlatformImports {
ERROR,
WARN,
IGNORE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.quarkus.builder.BuildResult;
import io.quarkus.builder.item.BuildItem;
import io.quarkus.deployment.builditem.AdditionalApplicationArchiveBuildItem;
import io.quarkus.deployment.builditem.AppModelProviderBuildItem;
import io.quarkus.deployment.builditem.ArchiveRootBuildItem;
import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
import io.quarkus.deployment.builditem.GeneratedResourceBuildItem;
Expand All @@ -33,7 +34,6 @@
import io.quarkus.deployment.builditem.RawCommandLineArgumentsBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.deployment.pkg.builditem.DeploymentResultBuildItem;
import io.quarkus.dev.spi.DevModeType;
import io.quarkus.runtime.LaunchMode;
Expand Down Expand Up @@ -117,7 +117,7 @@ public BuildResult run() throws Exception {
.addInitial(LiveReloadBuildItem.class)
.addInitial(AdditionalApplicationArchiveBuildItem.class)
.addInitial(BuildSystemTargetBuildItem.class)
.addInitial(CurateOutcomeBuildItem.class);
.addInitial(AppModelProviderBuildItem.class);
for (Class<? extends BuildItem> i : finalResults) {
chainBuilder.addFinal(i);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public BuildResult run() throws Exception {
devModeType == null ? Optional.empty() : Optional.of(devModeType), auxiliaryApplication))
.produce(new BuildSystemTargetBuildItem(targetDir, baseName, rebuild,
buildSystemProperties == null ? new Properties() : buildSystemProperties))
.produce(new CurateOutcomeBuildItem(effectiveModel));
.produce(new AppModelProviderBuildItem(effectiveModel));
for (PathsCollection i : additionalApplicationArchives) {
execBuilder.produce(new AdditionalApplicationArchiveBuildItem(i));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.quarkus.deployment.builditem;

import org.jboss.logging.Logger;

import io.quarkus.bootstrap.model.AppModel;
import io.quarkus.bootstrap.model.PlatformImports;
import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.deployment.BootstrapConfig;

public final class AppModelProviderBuildItem extends SimpleBuildItem {

private static final Logger log = Logger.getLogger(AppModelProviderBuildItem.class);

private final AppModel appModel;

public AppModelProviderBuildItem(AppModel appModel) {
this.appModel = appModel;
}

public AppModel validateAndGet(BootstrapConfig config) {
final PlatformImports platforms = appModel.getPlatforms();
if (platforms != null && !BootstrapConfig.MisalignedPlatformImports.IGNORE.equals(config.misalignedPlatformImports)
&& !platforms.isAligned()) {
switch (config.misalignedPlatformImports) {
case ERROR:
throw new RuntimeException(platforms.getMisalignmentReport());
case WARN:
log.warn(platforms.getMisalignmentReport());
break;
default:
throw new RuntimeException("Unrecognized option for quarkus.bootstrap.misaligned-platform-imports: "
+ config.misalignedPlatformImports);
}
}
return appModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import io.quarkus.bootstrap.BootstrapGradleException;
import io.quarkus.bootstrap.app.CuratedApplication;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.gradle.QuarkusModel;
import io.quarkus.bootstrap.model.gradle.WorkspaceModule;
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalWorkspace;
import io.quarkus.bootstrap.resolver.model.QuarkusModel;
import io.quarkus.bootstrap.resolver.model.WorkspaceModule;
import io.quarkus.bootstrap.util.QuarkusModelHelper;
import io.quarkus.bootstrap.utils.BuildToolHelper;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.deployment.steps;

import io.quarkus.deployment.BootstrapConfig;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.AppModelProviderBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;

public class CurateOutcomeBuildStep {

BootstrapConfig config;

@BuildStep
CurateOutcomeBuildItem curateOutcome(AppModelProviderBuildItem appModelProvider) {
return new CurateOutcomeBuildItem(appModelProvider.validateAndGet(config));
}
}
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);
}
}
6 changes: 0 additions & 6 deletions devtools/gradle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-core</artifactId>
<exclusions>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-resolver</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
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;
}

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 @@ -17,9 +17,9 @@
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.AppDependency;
import io.quarkus.bootstrap.model.AppModel;
import io.quarkus.bootstrap.model.gradle.QuarkusModel;
import io.quarkus.bootstrap.resolver.AppModelResolver;
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.resolver.model.QuarkusModel;
import io.quarkus.bootstrap.util.QuarkusModelHelper;

public class AppModelGradleResolver implements AppModelResolver {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package io.quarkus.gradle.builder;

import static io.quarkus.bootstrap.resolver.model.impl.ArtifactCoordsImpl.TYPE_JAR;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -46,19 +41,21 @@
import org.gradle.tooling.provider.model.ParameterizedToolingModelBuilder;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.resolver.model.ArtifactCoords;
import io.quarkus.bootstrap.resolver.model.Dependency;
import io.quarkus.bootstrap.resolver.model.ModelParameter;
import io.quarkus.bootstrap.resolver.model.QuarkusModel;
import io.quarkus.bootstrap.resolver.model.WorkspaceModule;
import io.quarkus.bootstrap.resolver.model.impl.ArtifactCoordsImpl;
import io.quarkus.bootstrap.resolver.model.impl.DependencyImpl;
import io.quarkus.bootstrap.resolver.model.impl.ModelParameterImpl;
import io.quarkus.bootstrap.resolver.model.impl.QuarkusModelImpl;
import io.quarkus.bootstrap.resolver.model.impl.SourceSetImpl;
import io.quarkus.bootstrap.resolver.model.impl.WorkspaceImpl;
import io.quarkus.bootstrap.resolver.model.impl.WorkspaceModuleImpl;
import io.quarkus.bootstrap.model.PlatformImports;
import io.quarkus.bootstrap.model.PlatformImportsImpl;
import io.quarkus.bootstrap.model.gradle.ArtifactCoords;
import io.quarkus.bootstrap.model.gradle.Dependency;
import io.quarkus.bootstrap.model.gradle.ModelParameter;
import io.quarkus.bootstrap.model.gradle.QuarkusModel;
import io.quarkus.bootstrap.model.gradle.WorkspaceModule;
import io.quarkus.bootstrap.model.gradle.impl.ArtifactCoordsImpl;
import io.quarkus.bootstrap.model.gradle.impl.DependencyImpl;
import io.quarkus.bootstrap.model.gradle.impl.ModelParameterImpl;
import io.quarkus.bootstrap.model.gradle.impl.QuarkusModelImpl;
import io.quarkus.bootstrap.model.gradle.impl.SourceSetImpl;
import io.quarkus.bootstrap.model.gradle.impl.WorkspaceImpl;
import io.quarkus.bootstrap.model.gradle.impl.WorkspaceModuleImpl;
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.util.QuarkusModelHelper;
import io.quarkus.gradle.QuarkusPlugin;
import io.quarkus.gradle.tasks.QuarkusGradleUtils;
Expand Down Expand Up @@ -103,7 +100,7 @@ public Object buildAll(String modelName, ModelParameter parameter, Project proje

final List<org.gradle.api.artifacts.Dependency> deploymentDeps = getEnforcedPlatforms(project);

final Map<String, String> platformProperties = resolvePlatformProperties(project, deploymentDeps);
final PlatformImports platformImports = resolvePlatformImports(project, deploymentDeps);

final Map<ArtifactCoords, Dependency> appDependencies = new LinkedHashMap<>();
final Set<ArtifactCoords> visitedDeps = new HashSet<>();
Expand All @@ -124,23 +121,20 @@ public Object buildAll(String modelName, ModelParameter parameter, Project proje
extensionDependencies,
deploymentDeps.stream().map(QuarkusModelBuilder::toEnforcedPlatformDependency)
.filter(Objects::nonNull).collect(Collectors.toList()),
platformProperties);
platformImports);
}

private Map<String, String> resolvePlatformProperties(Project project,
private PlatformImports resolvePlatformImports(Project project,
List<org.gradle.api.artifacts.Dependency> deploymentDeps) {
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 PlatformImportsImpl platformImports = new PlatformImportsImpl();
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,
name.substring(0, name.length() - BootstrapConstants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX.length()),
d.getTarget().getVersion()));
platformImports.addPlatformDescriptor(group, name, d.getTarget().getVersion(), "json",
d.getTarget().getVersion());
} else if (name.endsWith(BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX)) {
final DefaultDependencyArtifact dep = new DefaultDependencyArtifact();
dep.setExtension("properties");
Expand All @@ -154,44 +148,20 @@ private Map<String, String> resolvePlatformProperties(Project project,
for (ResolvedArtifact a : project.getConfigurations().detachedConfiguration(gradleDep)
.getResolvedConfiguration().getResolvedArtifacts()) {
if (a.getName().equals(name)) {
final Properties props = new Properties();
try (InputStream is = new FileInputStream(a.getFile())) {
props.load(is);
} catch (IOException e) {
throw new GradleException("Failed to read properties from " + a.getFile(), e);
}
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()));
}
try {
platformImports.addPlatformProperties(group, name, null, "properties", d.getTarget().getVersion(),
a.getFile().toPath());
} catch (AppModelResolverException e) {
throw new GradleException("Failed to import platform properties " + a.getFile(), e);
}
break;
}
}
propertyKeys.add(new AppArtifactKey(group,
name.substring(0, name.length() - BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX.length()),
d.getTarget().getVersion()));
}

});
boms.getResolvedConfiguration();
if (!descriptorKeys.containsAll(propertyKeys)) {
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)) {
if (l - buf.length() < 0) {
buf.append(',');
}
buf.append(' ').append(key);
}
}
throw new GradleException(buf.toString());
}
return platformProps;
return platformImports;
}

public Set<WorkspaceModule> getWorkspace(Project project, LaunchMode mode, ArtifactCoords mainModuleCoord) {
Expand Down Expand Up @@ -484,7 +454,7 @@ private SourceSetImpl convert(SourceSet sourceSet) {
return new SourceSetImpl(existingSrcDirs);
}

private io.quarkus.bootstrap.resolver.model.SourceSet getSourceSourceSet(SourceSet sourceSet) {
private io.quarkus.bootstrap.model.gradle.SourceSet getSourceSourceSet(SourceSet sourceSet) {
return new SourceSetImpl(sourceSet.getAllJava().getSrcDirs(),
sourceSet.getResources().getSourceDirectories().getSingleFile());
}
Expand Down Expand Up @@ -527,6 +497,6 @@ private static DependencyImpl initDependency(ResolvedArtifact a) {
private static ArtifactCoords toAppDependenciesKey(String groupId, String artifactId, String classifier) {
// Default classifier is empty string and not null value, lets keep it that way
classifier = classifier == null ? "" : classifier;
return new ArtifactCoordsImpl(groupId, artifactId, classifier, "", TYPE_JAR);
return new ArtifactCoordsImpl(groupId, artifactId, classifier, "", ArtifactCoordsImpl.TYPE_JAR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.bootstrap.model.AppModel;
import io.quarkus.bootstrap.model.gradle.ModelParameter;
import io.quarkus.bootstrap.model.gradle.QuarkusModel;
import io.quarkus.bootstrap.model.gradle.impl.ModelParameterImpl;
import io.quarkus.bootstrap.resolver.AppModelResolver;
import io.quarkus.bootstrap.resolver.model.ModelParameter;
import io.quarkus.bootstrap.resolver.model.QuarkusModel;
import io.quarkus.bootstrap.resolver.model.impl.ModelParameterImpl;
import io.quarkus.gradle.AppModelGradleResolver;
import io.quarkus.gradle.builder.QuarkusModelBuilder;
import io.quarkus.gradle.tasks.QuarkusGradleUtils;
Expand Down
Loading

0 comments on commit e1c2ba5

Please sign in to comment.