langtools/test/tools/javac/processing/options/testPrintProcessorInfo/TestWithXstdout.java
author jjh
Fri, 16 Dec 2011 16:41:00 -0800
changeset 11321 ce0082fea571
parent 11316 4dcad625e72e
child 13632 40c51bd45d38
permissions -rw-r--r--
7122342: testPrintProcessorInfo/TestWithXstdout.java failed for JDK8 nightly build at 12/16/2011 Summary: Do not pass empty args to javac Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11316
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
     1
/*
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
     4
 *
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
     8
 *
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    13
 * accompanied this code).
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    14
 *
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    18
 *
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    21
 * questions.
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    22
 */
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    23
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    24
/*
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    25
 * @test
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    26
 * @bug 6987384
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    27
 * @summary -XprintProcessorRoundsInfo message printed with different timing than previous
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    28
 * @library ../../../lib
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    29
 * @build JavacTestingAbstractProcessor Test TestWithXstdout
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    30
 * @run main TestWithXstdout
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    31
 */
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    32
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    33
import java.io.*;
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    34
import java.nio.charset.*;
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    35
import java.nio.file.*;
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    36
import java.util.*;
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    37
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    38
public class TestWithXstdout {
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    39
    public static void main(String... args) throws Exception {
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    40
        File testSrc = new File(System.getProperty("test.src"));
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    41
        File testClasses = new File(System.getProperty("test.classes"));
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    42
        File stdout = new File("stdout.out");
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    43
        run_javac("-XDrawDiagnostics",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    44
                "-XprintProcessorInfo",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    45
                "-Werror",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    46
                "-proc:only",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    47
                "-processor",  "Test",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    48
                "-Xstdout", stdout.getPath(),
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    49
                "-classpath", testClasses.getPath(),
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    50
                new File(testSrc, "Test.java").getPath());
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    51
        boolean ok = compare(stdout, new File(testSrc, "Test.out"));
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    52
        if (!ok)
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    53
            throw new Exception("differences found");
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    54
    }
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    55
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    56
    static void run_javac(String... args) throws IOException, InterruptedException {
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    57
        File javaHome = new File(System.getProperty("java.home"));
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    58
        if (javaHome.getName().equals("jre"))
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    59
            javaHome = javaHome.getParentFile();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    60
        File javac = new File(new File(javaHome, "bin"), "javac");
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    61
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    62
        List<String> opts = new ArrayList<>();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    63
        opts.add(javac.getPath());
11321
ce0082fea571 7122342: testPrintProcessorInfo/TestWithXstdout.java failed for JDK8 nightly build at 12/16/2011
jjh
parents: 11316
diff changeset
    64
ce0082fea571 7122342: testPrintProcessorInfo/TestWithXstdout.java failed for JDK8 nightly build at 12/16/2011
jjh
parents: 11316
diff changeset
    65
        String toolOpts = System.getProperty("test.tool.vm.opts");
ce0082fea571 7122342: testPrintProcessorInfo/TestWithXstdout.java failed for JDK8 nightly build at 12/16/2011
jjh
parents: 11316
diff changeset
    66
        if (toolOpts != null && !"".equals(toolOpts.trim())) {
ce0082fea571 7122342: testPrintProcessorInfo/TestWithXstdout.java failed for JDK8 nightly build at 12/16/2011
jjh
parents: 11316
diff changeset
    67
            opts.addAll(Arrays.asList(toolOpts.trim().split("[\\s]+")));
ce0082fea571 7122342: testPrintProcessorInfo/TestWithXstdout.java failed for JDK8 nightly build at 12/16/2011
jjh
parents: 11316
diff changeset
    68
        }
11316
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    69
        opts.addAll(Arrays.asList(args));
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    70
        System.out.println("exec: " + opts);
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    71
        ProcessBuilder pb = new ProcessBuilder(opts);
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    72
        pb.redirectErrorStream();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    73
        Process p = pb.start();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    74
        try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    75
            String line;
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    76
            while ((line = r.readLine()) != null)
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    77
                System.out.println();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    78
        }
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    79
        int rc = p.waitFor();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    80
        if (rc != 0)
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    81
            System.out.println("javac exited, rc=" + rc);
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    82
    }
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    83
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    84
    static boolean compare(File a, File b) throws IOException {
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    85
        List<String> aLines = Files.readAllLines(a.toPath(), Charset.defaultCharset());
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    86
        List<String> bLines = Files.readAllLines(b.toPath(), Charset.defaultCharset());
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    87
        System.out.println(a + ": " + aLines.size() + " lines");
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    88
        System.out.println(b + ": " + bLines.size() + " lines");
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    89
        return aLines.equals(bLines);
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    90
    }
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    91
}