7111022: javac no long prints last round of processing

Wed, 14 Dec 2011 16:16:04 -0800

author
jjg
date
Wed, 14 Dec 2011 16:16:04 -0800
changeset 1159
4261dc8af622
parent 1158
4e4fed1d02f9
child 1160
281eeedf9755

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

src/share/classes/com/sun/tools/javac/main/Option.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/Log.java file | annotate | diff | comparison | revisions
test/tools/javac/4846262/Test.sh file | annotate | diff | comparison | revisions
test/tools/javac/processing/options/testPrintProcessorInfo/TestWithXstdout.java file | annotate | diff | comparison | revisions
test/tools/javac/util/T6597678.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/main/Option.java	Tue Dec 13 14:33:39 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/main/Option.java	Wed Dec 14 16:16:04 2011 -0800
     1.3 @@ -360,7 +360,7 @@
     1.4  
     1.5      XMAXWARNS("-Xmaxwarns", "opt.arg.number", "opt.maxwarns", EXTENDED, BASIC),
     1.6  
     1.7 -    XSTDOUT("Xstdout", "opt.arg.file", "opt.Xstdout", EXTENDED, INFO) {
     1.8 +    XSTDOUT("-Xstdout", "opt.arg.file", "opt.Xstdout", EXTENDED, INFO) {
     1.9          @Override
    1.10          public boolean process(OptionHelper helper, String option, String arg) {
    1.11              try {
     2.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Tue Dec 13 14:33:39 2011 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Wed Dec 14 16:16:04 2011 -0800
     2.3 @@ -1033,12 +1033,10 @@
     2.4              Assert.checkNonNull(options);
     2.5              next.put(Options.optionsKey, options);
     2.6  
     2.7 -            PrintWriter out = context.get(Log.outKey);
     2.8 -            Assert.checkNonNull(out);
     2.9 -            next.put(Log.outKey, out);
    2.10              Locale locale = context.get(Locale.class);
    2.11              if (locale != null)
    2.12                  next.put(Locale.class, locale);
    2.13 +
    2.14              Assert.checkNonNull(messages);
    2.15              next.put(JavacMessages.messagesKey, messages);
    2.16  
    2.17 @@ -1076,6 +1074,9 @@
    2.18              Assert.checkNonNull(tokens);
    2.19              next.put(Tokens.tokensKey, tokens);
    2.20  
    2.21 +            // propogate the log's writers directly, instead of going through context
    2.22 +            Log.instance(next).setWriters(log);
    2.23 +
    2.24              JavaCompiler oldCompiler = JavaCompiler.instance(context);
    2.25              JavaCompiler nextCompiler = JavaCompiler.instance(next);
    2.26              nextCompiler.initRound(oldCompiler);
    2.27 @@ -1472,14 +1473,6 @@
    2.28          return context;
    2.29      }
    2.30  
    2.31 -    /**
    2.32 -     * Internal use method to return the writer being used by the
    2.33 -     * processing environment.
    2.34 -     */
    2.35 -    public PrintWriter getWriter() {
    2.36 -        return context.get(Log.outKey);
    2.37 -    }
    2.38 -
    2.39      public String toString() {
    2.40          return "javac ProcessingEnvironment";
    2.41      }
     3.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Tue Dec 13 14:33:39 2011 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Wed Dec 14 16:16:04 2011 -0800
     3.3 @@ -135,7 +135,6 @@
     3.4  
     3.5      /** Construct a log with given I/O redirections.
     3.6       */
     3.7 -    @Deprecated
     3.8      protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
     3.9          super(JCDiagnostic.Factory.instance(context));
    3.10          context.put(logKey, this);
    3.11 @@ -296,6 +295,12 @@
    3.12          noticeWriter = warnWriter = errWriter = pw;
    3.13      }
    3.14  
    3.15 +    public void setWriters(Log other) {
    3.16 +        this.noticeWriter = other.noticeWriter;
    3.17 +        this.warnWriter = other.warnWriter;
    3.18 +        this.errWriter = other.errWriter;
    3.19 +    }
    3.20 +
    3.21      /** Flush the logs
    3.22       */
    3.23      public void flush() {
     4.1 --- a/test/tools/javac/4846262/Test.sh	Tue Dec 13 14:33:39 2011 -0800
     4.2 +++ b/test/tools/javac/4846262/Test.sh	Wed Dec 14 16:16:04 2011 -0800
     4.3 @@ -1,7 +1,7 @@
     4.4  #!/bin/sh -f
     4.5  
     4.6  #
     4.7 -# Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
     4.8 +# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
     4.9  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4.10  #
    4.11  # This code is free software; you can redistribute it and/or modify it
    4.12 @@ -71,7 +71,7 @@
    4.13  diff ${DIFFOPTS} -c "${TESTSRC}${FS}Test.out" Test.out
    4.14  result=$?
    4.15  
    4.16 -if [ $result -eq o ]
    4.17 +if [ $result -eq 0 ]
    4.18  then
    4.19    echo "Passed"
    4.20  else
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/processing/options/testPrintProcessorInfo/TestWithXstdout.java	Wed Dec 14 16:16:04 2011 -0800
     5.3 @@ -0,0 +1,88 @@
     5.4 +/*
     5.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +
    5.27 +/*
    5.28 + * @test
    5.29 + * @bug 6987384
    5.30 + * @summary -XprintProcessorRoundsInfo message printed with different timing than previous
    5.31 + * @library ../../../lib
    5.32 + * @build JavacTestingAbstractProcessor Test TestWithXstdout
    5.33 + * @run main TestWithXstdout
    5.34 + */
    5.35 +
    5.36 +import java.io.*;
    5.37 +import java.nio.charset.*;
    5.38 +import java.nio.file.*;
    5.39 +import java.util.*;
    5.40 +
    5.41 +public class TestWithXstdout {
    5.42 +    public static void main(String... args) throws Exception {
    5.43 +        File testSrc = new File(System.getProperty("test.src"));
    5.44 +        File testClasses = new File(System.getProperty("test.classes"));
    5.45 +        File stdout = new File("stdout.out");
    5.46 +        run_javac("-XDrawDiagnostics",
    5.47 +                "-XprintProcessorInfo",
    5.48 +                "-Werror",
    5.49 +                "-proc:only",
    5.50 +                "-processor",  "Test",
    5.51 +                "-Xstdout", stdout.getPath(),
    5.52 +                "-classpath", testClasses.getPath(),
    5.53 +                new File(testSrc, "Test.java").getPath());
    5.54 +        boolean ok = compare(stdout, new File(testSrc, "Test.out"));
    5.55 +        if (!ok)
    5.56 +            throw new Exception("differences found");
    5.57 +    }
    5.58 +
    5.59 +    static void run_javac(String... args) throws IOException, InterruptedException {
    5.60 +        File javaHome = new File(System.getProperty("java.home"));
    5.61 +        if (javaHome.getName().equals("jre"))
    5.62 +            javaHome = javaHome.getParentFile();
    5.63 +        File javac = new File(new File(javaHome, "bin"), "javac");
    5.64 +        String toolOpts = System.getProperty("test.tool.vm.opts");
    5.65 +
    5.66 +        List<String> opts = new ArrayList<>();
    5.67 +        opts.add(javac.getPath());
    5.68 +        opts.addAll(Arrays.asList(toolOpts.trim().split("[\\s]+")));
    5.69 +        opts.addAll(Arrays.asList(args));
    5.70 +        System.out.println("exec: " + opts);
    5.71 +        ProcessBuilder pb = new ProcessBuilder(opts);
    5.72 +        pb.redirectErrorStream();
    5.73 +        Process p = pb.start();
    5.74 +        try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
    5.75 +            String line;
    5.76 +            while ((line = r.readLine()) != null)
    5.77 +                System.out.println();
    5.78 +        }
    5.79 +        int rc = p.waitFor();
    5.80 +        if (rc != 0)
    5.81 +            System.out.println("javac exited, rc=" + rc);
    5.82 +    }
    5.83 +
    5.84 +    static boolean compare(File a, File b) throws IOException {
    5.85 +        List<String> aLines = Files.readAllLines(a.toPath(), Charset.defaultCharset());
    5.86 +        List<String> bLines = Files.readAllLines(b.toPath(), Charset.defaultCharset());
    5.87 +        System.out.println(a + ": " + aLines.size() + " lines");
    5.88 +        System.out.println(b + ": " + bLines.size() + " lines");
    5.89 +        return aLines.equals(bLines);
    5.90 +    }
    5.91 +}
     6.1 --- a/test/tools/javac/util/T6597678.java	Tue Dec 13 14:33:39 2011 -0800
     6.2 +++ b/test/tools/javac/util/T6597678.java	Wed Dec 14 16:16:04 2011 -0800
     6.3 @@ -41,6 +41,7 @@
     6.4  import com.sun.tools.javac.processing.JavacProcessingEnvironment;
     6.5  import com.sun.tools.javac.util.Context;
     6.6  import com.sun.tools.javac.util.JavacMessages;
     6.7 +import com.sun.tools.javac.util.Log;
     6.8  
     6.9  @SupportedOptions("WriterString")
    6.10  public class T6597678 extends JavacTestingAbstractProcessor {
    6.11 @@ -78,7 +79,10 @@
    6.12      @Override
    6.13      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    6.14          Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    6.15 -        PrintWriter out = ((JavacProcessingEnvironment) processingEnv).getWriter();
    6.16 +        Log log = Log.instance(context);
    6.17 +        PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE);
    6.18 +        PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING);
    6.19 +        PrintWriter errOut  = log.getWriter(Log.WriterKind.ERROR);
    6.20          Locale locale = context.get(Locale.class);
    6.21          JavacMessages messages = context.get(JavacMessages.messagesKey);
    6.22  
    6.23 @@ -86,13 +90,20 @@
    6.24          if (round == 1) {
    6.25              initialLocale = locale;
    6.26              initialMessages = messages;
    6.27 -            initialWriter = out;
    6.28 +            initialNoteWriter = noteOut;
    6.29 +            initialWarnWriter = warnOut;
    6.30 +            initialErrWriter  = errOut;
    6.31  
    6.32 -            checkEqual("writerString", out.toString().intern(), options.get("WriterString").intern());
    6.33 +            String writerStringOpt = options.get("WriterString").intern();
    6.34 +            checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt);
    6.35 +            checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt);
    6.36 +            checkEqual("errWriterString",  errOut.toString().intern(),  writerStringOpt);
    6.37          } else {
    6.38              checkEqual("locale", locale, initialLocale);
    6.39              checkEqual("messages", messages, initialMessages);
    6.40 -            checkEqual("writer", out, initialWriter);
    6.41 +            checkEqual("noteWriter", noteOut, initialNoteWriter);
    6.42 +            checkEqual("warnWriter", warnOut, initialWarnWriter);
    6.43 +            checkEqual("errWriter",  errOut,  initialErrWriter);
    6.44          }
    6.45  
    6.46          return true;
    6.47 @@ -109,5 +120,7 @@
    6.48      int round = 0;
    6.49      Locale initialLocale;
    6.50      JavacMessages initialMessages;
    6.51 -    PrintWriter initialWriter;
    6.52 +    PrintWriter initialNoteWriter;
    6.53 +    PrintWriter initialWarnWriter;
    6.54 +    PrintWriter initialErrWriter;
    6.55  }

mercurial