Created
June 4, 2012 23:04
-
-
Save sully6768/2871378 to your computer and use it in GitHub Desktop.
Aether Plugin Test - Mojo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import org.apache.maven.plugin.AbstractMojo; | |
import org.apache.maven.plugin.MojoExecutionException; | |
import org.apache.maven.plugin.MojoFailureException; | |
import org.sonatype.aether.RepositorySystem; | |
import org.sonatype.aether.RepositorySystemSession; | |
import org.sonatype.aether.artifact.Artifact; | |
import org.sonatype.aether.repository.RemoteRepository; | |
import org.sonatype.aether.resolution.ArtifactRequest; | |
import org.sonatype.aether.resolution.ArtifactResolutionException; | |
import org.sonatype.aether.resolution.ArtifactResult; | |
import org.sonatype.aether.util.artifact.DefaultArtifact; | |
/** | |
* Goal which touches a timestamp file. | |
* | |
* @goal resolve | |
* @phase package | |
*/ | |
public class MyAetherMojo extends AbstractMojo { | |
/** | |
* The entry point to Aether, i.e. the component doing all the work. | |
* | |
* @component | |
*/ | |
private RepositorySystem repoSystem; | |
/** | |
* The current repository/network configuration of Maven. | |
* | |
* @parameter default-value="${repositorySystemSession}" | |
* @readonly | |
*/ | |
private RepositorySystemSession repoSession; | |
/** | |
* The project's remote repositories to use for the resolution. | |
* | |
* @parameter default-value="${project.remoteProjectRepositories}" | |
* @readonly | |
*/ | |
private List<RemoteRepository> remoteRepos; | |
/** | |
* The {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>} of the artifact to resolve. | |
* | |
* @parameter expression="${aether.artifactCoords}" | |
*/ | |
private String artifactCoords; | |
public void execute() | |
throws MojoExecutionException, MojoFailureException | |
{ | |
Artifact artifact; | |
try | |
{ | |
artifact = new DefaultArtifact( artifactCoords ); | |
} | |
catch ( IllegalArgumentException e ) | |
{ | |
throw new MojoFailureException( e.getMessage(), e ); | |
} | |
ArtifactRequest request = new ArtifactRequest(); | |
request.setArtifact( artifact ); | |
request.setRepositories( remoteRepos ); | |
getLog().info( "Resolving artifact " + artifact + " from " + remoteRepos ); | |
ArtifactResult result; | |
try | |
{ | |
result = repoSystem.resolveArtifact( repoSession, request ); | |
} | |
catch ( ArtifactResolutionException e ) | |
{ | |
throw new MojoExecutionException( e.getMessage(), e ); | |
} | |
getLog().info( "Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " | |
+ result.getRepository() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment