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 2009/07/06 14:29:47 UTC

svn commit: r791460 - in /maven/plugins/trunk/maven-javadoc-plugin/src: main/java/org/apache/maven/plugin/javadoc/ site/apt/examples/ test/java/org/apache/maven/plugin/javadoc/ test/resources/unit/fix-test/src/main/java/fix/test/

Author: vsiveton
Date: Mon Jul  6 12:29:47 2009
New Revision: 791460

URL: http://svn.apache.org/viewvc?rev=791460&view=rev
Log:
o add more test cases

Modified:
    maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
    maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt
    maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
    maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java

Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java?rev=791460&r1=791459&r2=791460&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java Mon Jul  6 12:29:47 2009
@@ -3107,37 +3107,36 @@
         String[] docletTagLines = getLines( docletTag.getValue() );
 
         StringBuffer sb = new StringBuffer();
-        for ( int i = 0; i < docletTagLines.length; i++ )
+        int start = 0;
+        int end = originalJavadocLines.length;
+        for ( int i = 0; i < originalJavadocLines.length; i++ )
         {
-            boolean found = false;
-            for ( int j = 0; j < originalJavadocLines.length; j++ )
-            {
-                String line = originalJavadocLines[j];
+            String originalJavadocLine = originalJavadocLines[i];
 
-                if ( line.indexOf( "@" + docletTag.getName() ) != -1 )
+            if ( JAVADOC_TAG_LINE_PATTERN.matcher( originalJavadocLine ).find() )
+            {
+                if ( start != 0 )
                 {
-                    found = true;
+                    end = i;
+                    break;
                 }
-                if ( found
-                    && StringUtils.removeDuplicateWhitespace( line ).trim()
-                                  .endsWith( StringUtils.removeDuplicateWhitespace( docletTagLines[i] ).trim() ) )
+
+                if ( originalJavadocLine.indexOf( docletTagLines[0] ) != -1 )
                 {
-                    sb.append( line );
-                    sb.append( EOL );
-                    if ( docletTag.getParameters().length == 1 )
-                    {
-                        break;
-                    }
+                    start = i;
                 }
             }
         }
 
-        if ( sb.toString().lastIndexOf( EOL ) != -1 )
+        for ( int i = start; i < end; i++ )
         {
-            return sb.toString().substring( 0, sb.toString().lastIndexOf( EOL ) );
+            String originalJavadocLine = originalJavadocLines[i];
+
+            sb.append( originalJavadocLine );
+            sb.append( EOL );
         }
 
-        return sb.toString();
+        return trimRight( sb.toString() );
     }
 
     /**

Modified: maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt?rev=791460&r1=791459&r2=791460&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/fix-javadocs.apt Mon Jul  6 12:29:47 2009
@@ -38,7 +38,7 @@
  a SCM, so you could always do a revert if a problem occurs. You could always add <<<-DoutputDirectory=/path/to/dir>>>
  to specify a target directory where classes will be generated.
 
-* Feature Summary
+* Features Summary
 
  The user could skip the class/field/method Javadoc fixing using specific parameters, i.e.
  {{{../fix-mojo.html#fixClassComment}fixClassComment}}.
@@ -57,6 +57,16 @@
  Finally, the user could process specific Java files using the
  {{{../fix-mojo.html#includes}includes}}/{{{../fix-mojo.html#excludes}excludes}} parameters.
 
+** Current limitations
+
+ The <fix> and <test-fix> goals use intensively {{{http://qdox.codehaus.org/}Qdox}} to extract class/interface/method
+ Javadoc from source files. Unfortunately, Qdox has {{{http://jira.codehaus.org/browse/QDOX}some known issues}}, some
+ of them could be blocker for your source files:
+
+ * {{{http://jira.codehaus.org/browse/QDOX-154}QDOX-154}}: JavaMethod#getComment() is parsed with an implicit order
+
+ []
+
 * Example Call
 
 +-----+
@@ -126,4 +136,5 @@
       </plugin>
     </plugins>
   </build>
-</project>
\ No newline at end of file
+</project>
++-----+

Modified: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java?rev=791460&r1=791459&r2=791460&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java Mon Jul  6 12:29:47 2009
@@ -25,6 +25,7 @@
 import java.io.PrintStream;
 import java.io.Reader;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
@@ -79,21 +80,6 @@
         M2_HOME = new File( mavenHome );
     }
 
-    /** {@inheritDoc} */
-    protected void setUp()
-        throws Exception
-    {
-        // required for mojo lookups to work
-        super.setUp();
-    }
-
-    /** {@inheritDoc} */
-    protected void tearDown()
-        throws Exception
-    {
-        super.tearDown();
-    }
-
     /**
      * @throws Exception if any
      */
@@ -108,11 +94,8 @@
         assertTrue( testPom.getAbsolutePath() + " should exist", testPom.exists() );
 
         // compile the test project
-        if ( !new File( testPom.getParentFile(), "target" ).exists() )
-        {
-            invokeCompileGoal( testPom );
-            assertTrue( new File( testPomBasedir, "target/classes" ).exists() );
-        }
+        invokeCompileGoal( testPom );
+        assertTrue( new File( testPomBasedir, "target/classes" ).exists() );
 
         FixJavadocMojo mojo = (FixJavadocMojo) lookupMojo( "fix", testPom );
         assertNotNull( mojo );
