author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 25603 | d5fa4eab2d26 |
child 26271 | 97603426a4ce |
permissions | -rw-r--r-- |
25290 | 1 |
/* |
2 |
* Copyright (c) 2014, 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
/* |
|
27 |
* @test |
|
28 |
* @bug 8047183 |
|
29 |
* @summary JDK build fails with sjavac enabled |
|
25603
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
25290
diff
changeset
|
30 |
* |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
25290
diff
changeset
|
31 |
* @build Wrapper |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
25290
diff
changeset
|
32 |
* @run main Wrapper IgnoreSymbolFile |
25290 | 33 |
*/ |
34 |
||
35 |
import java.io.File; |
|
36 |
import java.io.FileWriter; |
|
37 |
import java.io.IOException; |
|
38 |
import java.io.PrintStream; |
|
39 |
import java.lang.reflect.Method; |
|
40 |
import java.util.Arrays; |
|
41 |
||
42 |
public class IgnoreSymbolFile { |
|
43 |
public static void main(String... args) throws Exception { |
|
25603
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
25290
diff
changeset
|
44 |
IgnoreSymbolFile test = new IgnoreSymbolFile(); |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
25290
diff
changeset
|
45 |
test.run(); |
25290 | 46 |
} |
47 |
||
48 |
void run() throws Exception { |
|
49 |
String body = |
|
50 |
"package p;\n" |
|
51 |
+ "import sun.reflect.annotation.*;\n" |
|
52 |
+ "class X {\n" |
|
53 |
+ " ExceptionProxy proxy;" |
|
54 |
+ "}"; |
|
55 |
writeFile("src/p/X.java", body); |
|
56 |
||
57 |
new File("classes").mkdirs(); |
|
58 |
||
59 |
String server = "--server:portfile=testserver,background=false"; |
|
60 |
int rc1 = compile(server, "-d", "classes", "-Werror", "src"); |
|
61 |
if (rc1 == 0) |
|
62 |
error("compilation succeeded unexpectedly"); |
|
63 |
||
64 |
int rc2 = compile(server, "-d", "classes", "-Werror", "-XDignore.symbol.file=true", "src"); |
|
65 |
if (rc2 != 0) |
|
66 |
error("compilation failed unexpectedly: rc=" + rc2); |
|
67 |
||
68 |
if (errors > 0) |
|
69 |
throw new Exception(errors + " errors occurred"); |
|
70 |
} |
|
71 |
||
72 |
int compile(String... args) throws ReflectiveOperationException { |
|
73 |
// Use reflection to avoid a compile-time dependency on sjavac Main |
|
74 |
System.err.println("compile: " + Arrays.toString(args)); |
|
75 |
Class<?> c = Class.forName("com.sun.tools.sjavac.Main"); |
|
76 |
Method m = c.getDeclaredMethod("go", String[].class, PrintStream.class, PrintStream.class); |
|
77 |
Object sjavac = c.newInstance(); |
|
78 |
int rc = (Integer) m.invoke(sjavac, args, System.err, System.err); |
|
79 |
System.err.println("rc=" + rc); |
|
80 |
return rc; |
|
81 |
} |
|
82 |
||
83 |
void writeFile(String path, String body) throws IOException { |
|
84 |
File f = new File(path); |
|
85 |
if (f.getParentFile() != null) |
|
86 |
f.getParentFile().mkdirs(); |
|
87 |
try (FileWriter w = new FileWriter(f)) { |
|
88 |
w.write(body); |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
void error(String msg) { |
|
93 |
System.err.println("Error: " + msg); |
|
94 |
errors++; |
|
95 |
} |
|
96 |
||
97 |
int errors; |
|
98 |
} |