jvanzyl 2004/05/27 10:14:42
Modified: 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/java/org/apache/maven/plugin/generator
BeanGeneratorTest.java
PluginDescriptorGeneratorTest.java
PluginXdocGeneratorTest.java
maven-plugin/src/test/java/org/apache/maven/plugin/generator/jelly
JellyHarnessGeneratorTest.java
maven-plugin/src/test/resources/source IdeaPlugin.java
Added: maven-plugin/src/main/java/org/apache/maven/plugin/generator
Generator.java
maven-plugin/src/test/java/org/apache/maven/plugin/generator
AbstractGeneratorTestCase.java
Log:
o rework the testing of the generators to make it easier to test
o pass in the pom file as a string so that generators that need access
to the info in the pom can access via the xpp3 mini dom. in this case
i need access to the pom so that i can write out the dependencies in
the generated project.xml file for the jelly harness. this approach is
easier then trying to adapt the v3/v4 variants of the pom. we'll just
maven1 exactly what it expects and leave it at that.
Revision Changes Path
1.5 +9 -5
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractGenerator.java 27 May 2004 01:58:26 -0000 1.4
+++ AbstractGenerator.java 27 May 2004 17:14:41 -0000 1.5
@@ -4,13 +4,14 @@
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaSource;
+import com.thoughtworks.xstream.xml.xpp3.Xpp3DomBuilder;
+import com.thoughtworks.xstream.xml.xpp3.Xpp3Dom;
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.FileReader;
import java.util.ArrayList;
import java.util.List;
@@ -20,6 +21,7 @@
* maven2 can get validation directives to help users in IDEs.
*/
public abstract class AbstractGenerator
+ implements Generator
{
public static final String MAVEN_PLUGIN_ID = "maven.plugin.id";
@@ -29,10 +31,10 @@
public static final String MAVEN_PLUGIN_MODE = "maven.plugin.mode";
- protected abstract void writePluginArtifact( PluginDescriptor pluginDescriptor,
String destinationDirectory )
+ protected abstract void writePluginArtifact( PluginDescriptor pluginDescriptor,
String destinationDirectory, Xpp3Dom pomDom )
throws Exception;
- public void execute( String sourceDirectory, String destinationDirectory )
+ public void execute( String sourceDirectory, String destinationDirectory,
String pom )
throws Exception
{
JavaDocBuilder builder = new JavaDocBuilder();
@@ -51,7 +53,9 @@
{
PluginDescriptor pluginDescriptor = createPluginDescriptor(
javaSources[i] );
- writePluginArtifact( pluginDescriptor, destinationDirectory );
+ Xpp3Dom pomDom = Xpp3DomBuilder.build( new FileReader( pom ) );
+
+ writePluginArtifact( pluginDescriptor, destinationDirectory, pomDom
);
}
}
}
1.4 +3 -1
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BeanGenerator.java 27 May 2004 06:57:28 -0000 1.3
+++ BeanGenerator.java 27 May 2004 17:14:41 -0000 1.4
@@ -13,6 +13,8 @@
import java.io.File;
import java.util.List;
+import com.thoughtworks.xstream.xml.xpp3.Xpp3Dom;
+
/**
* @todo use the descriptions in the descriptor for the javadoc pushed into
* the source code.
@@ -20,7 +22,7 @@
public class BeanGenerator
extends AbstractGenerator
{
- protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String
destinationDirectory )
+ protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String
destinationDirectory, Xpp3Dom pomDom )
throws Exception
{
String implementation = pluginDescriptor.getImplementation();
1.5 +6 -4
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Main.java 27 May 2004 01:58:26 -0000 1.4
+++ Main.java 27 May 2004 17:14:41 -0000 1.5
@@ -11,9 +11,9 @@
public static void main( String[] args )
throws Exception
{
- if ( args.length != 3 )
+ if ( args.length != 4 )
{
- System.err.println( "Usage: pluggy <mode> <source directory> <output
directory>" );
+ System.err.println( "Usage: pluggy <mode> <source directory> <output
directory> <pom>" );
System.exit( 1 );
}
@@ -24,6 +24,8 @@
String outputDirectory = args[2];
+ String pom = args[3];
+
AbstractGenerator generator = null;
if ( mode.equals( "descriptor" ) )
@@ -43,6 +45,6 @@
generator = new BeanGenerator();
}
- generator.execute( sourceDirectory, outputDirectory );
+ generator.execute( sourceDirectory, outputDirectory, pom );
}
}
1.6 +2 -1
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PluginDescriptorGenerator.java 27 May 2004 01:58:26 -0000 1.5
+++ PluginDescriptorGenerator.java 27 May 2004 17:14:41 -0000 1.6
@@ -1,6 +1,7 @@
package org.apache.maven.plugin.generator;
import com.thoughtworks.xstream.xml.XMLWriter;
+import com.thoughtworks.xstream.xml.xpp3.Xpp3Dom;
import com.thoughtworks.xstream.xml.text.PrettyPrintXMLWriter;
import org.apache.maven.plugin.descriptor.Goal;
import org.apache.maven.plugin.descriptor.Parameter;
@@ -18,7 +19,7 @@
public class PluginDescriptorGenerator
extends AbstractGenerator
{
- protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String
destinationDirectory )
+ protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String
destinationDirectory, Xpp3Dom pomDom )
throws Exception
{
FileWriter writer = new FileWriter( new File( destinationDirectory,
"plugin.xml" ) );
1.5 +2 -1
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PluginXdocGenerator.java 27 May 2004 01:58:26 -0000 1.4
+++ PluginXdocGenerator.java 27 May 2004 17:14:41 -0000 1.5
@@ -1,6 +1,7 @@
package org.apache.maven.plugin.generator;
import com.thoughtworks.xstream.xml.XMLWriter;
+import com.thoughtworks.xstream.xml.xpp3.Xpp3Dom;
import com.thoughtworks.xstream.xml.text.PrettyPrintXMLWriter;
import org.apache.maven.plugin.descriptor.Goal;
import org.apache.maven.plugin.descriptor.Parameter;
@@ -19,7 +20,7 @@
public class PluginXdocGenerator
extends AbstractGenerator
{
- protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String
destinationDirectory )
+ protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String
destinationDirectory, Xpp3Dom pomDom )
throws Exception
{
FileWriter writer = new FileWriter( new File( destinationDirectory,
"plugin-doco.xml" ) );
1.1
maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/Generator.java
Index: Generator.java
===================================================================
package org.apache.maven.plugin.generator;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @version $Id: Generator.java,v 1.1 2004/05/27 17:14:41 jvanzyl Exp $
*/
public interface Generator
{
void execute( String sourceDirectory, String destinationDirectory, String pom )
throws Exception;
}
1.6 +39 -12
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JellyHarnessGenerator.java 27 May 2004 06:47:45 -0000 1.5
+++ JellyHarnessGenerator.java 27 May 2004 17:14:42 -0000 1.6
@@ -1,6 +1,8 @@
package org.apache.maven.plugin.generator.jelly;
import com.thoughtworks.xstream.xml.text.PrettyPrintXMLWriter;
+import com.thoughtworks.xstream.xml.XMLWriter;
+import com.thoughtworks.xstream.xml.xpp3.Xpp3Dom;
import org.apache.maven.plugin.descriptor.Goal;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
@@ -24,7 +26,7 @@
return pluginDescriptor.getImplementation() + "Bean";
}
- protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String
destinationDirectory )
+ protected void writePluginArtifact( PluginDescriptor pluginDescriptor, String
destinationDirectory, Xpp3Dom pomDom )
throws Exception
{
String id = pluginDescriptor.getId();
@@ -187,35 +189,60 @@
w.startElement( "dependencies" );
+ writeDependencies( w, pomDom );
+
+ w.endElement();
+
+ w.endElement();
+
+ writer.flush();
+
+ writer.close();
+ }
+
+ protected void writeDependencies( XMLWriter w, Xpp3Dom pomDom )
+ {
+ writeDependency( w, "maven", "maven-plugin", "2.0-SNAPSHOT" );
+
+ Xpp3Dom[] deps = pomDom.getChild( "dependencies" ).getChildren(
"dependency" );
+
+ for ( int i = 0; i < deps.length; i++ )
+ {
+ Xpp3Dom dep = deps[i];
+
+ String groupId = dep.getChild( "artifactId" ).getValue();
+
+ String artifactId = dep.getChild( "groupId" ).getValue();
+
+ String version = dep.getChild( "version" ).getValue();
+
+ writeDependency( w, groupId, artifactId, version );
+ }
+ }
+
+ protected void writeDependency( XMLWriter w, String groupId, String artifactId,
String version )
+ {
w.startElement( "dependency" );
w.startElement( "groupId" );
- w.writeText( "maven" );
+ w.writeText( groupId );
w.endElement();
w.startElement( "artifactId" );
- w.writeText( "maven-plugin" );
+ w.writeText( artifactId );
w.endElement();
w.startElement( "version" );
- w.writeText( "2.0-SNAPSHOT" );
-
- w.endElement();
-
- w.endElement();
+ w.writeText( version );
w.endElement();
w.endElement();
-
- writer.flush();
-
- writer.close();
}
protected String capitalise( String str )
1.2 +2 -11
maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/BeanGeneratorTest.java
Index: BeanGeneratorTest.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/BeanGeneratorTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BeanGeneratorTest.java 27 May 2004 01:58:26 -0000 1.1
+++ BeanGeneratorTest.java 27 May 2004 17:14:42 -0000 1.2
@@ -9,15 +9,6 @@
* @version $Id$
*/
public class BeanGeneratorTest
- extends TestCase
+ extends AbstractGeneratorTestCase
{
- 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.3 +3 -9
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PluginDescriptorGeneratorTest.java 20 May 2004 16:59:45 -0000 1.2
+++ PluginDescriptorGeneratorTest.java 27 May 2004 17:14:42 -0000 1.3
@@ -18,17 +18,11 @@
* @version $Id$
*/
public class PluginDescriptorGeneratorTest
- extends TestCase
+ extends AbstractGeneratorTestCase
{
- public void testPluginDescriptorCreationFromPluginSource()
+ protected void validate()
throws Exception
{
- String basedir = System.getProperty( "basedir" );
-
- PluginDescriptorGenerator pluggy = new PluginDescriptorGenerator();
-
- 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" );
1.3 +2 -13
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PluginXdocGeneratorTest.java 20 May 2004 16:59:45 -0000 1.2
+++ PluginXdocGeneratorTest.java 27 May 2004 17:14:42 -0000 1.3
@@ -1,23 +1,12 @@
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$
*/
public class PluginXdocGeneratorTest
- extends TestCase
+ extends AbstractGeneratorTestCase
{
- public void testPluginDescriptorCreationFromPluginSource()
- throws Exception
- {
- String basedir = System.getProperty( "basedir" );
-
- PluginXdocGenerator pluggy = new PluginXdocGenerator();
-
- pluggy.execute( new File( basedir, "src/test/resources/source" ).getPath(),
new File( basedir, "target" ).getPath() );
- }
}
1.1
maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/AbstractGeneratorTestCase.java
Index: AbstractGeneratorTestCase.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: AbstractGeneratorTestCase.java,v 1.1 2004/05/27 17:14:42 jvanzyl
Exp $
*/
public class AbstractGeneratorTestCase
extends TestCase
{
protected Generator generator;
protected String basedir;
protected void setUp()
throws Exception
{
basedir = System.getProperty( "basedir" );
}
public void testGenerator()
throws Exception
{
setupGenerator();
String sourceDirectory = new File( basedir, "src/test/resources/source"
).getPath();
String destinationDirectory = new File( basedir, "target" ).getPath();
String pom = new File( basedir, "project.xml" ).getPath();
generator.execute( sourceDirectory, destinationDirectory, pom );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
protected void setupGenerator()
throws Exception
{
String generatorClassName = getClass().getName();
generatorClassName = generatorClassName.substring( 0,
generatorClassName.length() - 4 );
try
{
Class generatorClass =
Thread.currentThread().getContextClassLoader().loadClass( generatorClassName );
generator = (Generator) generatorClass.newInstance();
}
catch ( Exception e )
{
throw new Exception(
"Cannot find " + generatorClassName + "! Make sure your test case is
named in the form ${generatorClassName}Test " +
"or override the setupPlugin() method to instantiate the mojo
yourself." );
}
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
protected void validate()
throws Exception
{
}
}
1.2 +3 -16
maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/jelly/JellyHarnessGeneratorTest.java
Index: JellyHarnessGeneratorTest.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-plugin/src/test/java/org/apache/maven/plugin/generator/jelly/JellyHarnessGeneratorTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JellyHarnessGeneratorTest.java 22 May 2004 14:58:41 -0000 1.1
+++ JellyHarnessGeneratorTest.java 27 May 2004 17:14:42 -0000 1.2
@@ -1,25 +1,12 @@
package org.apache.maven.plugin.generator.jelly;
-import junit.framework.TestCase;
-
-import java.io.File;
-
-import org.apache.maven.plugin.generator.jelly.JellyHarnessGenerator;
+import org.apache.maven.plugin.generator.AbstractGeneratorTestCase;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @version $Id$
*/
public class JellyHarnessGeneratorTest
- extends TestCase
+ extends AbstractGeneratorTestCase
{
- public void testPluginDescriptorCreationFromPluginSource()
- throws Exception
- {
- String basedir = System.getProperty( "basedir" );
-
- JellyHarnessGenerator pluggy = new JellyHarnessGenerator();
-
- pluggy.execute( new File( basedir, "src/test/resources/source" ).getPath(),
new File( basedir, "target" ).getPath() );
- }
}
1.5 +37 -19
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- IdeaPlugin.java 27 May 2004 01:58:26 -0000 1.4
+++ IdeaPlugin.java 27 May 2004 17:14:42 -0000 1.5
@@ -6,31 +6,49 @@
import org.apache.maven.plugin.PluginExecutionResponse;
/**
- * @maven.plugin.id compiler
+ * @maven.plugin.id idea
* @maven.plugin.description A maven2 plugin which integrates the use of Maven2
with IntelliJ's IDEA
*
- * @parameter sourceDirectory String required validator
- * @parameter outputDirectory String required validator
- * @parameter classpathElements String[] required validator
- * @parameter compiler String required validator
+ * @parameter project MavenProject true validator description
*
- * @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 idea
+ * @goal.idea.description Goal for generating IDEA files from a POM
+ * @goal.idea.parameter project #project
*
- * @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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]