You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2008/02/02 15:42:59 UTC

svn commit: r617807 - in /maven/plugin-tools/trunk/maven-plugin-tools-api: pom.xml src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java src/test/java/org/apache/maven/tools/plugin/generator/PluginXdocGeneratorTest.java

Author: vsiveton
Date: Sat Feb  2 06:42:59 2008
New Revision: 617807

URL: http://svn.apache.org/viewvc?rev=617807&view=rev
Log:
MPLUGIN-43: Adding validation in PluginXdocGenerator class?

o used jtidy to make HTML valid the javadoc comments from mojo/parameter description

Modified:
    maven/plugin-tools/trunk/maven-plugin-tools-api/pom.xml
    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/PluginXdocGeneratorTest.java

Modified: maven/plugin-tools/trunk/maven-plugin-tools-api/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-api/pom.xml?rev=617807&r1=617806&r2=617807&view=diff
==============================================================================
--- maven/plugin-tools/trunk/maven-plugin-tools-api/pom.xml (original)
+++ maven/plugin-tools/trunk/maven-plugin-tools-api/pom.xml Sat Feb  2 06:42:59 2008
@@ -42,5 +42,10 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
     </dependency>
+    <dependency>
+      <groupId>jtidy</groupId>
+      <artifactId>jtidy</artifactId>
+      <version>4aug2000r7-dev</version>
+    </dependency>
   </dependencies>
 </project>

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=617807&r1=617806&r2=617807&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 Sat Feb  2 06:42:59 2008
@@ -19,13 +19,6 @@
  * under the License.
  */
 
-import org.apache.maven.plugin.descriptor.MojoDescriptor;
-import org.apache.maven.plugin.descriptor.Parameter;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -33,6 +26,16 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.Parameter;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringInputStream;
+import org.codehaus.plexus.util.StringOutputStream;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.XMLWriter;
+import org.w3c.tidy.Tidy;
+
 /**
  * @todo add example usage tag that can be shown in the doco
  * @version $Id$
@@ -109,7 +112,7 @@
 
         if ( mojoDescriptor.getDescription() != null )
         {
-            w.writeMarkup( mojoDescriptor.getDescription() );
+            w.writeMarkup( makeHtmlValid( mojoDescriptor.getDescription() ) );
         }
         else
         {
@@ -193,8 +196,8 @@
         if ( StringUtils.isNotEmpty( value ) )
         {
             w.startElement( "li" );
-            w.writeMarkup(
-                "Invokes the execution of the lifecycle phase <code>" + value + "</code> prior to executing itself." );
+            w.writeMarkup( "Invokes the execution of the lifecycle phase <code>" + value
+                + "</code> prior to executing itself." );
             w.endElement(); //li
         }
 
@@ -202,8 +205,8 @@
         if ( StringUtils.isNotEmpty( value ) )
         {
             w.startElement( "li" );
-            w.writeMarkup(
-                "Invokes the execution of this plugin's goal <code>" + value + "</code> prior to executing itself." );
+            w.writeMarkup( "Invokes the execution of this plugin's goal <code>" + value
+                + "</code> prior to executing itself." );
             w.endElement(); //li
         }
 
@@ -290,6 +293,10 @@
             {
                 description = "No Description.";
             }
+            else
+            {
+                description = makeHtmlValid( description );
+            }
             w.startElement( "p" );
             w.writeMarkup( description );
             w.endElement(); //p
@@ -420,6 +427,10 @@
             {
                 description = "No description.";
             }
+            else
+            {
+                description = makeHtmlValid( description );
+            }
             if ( StringUtils.isNotEmpty( parameter.getDeprecated() ) )
             {
                 description = "<b>Deprecated</b>. " + description;
@@ -455,5 +466,41 @@
         }
 
         return list;
+    }
+
+    /**
+     * @param description Javadoc description with HTML tags
+     * @return the description with valid HTML tags
+     */
+    protected static String makeHtmlValid( String description )
+    {
+        if ( StringUtils.isEmpty( description ) )
+        {
+            return "";
+        }
+
+        StringOutputStream out = new StringOutputStream();
+
+        // Using jTidy to clean comment
+        Tidy tidy = new Tidy();
+        tidy.setDocType( "loose" );
+        tidy.setXHTML( true );
+        tidy.setXmlOut( true );
+        tidy.setMakeClean( true );
+        tidy.setQuiet( true );
+        tidy.setShowWarnings( false );
+        tidy.parse( new StringInputStream( description ), out );
+
+        // strip the header/body stuff
+        String LS = System.getProperty( "line.separator" );
+        String commentCleaned = out.toString();
+        if ( StringUtils.isEmpty( commentCleaned ) )
+        {
+            return "";
+        }
+        int startPos = commentCleaned.indexOf( "<body>" + LS ) + 6 + LS.length();
+        int endPos = commentCleaned.indexOf( LS + "</body>" );
+
+        return commentCleaned.substring( startPos, endPos );
     }
 }

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=617807&r1=617806&r2=617807&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 Sat Feb  2 06:42:59 2008
@@ -21,10 +21,24 @@
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
- * @version $Id: PluginXdocGeneratorTest.java,v 1.1 2005/02/20 16:25:21 jdcasey
- *          Exp $
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
  */
 public class PluginXdocGeneratorTest
     extends AbstractGeneratorTestCase
 {
+    public void testMakeHtmlValid()
+    {
+        String javadoc = "";
+        assertEquals( "", PluginXdocGenerator.makeHtmlValid( javadoc ) );
+
+        // true HTML
+        javadoc = "Generates <i>something</i> for the project.";
+        assertEquals( "Generates <i>something</i> for the project.", PluginXdocGenerator.makeHtmlValid( javadoc ) );
+
+        // wrong HTML
+        javadoc = "Generates <i>something</i> <b> for the project.";
+        assertEquals( "Generates <i>something</i> <b> for the project.</b>", PluginXdocGenerator
+            .makeHtmlValid( javadoc ) );
+    }
 }