diff --git a/maven-plugin-tools-java/pom.xml b/maven-plugin-tools-java/pom.xml index d9fbbd7..1afba00 100644 --- a/maven-plugin-tools-java/pom.xml +++ b/maven-plugin-tools-java/pom.xml @@ -68,6 +68,13 @@ qdox 1.11 + + + xmlunit + xmlunit + 1.3 + test + diff --git a/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java b/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java index 748febe..7b82ddf 100644 --- a/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java +++ b/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java @@ -33,6 +33,9 @@ import org.apache.maven.tools.plugin.generator.Generator; import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator; import org.codehaus.plexus.component.repository.ComponentDependency; import org.codehaus.plexus.util.FileUtils; +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.XMLUnit; +import org.w3c.dom.Document; import java.io.File; import java.net.URL; @@ -84,6 +87,9 @@ public class JavaMojoDescriptorExtractorTest return new DefaultPluginToolsRequest( project, pluginDescriptor ).setEncoding( "UTF-8" ); } + /** + * generate plugin.xml for a test resources directory content. + */ protected PluginDescriptor generate( String directory ) throws Exception { @@ -104,11 +110,42 @@ public class JavaMojoDescriptorExtractorTest return request.getPluginDescriptor(); } + /** + * compare mojos from generated plugin.xml against plugin-expected.xml + */ + protected void checkExpected( String directory ) + throws Exception + { + File testDirectory = new File( root, directory ); + + XMLUnit.setIgnoreWhitespace( true ); + XMLUnit.setIgnoreComments( true ); + + Document expected = + XMLUnit.buildControlDocument( FileUtils.fileRead( new File( testDirectory, "plugin-expected.xml" ), "UTF-8" ) ); + Document actual = + XMLUnit.buildTestDocument( FileUtils.fileRead( new File( testDirectory, "plugin.xml" ), "UTF-8" ) ); + + Diff diff = XMLUnit.compareXML( expected, actual ); + + if ( !diff.identical() ) + { + fail( "generated plugin.xml is not identital as plugin-expected.xml for " + directory + ": " + diff ); + } + } + + /** + * extract plugin descriptor for test resources directory and check against plugin-expected.xml + */ @SuppressWarnings( "unchecked" ) protected List extract( String directory ) throws Exception { - return generate( directory ).getMojos(); + PluginDescriptor descriptor = generate( directory ); + + checkExpected( directory ); + + return descriptor.getMojos(); } public void testShouldFindTwoMojoDescriptorsInTestSourceDirectory() diff --git a/maven-plugin-tools-java/src/test/resources/java-1.5/plugin-expected.xml b/maven-plugin-tools-java/src/test/resources/java-1.5/plugin-expected.xml new file mode 100644 index 0000000..51c0c83 --- /dev/null +++ b/maven-plugin-tools-java/src/test/resources/java-1.5/plugin-expected.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + test + false + true + + + test + Test for gleaning of source files with Java 1.5 features + false + true + false + false + false + true + MyMojo + java + per-lookup + once-per-session + false + + + + + \ No newline at end of file diff --git a/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml b/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml new file mode 100644 index 0000000..e432db8 --- /dev/null +++ b/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + test + false + true + + + ideaTwo + Create an IDEA project file from a Maven project. + compile + false + true + false + false + false + true + source.JavaExtractorTestTwo + java + per-lookup + once-per-session + false + + + project + java.lang.String[] + true + true + Maven project used to generate IDEA project files. + + + + + ideaOne + Create an IDEA project file from a Maven project. + runtime + false + true + false + false + false + true + source.JavaExtractorTestOne + java + per-lookup + once-per-session + false + + + project + java.lang.String[] + true + true + Maven project used to generate IDEA project files. + + + + + + \ No newline at end of file diff --git a/maven-plugin-tools-java/src/test/resources/source2/plugin-expected.xml b/maven-plugin-tools-java/src/test/resources/source2/plugin-expected.xml new file mode 100644 index 0000000..80170a1 --- /dev/null +++ b/maven-plugin-tools-java/src/test/resources/source2/plugin-expected.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + test + false + true + + + ideaThree + Tests the implementation argument of the parameter annotation. + compile + false + true + false + false + false + true + source2.JavaExtractorTestThree + java + per-lookup + once-per-session + test + true + + + bla + source2.Bla + source2.sub.MyBla + true + true + + + + + + + \ No newline at end of file diff --git a/maven-plugin-tools-java/src/test/resources/source3/plugin-expected.xml b/maven-plugin-tools-java/src/test/resources/source3/plugin-expected.xml new file mode 100644 index 0000000..4234096 --- /dev/null +++ b/maven-plugin-tools-java/src/test/resources/source3/plugin-expected.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + test + false + true + + + \ No newline at end of file