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

Fixes quarkus-platform native TS config #15929

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -72,6 +72,30 @@ public abstract class QuarkusBootstrapMojo extends AbstractMojo {
@Parameter(property = "ignoredEntries")
private String[] ignoredEntries;

/**
* Coordinates of the Maven artifact containing the original Java application to build the native image for.
* If not provided, the current project is assumed to be the original Java application.
* <p>
* The coordinates are expected to be expressed in the following format:
* <p>
* groupId:artifactId:classifier:type:version
* <p>
* With the classifier, type and version being optional.
* <p>
* If the type is missing, the artifact is assumed to be of type JAR.
* <p>
* If the version is missing, the artifact is going to be looked up among the project dependencies using the provided
* coordinates.
*
* <p>
* However, if the expression consists of only three parts, it is assumed to be groupId:artifactId:version.
*
* <p>
* If the expression consists of only four parts, it is assumed to be groupId:artifactId:classifier:type.
*/
@Parameter(required = false, property = "appArtifact")
private String appArtifact;

private AppArtifactKey projectId;

@Override
@@ -105,6 +129,10 @@ public void setLog(Log log) {
*/
protected abstract void doExecute() throws MojoExecutionException, MojoFailureException;

protected String appArtifactCoords() {
return appArtifact;
}

protected RepositorySystem repositorySystem() {
return bootstrapProvider.repositorySystem();
}
@@ -145,6 +173,8 @@ protected AppArtifactKey projectId() {
return projectId == null ? projectId = new AppArtifactKey(project.getGroupId(), project.getArtifactId()) : projectId;
}

// @deprecated in 1.14.0.Final
@Deprecated
protected AppArtifact projectArtifact() throws MojoExecutionException {
return bootstrapProvider.projectArtifact(this);
}
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.impl.RemoteRepositoryManager;

import com.google.common.cache.Cache;
@@ -60,9 +61,11 @@ public MavenArtifactResolver artifactResolver(QuarkusBootstrapMojo mojo)
return provider(mojo.projectId()).artifactResolver(mojo);
}

// @deprecated in 1.14.0.Final
@Deprecated
public AppArtifact projectArtifact(QuarkusBootstrapMojo mojo)
throws MojoExecutionException {
return provider(mojo.projectId()).projectArtifact(mojo);
return provider(mojo.projectId()).appArtifact(mojo);
}

public QuarkusBootstrap bootstrapQuarkus(QuarkusBootstrapMojo mojo)
@@ -91,7 +94,7 @@ public void close() throws IOException {

private class QuarkusAppBootstrapProvider implements Closeable {

private AppArtifact projectArtifact;
private AppArtifact appArtifact;
private MavenArtifactResolver artifactResolver;
private QuarkusBootstrap quarkusBootstrap;
private CuratedApplication curatedApp;
@@ -114,34 +117,6 @@ private MavenArtifactResolver artifactResolver(QuarkusBootstrapMojo mojo)
}
}

private AppArtifact projectArtifact(QuarkusBootstrapMojo mojo) throws MojoExecutionException {
if (projectArtifact != null) {
return projectArtifact;
}
final Artifact projectArtifact = mojo.mavenProject().getArtifact();
final AppArtifact appArtifact = new AppArtifact(projectArtifact.getGroupId(), projectArtifact.getArtifactId(),
projectArtifact.getClassifier(), projectArtifact.getArtifactHandler().getExtension(),
projectArtifact.getVersion());

File projectFile = projectArtifact.getFile();
if (projectFile == null) {
projectFile = new File(mojo.mavenProject().getBuild().getOutputDirectory());
if (!projectFile.exists()) {
/*
* TODO GenerateCodeMojo would fail
* if (hasSources(project)) {
* throw new MojoExecutionException("Project " + project.getArtifact() + " has not been compiled yet");
* }
*/
if (!projectFile.mkdirs()) {
throw new MojoExecutionException("Failed to create the output dir " + projectFile);
}
}
}
appArtifact.setPaths(PathsCollection.of(projectFile.toPath()));
return appArtifact;
}

protected QuarkusBootstrap bootstrapQuarkus(QuarkusBootstrapMojo mojo) throws MojoExecutionException {
if (quarkusBootstrap != null) {
return quarkusBootstrap;
@@ -164,7 +139,8 @@ protected QuarkusBootstrap bootstrapQuarkus(QuarkusBootstrapMojo mojo) throws Mo
effectiveProperties.putIfAbsent("quarkus.application.version", mojo.mavenProject().getVersion());

QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder()
.setAppArtifact(projectArtifact(mojo))
.setAppArtifact(appArtifact(mojo))
.setManagingProject(managingProject(mojo))
.setMavenArtifactResolver(artifactResolver(mojo))
.setIsolateDeployment(true)
.setBaseClassLoader(getClass().getClassLoader())
@@ -195,6 +171,96 @@ protected CuratedApplication curateApplication(QuarkusBootstrapMojo mojo) throws
}
}

protected AppArtifact managingProject(QuarkusBootstrapMojo mojo) {
if (mojo.appArtifactCoords() == null) {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if it's an external artifact, you return null here? What's bothering me a bit is that it wasn't set before so I'm not sure to understand why it's now set in the case that was already existing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. When the appArtifact is configured, the current project is used as the environment for the build and tests. That's the meaning behind the managingProject. It's either null or the current project. Setting it to null is equivalent to not setting it at all.

}
final Artifact artifact = mojo.mavenProject().getArtifact();
return new AppArtifact(artifact.getGroupId(), artifact.getArtifactId(),
artifact.getClassifier(), artifact.getArtifactHandler().getExtension(),
artifact.getVersion());
}

private AppArtifact appArtifact(QuarkusBootstrapMojo mojo) throws MojoExecutionException {
return appArtifact == null ? appArtifact = initAppArtifact(mojo) : appArtifact;
}

private AppArtifact initAppArtifact(QuarkusBootstrapMojo mojo) throws MojoExecutionException {
String appArtifactCoords = mojo.appArtifactCoords();
if (appArtifactCoords == null) {
final Artifact projectArtifact = mojo.mavenProject().getArtifact();
final AppArtifact appArtifact = new AppArtifact(projectArtifact.getGroupId(), projectArtifact.getArtifactId(),
projectArtifact.getClassifier(), projectArtifact.getArtifactHandler().getExtension(),
projectArtifact.getVersion());

File projectFile = projectArtifact.getFile();
if (projectFile == null) {
projectFile = new File(mojo.mavenProject().getBuild().getOutputDirectory());
if (!projectFile.exists()) {
/*
* TODO GenerateCodeMojo would fail
* if (hasSources(project)) {
* throw new MojoExecutionException("Project " + project.getArtifact() + " has not been compiled yet");
* }
*/
if (!projectFile.mkdirs()) {
throw new MojoExecutionException("Failed to create the output dir " + projectFile);
}
}
}
appArtifact.setPaths(PathsCollection.of(projectFile.toPath()));
return appArtifact;
}

final String[] coordsArr = appArtifactCoords.split(":");
if (coordsArr.length < 2 || coordsArr.length > 5) {
throw new MojoExecutionException(
"appArtifact expression " + appArtifactCoords
+ " does not follow format groupId:artifactId:classifier:type:version");
}
final String groupId = coordsArr[0];
final String artifactId = coordsArr[1];
String classifier = "";
String type = "jar";
String version = null;
if (coordsArr.length == 3) {
version = coordsArr[2];
} else if (coordsArr.length > 3) {
classifier = coordsArr[2] == null ? "" : coordsArr[2];
type = coordsArr[3] == null ? "jar" : coordsArr[3];
if (coordsArr.length > 4) {
version = coordsArr[4];
}
}
if (version == null) {
for (Artifact dep : mojo.mavenProject().getArtifacts()) {
if (dep.getArtifactId().equals(artifactId)
&& dep.getGroupId().equals(groupId)
&& dep.getClassifier().equals(classifier)
&& dep.getType().equals(type)) {
return new AppArtifact(dep.getGroupId(),
dep.getArtifactId(),
dep.getClassifier(),
dep.getArtifactHandler().getExtension(),
dep.getVersion());
}
}
throw new IllegalStateException("Failed to locate " + appArtifactCoords + " among the project dependencies");
}

final AppArtifact appArtifact = new AppArtifact(groupId, artifactId, classifier, type, version);
try {
appArtifact.setPath(
artifactResolver(mojo).resolve(new DefaultArtifact(groupId, artifactId, classifier, type, version))
.getArtifact().getFile().toPath());
} catch (MojoExecutionException e) {
throw e;
} catch (Exception e) {
throw new MojoExecutionException("Failed to resolve " + appArtifact, e);
}
return appArtifact;
}

@Override
public void close() throws IOException {
if (curatedApp != null) {