You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by nicolas de loof <ni...@gmail.com> on 2007/10/01 11:48:34 UTC

maven extension : adding a custom ArtifactHandler

Hello,

I'd like to add support in maven for a custom packaging.
I've created a META-INF/plexus/components.xml to define a new ArtifactHandler :

    <component>
      <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
      <role-hint>javascript</role-hint>
      <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
      <configuration>
        <type>javascript</type>
        <extension>jsar</extension>
        <language>javascript</language>
        <addedToClasspath>false</addedToClasspath>
      </configuration>
    </component>

I the run "mvn install" from a test project that has a dependency of
type "javascript" and defines my custom plugin as a build extension.
The requested URL in my repo uses the unexpected ".javascript"
extension.

Runing maven in a debug session, in DefaultWagonManager.getArtifact()
the requested artifact doens't have my custom handler attached, but
what seems to be the default one for unresolved types.

Is this the good way to extend maven ? What's wrong ?

Nico.

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


Re: [resolved] maven extension : adding a custom ArtifactHandler

Posted by Shane Isbell <sh...@gmail.com>.
This artifact handler bug has proven a problem for me as well. Maven does
pick up and maintain the handlers from the components.xml file; it just
doesn't add them to the ArtifactHandlerManager, making the
handlers inaccessible to the ArtifactFactory, which creates the respective
artifacts. If you need to add multiple handlers, you could take the list of
artifact handlers and programmaticly add any missing ones to the
ArtifactHandlerManager. This should also be relatively simple to fix within
the core.

Shane


On 10/1/07, Arnaud HERITIER <ah...@gmail.com> wrote:
>
> I had this problem (It's a bug and also a problem in the conception of the
> core) and I solved it like this :
>
> package com.octo.mtg.plugin;
>
> import java.io.File;
>
> import org.apache.maven.artifact.handler.ArtifactHandler;
> import org.apache.maven.plugin.MojoExecutionException;
> import org.apache.maven.plugin.MojoFailureException;
> import org.apache.maven.project.MavenProject;
>
> /**
> * Creates a WAR archive and register it in maven.
> *
> * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
> * @version $Id$
> *
> * @description Creates a WAR archive and register it in maven.
> * @goal maven-war
> * @phase package
> * @since 0.1
> */
> public class MavenWarMojo extends AbstractGrailsMojo {
>
>        /**
>         * The maven project.
>         *
>         * @parameter expression="${project}"
>         * @required
>         * @readonly
>         */
>        private MavenProject project;
>
>        /**
>         * The artifact handler.
>         *
>         * @parameter expression="${
> component.org.apache.maven.artifact.handler.ArtifactHandler#grails-app}"
>         * @required
>         * @readonly
>         */
>        protected ArtifactHandler artifactHandler;
>
>        /**
>         * Executes the MavenWarMojo on the current project.
>         *
>         * @throws MojoExecutionException
>         *             if an error occured while building the webapp
>         */
>        public void execute() throws MojoExecutionException,
> MojoFailureException {
>                // launch grails
>                launchGrails("war");
>                File warGeneratedByGrails = new File(getBasedir(),
>                                getGrailsDescriptor().getAppName() + "-"
>                                                +
> getGrailsDescriptor().getAppVersion() + ".war");
>                project.getArtifact().setFile(warGeneratedByGrails);
>                project.getArtifact().setArtifactHandler(artifactHandler);
>        }
>
> }
>
>
> You have to manually set the file and the artifact handler
>
>
> Arnaud
>
>
>
> http://forge.octo.com/svn/mtg/trunk/grails-maven-plugin/src/main/java/com/octo/mtg/plugin/MavenWarMojo.java
>
>
> On 01/10/2007, nicolas de loof <ni...@gmail.com> wrote:
> >
> > I just understood I have to configure the plugin in the build/plugins
> > element with <extensions>true</extensions>
> >
> > What's the meaning of the build/extensions element ?
> >
> > 2007/10/1, nicolas de loof <ni...@gmail.com>:
> > > Hello,
> > >
> > > I'd like to add support in maven for a custom packaging.
> > > I've created a META-INF/plexus/components.xml to define a new
> > ArtifactHandler :
> > >
> > >     <component>
> > >       <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
> > >       <role-hint>javascript</role-hint>
> > >       <implementation>
> > org.apache.maven.artifact.handler.DefaultArtifactHandler
> </implementation>
> > >       <configuration>
> > >         <type>javascript</type>
> > >         <extension>jsar</extension>
> > >         <language>javascript</language>
> > >         <addedToClasspath>false</addedToClasspath>
> > >       </configuration>
> > >     </component>
> > >
> > > I the run "mvn install" from a test project that has a dependency of
> > > type "javascript" and defines my custom plugin as a build extension.
> > > The requested URL in my repo uses the unexpected ".javascript"
> > > extension.
> > >
> > > Runing maven in a debug session, in DefaultWagonManager.getArtifact()
> > > the requested artifact doens't have my custom handler attached, but
> > > what seems to be the default one for unresolved types.
> > >
> > > Is this the good way to extend maven ? What's wrong ?
> > >
> > > Nico.
> > >
> >
>
>
>
> --
> ..........................................................
> Arnaud HERITIER
> ..........................................................
> OCTO Technology - aheritier AT octo DOT com
> www.octo.com | blog.octo.com
> ..........................................................
> ASF - aheritier AT apache DOT org
> www.apache.org | maven.apache.org
> ...........................................................
>

