Author: bentmann
Date: Sun Oct  4 11:22:41 2009
New Revision: 821512

URL: http://svn.apache.org/viewvc?rev=821512&view=rev
Log:
[MPLUGIN-148] PluginXdocGenerator generates poorly formed output when default 
values contain XML
Submitted by: Brent N Atkinson

o Enriched with test

Modified:
    
maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/src/main/java/org/MyMojo.java
    maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/verify.bsh
    
maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
    
maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
    
maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginXdocGeneratorTest.java

Modified: 
maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/src/main/java/org/MyMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/src/main/java/org/MyMojo.java?rev=821512&r1=821511&r2=821512&view=diff
==============================================================================
--- 
maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/src/main/java/org/MyMojo.java
 (original)
+++ 
maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/src/main/java/org/MyMojo.java
 Sun Oct  4 11:22:41 2009
@@ -51,7 +51,7 @@
     /**
      * This is a test.
      * 
-     * @parameter expression="${string}" default-value="${project.version}"
+     * @parameter expression="${string}" 
default-value="${project.version}/</markup-must-be-escaped>"
      * @deprecated Just testing.
      * @since 1.1
      */

Modified: 
maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/verify.bsh
URL: 
http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/verify.bsh?rev=821512&r1=821511&r2=821512&view=diff
==============================================================================
--- 
maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/verify.bsh 
(original)
+++ 
maven/plugin-tools/trunk/maven-plugin-plugin/src/it/plugin-report/verify.bsh 
Sun Oct  4 11:22:41 2009
@@ -20,7 +20,7 @@
     {
         File file = new File( siteDir, path );
         System.out.println( "Checking for existence of doc file: " + file );
-        if ( !file.isFile() )
+        if ( !file.isFile() || file.length() <= 0 )
         {
             System.out.println( "FAILED!" );
             return false;

Modified: 
maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
URL: 
http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java?rev=821512&r1=821511&r2=821512&view=diff
==============================================================================
--- 
maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
 (original)
+++ 
maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
 Sun Oct  4 11:22:41 2009
@@ -563,7 +563,8 @@
                 w.startElement( "ul" );
                 addedUl = true;
             }
-            writeDetail( getString( 
"pluginxdoc.mojodescriptor.parameter.default" ), parameter.getDefaultValue(), w 
);
+            writeDetail( getString( 
"pluginxdoc.mojodescriptor.parameter.default" ),
+                         escapeXml( parameter.getDefaultValue() ), w );
 
             if ( addedUl )
             {
@@ -696,7 +697,7 @@
             if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) )
             {
                 w.writeMarkup( format( 
"pluginxdoc.mojodescriptor.parameter.defaultValue",
-                                       parameter.getDefaultValue() ) );
+                                       escapeXml( parameter.getDefaultValue() 
) ) );
             }
             w.endElement(); //td
             w.endElement(); //tr
@@ -781,4 +782,22 @@
 
         return messageFormat.format( args );
     }
+
+    /**
+     * @param text the string to escape
+     * @return A string escaped with XML entities
+     */
+    private String escapeXml( String text )
+    {
+        if ( text != null )
+        {
+            text = text.replaceAll( "&", "&amp;" );
+            text = text.replaceAll( "<", "&lt;" );
+            text = text.replaceAll( ">", "&gt;" );
+            text = text.replaceAll( "\"", "&quot;" );
+            text = text.replaceAll( "\'", "&apos;" );
+        }
+        return text;
+    }
+
 }

Modified: 
maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
URL: 
http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java?rev=821512&r1=821511&r2=821512&view=diff
==============================================================================
--- 
maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
 (original)
+++ 
maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
 Sun Oct  4 11:22:41 2009
@@ -64,6 +64,7 @@
 
         Parameter param = new Parameter();
         param.setExpression( "${project.build.directory}" );
+        param.setDefaultValue( "</markup-must-be-escaped>" );
         param.setName( "dir" );
         param.setRequired( true );
         param.setType( "java.lang.String" );

Modified: 
maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginXdocGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginXdocGeneratorTest.java?rev=821512&r1=821511&r2=821512&view=diff
==============================================================================
--- 
maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginXdocGeneratorTest.java
 (original)
+++ 
maven/plugin-tools/trunk/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginXdocGeneratorTest.java
 Sun Oct  4 11:22:41 2009
@@ -19,6 +19,11 @@
  * under the License.
  */
 
+import java.io.File;
+
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+
 /**
  * @author <a href="mailto:ja...@maven.org";>Jason van Zyl </a>
  * @author <a href="mailto:vincent.sive...@gmail.com";>Vincent Siveton</a>
@@ -27,5 +32,16 @@
 public class PluginXdocGeneratorTest
     extends AbstractGeneratorTestCase
 {
+
     // inherits tests from base class
+
+    protected void validate( File destinationDirectory )
+        throws Exception
+    {
+        File docFile = new File( destinationDirectory, "testGoal-mojo.xml" );
+
+        // sanity check: is the output well-formed?
+        Xpp3DomBuilder.build( ReaderFactory.newXmlReader( docFile ) );
+    }
+
 }


Reply via email to