Skip to content

Commit

Permalink
Merge pull request #5268 from aloubyansky/resolve-latest-universe
Browse files Browse the repository at this point in the history
Make the tooling resolve the latest version of the universe
  • Loading branch information
aloubyansky authored Nov 14, 2019
2 parents 95c33f9 + 6474bee commit b43df0e
Show file tree
Hide file tree
Showing 23 changed files with 703 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor;
import io.quarkus.platform.descriptor.resolver.json.QuarkusJsonPlatformDescriptorResolver;
import io.quarkus.platform.tools.MessageWriter;
import io.quarkus.platform.tools.ToolsConstants;
import io.quarkus.platform.tools.config.QuarkusPlatformConfig;
import io.quarkus.platform.tools.maven.MojoMessageWriter;

Expand All @@ -42,10 +43,10 @@ public abstract class BuildFileMojoBase extends AbstractMojo {
@Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true)
protected List<RemoteRepository> repos;

@Parameter(property = "bomGroupId", defaultValue = CreateUtils.DEFAULT_PLATFORM_BOM_GROUP_ID)
@Parameter(property = "bomGroupId", defaultValue = ToolsConstants.DEFAULT_PLATFORM_BOM_GROUP_ID)
private String bomGroupId;

@Parameter(property = "bomArtifactId", defaultValue = CreateUtils.DEFAULT_PLATFORM_BOM_ARTIFACT_ID)
@Parameter(property = "bomArtifactId", required = false)
private String bomArtifactId;

@Parameter(property = "bomVersion", required = false)
Expand Down Expand Up @@ -128,34 +129,10 @@ public void execute() throws MojoExecutionException {
|| new File(project.getBasedir(), "build.gradle.kts").exists()) {
// Gradle project
buildFile = new GradleBuildFile(new FileProjectWriter(project.getBasedir()));
} else {

}

if (!QuarkusPlatformConfig.hasGlobalDefault()) {
String bomGroupId = this.bomGroupId;
if (bomGroupId == null) {
bomGroupId = CreateUtils.DEFAULT_PLATFORM_BOM_GROUP_ID;
}
String bomArtifactId = this.bomArtifactId;
if (bomArtifactId == null) {
bomArtifactId = CreateUtils.DEFAULT_PLATFORM_BOM_ARTIFACT_ID;
}

String bomVersion = this.bomVersion;
if (bomVersion == null) {
// if the BOM artifactId matches Quarkus BOM we use the plugins version as its version
bomVersion = CreateUtils.QUARKUS_CORE_BOM_ARTIFACT_ID.equals(bomArtifactId)
? CreateUtils.resolvePluginInfo(BuildFileMojoBase.class).getVersion()
: null;
}
final QuarkusPlatformDescriptor platform = QuarkusJsonPlatformDescriptorResolver.newInstance()
.setArtifactResolver(new BootstrapAppModelResolver(mvn))
.setMessageWriter(log)
.resolveFromBom(bomGroupId, bomArtifactId, bomVersion);
QuarkusPlatformConfig.defaultConfigBuilder()
.setPlatformDescriptor(platform)
.build();
CreateUtils.setGlobalPlatformDescriptor(bomGroupId, bomArtifactId, bomVersion, mvn, getLog());
}

