author | cushon |
Thu, 25 Jan 2018 15:18:13 -0800 | |
changeset 48680 | f944d1b7ab25 |
permissions | -rw-r--r-- |
48680
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
1 |
/* |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Google Inc. All rights reserved. |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
4 |
* |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
8 |
* |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
13 |
* accompanied this code). |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
14 |
* |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
18 |
* |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
21 |
* questions. |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
22 |
*/ |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
23 |
|
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
24 |
/* |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
25 |
* @test |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
26 |
* @bug 8179373 |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
27 |
* @summary javac -verbose logs the class path multiple times |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
28 |
* @modules jdk.compiler |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
29 |
* @run main VerboseClassPathTest |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
30 |
*/ |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
31 |
|
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
32 |
import java.io.BufferedReader; |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
33 |
import java.io.PrintWriter; |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
34 |
import java.io.StringReader; |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
35 |
import java.io.StringWriter; |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
36 |
import java.nio.file.Path; |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
37 |
import java.nio.file.Paths; |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
38 |
import java.util.spi.ToolProvider; |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
39 |
|
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
40 |
public class VerboseClassPathTest { |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
41 |
public static void main(String... args) throws Exception { |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
42 |
new VerboseClassPathTest().run(); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
43 |
} |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
44 |
|
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
45 |
void run() throws Exception { |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
46 |
String className = getClass().getName(); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
47 |
Path testSrc = Paths.get(System.getProperty("test.src")); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
48 |
Path file = testSrc.resolve(className + ".java"); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
49 |
ToolProvider javac = ToolProvider.findFirst("javac").orElseThrow(); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
50 |
StringWriter sw = new StringWriter(); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
51 |
PrintWriter pw = new PrintWriter(sw, true); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
52 |
int rc = |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
53 |
javac.run( |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
54 |
pw, |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
55 |
pw, |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
56 |
"-d", |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
57 |
",", |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
58 |
"-source", |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
59 |
"8", |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
60 |
"-target", |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
61 |
"8", |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
62 |
"-verbose", |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
63 |
file.toString()); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
64 |
String log = sw.toString(); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
65 |
System.out.println(log); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
66 |
if (rc != 0) { |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
67 |
throw new Exception("compilation failed: rc=" + rc); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
68 |
} |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
69 |
String expect = "[search path for class files:"; |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
70 |
long count = |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
71 |
new BufferedReader(new StringReader(log)) |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
72 |
.lines() |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
73 |
.filter(line -> line.startsWith(expect)) |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
74 |
.count(); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
75 |
if (count != 1) { |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
76 |
throw new Exception("expected '" + expect + "' to appear once, actual: " + count); |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
77 |
} |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
78 |
} |
f944d1b7ab25
8179373: javac -verbose logs the class path multiple times
cushon
parents:
diff
changeset
|
79 |
} |