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