jvanzyl     2004/05/26 18:58:26

  Modified:    maven-plugin/src/main/java/org/apache/maven/plugin
                        PluginExecutionRequest.java
               maven-plugin/src/main/java/org/apache/maven/plugin/generator
                        AbstractGenerator.java BeanGenerator.java Main.java
                        PluginDescriptorGenerator.java
                        PluginXdocGenerator.java
               maven-plugin/src/main/java/org/apache/maven/plugin/generator/jelly
                        JellyHarnessGenerator.java
               maven-plugin/src/test/resources/source IdeaPlugin.java
  Added:       maven-plugin/src/test/java/org/apache/maven/plugin/generator
                        BeanGeneratorTest.java
  Removed:     maven-plugin/src/main/java/org/apache/maven/plugin/generator
                        BeanPluginGenerator.java
               maven-plugin/src/test/java/org/apache/maven/plugin/generator
                        BeanPluginGeneratorTest.java
  Log:
  o leave control over the destination entirely up to the generator
  
  Revision  Changes    Path
  1.2       +1 -13     
maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/PluginExecutionRequest.java
  
  Index: PluginExecutionRequest.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/PluginExecutionRequest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PluginExecutionRequest.java       16 May 2004 04:25:16 -0000      1.1
  +++ PluginExecutionRequest.java       27 May 2004 01:58:26 -0000      1.2
  @@ -29,8 +29,6 @@
   
       private Map context;
   
  -    private Object plugin;
  -
       public PluginExecutionRequest( Map parameters )
       {
           context = new HashMap();
  @@ -61,15 +59,5 @@
       public Object getContextValue( String key )
       {
           return context.get( key );
  -    }
  -
  -    public void setPlugin( Object plugin )
  -    {
  -        this.plugin = plugin;
  -    }
  -
  -    public Object getPlugin()
  -    {
  -        return plugin;
       }
   }
  
  
  
  1.4       +2 -6      
maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/AbstractGenerator.java
  
  Index: AbstractGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/AbstractGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractGenerator.java    22 May 2004 02:46:03 -0000      1.3
  +++ AbstractGenerator.java    27 May 2004 01:58:26 -0000      1.4
  @@ -29,11 +29,9 @@
   
       public static final String MAVEN_PLUGIN_MODE = "maven.plugin.mode";
   
  -    protected abstract void writePluginArtifact( PluginDescriptor pluginDescriptor, 
File destination )
  +    protected abstract void writePluginArtifact( PluginDescriptor pluginDescriptor, 
String destinationDirectory )
           throws Exception;
   
  -    protected abstract String pluginArtifactName( PluginDescriptor pluginDescriptor 
);
  -
       public void execute( String sourceDirectory, String destinationDirectory )
           throws Exception
       {
  @@ -53,9 +51,7 @@
               {
                   PluginDescriptor pluginDescriptor = createPluginDescriptor( 
javaSources[i] );
   
  -                File pluginDescriptorFile = new File( destinationDirectory, 
pluginArtifactName( pluginDescriptor ) );
  -
  -                writePluginArtifact( pluginDescriptor, pluginDescriptorFile );
  +                writePluginArtifact( pluginDescriptor, destinationDirectory );
               }
           }
       }
  
  
  
  1.2       +37 -19    
maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/BeanGenerator.java
  
  Index: BeanGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/BeanGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BeanGenerator.java        27 May 2004 01:31:23 -0000      1.1
  +++ BeanGenerator.java        27 May 2004 01:58:26 -0000      1.2
  @@ -9,8 +9,8 @@
   import org.codehaus.modello.generator.java.javasource.JSourceWriter;
   import org.codehaus.modello.generator.java.javasource.JType;
   
  -import java.io.File;
   import java.io.FileWriter;
  +import java.io.File;
   import java.util.List;
   
   /**
  @@ -20,28 +20,14 @@
   public class BeanGenerator
       extends AbstractGenerator
   {
  -    protected String pluginArtifactName( PluginDescriptor pluginDescriptor )
  -    {
  -        // ----------------------------------------------------------------------
  -        // We will base the classname on the implementation we are wrapping
  -        // ----------------------------------------------------------------------
  -
  -        return getClassName( pluginDescriptor ) + ".java";
  -    }
  -
  -    protected String getClassName( PluginDescriptor pluginDescriptor )
  -    {
  -        String implementation = pluginDescriptor.getImplementation();
  -
  -        return implementation.substring( implementation.lastIndexOf( "." ) + 1 ) + 
"Bean";
  -    }
  -
  -    protected void writePluginArtifact( PluginDescriptor pluginDescriptor, File 
destination )
  +    protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String 
destinationDirectory )
           throws Exception
       {
           String implementation = pluginDescriptor.getImplementation();
   
  -        JClass jClass = new JClass( getClassName( pluginDescriptor ) );
  +        String className = implementation.substring( implementation.lastIndexOf( 
"." ) + 1 ) + "Bean";
  +
  +        JClass jClass = new JClass( className );
   
           // ----------------------------------------------------------------------
           //
  @@ -84,6 +70,15 @@
           //
           // ----------------------------------------------------------------------
   
  +        String packageDirectory = replace( packageName, ".", "/", -1 );
  +
  +        File destination = new File( destinationDirectory, packageDirectory + "/" + 
className + ".java" );
  +
  +        if ( !destination.getParentFile().exists() )
  +        {
  +            destination.getParentFile().mkdirs();
  +        }
  +
           FileWriter writer = new FileWriter( destination );
   
           JSourceWriter sourceWriter = new JSourceWriter( writer );
  @@ -134,5 +129,28 @@
               .append( Character.toTitleCase( str.charAt( 0 ) ) )
               .append( str.substring( 1 ) )
               .toString();
  +    }
  +
  +    protected String replace( String text, String repl, String with, int max )
  +    {
  +        if ( text == null || repl == null || with == null || repl.length() == 0 )
  +        {
  +            return text;
  +        }
  +
  +        StringBuffer buf = new StringBuffer( text.length() );
  +        int start = 0, end = 0;
  +        while ( ( end = text.indexOf( repl, start ) ) != -1 )
  +        {
  +            buf.append( text.substring( start, end ) ).append( with );
  +            start = end + repl.length();
  +
  +            if ( --max == 0 )
  +            {
  +                break;
  +            }
  +        }
  +        buf.append( text.substring( start ) );
  +        return buf.toString();
       }
   }
  
  
  
  1.4       +5 -1      
maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/Main.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Main.java 26 May 2004 15:32:24 -0000      1.3
  +++ Main.java 27 May 2004 01:58:26 -0000      1.4
  @@ -38,6 +38,10 @@
           {
               generator = new JellyHarnessGenerator();
           }
  +        else if ( mode.equals( "bean" ) )
  +        {
  +            generator = new BeanGenerator();
  +        }
   
           generator.execute( sourceDirectory, outputDirectory );
       }
  
  
  
  1.5       +2 -7      
maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/PluginDescriptorGenerator.java
  
  Index: PluginDescriptorGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/PluginDescriptorGenerator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PluginDescriptorGenerator.java    22 May 2004 02:46:03 -0000      1.4
  +++ PluginDescriptorGenerator.java    27 May 2004 01:58:26 -0000      1.5
  @@ -18,15 +18,10 @@
   public class PluginDescriptorGenerator
       extends AbstractGenerator
   {
  -    protected String pluginArtifactName( PluginDescriptor pluginDescriptor )
  -    {
  -        return "plugin.xml";
  -    }
  -
  -    protected void writePluginArtifact( PluginDescriptor pluginDescriptor, File 
destination )
  +    protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String 
destinationDirectory )
           throws Exception
       {
  -        FileWriter writer = new FileWriter( destination );
  +        FileWriter writer = new FileWriter( new File( destinationDirectory, 
"plugin.xml" ) );
   
           XMLWriter w = new PrettyPrintXMLWriter( writer );
   
  
  
  
  1.4       +2 -7      
maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/PluginXdocGenerator.java
  
  Index: PluginXdocGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/PluginXdocGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PluginXdocGenerator.java  22 May 2004 02:46:03 -0000      1.3
  +++ PluginXdocGenerator.java  27 May 2004 01:58:26 -0000      1.4
  @@ -19,15 +19,10 @@
   public class PluginXdocGenerator
       extends AbstractGenerator
   {
  -    protected String pluginArtifactName( PluginDescriptor pluginDescriptor )
  -    {
  -        return "plugin-doco.xml";
  -    }
  -
  -    protected void writePluginArtifact( PluginDescriptor pluginDescriptor, File 
destination )
  +    protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String 
destinationDirectory )
           throws Exception
       {
  -        FileWriter writer = new FileWriter( destination );
  +        FileWriter writer = new FileWriter( new File( destinationDirectory, 
"plugin-doco.xml" ) );
   
           XMLWriter w = new PrettyPrintXMLWriter( writer );
   
  
  
  
  1.4       +2 -7      
maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/jelly/JellyHarnessGenerator.java
  
  Index: JellyHarnessGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/jelly/JellyHarnessGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JellyHarnessGenerator.java        22 May 2004 15:17:14 -0000      1.3
  +++ JellyHarnessGenerator.java        27 May 2004 01:58:26 -0000      1.4
  @@ -18,22 +18,17 @@
   public class JellyHarnessGenerator
       extends AbstractGenerator
   {
  -    protected String pluginArtifactName( PluginDescriptor pluginDescriptor )
  -    {
  -        return "plugin.jelly";
  -    }
  -
       protected String getClassName( PluginDescriptor pluginDescriptor )
       {
           return pluginDescriptor.getImplementation() + "Bean";
       }
   
  -    protected void writePluginArtifact( PluginDescriptor pluginDescriptor, File 
destination )
  +    protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String 
destinationDirectory )
           throws Exception
       {
           String id = pluginDescriptor.getId();
   
  -        FileWriter writer = new FileWriter( destination );
  +        FileWriter writer = new FileWriter( new File( destinationDirectory, 
"plugin.jelly" ) );
   
           PrettyPrintXMLWriter w = new PrettyPrintXMLWriter( writer );
   
  
  
  
  1.1                  
maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/BeanGeneratorTest.java
  
  Index: BeanGeneratorTest.java
  ===================================================================
  package org.apache.maven.plugin.generator;
  
  import junit.framework.TestCase;
  
  import java.io.File;
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
   * @version $Id: BeanGeneratorTest.java,v 1.1 2004/05/27 01:58:26 jvanzyl Exp $
   */
  public class BeanGeneratorTest
      extends TestCase
  {
      public void testPluginDescriptorCreationFromPluginSource()
          throws Exception
      {
          String basedir = System.getProperty( "basedir" );
  
          BeanGenerator pluggy = new BeanGenerator();
  
          pluggy.execute( new File( basedir, "src/test/resources/source" ).getPath(), 
new File( basedir, "target" ).getPath() );
      }
  }
  
  
  
  1.4       +1 -1      
maven-components/maven-plugin/src/test/resources/source/IdeaPlugin.java
  
  Index: IdeaPlugin.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-plugin/src/test/resources/source/IdeaPlugin.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IdeaPlugin.java   22 May 2004 00:50:06 -0000      1.3
  +++ IdeaPlugin.java   27 May 2004 01:58:26 -0000      1.4
  @@ -11,7 +11,7 @@
    *
    * @parameter sourceDirectory String required validator
    * @parameter outputDirectory String required validator
  - * @parameter classpathElements String required validator
  + * @parameter classpathElements String[] required validator
    * @parameter compiler String required validator
    *
    * @goal.name compile
  
  
  

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

Reply via email to