jvanzyl     2004/02/14 09:08:31

  Modified:    maven-core project.xml
               maven-core/src/conf defaults.properties
               maven-core/src/java/org/apache/maven/plugin Plugin.java
               maven-core/src/java/org/apache/maven/plugin/plexus
                        PlexusPluginManager.java
  Log:
  o first prototype of using OGNL to extract parameters for plugin execution
    from the maven project. work in progress.
  
  Revision  Changes    Path
  1.3       +6 -0      maven-components/maven-core/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml       12 Feb 2004 01:59:00 -0000      1.2
  +++ project.xml       14 Feb 2004 17:08:31 -0000      1.3
  @@ -89,6 +89,12 @@
         <version>0.4</version>
       </dependency>
   
  +    <dependency>
  +      <groupId>ognl</groupId>
  +      <artifactId>ognl</artifactId>
  +      <version>2.5.1</version>
  +    </dependency>
  +
       <!-- This will eventually be removed -->
       <dependency>
         <groupId>plexus</groupId>
  
  
  
  1.2       +2 -0      maven-components/maven-core/src/conf/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/conf/defaults.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- defaults.properties       6 Feb 2004 23:27:41 -0000       1.1
  +++ defaults.properties       14 Feb 2004 17:08:31 -0000      1.2
  @@ -10,6 +10,8 @@
   maven.build.src = ${maven.build.dir}/src
   maven.build.dest = ${maven.build.dir}/classes
   
  +maven.test.dest = ${maven.build.dir}/test-classes
  +
   # -------------------------------------------------------------------
   # M A V E N  L O C A L  R E P O 
   # -------------------------------------------------------------------
  
  
  
  1.3       +2 -2      
maven-components/maven-core/src/java/org/apache/maven/plugin/Plugin.java
  
  Index: Plugin.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/java/org/apache/maven/plugin/Plugin.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Plugin.java       12 Feb 2004 19:28:53 -0000      1.2
  +++ Plugin.java       14 Feb 2004 17:08:31 -0000      1.3
  @@ -13,6 +13,6 @@
    */
   public interface Plugin
   {
  -    void execute( MavenProject project, Map parameters )
  +    void execute( Map parameters )
           throws Exception;
   }
  
  
  
  1.4       +135 -2    
