From 3b95d6dc492983ee0236c2ae5824a83489f176fb Mon Sep 17 00:00:00 2001 From: Ilya Pyatizbyantsev <47037396+pyatizbyantsevia@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:35:30 +0300 Subject: [PATCH] Migrate from `maven-artifact-transfer` to direct use of Resolver API (#118) Co-authored-by: Basil Crow --- jellydoc-maven-plugin/pom.xml | 12 ++----- .../jvnet/maven/jellydoc/JellydocMojo.java | 31 +++++++++++++------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/jellydoc-maven-plugin/pom.xml b/jellydoc-maven-plugin/pom.xml index 5a0e0ec..e3d07d3 100644 --- a/jellydoc-maven-plugin/pom.xml +++ b/jellydoc-maven-plugin/pom.xml @@ -129,15 +129,9 @@ - org.apache.maven.shared - maven-artifact-transfer - 0.13.1 - - - org.apache.maven.resolver - maven-resolver-api - - + org.apache.maven.resolver + maven-resolver-api + 2.0.1 org.dom4j diff --git a/jellydoc-maven-plugin/src/main/java/org/jvnet/maven/jellydoc/JellydocMojo.java b/jellydoc-maven-plugin/src/main/java/org/jvnet/maven/jellydoc/JellydocMojo.java index 1489804..11a1fb2 100644 --- a/jellydoc-maven-plugin/src/main/java/org/jvnet/maven/jellydoc/JellydocMojo.java +++ b/jellydoc-maven-plugin/src/main/java/org/jvnet/maven/jellydoc/JellydocMojo.java @@ -27,6 +27,7 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.doxia.sink.Sink; @@ -41,12 +42,12 @@ 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.reporting.MavenMultiPageReport; import org.apache.maven.reporting.MavenReportException; -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver; -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException; import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Javadoc; @@ -59,6 +60,10 @@ import org.dom4j.io.DocumentSource; import org.dom4j.io.SAXReader; import org.dom4j.tree.DefaultDocument; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactResolutionException; /** * Generates jellydoc XML and other artifacts from there. @@ -102,7 +107,7 @@ public class JellydocMojo extends AbstractMojo implements MavenMultiPageReport { * Used for resolving artifacts */ @Component - public ArtifactResolver resolver; + public RepositorySystem repositorySystem; @Component public MavenProjectHelper helper; @@ -148,15 +153,23 @@ public void execute() throws MojoExecutionException { setParam(d, "-d", targetDir().getAbsolutePath()); Path docletPath = makePath(p, pluginArtifacts); + + ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); + buildingRequest.setRemoteRepositories(project.getRemoteArtifactRepositories()); + List remoteRepositories = RepositoryUtils.toRepos(buildingRequest.getRemoteRepositories()); + + Artifact artifact = factory.createArtifact( + "io.jenkins.tools.maven", "jellydoc-maven-plugin", pluginVersion, null, "maven-plugin"); + ArtifactRequest request = new ArtifactRequest(RepositoryUtils.toArtifact(artifact), remoteRepositories, null); + Artifact self; try { - Artifact self = factory.createArtifact( - "io.jenkins.tools.maven", "jellydoc-maven-plugin", pluginVersion, null, "maven-plugin"); - self = resolver.resolveArtifact(session.getProjectBuildingRequest(), self) - .getArtifact(); - docletPath.createPathElement().setLocation(self.getFile()); - } catch (ArtifactResolverException e) { + self = RepositoryUtils.toArtifact(repositorySystem + .resolveArtifact(buildingRequest.getRepositorySession(), request) + .getArtifact()); + } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Failed to resolve plugin from within itself", e); } + docletPath.createPathElement().setLocation(self.getFile()); d.setPath(docletPath); // debug support