author | avstepan |
Tue, 19 May 2015 16:04:14 +0400 | |
changeset 30655 | d83f50188ca9 |
parent 27319 | 030080f03e4f |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
8844
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
1 |
/* |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
2 |
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
8844
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
4 |
* |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
8 |
* |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
14 |
* |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
18 |
* |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
21 |
* questions. |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
22 |
*/ |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
23 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
24 |
/* |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
25 |
* @test |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
26 |
* @bug 7026509 |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
27 |
* @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
28 |
*/ |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
29 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
30 |
import java.io.*; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
31 |
import java.util.*; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
32 |
import javax.lang.model.element.*; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
33 |
import javax.tools.*; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
34 |
import com.sun.source.tree.*; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
35 |
import com.sun.source.util.*; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
36 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
37 |
public class TestJavacTask_ParseAttrGen { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
38 |
public static void main(String... args) throws Exception { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
39 |
new TestJavacTask_ParseAttrGen().run(); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
40 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
41 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
42 |
JavaCompiler comp; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
43 |
StandardJavaFileManager fm; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
44 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
45 |
void run() throws Exception { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
46 |
comp = ToolProvider.getSystemJavaCompiler(); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
47 |
fm = comp.getStandardFileManager(null, null, null); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
48 |
try { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
49 |
final boolean[] booleanValues = { false, true }; |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
50 |
for (boolean pk: booleanValues) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
51 |
for (boolean ak: booleanValues) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
52 |
for (boolean gk: booleanValues) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
53 |
test(pk, ak, gk); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
54 |
} |
8844
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
55 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
56 |
} |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
57 |
} finally { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
9744
diff
changeset
|
58 |
fm.close(); |
8844
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
59 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
60 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
61 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
62 |
void test(boolean pk, boolean ak, boolean gk) throws Exception { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
63 |
if (!pk && !ak && !gk) // nothing to do |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
64 |
return; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
65 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
66 |
System.err.println("test: pk:" + pk + ", ak:" + ak + ", gk: " + gk); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
67 |
File testSrc = new File(System.getProperty("test.src")); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
68 |
String thisClassName = TestJavacTask_ParseAttrGen.class.getName(); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
69 |
Iterable<? extends JavaFileObject> files = |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
70 |
fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java")); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
71 |
File tmpDir = new File((pk ? "p" : "") + (ak ? "a" : "") + (gk ? "g" : "")); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
72 |
tmpDir.mkdirs(); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
73 |
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir)); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
74 |
JavacTask t = (JavacTask) comp.getTask(null, fm, null, null, null, files); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
75 |
//t.setTaskListener(createTaskListener()); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
76 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
77 |
try { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
78 |
if (pk) { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
79 |
Iterable<? extends CompilationUnitTree> trees = t.parse(); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
80 |
System.err.println(count(trees) + " trees parsed"); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
81 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
82 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
83 |
if (ak) { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
84 |
Iterable<? extends Element> elems = t.analyze(); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
85 |
System.err.println(count(elems) + " elements analyzed"); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
86 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
87 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
88 |
if (gk) { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
89 |
Iterable<? extends JavaFileObject> classfiles = t.generate(); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
90 |
System.err.println(count(classfiles) + " class files generated"); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
91 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
92 |
} catch (IOException e) { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
93 |
error("unexpected exception caught: " + e); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
94 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
95 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
96 |
File[] genFiles = tmpDir.listFiles(); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
97 |
int expect = (gk ? 2 : 0); // main class and anon class for TaskListener |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
98 |
if (genFiles.length != expect) |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
99 |
error("unexpected number of files generated: " + genFiles.length |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
100 |
+ ", expected: " + expect); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
101 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
102 |
System.err.println(); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
103 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
104 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
105 |
TaskListener createTaskListener() { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
106 |
return new TaskListener() { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
107 |
public void started(TaskEvent e) { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
108 |
System.err.println(e + " started"); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
109 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
110 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
111 |
public void finished(TaskEvent e) { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
112 |
System.err.println(e + " finished"); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
113 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
114 |
}; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
115 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
116 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
117 |
<T> int count(Iterable<T> items) { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
118 |
int count = 0; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
119 |
for (T item: items) |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
120 |
count++; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
121 |
return count; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
122 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
123 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
124 |
void error(String msg) { |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
125 |
System.err.println("Error: " + msg); |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
126 |
errors++; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
127 |
} |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
128 |
|
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
129 |
int errors; |
18170a311747
7026509: Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
jjg
parents:
diff
changeset
|
130 |
} |