author | mcimadamore |
Wed, 26 Oct 2016 15:41:25 +0100 | |
changeset 41856 | 13a056e8f16e |
parent 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
2 |
* Copyright (c) 2006, 2015, 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 6361619 6392118 |
|
27 |
* @summary AssertionError from ClassReader; mismatch between JavacTaskImpl.context and JSR 269 |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.file |
10 | 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.source.util.*; |
|
39 |
import com.sun.tools.javac.api.*; |
|
40 |
import com.sun.source.util.Trees; |
|
41 |
||
42 |
@SupportedAnnotationTypes("*") |
|
43 |
public class T6361619 extends AbstractProcessor { |
|
44 |
public static void main(String... args) throws Throwable { |
|
45 |
String testSrcDir = System.getProperty("test.src"); |
|
46 |
String testClassDir = System.getProperty("test.classes"); |
|
47 |
String self = T6361619.class.getName(); |
|
48 |
||
49 |
JavacTool tool = JavacTool.create(); |
|
50 |
||
51 |
final PrintWriter out = new PrintWriter(System.err, true); |
|
52 |
||
53 |
Iterable<String> flags = Arrays.asList("-processorpath", testClassDir, |
|
54 |
"-processor", self, |
|
55 |
"-d", "."); |
|
56 |
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() { |
|
57 |
public void report(Diagnostic<? extends JavaFileObject> m) { |
|
58 |
out.println(m); |
|
59 |
} |
|
60 |
}; |
|
61 |
||
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
62 |
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
63 |
Iterable<? extends JavaFileObject> f = |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
64 |
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
65 |
self + ".java"))); |
10 | 66 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
67 |
JavacTask task = tool.getTask(out, fm, dl, flags, null, f); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
68 |
MyTaskListener tl = new MyTaskListener(task); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
69 |
task.setTaskListener(tl); |
10 | 70 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
71 |
// should complete, without exceptions |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
72 |
task.call(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
73 |
} |
10 | 74 |
} |
75 |
||
76 |
public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv) { |
|
77 |
return true; |
|
78 |
} |
|
79 |
||
80 |
||
81 |
static class MyTaskListener implements TaskListener { |
|
82 |
public MyTaskListener(JavacTask task) { |
|
83 |
this.task = task; |
|
84 |
} |
|
85 |
||
86 |
public void started(TaskEvent e) { |
|
87 |
System.err.println("Started: " + e); |
|
88 |
Trees t = Trees.instance(task); |
|
89 |
} |
|
90 |
public void finished(TaskEvent e) { |
|
91 |
System.err.println("Finished: " + e); |
|
92 |
Trees t = Trees.instance(task); |
|
93 |
} |
|
94 |
||
95 |
JavacTask task; |
|
96 |
} |
|
97 |
} |