You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Ian Brandt <ia...@ianbrandt.com> on 2012/06/20 01:41:18 UTC

Re: Custom type converter for Mojo configuration?

I too would like to know if it is possible for plugins to define custom converters for <configuration> handling.

I notice the maven-toolchain-plugin seems to be doing something along these lines:

http://svn.apache.org/viewvc/maven/plugins/tags/maven-toolchains-plugin-1.0/src/main/resources/META-INF/plexus/components.xml?view=markup

http://svn.apache.org/viewvc/maven/plugins/tags/maven-toolchains-plugin-1.0/src/main/java/org/apache/maven/plugin/toolchain/ToolchainConverter.java?view=markup

Is this acceptable public API?

The Maven Dependency Plugin takes <includes> and <excludes> as a comma separated list of patterns that map to String.  Most other Maven plugins seem to use a collection (e.g. String[]) and nested <include>/<exclude> elements.  With a custom ConfigurationConverter the plugin could be extended to accept both formats:

<includes>one/**,two/**</includes>

...and...

<includes>
	<include>one/**</include>
	<include>two/**</include>
</includes>

This would maintain backwards compatibility, and be arguably more elegant than introducing new parameters such as <includesList>/<excludesList>.  With the additional parameters you'd have to define what happens when both versions are present.  Would you throw an exception, ignore one, or merge them in some order of precedence? I'd think it better to just avoid the issue.

Ian


On Apr 18, 2012, at 12:33 AM, Xie Jilei wrote:

> (From: http://stackoverflow.com/questions/10188534/)
> 
> I need to use custom type, e.g., `LunarDate`, in my Mojo object:
> 
>    class MyMojo extends AbstractMojo {
> 
>        /** @parameter */
>        LunarDate lunarDate;
> 
>    }
> 
> And I want to configure the parameter in `<configuration>` section in
> pom.xml.
> 
>    <configuration>
>         <lunarDate>丁丑年二月初四</lunarDate>
>    </configuration>
> 
> (The type `LunarDate` is just an example to illustrate the question)
> 
> I've already had the type converters, but how to enable them?


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