PluginsInModulesTest.java revision 3822:d8766c39123a
1118848Simp/* 2118848Simp * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3118848Simp * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4118848Simp * 5118848Simp * This code is free software; you can redistribute it and/or modify it 6118848Simp * under the terms of the GNU General Public License version 2 only, as 7118848Simp * published by the Free Software Foundation. 8118848Simp * 9118848Simp * This code is distributed in the hope that it will be useful, but WITHOUT 10118848Simp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11118848Simp * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12118848Simp * version 2 for more details (a copy is included in the LICENSE file that 13118848Simp * accompanied this code). 14118848Simp * 15118848Simp * You should have received a copy of the GNU General Public License version 16118848Simp * 2 along with this work; if not, write to the Free Software Foundation, 17118848Simp * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18118848Simp * 19118848Simp * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20118848Simp * or visit www.oracle.com if you need additional information or have any 21118848Simp * questions. 22118848Simp */ 23118848Simp 24118848Simp/** 25118848Simp * @test 26118848Simp * @summary Verify that plugins inside modules works 2742956Sdillon * @library /tools/lib 2842956Sdillon * @modules 2942956Sdillon * jdk.compiler/com.sun.tools.javac.api 3042956Sdillon * jdk.compiler/com.sun.tools.javac.main 3142956Sdillon * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase 32229832Seadler * @run main PluginsInModulesTest 3342956Sdillon */ 3442956Sdillon 3542956Sdillonimport java.nio.file.Files; 3642956Sdillonimport java.nio.file.Path; 3742956Sdillonimport java.util.Arrays; 3842956Sdillonimport java.util.List; 3942956Sdillon 4042956Sdillonimport toolbox.JavacTask; 4142956Sdillonimport toolbox.Task; 4242956Sdillon 4342956Sdillonpublic class PluginsInModulesTest extends ModuleTestBase { 4442956Sdillon 4542956Sdillon public static void main(String... args) throws Exception { 4642956Sdillon new PluginsInModulesTest().runTests(); 4742956Sdillon } 4842956Sdillon 4942956Sdillon private static final String pluginModule1 = 5042956Sdillon "module pluginMod1x {\n" + 5142956Sdillon " requires jdk.compiler;\n" + 5242956Sdillon "\n" + 5342956Sdillon " provides com.sun.source.util.Plugin\n" + 5442956Sdillon " with mypkg1.SimplePlugin1;\n" + 55246708Spluknet "}"; 56246708Spluknet 57246708Spluknet private static final String plugin1 = 58246708Spluknet "package mypkg1;\n" + 5942956Sdillon "import com.sun.source.util.JavacTask;\n" + 6042956Sdillon "import com.sun.source.util.Plugin;\n" + 6142956Sdillon "import com.sun.source.util.TaskEvent;\n" + 6242956Sdillon "import com.sun.source.util.TaskListener;\n" + 6342956Sdillon "\n" + 6442956Sdillon "public class SimplePlugin1 implements Plugin {\n" + 6542956Sdillon "\n" + 6642956Sdillon " @Override\n" + 6742956Sdillon " public String getName() {\n" + 6842956Sdillon " return \"simpleplugin1\";\n" + 6942956Sdillon " }\n" + 7042956Sdillon "\n" + 71229832Seadler " @Override\n" + 7242956Sdillon " public void init(JavacTask task, String... args) {\n" + 7342956Sdillon " task.addTaskListener(new PostAnalyzeTaskListener());\n" + 7442956Sdillon " }\n" + 7542956Sdillon "\n" + 7642956Sdillon " private static class PostAnalyzeTaskListener implements TaskListener {\n" + 7742956Sdillon " @Override\n" + 7842956Sdillon " public void started(TaskEvent taskEvent) { \n" + 7942956Sdillon " if (taskEvent.getKind().equals(TaskEvent.Kind.COMPILATION)) {\n" + 8042956Sdillon " System.out.println(\"simpleplugin1 started for event \" + taskEvent.getKind());\n" + 8142956Sdillon " }\n" + 82116182Sobrien " }\n" + 83116182Sobrien "\n" + 84116182Sobrien " @Override\n" + 8555206Speter " public void finished(TaskEvent taskEvent) {\n" + 8642956Sdillon " if (taskEvent.getKind().equals(TaskEvent.Kind.COMPILATION)) {\n" + 8742956Sdillon " System.out.println(\"simpleplugin1 finished for event \" + taskEvent.getKind());\n" + 8842956Sdillon " }\n" + 8942956Sdillon " }\n" + 9042956Sdillon " }\n" + 9142956Sdillon "}"; 9242956Sdillon 9379224Sdillon private static final String testClass = "class Test { }"; 9476827Salfred 9542956Sdillon void initialization(Path base) throws Exception { 9642956Sdillon moduleSrc = base.resolve("plugin_mods_src"); 9742956Sdillon Path pluginMod1 = moduleSrc.resolve("pluginMod1x"); 9842956Sdillon 9942956Sdillon processorCompiledModules = base.resolve("mods"); 10042956Sdillon 10142956Sdillon Files.createDirectories(processorCompiledModules); 10242956Sdillon 10342956Sdillon tb.writeJavaFiles( 10442956Sdillon pluginMod1, 10542956Sdillon pluginModule1, 10642956Sdillon plugin1); 10742956Sdillon 10842956Sdillon String log = new JavacTask(tb) 10942956Sdillon .options("--module-source-path", moduleSrc.toString()) 110107913Sdillon .outdir(processorCompiledModules) 11142956Sdillon .files(findJavaFiles(moduleSrc)) 11242956Sdillon .run() 11342956Sdillon .writeAll() 11442956Sdillon .getOutput(Task.OutputKind.DIRECT); 11542956Sdillon 11642956Sdillon if (!log.isEmpty()) { 11742956Sdillon throw new AssertionError("Unexpected output: " + log); 11842956Sdillon } 11942956Sdillon 12042956Sdillon classes = base.resolve("classes"); 12142956Sdillon Files.createDirectories(classes); 12242956Sdillon } 12342956Sdillon 12442956Sdillon Path processorCompiledModules; 12542956Sdillon Path moduleSrc; 12642956Sdillon Path classes; 12742956Sdillon 12842956Sdillon @Test 12942956Sdillon public void testUseOnlyOneProcessor(Path base) throws Exception { 13042956Sdillon initialization(base); 13142956Sdillon List<String> log = new JavacTask(tb) 13242956Sdillon .options("--processor-module-path", processorCompiledModules.toString(), 133107913Sdillon "-Xplugin:simpleplugin1") 134107913Sdillon .outdir(classes) 135107913Sdillon .sources(testClass) 13642956Sdillon .run() 13742956Sdillon .writeAll() 13855206Speter .getOutputLines(Task.OutputKind.STDOUT); 13942956Sdillon if (!log.equals(Arrays.asList("simpleplugin1 started for event COMPILATION", 14042956Sdillon "simpleplugin1 finished for event COMPILATION"))) { 14142956Sdillon throw new AssertionError("Unexpected output: " + log); 14242956Sdillon } 14355206Speter } 14442956Sdillon} 14542956Sdillon