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