mirror of https://github.com/apache/maven.git
hack in a dom so we can use plexus configuration. more to do...
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
28e193d14c
commit
3bd980bdb1
|
@ -43,10 +43,14 @@ import org.apache.maven.settings.MavenSettingsBuilder;
|
||||||
import org.codehaus.plexus.ArtifactEnabledContainer;
|
import org.codehaus.plexus.ArtifactEnabledContainer;
|
||||||
import org.codehaus.plexus.PlexusConstants;
|
import org.codehaus.plexus.PlexusConstants;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
|
import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
|
||||||
|
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
|
||||||
|
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
|
||||||
import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
|
import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
|
||||||
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
|
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
|
||||||
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
|
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
|
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
|
||||||
import org.codehaus.plexus.context.Context;
|
import org.codehaus.plexus.context.Context;
|
||||||
import org.codehaus.plexus.context.ContextException;
|
import org.codehaus.plexus.context.ContextException;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
|
@ -55,6 +59,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||||
import org.codehaus.plexus.util.CollectionUtils;
|
import org.codehaus.plexus.util.CollectionUtils;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||||
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -493,37 +498,60 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
List parameters = mojoDescriptor.getParameters();
|
List parameters = mojoDescriptor.getParameters();
|
||||||
|
|
||||||
|
Xpp3Dom dom = new Xpp3Dom( mojoDescriptor.getId() );
|
||||||
|
|
||||||
for ( Iterator i = parameters.iterator(); i.hasNext(); )
|
for ( Iterator i = parameters.iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
Parameter param = (Parameter) i.next();
|
Parameter param = (Parameter) i.next();
|
||||||
String name = param.getName();
|
String name = param.getName();
|
||||||
Object value = values.get( name );
|
Object value = values.get( name );
|
||||||
|
|
||||||
Class clazz = plugin.getClass();
|
// TODO:Still not complete robust - need to merge in the processing in createParameters
|
||||||
try
|
if ( value instanceof String )
|
||||||
{
|
{
|
||||||
Field f = clazz.getDeclaredField( name );
|
Xpp3Dom d = new Xpp3Dom( name );
|
||||||
boolean accessible = f.isAccessible();
|
d.setValue( (String) value );
|
||||||
if ( !accessible )
|
dom.addChild( d );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Class clazz = plugin.getClass();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
f.setAccessible( true );
|
Field f = clazz.getDeclaredField( name );
|
||||||
|
boolean accessible = f.isAccessible();
|
||||||
|
if ( !accessible )
|
||||||
|
{
|
||||||
|
f.setAccessible( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
f.set( plugin, value );
|
||||||
|
|
||||||
|
if ( !accessible )
|
||||||
|
{
|
||||||
|
f.setAccessible( false );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch ( NoSuchFieldException e )
|
||||||
f.set( plugin, value );
|
|
||||||
|
|
||||||
if ( !accessible )
|
|
||||||
{
|
{
|
||||||
f.setAccessible( false );
|
throw new PluginConfigurationException( "Unable to set field '" + name + "' on '" + clazz + "'" );
|
||||||
|
}
|
||||||
|
catch ( IllegalAccessException e )
|
||||||
|
{
|
||||||
|
throw new PluginConfigurationException( "Unable to set field '" + name + "' on '" + clazz + "'" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( NoSuchFieldException e )
|
}
|
||||||
{
|
|
||||||
throw new PluginConfigurationException( "Unable to set field '" + name + "' on '" + clazz + "'" );
|
// TODO: should be a component
|
||||||
}
|
ComponentConfigurator configurator = new BasicComponentConfigurator();
|
||||||
catch ( IllegalAccessException e )
|
try
|
||||||
{
|
{
|
||||||
throw new PluginConfigurationException( "Unable to set field '" + name + "' on '" + clazz + "'" );
|
configurator.configureComponent( plugin, new XmlPlexusConfiguration( dom ) );
|
||||||
}
|
}
|
||||||
|
catch ( ComponentConfigurationException e )
|
||||||
|
{
|
||||||
|
throw new PluginConfigurationException( "Unable to parse the created DOM for plugin configuration", e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue