jjg@944: /* jjg@944: * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. jjg@944: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@944: * jjg@944: * This code is free software; you can redistribute it and/or modify it jjg@944: * under the terms of the GNU General Public License version 2 only, as jjg@944: * published by the Free Software Foundation. jjg@944: * jjg@944: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@944: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@944: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@944: * version 2 for more details (a copy is included in the LICENSE file that jjg@944: * accompanied this code). jjg@944: * jjg@944: * You should have received a copy of the GNU General Public License version jjg@944: * 2 along with this work; if not, write to the Free Software Foundation, jjg@944: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@944: * jjg@944: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@944: * or visit www.oracle.com if you need additional information or have any jjg@944: * questions. jjg@944: */ jjg@944: jjg@944: /** jjg@944: * @test darcy@1044: * @bug 6597678 6449184 jjg@944: * @summary Ensure Messages propogated between rounds darcy@1466: * @library /tools/javac/lib jjg@944: * @build JavacTestingAbstractProcessor T6597678 jjg@944: * @run main T6597678 jjg@944: */ jjg@944: jjg@944: import java.io.*; jjg@944: import java.util.*; jjg@944: import javax.annotation.processing.RoundEnvironment; jjg@944: import javax.annotation.processing.SupportedOptions; jjg@944: import javax.lang.model.element.TypeElement; jjg@944: import javax.tools.Diagnostic; jjg@944: jjg@944: jjg@944: import com.sun.tools.javac.processing.JavacProcessingEnvironment; jjg@944: import com.sun.tools.javac.util.Context; jjg@944: import com.sun.tools.javac.util.JavacMessages; jjg@1159: import com.sun.tools.javac.util.Log; jjg@944: darcy@1044: @SupportedOptions("WriterString") jjg@944: public class T6597678 extends JavacTestingAbstractProcessor { jjg@944: public static void main(String... args) throws Exception { jjg@944: new T6597678().run(); jjg@944: } jjg@944: jjg@944: void run() throws Exception { jjg@944: String myName = T6597678.class.getSimpleName(); jjg@944: File testSrc = new File(System.getProperty("test.src")); jjg@944: File file = new File(testSrc, myName + ".java"); jjg@944: darcy@1044: StringWriter sw = new StringWriter(); darcy@1044: PrintWriter pw = new PrintWriter(sw); darcy@1044: darcy@1044: compile(sw, pw, jjg@944: "-proc:only", jjg@944: "-processor", myName, darcy@1044: "-AWriterString=" + pw.toString(), jjg@944: file.getPath()); jjg@944: } jjg@944: darcy@1044: void compile(StringWriter sw, PrintWriter pw, String... args) throws Exception { jjg@944: int rc = com.sun.tools.javac.Main.compile(args, pw); jjg@944: pw.close(); jjg@944: String out = sw.toString(); jjg@944: if (!out.isEmpty()) jjg@944: System.err.println(out); jjg@944: if (rc != 0) jjg@944: throw new Exception("compilation failed unexpectedly: rc=" + rc); jjg@944: } jjg@944: jjg@944: //--------------- jjg@944: jjg@944: @Override jjg@944: public boolean process(Set annotations, RoundEnvironment roundEnv) { jjg@944: Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); jjg@1159: Log log = Log.instance(context); jjg@1159: PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE); jjg@1159: PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING); jjg@1159: PrintWriter errOut = log.getWriter(Log.WriterKind.ERROR); jjg@944: Locale locale = context.get(Locale.class); jjg@944: JavacMessages messages = context.get(JavacMessages.messagesKey); jjg@944: jjg@944: round++; jjg@944: if (round == 1) { jjg@944: initialLocale = locale; jjg@944: initialMessages = messages; jjg@1159: initialNoteWriter = noteOut; jjg@1159: initialWarnWriter = warnOut; jjg@1159: initialErrWriter = errOut; darcy@1044: jjg@1159: String writerStringOpt = options.get("WriterString").intern(); jjg@1159: checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt); jjg@1159: checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt); jjg@1159: checkEqual("errWriterString", errOut.toString().intern(), writerStringOpt); jjg@944: } else { jjg@944: checkEqual("locale", locale, initialLocale); jjg@944: checkEqual("messages", messages, initialMessages); jjg@1159: checkEqual("noteWriter", noteOut, initialNoteWriter); jjg@1159: checkEqual("warnWriter", warnOut, initialWarnWriter); jjg@1159: checkEqual("errWriter", errOut, initialErrWriter); jjg@944: } jjg@944: jjg@944: return true; jjg@944: } jjg@944: jjg@944: void checkEqual(String label, T actual, T expected) { jjg@944: if (actual != expected) jjg@944: messager.printMessage(Diagnostic.Kind.ERROR, jjg@944: "Unexpected value for " + label jjg@944: + "; expected: " + expected jjg@944: + "; found: " + actual); jjg@944: } jjg@944: jjg@944: int round = 0; jjg@944: Locale initialLocale; jjg@944: JavacMessages initialMessages; jjg@1159: PrintWriter initialNoteWriter; jjg@1159: PrintWriter initialWarnWriter; jjg@1159: PrintWriter initialErrWriter; jjg@944: }