Revision: 7468
Author: [email protected]
Date: Mon Jan 25 10:18:32 2010
Log: Updates JreDocTool to print the JRE emulation reference HTML fragment to a file instead of stdout.

Rietveld review: http://gwt-code-reviews.appspot.com/130816

http://code.google.com/p/google-web-toolkit/source/detail?r=7468

Modified:
 /trunk/build-tools/doctool/src/com/google/doctool/JreDocTool.java
 /trunk/build-tools/doctool/src/com/google/doctool/JreDocToolFactory.java
 /trunk/build-tools/doctool/src/com/google/doctool/custom/EztDoclet.java
 /trunk/doc/build.xml

=======================================
--- /trunk/build-tools/doctool/src/com/google/doctool/JreDocTool.java Mon Dec 14 13:17:56 2009 +++ /trunk/build-tools/doctool/src/com/google/doctool/JreDocTool.java Mon Jan 25 10:18:32 2010
@@ -39,6 +39,9 @@
       } else if (null != (arg = tryParseArg(args, i, "-classpath"))) {
         i++;
         factory.setClasspath(arg);
+      } else if (null != (arg = tryParseArg(args, i, "-out"))) {
+        i++;
+        factory.setOutputFile(arg);
       } else if (null != (arg = tryParseArg(args, i, "-packages"))) {
         i++;
         factory.setPackages(arg);
@@ -69,6 +72,8 @@
     s += "  -sourcepath\n";
     s += "    The path to find Java source for this doc set.\n";
     s += "    E.g. /gwt/src/trunk/user/super/com/google/gwt/emul\n";
+    s += "  -out\n";
+    s += "    The path and filename of the output file\n";
     s += "  -packages\n";
s += " A semicolon-separated list of fully-qualified package names.\n"; s += " E.g. java.lang;java.lang.annotation;java.util;java.io;java.sql\n";
@@ -112,12 +117,16 @@

   private String classpath;

+  private String outputFile;
+
   private String packages;

   private String sourcepath;

-  JreDocTool(String classpath, String packages, String sourcepath) {
+  JreDocTool(String classpath, String outputFile, String packages,
+      String sourcepath) {
     this.classpath = classpath;
+    this.outputFile = outputFile;
     this.packages = packages;
     this.sourcepath = sourcepath;
   }
@@ -141,6 +150,9 @@
     args.add("-sourcepath");
     args.add(this.sourcepath);

+    args.add(EztDoclet.OPT_EZTFILE);
+    args.add(this.outputFile);
+
     args.addAll(Arrays.asList(this.packages.split(";")));

     com.sun.tools.javadoc.Main.execute(args.toArray(new String[0]));
=======================================
--- /trunk/build-tools/doctool/src/com/google/doctool/JreDocToolFactory.java Mon Dec 14 13:17:56 2009 +++ /trunk/build-tools/doctool/src/com/google/doctool/JreDocToolFactory.java Mon Jan 25 10:18:32 2010
@@ -25,6 +25,8 @@

   private String classpath;

+  private String outputFile;
+
   private String packages;

   private String sourcepath;
@@ -34,6 +36,11 @@
       err.println("You must specify the -classpath");
       return null;
     }
+
+    if (this.outputFile == null) {
+      err.println("You must specify the output file (-out)");
+      return null;
+    }

     if (this.packages == null) {
       err.println("You must specify the -packages");
@@ -45,12 +52,16 @@
       return null;
     }

-    return new JreDocTool(classpath, packages, sourcepath);
+    return new JreDocTool(classpath, outputFile, packages, sourcepath);
   }

   public void setClasspath(String classpath) {
     this.classpath = classpath;
   }
