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
…118)

Co-authored-by: Basil Crow <me@basilcrow.com>
  • Loading branch information
pyatizbyantsevia and basil authored Oct 28, 2024
1 parent afe5efe commit 3b95d6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
12 changes: 3 additions & 9 deletions jellydoc-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
<version>0.13.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
</exclusion>
</exclusions>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<RemoteRepository> 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
Expand Down

0 comments on commit 3b95d6d

Please sign in to comment.