From c0a5ae7668a9786f17d4bf33383ef8a1d9aac633 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 17 Oct 2008 08:50:28 +0000 Subject: [PATCH] [MNG-3503] test for shading of plexus-utils pull parser classes git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@705515 13f79535-47bb-0310-9956-ffa450edef68 --- .../it/MavenITmng3503Xpp3ShadingTest.java | 51 ++--- .../mng-3503-xpp3Shading-pu-new/pom.xml | 24 +++ .../mng-3503-xpp3Shading-pu11/pom.xml | 24 +++ .../resources/mng-3503-xpp3Shading/pom.xml | 8 - .../mng-3503-xpp3Shading/src/site/site.xml | 62 ------ .../maven-it-plugin-plexus-utils-11/pom.xml | 29 +++ .../maven/its/plugins/SerializeMojo.java | 50 +++++ .../maven-it-plugin-plexus-utils-new/pom.xml | 29 +++ .../maven/its/plugins/SerializeMojo.java | 50 +++++ .../org/codehaus/plexus/util/xml/Xpp3Dom.java | 26 +++ .../plexus/util/xml/pull/MXSerializer.java | 180 ++++++++++++++++++ .../plexus/util/xml/pull/XmlSerializer.java | 79 ++++++++ its/core-it-support/core-it-plugins/pom.xml | 2 + 13 files changed, 513 insertions(+), 101 deletions(-) create mode 100644 its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/mng-3503-xpp3Shading-pu-new/pom.xml create mode 100644 its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/mng-3503-xpp3Shading-pu11/pom.xml delete mode 100644 its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/pom.xml delete mode 100644 its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/src/site/site.xml create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-11/pom.xml create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-11/src/main/java/org/apache/maven/its/plugins/SerializeMojo.java create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/pom.xml create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/apache/maven/its/plugins/SerializeMojo.java create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java create mode 100644 its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3503Xpp3ShadingTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3503Xpp3ShadingTest.java index 10ca1ef2db..86833ca132 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3503Xpp3ShadingTest.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3503Xpp3ShadingTest.java @@ -20,30 +20,25 @@ package org.apache.maven.it; */ import java.io.File; -import java.util.ArrayList; -import java.util.List; -import org.apache.maven.it.Verifier; +import org.apache.maven.it.util.FileUtils; import org.apache.maven.it.util.ResourceExtractor; /** * This is a test set for MNG-3503. - * - * @todo Fill in a better description of what this test verifies! - * - * @author Brian Fox - * @author jdcasey * + * The first test verifies that a plugin using plexus-utils-1.1 does not cause linkage errors. + * The second test verifies that a plugin with a different implementation of the shaded classes is used instead. */ public class MavenITmng3503Xpp3ShadingTest extends AbstractMavenIntegrationTestCase { public MavenITmng3503Xpp3ShadingTest() { - super( "(2.0.9,)" ); // only test in 2.0.9+ + super( "(2.0.9,2.1.0-M1),(2.1.0-M1,)" ); // only test in 2.0.9+, and not in 2.1.0-M1 } - public void testitMNG3503 () + public void testitMNG3503() throws Exception { // The testdir is computed from the location of this @@ -52,32 +47,26 @@ public class MavenITmng3503Xpp3ShadingTest Verifier verifier; - /* - * We must first make sure that any artifact created - * by this test has been removed from the local - * repository. Failing to do this could cause - * unstable test results. Fortunately, the verifier - * makes it easy to do this. - */ - verifier = new Verifier( testDir.getAbsolutePath() ); + File dir = new File( testDir, "mng-3503-xpp3Shading-pu11" ); + verifier = new Verifier( dir.getAbsolutePath() ); verifier.executeGoal( "install" ); - /* - * This is the simplest way to check a build - * succeeded. It is also the simplest way to create - * an IT test: make the build pass when the test - * should pass, and make the build fail when the - * test should fail. There are other methods - * supported by the verifier. They can be seen here: - * http://maven.apache.org/shared/maven-verifier/apidocs/index.html - */ verifier.verifyErrorFreeLog(); - /* - * Reset the streams before executing the verifier - * again. - */ verifier.resetStreams(); + + assertEquals( "", FileUtils.fileRead( new File( dir, "target/serialized.xml" ) ) ); + + dir = new File( testDir, "mng-3503-xpp3Shading-pu-new" ); + verifier = new Verifier( dir.getAbsolutePath() ); + + verifier.executeGoal( "install" ); + + verifier.verifyErrorFreeLog(); + + verifier.resetStreams(); + + assertEquals( "root", FileUtils.fileRead( new File( dir, "target/serialized.xml" ) ) ); } } diff --git a/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/mng-3503-xpp3Shading-pu-new/pom.xml b/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/mng-3503-xpp3Shading-pu-new/pom.xml new file mode 100644 index 0000000000..250a4507e5 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/mng-3503-xpp3Shading-pu-new/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + org.apache.maven.its.mng3503 + mng-3503-xpp3Shading-pu-new + jar + 1.0-SNAPSHOT + + + + org.apache.maven.its.plugins + maven-it-plugin-plexus-utils-new + 2.1-SNAPSHOT + + + + serialize + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/mng-3503-xpp3Shading-pu11/pom.xml b/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/mng-3503-xpp3Shading-pu11/pom.xml new file mode 100644 index 0000000000..32db9d3290 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/mng-3503-xpp3Shading-pu11/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + org.apache.maven.its.mng3503 + mng-3503-xpp3Shading-pu11 + jar + 1.0-SNAPSHOT + + + + org.apache.maven.its.plugins + maven-it-plugin-plexus-utils-11 + 2.1-SNAPSHOT + + + + serialize + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/pom.xml b/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/pom.xml deleted file mode 100644 index aeac172d51..0000000000 --- a/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/pom.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - 4.0.0 - testing - mng-3503-xpp3Shading - 1.0-SNAPSHOT - pom - diff --git a/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/src/site/site.xml b/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/src/site/site.xml deleted file mode 100644 index f467b5a37d..0000000000 --- a/its/core-it-suite/src/test/resources/mng-3503-xpp3Shading/src/site/site.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - Doxia - images/apache-maven-project-2.png - - - images/maven-logo-2.gif - - - - org.apache.maven.skins - maven-stylus-skin - 1.0.1 - - - - - - - - - - - - - - - - - - - - - - diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-11/pom.xml b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-11/pom.xml new file mode 100644 index 0000000000..0243433347 --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-11/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + maven-it-plugins + org.apache.maven.its.plugins + 2.1-SNAPSHOT + + maven-it-plugin-plexus-utils-11 + maven-plugin + + + org.codehaus.plexus + plexus-utils + 1.1 + + + org.apache.maven + maven-plugin-api + 2.0 + + + junit + junit + 3.8.1 + test + + + diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-11/src/main/java/org/apache/maven/its/plugins/SerializeMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-11/src/main/java/org/apache/maven/its/plugins/SerializeMojo.java new file mode 100644 index 0000000000..b681fa7af8 --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-11/src/main/java/org/apache/maven/its/plugins/SerializeMojo.java @@ -0,0 +1,50 @@ +package org.apache.maven.its.plugins; + +import java.io.FileWriter; +import java.io.IOException; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.pull.MXSerializer; +import org.codehaus.plexus.util.xml.pull.XmlSerializer; + +/** + * @goal serialize + * @phase package + */ +public class SerializeMojo + extends AbstractMojo +{ + + /** + * @parameter default-value="${project.build.directory}/serialized.xml" + */ + private String filename; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + FileWriter writer = null; + XmlSerializer s = new MXSerializer(); + try + { + writer = new FileWriter( filename ); + s.setOutput( writer ); + + Xpp3Dom dom = new Xpp3Dom( "root" ); + + dom.writeToSerializer( "", s ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + finally + { + IOUtil.close( writer ); + } + } +} diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/pom.xml b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/pom.xml new file mode 100644 index 0000000000..b6f783c151 --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + maven-it-plugins + org.apache.maven.its.plugins + 2.1-SNAPSHOT + + maven-it-plugin-plexus-utils-new + maven-plugin + + + commons-io + commons-io + 1.4 + + + org.apache.maven + maven-plugin-api + 2.0 + + + junit + junit + 3.8.1 + test + + + diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/apache/maven/its/plugins/SerializeMojo.java b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/apache/maven/its/plugins/SerializeMojo.java new file mode 100644 index 0000000000..ff49ebf873 --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/apache/maven/its/plugins/SerializeMojo.java @@ -0,0 +1,50 @@ +package org.apache.maven.its.plugins; + +import java.io.FileWriter; +import java.io.IOException; + +import org.apache.commons.io.IOUtils; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.pull.MXSerializer; +import org.codehaus.plexus.util.xml.pull.XmlSerializer; + +/** + * @goal serialize + * @phase package + */ +public class SerializeMojo + extends AbstractMojo +{ + + /** + * @parameter default-value="${project.build.directory}/serialized.xml" + */ + private String filename; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + FileWriter writer = null; + XmlSerializer s = new MXSerializer(); + try + { + writer = new FileWriter( filename ); + s.setOutput( writer ); + + Xpp3Dom dom = new Xpp3Dom( "root" ); + + dom.writeToSerializer( "", s ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + finally + { + IOUtils.closeQuietly( writer ); + } + } +} diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java new file mode 100644 index 0000000000..32fc7b676f --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java @@ -0,0 +1,26 @@ +package org.codehaus.plexus.util.xml; + +import java.io.IOException; + +import org.codehaus.plexus.util.xml.pull.XmlSerializer; + +public class Xpp3Dom +{ + + private String root; + + public Xpp3Dom( String root ) + { + this.root = root; + } + + public void writeToSerializer( String namespace, XmlSerializer s ) + throws IOException + { + s.startDocument( "UTF-8", Boolean.FALSE ); + s.startTag( namespace, root ); + s.endTag( namespace, root ); + s.endDocument(); + } + +} diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java new file mode 100644 index 0000000000..4c07387ac5 --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java @@ -0,0 +1,180 @@ +package org.codehaus.plexus.util.xml.pull; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; + +public class MXSerializer + implements XmlSerializer +{ + private Writer output; + + public void setOutput( Writer writer ) + { + output = writer; + } + + public XmlSerializer attribute( String namespace, String name, String value ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + return null; + } + + public void cdsect( String text ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void comment( String text ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void docdecl( String text ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void endDocument() + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public XmlSerializer endTag( String namespace, String name ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + return null; + } + + public void entityRef( String text ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void flush() + throws IOException + { + // TODO Auto-generated method stub + + } + + public int getDepth() + { + // TODO Auto-generated method stub + return 0; + } + + public boolean getFeature( String name ) + { + // TODO Auto-generated method stub + return false; + } + + public String getName() + { + // TODO Auto-generated method stub + return null; + } + + public String getNamespace() + { + // TODO Auto-generated method stub + return null; + } + + public String getPrefix( String namespace, boolean generatePrefix ) + throws IllegalArgumentException + { + // TODO Auto-generated method stub + return null; + } + + public Object getProperty( String name ) + { + // TODO Auto-generated method stub + return null; + } + + public void ignorableWhitespace( String text ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void processingInstruction( String text ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void setFeature( String name, boolean state ) + throws IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void setOutput( OutputStream os, String encoding ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void setPrefix( String prefix, String namespace ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void setProperty( String name, Object value ) + throws IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public void startDocument( String encoding, Boolean standalone ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + + } + + public XmlSerializer startTag( String namespace, String name ) + throws IOException, IllegalArgumentException, IllegalStateException + { + output.write( name ); + + return this; + } + + public XmlSerializer text( String text ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + return null; + } + + public XmlSerializer text( char[] buf, int start, int len ) + throws IOException, IllegalArgumentException, IllegalStateException + { + // TODO Auto-generated method stub + return null; + } +} diff --git a/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java new file mode 100644 index 0000000000..2467afa528 --- /dev/null +++ b/its/core-it-support/core-it-plugins/maven-it-plugin-plexus-utils-new/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java @@ -0,0 +1,79 @@ +package org.codehaus.plexus.util.xml.pull; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; + +public interface XmlSerializer +{ + + void setFeature( String name, boolean state ) + throws IllegalArgumentException, IllegalStateException; + + boolean getFeature( String name ); + + void setProperty( String name, Object value ) + throws IllegalArgumentException, IllegalStateException; + + Object getProperty( String name ); + + void setOutput( OutputStream os, String encoding ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void setOutput( Writer writer ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void startDocument( String encoding, Boolean standalone ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void endDocument() + throws IOException, IllegalArgumentException, IllegalStateException; + + void setPrefix( String prefix, String namespace ) + throws IOException, IllegalArgumentException, IllegalStateException; + + String getPrefix( String namespace, boolean generatePrefix ) + throws IllegalArgumentException; + + int getDepth(); + + String getNamespace(); + + String getName(); + + XmlSerializer startTag( String namespace, String name ) + throws IOException, IllegalArgumentException, IllegalStateException; + + XmlSerializer attribute( String namespace, String name, String value ) + throws IOException, IllegalArgumentException, IllegalStateException; + + XmlSerializer endTag( String namespace, String name ) + throws IOException, IllegalArgumentException, IllegalStateException; + + XmlSerializer text( String text ) + throws IOException, IllegalArgumentException, IllegalStateException; + + XmlSerializer text( char[] buf, int start, int len ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void cdsect( String text ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void entityRef( String text ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void processingInstruction( String text ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void comment( String text ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void docdecl( String text ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void ignorableWhitespace( String text ) + throws IOException, IllegalArgumentException, IllegalStateException; + + void flush() + throws IOException; +} diff --git a/its/core-it-support/core-it-plugins/pom.xml b/its/core-it-support/core-it-plugins/pom.xml index 9938a65a22..452c4cfc5f 100644 --- a/its/core-it-support/core-it-plugins/pom.xml +++ b/its/core-it-support/core-it-plugins/pom.xml @@ -57,6 +57,8 @@ under the License. maven-it-plugin-uses-properties maven-it-plugin-uses-wagon maven-it-plugin-all + maven-it-plugin-plexus-utils-11 + maven-it-plugin-plexus-utils-new