23 |
23 |
24 /** |
24 /** |
25 * @test |
25 * @test |
26 * @summary Verify that annotation processors inside modules works |
26 * @summary Verify that annotation processors inside modules works |
27 * @library /tools/lib |
27 * @library /tools/lib |
28 * @modules |
28 * @modules jdk.compiler/com.sun.tools.javac.api |
29 * jdk.compiler/com.sun.tools.javac.api |
29 * jdk.compiler/com.sun.tools.javac.main |
30 * jdk.compiler/com.sun.tools.javac.main |
30 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
31 * jdk.jdeps/com.sun.tools.javap |
|
32 * @build ToolBox ModuleTestBase |
|
33 * @run main AnnotationProcessorsInModulesTest |
31 * @run main AnnotationProcessorsInModulesTest |
34 */ |
32 */ |
35 |
33 |
36 import java.nio.file.Files; |
34 import java.nio.file.Files; |
37 import java.nio.file.Path; |
35 import java.nio.file.Path; |
38 import java.util.Arrays; |
36 import java.util.Arrays; |
39 import java.util.List; |
37 import java.util.List; |
|
38 |
|
39 import toolbox.JavacTask; |
|
40 import toolbox.Task; |
|
41 import toolbox.ToolBox; |
40 |
42 |
41 public class AnnotationProcessorsInModulesTest extends ModuleTestBase { |
43 public class AnnotationProcessorsInModulesTest extends ModuleTestBase { |
42 |
44 |
43 public static void main(String... args) throws Exception { |
45 public static void main(String... args) throws Exception { |
44 new AnnotationProcessorsInModulesTest().runTests(); |
46 new AnnotationProcessorsInModulesTest().runTests(); |
154 Path classes; |
156 Path classes; |
155 |
157 |
156 @Test |
158 @Test |
157 void testUseOnlyOneProcessor(Path base) throws Exception { |
159 void testUseOnlyOneProcessor(Path base) throws Exception { |
158 initialization(base); |
160 initialization(base); |
159 String log = tb.new JavacTask() |
161 String log = new JavacTask(tb) |
160 .options("-processormodulepath", processorCompiledModules.toString(), |
162 .options("-processormodulepath", processorCompiledModules.toString(), |
161 "-processor", "mypkg2.MyProcessor2") |
163 "-processor", "mypkg2.MyProcessor2") |
162 .outdir(classes) |
164 .outdir(classes) |
163 .sources(testClass) |
165 .sources(testClass) |
164 .run() |
166 .run() |
165 .writeAll() |
167 .writeAll() |
166 .getOutput(ToolBox.OutputKind.STDOUT); |
168 .getOutput(Task.OutputKind.STDOUT); |
167 if (!log.trim().equals("the annotation processor 2 is working!")) { |
169 if (!log.trim().equals("the annotation processor 2 is working!")) { |
168 throw new AssertionError("Unexpected output: " + log); |
170 throw new AssertionError("Unexpected output: " + log); |
169 } |
171 } |
170 } |
172 } |
171 |
173 |
172 @Test |
174 @Test |
173 void testAnnotationProcessorExecutionOrder(Path base) throws Exception { |
175 void testAnnotationProcessorExecutionOrder(Path base) throws Exception { |
174 initialization(base); |
176 initialization(base); |
175 List<String> log = tb.new JavacTask() |
177 List<String> log = new JavacTask(tb) |
176 .options("-processormodulepath", processorCompiledModules.toString(), |
178 .options("-processormodulepath", processorCompiledModules.toString(), |
177 "-processor", "mypkg1.MyProcessor1,mypkg2.MyProcessor2") |
179 "-processor", "mypkg1.MyProcessor1,mypkg2.MyProcessor2") |
178 .outdir(classes) |
180 .outdir(classes) |
179 .sources(testClass) |
181 .sources(testClass) |
180 .run() |
182 .run() |
181 .writeAll() |
183 .writeAll() |
182 .getOutputLines(ToolBox.OutputKind.STDOUT); |
184 .getOutputLines(Task.OutputKind.STDOUT); |
183 if (!log.equals(Arrays.asList("the annotation processor 1 is working!", |
185 if (!log.equals(Arrays.asList("the annotation processor 1 is working!", |
184 "the annotation processor 2 is working!"))) { |
186 "the annotation processor 2 is working!"))) { |
185 throw new AssertionError("Unexpected output: " + log); |
187 throw new AssertionError("Unexpected output: " + log); |
186 } |
188 } |
187 |
189 |
188 log = tb.new JavacTask() |
190 log = new JavacTask(tb) |
189 .options("-processormodulepath", processorCompiledModules.toString(), |
191 .options("-processormodulepath", processorCompiledModules.toString(), |
190 "-processor", "mypkg2.MyProcessor2,mypkg1.MyProcessor1") |
192 "-processor", "mypkg2.MyProcessor2,mypkg1.MyProcessor1") |
191 .outdir(classes) |
193 .outdir(classes) |
192 .sources(testClass) |
194 .sources(testClass) |
193 .run() |
195 .run() |
194 .writeAll() |
196 .writeAll() |
195 .getOutputLines(ToolBox.OutputKind.STDOUT); |
197 .getOutputLines(Task.OutputKind.STDOUT); |
196 if (!log.equals(Arrays.asList("the annotation processor 2 is working!", |
198 if (!log.equals(Arrays.asList("the annotation processor 2 is working!", |
197 "the annotation processor 1 is working!"))) { |
199 "the annotation processor 1 is working!"))) { |
198 throw new AssertionError("Unexpected output: " + log); |
200 throw new AssertionError("Unexpected output: " + log); |
199 } |
201 } |
200 } |
202 } |
201 |
203 |
202 @Test |
204 @Test |
203 void testErrorOutputIfOneProcessorNameIsIncorrect(Path base) throws Exception { |
205 void testErrorOutputIfOneProcessorNameIsIncorrect(Path base) throws Exception { |
204 initialization(base); |
206 initialization(base); |
205 String log = tb.new JavacTask() |
207 String log = new JavacTask(tb) |
206 .options("-XDrawDiagnostics", "-processormodulepath", processorCompiledModules.toString(), |
208 .options("-XDrawDiagnostics", "-processormodulepath", processorCompiledModules.toString(), |
207 "-processor", "mypkg2.MyProcessor2,noPackage.noProcessor,mypkg1.MyProcessor1") |
209 "-processor", "mypkg2.MyProcessor2,noPackage.noProcessor,mypkg1.MyProcessor1") |
208 .outdir(classes) |
210 .outdir(classes) |
209 .sources(testClass) |
211 .sources(testClass) |
210 .run(ToolBox.Expect.FAIL) |
212 .run(Task.Expect.FAIL) |
211 .writeAll() |
213 .writeAll() |
212 .getOutputLines(ToolBox.OutputKind.STDOUT, ToolBox.OutputKind.DIRECT).toString(); |
214 .getOutputLines(Task.OutputKind.STDOUT, Task.OutputKind.DIRECT).toString(); |
213 if (!log.trim().equals("[the annotation processor 2 is working!, - compiler.err.proc.processor.not.found: noPackage.noProcessor, 1 error]")) { |
215 if (!log.trim().equals("[the annotation processor 2 is working!, - compiler.err.proc.processor.not.found: noPackage.noProcessor, 1 error]")) { |
214 throw new AssertionError("Unexpected output: " + log); |
216 throw new AssertionError("Unexpected output: " + log); |
215 } |
217 } |
216 } |
218 } |
217 |
219 |
218 @Test |
220 @Test |
219 void testOptionsExclusion(Path base) throws Exception { |
221 void testOptionsExclusion(Path base) throws Exception { |
220 initialization(base); |
222 initialization(base); |
221 List<String> log = tb.new JavacTask() |
223 List<String> log = new JavacTask(tb) |
222 .options("-XDrawDiagnostics", "-processormodulepath", processorCompiledModules.toString(), |
224 .options("-XDrawDiagnostics", "-processormodulepath", processorCompiledModules.toString(), |
223 "-processorpath", processorCompiledModules.toString()) |
225 "-processorpath", processorCompiledModules.toString()) |
224 .outdir(classes) |
226 .outdir(classes) |
225 .sources(testClass) |
227 .sources(testClass) |
226 .run(ToolBox.Expect.FAIL) |
228 .run(Task.Expect.FAIL) |
227 .writeAll() |
229 .writeAll() |
228 .getOutputLines(ToolBox.OutputKind.DIRECT); |
230 .getOutputLines(Task.OutputKind.DIRECT); |
229 if (!log.equals(Arrays.asList("- compiler.err.processorpath.no.processormodulepath", |
231 if (!log.equals(Arrays.asList("- compiler.err.processorpath.no.processormodulepath", |
230 "1 error"))) { |
232 "1 error"))) { |
231 throw new AssertionError("Unexpected output: " + log); |
233 throw new AssertionError("Unexpected output: " + log); |
232 } |
234 } |
233 } |
235 } |