< prev index next >

test/tools/javac/modules/AnnotationProcessorsInModulesTest.java

Print this page




 119     void initialization(Path base) throws Exception {
 120         moduleSrc = base.resolve("anno_proc_src");
 121         Path anno_proc1 = moduleSrc.resolve("anno_proc1");
 122         Path anno_proc2 = moduleSrc.resolve("anno_proc2");
 123 
 124         processorCompiledModules = base.resolve("mods");
 125 
 126         Files.createDirectories(processorCompiledModules);
 127 
 128         tb.writeJavaFiles(
 129                 anno_proc1,
 130                 annotationProcessorModule1,
 131                 annotationProcessor1);
 132 
 133         tb.writeJavaFiles(
 134                 anno_proc2,
 135                 annotationProcessorModule2,
 136                 annotationProcessor2);
 137 
 138         String log = new JavacTask(tb)
 139                 .options("-modulesourcepath", moduleSrc.toString())
 140                 .outdir(processorCompiledModules)
 141                 .files(findJavaFiles(moduleSrc))
 142                 .run()
 143                 .writeAll()
 144                 .getOutput(Task.OutputKind.DIRECT);
 145 
 146         if (!log.isEmpty()) {
 147             throw new AssertionError("Unexpected output: " + log);
 148         }
 149 
 150         classes = base.resolve("classes");
 151         Files.createDirectories(classes);
 152     }
 153 
 154     Path processorCompiledModules;
 155     Path moduleSrc;
 156     Path classes;
 157 
 158     @Test
 159     public void testUseOnlyOneProcessor(Path base) throws Exception {
 160         initialization(base);
 161         String log = new JavacTask(tb)
 162                 .options("-processormodulepath", processorCompiledModules.toString(),
 163                         "-processor", "mypkg2.MyProcessor2")
 164                 .outdir(classes)
 165                 .sources(testClass)
 166                 .run()
 167                 .writeAll()
 168                 .getOutput(Task.OutputKind.STDOUT);
 169         if (!log.trim().equals("the annotation processor 2 is working!")) {
 170             throw new AssertionError("Unexpected output: " + log);
 171         }
 172     }
 173 
 174     @Test
 175     public void testAnnotationProcessorExecutionOrder(Path base) throws Exception {
 176         initialization(base);
 177         List<String> log = new JavacTask(tb)
 178                 .options("-processormodulepath", processorCompiledModules.toString(),
 179                         "-processor", "mypkg1.MyProcessor1,mypkg2.MyProcessor2")
 180                 .outdir(classes)
 181                 .sources(testClass)
 182                 .run()
 183                 .writeAll()
 184                 .getOutputLines(Task.OutputKind.STDOUT);
 185         if (!log.equals(Arrays.asList("the annotation processor 1 is working!",
 186                                       "the annotation processor 2 is working!"))) {
 187             throw new AssertionError("Unexpected output: " + log);
 188         }
 189 
 190         log = new JavacTask(tb)
 191                 .options("-processormodulepath", processorCompiledModules.toString(),
 192                         "-processor", "mypkg2.MyProcessor2,mypkg1.MyProcessor1")
 193                 .outdir(classes)
 194                 .sources(testClass)
 195                 .run()
 196                 .writeAll()
 197                 .getOutputLines(Task.OutputKind.STDOUT);
 198         if (!log.equals(Arrays.asList("the annotation processor 2 is working!",
 199                                       "the annotation processor 1 is working!"))) {
 200             throw new AssertionError("Unexpected output: " + log);
 201         }
 202     }
 203 
 204     @Test
 205     public void testErrorOutputIfOneProcessorNameIsIncorrect(Path base) throws Exception {
 206         initialization(base);
 207         String log = new JavacTask(tb)
 208                 .options("-XDrawDiagnostics", "-processormodulepath", processorCompiledModules.toString(),

 209                          "-processor", "mypkg2.MyProcessor2,noPackage.noProcessor,mypkg1.MyProcessor1")
 210                 .outdir(classes)
 211                 .sources(testClass)
 212                 .run(Task.Expect.FAIL)
 213                 .writeAll()
 214                 .getOutputLines(Task.OutputKind.STDOUT, Task.OutputKind.DIRECT).toString();
 215         if (!log.trim().equals("[the annotation processor 2 is working!, - compiler.err.proc.processor.not.found: noPackage.noProcessor, 1 error]")) {
 216             throw new AssertionError("Unexpected output: " + log);
 217         }
 218     }
 219 
 220     @Test
 221     public void testOptionsExclusion(Path base) throws Exception {
 222         initialization(base);
 223         List<String> log = new JavacTask(tb)
 224                 .options("-XDrawDiagnostics", "-processormodulepath", processorCompiledModules.toString(),
 225                         "-processorpath", processorCompiledModules.toString())

 226                 .outdir(classes)
 227                 .sources(testClass)
 228                 .run(Task.Expect.FAIL)
 229                 .writeAll()
 230                 .getOutputLines(Task.OutputKind.DIRECT);
 231         if (!log.equals(Arrays.asList("- compiler.err.processorpath.no.processormodulepath",
 232                                       "1 error"))) {
 233             throw new AssertionError("Unexpected output: " + log);
 234         }
 235     }
 236 }


 119     void initialization(Path base) throws Exception {
 120         moduleSrc = base.resolve("anno_proc_src");
 121         Path anno_proc1 = moduleSrc.resolve("anno_proc1");
 122         Path anno_proc2 = moduleSrc.resolve("anno_proc2");
 123 
 124         processorCompiledModules = base.resolve("mods");
 125 
 126         Files.createDirectories(processorCompiledModules);
 127 
 128         tb.writeJavaFiles(
 129                 anno_proc1,
 130                 annotationProcessorModule1,
 131                 annotationProcessor1);
 132 
 133         tb.writeJavaFiles(
 134                 anno_proc2,
 135                 annotationProcessorModule2,
 136                 annotationProcessor2);
 137 
 138         String log = new JavacTask(tb)
 139                 .options("--module-source-path", moduleSrc.toString())
 140                 .outdir(processorCompiledModules)
 141                 .files(findJavaFiles(moduleSrc))
 142                 .run()
 143                 .writeAll()
 144                 .getOutput(Task.OutputKind.DIRECT);
 145 
 146         if (!log.isEmpty()) {
 147             throw new AssertionError("Unexpected output: " + log);
 148         }
 149 
 150         classes = base.resolve("classes");
 151         Files.createDirectories(classes);
 152     }
 153 
 154     Path processorCompiledModules;
 155     Path moduleSrc;
 156     Path classes;
 157 
 158     @Test
 159     public void testUseOnlyOneProcessor(Path base) throws Exception {
 160         initialization(base);
 161         String log = new JavacTask(tb)
 162                 .options("--processor-module-path", processorCompiledModules.toString(),
 163                         "-processor", "mypkg2.MyProcessor2")
 164                 .outdir(classes)
 165                 .sources(testClass)
 166                 .run()
 167                 .writeAll()
 168                 .getOutput(Task.OutputKind.STDOUT);
 169         if (!log.trim().equals("the annotation processor 2 is working!")) {
 170             throw new AssertionError("Unexpected output: " + log);
 171         }
 172     }
 173 
 174     @Test
 175     public void testAnnotationProcessorExecutionOrder(Path base) throws Exception {
 176         initialization(base);
 177         List<String> log = new JavacTask(tb)
 178                 .options("--processor-module-path", processorCompiledModules.toString(),
 179                         "-processor", "mypkg1.MyProcessor1,mypkg2.MyProcessor2")
 180                 .outdir(classes)
 181                 .sources(testClass)
 182                 .run()
 183                 .writeAll()
 184                 .getOutputLines(Task.OutputKind.STDOUT);
 185         if (!log.equals(Arrays.asList("the annotation processor 1 is working!",
 186                                       "the annotation processor 2 is working!"))) {
 187             throw new AssertionError("Unexpected output: " + log);
 188         }
 189 
 190         log = new JavacTask(tb)
 191                 .options("--processor-module-path", processorCompiledModules.toString(),
 192                         "-processor", "mypkg2.MyProcessor2,mypkg1.MyProcessor1")
 193                 .outdir(classes)
 194                 .sources(testClass)
 195                 .run()
 196                 .writeAll()
 197                 .getOutputLines(Task.OutputKind.STDOUT);
 198         if (!log.equals(Arrays.asList("the annotation processor 2 is working!",
 199                                       "the annotation processor 1 is working!"))) {
 200             throw new AssertionError("Unexpected output: " + log);
 201         }
 202     }
 203 
 204     @Test
 205     public void testErrorOutputIfOneProcessorNameIsIncorrect(Path base) throws Exception {
 206         initialization(base);
 207         String log = new JavacTask(tb)
 208                 .options("-XDrawDiagnostics",
 209                          "--processor-module-path", processorCompiledModules.toString(),
 210                          "-processor", "mypkg2.MyProcessor2,noPackage.noProcessor,mypkg1.MyProcessor1")
 211                 .outdir(classes)
 212                 .sources(testClass)
 213                 .run(Task.Expect.FAIL)
 214                 .writeAll()
 215                 .getOutputLines(Task.OutputKind.STDOUT, Task.OutputKind.DIRECT).toString();
 216         if (!log.trim().equals("[the annotation processor 2 is working!, - compiler.err.proc.processor.not.found: noPackage.noProcessor, 1 error]")) {
 217             throw new AssertionError("Unexpected output: " + log);
 218         }
 219     }
 220 
 221     @Test
 222     public void testOptionsExclusion(Path base) throws Exception {
 223         initialization(base);
 224         List<String> log = new JavacTask(tb)
 225                 .options("-XDrawDiagnostics",
 226                         "--processor-module-path", processorCompiledModules.toString(),
 227                         "--processor-path", processorCompiledModules.toString())
 228                 .outdir(classes)
 229                 .sources(testClass)
 230                 .run(Task.Expect.FAIL)
 231                 .writeAll()
 232                 .getOutputLines(Task.OutputKind.DIRECT);
 233         if (!log.equals(Arrays.asList("- compiler.err.processorpath.no.processormodulepath",
 234                                       "1 error"))) {
 235             throw new AssertionError("Unexpected output: " + log);
 236         }
 237     }
 238 }
< prev index next >