maven-components/maven-core/src/java/org/apache/maven/plugin/plexus/PlexusPluginManager.java
  
  Index: PlexusPluginManager.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-core/src/java/org/apache/maven/plugin/plexus/PlexusPluginManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PlexusPluginManager.java  12 Feb 2004 19:28:53 -0000      1.3
  +++ PlexusPluginManager.java  14 Feb 2004 17:08:31 -0000      1.4
  @@ -1,12 +1,17 @@
   package org.apache.maven.plugin.plexus;
   
  +import ognl.Ognl;
  +import ognl.OgnlException;
   import org.apache.maven.GoalException;
   import org.apache.maven.plugin.AbstractPluginManager;
  +import org.apache.maven.plugin.ParameterCollectionException;
   import org.apache.maven.plugin.Plugin;
   import org.apache.maven.project.MavenProject;
   
   import java.util.HashMap;
  +import java.util.Iterator;
   import java.util.Map;
  +import java.io.File;
   
   /**
    *
  @@ -22,14 +27,90 @@
   
       private Map goalToPluginMap;
   
  +    private Map goalParameterMap;
  +
  +    // parameters can be extracted from the MavenProject itself
  +    // or from properties or good old hard coded values.
  +
       public PlexusPluginManager()
       {
           goalToPluginMap = new HashMap();
   
  +        goalParameterMap = new HashMap();
  +
  +        // 
--------------------------------------------------------------------------
  +        // Compile
  +        // 
--------------------------------------------------------------------------
  +        // sourceDirectory = project.build.sourceDirectory
  +        // outputDirectory = project.build.testOutputDirectory
  +        // compiler =
  +        // options
  +
  +        Map compile = new HashMap();
  +
  +        compile.put( "sourceDirectory", "#build.sourceDirectory" );
  +        compile.put( "outputDirectory", "maven.build.dest" );
  +        compile.put( "classpathElements", "#classpathElements" );
  +        compile.put( "compiler", "jikes" );
  +
  +        goalParameterMap.put( "compile", compile );
  +
           goalToPluginMap.put( "compile", "compiler" );
   
  +        // 
--------------------------------------------------------------------------
  +        // Test Compile
  +        // 
--------------------------------------------------------------------------
  +        // sourceDirectory = project.build.testSourceDirectory
  +        // targetDirectory = project.build.testOutputDirectory
  +        // compiler =
  +        // options
  +
  +        Map testCompile = new HashMap();
  +
  +        testCompile.put( "sourceDirectory", "#build.unitTestSourceDirectory" );
  +        testCompile.put( "outputDirectory", "maven.test.dest" );
  +        testCompile.put( "classpathElements", "#classpathElements" );
  +        testCompile.put( "compiler", "jikes" );
  +
  +        goalParameterMap.put( "test:compile", testCompile );
  +
  +        goalToPluginMap.put( "test:compile", "compiler" );
  +
  +        // 
--------------------------------------------------------------------------
  +        // Jar
  +        // 
--------------------------------------------------------------------------
  +        // jarName
  +        // basedir
  +
  +        Map jar = new HashMap();
  +
  +        jar.put( "jarName", "maven.final.name" );
  +        jar.put( "outputDirectory", "maven.build.dir" );
  +        jar.put( "basedir", "maven.build.dest" );
  +        jar.put( "project", "project" );
  +
  +        goalParameterMap.put( "jar", jar );
  +
           goalToPluginMap.put( "jar", "jar" );
   
  +        // 
--------------------------------------------------------------------------
  +        // Test
  +        // 
--------------------------------------------------------------------------
  +        // mavenRepoLocal
  +        // basedir
  +        // includes
  +        // excludes
  +
  +        Map surefire = new HashMap();
  +
  +        surefire.put( "mavenRepoLocal", "maven.repo.local" );
  +        surefire.put( "basedir", "basedir" );
  +        surefire.put( "includes", "#build.unitTest.includes" );
  +        surefire.put( "excludes", "#build.unitTest.excludes" );
  +        surefire.put( "classpathElements", "#classpathElements" );
  +
  +        goalParameterMap.put( "test", surefire );
  +
           goalToPluginMap.put( "test", "surefire" );
       }
   
  @@ -42,10 +123,62 @@
   
           // Now this brings up the question of where do the parameters come from?
   
  +        Map parameters = collectParameters( goal, project );
  +
  +        System.out.println( "parameters = " + parameters );
  +
  +        plugin.execute( parameters );
  +    }
  +
  +    private Map collectParameters( String goal, MavenProject project )
  +        throws ParameterCollectionException
  +    {
  +        Map goalParameters = (Map) goalParameterMap.get( goal );
  +
           Map parameters = new HashMap();
   
  -        plugin.execute( project, parameters );
  +        for ( Iterator i = goalParameters.keySet().iterator(); i.hasNext(); )
  +        {
  +            String key = (String) i.next();
  +
  +            String keyValue = (String) goalParameters.get( key );
  +
  +            System.out.println( "keyValue = " + keyValue );
  +
  +            Object value;
  +
  +            if ( keyValue.startsWith( "#" ) )
  +            {
  +                try
  +                {
  +                    value = Ognl.getValue( keyValue.substring( 1 ), project );
  +                }
  +                catch ( OgnlException e )
  +                {
  +                    throw new ParameterCollectionException(
  +                        "Error trying to extract parameter from the project using: 
" + key, e );
  +                }
  +            }
  +            else if ( keyValue.equals( "project" ) )
  +            {
  +                value = project;
  +            }
  +            else
  +            {
  +                value = project.getProperty( keyValue );
  +            }
  +
  +            if ( value == null )
  +            {
  +                value = keyValue;
  +            }
  +
  +            parameters.put( key, value );
  +        }
  +
  +        return parameters;
       }
  +
   
       public void loadPlugin( String name )
           throws Exception
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to