6748541: javadoc should be reusable
authorjjg
Wed, 15 Oct 2008 08:07:59 -0700
changeset 1475 19c0851667ca
parent 1474 b808d0ebfe20
child 1476 4b54f7c2d3db
6748541: javadoc should be reusable Reviewed-by: bpatel
langtools/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/WriterFactoryImpl.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/AbstractDoclet.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Group.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MetaKeywords.java
langtools/test/com/sun/javadoc/AuthorDD/AuthorDD.java
langtools/test/com/sun/javadoc/lib/JavadocTester.java
langtools/test/tools/javadoc/BooleanConst.java
langtools/test/tools/javadoc/BreakIteratorWarning.java
langtools/test/tools/javadoc/FlagsTooEarly.java
langtools/test/tools/javadoc/InlineTagsWithBraces.java
langtools/test/tools/javadoc/LangVers.java
langtools/test/tools/javadoc/MethodLinks.java
langtools/test/tools/javadoc/NoStar.java
langtools/test/tools/javadoc/T4994049/T4994049.java
langtools/test/tools/javadoc/XWerror.java
langtools/test/tools/javadoc/completionFailure/CompletionFailure.java
langtools/test/tools/javadoc/dupOk/DupOk.java
langtools/test/tools/javadoc/imports/MissingImport.java
langtools/test/tools/javadoc/lib/Tester.java
langtools/test/tools/javadoc/nestedClass/NestedClass.java
langtools/test/tools/javadoc/sourceOnly/p/SourceOnly.java
langtools/test/tools/javadoc/sourceOption/SourceOption.java
langtools/test/tools/javadoc/subpackageIgnore/SubpackageIgnore.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Wed Oct 15 08:07:59 2008 -0700
@@ -51,7 +51,7 @@
  */
 public class ConfigurationImpl extends Configuration {
 
-    private static final ConfigurationImpl instance = new ConfigurationImpl();
+    private static ConfigurationImpl instance = new ConfigurationImpl();
 
     /**
      * The build date.  Note: For now, we will use
@@ -189,6 +189,15 @@
             "com.sun.tools.doclets.formats.html.resources.standard");
     }
 
+    /**
+     * Reset to a fresh new ConfigurationImpl, to allow multiple invocations
+     * of javadoc within a single VM. It would be better not to be using
+     * static fields at all, but .... (sigh).
+     */
+    public static void reset() {
+        instance = new ConfigurationImpl();
+    }
+
     public static ConfigurationImpl getInstance() {
         return instance;
     }
@@ -475,7 +484,7 @@
      * {@inheritDoc}
      */
     public WriterFactory getWriterFactory() {
-        return WriterFactoryImpl.getInstance();
+        return new WriterFactoryImpl(this);
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java	Wed Oct 15 08:07:59 2008 -0700
@@ -41,12 +41,14 @@
  *
  */
 public class HtmlDoclet extends AbstractDoclet {
+    public HtmlDoclet() {
+        configuration = (ConfigurationImpl) configuration();
+    }
 
     /**
      * The global configuration information for this run.
      */
-    public ConfigurationImpl configuration =
-        (ConfigurationImpl) configuration();
+    public ConfigurationImpl configuration;
 
     /**
      * The "start" method as required by Javadoc.
@@ -56,8 +58,12 @@
      * @return true if the doclet ran without encountering any errors.
      */
     public static boolean start(RootDoc root) {
-        HtmlDoclet doclet = new HtmlDoclet();
-        return doclet.start(doclet, root);
+        try {
+            HtmlDoclet doclet = new HtmlDoclet();
+            return doclet.start(doclet, root);
+        } finally {
+            ConfigurationImpl.reset();
+        }
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/WriterFactoryImpl.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/WriterFactoryImpl.java	Wed Oct 15 08:07:59 2008 -0700
@@ -37,27 +37,13 @@
  */
 public class WriterFactoryImpl implements WriterFactory {
 
-    private static WriterFactoryImpl instance;
-
     private ConfigurationImpl configuration;
 
-    private WriterFactoryImpl(ConfigurationImpl configuration) {
+    public WriterFactoryImpl(ConfigurationImpl configuration) {
         this.configuration = configuration;
     }
 
     /**
-     * Return an instance of this factory.
-     *
-     * @return an instance of this factory.
-     */
-    public static WriterFactoryImpl getInstance() {
-        if (instance == null) {
-            instance = new WriterFactoryImpl(ConfigurationImpl.getInstance());
-        }
-        return instance;
-    }
-
-    /**
      * {@inheritDoc}
      */
     public ConstantsSummaryWriter getConstantsSummaryWriter() throws Exception {
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/AbstractDoclet.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/AbstractDoclet.java	Wed Oct 15 08:07:59 2008 -0700
@@ -45,7 +45,7 @@
     /**
      * The global configuration information for this run.
      */
-    public Configuration configuration = configuration();
+    public Configuration configuration;
 
     /**
      * The only doclet that may use this toolkit is {@value}
@@ -74,6 +74,7 @@
      * @return true if the doclet executed without error.  False otherwise.
      */
     public boolean start(AbstractDoclet doclet, RootDoc root) {
+        configuration = configuration();
         configuration.root = root;
         if (! isValidDoclet(doclet)) {
             return false;
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Wed Oct 15 08:07:59 2008 -0700
@@ -113,9 +113,9 @@
     public boolean keywords = false;
 
     /**
-     * The meta tag keywords sole-instance.
+     * The meta tag keywords instance.
      */
-    public final MetaKeywords metakeywords = MetaKeywords.getInstance(this);
+    public final MetaKeywords metakeywords = new MetaKeywords(this);
 
     /**
      * The list of doc-file subdirectories to exclude
@@ -211,12 +211,12 @@
     public boolean notimestamp= false;
 
     /**
-     * The package grouping sole-instance.
+     * The package grouping instance.
      */
-    public final Group group = Group.getInstance(this);
+    public final Group group = new Group(this);
 
     /**
-     * The tracker of external package links (sole-instance).
+     * The tracker of external package links.
      */
     public final Extern extern = new Extern(this);
 
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Group.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Group.java	Wed Oct 15 08:07:59 2008 -0700
@@ -56,8 +56,6 @@
  */
 public class Group {
 
-    private static Group instance;
-
     /**
      * Map of regular expressions with the corresponding group name.
      */
@@ -96,17 +94,10 @@
         }
     }
 
-    private Group(Configuration configuration) {
+    public Group(Configuration configuration) {
         this.configuration = configuration;
     }
 
-    public static Group getInstance(Configuration configuration) {
-        if (instance == null) {
-            instance = new Group(configuration);
-        }
-        return instance;
-    }
-
     /**
      * Depending upon the format of the package name provided in the "-group"
      * option, generate two separate maps. There will be a map for mapping
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MetaKeywords.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MetaKeywords.java	Wed Oct 15 08:07:59 2008 -0700
@@ -43,8 +43,6 @@
  */
 public class MetaKeywords {
 
-    private static MetaKeywords instance = null;
-
     /**
      * The global configuration information for this run.
      */
@@ -53,23 +51,11 @@
     /**
      * Constructor
      */
-    private MetaKeywords(Configuration configuration) {
+    public MetaKeywords(Configuration configuration) {
         this.configuration = configuration;
     }
 
     /**
-     * Return an instance of MetaKeywords.  This class is a singleton.
-     *
-     * @param configuration the current configuration of the doclet.
-     */
-    public static MetaKeywords getInstance(Configuration configuration) {
-        if (instance == null) {
-            instance = new MetaKeywords(configuration);
-        }
-        return instance;
-    }
-
-    /**
      * Returns an array of strings where each element
      * is a class, method or field name.  This array is
      * used to create one meta keyword tag for each element.
--- a/langtools/test/com/sun/javadoc/AuthorDD/AuthorDD.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/com/sun/javadoc/AuthorDD/AuthorDD.java	Wed Oct 15 08:07:59 2008 -0700
@@ -72,7 +72,8 @@
 
     /** Run javadoc */
     public static void runJavadoc(String[] javadocArgs) {
-        if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
+        if (com.sun.tools.javadoc.Main.execute(AuthorDD.class.getClassLoader(),
+                                               javadocArgs) != 0) {
             throw new Error("Javadoc failed to execute");
         }
     }
--- a/langtools/test/com/sun/javadoc/lib/JavadocTester.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/com/sun/javadoc/lib/JavadocTester.java	Wed Oct 15 08:07:59 2008 -0700
@@ -197,6 +197,7 @@
                 new PrintWriter(warnings, true),
                 new PrintWriter(notices, true),
                 docletClass,
+                getClass().getClassLoader(),
                 args);
         System.setOut(prev);
         standardOut = new StringBuffer(stdout.toString());
--- a/langtools/test/tools/javadoc/BooleanConst.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/BooleanConst.java	Wed Oct 15 08:07:59 2008 -0700
@@ -37,7 +37,7 @@
     public static void main(String[] args) {
         // run javadoc on package p
         if (com.sun.tools.javadoc.Main.
-            execute("javadoc", "BooleanConst",
+            execute("javadoc", "BooleanConst", BooleanConst.class.getClassLoader(),
                     new String[] {System.getProperty("test.src", ".") + java.io.File.separatorChar + "BooleanConst.java"}) != 0)
             throw new Error();
     }
--- a/langtools/test/tools/javadoc/BreakIteratorWarning.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/BreakIteratorWarning.java	Wed Oct 15 08:07:59 2008 -0700
@@ -41,6 +41,7 @@
         if (com.sun.tools.javadoc.Main.execute(
                 "javadoc",
                 "BreakIteratorWarning",
+                BreakIteratorWarning.class.getClassLoader(),
                 new String[] {"-Xwerror", thisFile}) != 0)
             throw new Error("Javadoc encountered warnings or errors.");
     }
--- a/langtools/test/tools/javadoc/FlagsTooEarly.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/FlagsTooEarly.java	Wed Oct 15 08:07:59 2008 -0700
@@ -40,6 +40,7 @@
         if (com.sun.tools.javadoc.Main.execute(
                 "javadoc",
                 "FlagsTooEarly",
+                FlagsTooEarly.class.getClassLoader(),
                 new String[] {"-Xwerror", thisFile}) != 0)
             throw new Error("Javadoc encountered warnings or errors.");
     }
--- a/langtools/test/tools/javadoc/InlineTagsWithBraces.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/InlineTagsWithBraces.java	Wed Oct 15 08:07:59 2008 -0700
@@ -60,6 +60,7 @@
         if (com.sun.tools.javadoc.Main.execute(
                 "javadoc",
                 "InlineTagsWithBraces",
+                InlineTagsWithBraces.class.getClassLoader(),
                 new String[] {"-Xwerror", thisFile}) != 0)
             throw new Error("Javadoc encountered warnings or errors.");
     }
--- a/langtools/test/tools/javadoc/LangVers.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/LangVers.java	Wed Oct 15 08:07:59 2008 -0700
@@ -43,6 +43,7 @@
         if (com.sun.tools.javadoc.Main.execute(
                 "javadoc",
                 "LangVers",
+                LangVers.class.getClassLoader(),
                 new String[] {"-source", "1.5", thisFile}) != 0)
             throw new Error("Javadoc encountered warnings or errors.");
     }
--- a/langtools/test/tools/javadoc/MethodLinks.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/MethodLinks.java	Wed Oct 15 08:07:59 2008 -0700
@@ -36,7 +36,7 @@
 {
     public static void main(String[] args) {
         if (com.sun.tools.javadoc.Main.
-            execute("javadoc", "MethodLinks",
+            execute("javadoc", "MethodLinks", MethodLinks.class.getClassLoader(),
                     new String[] {System.getProperty("test.src", ".") +
                                   java.io.File.separatorChar + "MethodLinks.java"}
                     ) != 0)
--- a/langtools/test/tools/javadoc/NoStar.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/NoStar.java	Wed Oct 15 08:07:59 2008 -0700
@@ -44,7 +44,7 @@
 {
     public static void main(String[] args) {
         if (com.sun.tools.javadoc.Main.
-            execute("javadoc", "NoStar",
+            execute("javadoc", "NoStar", NoStar.class.getClassLoader(),
                     new String[] {System.getProperty("test.src", ".") + java.io.File.separatorChar + "NoStar.java"}) != 0)
             throw new Error();
     }
--- a/langtools/test/tools/javadoc/T4994049/T4994049.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/T4994049/T4994049.java	Wed Oct 15 08:07:59 2008 -0700
@@ -55,7 +55,8 @@
     public static void main(String... args) {
         for (String file : args) {
             File source = new File(System.getProperty("test.src", "."), file);
-            if (execute("javadoc", "T4994049", new String[]{source.getPath()} ) != 0)
+            if (execute("javadoc", "T4994049", T4994049.class.getClassLoader(),
+                        new String[]{source.getPath()} ) != 0)
                 throw new Error();
         }
     }
--- a/langtools/test/tools/javadoc/XWerror.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/XWerror.java	Wed Oct 15 08:07:59 2008 -0700
@@ -36,7 +36,7 @@
 {
     public static void main(String[] args) {
         if (com.sun.tools.javadoc.Main.
-            execute("javadoc", "XWerror",
+            execute("javadoc", "XWerror", XWerror.class.getClassLoader(),
                     new String[] {"-Xwerror",
                                   System.getProperty("test.src", ".") +
                                   java.io.File.separatorChar +
--- a/langtools/test/tools/javadoc/completionFailure/CompletionFailure.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/completionFailure/CompletionFailure.java	Wed Oct 15 08:07:59 2008 -0700
@@ -37,6 +37,7 @@
         // run javadoc on package pkg
         if (com.sun.tools.javadoc.Main.execute("javadoc",
                                                "CompletionFailure",
+                                               CompletionFailure.class.getClassLoader(),
                                                new String[]{"pkg"}) != 0)
             throw new Error();
     }
--- a/langtools/test/tools/javadoc/dupOk/DupOk.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/dupOk/DupOk.java	Wed Oct 15 08:07:59 2008 -0700
@@ -36,7 +36,7 @@
     public static void main(String[] args) {
         // run javadoc on package p
         if (com.sun.tools.javadoc.Main.
-            execute("javadoc", "DupOk",
+            execute("javadoc", "DupOk", DupOk.class.getClassLoader(),
                     new String[]
                 {"-sourcepath",
                  System.getProperty("test.src", ".") + java.io.File.separatorChar + "sp1" +
--- a/langtools/test/tools/javadoc/imports/MissingImport.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/imports/MissingImport.java	Wed Oct 15 08:07:59 2008 -0700
@@ -41,6 +41,7 @@
         if (com.sun.tools.javadoc.Main.execute(
                 "javadoc",
                 "MissingImport",
+                MissingImport.class.getClassLoader(),
                 new String[] {thisFile}) != 0)
             throw new Error("Javadoc encountered warnings or errors.");
     }
--- a/langtools/test/tools/javadoc/lib/Tester.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/lib/Tester.java	Wed Oct 15 08:07:59 2008 -0700
@@ -89,7 +89,9 @@
     public void run() throws IOException {
         try {
             if (com.sun.tools.javadoc.Main.execute("javadoc",
-                                                   docletName, args) != 0) {
+                                                   docletName,
+                                                   getClass().getClassLoader(),
+                                                   args) != 0) {
                 throw new Error("Javadoc errors encountered.");
             }
             System.out.println("--> Output written to " + outputFile);
--- a/langtools/test/tools/javadoc/nestedClass/NestedClass.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/nestedClass/NestedClass.java	Wed Oct 15 08:07:59 2008 -0700
@@ -39,7 +39,7 @@
 
     public static void main(String[] args) {
         if (com.sun.tools.javadoc.Main.
-            execute("javadoc", "NestedClass",
+            execute("javadoc", "NestedClass", NestedClass.class.getClassLoader(),
                     new String[] {System.getProperty("test.src", ".") +
                                   java.io.File.separatorChar +
                                   "NestedClass.java"})
--- a/langtools/test/tools/javadoc/sourceOnly/p/SourceOnly.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/sourceOnly/p/SourceOnly.java	Wed Oct 15 08:07:59 2008 -0700
@@ -31,7 +31,7 @@
     public static void main(String[] args) {
         // run javadoc on package p
         int result = com.sun.tools.javadoc.Main.
-            execute("javadoc", "p.SourceOnly", new String[] {"p"});
+            execute("javadoc", "p.SourceOnly", SourceOnly.class.getClassLoader(), new String[] {"p"});
         if (result != 0)
             throw new Error();
     }
--- a/langtools/test/tools/javadoc/sourceOption/SourceOption.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/sourceOption/SourceOption.java	Wed Oct 15 08:07:59 2008 -0700
@@ -36,6 +36,7 @@
         if (com.sun.tools.javadoc.Main.execute(
                 "javadoc",
                 "SourceOption",
+                SourceOption.class.getClassLoader(),
                 new String[] {"-source", "1.3", "p"}) != 0)
             throw new Error("Javadoc encountered warnings or errors.");
     }
--- a/langtools/test/tools/javadoc/subpackageIgnore/SubpackageIgnore.java	Tue Oct 14 17:05:48 2008 +0100
+++ b/langtools/test/tools/javadoc/subpackageIgnore/SubpackageIgnore.java	Wed Oct 15 08:07:59 2008 -0700
@@ -36,6 +36,7 @@
         if (com.sun.tools.javadoc.Main.execute(
                 "javadoc",
                 "SubpackageIgnore",
+                SubpackageIgnore.class.getClassLoader(),
                 new String[] {"-Xwerror",
                               "-sourcepath",
                               System.getProperty("test.src", "."),