You are viewing a plain text version of this content. The canonical link for it is here.
Posted to m2-dev@maven.apache.org by br...@apache.org on 2005/03/21 04:49:17 UTC

cvs commit: maven-components/maven-plugin/src/main/java/org/apache/maven/plugin AbstractPlugin.java

brett       2005/03/20 19:49:17

  Modified:    maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean
                        CleanPlugin.java
               maven-core/src/main/java/org/apache/maven/plugin
                        DefaultPluginManager.java
               maven-plugin/src/main/java/org/apache/maven/plugin
                        AbstractPlugin.java
  Log:
  most basic of field based plugins
  
  Revision  Changes    Path
  1.5       +47 -53    maven-components/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java
  
  Index: CleanPlugin.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/clean/CleanPlugin.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CleanPlugin.java	21 Mar 2005 00:07:38 -0000	1.4
  +++ CleanPlugin.java	21 Mar 2005 03:49:17 -0000	1.5
  @@ -17,26 +17,21 @@
    */
   
   import org.apache.maven.plugin.AbstractPlugin;
  -import org.apache.maven.plugin.PluginExecutionRequest;
  -import org.apache.maven.plugin.PluginExecutionResponse;
  +import org.apache.maven.plugin.PluginExecutionException;
   
   import java.io.File;
   
   /**
  - * @goal clean
  - *
  - * @description Goal which cleans the build
  - *
  - * @parameter
  - *  name="outputDirectory"
  - *  type="String"
  - *  required="true"
  - *  validator=""
  - *  expression="#project.build.directory"
  - *  description=""
  - *
    * @author <a href="mailto:evenisse@maven.org">Emmanuel Venisse</a>
    * @version $Id$
  + * @goal clean
  + * @description Goal which cleans the build
  + * @parameter name="outputDirectory"
  + * type="String"
  + * required="true"
  + * validator=""
  + * expression="#project.build.directory"
  + * description=""
    */
   public class CleanPlugin
       extends AbstractPlugin
  @@ -45,34 +40,33 @@
   
       private String outputDirectory;
   
  -    private boolean failOnError;
  +    // TODO: not in the descriptor previously
  +//    private boolean failOnError;
  +    public boolean supportsNewMojoParadigm()
  +    {
  +        return true;
  +    }
   
  -    public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
  -        throws Exception
  +    public void execute()
  +        throws PluginExecutionException
       {
  -        try
  +        if ( outputDirectory != null )
           {
  -            outputDirectory = (String) request.getParameter( "outputDirectory" );
  +            File dir = new File( outputDirectory );
   
  -            failOnError = Boolean.valueOf( (String) request.getParameter( "failedOnError" ) ).booleanValue();
  -            
  -            if ( outputDirectory != null )
  +            if ( dir.exists() && dir.isDirectory() )
               {
  -                File dir = new File( outputDirectory );
  -
  -                if ( dir.exists() && dir.isDirectory() )
  +                getLog().info( "Deleting directory " + dir.getAbsolutePath() );
  +                try
                   {
  -                    getLog().info( "Deleting directory " + dir.getAbsolutePath() );
                       removeDir( dir );
                   }
  +                catch ( Exception e )
  +                {
  +                    throw new PluginExecutionException( "Unable to delete directory", e );
  +                }
               }
           }
  -        finally
  -        {
  -            // clean up state.
  -            failOnError = false;
  -            outputDirectory = null;
  -        }
       }
   
       /**
  @@ -106,7 +100,8 @@
        *
        * @param d the directory to delete
        */
  -    protected void removeDir( File d ) throws Exception
  +    protected void removeDir( File d )
  +        throws Exception
       {
           String[] list = d.list();
           if ( list == null )
  @@ -123,35 +118,34 @@
               }
               else
               {
  -                //log("Deleting " + f.getAbsolutePath());
                   if ( !delete( f ) )
                   {
  -                    String message = "Unable to delete file "
  -                        + f.getAbsolutePath();
  -                    if ( failOnError )
  -                    {
  -                        throw new Exception( message );
  -                    }
  -                    else
  -                    {
  +                    String message = "Unable to delete file " + f.getAbsolutePath();
  +// TODO:...
  +//                    if ( failOnError )
  +//                    {
  +//                        throw new Exception( message );
  +//                    }
  +//                    else
  +//                    {
                           getLog().info( message );
  -                    }
  +//                    }
                   }
               }
           }
  -        //log("Deleting directory " + d.getAbsolutePath());
  +
           if ( !delete( d ) )
           {
  -            String message = "Unable to delete directory "
  -                + d.getAbsolutePath();
  -            if ( failOnError )
  -            {
  -                throw new Exception( message );
  -            }
  -            else
  -            {
  +            String message = "Unable to delete directory " + d.getAbsolutePath();
  +// TODO:...
  +//            if ( failOnError )
  +//            {
  +//                throw new Exception( message );
  +//            }
  +//            else
  +//            {
                   getLog().info( message );
  -            }
  +//            }
           }
       }
   
  
  
  
  1.61      +53 -6     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.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- DefaultPluginManager.java	21 Mar 2005 01:02:36 -0000	1.60
  +++ DefaultPluginManager.java	21 Mar 2005 03:49:17 -0000	1.61
  @@ -56,6 +56,7 @@
   import org.codehaus.plexus.util.StringUtils;
   import org.codehaus.plexus.util.dag.CycleDetectedException;
   
  +import java.lang.reflect.Field;
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.HashSet;
  @@ -382,7 +383,7 @@
   
               if ( plugin.supportsNewMojoParadigm() )
               {
  -                // TODO: construct request
  +                populateParameters( plugin, mojoDescriptor, session );
               }
               else
               {
  @@ -468,6 +469,52 @@
       // Mojo Parameter Handling
       // ----------------------------------------------------------------------
   
  +    private void populateParameters( Plugin plugin, MojoDescriptor mojoDescriptor, MavenSession session )
  +        throws PluginConfigurationException
  +    {
  +        // TODO: merge eventually, just to avoid reuse
  +        // TODO: probably want to use the plexus component configurator... then do the additional processing in
  +        //  createParameters afterwards. Not sure how we might find files that are nested in other objects... perhaps
  +        //  we add a "needs translation" to the mojo so such types can be translated (implementing some interface) and
  +        //  address their own file objects
  +        Map values = createParameters( mojoDescriptor, session );
  +
  +        List parameters = mojoDescriptor.getParameters();
  +
  +        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
  +            {
  +                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 )
  +            {
  +                throw new PluginConfigurationException( "Unable to set field '" + name + "' on '" + clazz + "'" );
  +            }
  +            catch ( IllegalAccessException e )
  +            {
  +                throw new PluginConfigurationException( "Unable to set field '" + name + "' on '" + clazz + "'" );
  +            }
  +        }
  +    }
  +
       public Map createParameters( MojoDescriptor goal, MavenSession session )
           throws PluginConfigurationException
       {
  @@ -664,12 +711,12 @@
       private void downloadDependencies( MavenSession context, ArtifactResolver artifactResolver )
           throws ArtifactResolutionException
       {
  -            for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); )
  -            {
  -                Artifact artifact = (Artifact) it.next();
  +        for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); )
  +        {
  +            Artifact artifact = (Artifact) it.next();
   
  -                artifactResolver.resolve( artifact, context.getRemoteRepositories(), context.getLocalRepository() );
  -            }
  +            artifactResolver.resolve( artifact, context.getRemoteRepositories(), context.getLocalRepository() );
  +        }
       }
   
   }
  
  
  
  1.6       +9 -3      maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/AbstractPlugin.java
  
  Index: AbstractPlugin.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/AbstractPlugin.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractPlugin.java	21 Mar 2005 01:02:36 -0000	1.5
  +++ AbstractPlugin.java	21 Mar 2005 03:49:17 -0000	1.6
  @@ -55,8 +55,12 @@
       /**
        * @deprecated
        */
  -    public abstract void execute( PluginExecutionRequest request, PluginExecutionResponse response )
  -        throws Exception;
  +    public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
  +        throws Exception
  +    {
  +        throw new UnsupportedOperationException(
  +            "If you are using the old technioque, you must override execute(req,resp)" );
  +    }
   
       public void setLog( Log log )
       {
  @@ -80,7 +84,9 @@
           throws PluginExecutionException
       {
           if ( supportsNewMojoParadigm() )
  +        {
               throw new PluginExecutionException( "You must override execute() if you implement the new paradigm" );
  +        }
       }
   
       public boolean supportsNewMojoParadigm()