You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2004/05/20 18:59:45 UTC

cvs commit: maven-components/maven-plugin/src/test/resources/source IdeaPlugin.java

jvanzyl     2004/05/20 09:59:45

  Modified:    maven-plugin project.xml
               maven-plugin/src/main/java/org/apache/maven/plugin/generator
                        AbstractGenerator.java Main.java
                        PluginDescriptorGenerator.java
                        PluginXdocGenerator.java
               maven-plugin/src/test/java/org/apache/maven/plugin/generator
                        PluginDescriptorGeneratorTest.java
                        PluginXdocGeneratorTest.java
               maven-plugin/src/test/resources/source IdeaPlugin.java
  Added:       maven-plugin/src/main/java/org/apache/maven/plugin/descriptor
                        Goal.java Parameter.java PluginDescriptor.java
                        PluginDescriptorBuilder.java
  Removed:     maven-plugin/src/main/java/org/apache/maven/plugin
                        GoalDescriptor.java ParameterDescriptor.java
                        PluginDescriptor.java PluginDescriptorBuilder.java
               maven-plugin/src/test/java/org/apache/maven/plugin
                        PluginDescriptorBuilderTest.java
  Log:
  o maven-plugin is now fully decoupled from maven and plexus itself (even
    when plugins use plexus components because they are just pojos) and
    maven-core just uses an adapter to use the generic plugin descriptor
    found in this package.
  
    I don't know what to really called them, they are just POJOs with
    methods of a certain signature and everything is self contained in
    this package. There are tools that require qdox and xstream and those
    can be moved to another build if deemed necessary. There is also
    a dep on JUnit for an abstract test for the maven plugins. Maybe we
    can called them Maven POJOs or Mojos :-)
  
  Revision  Changes    Path
  1.2       +5 -0      maven-components/maven-plugin/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugin/project.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- project.xml	16 May 2004 04:25:15 -0000	1.1
  +++ project.xml	20 May 2004 16:59:45 -0000	1.2
  @@ -26,5 +26,10 @@
         <artifactId>xpp3</artifactId>
         <version>1.1.3.3</version>
       </dependency>
  +    <dependency>
  +      <groupId>junit</groupId>
  +      <artifactId>junit</artifactId>
  +      <version>3.8.1</version>
  +    </dependency>
     </dependencies>
   </project>
  
  
  
  1.1                  maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/Goal.java
  
  Index: Goal.java
  ===================================================================
  package org.apache.maven.plugin.descriptor;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import java.util.List;
  
  /**
   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
   * @version $Id: Goal.java,v 1.1 2004/05/20 16:59:45 jvanzyl Exp $
   */
  public class Goal
  {
      private String name;
  
      private List parameters;
  
      private List prereqs;
  
      private String description;
  
      private boolean requiresDependencyResolution = true;
  
      private boolean requiresProject = true;
  
      private String method = "execute";
  
      public String getName()
      {
          return name;
      }
  
      public List getPrereqs()
      {
          return prereqs;
      }
  
      public String getDescription()
      {
          return description;
      }
  
      public List getParameters()
      {
          return parameters;
      }
  
      public String getMethod()
      {
          return method;
      }
  
      // ----------------------------------------------------------------------
      //
      // ----------------------------------------------------------------------
  
      public void setName( String name )
      {
          this.name = name;
      }
  
      public void setParameters( List parameters )
      {
          this.parameters = parameters;
      }
  
      public void setPrereqs( List prereqs )
      {
          this.prereqs = prereqs;
      }
  
      public void setDescription( String description )
      {
          this.description = description;
      }
  
      public void setRequiresDependencyResolution( boolean requiresDependencyResolution )
      {
          this.requiresDependencyResolution = requiresDependencyResolution;
      }
  
      public void setRequiresProject( boolean requiresProject )
      {
          this.requiresProject = requiresProject;
      }
  
      public void setMethod( String method )
      {
          this.method = method;
      }
  }
  
  
  1.1                  maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java
  
  Index: Parameter.java
  ===================================================================
  package org.apache.maven.plugin.descriptor;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
   * @version $Id: Parameter.java,v 1.1 2004/05/20 16:59:45 jvanzyl Exp $
   */
  public class Parameter
  {
      private String name;
  
      private String type;
  
      private boolean required;
  
      private String validator;
  
      private String description;
  
      private String expression;
  
      // ----------------------------------------------------------------------
      //
      // ----------------------------------------------------------------------
  
      public String getName()
      {
          return name;
      }
  
      public void setName( String name )
      {
          this.name = name;
      }
  
      public String getType()
      {
          return type;
      }
  
      public void setType( String type )
      {
          this.type = type;
      }
  
      public boolean isRequired()
      {
          return required;
      }
  
      public void setRequired( boolean required )
      {
          this.required = required;
      }
  
      public String getValidator()
      {
          return validator;
      }
  
      public void setValidator( String validator )
      {
          this.validator = validator;
      }
  
      public String getDescription()
      {
          return description;
      }
  
      public void setDescription( String description )
      {
          this.description = description;
      }
  
      public String getExpression()
      {
          return expression;
      }
  
      public void setExpression( String expression )
      {
          this.expression = expression;
      }
  }
  
  
  
  1.1                  maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
  
  Index: PluginDescriptor.java
  ===================================================================
  package org.apache.maven.plugin.descriptor;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.maven.plugin.descriptor.Parameter;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  public class PluginDescriptor
  {
      private String implementation;
  
      private String description;
  
      private String id;
  
      private List goals;
  
      private List parameters;
  
      private Map parameterMap;
  
      private String mode = "integrated";
  
      private String instantiationStrategy = "singleton";
  
      public String getRole()
      {
          return "org.apache.maven.plugin.Plugin";
      }
  
      public String getImplementation()
      {
          return implementation;
      }
  
      public void setImplementation( String implementation )
      {
          this.implementation = implementation;
      }
  
      public String getDescription()
      {
          return description;
      }
  
      public void setDescription( String description )
      {
          this.description = description;
      }
  
      public String getInstantiationStrategy()
      {
          return instantiationStrategy;
      }
  
      public void setInstantiationStrategy( String instantiationStrategy )
      {
          this.instantiationStrategy = instantiationStrategy;
      }
  
      public String getId()
      {
          return id;
      }
  
      public void setId( String id )
      {
          this.id = id;
      }
  
      public List getGoals()
      {
          return goals;
      }
  
      public void setGoals( List goals )
      {
          this.goals = goals;
      }
  
      public List getParameters()
      {
          return parameters;
      }
  
      public void setParameters( List parameters )
      {
          this.parameters = parameters;
      }
  
      public Map getParameterMap()
      {
          if ( parameterMap == null )
          {
              parameterMap = new HashMap();
  
              for ( Iterator iterator = parameters.iterator(); iterator.hasNext(); )
              {
                  Parameter pd = (Parameter) iterator.next();
  
                  parameterMap.put( pd.getName(), pd );
              }
          }
  
          return parameterMap;
      }
  
      public String getMode()
      {
          return mode;
      }
  
      public void setMode( String mode )
      {
          this.mode = mode;
      }
  }
  
  
  
  1.1                  maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
  
  Index: PluginDescriptorBuilder.java
  ===================================================================
  package org.apache.maven.plugin.descriptor;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import com.thoughtworks.xstream.XStream;
  import com.thoughtworks.xstream.alias.DefaultClassMapper;
  import com.thoughtworks.xstream.alias.DefaultNameMapper;
  import com.thoughtworks.xstream.objecttree.reflection.JavaReflectionObjectFactory;
  import com.thoughtworks.xstream.xml.xpp3.Xpp3DomBuilder;
  import com.thoughtworks.xstream.xml.xpp3.Xpp3DomXMLReader;
  import com.thoughtworks.xstream.xml.xpp3.Xpp3DomXMLReaderDriver;
  
  import java.io.Reader;
  
  import org.apache.maven.plugin.descriptor.Goal;
  import org.apache.maven.plugin.descriptor.Parameter;
  import org.apache.maven.plugin.descriptor.PluginDescriptor;
  
  /**
   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
   * @version $Id: PluginDescriptorBuilder.java,v 1.1 2004/05/20 16:59:45 jvanzyl Exp $
   */
  public class PluginDescriptorBuilder
  {
      private XStream xstream;
  
      public PluginDescriptorBuilder()
      {
          xstream = new XStream( new JavaReflectionObjectFactory(),
                                 new DefaultClassMapper( new DefaultNameMapper() ),
                                 new Xpp3DomXMLReaderDriver(),
                                 "implementation" );
  
          xstream.alias( "plugin", PluginDescriptor.class );
  
          xstream.alias( "goal", Goal.class );
  
          xstream.alias( "prereq", String.class );
  
          xstream.alias( "parameter", Parameter.class );
      }
  
      public PluginDescriptor build( Reader reader )
          throws Exception
      {
          return (PluginDescriptor) xstream.fromXML( new Xpp3DomXMLReader( Xpp3DomBuilder.build( reader ) ) );
      }
  }
  
  
  
  1.2       +99 -36    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractGenerator.java	16 May 2004 04:25:16 -0000	1.1
  +++ AbstractGenerator.java	20 May 2004 16:59:45 -0000	1.2
  @@ -4,14 +4,13 @@
   import com.thoughtworks.qdox.model.DocletTag;
   import com.thoughtworks.qdox.model.JavaClass;
   import com.thoughtworks.qdox.model.JavaSource;
  -import com.thoughtworks.xstream.xml.XMLWriter;
  -import com.thoughtworks.xstream.xml.text.PrettyPrintXMLWriter;
  -import org.apache.maven.plugin.PluginDescriptor;
  -import org.apache.maven.plugin.GoalDescriptor;
  -import org.apache.maven.plugin.ParameterDescriptor;
  +import org.apache.maven.plugin.descriptor.Goal;
  +import org.apache.maven.plugin.descriptor.Parameter;
  +import org.apache.maven.plugin.descriptor.Parameter;
  +import org.apache.maven.plugin.descriptor.PluginDescriptor;
  +import org.apache.maven.plugin.descriptor.PluginDescriptor;
   
   import java.io.File;
  -import java.io.FileWriter;
   import java.util.ArrayList;
   import java.util.List;
   
  @@ -22,6 +21,14 @@
    */
   public abstract class AbstractGenerator
   {
  +    public static final String MAVEN_PLUGIN_ID = "maven.plugin.id";
  +
  +    public static final String MAVEN_PLUGIN_DESCRIPTION = "maven.plugin.description";
  +
  +    public static final String MAVEN_PLUGIN_INSTANTIATION = "maven.plugin.instantiation";
  +
  +    public static final String MAVEN_PLUGIN_MODE = "maven.plugin.mode";
  +
       protected abstract void writePluginArtifact( PluginDescriptor pluginDescriptor, File destination )
           throws Exception;
   
  @@ -36,20 +43,16 @@
   
           builder.addSourceTree( sourceDirectoryFile );
   
  -        // Should there only be one
  -
           JavaSource[] javaSources = builder.getSources();
   
           for ( int i = 0; i < javaSources.length; i++ )
           {
  -            String file = javaSources[i].getFile().getName();
  +            DocletTag tag = getJavaClass( javaSources[i] ).getTagByName( MAVEN_PLUGIN_ID );
   
  -            if ( file.endsWith( "Plugin.java" ) )
  +            if ( tag != null )
               {
                   PluginDescriptor pluginDescriptor = createPluginDescriptor( javaSources[i] );
   
  -                System.out.println( "file = " + file );
  -
                   File pluginDescriptorFile = new File( destinationDirectory, pluginArtifactName() );
   
                   writePluginArtifact( pluginDescriptor, pluginDescriptorFile );
  @@ -71,34 +74,77 @@
   
           DocletTag tag;
   
  -        tag = javaClass.getTagByName( "plugin.id" );
  +        tag = javaClass.getTagByName( MAVEN_PLUGIN_ID );
   
           if ( tag != null )
           {
               pluginDescriptor.setId( tag.getValue() );
           }
   
  -        tag = javaClass.getTagByName( "plugin.description" );
  +        tag = javaClass.getTagByName( MAVEN_PLUGIN_DESCRIPTION );
   
           if ( tag != null )
           {
               pluginDescriptor.setDescription( tag.getValue() );
           }
   
  -        tag = javaClass.getTagByName( "plugin.instantiation" );
  +        tag = javaClass.getTagByName( MAVEN_PLUGIN_INSTANTIATION );
   
           if ( tag != null )
           {
               pluginDescriptor.setInstantiationStrategy( tag.getValue() );
           }
   
  -        tag = javaClass.getTagByName( "plugin.mode" );
  +        tag = javaClass.getTagByName( "maven.plugin.mode" );
   
           if ( tag != null )
           {
               pluginDescriptor.setMode( tag.getValue() );
           }
   
  +        // ----------------------------------------------------------------------
  +        //
  +        // ----------------------------------------------------------------------
  +
  +        DocletTag[] parameterTags = javaClass.getTagsByName( "parameter" );
  +
  +        List parameters = new ArrayList();
  +
  +        for ( int j = 0; j < parameterTags.length; j++ )
  +        {
  +            DocletTag parameter = parameterTags[j];
  +
  +            Parameter pd = new Parameter();
  +
  +            pd.setName( parameter.getParameters()[0] );
  +
  +            pd.setType( parameter.getParameters()[1] );
  +
  +            pd.setRequired( Boolean.getBoolean( parameter.getParameters()[2] ) );
  +
  +            pd.setValidator( parameter.getParameters()[3] );
  +
  +            int length = parameter.getParameters().length;
  +
  +            StringBuffer parameterDescription = new StringBuffer();
  +
  +            for ( int k = 4; k < length; k++ )
  +            {
  +                // Collect all the parameters which make up the parameter description.
  +                parameterDescription.append( parameter.getParameters()[k] ).append( " " );
  +            }
  +
  +            pd.setDescription( parameterDescription.toString() );
  +
  +            parameters.add( pd );
  +        }
  +
  +        pluginDescriptor.setParameters( parameters );
  +
  +        // ----------------------------------------------------------------------
  +        //
  +        // ----------------------------------------------------------------------
  +
           DocletTag[] goalNameTags = javaClass.getTagsByName( "goal.name" );
   
           List goals = new ArrayList();
  @@ -107,52 +153,69 @@
           {
               DocletTag goalNameTag = goalNameTags[i];
   
  -            DocletTag[] goalParameters = javaClass.getTagsByName( "goal." + goalNameTag.getValue() + ".parameter" );
  -
  -            GoalDescriptor goalDescriptor = new GoalDescriptor();
  +            Goal goal = new Goal();
   
  -            goalDescriptor.setName( goalNameTag.getValue() );
  +            goal.setName( goalNameTag.getValue() );
   
               DocletTag goalDescriptionTag = javaClass.getTagByName( "goal." + goalNameTag.getValue() + ".description" );
   
               if ( goalDescriptionTag != null )
               {
  -                goalDescriptor.setDescription( goalDescriptionTag.getValue() );
  +                goal.setDescription( goalDescriptionTag.getValue() );
               }
   
  -            List parameters = new ArrayList();
  +            // ----------------------------------------------------------------------
  +            // Parameters
  +            // ----------------------------------------------------------------------
   
  -            for ( int j = 0; j < goalParameters.length; j++ )
  +            DocletTag[] goalParameterTags = javaClass.getTagsByName( "goal." + goalNameTag.getValue() + ".parameter" );
  +
  +            List goalParameters = new ArrayList();
  +
  +            for ( int j = 0; j < goalParameterTags.length; j++ )
               {
  -                DocletTag goalParameter = goalParameters[j];
  +                DocletTag goalParameter = goalParameterTags[j];
   
  -                ParameterDescriptor pd = new ParameterDescriptor();
  +                Parameter pd = new Parameter();
   
                   pd.setName( goalParameter.getParameters()[0] );
   
                   pd.setExpression( goalParameter.getParameters()[1] );
   
  -                int length = goalParameter.getParameters().length;
  +                goalParameters.add( pd );
  +            }
  +
  +            goal.setParameters( goalParameters );
   
  -                StringBuffer parameterDescription = new StringBuffer();
  +            // ----------------------------------------------------------------------
  +            // Prereqs
  +            // ----------------------------------------------------------------------
   
  -                for ( int k = 2; k < length; k++ )
  -                {
  -                    // Collect all the parameters which make up the parameter description.
  -                    parameterDescription.append( goalParameter.getParameters()[k] ).append( " " );
  -                }
  +            DocletTag[] goalPrereqTags = javaClass.getTagsByName( "goal." + goalNameTag.getValue() + ".prereq" );
   
  -                pd.setDescription( parameterDescription.toString() );
  +            List goalPrereqs = new ArrayList();
   
  -                parameters.add( pd );
  +            for ( int j = 0; j < goalPrereqTags.length; j++ )
  +            {
  +                DocletTag goalPrereq = goalPrereqTags[j];
  +
  +                goalPrereqs.add( goalPrereq.getValue() );
               }
   
  -            goalDescriptor.setParameters( parameters );
  +            goal.setPrereqs( goalPrereqs );
   
  -            goals.add( goalDescriptor );
  +            // ----------------------------------------------------------------------
  +            //
  +            // ----------------------------------------------------------------------
  +
  +            goals.add( goal );
           }
   
           pluginDescriptor.setGoals( goals );
  +
  +        // ----------------------------------------------------------------------
  +        //
  +        // ----------------------------------------------------------------------
   
           return pluginDescriptor;
       }
  
  
  
  1.2       +3 -3      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Main.java	16 May 2004 04:25:16 -0000	1.1
  +++ Main.java	20 May 2004 16:59:45 -0000	1.2
  @@ -28,11 +28,11 @@
           {
               generator = new PluginDescriptorGenerator();
           }
  -        else if ( mode. equals( "xdoc" ) )
  +        else if ( mode.equals( "xdoc" ) )
           {
               generator = new PluginXdocGenerator();
           }
   
  -        generator.execute( sourceDirectory, outputDirectory);
  +        generator.execute( sourceDirectory, outputDirectory );
       }
   }
  
  
  
  1.2       +87 -25    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PluginDescriptorGenerator.java	16 May 2004 04:25:16 -0000	1.1
  +++ PluginDescriptorGenerator.java	20 May 2004 16:59:45 -0000	1.2
  @@ -2,9 +2,11 @@
   
   import com.thoughtworks.xstream.xml.XMLWriter;
   import com.thoughtworks.xstream.xml.text.PrettyPrintXMLWriter;
  -import org.apache.maven.plugin.GoalDescriptor;
  -import org.apache.maven.plugin.ParameterDescriptor;
  -import org.apache.maven.plugin.PluginDescriptor;
  +import org.apache.maven.plugin.descriptor.Goal;
  +import org.apache.maven.plugin.descriptor.Parameter;
  +import org.apache.maven.plugin.descriptor.PluginDescriptor;
  +import org.apache.maven.plugin.descriptor.Goal;
  +import org.apache.maven.plugin.descriptor.Parameter;
   
   import java.io.File;
   import java.io.FileWriter;
  @@ -73,6 +75,35 @@
           w.endElement();
   
           // ----------------------------------------------------------------------
  +        // Parameters
  +        // ----------------------------------------------------------------------
  +
  +        List parameters = pluginDescriptor.getParameters();
  +
  +        w.startElement( "parameters" );
  +
  +        for ( int j = 0; j < parameters.size(); j++ )
  +        {
  +            Parameter parameter = (Parameter) parameters.get( j );
  +
  +            w.startElement( "parameter" );
  +
  +            element( w, "name", parameter.getName() );
  +
  +            element( w, "type", parameter.getType() );
  +
  +            element( w, "required", Boolean.toString( parameter.isRequired() ) );
  +
  +            element( w, "validator", parameter.getValidator() );
  +
  +            element( w, "description", parameter.getDescription() );
  +
  +            w.endElement();
  +        }
  +
  +        w.endElement();
  +
  +        // ----------------------------------------------------------------------
           // Goals
           // ----------------------------------------------------------------------
   
  @@ -82,61 +113,92 @@
   
           for ( int i = 0; i < goals.size(); i++ )
           {
  -            GoalDescriptor goal = (GoalDescriptor) goals.get( i );
  +            Goal goal = (Goal) goals.get( i );
   
               w.startElement( "goal" );
   
  -            w.startElement( "name" );
  -
  -            w.writeText( goal.getName() );
  -
  -            w.endElement();
  +            element( w, "name", goal.getName() );
   
               if ( goal.getDescription() != null )
               {
  -                w.startElement( "description" );
  -
  -                w.writeText( goal.getDescription() );
  -
  -                w.endElement();
  +                element( w, "description", goal.getDescription() );
               }
   
  -            List parameters = goal.getParameters();
  +            // ----------------------------------------------------------------------
  +            // Goal parameters
  +            // ----------------------------------------------------------------------
   
  -            w.startElement( "parameters" );
  +            List goalParameters = goal.getParameters();
   
  -            for ( int j = 0; j < parameters.size(); j++ )
  +            if ( goalParameters.size() > 0 )
               {
  -                ParameterDescriptor parameter = (ParameterDescriptor) parameters.get( j );
   
  -                w.startElement( "parameter" );
  +                w.startElement( "parameters" );
  +
  +                for ( int j = 0; j < goalParameters.size(); j++ )
  +                {
  +                    Parameter parameter = (Parameter) goalParameters.get( j );
   
  -                w.startElement( "name" );
  +                    w.startElement( "parameter" );
   
  -                w.writeText( parameter.getName() );
  +                    element( w, "name", parameter.getName() );
  +
  +                    element( w, "expression", parameter.getExpression() );
  +
  +                    w.endElement();
  +                }
   
                   w.endElement();
  +            }
  +
  +            // ----------------------------------------------------------------------
  +            // Goal prereqs
  +            // ----------------------------------------------------------------------
  +
  +            List goalPrereqs = goal.getPrereqs();
  +
  +            System.out.println( "goalPrereqs.size() = " + goalPrereqs.size() );
  +
  +            if ( goalPrereqs.size() > 0 )
  +            {
  +                w.startElement( "prereqs" );
   
  -                w.startElement( "expression" );
  +                for ( int j = 0; j < goalPrereqs.size(); j++ )
  +                {
  +                    String prereq = (String) goalPrereqs.get( j );
   
  -                w.writeText( parameter.getExpression() );
  +                    element( w, "prereq", prereq );
  +                }
   
                   w.endElement();
               }
   
  -            w.endElement();
  +            // ----------------------------------------------------------------------
  +            //
  +            // ----------------------------------------------------------------------
   
               w.endElement();
           }
   
           w.endElement();
   
  -        w.endElement();
  +        // ----------------------------------------------------------------------
  +        //
  +        // ----------------------------------------------------------------------
   
           w.endElement();
   
           writer.flush();
   
           writer.close();
  +    }
  +
  +    public void element( XMLWriter w, String name, String value )
  +    {
  +        w.startElement( name );
  +
  +        w.writeText( value );
  +
  +        w.endElement();
       }
   }
  
  
  
  1.2       +16 -8     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PluginXdocGenerator.java	16 May 2004 04:25:16 -0000	1.1
  +++ PluginXdocGenerator.java	20 May 2004 16:59:45 -0000	1.2
  @@ -2,13 +2,17 @@
   
   import com.thoughtworks.xstream.xml.XMLWriter;
   import com.thoughtworks.xstream.xml.text.PrettyPrintXMLWriter;
  -import org.apache.maven.plugin.GoalDescriptor;
  -import org.apache.maven.plugin.ParameterDescriptor;
  -import org.apache.maven.plugin.PluginDescriptor;
  +import org.apache.maven.plugin.descriptor.Goal;
  +import org.apache.maven.plugin.descriptor.Parameter;
  +import org.apache.maven.plugin.descriptor.PluginDescriptor;
  +import org.apache.maven.plugin.descriptor.Goal;
  +import org.apache.maven.plugin.descriptor.Parameter;
  +import org.apache.maven.plugin.descriptor.PluginDescriptor;
   
   import java.io.File;
   import java.io.FileWriter;
   import java.util.List;
  +import java.util.Map;
   
   /**
    * @todo add example usage tag that can be shown in the doco
  @@ -76,7 +80,7 @@
   
           for ( int i = 0; i < goals.size(); i++ )
           {
  -            GoalDescriptor goal = (GoalDescriptor) goals.get( i );
  +            Goal goal = (Goal) goals.get( i );
   
               w.startElement( "subsection" );
   
  @@ -97,7 +101,7 @@
   
               w.endElement();
   
  -            writeGoalParameterTable( goal, w );
  +            writeGoalParameterTable( pluginDescriptor, goal, w );
   
               w.endElement();
           }
  @@ -119,7 +123,7 @@
           writer.close();
       }
   
  -    private void writeGoalParameterTable( GoalDescriptor goal, XMLWriter w )
  +    private void writeGoalParameterTable( PluginDescriptor pd, Goal goal, XMLWriter w )
           throws Exception
       {
           w.startElement( "p" );
  @@ -150,9 +154,11 @@
   
           List parameters = goal.getParameters();
   
  +        Map parameterMap = pd.getParameterMap();
  +
           for ( int i = 0; i < parameters.size(); i++ )
           {
  -            ParameterDescriptor parameter = (ParameterDescriptor) parameters.get( i );
  +            Parameter parameter = (Parameter) parameters.get( i );
   
               w.startElement( "tr" );
   
  @@ -182,7 +188,9 @@
   
               w.startElement( "td" );
   
  -            w.writeText( parameter.getDescription() );
  +            Parameter p = (Parameter) parameterMap.get( parameter.getName() );
  +
  +            w.writeText( p.getDescription() );
   
               w.endElement();
   
  
  
  
  1.2       +17 -15    maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/PluginDescriptorGeneratorTest.java
  
  Index: PluginDescriptorGeneratorTest.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/PluginDescriptorGeneratorTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PluginDescriptorGeneratorTest.java	16 May 2004 04:25:16 -0000	1.1
  +++ PluginDescriptorGeneratorTest.java	20 May 2004 16:59:45 -0000	1.2
  @@ -1,16 +1,18 @@
   package org.apache.maven.plugin.generator;
   
   import junit.framework.TestCase;
  +import org.apache.maven.plugin.descriptor.Goal;
  +import org.apache.maven.plugin.descriptor.Parameter;
  +import org.apache.maven.plugin.descriptor.PluginDescriptor;
  +import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
  +import org.apache.maven.plugin.descriptor.Goal;
  +import org.apache.maven.plugin.descriptor.Parameter;
  +import org.apache.maven.plugin.descriptor.PluginDescriptor;
   
   import java.io.File;
   import java.io.FileReader;
   import java.util.List;
   
  -import org.apache.maven.plugin.PluginDescriptorBuilder;
  -import org.apache.maven.plugin.PluginDescriptor;
  -import org.apache.maven.plugin.GoalDescriptor;
  -import org.apache.maven.plugin.ParameterDescriptor;
  -
   /**
    * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
    * @version $Id$
  @@ -33,7 +35,7 @@
   
           PluginDescriptor pluginDescriptor = pdb.build( new FileReader( pluginDescriptorFile ) );
   
  -        assertEquals( "idea", pluginDescriptor.getId() );
  +        assertEquals( "compiler", pluginDescriptor.getId() );
   
           assertEquals( "org.apache.maven.plugin.idea.IdeaPlugin", pluginDescriptor.getImplementation() );
   
  @@ -47,13 +49,13 @@
   
           List goals = pluginDescriptor.getGoals();
   
  -        assertEquals( 1, goals.size() );
  +        assertEquals( 2, goals.size() );
   
  -        GoalDescriptor gd = (GoalDescriptor) goals.get( 0 );
  +        Goal gd = (Goal) goals.get( 0 );
   
  -        assertEquals( "idea", gd.getName() );
  +        assertEquals( "compile", gd.getName() );
   
  -        assertEquals( "Goal to create IDEA files from a POM", gd.getDescription() );
  +        assertEquals( "compile", gd.getDescription() );
   
           // ----------------------------------------------------------------------
           // Parameters
  @@ -61,12 +63,12 @@
   
           List parameters = gd.getParameters();
   
  -        assertEquals( 1, parameters.size() );
  +        assertEquals( 4, parameters.size() );
   
  -        ParameterDescriptor pd = (ParameterDescriptor) gd.getParameters().get( 0 );
  +        Parameter pd = (Parameter) gd.getParameters().get( 0 );
   
  -        assertEquals( "project", pd.getName() );
  +        assertEquals( "sourceDirectory", pd.getName() );
   
  -        assertEquals( "#project", pd.getExpression() );
  +        assertEquals( "#project.build.sourceDirectory", pd.getExpression() );
       }
   }
  
  
  
  1.2       +1 -50     maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/PluginXdocGeneratorTest.java
  
  Index: PluginXdocGeneratorTest.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/PluginXdocGeneratorTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PluginXdocGeneratorTest.java	16 May 2004 04:25:16 -0000	1.1
  +++ PluginXdocGeneratorTest.java	20 May 2004 16:59:45 -0000	1.2
  @@ -3,13 +3,6 @@
   import junit.framework.TestCase;
   
   import java.io.File;
  -import java.io.FileReader;
  -import java.util.List;
  -
  -import org.apache.maven.plugin.PluginDescriptorBuilder;
  -import org.apache.maven.plugin.PluginDescriptor;
  -import org.apache.maven.plugin.GoalDescriptor;
  -import org.apache.maven.plugin.ParameterDescriptor;
   
   /**
    * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
  @@ -26,47 +19,5 @@
           PluginXdocGenerator pluggy = new PluginXdocGenerator();
   
           pluggy.execute( new File( basedir, "src/test/resources/source" ).getPath(), new File( basedir, "target" ).getPath() );
  -
  -        PluginDescriptorBuilder pdb = new PluginDescriptorBuilder();
  -
  -        File pluginDescriptorFile = new File( basedir, "target/plugin.xml" );
  -
  -        PluginDescriptor pluginDescriptor = pdb.build( new FileReader( pluginDescriptorFile ) );
  -
  -        assertEquals( "idea", pluginDescriptor.getId() );
  -
  -        assertEquals( "org.apache.maven.plugin.idea.IdeaPlugin", pluginDescriptor.getImplementation() );
  -
  -        assertEquals( "singleton", pluginDescriptor.getInstantiationStrategy() );
  -
  -        assertEquals( "integrated", pluginDescriptor.getMode() );
  -
  -        // ----------------------------------------------------------------------
  -        // Goals
  -        // ----------------------------------------------------------------------
  -
  -        List goals = pluginDescriptor.getGoals();
  -
  -        assertEquals( 1, goals.size() );
  -
  -        GoalDescriptor gd = (GoalDescriptor) goals.get( 0 );
  -
  -        assertEquals( "idea", gd.getName() );
  -
  -        assertEquals( "Goal to create IDEA files from a POM", gd.getDescription() );
  -
  -        // ----------------------------------------------------------------------
  -        // Parameters
  -        // ----------------------------------------------------------------------
  -
  -        List parameters = gd.getParameters();
  -
  -        assertEquals( 1, parameters.size() );
  -
  -        ParameterDescriptor pd = (ParameterDescriptor) gd.getParameters().get( 0 );
  -
  -        assertEquals( "project", pd.getName() );
  -
  -        assertEquals( "#project", pd.getExpression() );
       }
   }
  
  
  
  1.2       +22 -39    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IdeaPlugin.java	16 May 2004 04:25:16 -0000	1.1
  +++ IdeaPlugin.java	20 May 2004 16:59:45 -0000	1.2
  @@ -6,48 +6,31 @@
   import org.apache.maven.plugin.PluginExecutionResponse;
   
   /**
  - * @plugin.id idea
  - * @plugin.description A maven2 plugin which integrates the use of Maven2 with IntelliJ's IDEA
  - * @plugin.instantiation singleton
  - * @plugin.mode integrated
  + * @maven.plugin.id compiler
  + * @maven.plugin.description A maven2 plugin which integrates the use of Maven2 with IntelliJ's IDEA
    *
  - * @goal.name idea
  - * @goal.idea.description Goal to create IDEA files from a POM
  - * @goal.idea.parameter project #project Maven project for which the IDEA files will be generated for
  + * @parameter sourceDirectory String required validator
  + * @parameter outputDirectory String required validator
  + * @parameter classpathElements String[] required validator
  + * @parameter compiler String required validator
  + *
  + * @goal.name compile
  + * @goal.compile.description compile
  + * @goal.compile.parameter sourceDirectory #project.build.sourceDirectory
  + * @goal.compile.parameter outputDirectory #maven.build.dest
  + * @goal.compile.parameter classpathElements #project.classpathElements
  + * @goal.compile.parameter compiler javac
  + * @goal.compile.prereq foo
  + * @goal.compile.prereq bar
  + *
  + * @goal.name test:compile
  + * @goal.test:compile.description test:compile
  + * @goal.test:compile.parameter sourceDirectory #project.build.unitTestSourceDirectory
  + * @goal.test:compile.parameter outputDirectory #maven.test.dest
  + * @goal.test:compile.parameter classpathElements #project.classpathElements
  + * @goal.test:compile.parameter compiler javac
    */
   public class IdeaPlugin
       extends AbstractPlugin
   {
  -    protected IdeaWriter ideaWriter;
  -
  -    public IdeaPlugin()
  -    {
  -        ideaWriter = new IdeaWriter();
  -    }
  -
  -    // ----------------------------------------------------------------------
  -    // Now even in the context of a reactor, different things may be required:
  -    //
  -    // o you may actually want to generate complete ipr/iws/iml files for each
  -    //   project that is picked up by the reactor.
  -    //
  -    // o you may want to generate the ipr/iws files for the top-level project and
  -    //   only create iml files for each of the nested projects.
  -    //
  -    // Or the ipr/iws/iml files could be generated for each regardless but aggregated
  -    // in a top-level project. This probably won't cause any harm as it will allow each
  -    // project to be open individually or by the aggregated project with the child iml
  -    // files. Most probably wouldn't use both modes but this is more akin to what might
  -    // happen with a report vis-a-vis aggregation at the top-level.
  -    //
  -    // Here we go ...
  -    // ----------------------------------------------------------------------
  -
  -    public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
  -        throws Exception
  -    {
  -        MavenProject project = (MavenProject) request.getParameter( "project" );
  -
  -        ideaWriter.write( project );
  -    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org