Re: [resolved] maven extension : adding a custom ArtifactHandler

Posted by Arnaud HERITIER <ah...@gmail.com>.
I had this problem (It's a bug and also a problem in the conception of the
core) and I solved it like this :

package com.octo.mtg.plugin;

import java.io.File;

import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;

/**
 * Creates a WAR archive and register it in maven.
 *
 * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
 * @version $Id$
 *
 * @description Creates a WAR archive and register it in maven.
 * @goal maven-war
 * @phase package
 * @since 0.1
 */
public class MavenWarMojo extends AbstractGrailsMojo {

	/**
	 * The maven project.
	 *
	 * @parameter expression="${project}"
	 * @required
	 * @readonly
	 */
	private MavenProject project;

	/**
	 * The artifact handler.
	 *
	 * @parameter expression="${component.org.apache.maven.artifact.handler.ArtifactHandler#grails-app}"
	 * @required
	 * @readonly
	 */
	protected ArtifactHandler artifactHandler;

	/**
	 * Executes the MavenWarMojo on the current project.
	 *
	 * @throws MojoExecutionException
	 *             if an error occured while building the webapp
	 */
	public void execute() throws MojoExecutionException, MojoFailureException {
		// launch grails
		launchGrails("war");
		File warGeneratedByGrails = new File(getBasedir(),
				getGrailsDescriptor().getAppName() + "-"
						+ getGrailsDescriptor().getAppVersion() + ".war");
		project.getArtifact().setFile(warGeneratedByGrails);
		project.getArtifact().setArtifactHandler(artifactHandler);
	}

}


You have to manually set the file and the artifact handler


Arnaud


http://forge.octo.com/svn/mtg/trunk/grails-maven-plugin/src/main/java/com/octo/mtg/plugin/MavenWarMojo.java


On 01/10/2007, nicolas de loof <ni...@gmail.com> wrote:
>
> I just understood I have to configure the plugin in the build/plugins
> element with <extensions>true</extensions>
>
> What's the meaning of the build/extensions element ?
>
> 2007/10/1, nicolas de loof <ni...@gmail.com>:
> > Hello,
> >
> > I'd like to add support in maven for a custom packaging.
> > I've created a META-INF/plexus/components.xml to define a new
> ArtifactHandler :
> >
> >     <component>
> >       <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
> >       <role-hint>javascript</role-hint>
> >       <implementation>
> org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
> >       <configuration>
> >         <type>javascript</type>
> >         <extension>jsar</extension>
> >         <language>javascript</language>
> >         <addedToClasspath>false</addedToClasspath>
> >       </configuration>
> >     </component>
> >
> > I the run "mvn install" from a test project that has a dependency of
> > type "javascript" and defines my custom plugin as a build extension.
> > The requested URL in my repo uses the unexpected ".javascript"
> > extension.
> >
> > Runing maven in a debug session, in DefaultWagonManager.getArtifact()
> > the requested artifact doens't have my custom handler attached, but
> > what seems to be the default one for unresolved types.
> >
> > Is this the good way to extend maven ? What's wrong ?
> >
> > Nico.
> >
>



-- 
..........................................................
Arnaud HERITIER
..........................................................
OCTO Technology - aheritier AT octo DOT com
www.octo.com | blog.octo.com
..........................................................
ASF - aheritier AT apache DOT org
www.apache.org | maven.apache.org
...........................................................

[resolved] maven extension : adding a custom ArtifactHandler

Posted by nicolas de loof <ni...@gmail.com>.
I just understood I have to configure the plugin in the build/plugins
element with <extensions>true</extensions>

What's the meaning of the build/extensions element ?

2007/10/1, nicolas de loof <ni...@gmail.com>:
> Hello,
>
> I'd like to add support in maven for a custom packaging.
> I've created a META-INF/plexus/components.xml to define a new
ArtifactHandler :
>
>     <component>
>       <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
>       <role-hint>javascript</role-hint>
>       <implementation>
org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
>       <configuration>
>         <type>javascript</type>
>         <extension>jsar</extension>
>         <language>javascript</language>
>         <addedToClasspath>false</addedToClasspath>
>       </configuration>
>     </component>
>
> I the run "mvn install" from a test project that has a dependency of
> type "javascript" and defines my custom plugin as a build extension.
> The requested URL in my repo uses the unexpected ".javascript"
> extension.
>
> Runing maven in a debug session, in DefaultWagonManager.getArtifact()
> the requested artifact doens't have my custom handler attached, but
> what seems to be the default one for unresolved types.
>
> Is this the good way to extend maven ? What's wrong ?
>
> Nico.
>