Skip to content

Commit

Permalink
Migrate from maven-artifact-transfer to direct use of Resolver API (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Jun 21, 2023
1 parent 4b55e55 commit 5ac74c2
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 220 deletions.
112 changes: 5 additions & 107 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@
<dollar>$</dollar>
<openbracket>{</openbracket>
<gitHubRepo>jenkinsci/${project.artifactId}</gitHubRepo>
<aether.version>1.1.0</aether.version>
<!-- if we update this all consumers need to be running at least this version -->
<maven.version>3.8.1</maven.version>
<maven-plugin-tools.version>3.9.0</maven-plugin-tools.version>
<aether.version>1.1.0</aether.version>
<spotless.check.skip>false</spotless.check.skip>
</properties>

Expand All @@ -67,64 +65,9 @@
<version>1.15</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>4.7.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-io</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-spi</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${aether.version}</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -171,11 +114,6 @@
<artifactId>maven-archiver</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
<version>0.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
Expand Down Expand Up @@ -220,22 +158,19 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-builder-support</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -247,11 +182,6 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
Expand All @@ -261,18 +191,6 @@
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings-builder</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand Down Expand Up @@ -308,26 +226,6 @@

<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>display-info</id>
<configuration>
<rules>
<requireUpperBoundDeps>
<excludes combine.children="append">
<exclude>commons-lang:commons-lang</exclude>
<exclude>org.apache.commons:commons-collections4</exclude>
<exclude>org.apache.commons:commons-lang3</exclude>
<exclude>org.slf4j:slf4j-api</exclude>
</excludes>
</requireUpperBoundDeps>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@
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;
import org.eclipse.aether.RepositorySystem;

/**
* Mojos that need to figure out the Jenkins version it's working with.
Expand Down Expand Up @@ -62,7 +58,7 @@ public abstract class AbstractJenkinsMojo extends AbstractMojo {
protected ArtifactFactory artifactFactory;

@Component
protected ArtifactResolver artifactResolver;
protected RepositorySystem repositorySystem;

@Component
protected ProjectBuilder projectBuilder;
Expand Down Expand Up @@ -127,30 +123,20 @@ protected JavaSpecificationVersion getMinimumJavaVersion() throws MojoExecutionE
}

private Artifact resolveJenkinsCore() throws MojoExecutionException {
DefaultArtifactCoordinate artifactCoordinate = new DefaultArtifactCoordinate();
String groupId, artifactId;
if (jenkinsCoreId != null) {
String[] parts = jenkinsCoreId.split(":");
artifactCoordinate.setGroupId(parts[0]);
artifactCoordinate.setArtifactId(parts[1]);
groupId = parts[0];
artifactId = parts[1];
} else {
artifactCoordinate.setGroupId("org.jenkins-ci.main");
artifactCoordinate.setArtifactId("jenkins-core");
}
artifactCoordinate.setVersion(findJenkinsVersion());

try {
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
return artifactResolver
.resolveArtifact(buildingRequest, artifactCoordinate)
.getArtifact();
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: ", e);
groupId = "org.jenkins-ci.main";
artifactId = "jenkins-core";
}
Artifact artifact = artifactFactory.createArtifact(groupId, artifactId, findJenkinsVersion(), null, "jar");
return MavenArtifact.resolveArtifact(artifact, project, session, repositorySystem);
}

protected MavenArtifact wrap(Artifact a) {
return new MavenArtifact(a, artifactResolver, artifactFactory, projectBuilder, session, project);
return new MavenArtifact(a, repositorySystem, artifactFactory, projectBuilder, session, project);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jenkinsci/maven/plugins/hpi/HplMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* puts into WEB-INF/lib should be the same so that the plugins see consistent
* environment.
*/
private void buildLibraries(List<String> paths) throws IOException {
private void buildLibraries(List<String> paths) throws IOException, MojoExecutionException {
Set<MavenArtifact> artifacts = getProjectArtfacts();

// List up IDs of Jenkins plugin dependencies
Expand Down

0 comments on commit 5ac74c2

Please sign in to comment.