maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r590989 - in /maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src: main/java/org/apache/maven/jxr/java/doc/XMLDoclet.java test/java/org/apache/maven/jxr/java/doc/XMLDocletTest.java
Date Thu, 01 Nov 2007 13:09:54 GMT
Author: vsiveton
Date: Thu Nov  1 06:09:53 2007
New Revision: 590989

URL: http://svn.apache.org/viewvc?rev=590989&view=rev
Log:
o updated test cases and javadoc

Modified:
    maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/doc/XMLDoclet.java
    maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/test/java/org/apache/maven/jxr/java/doc/XMLDocletTest.java

Modified: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/doc/XMLDoclet.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/doc/XMLDoclet.java?rev=590989&r1=590988&r2=590989&view=diff
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/doc/XMLDoclet.java
(original)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/main/java/org/apache/maven/jxr/java/doc/XMLDoclet.java
Thu Nov  1 06:09:53 2007
@@ -61,15 +61,15 @@
 public class XMLDoclet
     extends Doclet
 {
-    /**
-     * The specified DTD for the generated Javadoc XML.
-     */
+    /** The specified DTD for the generated Javadoc XML. */
     public static final String XMLDOCLET_DTD = "javadoc-v04draft.dtd";
 
-    private static final String USAGE = "Usage: javadoc <-xmlencoding ISO-8859-1> "
+    /** The Doclet usage. */
+    protected static final String USAGE = "Usage: javadoc <-xmlencoding ISO-8859-1>
"
         + "-o /path/to/generatedXmlFile -doclet org.apache.maven.jxr.java.doc.XMLDoclet ...";
 
-    private static final String DEFAULT_ENCODING_FORMAT = "ISO-8859-1";
+    /** Default encoding format for the generated XML. */
+    protected static final String DEFAULT_ENCODING_FORMAT = "ISO-8859-1";
 
     private String xmlns = "";
 

Modified: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/test/java/org/apache/maven/jxr/java/doc/XMLDocletTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/test/java/org/apache/maven/jxr/java/doc/XMLDocletTest.java?rev=590989&r1=590988&r2=590989&view=diff
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/test/java/org/apache/maven/jxr/java/doc/XMLDocletTest.java
(original)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-java/src/test/java/org/apache/maven/jxr/java/doc/XMLDocletTest.java
Thu Nov  1 06:09:53 2007
@@ -20,6 +20,8 @@
  */
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Iterator;
@@ -29,6 +31,7 @@
 import junit.framework.TestCase;
 
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 
 import com.sun.tools.javadoc.Main;
@@ -62,25 +65,80 @@
         args.add( "-package" );
         args.add( "-sourcepath" );
         args.add( srcDir.getAbsolutePath() );
+        args.add( "-xmlencoding" );
+        args.add( "UTF-8" );
         args.add( "-o" );
         args.add( outputXML.getAbsolutePath() );
-        List packages = FileUtils.getDirectoryNames( srcDir, null, DEFAULT_EXCLUDES, false
);
-        for ( Iterator it = packages.iterator(); it.hasNext(); )
-        {
-            String p = (String) it.next();
 
-            if ( StringUtils.isEmpty( p ) )
-            {
-                continue;
-            }
+        addPackages( args, srcDir );
 
-            if ( FileUtils.getFileNames( new File( srcDir, p ), "*.java", "", false ).isEmpty()
)
-            {
-                continue;
-            }
+        StringWriter err = new StringWriter();
+        StringWriter warn = new StringWriter();
+        StringWriter notice = new StringWriter();
+        int exit = Main.execute( "javadoc", new PrintWriter( err ), new PrintWriter( warn
), new PrintWriter( notice ),
+                                 XMLDoclet.class.getName(), (String[]) args.toArray( new
String[0] ) );
 
-            args.add( StringUtils.replace( p, File.separator, "." ) );
-        }
+        assertEquals( err.toString(), exit, 0 );
+
+        // Generated files
+        assertTrue( outputXML.exists() );
+        assertTrue( outputXML.length() > 0 );
+        String content = IOUtil.toString( new FileInputStream( outputXML ) );
+        assertTrue( content.indexOf( "\"UTF-8\"" ) != -1 );
+        File dtd = new File( BASEDIR, "target/unit/xmldoclet-default/" + XMLDoclet.XMLDOCLET_DTD
);
+        assertTrue( dtd.exists() );
+        assertTrue( dtd.length() > 0 );
+    }
+
+    /**
+     * Call Javadoc tool with XML doclet without out option.
+     *
+     * @throws Exception if any
+     */
+    public void testMissingOptionsExecute()
+        throws Exception
+    {
+        File srcDir = new File( BASEDIR, "src/test/resources/javasrc" );
+
+        // test phase is after compile phase, so we are sure that classes dir exists
+        List args = new LinkedList();
+        args.add( "-package" );
+        args.add( "-sourcepath" );
+        args.add( srcDir.getAbsolutePath() );
+
+        addPackages( args, srcDir );
+
+        StringWriter err = new StringWriter();
+        StringWriter warn = new StringWriter();
+        StringWriter notice = new StringWriter();
+        int exit = Main.execute( "javadoc", new PrintWriter( err ), new PrintWriter( warn
), new PrintWriter( notice ),
+                                 XMLDoclet.class.getName(), (String[]) args.toArray( new
String[0] ) );
+
+        assertEquals( err.toString(), exit, 1 );
+        assertTrue( err.toString().indexOf( XMLDoclet.USAGE ) != -1 );
+    }
+
+    /**
+     * Call Javadoc tool with XML doclet and non mandatory option.
+     *
+     * @throws Exception if any
+     */
+    public void testNonMandatoryOptionExecute()
+        throws Exception
+    {
+        File srcDir = new File( BASEDIR, "src/test/resources/javasrc" );
+
+        File outputXML = new File( BASEDIR, "target/unit/xmldoclet-default/javadoc.xml" );
+
+        // test phase is after compile phase, so we are sure that classes dir exists
+        List args = new LinkedList();
+        args.add( "-package" );
+        args.add( "-sourcepath" );
+        args.add( srcDir.getAbsolutePath() );
+        args.add( "-o" );
+        args.add( outputXML.getAbsolutePath() );
+
+        addPackages( args, srcDir );
 
         StringWriter err = new StringWriter();
         StringWriter warn = new StringWriter();
@@ -93,8 +151,32 @@
         // Generated files
         assertTrue( outputXML.exists() );
         assertTrue( outputXML.length() > 0 );
+        String content = IOUtil.toString( new FileInputStream( outputXML ) );
+        assertTrue( content.indexOf( "\"" + XMLDoclet.DEFAULT_ENCODING_FORMAT + "\"" ) !=
-1 );
         File dtd = new File( BASEDIR, "target/unit/xmldoclet-default/" + XMLDoclet.XMLDOCLET_DTD
);
         assertTrue( dtd.exists() );
         assertTrue( dtd.length() > 0 );
+    }
+
+    private void addPackages( List args, File srcDir )
+        throws IOException
+    {
+        List packages = FileUtils.getDirectoryNames( srcDir, null, DEFAULT_EXCLUDES, false
);
+        for ( Iterator it = packages.iterator(); it.hasNext(); )
+        {
+            String p = (String) it.next();
+
+            if ( StringUtils.isEmpty( p ) )
+            {
+                continue;
+            }
+
+            if ( FileUtils.getFileNames( new File( srcDir, p ), "*.java", "", false ).isEmpty()
)
+            {
+                continue;
+            }
+
+            args.add( StringUtils.replace( p, File.separator, "." ) );
+        }
     }
 }



Mime
View raw message