brett       2005/03/20 23:23:08

  Modified:    maven-core/src/main/java/org/apache/maven/plugin
                        DefaultPluginManager.java
  Log:
  hack in a dom so we can use plexus configuration. more to do...
  
  Revision  Changes    Path
  1.63      +46 -18    
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.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- DefaultPluginManager.java 21 Mar 2005 04:00:46 -0000      1.62
  +++ DefaultPluginManager.java 21 Mar 2005 07:23:07 -0000      1.63
  @@ -43,10 +43,14 @@
   import org.codehaus.plexus.ArtifactEnabledContainer;
   import org.codehaus.plexus.PlexusConstants;
   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.ComponentDiscoveryListener;
   import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
   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.ContextException;
   import org.codehaus.plexus.logging.AbstractLogEnabled;
  @@ -55,6 +59,7 @@
   import org.codehaus.plexus.util.CollectionUtils;
   import org.codehaus.plexus.util.StringUtils;
   import org.codehaus.plexus.util.dag.CycleDetectedException;
  +import org.codehaus.plexus.util.xml.Xpp3Dom;
   
   import java.lang.reflect.Field;
   import java.util.ArrayList;
  @@ -493,37 +498,60 @@
   
           List parameters = mojoDescriptor.getParameters();
   
  +        Xpp3Dom dom = new Xpp3Dom( mojoDescriptor.getId() );
  +
           for ( Iterator i = parameters.iterator(); i.hasNext(); )
           {
               Parameter param = (Parameter) i.next();
               String name = param.getName();
               Object value = values.get( name );
   
  -            Class clazz = plugin.getClass();
  -            try
  +            // TODO:Still not complete robust - need to merge in the 
processing in createParameters
  +            if ( value instanceof String )
  +            {
  +                Xpp3Dom d = new Xpp3Dom( name );
  +                d.setValue( (String) value );
  +                dom.addChild( d );
  +            }
  +            else
               {
  -                Field f = clazz.getDeclaredField( name );
  -                boolean accessible = f.isAccessible();
  -                if ( !accessible )
  +                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 );
  +                    f.set( plugin, value );
   
  -                if ( !accessible )
  +                    if ( !accessible )
  +                    {
  +                        f.setAccessible( false );
  +                    }
  +                }
  +                catch ( NoSuchFieldException e )
                   {
  -                    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 + "'" );
  -            }
  -            catch ( IllegalAccessException e )
  -            {
  -                throw new PluginConfigurationException( "Unable to set field 
'" + name + "' on '" + clazz + "'" );
  -            }
  +        }
  +
  +        // TODO: should be a component
  +        ComponentConfigurator configurator = new 
BasicComponentConfigurator();
  +        try
  +        {
  +            configurator.configureComponent( plugin, new 
XmlPlexusConfiguration( dom ) );
  +        }
  +        catch ( ComponentConfigurationException e )
  +        {
  +            throw new PluginConfigurationException( "Unable to parse the 
created DOM for plugin configuration", e );
           }
       }
   
  
  
  

Reply via email to