Skip to content

Commit

Permalink
Merge pull request #11346 from aloubyansky/build-tree-no-install
Browse files Browse the repository at this point in the history
Make quarkus-bootstrap-maven-plugin:build-tree work for not installed local projects
  • Loading branch information
gsmet authored Aug 13, 2020
2 parents f90bea3 + b729c5c commit f2c23c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,28 @@

import io.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import java.util.List;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;

public class AbstractTreeMojo extends AbstractMojo {
/**
* The entry point to Aether, i.e. the component doing all the work.
*
* @component
*/
@Component
protected RepositorySystem repoSystem;

/**
* The current repository/network configuration of Maven.
*
* @parameter default-value="${repositorySystemSession}"
* @readonly
*/
@Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
protected RepositorySystemSession repoSession;

/**
* The project's remote repositories to use for the resolution of artifacts and their dependencies.
*
* @parameter default-value="${project.remoteProjectRepositories}"
* @readonly
*/
@Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true)
protected List<RemoteRepository> repos;

@Parameter(defaultValue = "${project}", readonly = true, required = true)
protected MavenProject project;

protected MavenArtifactResolver resolver;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
final AppArtifact appArtifact = new AppArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion());
final BootstrapAppModelResolver modelResolver;
try {
modelResolver = new BootstrapAppModelResolver(
MavenArtifactResolver.builder()
.setRepositorySystem(repoSystem)
.setRepositorySystemSession(repoSession)
.setRemoteRepositories(repos)
.build());
modelResolver = new BootstrapAppModelResolver(resolver());
setupResolver(modelResolver);
modelResolver.setBuildTreeLogger(s -> getLog().info(s));
modelResolver.resolveModel(appArtifact);
Expand All @@ -63,6 +32,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

protected MavenArtifactResolver resolver() throws BootstrapMavenException {
return resolver == null ? resolver = new MavenArtifactResolver(new BootstrapMavenContext()) : resolver;
}

protected void setupResolver(BootstrapAppModelResolver modelResolver) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
/**
* Displays Quarkus application build dependency tree including the deployment ones.
*/
@Mojo(name = "build-tree", defaultPhase = LifecyclePhase.NONE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
@Mojo(name = "build-tree", defaultPhase = LifecyclePhase.NONE, requiresDependencyResolution = ResolutionScope.NONE)
public class BuildTreeMojo extends AbstractTreeMojo {
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ public void test() throws Exception {
app.getType(), app.getClassifier(), new DefaultArtifactHandler("jar")));
mojo.project.setModel(appModel);
mojo.project.setOriginalModel(appModel);

mojo.repoSystem = mvnResolver.getSystem();
mojo.repoSession = mvnResolver.getSession();
mojo.repos = mvnResolver.getRepositories();
mojo.resolver = mvnResolver;

final Path mojoLog = workDir.resolve("mojo.log");
final PrintStream defaultOut = System.out;
Expand Down

0 comments on commit f2c23c0

Please sign in to comment.