@@ -146,6 +129,11 @@
                 "    private static final String MY_PRIVATE_CONSTANT = \"\";" ) != -1 );
         assertTrue( content.indexOf( "" + EOL +
                 "    /**" + EOL +
+                "     * <p>Constructor for ClassWithJavadoc.</p>" + EOL +
+                "     */" + EOL +
+                "    public ClassWithJavadoc()" ) != -1 );
+        assertTrue( content.indexOf( "" + EOL +
+                "    /**" + EOL +
                 "     * <p>main</p>" + EOL +
                 "     *" + EOL +
                 "     * @param args an array of {@link java.lang.String} objects." + EOL +
@@ -163,11 +151,39 @@
                 "    public String methodWithMissingParameters( String str, boolean b, int i )" ) != -1 );
         assertTrue( content.indexOf( "" + EOL +
                 "    /**" + EOL +
+                "     * <p>methodWithMissingParameters2</p>" + EOL +
+                "     *" + EOL +
+                "     * @param str a {@link java.lang.String} object." + EOL +
+                "     * @throws java.lang.UnsupportedOperationException if any" + EOL +
+                "     * @param b a boolean." + EOL +
+                "     * @param i a int." + EOL +
+                "     * @return a {@link java.lang.String} object." + EOL +
+                "     */" + EOL +
+                "    public String methodWithMissingParameters2( String str, boolean b, int i )" ) != -1 );
+        assertTrue( content.indexOf( "" + EOL +
+                "    /**" + EOL +
                 "     * <p>methodWithWrongJavadocParameters</p>" + EOL +
                 "     *" + EOL +
                 "     * @param aString a {@link java.lang.String} object." + EOL +
                 "     */" + EOL +
                 "    public void methodWithWrongJavadocParameters( String aString )" ) != -1 );
+        assertTrue( content.indexOf( "" + EOL +
+                "    /**" + EOL +
+                "     * <p>methodWithMultiLinesJavadoc</p>" + EOL +
+                "     *" + EOL +
+                "     * @param aString" + EOL +
+                "     *      a string" + EOL +
+                "     * @param anotherString" + EOL +
+                "     *      with" + EOL +
+                "     *      multi" + EOL +
+                "     *      line" + EOL +
+                "     *      comments" + EOL +
+                "     * @param aString" + EOL +
+                "     *      a string" + EOL +
+                "     * @throws java.lang.UnsupportedOperationException" + EOL +
+                "     *      if any" + EOL +
+                "     */" + EOL +
+                "    public String methodWithMultiLinesJavadoc( String aString, String anotherString )" ) != -1 );
 
         clazzFile = new File( packageDir, "ClassWithNoJavadoc.java" );
         assertTrue( clazzFile.exists() );
@@ -277,28 +293,22 @@
             InvocationResult result = invoker.execute( request );
             if ( result.getExitCode() != 0 )
             {
-                if ( getContainer().getLogger().isDebugEnabled() )
-                {
-                    StringBuffer msg = new StringBuffer();
-                    msg.append( "Ouput from invoker:" ).append( "\n\n" );
-                    msg.append( invokerLog ).append( "\n\n" );
+                StringBuffer msg = new StringBuffer();
+                msg.append( "Ouput from invoker:" ).append( "\n\n" );
+                msg.append( invokerLog ).append( "\n\n" );
 
-                    getContainer().getLogger().debug( msg.toString() );
-                }
+                getContainer().getLogger().error( msg.toString() );
 
                 fail( "Error when invoking Maven, see invoker log above" );
             }
         }
         catch ( MavenInvocationException e )
         {
-            if ( getContainer().getLogger().isDebugEnabled() )
-            {
-                StringBuffer msg = new StringBuffer();
-                msg.append( "Ouput from invoker:" ).append( "\n\n" );
-                msg.append( invokerLog ).append( "\n\n" );
+            StringBuffer msg = new StringBuffer();
+            msg.append( "Ouput from invoker:" ).append( "\n\n" );
+            msg.append( invokerLog ).append( "\n\n" );
 
-                getContainer().getLogger().debug( msg.toString() );
-            }
+            getContainer().getLogger().error( msg.toString() );
 
             fail( "Error when invoking Maven, see invoker log above" );
         }
@@ -316,6 +326,16 @@
         // Using unit test dir
         FileUtils.copyDirectoryStructure( new File( getBasedir(), "src/test/resources/unit/" + testDir ),
                                           testPomBasedir );
+        List scmFiles = FileUtils.getDirectoryNames( testPomBasedir, "**/.svn", null, true );
+        for ( Iterator it = scmFiles.iterator(); it.hasNext(); )
+        {
+            File dir = new File( it.next().toString() );
+
+            if ( dir.isDirectory() )
+            {
+                FileUtils.deleteDirectory( dir );
+            }
+        }
     }
 
     /**

Modified: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java?rev=791460&r1=791459&r2=791460&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java Mon Jul  6 12:29:47 2009
@@ -32,6 +32,11 @@
 
     private static final String MY_PRIVATE_CONSTANT = "";
 
+    public ClassWithJavadoc()
+    {
+        // nop
+    }
+
     public static void main( String[] args )
     {
         System.out.println( "Sample Application." );
@@ -47,8 +52,37 @@
 
     /**
      * @param str
+     * @throws UnsupportedOperationException if any
+     */
+    public String methodWithMissingParameters2( String str, boolean b, int i )
+        throws UnsupportedOperationException
+    {
+        return null;
+    }
+
+    /**
+     * @param str
      */
     public void methodWithWrongJavadocParameters( String aString )
     {
     }
+
+    /**
+     * @param aString
+     *      a string
+     * @param anotherString
+     *      with
+     *      multi
+     *      line
+     *      comments
+     * @return a
+     *      String
+     * @throws UnsupportedOperationException
+     *      if any
+     */
+    public String methodWithMultiLinesJavadoc( String aString, String anotherString )
+        throws UnsupportedOperationException
+    {
+        return null;
+    }
 }