langtools/test/tools/javac/processing/options/testPrintProcessorInfo/TestWithXstdout.java
author jjg
Fri, 17 Aug 2012 17:30:03 -0700
changeset 13632 40c51bd45d38
parent 11321 ce0082fea571
child 14963 974d4423c999
permissions -rw-r--r--
7192449: fix up tests to accommodate jtreg spec change Reviewed-by: darcy
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
/*
13632
40c51bd45d38 7192449: fix up tests to accommodate jtreg spec change
jjg
parents: 11321
diff changeset
     2
 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
11316
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"));
13632
40c51bd45d38 7192449: fix up tests to accommodate jtreg spec change
jjg
parents: 11321
diff changeset
    41
        String testClasses = System.getProperty("test.classes", ".");
40c51bd45d38 7192449: fix up tests to accommodate jtreg spec change
jjg
parents: 11321
diff changeset
    42
        String testClassPath = System.getProperty("test.class.path", testClasses);
11316
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    43
        File stdout = new File("stdout.out");
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    44
        run_javac("-XDrawDiagnostics",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    45
                "-XprintProcessorInfo",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    46
                "-Werror",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    47
                "-proc:only",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    48
                "-processor",  "Test",
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    49
                "-Xstdout", stdout.getPath(),
13632
40c51bd45d38 7192449: fix up tests to accommodate jtreg spec change
jjg
parents: 11321
diff changeset
    50
                "-classpath", testClassPath,
11316
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    51
                new File(testSrc, "Test.java").getPath());
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    52
        boolean ok = compare(stdout, new File(testSrc, "Test.out"));
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    53
        if (!ok)
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    54
            throw new Exception("differences found");
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
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    57
    static void run_javac(String... args) throws IOException, InterruptedException {
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    58
        File javaHome = new File(System.getProperty("java.home"));
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    59
        if (javaHome.getName().equals("jre"))
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    60
            javaHome = javaHome.getParentFile();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    61
        File javac = new File(new File(javaHome, "bin"), "javac");
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    62
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    63
        List<String> opts = new ArrayList<>();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    64
        opts.add(javac.getPath());
11321
ce0082fea571 7122342: testPrintProcessorInfo/TestWithXstdout.java failed for JDK8 nightly build at 12/16/2011
jjh
parents: 11316
diff changeset
    65
ce0082fea571 7122342: testPrintProcessorInfo/TestWithXstdout.java failed for JDK8 nightly build at 12/16/2011
jjh
parents: 11316
diff changeset
    66
        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
    67
        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
    68
            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
    69
        }
11316
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    70
        opts.addAll(Arrays.asList(args));
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    71
        System.out.println("exec: " + opts);
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    72
        ProcessBuilder pb = new ProcessBuilder(opts);
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    73
        pb.redirectErrorStream();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    74
        Process p = pb.start();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    75
        try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    76
            String line;
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    77
            while ((line = r.readLine()) != null)
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    78
                System.out.println();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    79
        }
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    80
        int rc = p.waitFor();
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    81
        if (rc != 0)
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    82
            System.out.println("javac exited, rc=" + rc);
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
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    85
    static boolean compare(File a, File b) throws IOException {
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    86
        List<String> aLines = Files.readAllLines(a.toPath(), Charset.defaultCharset());
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    87
        List<String> bLines = Files.readAllLines(b.toPath(), Charset.defaultCharset());
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    88
        System.out.println(a + ": " + aLines.size() + " lines");
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    89
        System.out.println(b + ": " + bLines.size() + " lines");
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    90
        return aLines.equals(bLines);
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    91
    }
4dcad625e72e 7111022: javac no long prints last round of processing
jjg
parents:
diff changeset
    92
}