doExecute(buildFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.fusesource.jansi.Ansi;

import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.cli.commands.AddExtensionResult;
import io.quarkus.cli.commands.AddExtensions;
Expand All @@ -56,10 +55,6 @@
import io.quarkus.maven.components.MavenVersionEnforcer;
import io.quarkus.maven.components.Prompter;
import io.quarkus.maven.utilities.MojoUtils;
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor;
import io.quarkus.platform.descriptor.resolver.json.QuarkusJsonPlatformDescriptorResolver;
import io.quarkus.platform.tools.config.QuarkusPlatformConfig;
import io.quarkus.platform.tools.maven.MojoMessageWriter;

/**
* This goal helps in setting up Quarkus Maven project with quarkus-maven-plugin, with sensible defaults
Expand All @@ -83,12 +78,21 @@ public class CreateProjectMojo extends AbstractMojo {
@Parameter(property = "projectVersion")
private String projectVersion;

@Parameter(property = "platformGroupId", defaultValue = CreateUtils.DEFAULT_PLATFORM_BOM_GROUP_ID)
/**
* Group ID of the target platform BOM
*/
@Parameter(property = "platformGroupId", required = false)
private String bomGroupId;

@Parameter(property = "platformArtifactId", defaultValue = CreateUtils.DEFAULT_PLATFORM_BOM_ARTIFACT_ID)
/**
* Artifact ID of the target platform BOM
*/
@Parameter(property = "platformArtifactId", required = false)
private String bomArtifactId;

/**
* Version of the target platform BOM
*/
@Parameter(property = "platformVersion", required = false)
private String bomVersion;

Expand Down Expand Up @@ -143,19 +147,7 @@ public void execute() throws MojoExecutionException {
} catch (AppModelResolverException e1) {
throw new MojoExecutionException("Failed to initialize Maven artifact resolver", e1);
}

if (CreateUtils.QUARKUS_CORE_BOM_ARTIFACT_ID.equals(bomArtifactId)
&& (bomVersion == null || bomVersion.isEmpty())) {
bomVersion = CreateUtils.resolvePluginInfo(getClass()).getVersion();
}

// We assume platform specified by user refers to a BOM.
final QuarkusPlatformDescriptor platform = QuarkusJsonPlatformDescriptorResolver.newInstance()
.setMessageWriter(new MojoMessageWriter(getLog()))
.setArtifactResolver(new BootstrapAppModelResolver(mvn))
.resolveFromBom(bomGroupId, bomArtifactId, bomVersion);

QuarkusPlatformConfig.defaultConfigBuilder().setPlatformDescriptor(platform).build();
CreateUtils.setGlobalPlatformDescriptor(bomGroupId, bomArtifactId, bomVersion, mvn, getLog());

// We detect the Maven version during the project generation to indicate the user immediately that the installed
// version may not be supported.
Expand Down
54 changes: 54 additions & 0 deletions devtools/maven/src/main/java/io/quarkus/maven/CreateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.bootstrap.util.ZipUtils;
import io.quarkus.maven.utilities.MojoUtils;
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor;
import io.quarkus.platform.descriptor.resolver.json.QuarkusJsonPlatformDescriptorResolver;
import io.quarkus.platform.tools.config.QuarkusPlatformConfig;
import io.quarkus.platform.tools.maven.MojoMessageWriter;

public final class CreateUtils {

Expand All @@ -28,6 +35,53 @@ private CreateUtils() {
//Not to be constructed
}

private static boolean isVersionRange(String versionStr) {
if (versionStr == null || versionStr.isEmpty()) {
return false;
}
char c = versionStr.charAt(0);
if (c == '[' || c == '(') {
return true;
}
c = versionStr.charAt(versionStr.length() - 1);
if (c == ']' || c == ')') {
return true;
}
return versionStr.indexOf(',') >= 0;
}

static void setGlobalPlatformDescriptor(final String bomGroupId, final String bomArtifactId, final String bomVersion,
MavenArtifactResolver mvn, Log log) throws MojoExecutionException {

final QuarkusJsonPlatformDescriptorResolver platformResolver = QuarkusJsonPlatformDescriptorResolver.newInstance()
.setMessageWriter(new MojoMessageWriter(log))
.setArtifactResolver(new BootstrapAppModelResolver(mvn));

String groupId = StringUtils.defaultIfBlank(bomGroupId, null);
String artifactId = StringUtils.defaultIfBlank(bomArtifactId, null);
String version = StringUtils.defaultIfBlank(bomVersion, null);

if (CreateUtils.QUARKUS_CORE_BOM_ARTIFACT_ID.equals(artifactId)
&& version == null) {
version = resolvePluginInfo(CreateUtils.class).getVersion();
}

final QuarkusPlatformDescriptor platform;
if (version == null) {
if (artifactId == null && groupId == null) {
platform = platformResolver.resolve();
} else {
platform = platformResolver.resolveLatestFromBom(groupId, artifactId, null);
}
} else if (isVersionRange(version)) {
platform = platformResolver.resolveLatestFromBom(groupId, artifactId, version);
} else {
platform = platformResolver.resolveFromBom(groupId, artifactId, version);
}

QuarkusPlatformConfig.defaultConfigBuilder().setPlatformDescriptor(platform).build();
}

public static String getDerivedPath(String className) {
String[] resourceClassName = StringUtils.splitByCharacterTypeCamelCase(
className.substring(className.lastIndexOf(".") + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,27 @@ public class ResolverSetupCleanup {

@BeforeEach
public void setup() throws Exception {
workDir = IoUtils.createRandomTmpDir();
workDir = initWorkDir();
repoHome = IoUtils.mkdirs(workDir.resolve("repo"));
resolver = initResolver();
repo = TsRepoBuilder.getInstance(resolver, workDir);
}

@AfterEach
public void cleanup() {
if(workDir != null) {
if(cleanWorkDir() && workDir != null) {
IoUtils.recursiveDelete(workDir);
}
}

protected Path initWorkDir() {
return IoUtils.createRandomTmpDir();
}

protected boolean cleanWorkDir() {
return true;
}

protected BootstrapAppModelResolver initResolver() throws AppModelResolverException {
return new BootstrapAppModelResolver(MavenArtifactResolver.builder()
.setRepoHome(repoHome)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static TsArtifact jar(String artifactId, String version) {
return new TsArtifact(DEFAULT_GROUP_ID, artifactId, EMPTY, TYPE_JAR, version);
}

interface ContentProvider {
public interface ContentProvider {
Path getPath(Path workDir) throws IOException;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ public void install(TsArtifact artifact, Path p) {
case TsArtifact.TYPE_TXT:
p = newTxt(artifact);
break;
case TsArtifact.TYPE_POM:
break;
default:
throw new IllegalStateException("Unsupported artifact type " + artifact.type);
}
}
install(artifact.toAppArtifact(), p);
if (p != null) {
install(artifact.toAppArtifact(), p);
}
}

protected void install(AppArtifact artifact, Path file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public static String getProperty(String name) {
public static String getProperty(String name, String defaultValue) {
return System.getProperty(name, defaultValue);
}

public static boolean isNullOrEmpty(String arg) {
return arg == null || arg.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
<version>${quarkus.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.platform.descriptor.resolver.json;

import java.lang.Exception;

public class PlatformDescriptorLoadingException extends Exception {

private static final long serialVersionUID = 1L;

public PlatformDescriptorLoadingException(String message, Throwable cause) {
super(message, cause);
}

public PlatformDescriptorLoadingException(String message) {
super(message);
}
}
Loading

0 comments on commit b43df0e

Please sign in to comment.