Hi,
I have a question related to the defining of a plugin parameter within a
Mojo. Say for brevity something simple:
@Parameter
private String theValue;
During the build of my plugin maven-plugin-plugin will create a plugin
descriptor (plugin.xml) which contains the parameter definition etc.
So now I will use this in my pom:
<configuration>
<theValue>This it is</theValue>
</configuration>
If i run the build with this plugin the plugin will be loaded by Maven
Core by using the plugin.xml to know which class to instantiate (etc.)
during this instantiation the parameters will be injected into the mojo
instance.
So far so good. But now the following will be done in the pom file:
<configuration>
<theValue>This it is</theValue>
<theValue>This is the second value</theValue>
</configuration>
I can see that the result of this is that of course only one value will
be taken and injected into the mojo parameter...
The question is could this being detected and maybe produce a warning,
cause it does not make sense...
Can someone give a little hint where to start searching in Maven Core ?
From within a plugin it's a hard job to detect such things.
I have played a little bit around:
@Parameter( defaultValue = "${plugin}" )
private PluginDescriptor plugin;
....
Map<String, Plugin> pluginsAsMap =
getMavenProject().getOriginalModel().getBuild().getPluginsAsMap();
Plugin pluginFromMap = pluginsAsMap.get( plugin.getPluginLookupKey() );
Xpp3Dom dom = (Xpp3Dom) pluginFromMap.getConfiguration();
Xpp3Dom[] children = dom.getChildren();
for(int i=0; i<children.length; i++) {
getLog().info( "Child[" + i + "]=" + children[i].getName() + "
v:" + children[i].getValue() );
}
So now based on the Xpp3Dom I could build something which could detected
such situation...but from my point very inconvenient..
The whole story is related to the issue[1]. which also gives a more
complex part...which I'm not sure if it makes sense:
@Parameter
private List<String> theValues;
@Parameter
private String theValue;
So in cases where you use mutliple times "theValue" there should be hint
to use the list variant instead...
<configuration>
<theValue>1</theValue>
<theValue>2</theValue>
</configuration>
This could produce a warning like "Better use
<theValues><theValue>1</theValue></theValues>"...(Came into my mind)..
Maybe no that simple to implement?
Kind regards
Karl Heinz Marbaise
[1]: https://issues.apache.org/jira/browse/MNG-6227
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org