o Allowed plugin to dump plugin configuration

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@785726 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-17 17:03:34 +00:00
parent 9e5a037b4b
commit d0f6936bbc
1 changed files with 47 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -43,6 +44,8 @@ class PropertyUtil
private static final Object[] NO_ARGS = {}; private static final Object[] NO_ARGS = {};
private static final Class[] NO_PARAMS = {};
/** /**
* Serializes the specified object into the given properties, using the provided key. The object may be a scalar * Serializes the specified object into the given properties, using the provided key. The object may be a scalar
* value like a string or some array/collection/map or a bean. * value like a string or some array/collection/map or a bean.
@ -108,7 +111,50 @@ class PropertyUtil
store( props, key + "." + index, elem, visited ); store( props, key + "." + index, elem, visited );
} }
} }
else if ( obj != null ) else if ( obj.getClass().getName().endsWith( "Xpp3Dom" ) )
{
Class type = obj.getClass();
try
{
Method getValue = type.getMethod( "getValue", NO_PARAMS );
String value = (String) getValue.invoke( obj, NO_ARGS );
if ( value != null )
{
props.put( key + ".value", value );
}
Method getName = type.getMethod( "getName", NO_PARAMS );
Method getChildren = type.getMethod( "getChildren", NO_PARAMS );
Object[] children = (Object[]) getChildren.invoke( obj, NO_ARGS );
props.put( key + ".children", Integer.toString( children.length ) );
Map indices = new HashMap();
for ( int i = 0; i < children.length; i++ )
{
Object child = children[i];
String name = (String) getName.invoke( child, NO_ARGS );
Integer index = (Integer) indices.get( name );
if ( index == null )
{
index = new Integer( 0 );
}
store( props, key + ".children." + name + "." + index, child, visited );
indices.put( name, new Integer( index.intValue() + 1 ) );
}
}
catch ( Exception e )
{
// can't happen
}
}
else
{ {
Class type = obj.getClass(); Class type = obj.getClass();
Method[] methods = type.getMethods(); Method[] methods = type.getMethods();