author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 19488 | 3d9b2d67f71f |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
1 |
/* |
19488
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
4 |
* |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
8 |
* |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
14 |
* |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
18 |
* |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
21 |
* questions. |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
22 |
*/ |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
23 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
24 |
/* |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
25 |
* @test |
19488
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
26 |
* @bug 6960424 8022161 |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
27 |
* @summary new option -Xpkginfo for better control of when package-info.class |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
28 |
* is generated, also ensures no failures if package-info.java is |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
29 |
* not available. |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
30 |
*/ |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
31 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
32 |
import java.io.*; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
33 |
import java.util.*; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
34 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
35 |
public class TestPkgInfo { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
36 |
enum OptKind { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
37 |
NONE(null), |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
38 |
ALWAYS("-Xpkginfo:always"), |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
39 |
NONEMPTY("-Xpkginfo:nonempty"), |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
40 |
LEGACY("-Xpkginfo:legacy"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
41 |
OptKind(String opt) { this.opt = opt; } |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
42 |
final String opt; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
43 |
}; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
44 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
45 |
public static void main(String... args) throws Exception { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
46 |
new TestPkgInfo().run(args); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
47 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
48 |
public void run(String... args) throws Exception { |
19488
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
49 |
testPositive(); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
50 |
testNoExceptions(); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
51 |
} |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
52 |
public void testPositive(String... args) throws Exception { |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
53 |
boolean[] booleanValues = { false, true }; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
54 |
for (OptKind ok: OptKind.values()) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
55 |
for (boolean sr: booleanValues) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
56 |
for (boolean cr: booleanValues) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
57 |
for (boolean rr: booleanValues) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
58 |
try { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
59 |
test(ok, sr, cr, rr); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
60 |
} catch (Exception e) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
61 |
error("Exception: " + e); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
62 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
63 |
if (errors > 0) throw new AssertionError(); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
64 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
65 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
66 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
67 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
68 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
69 |
if (errors > 0) |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
70 |
throw new Exception(errors + " errors occurred"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
71 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
72 |
|
19488
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
73 |
/** this should throw no exceptions **/ |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
74 |
void testNoExceptions() throws Exception { |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
75 |
count++; |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
76 |
System.err.println("Test " + count + ": ALWAYS nofile"); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
77 |
|
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
78 |
StringBuilder sb = new StringBuilder(); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
79 |
sb.append("package test; class Hello{}"); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
80 |
|
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
81 |
// test specific tmp directory |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
82 |
File tmpDir = new File("tmp.test" + count); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
83 |
File classesDir = new File(tmpDir, "classes"); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
84 |
classesDir.mkdirs(); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
85 |
File javafile = new File(new File(tmpDir, "src"), "Hello.java"); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
86 |
writeFile(javafile, sb.toString()); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
87 |
// build up list of options and files to be compiled |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
88 |
List<String> opts = new ArrayList<>(); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
89 |
List<File> files = new ArrayList<>(); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
90 |
|
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
91 |
opts.add("-d"); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
92 |
opts.add(classesDir.getPath()); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
93 |
opts.add("-Xpkginfo:always"); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
94 |
files.add(javafile); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
95 |
|
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
96 |
compile(opts, files); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
97 |
} |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
98 |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
99 |
void test(OptKind ok, boolean sr, boolean cr, boolean rr) throws Exception { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
100 |
count++; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
101 |
System.err.println("Test " + count + ": ok:" + ok + " sr:" + sr + " cr:" + cr + " rr:" + rr); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
102 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
103 |
StringBuilder sb = new StringBuilder(); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
104 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
105 |
// create annotated package statement with all combinations of retention policy |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
106 |
if (sr) sb.append("@SR\n"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
107 |
if (cr) sb.append("@CR\n"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
108 |
if (rr) sb.append("@RR\n"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
109 |
sb.append("package p;\n"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
110 |
sb.append("\n"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
111 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
112 |
sb.append("import java.lang.annotation.*;\n"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
113 |
sb.append("@Retention(RetentionPolicy.SOURCE) @interface SR { }\n"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
114 |
sb.append("@Retention(RetentionPolicy.CLASS) @interface CR { }\n"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
115 |
sb.append("@Retention(RetentionPolicy.RUNTIME) @interface RR { }\n"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
116 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
117 |
// test specific tmp directory |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
118 |
File tmpDir = new File("tmp.test" + count); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
119 |
File classesDir = new File(tmpDir, "classes"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
120 |
classesDir.mkdirs(); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
121 |
File pkginfo_java = new File(new File(tmpDir, "src"), "package-info.java"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
122 |
writeFile(pkginfo_java, sb.toString()); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
123 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
124 |
// build up list of options and files to be compiled |
19488
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
125 |
List<String> opts = new ArrayList<>(); |
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
126 |
List<File> files = new ArrayList<>(); |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
127 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
128 |
opts.add("-d"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
129 |
opts.add(classesDir.getPath()); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
130 |
if (ok.opt != null) |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
131 |
opts.add(ok.opt); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
132 |
//opts.add("-verbose"); |
19488
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
133 |
files.add(pkginfo_java); |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
134 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
135 |
compile(opts, files); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
136 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
137 |
File pkginfo_class = new File(new File(classesDir, "p"), "package-info.class"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
138 |
boolean exists = pkginfo_class.exists(); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
139 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
140 |
boolean expected; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
141 |
switch (ok) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
142 |
case ALWAYS: |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
143 |
expected = true; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
144 |
break; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
145 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
146 |
case LEGACY: |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
147 |
case NONE: |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
148 |
expected = (sr || cr || rr ); // any annotation |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
149 |
break; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
150 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
151 |
case NONEMPTY: |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
152 |
expected = (cr || rr ); // any annotation in class file |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
153 |
break; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
154 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
155 |
default: |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
156 |
throw new IllegalStateException(); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
157 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
158 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
159 |
if (exists && !expected) |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
160 |
error("package-info.class found but not expected"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
161 |
if (!exists && expected) |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
162 |
error("package-info.class expected but not found"); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
163 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
164 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
165 |
/** Compile files with options provided. */ |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
166 |
void compile(List<String> opts, List<File> files) throws Exception { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
167 |
System.err.println("javac: " + opts + " " + files); |
19488
3d9b2d67f71f
8022161: javac Null Pointer Exception in Enter.visitTopLevel
ksrini
parents:
6575
diff
changeset
|
168 |
List<String> args = new ArrayList<>(); |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
169 |
args.addAll(opts); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
170 |
for (File f: files) |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
171 |
args.add(f.getPath()); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
172 |
StringWriter sw = new StringWriter(); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
173 |
PrintWriter pw = new PrintWriter(sw); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
174 |
int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
175 |
pw.flush(); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
176 |
if (sw.getBuffer().length() > 0) |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
177 |
System.err.println(sw.toString()); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
178 |
if (rc != 0) |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
179 |
throw new Exception("compilation failed: rc=" + rc); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
180 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
181 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
182 |
/** Write a file with a given body. */ |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
183 |
void writeFile(File f, String body) throws Exception { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
184 |
if (f.getParentFile() != null) |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
185 |
f.getParentFile().mkdirs(); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
186 |
Writer out = new FileWriter(f); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
187 |
try { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
188 |
out.write(body); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
189 |
} finally { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
190 |
out.close(); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
191 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
192 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
193 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
194 |
/** Report an error. */ |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
195 |
void error(String msg) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
196 |
System.err.println("Error: " + msg); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
197 |
errors++; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
198 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
199 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
200 |
/** Test case counter. */ |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
201 |
int count; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
202 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
203 |
/** Number of errors found. */ |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
204 |
int errors; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff
changeset
|
205 |
} |