author | jjg |
Thu, 04 Dec 2014 19:09:29 -0800 | |
changeset 27988 | d81c4220d579 |
parent 27319 | 030080f03e4f |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
2 |
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6348193 |
|
27 |
* @summary AS8.1 UR2 BAT test failure with "javac" |
|
28 |
* @compile -proc:none T6348193.java |
|
29 |
* @run main/othervm T6348193 |
|
30 |
*/ |
|
31 |
||
32 |
import java.io.*; |
|
33 |
import java.net.*; |
|
27988
d81c4220d579
8066737: langtools/test/tools/javac/processing/6348193/T6348193.java fails
jjg
parents:
27319
diff
changeset
|
34 |
import java.security.*; |
10 | 35 |
import java.util.*; |
36 |
import javax.annotation.processing.*; |
|
37 |
import javax.lang.model.element.*; |
|
38 |
import javax.tools.*; |
|
39 |
import com.sun.tools.javac.api.JavacTool; |
|
40 |
||
41 |
@SupportedAnnotationTypes({"*"}) |
|
42 |
public class T6348193 extends AbstractProcessor |
|
43 |
{ |
|
44 |
private static final boolean verbose = true; |
|
45 |
||
46 |
enum NoYes { NO, YES }; |
|
47 |
enum NoGoodBad { NO, GOOD, BAD}; |
|
48 |
||
49 |
public static final String myName = T6348193.class.getName(); |
|
50 |
||
51 |
public static void main(String... args) throws IOException { |
|
52 |
if (System.getSecurityManager() != null) |
|
53 |
throw new AssertionError("unexpected security manager"); |
|
54 |
||
55 |
for (NoYes secMgr: EnumSet.allOf(NoYes.class)) |
|
56 |
for (NoGoodBad config: EnumSet.allOf(NoGoodBad.class)) |
|
57 |
for (NoYes proc: EnumSet.allOf(NoYes.class)) |
|
58 |
test(secMgr, config, proc); |
|
59 |
} |
|
60 |
||
61 |
private static File processed = new File("processed"); |
|
62 |
||
63 |
public static void test(NoYes secMgr, NoGoodBad config, NoYes proc) throws IOException { |
|
64 |
if (verbose) |
|
65 |
System.err.println("secMgr:" + secMgr + " config:" + config + " proc:" + proc); |
|
66 |
||
67 |
if (secMgr == NoYes.YES && System.getSecurityManager() == null) |
|
68 |
System.setSecurityManager(new NoLoaderSecurityManager()); |
|
69 |
||
70 |
installConfigFile(config); |
|
71 |
||
72 |
processed.delete(); |
|
73 |
||
74 |
List<String> args = new ArrayList<String>(); |
|
75 |
//args.add("-XprintRounds"); |
|
76 |
if (proc == NoYes.YES) { |
|
77 |
args.add("-processor"); |
|
78 |
args.add(myName); |
|
79 |
} |
|
80 |
args.add("-processorpath"); |
|
81 |
args.add(System.getProperty("java.class.path")); |
|
82 |
args.add("-d"); |
|
83 |
args.add("."); |
|
84 |
||
85 |
JavacTool t = JavacTool.create(); // avoid using class loader |
|
86 |
||
87 |
MyDiagListener dl = new MyDiagListener(); |
|
88 |
PrintWriter out = new PrintWriter(System.err, true); |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
89 |
try (StandardJavaFileManager fm = t.getStandardFileManager(dl, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
90 |
File file = new File(System.getProperty("test.src"), myName+".java"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
91 |
Iterable<? extends JavaFileObject> files = |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
92 |
fm.getJavaFileObjectsFromFiles(Arrays.asList(file)); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
93 |
boolean ok = t.getTask(out, null, dl, args, null, files).call(); |
10 | 94 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
95 |
if (config == NoGoodBad.GOOD || proc == NoYes.YES) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
96 |
if (secMgr == NoYes.YES) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
97 |
if (dl.last == null) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
98 |
throw new AssertionError("Security manager installed, and processors present, " |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
99 |
+ " but no diagnostic received"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
100 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
101 |
else { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
102 |
if (!processed.exists()) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
103 |
throw new AssertionError("No security manager installed, and processors present, " |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
104 |
+ " but no processing occurred"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
105 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
106 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
107 |
else if (config == NoGoodBad.BAD) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
108 |
// TODO: should verify that no compiler crash occurred |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
109 |
// needs revised JSR199 spec |
10 | 110 |
} |
111 |
else { |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
112 |
if (processed.exists()) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
113 |
throw new AssertionError("No processors present, but processing occurred!"); |
10 | 114 |
} |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
115 |
|
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
116 |
if (verbose) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
117 |
System.err.println("OK"); |
10 | 118 |
} |
119 |
} |
|
120 |
||
121 |
// set up or remove a service configuration file |
|
122 |
static void installConfigFile(NoGoodBad type) throws IOException { |
|
1478
1847a080da9a
6759796: test/tools/javac/6348193/T6348193.java fails if there are empty entries on the bootclasspath
jjg
parents:
10
diff
changeset
|
123 |
File f = new File(System.getProperty("test.classes", ".")); |
10 | 124 |
for (String s: new String[] { "META-INF", "services", Processor.class.getName() }) |
125 |
f = new File(f, s); |
|
126 |
BufferedWriter out; |
|
127 |
switch (type) { |
|
128 |
case GOOD: |
|
129 |
f.getParentFile().mkdirs(); |
|
130 |
out = new BufferedWriter(new FileWriter(f)); |
|
131 |
out.write(myName); |
|
132 |
out.newLine(); |
|
133 |
out.close(); |
|
134 |
break; |
|
135 |
case BAD: |
|
136 |
f.getParentFile().mkdirs(); |
|
137 |
out = new BufferedWriter(new FileWriter(f)); |
|
138 |
out.write("This is not a valid line"); |
|
139 |
out.newLine(); |
|
140 |
out.close(); |
|
141 |
break; |
|
142 |
case NO: |
|
143 |
f.delete(); |
|
144 |
} |
|
145 |
||
146 |
||
147 |
} |
|
148 |
||
149 |
// annotation processor method |
|
150 |
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv ) |
|
151 |
{ |
|
152 |
try { |
|
153 |
// touch a file to indicate we have run |
|
154 |
new FileWriter(processed).close(); |
|
155 |
} catch (IOException e) { |
|
156 |
} |
|
157 |
return true; |
|
158 |
} |
|
159 |
||
160 |
static class MyDiagListener implements DiagnosticListener<JavaFileObject> |
|
161 |
{ |
|
162 |
public void report(Diagnostic<? extends JavaFileObject> message) { |
|
163 |
if (verbose) |
|
164 |
System.err.println(message); |
|
165 |
last = message; |
|
166 |
} |
|
167 |
||
168 |
Diagnostic<? extends JavaFileObject> last; |
|
169 |
} |
|
170 |
||
171 |
static class NoLoaderSecurityManager extends SecurityManager |
|
172 |
{ |
|
173 |
public void checkCreateClassLoader() { |
|
174 |
throw new SecurityException("Not today, thanks you!"); |
|
175 |
} |
|
176 |
||
177 |
public void checkPropertyAccess(String key) { /*OK*/ } |
|
178 |
||
179 |
public void checkDelete(String file) { /*OK*/ } |
|
27988
d81c4220d579
8066737: langtools/test/tools/javac/processing/6348193/T6348193.java fails
jjg
parents:
27319
diff
changeset
|
180 |
public void checkPermission(Permission perm) { /*OK*/ } |
10 | 181 |
public void checkRead(FileDescriptor fd) { /*OK*/ } |
182 |
public void checkRead(String file) { /*OK*/ } |
|
183 |
public void checkRead(String file, Object context) { /*OK*/ } |
|
184 |
public void checkWrite(String file) { /*OK*/ } |
|
185 |
||
186 |
} |
|
187 |
} |