Resolving: MNG-496

o Adding extraction of mojo-specific configuration from the merged config for the plugin
o Warning at the DEBUG log-level for unused plugin configuration during the extraction process above
o Added integration test it0028 to test with unused plugin configuration present.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191552 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-06-20 20:11:01 +00:00
parent 9aaca6a72d
commit d7e421fd01
8 changed files with 103 additions and 2 deletions

View File

@ -84,6 +84,10 @@ it0025: Test multiple goal executions with different execution-level configs.
it0026: Test merging of global- and user-level settings.xml files. it0026: Test merging of global- and user-level settings.xml files.
it0027: Test @execute with a custom lifecycle, including configuration it0027: Test @execute with a custom lifecycle, including configuration
it0028: Test that unused configuration parameters from the POM don't cause the
mojo to fail...they will show up as warnings in the -X output instead.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
- generated sources - generated sources

View File

@ -1,3 +1,4 @@
it0028
#Cannot find core-it:fork... #Cannot find core-it:fork...
#it0027 #it0027
it0026 it0026

View File

@ -0,0 +1 @@
target/classes/org/apache/maven/it0001/Person.class

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1,29 @@
<model>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core-it0028</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.4</source>
<target>1.4</target>
<unused>something</unused>
</configuration>
</plugin>
</plugins>
</build>
</model>

View File

@ -0,0 +1,18 @@
package org.apache.maven.it0001;
public class Person
{
private String name;
public void setName( String name )
{
this.name = name;
assert true;
}
public String getName()
{
return name;
}
}

View File

@ -0,0 +1,16 @@
package org.apache.maven.it0001;
import junit.framework.TestCase;
public class PersonTest
extends TestCase
{
public void testPerson()
{
Person person = new Person();
person.setName( "foo" );
assertEquals( "foo", person.getName() );
}
}

View File

@ -551,12 +551,41 @@ public class DefaultPluginManager
pathTranslator, getLogger(), pathTranslator, getLogger(),
project ); project );
checkRequiredParameters( mojoDescriptor, mergedConfiguration, expressionEvaluator, plugin ); PlexusConfiguration extractedMojoConfiguration = extractMojoConfiguration( mergedConfiguration, mojoDescriptor );
populatePluginFields( plugin, mojoDescriptor, mergedConfiguration, pluginContainer, expressionEvaluator ); checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator, plugin );
populatePluginFields( plugin, mojoDescriptor, extractedMojoConfiguration, pluginContainer, expressionEvaluator );
return plugin; return plugin;
} }
private PlexusConfiguration extractMojoConfiguration( PlexusConfiguration mergedConfiguration, MojoDescriptor mojoDescriptor )
{
Map parameterMap = mojoDescriptor.getParameterMap();
PlexusConfiguration[] mergedChildren = mergedConfiguration.getChildren();
XmlPlexusConfiguration extractedConfiguration = new XmlPlexusConfiguration( "configuration" );
for ( int i = 0; i < mergedChildren.length; i++ )
{
PlexusConfiguration child = mergedChildren[i];
if ( parameterMap.containsKey( child.getName() ) )
{
extractedConfiguration.addChild( DefaultPluginManager.copyConfiguration( child ) );
}
else
{
// TODO: I defy anyone to find these messages in the '-X' output! Do we need a new log level?
// ideally, this would be elevated above the true debug output, but below the default INFO level...
getLogger().debug( "*** WARNING: Configuration \'" + child.getName() + "\' is not used in goal \'" + mojoDescriptor.getFullGoalName() + "; this may indicate a typo... ***");
}
}
return extractedConfiguration;
}
private void checkRequiredParameters( MojoDescriptor goal, PlexusConfiguration configuration, private void checkRequiredParameters( MojoDescriptor goal, PlexusConfiguration configuration,
ExpressionEvaluator expressionEvaluator, Mojo plugin ) ExpressionEvaluator expressionEvaluator, Mojo plugin )
throws PluginConfigurationException throws PluginConfigurationException
@ -758,6 +787,8 @@ public class DefaultPluginManager
String configuratorId = mojoDescriptor.getComponentConfigurator(); String configuratorId = mojoDescriptor.getComponentConfigurator();
// TODO: should this be known to the component factory instead? And if so, should configuration be part of lookup? // TODO: should this be known to the component factory instead? And if so, should configuration be part of lookup?
// [jc]: I don't think we can be that strict with the configurator. It makes some measure of sense that
// people may want different configurators for their java mojos...
if ( StringUtils.isNotEmpty( configuratorId ) ) if ( StringUtils.isNotEmpty( configuratorId ) )
{ {
configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE, configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE,