author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 42822 | a84956e7ee4d |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, 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 |
* @summary Verify that plugins inside modules works |
|
27 |
* @library /tools/lib |
|
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
36526 | 32 |
* @run main PluginsInModulesTest |
33 |
*/ |
|
34 |
||
35 |
import java.nio.file.Files; |
|
36 |
import java.nio.file.Path; |
|
37 |
import java.util.Arrays; |
|
38 |
import java.util.List; |
|
39 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
|
36526 | 43 |
public class PluginsInModulesTest extends ModuleTestBase { |
44 |
||
45 |
public static void main(String... args) throws Exception { |
|
46 |
new PluginsInModulesTest().runTests(); |
|
47 |
} |
|
48 |
||
49 |
private static final String pluginModule1 = |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
50 |
"module pluginMod1x {\n" + |
36526 | 51 |
" requires jdk.compiler;\n" + |
52 |
"\n" + |
|
53 |
" provides com.sun.source.util.Plugin\n" + |
|
54 |
" with mypkg1.SimplePlugin1;\n" + |
|
55 |
"}"; |
|
56 |
||
57 |
private static final String plugin1 = |
|
58 |
"package mypkg1;\n" + |
|
59 |
"import com.sun.source.util.JavacTask;\n" + |
|
60 |
"import com.sun.source.util.Plugin;\n" + |
|
61 |
"import com.sun.source.util.TaskEvent;\n" + |
|
62 |
"import com.sun.source.util.TaskListener;\n" + |
|
63 |
"\n" + |
|
64 |
"public class SimplePlugin1 implements Plugin {\n" + |
|
65 |
"\n" + |
|
66 |
" @Override\n" + |
|
67 |
" public String getName() {\n" + |
|
68 |
" return \"simpleplugin1\";\n" + |
|
69 |
" }\n" + |
|
70 |
"\n" + |
|
71 |
" @Override\n" + |
|
72 |
" public void init(JavacTask task, String... args) {\n" + |
|
73 |
" task.addTaskListener(new PostAnalyzeTaskListener());\n" + |
|
74 |
" }\n" + |
|
75 |
"\n" + |
|
76 |
" private static class PostAnalyzeTaskListener implements TaskListener {\n" + |
|
77 |
" @Override\n" + |
|
78 |
" public void started(TaskEvent taskEvent) { \n" + |
|
79 |
" if (taskEvent.getKind().equals(TaskEvent.Kind.COMPILATION)) {\n" + |
|
80 |
" System.out.println(\"simpleplugin1 started for event \" + taskEvent.getKind());\n" + |
|
81 |
" }\n" + |
|
82 |
" }\n" + |
|
83 |
"\n" + |
|
84 |
" @Override\n" + |
|
85 |
" public void finished(TaskEvent taskEvent) {\n" + |
|
86 |
" if (taskEvent.getKind().equals(TaskEvent.Kind.COMPILATION)) {\n" + |
|
87 |
" System.out.println(\"simpleplugin1 finished for event \" + taskEvent.getKind());\n" + |
|
88 |
" }\n" + |
|
89 |
" }\n" + |
|
90 |
" }\n" + |
|
91 |
"}"; |
|
92 |
||
93 |
private static final String testClass = "class Test { }"; |
|
94 |
||
95 |
void initialization(Path base) throws Exception { |
|
96 |
moduleSrc = base.resolve("plugin_mods_src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
97 |
Path pluginMod1 = moduleSrc.resolve("pluginMod1x"); |
36526 | 98 |
|
99 |
processorCompiledModules = base.resolve("mods"); |
|
100 |
||
101 |
Files.createDirectories(processorCompiledModules); |
|
102 |
||
103 |
tb.writeJavaFiles( |
|
104 |
pluginMod1, |
|
105 |
pluginModule1, |
|
106 |
plugin1); |
|
107 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
108 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
109 |
.options("--module-source-path", moduleSrc.toString()) |
36526 | 110 |
.outdir(processorCompiledModules) |
111 |
.files(findJavaFiles(moduleSrc)) |
|
112 |
.run() |
|
113 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
114 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 115 |
|
116 |
if (!log.isEmpty()) { |
|
117 |
throw new AssertionError("Unexpected output: " + log); |
|
118 |
} |
|
119 |
||
120 |
classes = base.resolve("classes"); |
|
121 |
Files.createDirectories(classes); |
|
122 |
} |
|
123 |
||
124 |
Path processorCompiledModules; |
|
125 |
Path moduleSrc; |
|
126 |
Path classes; |
|
127 |
||
128 |
@Test |
|
37758 | 129 |
public void testUseOnlyOneProcessor(Path base) throws Exception { |
36526 | 130 |
initialization(base); |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
131 |
List<String> log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
132 |
.options("--processor-module-path", processorCompiledModules.toString(), |
36526 | 133 |
"-Xplugin:simpleplugin1") |
134 |
.outdir(classes) |
|
135 |
.sources(testClass) |
|
136 |
.run() |
|
137 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
138 |
.getOutputLines(Task.OutputKind.STDOUT); |
36526 | 139 |
if (!log.equals(Arrays.asList("simpleplugin1 started for event COMPILATION", |
140 |
"simpleplugin1 finished for event COMPILATION"))) { |
|
141 |
throw new AssertionError("Unexpected output: " + log); |
|
142 |
} |
|
143 |
} |
|
144 |
} |