+
+  public void setOutputFile(String outputFile) {
+    this.outputFile = outputFile;
+  }

   public void setPackages(String packages) {
     this.packages = packages;
=======================================
--- /trunk/build-tools/doctool/src/com/google/doctool/custom/EztDoclet.java Fri Jan 15 08:24:03 2010 +++ /trunk/build-tools/doctool/src/com/google/doctool/custom/EztDoclet.java Mon Jan 25 10:18:32 2010
@@ -17,10 +17,14 @@
 package com.google.doctool.custom;

 import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.DocErrorReporter;
 import com.sun.javadoc.ExecutableMemberDoc;
 import com.sun.javadoc.PackageDoc;
 import com.sun.javadoc.RootDoc;

+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -34,14 +38,28 @@
  */
 public class EztDoclet {

- private static final String JAVADOC_URL = "http://java.sun.com/javase/6/docs/api/";;
+  public static final String OPT_EZTFILE = "-eztfile";

   private static EztDoclet EZT_DOCLET;
+
+ private static final String JAVADOC_URL = "http://java.sun.com/javase/6/docs/api/";;
+
+  public static int optionLength(String option) {
+    if (option.equals(OPT_EZTFILE)) {
+      return 2;
+    }
+    return 0;
+  }

   public static boolean start(RootDoc root) {
     getDoclet().process(root);
     return true;
   }
+
+  public static boolean validOptions(String[][] options,
+      DocErrorReporter reporter) {
+    return getDoclet().analyzeOptions(options, reporter);
+  }

   private static EztDoclet getDoclet() {
     if (EZT_DOCLET == null) {
@@ -49,6 +67,24 @@
     }
     return EZT_DOCLET;
   }
+
+  private String outputFile;
+
+ private boolean analyzeOptions(String[][] options, DocErrorReporter reporter) {
+    for (int i = 0; i < options.length; i++) {
+      if (options[i][0] == OPT_EZTFILE) {
+        outputFile = options[i][1];
+      }
+    }
+
+    if (outputFile == null) {
+      reporter.printError("You must specify an output filepath with "
+          + OPT_EZTFILE);
+      return false;
+    }
+
+    return true;
+  }

private String createMemberList(Collection<ExecutableMemberDoc> members) {
     StringBuffer buffer = new StringBuffer();
@@ -64,54 +100,61 @@
   }

   private void process(RootDoc root) {
-    PrintWriter pw = new PrintWriter(System.out, true);
-
-    pw.println("<ol class=\"toc\" id=\"pageToc\">");
-    for (PackageDoc pack : root.specifiedPackages()) {
-      pw.format("  <li><a href=\"#Package_%s\">%s</a></li>\n",
-          pack.name().replace('.', '_'), pack.name());
-    }
-    pw.println("</ol>\n");
-
-    for (PackageDoc pack : root.specifiedPackages()) {
- pw.format("<h1 id=\"Package_%s\">Package %s</h1>\n", pack.name().replace(
-          '.', '_'), pack.name());
-      pw.println("<dl>");
-
-      String packURL = JAVADOC_URL + pack.name().replace(".", "/") + "/";
-
-      // Sort the classes alphabetically
-      ClassDoc[] classes = pack.allClasses(true);
-      Arrays.sort(classes, new Comparator<ClassDoc>() {
-        public int compare(ClassDoc arg0, ClassDoc arg1) {
-          return arg0.name().compareTo(arg1.name());
-        }
-      });
-
-      Iterator<ClassDoc> iter = Arrays.asList(classes).iterator();
-      while (iter.hasNext()) {
-        ClassDoc cls = iter.next();
-
-        // Each class links to Sun's main JavaDoc
-        pw.format("  <dt><a href=\"%s%s.html\">%s</a></dt>\n", packURL,
-            cls.name(), cls.name());
-
-        // Print out all constructors and methods
- Collection<ExecutableMemberDoc> members = new ArrayList<ExecutableMemberDoc>();
-        members.addAll(Arrays.asList(cls.constructors(true)));
-        members.addAll(Arrays.asList(cls.methods(true)));
-
-        if (!members.isEmpty()) {
-          pw.format("  <dd>%s</dd>\n", createMemberList(members));
-        }
-
-        if (iter.hasNext()) {
-          pw.print("\n");
-        }
-      }
-
-      pw.println("</dl>\n");
-    }
-    pw.close();
+    try {
+      File outFile = new File(outputFile);
+      outFile.getParentFile().mkdirs();
+      FileWriter fw = new FileWriter(outFile);
+      PrintWriter pw = new PrintWriter(fw, true);
+
+      pw.println("<ol class=\"toc\" id=\"pageToc\">");
+      for (PackageDoc pack : root.specifiedPackages()) {
+        pw.format("  <li><a href=\"#Package_%s\">%s</a></li>\n",
+            pack.name().replace('.', '_'), pack.name());
+      }
+      pw.println("</ol>\n");
+
+      for (PackageDoc pack : root.specifiedPackages()) {
+        pw.format("<h1 id=\"Package_%s\">Package %s</h1>\n",
+            pack.name().replace('.', '_'), pack.name());
+        pw.println("<dl>");
+
+        String packURL = JAVADOC_URL + pack.name().replace(".", "/") + "/";
+
+        // Sort the classes alphabetically
+        ClassDoc[] classes = pack.allClasses(true);
+        Arrays.sort(classes, new Comparator<ClassDoc>() {
+          public int compare(ClassDoc arg0, ClassDoc arg1) {
+            return arg0.name().compareTo(arg1.name());
+          }
+        });
+
+        Iterator<ClassDoc> iter = Arrays.asList(classes).iterator();
+        while (iter.hasNext()) {
+          ClassDoc cls = iter.next();
+
+          // Each class links to Sun's main JavaDoc
+          pw.format("  <dt><a href=\"%s%s.html\">%s</a></dt>\n", packURL,
+              cls.name(), cls.name());
+
+          // Print out all constructors and methods
+ Collection<ExecutableMemberDoc> members = new ArrayList<ExecutableMemberDoc>();
+          members.addAll(Arrays.asList(cls.constructors(true)));
+          members.addAll(Arrays.asList(cls.methods(true)));
+
+          if (!members.isEmpty()) {
+            pw.format("  <dd>%s</dd>\n", createMemberList(members));
+          }
+
+          if (iter.hasNext()) {
+            pw.print("\n");
+          }
+        }
+
+        pw.println("</dl>\n");
+      }
+      pw.close();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
   }
 }
=======================================
--- /trunk/doc/build.xml        Tue Dec  8 13:35:13 2009
+++ /trunk/doc/build.xml        Mon Jan 25 10:18:32 2010
@@ -100,23 +100,21 @@
     </outofdate>
   </target>

-  <target name="wiki-lang">
+  <target name="emul-ezt">
     <outofdate>
       <sourcefiles>
-        <fileset file="./src/RefJreHeader.wiki" />
         <fileset dir="${gwt.root}/user/super/com/google/gwt/emul">
           <include name="**/*.java" />
         </fileset>
       </sourcefiles>
       <targetfiles>
-        <pathelement path="${project.build}/wiki/RefJreEmulation.wiki" />
+        <pathelement path="${project.build}/emul-ezt/fragment.html" />
       </targetfiles>
       <sequential>
+        <echo>Building JRE emulation EZT</echo>
<java classpathref="DOC_PATH" classname="com.google.doctool.JreDocTool" fork="yes" failonerror="true">
           <arg value="-out" />
-          <arg value="${project.build}/wiki/RefJreEmulation.wiki" />
-          <arg value="-header" />
-          <arg value="./src/RefJreHeader.wiki" />
+          <arg value="${project.build}/emul-ezt/fragment.html" />
           <arg value="-classpath" />
           <arg pathref="USER_CLASS_PATH" />
           <arg value="-sourcepath" />
@@ -128,5 +126,5 @@
     </outofdate>
   </target>

-  <target name="build" depends="javadoc, wiki-lang" />
+  <target name="build" depends="javadoc, emul-ezt" />
 </project>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to