7111022: javac no long prints last round of processing
7121323: Sqe tests using -Xstdout option fail with an invalid flag error message
Reviewed-by: darcy
--- a/langtools/src/share/classes/com/sun/tools/javac/main/Option.java Tue Dec 13 14:33:39 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/Option.java Wed Dec 14 16:16:04 2011 -0800
@@ -360,7 +360,7 @@
XMAXWARNS("-Xmaxwarns", "opt.arg.number", "opt.maxwarns", EXTENDED, BASIC),
- XSTDOUT("Xstdout", "opt.arg.file", "opt.Xstdout", EXTENDED, INFO) {
+ XSTDOUT("-Xstdout", "opt.arg.file", "opt.Xstdout", EXTENDED, INFO) {
@Override
public boolean process(OptionHelper helper, String option, String arg) {
try {
--- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Dec 13 14:33:39 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Wed Dec 14 16:16:04 2011 -0800
@@ -1033,12 +1033,10 @@
Assert.checkNonNull(options);
next.put(Options.optionsKey, options);
- PrintWriter out = context.get(Log.outKey);
- Assert.checkNonNull(out);
- next.put(Log.outKey, out);
Locale locale = context.get(Locale.class);
if (locale != null)
next.put(Locale.class, locale);
+
Assert.checkNonNull(messages);
next.put(JavacMessages.messagesKey, messages);
@@ -1076,6 +1074,9 @@
Assert.checkNonNull(tokens);
next.put(Tokens.tokensKey, tokens);
+ // propogate the log's writers directly, instead of going through context
+ Log.instance(next).setWriters(log);
+
JavaCompiler oldCompiler = JavaCompiler.instance(context);
JavaCompiler nextCompiler = JavaCompiler.instance(next);
nextCompiler.initRound(oldCompiler);
@@ -1472,14 +1473,6 @@
return context;
}
- /**
- * Internal use method to return the writer being used by the
- * processing environment.
- */
- public PrintWriter getWriter() {
- return context.get(Log.outKey);
- }
-
public String toString() {
return "javac ProcessingEnvironment";
}
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Tue Dec 13 14:33:39 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Wed Dec 14 16:16:04 2011 -0800
@@ -135,7 +135,6 @@
/** Construct a log with given I/O redirections.
*/
- @Deprecated
protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
super(JCDiagnostic.Factory.instance(context));
context.put(logKey, this);
@@ -296,6 +295,12 @@
noticeWriter = warnWriter = errWriter = pw;
}
+ public void setWriters(Log other) {
+ this.noticeWriter = other.noticeWriter;
+ this.warnWriter = other.warnWriter;
+ this.errWriter = other.errWriter;
+ }
+
/** Flush the logs
*/
public void flush() {
--- a/langtools/test/tools/javac/4846262/Test.sh Tue Dec 13 14:33:39 2011 -0800
+++ b/langtools/test/tools/javac/4846262/Test.sh Wed Dec 14 16:16:04 2011 -0800
@@ -1,7 +1,7 @@
#!/bin/sh -f
#
-# Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2005, 2011, 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
@@ -71,7 +71,7 @@
diff ${DIFFOPTS} -c "${TESTSRC}${FS}Test.out" Test.out
result=$?
-if [ $result -eq o ]
+if [ $result -eq 0 ]
then
echo "Passed"
else
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/processing/options/testPrintProcessorInfo/TestWithXstdout.java Wed Dec 14 16:16:04 2011 -0800
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6987384
+ * @summary -XprintProcessorRoundsInfo message printed with different timing than previous
+ * @library ../../../lib
+ * @build JavacTestingAbstractProcessor Test TestWithXstdout
+ * @run main TestWithXstdout
+ */
+
+import java.io.*;
+import java.nio.charset.*;
+import java.nio.file.*;
+import java.util.*;
+
+public class TestWithXstdout {
+ public static void main(String... args) throws Exception {
+ File testSrc = new File(System.getProperty("test.src"));
+ File testClasses = new File(System.getProperty("test.classes"));
+ File stdout = new File("stdout.out");
+ run_javac("-XDrawDiagnostics",
+ "-XprintProcessorInfo",
+ "-Werror",
+ "-proc:only",
+ "-processor", "Test",
+ "-Xstdout", stdout.getPath(),
+ "-classpath", testClasses.getPath(),
+ new File(testSrc, "Test.java").getPath());
+ boolean ok = compare(stdout, new File(testSrc, "Test.out"));
+ if (!ok)
+ throw new Exception("differences found");
+ }
+
+ static void run_javac(String... args) throws IOException, InterruptedException {
+ File javaHome = new File(System.getProperty("java.home"));
+ if (javaHome.getName().equals("jre"))
+ javaHome = javaHome.getParentFile();
+ File javac = new File(new File(javaHome, "bin"), "javac");
+ String toolOpts = System.getProperty("test.tool.vm.opts");
+
+ List<String> opts = new ArrayList<>();
+ opts.add(javac.getPath());
+ opts.addAll(Arrays.asList(toolOpts.trim().split("[\\s]+")));
+ opts.addAll(Arrays.asList(args));
+ System.out.println("exec: " + opts);
+ ProcessBuilder pb = new ProcessBuilder(opts);
+ pb.redirectErrorStream();
+ Process p = pb.start();
+ try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
+ String line;
+ while ((line = r.readLine()) != null)
+ System.out.println();
+ }
+ int rc = p.waitFor();
+ if (rc != 0)
+ System.out.println("javac exited, rc=" + rc);
+ }
+
+ static boolean compare(File a, File b) throws IOException {
+ List<String> aLines = Files.readAllLines(a.toPath(), Charset.defaultCharset());
+ List<String> bLines = Files.readAllLines(b.toPath(), Charset.defaultCharset());
+ System.out.println(a + ": " + aLines.size() + " lines");
+ System.out.println(b + ": " + bLines.size() + " lines");
+ return aLines.equals(bLines);
+ }
+}
--- a/langtools/test/tools/javac/util/T6597678.java Tue Dec 13 14:33:39 2011 -0800
+++ b/langtools/test/tools/javac/util/T6597678.java Wed Dec 14 16:16:04 2011 -0800
@@ -41,6 +41,7 @@
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JavacMessages;
+import com.sun.tools.javac.util.Log;
@SupportedOptions("WriterString")
public class T6597678 extends JavacTestingAbstractProcessor {
@@ -78,7 +79,10 @@
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
- PrintWriter out = ((JavacProcessingEnvironment) processingEnv).getWriter();
+ Log log = Log.instance(context);
+ PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE);
+ PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING);
+ PrintWriter errOut = log.getWriter(Log.WriterKind.ERROR);
Locale locale = context.get(Locale.class);
JavacMessages messages = context.get(JavacMessages.messagesKey);
@@ -86,13 +90,20 @@
if (round == 1) {
initialLocale = locale;
initialMessages = messages;
- initialWriter = out;
+ initialNoteWriter = noteOut;
+ initialWarnWriter = warnOut;
+ initialErrWriter = errOut;
- checkEqual("writerString", out.toString().intern(), options.get("WriterString").intern());
+ String writerStringOpt = options.get("WriterString").intern();
+ checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt);
+ checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt);
+ checkEqual("errWriterString", errOut.toString().intern(), writerStringOpt);
} else {
checkEqual("locale", locale, initialLocale);
checkEqual("messages", messages, initialMessages);
- checkEqual("writer", out, initialWriter);
+ checkEqual("noteWriter", noteOut, initialNoteWriter);
+ checkEqual("warnWriter", warnOut, initialWarnWriter);
+ checkEqual("errWriter", errOut, initialErrWriter);
}
return true;
@@ -109,5 +120,7 @@
int round = 0;
Locale initialLocale;
JavacMessages initialMessages;
- PrintWriter initialWriter;
+ PrintWriter initialNoteWriter;
+ PrintWriter initialWarnWriter;
+ PrintWriter initialErrWriter;
}