1 | /*
|
---|
2 | * Copyright (c) 2006, Oracle and/or its affiliates. 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 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.
|
---|
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.file.*;
|
---|
39 | import com.sun.tools.javac.file.JavacFileManager;
|
---|
40 | import com.sun.tools.javac.main.*;
|
---|
41 | import com.sun.tools.javac.util.*;
|
---|
42 |
|
---|
43 |
|
---|
44 | @SupportedAnnotationTypes("*")
|
---|
45 | public class T6358024 extends AbstractProcessor {
|
---|
46 | static JavacFileManager fm;
|
---|
47 | public static void main(String... args) throws Throwable {
|
---|
48 | String self = T6358024.class.getName();
|
---|
49 |
|
---|
50 | String testSrc = System.getProperty("test.src");
|
---|
51 |
|
---|
52 | fm = new JavacFileManager(new Context(), false, null);
|
---|
53 | JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + self + ".java");
|
---|
54 |
|
---|
55 | test(fm, f,
|
---|
56 | new Option[] { new Option("-d", ".")},
|
---|
57 | 7);
|
---|
58 |
|
---|
59 | test(fm, f,
|
---|
60 | new Option[] { new XOption("-XprintRounds"),
|
---|
61 | new Option("-processorpath", "."),
|
---|
62 | new Option("-processor", self) },
|
---|
63 | 11);
|
---|
64 | }
|
---|
65 |
|
---|
66 | static void test(JavacFileManager fm, JavaFileObject f, Option[] opts, int expect) throws Throwable {
|
---|
67 | PrintWriter out = new PrintWriter(System.err, true);
|
---|
68 |
|
---|
69 | JavacTool tool = JavacTool.create();
|
---|
70 | List<String> flags = new ArrayList<String>();
|
---|
71 | for (Option opt: opts) {
|
---|
72 | flags.add(opt.name);
|
---|
73 | for (Object arg : opt.args)
|
---|
74 | flags.add(arg.toString());
|
---|
75 | }
|
---|
76 |
|
---|
77 | JavacTaskImpl task = (JavacTaskImpl) tool.getTask(out,
|
---|
78 | fm,
|
---|
79 | null,
|
---|
80 | flags,
|
---|
81 | null,
|
---|
82 | Arrays.asList(f));
|
---|
83 | MyTaskListener tl = new MyTaskListener();
|
---|
84 | task.setTaskListener(tl);
|
---|
85 | task.call();
|
---|
86 | if (tl.started != expect)
|
---|
87 | throw new AssertionError("Unexpected number of TaskListener events; "
|
---|
88 | + "expected " + expect + ", found " + tl.started);
|
---|
89 | }
|
---|
90 |
|
---|
91 | public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
|
---|
92 | return true;
|
---|
93 | }
|
---|
94 |
|
---|
95 | static class MyTaskListener implements TaskListener {
|
---|
96 | public void started(TaskEvent e) {
|
---|
97 | System.err.println("Started: " + e);
|
---|
98 | started++;
|
---|
99 | }
|
---|
100 | public void finished(TaskEvent e) {
|
---|
101 | }
|
---|
102 |
|
---|
103 | int started = 0;
|
---|
104 | }
|
---|
105 |
|
---|
106 | static class Option {
|
---|
107 | Option(String name, String... args) {
|
---|
108 | this.name = name;
|
---|
109 | this.args = args;
|
---|
110 | }
|
---|
111 | public final String name;
|
---|
112 | public final String[] args;
|
---|
113 | }
|
---|
114 |
|
---|
115 | static class XOption extends Option {
|
---|
116 | XOption(String name, String... args) {
|
---|
117 | super(name, args);
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|