Skip to content

Commit

Permalink
Support multi-module builds (regression in 3.26) (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Nov 28, 2022
1 parent 546271b commit 427b6ab
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected void traverseProject() throws DependencyGraphBuilderException {
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setProject(project);
buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
visit(graphBuilder.buildDependencyGraph(buildingRequest, null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
Expand Down Expand Up @@ -132,8 +134,11 @@ private Artifact resolveJenkinsCore() throws MojoExecutionException {
artifactCoordinate.setVersion(findJenkinsVersion());

try {
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
return artifactResolver
.resolveArtifact(session.getProjectBuildingRequest(), artifactCoordinate)
.resolveArtifact(buildingRequest, artifactCoordinate)
.getArtifact();
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: ", e);
Expand All @@ -146,6 +151,7 @@ protected MavenArtifact wrap(Artifact a) {
artifactResolver,
artifactFactory,
projectBuilder,
session);
session,
project);
}
}
14 changes: 11 additions & 3 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/MavenArtifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,28 @@ public class MavenArtifact implements Comparable<MavenArtifact> {
public final Artifact artifact;
public final ArtifactResolver resolver;
public final MavenSession session;
public final MavenProject project;

public MavenArtifact(
Artifact artifact,
ArtifactResolver resolver,
ArtifactFactory artifactFactory,
ProjectBuilder builder,
MavenSession session) {
MavenSession session,
MavenProject project) {
this.artifact = artifact;
this.resolver = resolver;
this.artifactFactory = artifactFactory;
this.builder = builder;
this.session = Objects.requireNonNull(session);
this.project = Objects.requireNonNull(project);
}

public MavenProject resolvePom() throws ProjectBuildingException {
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setProcessPlugins(false); // improve performance
buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
buildingRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
return builder.build(artifact, buildingRequest).getProject();
}
Expand Down Expand Up @@ -123,7 +127,10 @@ public String getType() {
public File getFile() {
if (artifact.getFile()==null)
try {
return resolver.resolveArtifact(session.getProjectBuildingRequest(), artifact).getArtifact().getFile();
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
return resolver.resolveArtifact(buildingRequest, artifact).getArtifact().getFile();
} catch (ArtifactResolverException e) {
throw new RuntimeException("Failed to resolve "+getId(),e);
}
Expand All @@ -141,7 +148,8 @@ public MavenArtifact getHpi() throws IOException {
resolver,
artifactFactory,
builder,
session);
session,
project);
}

public List<String/* of IDs*/> getDependencyTrail() {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/RunMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.DefaultDependencyResolutionRequest;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.DependencyResolutionException;
import org.apache.maven.project.DependencyResolutionRequest;
import org.apache.maven.project.DependencyResolutionResult;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectDependenciesResolver;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
Expand Down Expand Up @@ -327,7 +329,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (webAppFile == null) {
Artifact jenkinsWarArtifact = getJenkinsWarArtifact();
try {
jenkinsWarArtifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), jenkinsWarArtifact).getArtifact();
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
jenkinsWarArtifact = artifactResolver.resolveArtifact(buildingRequest, jenkinsWarArtifact).getArtifact();
} catch (ArtifactResolverException x) {
throw new MojoExecutionException("Could not resolve " + jenkinsWarArtifact + ": " + x, x);
}
Expand Down Expand Up @@ -375,7 +380,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {

// find corresponding .hpi file
Artifact hpi = artifactFactory.createArtifact(a.getGroupId(),a.getArtifactId(),a.getVersion(),null,"hpi");
hpi = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), hpi).getArtifact();
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
hpi = artifactResolver.resolveArtifact(buildingRequest, hpi).getArtifact();

// check recursive dependency. this is a rare case that happens when we split out some things from the core
// into a plugin
Expand Down Expand Up @@ -829,7 +837,8 @@ protected MavenArtifact wrap(Artifact a) {
artifactResolver,
artifactFactory,
projectBuilder,
session);
session,
project);
}

protected Artifact getJenkinsWarArtifact() throws MojoExecutionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void execute() throws MojoExecutionException {
try {
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setProject(shadow);
buildingRequest.setRemoteRepositories(shadow.getRemoteArtifactRepositories());
ArtifactFilter filter = null; // Evaluate all scopes
node = dependencyCollectorBuilder.collectDependencyGraph(buildingRequest, filter);
} catch (DependencyCollectorBuilderException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;

Expand Down Expand Up @@ -79,8 +81,11 @@ private Artifact resolveJenkinsWar() throws MojoExecutionException {
artifactCoordinate.setExtension("war");

try {
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
return artifactResolver
.resolveArtifact(session.getProjectBuildingRequest(), artifactCoordinate)
.resolveArtifact(buildingRequest, artifactCoordinate)
.getArtifact();
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: ", e);
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/jenkinsci/maven/plugins/hpi/WarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Zip;
Expand Down Expand Up @@ -84,7 +86,10 @@ public void execute() throws MojoExecutionException {

// find corresponding .hpi file
Artifact hpi = artifactFactory.createArtifact(a.getGroupId(),a.getArtifactId(),a.getVersion(),null,"hpi");
hpi = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), hpi).getArtifact();
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
hpi = artifactResolver.resolveArtifact(buildingRequest, hpi).getArtifact();

if (hpi.getFile().isDirectory())
throw new UnsupportedOperationException(hpi.getFile()+" is a directory and not packaged yet. this isn't supported");
Expand Down

0 comments on commit 427b6ab

Please sign in to comment.