8002168: Cleanup initialization of javadoc Messager
authorjjg
Sat, 03 Nov 2012 21:09:57 -0700
changeset 14442 6dc10c88c07a
parent 14441 6c066a762e05
child 14443 91c05eb19277
8002168: Cleanup initialization of javadoc Messager Reviewed-by: darcy
langtools/src/share/classes/com/sun/tools/javadoc/Start.java
langtools/test/tools/javadoc/6958836/Test.java
--- a/langtools/src/share/classes/com/sun/tools/javadoc/Start.java	Sat Nov 03 21:07:30 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/Start.java	Sat Nov 03 21:09:57 2012 -0700
@@ -54,6 +54,8 @@
  * @author Neal Gafter (rewrite)
  */
 class Start {
+    /** Context for this invocation. */
+    private final Context context;
 
     private final String defaultDocletClassName;
     private final ClassLoader docletParentClassLoader;
@@ -69,7 +71,7 @@
 
     private long defaultFilter = PUBLIC | PROTECTED;
 
-    private Messager messager;
+    private final Messager messager;
 
     String docLocale = "";
 
@@ -96,8 +98,8 @@
           PrintWriter noticeWriter,
           String defaultDocletClassName,
           ClassLoader docletParentClassLoader) {
-        Context tempContext = new Context(); // interim context until option decoding completed
-        messager = new Messager(tempContext, programName, errWriter, warnWriter, noticeWriter);
+        context = new Context();
+        messager = new Messager(context, programName, errWriter, warnWriter, noticeWriter);
         this.defaultDocletClassName = defaultDocletClassName;
         this.docletParentClassLoader = docletParentClassLoader;
     }
@@ -108,8 +110,8 @@
 
     Start(String programName, String defaultDocletClassName,
           ClassLoader docletParentClassLoader) {
-        Context tempContext = new Context(); // interim context until option decoding completed
-        messager = new Messager(tempContext, programName);
+        context = new Context();
+        messager = new Messager(context, programName);
         this.defaultDocletClassName = defaultDocletClassName;
         this.docletParentClassLoader = docletParentClassLoader;
     }
@@ -219,16 +221,6 @@
         ListBuffer<String> subPackages = new ListBuffer<String>();
         ListBuffer<String> excludedPackages = new ListBuffer<String>();
 
-        Context context = new Context();
-        // Setup a new Messager, using the same initial parameters as the
-        // existing Messager, except that this one will be able to use any
-        // options that may be set up below.
-        Messager.preRegister(context,
-                messager.programName,
-                messager.getWriter(Log.WriterKind.ERROR),
-                messager.getWriter(Log.WriterKind.WARNING),
-                messager.getWriter(Log.WriterKind.NOTICE));
-
         Options compOpts = Options.instance(context);
         boolean docClasses = false;
 
@@ -368,6 +360,7 @@
                 javaNames.append(arg);
             }
         }
+        compOpts.notifyListeners();
 
         if (javaNames.isEmpty() && subPackages.isEmpty()) {
             usageError("main.No_packages_or_classes_specified");
@@ -401,10 +394,6 @@
         boolean ok = root != null;
         if (ok) ok = docletInvoker.start(root);
 
-        Messager docletMessager = Messager.instance0(context);
-        messager.nwarnings += docletMessager.nwarnings;
-        messager.nerrors += docletMessager.nerrors;
-
         // We're done.
         if (compOpts.get("-verbose") != null) {
             tm = System.currentTimeMillis() - tm;
--- a/langtools/test/tools/javadoc/6958836/Test.java	Sat Nov 03 21:07:30 2012 -0700
+++ b/langtools/test/tools/javadoc/6958836/Test.java	Sat Nov 03 21:09:57 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6958836
+ * @bug 6958836 8002168
  * @summary javadoc should support -Xmaxerrs and -Xmaxwarns
  */