author | duke |
Wed, 05 Jul 2017 22:06:37 +0200 | |
changeset 40471 | ad45133ff99e |
parent 40261 | 86a49ba76f52 |
child 41212 | 54a8bb41b174 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
import java.io.IOException; |
|
25 |
import java.io.PrintWriter; |
|
26 |
import java.io.StringWriter; |
|
39153
26b3cb81aac9
8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents:
37893
diff
changeset
|
27 |
import java.lang.module.ModuleDescriptor; |
36511 | 28 |
import java.lang.reflect.Layer; |
29 |
import java.nio.file.Files; |
|
30 |
import java.nio.file.Path; |
|
31 |
import java.nio.file.Paths; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.Collections; |
|
34 |
import java.util.List; |
|
35 |
import java.util.stream.Stream; |
|
36 |
||
37 |
import jdk.tools.jlink.plugin.Plugin; |
|
38 |
import jdk.tools.jlink.internal.PluginRepository; |
|
39 |
import tests.Helper; |
|
40 |
import tests.JImageGenerator; |
|
41 |
import tests.JImageGenerator.InMemoryFile; |
|
42 |
||
43 |
/* |
|
44 |
* @test |
|
45 |
* @summary Test image creation |
|
46 |
* @author Jean-Francois Denise |
|
47 |
* @library ../lib |
|
48 |
* @modules java.base/jdk.internal.jimage |
|
49 |
* jdk.jdeps/com.sun.tools.classfile |
|
50 |
* jdk.jlink/jdk.tools.jlink.internal |
|
51 |
* jdk.jlink/jdk.tools.jmod |
|
52 |
* jdk.jlink/jdk.tools.jimage |
|
53 |
* jdk.compiler |
|
54 |
* @build tests.* |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
55 |
* @run main/othervm -Xmx1g JLinkTest |
36511 | 56 |
*/ |
57 |
public class JLinkTest { |
|
39153
26b3cb81aac9
8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents:
37893
diff
changeset
|
58 |
// number of built-in plugins from jdk.jlink module |
26b3cb81aac9
8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents:
37893
diff
changeset
|
59 |
private static int getNumJlinkPlugins() { |
26b3cb81aac9
8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents:
37893
diff
changeset
|
60 |
ModuleDescriptor desc = Plugin.class.getModule().getDescriptor(); |
26b3cb81aac9
8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents:
37893
diff
changeset
|
61 |
return desc.provides(). |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39304
diff
changeset
|
62 |
get(Plugin.class.getName()). |
39153
26b3cb81aac9
8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents:
37893
diff
changeset
|
63 |
providers().size(); |
26b3cb81aac9
8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents:
37893
diff
changeset
|
64 |
} |
36511 | 65 |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
66 |
private static boolean isOfJLinkModule(Plugin p) { |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
67 |
return p.getClass().getModule() == Plugin.class.getModule(); |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
68 |
} |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
69 |
|
36511 | 70 |
public static void main(String[] args) throws Exception { |
71 |
||
72 |
Helper helper = Helper.newHelper(); |
|
73 |
if (helper == null) { |
|
74 |
System.err.println("Test not run"); |
|
75 |
return; |
|
76 |
} |
|
77 |
helper.generateDefaultModules(); |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
78 |
// expected num. of plugins from jdk.jlink module |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
79 |
int expectedJLinkPlugins = getNumJlinkPlugins(); |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
80 |
int totalPlugins = 0; |
36511 | 81 |
{ |
82 |
// number of built-in plugins |
|
83 |
List<Plugin> builtInPlugins = new ArrayList<>(); |
|
84 |
builtInPlugins.addAll(PluginRepository.getPlugins(Layer.boot())); |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
85 |
totalPlugins = builtInPlugins.size(); |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
86 |
// actual num. of plugins loaded from jdk.jlink module |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
87 |
int actualJLinkPlugins = 0; |
36511 | 88 |
for (Plugin p : builtInPlugins) { |
89 |
p.getState(); |
|
90 |
p.getType(); |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
91 |
if (isOfJLinkModule(p)) { |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
92 |
actualJLinkPlugins++; |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
93 |
} |
36511 | 94 |
} |
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
95 |
if (expectedJLinkPlugins != actualJLinkPlugins) { |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
96 |
throw new AssertionError("Actual plugins loaded from jdk.jlink: " + |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
97 |
actualJLinkPlugins + " which doesn't match expected number : " + |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
98 |
expectedJLinkPlugins); |
36511 | 99 |
} |
100 |
} |
|
101 |
||
102 |
{ |
|
103 |
String moduleName = "bug8134651"; |
|
104 |
JImageGenerator.getJLinkTask() |
|
105 |
.modulePath(helper.defaultModulePath()) |
|
106 |
.output(helper.createNewImageDir(moduleName)) |
|
107 |
.addMods("leaf1") |
|
108 |
.option("") |
|
109 |
.call().assertSuccess(); |
|
110 |
JImageGenerator.getJLinkTask() |
|
111 |
.modulePath(helper.defaultModulePath()) |
|
112 |
.addMods("leaf1") |
|
113 |
.option("--output") |
|
114 |
.option("") |
|
115 |
.call().assertFailure("Error: no value given for --output"); |
|
116 |
JImageGenerator.getJLinkTask() |
|
117 |
.modulePath("") |
|
118 |
.output(helper.createNewImageDir(moduleName)) |
|
119 |
.addMods("leaf1") |
|
120 |
.option("") |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
40209
diff
changeset
|
121 |
.call().assertFailure("Error: no value given for --module-path"); |
36511 | 122 |
} |
123 |
||
124 |
{ |
|
125 |
String moduleName = "filter"; |
|
126 |
Path jmod = helper.generateDefaultJModule(moduleName).assertSuccess(); |
|
127 |
String className = "_A.class"; |
|
128 |
JImageGenerator.addFiles(jmod, new InMemoryFile(className, new byte[0])); |
|
129 |
Path image = helper.generateDefaultImage(moduleName).assertSuccess(); |
|
130 |
helper.checkImage(image, moduleName, new String[] {"/" + moduleName + "/" + className}, null); |
|
131 |
} |
|
132 |
||
133 |
{ |
|
40209
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
134 |
String moduleName = "m"; // 8163382 |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
135 |
Path jmod = helper.generateDefaultJModule(moduleName).assertSuccess(); |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
136 |
JImageGenerator.getJLinkTask() |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
137 |
.modulePath(helper.defaultModulePath()) |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
138 |
.output(helper.createNewImageDir(moduleName)) |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
139 |
.addMods("m") |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
140 |
.option("") |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
141 |
.call().assertSuccess(); |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
142 |
moduleName = "mod"; |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
143 |
jmod = helper.generateDefaultJModule(moduleName).assertSuccess(); |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
144 |
JImageGenerator.getJLinkTask() |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
145 |
.modulePath(helper.defaultModulePath()) |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
146 |
.output(helper.createNewImageDir(moduleName)) |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
147 |
.addMods("m") |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
148 |
.option("") |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
149 |
.call().assertSuccess(); |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
150 |
} |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
151 |
|
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
152 |
{ |
36511 | 153 |
// Help |
154 |
StringWriter writer = new StringWriter(); |
|
155 |
jdk.tools.jlink.internal.Main.run(new String[]{"--help"}, new PrintWriter(writer)); |
|
156 |
String output = writer.toString(); |
|
157 |
if (output.split("\n").length < 10) { |
|
158 |
System.err.println(output); |
|
159 |
throw new AssertionError("Help"); |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
{ |
|
164 |
// License files |
|
165 |
String copied = "LICENSE"; |
|
166 |
String[] arr = copied.split(","); |
|
167 |
String[] copyFiles = new String[2]; |
|
168 |
copyFiles[0] = "--copy-files"; |
|
169 |
copyFiles[1] = copied; |
|
170 |
Path imageDir = helper.generateDefaultImage(copyFiles, "composite2").assertSuccess(); |
|
171 |
helper.checkImage(imageDir, "composite2", null, null, arr); |
|
172 |
} |
|
173 |
||
174 |
{ |
|
175 |
// List plugins |
|
176 |
StringWriter writer = new StringWriter(); |
|
177 |
jdk.tools.jlink.internal.Main.run(new String[]{"--list-plugins"}, new PrintWriter(writer)); |
|
178 |
String output = writer.toString(); |
|
179 |
long number = Stream.of(output.split("\\R")) |
|
180 |
.filter((s) -> s.matches("Plugin Name:.*")) |
|
181 |
.count(); |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
182 |
if (number != totalPlugins) { |
36511 | 183 |
System.err.println(output); |
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
184 |
throw new AssertionError("Found: " + number + " expected " + totalPlugins); |
36511 | 185 |
} |
186 |
} |
|
187 |
||
188 |
// filter out files and resources + Skip debug + compress |
|
189 |
{ |
|
190 |
String[] userOptions = {"--compress", "2", "--strip-debug", |
|
191 |
"--exclude-resources", "*.jcov, */META-INF/*", "--exclude-files", |
|
192 |
"*" + Helper.getDebugSymbolsExtension()}; |
|
193 |
String moduleName = "excludezipskipdebugcomposite2"; |
|
194 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
195 |
String[] res = {".jcov", "/META-INF/"}; |
|
196 |
String[] files = {Helper.getDebugSymbolsExtension()}; |
|
197 |
Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); |
|
198 |
helper.checkImage(imageDir, moduleName, res, files); |
|
199 |
} |
|
200 |
||
201 |
// filter out + Skip debug + compress with filter + sort resources |
|
202 |
{ |
|
203 |
String[] userOptions2 = {"--compress=2:compress-filter=^/java.base/*", |
|
204 |
"--strip-debug", "--exclude-resources", |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
37779
diff
changeset
|
205 |
"*.jcov, */META-INF/*", "--order-resources", |
36511 | 206 |
"*/module-info.class,/sortcomposite2/*,*/javax/management/*"}; |
207 |
String moduleName = "excludezipfilterskipdebugcomposite2"; |
|
208 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
209 |
String[] res = {".jcov", "/META-INF/"}; |
|
210 |
Path imageDir = helper.generateDefaultImage(userOptions2, moduleName).assertSuccess(); |
|
211 |
helper.checkImage(imageDir, moduleName, res, null); |
|
212 |
} |
|
213 |
||
214 |
// default compress |
|
215 |
{ |
|
216 |
testCompress(helper, "compresscmdcomposite2", "--compress", "2"); |
|
217 |
} |
|
218 |
||
219 |
{ |
|
220 |
testCompress(helper, "compressfiltercmdcomposite2", |
|
221 |
"--compress=2:filter=^/java.base/java/lang/*"); |
|
222 |
} |
|
223 |
||
224 |
// compress 0 |
|
225 |
{ |
|
226 |
testCompress(helper, "compress0filtercmdcomposite2", |
|
227 |
"--compress=0:filter=^/java.base/java/lang/*"); |
|
228 |
} |
|
229 |
||
230 |
// compress 1 |
|
231 |
{ |
|
232 |
testCompress(helper, "compress1filtercmdcomposite2", |
|
233 |
"--compress=1:filter=^/java.base/java/lang/*"); |
|
234 |
} |
|
235 |
||
236 |
// compress 2 |
|
237 |
{ |
|
238 |
testCompress(helper, "compress2filtercmdcomposite2", |
|
239 |
"--compress=2:filter=^/java.base/java/lang/*"); |
|
240 |
} |
|
241 |
||
242 |
// invalid compress level |
|
243 |
{ |
|
244 |
String[] userOptions = {"--compress", "invalid"}; |
|
245 |
String moduleName = "invalidCompressLevel"; |
|
246 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36757
diff
changeset
|
247 |
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: Invalid compression level invalid"); |
36511 | 248 |
} |
249 |
||
250 |
// @file |
|
251 |
{ |
|
252 |
Path path = Paths.get("embedded.properties"); |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
40209
diff
changeset
|
253 |
Files.write(path, Collections.singletonList("--strip-debug --add-modules " + |
36511 | 254 |
"toto.unknown --compress UNKNOWN\n")); |
255 |
String[] userOptions = {"@", path.toAbsolutePath().toString()}; |
|
256 |
String moduleName = "configembeddednocompresscomposite2"; |
|
257 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
258 |
Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); |
|
259 |
helper.checkImage(imageDir, moduleName, null, null); |
|
260 |
} |
|
261 |
||
262 |
} |
|
263 |
||
264 |
private static void testCompress(Helper helper, String moduleName, String... userOptions) throws IOException { |
|
265 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
266 |
Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); |
|
267 |
helper.checkImage(imageDir, moduleName, null, null); |
|
268 |
} |
|
269 |
} |