You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ansgar Konermann <an...@googlemail.com> on 2011/04/03 06:48:16 UTC

How to define file extension and packaging in component.xml? DefaultArtifactHandler does not work?

Hi,

I'm creating a plugin for Maven (3.0.3) which is to provide a custom 
packaging type to compile drools rules and would like to assign a custom 
file extension to the generated artifact. However I got stuck:
- the generated file extension corresponds to the type given to the 
ArtifactHandler (or even to the role hint, they are the same in my 
case), but this is way too long for a file extension
- I cannot use the specified <packaging> identifier in my test poms 
(Maven complains: "unknown packaging")

Here are some source code snippets:

components.xml:
https://github.com/ansgarkonermann/maven-drools-plugin/blob/47cb8704f00fb8d1f4b8bff9cc5bb445a8bd2c85/maven-drools-plugin/src/main/resources/META-INF/plexus/components.xml

example pom.xml:
https://github.com/ansgarkonermann/maven-drools-plugin/blob/47cb8704f00fb8d1f4b8bff9cc5bb445a8bd2c85/maven-drools-plugin/src/test/resources/de/lightful/maven/plugins/drools/integrationtests/can_compile_single_file/pom.xml

CompileMojo.java:
https://github.com/ansgarkonermann/maven-drools-plugin/blob/47cb8704f00fb8d1f4b8bff9cc5bb445a8bd2c85/maven-drools-plugin/src/main/java/de/lightful/maven/plugins/drools/mojos/CompileMojo.java

Does someone have a pointer to a good explanation of what an 
ArtifactHandler is supposed to do, and how it should be used? The 
javadoc of interface ArtifactHandler is empty, unfortunately.

In particular, I'd like to know:
- does the <role-hint> in components.xml have any meaning besides 
helping with dependency injection of components which share the same 
interface? Will a role-hint ever appear in a pom.xml to specify the 
<packaging>?
- is it possible to define the string I have to use in a pom to specify 
the <packaging> by using the <packaging> element/attribute of a 
DefaultArtifactHandler?
- which roles do all the other attributes of DefaultArtifactHandler play?
- are there any "well known resources" which I should read before 
continuing plugin development (besides the source code itself, which is 
what I'd like to prevent)? I could not find much in-depth description 
regarding the inner workings of maven in the well-known book "Maven: The 
Complete Reference" and the JavaDoc seem patchy.

I'd be very glad if someone could push me into the right direction.

Thanks in advance

Ansgar


Re: How to define file extension and packaging in component.xml? DefaultArtifactHandler does not work?

Posted by Manfred Moser <ma...@mosabuam.com>.
I dont have any answers but for reference you could have a look at the
Maven Android Plugin. It adds new packaging types and works great..

manfred



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


Re: How to define file extension and packaging in component.xml? DefaultArtifactHandler does not work?

Posted by Ansgar Konermann <an...@googlemail.com>.
On 04.04.2011 09:58, Peter Schmidt wrote:
>
> That is the key, the "role-hint" is  your packaging type. See also section
> 11.6.3 [1]. I'm not a maven expert, but i would assume that helps maven to
> find the ArtifactHandler and LifecycleMapping for a custom packaging type.
>
> The javascript-maven-tools plugin also defines a custom packaging type, You
> should take a look at it, here is a fork on github [2].
>
> [1]
> http://www.sonatype.com/books/mvnref-book/reference/writing-plugins-sect-plugins-lifecycle.html
> [2]
> https://github.com/harlanji/javascript-maven-tools/blob/master/javascript-maven-plugin/src/main/resources/META-INF/plexus/components.xml
>
>    

Hi Peter,

thanks a lot for this clear reference. I found a few components.xml 
files from various other plugins which also define a 
DefaultArtifactHandler in addition to a LifecycleMapping. These 
DefaultArtifactHandlers commonly have properties like <type>, 
<extension> and <packaging>. Do you or someone else know what an 
ArtifactHandler is supposed to do, and what all the properties are 
supposed to mean?

Thanks in advance

Ansgar


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


Re: How to define file extension and packaging in component.xml? DefaultArtifactHandler does not work?

Posted by Peter Schmidt <ge...@gmail.com>.
On Sun, Apr 3, 2011 at 2:34 PM, Ansgar Konermann <
ansgar.konermann@googlemail.com> wrote:

>
> Interestingly, if I change all occurrences of "drools-knowledge-module" in
> the components.xml into "dkm" and use <packaging>dkm</packaging> in my poms,
> the plugin works okay. Do I have to use the string specified as <role-hint>
> when I specify my packaging type in the POM?
>

That is the key, the "role-hint" is  your packaging type. See also section
11.6.3 [1]. I'm not a maven expert, but i would assume that helps maven to
find the ArtifactHandler and LifecycleMapping for a custom packaging type.

The javascript-maven-tools plugin also defines a custom packaging type, You
should take a look at it, here is a fork on github [2].

[1]
http://www.sonatype.com/books/mvnref-book/reference/writing-plugins-sect-plugins-lifecycle.html
[2]
https://github.com/harlanji/javascript-maven-tools/blob/master/javascript-maven-plugin/src/main/resources/META-INF/plexus/components.xml

Re: How to define file extension and packaging in component.xml? DefaultArtifactHandler does not work?

Posted by Ansgar Konermann <an...@googlemail.com>.
On 03.04.2011 09:18, Stephen Connolly wrote:
> when you add the plugins defining the lifecycle you need to add
> the<extension>true</extension>  to the plugin. and you have to add the plugin
> for a custom lifecycle
>    

Hi Stephen,

thank you for helping out.

In the pom.xml of integration tests, I have:

<build>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<extensions>true</extensions>
<dependencies>
<!-- ... -->
</build>

So the <extensions>true</extensions> is already in.

I'm not so sure what you mean by "you have to add the plugin for a 
custom lifecycle". In my components.xml, there is a custom lifecycle 
_mapping_:

<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>drools-knowledge-module</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<phases>
<!--<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>-->
<compile>de.lightful.maven.plugins:maven-drools-plugin:compile</compile>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
</configuration>
</component>
</components>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>drools-knowledge-module</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
       <type>drools-knowledge-module</type>
       <extension>dkm</extension>
<packaging>schlumpf</packaging>
<language>drools</language>
<includesDependencies>false</includesDependencies>
<addedToClasspath>false</addedToClasspath>
</configuration>
</component>
</component-set>


I also have a lifecycles.xml with a custom lifecycle, but as I don't 
trigger that lifecycle anywhere (yet), it should not (?) pose any 
problems. The CompileMojo has only two AnnoMojo annotations:

@MojoGoal(CompileMojo.GOAL)
@MojoRequiresDependencyResolution("runtime")
public class CompileMojo extends AbstractMojo {

public static final String GOAL = "compile";

// ...

Interestingly, if I change all occurrences of "drools-knowledge-module" 
in the components.xml into "dkm" and use <packaging>dkm</packaging> in 
my poms, the plugin works okay. Do I have to use the string specified as 
<role-hint> when I specify my packaging type in the POM?

What am I missing?


Best regards

Ansgar

Re: How to define file extension and packaging in component.xml? DefaultArtifactHandler does not work?

Posted by Stephen Connolly <st...@gmail.com>.
when you add the plugins defining the lifecycle you need to add
the<extension>true</extension> to the plugin. and you have to add the plugin
for a custom lifecycle

- Stephen

---
Sent from my Android phone, so random spelling mistakes, random nonsense
words and other nonsense are a direct result of using swype to type on the
screen
On 3 Apr 2011 05:48, "Ansgar Konermann" <an...@googlemail.com>
wrote: