|
1 /* |
|
2 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. |
|
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 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 6358024 |
|
27 * @summary TaskListener should be propogated between processing rounds |
|
28 */ |
|
29 |
|
30 import java.io.*; |
|
31 import java.util.*; |
|
32 import java.util.List; |
|
33 import javax.annotation.processing.*; |
|
34 import javax.lang.model.element.*; |
|
35 import javax.tools.*; |
|
36 import com.sun.source.util.*; |
|
37 import com.sun.tools.javac.api.*; |
|
38 import com.sun.tools.javac.main.*; |
|
39 import com.sun.tools.javac.util.*; |
|
40 |
|
41 |
|
42 @SupportedAnnotationTypes("*") |
|
43 public class T6358024 extends AbstractProcessor { |
|
44 static JavacFileManager fm; |
|
45 public static void main(String... args) throws Throwable { |
|
46 String self = T6358024.class.getName(); |
|
47 |
|
48 String testSrc = System.getProperty("test.src"); |
|
49 |
|
50 fm = new JavacFileManager(new Context(), false, null); |
|
51 JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + self + ".java"); |
|
52 |
|
53 test(fm, f, |
|
54 new Option[] { new Option("-d", ".")}, |
|
55 7); |
|
56 |
|
57 test(fm, f, |
|
58 new Option[] { new XOption("-XprintRounds"), |
|
59 new Option("-processorpath", "."), |
|
60 new Option("-processor", self) }, |
|
61 11); |
|
62 } |
|
63 |
|
64 static void test(JavacFileManager fm, JavaFileObject f, Option[] opts, int expect) throws Throwable { |
|
65 PrintWriter out = new PrintWriter(System.err, true); |
|
66 |
|
67 JavacTool tool = JavacTool.create(); |
|
68 List<String> flags = new ArrayList<String>(); |
|
69 for (Option opt: opts) { |
|
70 flags.add(opt.name); |
|
71 for (Object arg : opt.args) |
|
72 flags.add(arg.toString()); |
|
73 } |
|
74 |
|
75 JavacTaskImpl task = (JavacTaskImpl) tool.getTask(out, |
|
76 fm, |
|
77 null, |
|
78 flags, |
|
79 null, |
|
80 Arrays.asList(f)); |
|
81 MyTaskListener tl = new MyTaskListener(); |
|
82 task.setTaskListener(tl); |
|
83 task.call(); |
|
84 if (tl.started != expect) |
|
85 throw new AssertionError("Unexpected number of TaskListener events; " |
|
86 + "expected " + expect + ", found " + tl.started); |
|
87 } |
|
88 |
|
89 public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { |
|
90 return true; |
|
91 } |
|
92 |
|
93 static class MyTaskListener implements TaskListener { |
|
94 public void started(TaskEvent e) { |
|
95 System.err.println("Started: " + e); |
|
96 started++; |
|
97 } |
|
98 public void finished(TaskEvent e) { |
|
99 } |
|
100 |
|
101 int started = 0; |
|
102 } |
|
103 |
|
104 static class Option { |
|
105 Option(String name, String... args) { |
|
106 this.name = name; |
|
107 this.args = args; |
|
108 } |
|
109 public final String name; |
|
110 public final String[] args; |
|
111 } |
|
112 |
|
113 static class XOption extends Option { |
|
114 XOption(String name, String... args) { |
|
115 super(name, args); |
|
116 } |
|
117 } |
|
118 } |