mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-16 10:53:31 +00:00
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
This commit is contained in:
parent
0707071217
commit
9a127e2710
@ -360,7 +360,7 @@ public enum Option {
|
||||
|
||||
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 {
|
||||
|
||||
@ -1033,12 +1033,10 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
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";
|
||||
}
|
||||
|
||||
@ -135,7 +135,6 @@ public class Log extends AbstractLog {
|
||||
|
||||
/** 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 @@ public class Log extends AbstractLog {
|
||||
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() {
|
||||
|
||||
@ -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 @@ rm -f Test.java Test.out
|
||||
diff ${DIFFOPTS} -c "${TESTSRC}${FS}Test.out" Test.out
|
||||
result=$?
|
||||
|
||||
if [ $result -eq o ]
|
||||
if [ $result -eq 0 ]
|
||||
then
|
||||
echo "Passed"
|
||||
else
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -41,6 +41,7 @@ import javax.tools.Diagnostic;
|
||||
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 @@ public class T6597678 extends JavacTestingAbstractProcessor {
|
||||
@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 @@ public class T6597678 extends JavacTestingAbstractProcessor {
|
||||
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 @@ public class T6597678 extends JavacTestingAbstractProcessor {
|
||||
int round = 0;
|
||||
Locale initialLocale;
|
||||
JavacMessages initialMessages;
|
||||
PrintWriter initialWriter;
|
||||
PrintWriter initialNoteWriter;
|
||||
PrintWriter initialWarnWriter;
|
||||
PrintWriter initialErrWriter;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user