brett 2005/03/22 04:28:36
Modified: maven-core/src/main/java/org/apache/maven/plugin
DefaultPluginManager.java
Log:
check super classes for fields to set
Revision Changes Path
1.67 +50 -14
maven-components/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
Index: DefaultPluginManager.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- DefaultPluginManager.java 22 Mar 2005 11:29:55 -0000 1.66
+++ DefaultPluginManager.java 22 Mar 2005 12:28:36 -0000 1.67
@@ -385,16 +385,7 @@
plugin.setLog( session.getLog() );
// TODO: remove
- boolean newMojoTechnique = false;
- try
- {
- plugin.getClass().getDeclaredMethod( "execute", new Class[0]
);
- newMojoTechnique = true;
- }
- catch ( NoSuchMethodException e )
- {
- // intentionally ignored
- }
+ boolean newMojoTechnique = checkMojoTechnique( plugin.getClass()
);
// TODO: can probable refactor these a little when only the new
plugin technique is in place
PlexusConfiguration configuration =
getProjectDefinedPluginConfiguration( session.getProject(),
@@ -462,6 +453,30 @@
}
}
+ /**
+ * @deprecated
+ */
+ private static boolean checkMojoTechnique( Class aClass )
+ {
+ boolean newMojoTechnique = false;
+ try
+ {
+ aClass.getDeclaredMethod( "execute", new Class[0] );
+ newMojoTechnique = true;
+ }
+ catch ( NoSuchMethodException e )
+ {
+ // intentionally ignored
+
+ Class superclass = aClass.getSuperclass();
+ if ( superclass != AbstractPlugin.class )
+ {
+ return checkMojoTechnique( superclass );
+ }
+ }
+ return newMojoTechnique;
+ }
+
// TODO: don't throw Exception
private void releaseComponents( MojoDescriptor goal,
PluginExecutionRequest request )
throws Exception
@@ -524,7 +539,7 @@
}
// Configuration does not store objects, so the non-String fields
are configured here
- // TODO: we don't have converters, so something things that -are-
strings are not configured properly (eg String -> File from an expression)
+ // TODO: we don't have converters, so "primitives" that -are-
strings are not configured properly (eg String -> File from an expression)
for ( Iterator i = map.keySet().iterator(); i.hasNext(); )
{
String key = (String) i.next();
@@ -533,7 +548,7 @@
Class clazz = plugin.getClass();
try
{
- Field f = clazz.getDeclaredField( key );
+ Field f = findPluginField( clazz, key );
boolean accessible = f.isAccessible();
if ( !accessible )
{
@@ -547,17 +562,38 @@
f.setAccessible( false );
}
}
- catch ( NoSuchFieldException e1 )
+ catch ( NoSuchFieldException e )
{
throw new PluginConfigurationException( "Unable to set field
'" + key + "' on '" + clazz + "'" );
}
- catch ( IllegalAccessException e11 )
+ catch ( IllegalAccessException e )
{
throw new PluginConfigurationException( "Unable to set field
'" + key + "' on '" + clazz + "'" );
}
}
}
+ private Field findPluginField( Class clazz, String key )
+ throws NoSuchFieldException
+ {
+ try
+ {
+ return clazz.getDeclaredField( key );
+ }
+ catch ( NoSuchFieldException e )
+ {
+ Class superclass = clazz.getSuperclass();
+ if ( superclass != Object.class )
+ {
+ return findPluginField( superclass, key );
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
private Map getPluginConfigurationFromExpressions( MojoDescriptor goal,
PlexusConfiguration configuration,
MavenSession session )
throws PluginConfigurationException