You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Tristan JC Rouse <tr...@tristanjcrouse.com> on 2009/09/15 15:23:02 UTC

Plugin Development: resolving arbitrary artifacts

Hi,
I'm currently trying to write a plugin to deploy a project to an application
server. This project is of a type not currently buildable by Maven so my
plan of action is to manually build the artifact and deploy it to my
internal remote repository (deploy:deployfile) and then get Maven to resolve
this artifact to the local repository and deploy it from there. I already
have the code necessary to deploy the artifact, I'm just trying to hook it
into Maven, and I need to get maven to download the artifact to the local
repository and then give me it's path there.

   1. /**
   2.  * @goal extract
   3.  * @phase package
   4.  * @requiresDependencyResolution test
   5.  */
   6. public class DeployWierdProjectType extends AbstractMojo {
   7.
   8.     /**
   9.      * @parameter default-value="${project}"
   10.      * @required
   11.      * @readonly
   12.      */
   13.     private MavenProject project;
   14.
   15.     public void execute() throws MojoExecutionException {
   16.
   17.
           System.out.println(project.getArtifact().getFile().getAbsolutePath());
   18.
   19.     }
   20. }

/** * @goal extract * @phase package * @requiresDependencyResolution test */
public class DeployWierdProjectType extends AbstractMojo { /** * @parameter
default-value="${project}" * @required * @readonly */ private MavenProject
project; public void execute() throws MojoExecutionException {
System.out.println(project.getArtifact().getFile().getAbsolutePath()); } }

I've been teaching myself the Maven api using a tutorial project. The code
above gives me different results depending on the phase I define, so this
probably not an accurate exercise as my mojo will not be bound to the
lifecycle. I think I'm missing a couple pieces to my puzzle right now:

1) The DefaultArtifactResolver class's resolve(Artifact, List,
ArtifactRepository) method takes an ArtifactRepository parameter which
specifies the local repository. I can't figure out where to find this as the
MavenProject doesn't seem to supply it. MavenProject.getRepositores()
returned only remote repositories for me when trying it. If I could figure
out the ArtifactRepositoryLayout class I might be able to generate a
DefaultArtifactRepository from scratch but for portability this information
should really come from the currently running installation of Maven's
"conf/settings.xml" file (or a profile if that's possible?).

2) Actually due to the lack of information in the javadoc I'm really just
guessing that the ArtifactResolver's resolve method will, in fact, download
the specified Artifact to the local repository and update the value returned
by the Artifact.getFile() method. I could be off base here.

Any input on how to accomplish these tasks in maven is greatly appreciated.

Thanks

-- 
Tristan JC Rouse

Re: Plugin Development: resolving arbitrary artifacts

Posted by Benjamin Bentmann <be...@udo.edu>.
Tristan JC Rouse wrote:

> 1) The DefaultArtifactResolver class's resolve(Artifact, List,
> ArtifactRepository) method takes an ArtifactRepository parameter which
> specifies the local repository. I can't figure out where to find this

Have a glance at the sections "For accessing artifacts and repositories"
and "Creating and resolving an artifact" of [0].

Apart from this, existing plugins can also provide inspirations. For 
instance, the Maven Dependency Plugin has some bits to deal with 
artifact resolution.

> 2) Actually due to the lack of information in the javadoc I'm really just
> guessing that the ArtifactResolver's resolve method will, in fact, download
> the specified Artifact to the local repository and update the value returned
> by the Artifact.getFile() method. I could be off base here.

Yeah, the javadoc is admittedly thin but as this is all open source, you 
can always check the sources to see what actually goes on. Of course, 
single-stepping through Maven code with the debugger can also be a good 
way to get a rough understanding.


Benjamin


[0] http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org