author | sundar |
Fri, 27 Oct 2017 08:21:53 +0530 | |
changeset 47464 | 36de9c637393 |
parent 47216 | 71c04702a3d5 |
child 48663 | b742e0f9ce80 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
43495
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
36511 | 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.nio.file.Files; |
29 |
import java.nio.file.Path; |
|
30 |
import java.nio.file.Paths; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Collections; |
|
33 |
import java.util.List; |
|
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
34 |
import java.util.spi.ToolProvider; |
36511 | 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 |
||
42 |
/* |
|
43 |
* @test |
|
44 |
* @summary Test image creation |
|
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
45 |
* @bug 8189777 |
36511 | 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 |
|
43185 | 51 |
* jdk.jlink/jdk.tools.jlink.plugin |
36511 | 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 { |
|
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
58 |
static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink") |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
59 |
.orElseThrow(() -> |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
60 |
new RuntimeException("jlink tool not found") |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
61 |
); |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
62 |
|
39153
26b3cb81aac9
8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents:
37893
diff
changeset
|
63 |
// 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
|
64 |
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
|
65 |
ModuleDescriptor desc = Plugin.class.getModule().getDescriptor(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41766
diff
changeset
|
66 |
return desc.provides().stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41766
diff
changeset
|
67 |
.filter(p -> p.service().equals(Plugin.class.getName())) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41766
diff
changeset
|
68 |
.map(p -> p.providers().size()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41766
diff
changeset
|
69 |
.findAny() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41766
diff
changeset
|
70 |
.orElse(0); |
39153
26b3cb81aac9
8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents:
37893
diff
changeset
|
71 |
} |
36511 | 72 |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
} |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
76 |
|
36511 | 77 |
public static void main(String[] args) throws Exception { |
78 |
||
79 |
Helper helper = Helper.newHelper(); |
|
80 |
if (helper == null) { |
|
81 |
System.err.println("Test not run"); |
|
82 |
return; |
|
83 |
} |
|
84 |
helper.generateDefaultModules(); |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
85 |
// 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
|
86 |
int expectedJLinkPlugins = getNumJlinkPlugins(); |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
87 |
int totalPlugins = 0; |
36511 | 88 |
{ |
89 |
// number of built-in plugins |
|
90 |
List<Plugin> builtInPlugins = new ArrayList<>(); |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44367
diff
changeset
|
91 |
builtInPlugins.addAll(PluginRepository.getPlugins(ModuleLayer.boot())); |
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
92 |
totalPlugins = builtInPlugins.size(); |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
93 |
// 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
|
94 |
int actualJLinkPlugins = 0; |
36511 | 95 |
for (Plugin p : builtInPlugins) { |
96 |
p.getState(); |
|
97 |
p.getType(); |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
98 |
if (isOfJLinkModule(p)) { |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
99 |
actualJLinkPlugins++; |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
100 |
} |
36511 | 101 |
} |
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
102 |
if (expectedJLinkPlugins != actualJLinkPlugins) { |
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
expectedJLinkPlugins); |
36511 | 106 |
} |
107 |
} |
|
108 |
||
109 |
{ |
|
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
110 |
// No --module-path specified. $JAVA_HOME/jmods should be assumed. |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
111 |
// The following should succeed as it uses only system modules. |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
112 |
String imageDir = "bug818977-no-modulepath"; |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
113 |
JImageGenerator.getJLinkTask() |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
114 |
.output(helper.createNewImageDir(imageDir)) |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
115 |
.addMods("jdk.scripting.nashorn") |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
116 |
.call().assertSuccess(); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
117 |
} |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
118 |
|
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
119 |
{ |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
120 |
// invalid --module-path specified. java.base not found it it. |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
121 |
// $JAVA_HOME/jmods should be added automatically. |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
122 |
// The following should succeed as it uses only system modules. |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
123 |
String imageDir = "bug8189777-invalid-modulepath"; |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
124 |
JImageGenerator.getJLinkTask() |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
125 |
.modulePath("does_not_exist_path") |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
126 |
.output(helper.createNewImageDir(imageDir)) |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
127 |
.addMods("jdk.scripting.nashorn") |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
128 |
.call().assertSuccess(); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
129 |
} |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
130 |
|
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
131 |
{ |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
132 |
// No --module-path specified. --add-modules ALL-MODULE-PATH specified. |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
133 |
String imageDir = "bug8189777-all-module-path"; |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
134 |
JImageGenerator.getJLinkTask() |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
135 |
.output(helper.createNewImageDir(imageDir)) |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
136 |
.addMods("ALL-MODULE-PATH") |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
137 |
.call().assertSuccess(); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
138 |
} |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
139 |
|
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
140 |
{ |
36511 | 141 |
String moduleName = "bug8134651"; |
142 |
JImageGenerator.getJLinkTask() |
|
143 |
.modulePath(helper.defaultModulePath()) |
|
144 |
.output(helper.createNewImageDir(moduleName)) |
|
145 |
.addMods("leaf1") |
|
146 |
.call().assertSuccess(); |
|
147 |
JImageGenerator.getJLinkTask() |
|
148 |
.modulePath(helper.defaultModulePath()) |
|
149 |
.addMods("leaf1") |
|
150 |
.option("--output") |
|
151 |
.call().assertFailure("Error: no value given for --output"); |
|
152 |
JImageGenerator.getJLinkTask() |
|
153 |
.modulePath("") |
|
154 |
.output(helper.createNewImageDir(moduleName)) |
|
155 |
.addMods("leaf1") |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
40209
diff
changeset
|
156 |
.call().assertFailure("Error: no value given for --module-path"); |
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
157 |
// do not include standard module path - should be added automatically |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
158 |
JImageGenerator.getJLinkTask() |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
159 |
.modulePath(helper.defaultModulePath(false)) |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
160 |
.output(helper.createNewImageDir(moduleName)) |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
161 |
.addMods("leaf1") |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
162 |
.call().assertSuccess(); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
163 |
// no --module-path. default sys mod path is assumed - but that won't contain 'leaf1' module |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
164 |
JImageGenerator.getJLinkTask() |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
165 |
.output(helper.createNewImageDir(moduleName)) |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
166 |
.addMods("leaf1") |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47216
diff
changeset
|
167 |
.call().assertFailure("Error: Module leaf1 not found"); |
36511 | 168 |
} |
169 |
||
170 |
{ |
|
40209
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
171 |
String moduleName = "m"; // 8163382 |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
172 |
Path jmod = helper.generateDefaultJModule(moduleName).assertSuccess(); |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
173 |
JImageGenerator.getJLinkTask() |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
174 |
.modulePath(helper.defaultModulePath()) |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
175 |
.output(helper.createNewImageDir(moduleName)) |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
176 |
.addMods("m") |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
177 |
.call().assertSuccess(); |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
178 |
moduleName = "mod"; |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
179 |
jmod = helper.generateDefaultJModule(moduleName).assertSuccess(); |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
180 |
JImageGenerator.getJLinkTask() |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
181 |
.modulePath(helper.defaultModulePath()) |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
182 |
.output(helper.createNewImageDir(moduleName)) |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
183 |
.addMods("m") |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
184 |
.call().assertSuccess(); |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
185 |
} |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
186 |
|
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
39321
diff
changeset
|
187 |
{ |
41212
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
188 |
String moduleName = "m_8165735"; // JDK-8165735 |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
189 |
helper.generateDefaultJModule(moduleName+"dependency").assertSuccess(); |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
190 |
Path jmod = helper.generateDefaultJModule(moduleName, moduleName+"dependency").assertSuccess(); |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
191 |
JImageGenerator.getJLinkTask() |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
192 |
.modulePath(helper.defaultModulePath()) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
193 |
.repeatedModulePath(".") // second --module-path overrides the first one |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
194 |
.output(helper.createNewImageDir(moduleName)) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
195 |
.addMods(moduleName) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
196 |
// second --module-path does not have that module |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
197 |
.call().assertFailure("Error: Module m_8165735 not found"); |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
198 |
|
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
199 |
JImageGenerator.getJLinkTask() |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
200 |
.modulePath(".") // first --module-path overridden later |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
201 |
.repeatedModulePath(helper.defaultModulePath()) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
202 |
.output(helper.createNewImageDir(moduleName)) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
203 |
.addMods(moduleName) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
204 |
// second --module-path has that module |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
205 |
.call().assertSuccess(); |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
206 |
|
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
207 |
JImageGenerator.getJLinkTask() |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
208 |
.modulePath(helper.defaultModulePath()) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
209 |
.output(helper.createNewImageDir(moduleName)) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
210 |
.limitMods(moduleName) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
211 |
.repeatedLimitMods("java.base") // second --limit-modules overrides first |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
212 |
.addMods(moduleName) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
213 |
.call().assertFailure("Error: Module m_8165735dependency not found, required by m_8165735"); |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
214 |
|
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
215 |
JImageGenerator.getJLinkTask() |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
216 |
.modulePath(helper.defaultModulePath()) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
217 |
.output(helper.createNewImageDir(moduleName)) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
218 |
.limitMods("java.base") |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
219 |
.repeatedLimitMods(moduleName) // second --limit-modules overrides first |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
220 |
.addMods(moduleName) |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
221 |
.call().assertSuccess(); |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
222 |
} |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
223 |
|
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
224 |
{ |
36511 | 225 |
// Help |
226 |
StringWriter writer = new StringWriter(); |
|
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
227 |
PrintWriter pw = new PrintWriter(writer); |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
228 |
JLINK_TOOL.run(pw, pw, "--help"); |
36511 | 229 |
String output = writer.toString(); |
230 |
if (output.split("\n").length < 10) { |
|
231 |
System.err.println(output); |
|
232 |
throw new AssertionError("Help"); |
|
233 |
} |
|
234 |
} |
|
235 |
||
236 |
{ |
|
237 |
// List plugins |
|
238 |
StringWriter writer = new StringWriter(); |
|
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
239 |
PrintWriter pw = new PrintWriter(writer); |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
240 |
|
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41352
diff
changeset
|
241 |
JLINK_TOOL.run(pw, pw, "--list-plugins"); |
36511 | 242 |
String output = writer.toString(); |
243 |
long number = Stream.of(output.split("\\R")) |
|
244 |
.filter((s) -> s.matches("Plugin Name:.*")) |
|
245 |
.count(); |
|
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
246 |
if (number != totalPlugins) { |
36511 | 247 |
System.err.println(output); |
39304
8d9ceb81a46e
8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents:
39153
diff
changeset
|
248 |
throw new AssertionError("Found: " + number + " expected " + totalPlugins); |
36511 | 249 |
} |
250 |
} |
|
251 |
||
252 |
// filter out files and resources + Skip debug + compress |
|
253 |
{ |
|
254 |
String[] userOptions = {"--compress", "2", "--strip-debug", |
|
255 |
"--exclude-resources", "*.jcov, */META-INF/*", "--exclude-files", |
|
256 |
"*" + Helper.getDebugSymbolsExtension()}; |
|
257 |
String moduleName = "excludezipskipdebugcomposite2"; |
|
258 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
259 |
String[] res = {".jcov", "/META-INF/"}; |
|
260 |
String[] files = {Helper.getDebugSymbolsExtension()}; |
|
261 |
Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); |
|
262 |
helper.checkImage(imageDir, moduleName, res, files); |
|
263 |
} |
|
264 |
||
265 |
// filter out + Skip debug + compress with filter + sort resources |
|
266 |
{ |
|
267 |
String[] userOptions2 = {"--compress=2:compress-filter=^/java.base/*", |
|
268 |
"--strip-debug", "--exclude-resources", |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
37779
diff
changeset
|
269 |
"*.jcov, */META-INF/*", "--order-resources", |
36511 | 270 |
"*/module-info.class,/sortcomposite2/*,*/javax/management/*"}; |
271 |
String moduleName = "excludezipfilterskipdebugcomposite2"; |
|
272 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
273 |
String[] res = {".jcov", "/META-INF/"}; |
|
274 |
Path imageDir = helper.generateDefaultImage(userOptions2, moduleName).assertSuccess(); |
|
275 |
helper.checkImage(imageDir, moduleName, res, null); |
|
276 |
} |
|
277 |
||
278 |
// default compress |
|
279 |
{ |
|
280 |
testCompress(helper, "compresscmdcomposite2", "--compress", "2"); |
|
281 |
} |
|
282 |
||
283 |
{ |
|
284 |
testCompress(helper, "compressfiltercmdcomposite2", |
|
285 |
"--compress=2:filter=^/java.base/java/lang/*"); |
|
286 |
} |
|
287 |
||
288 |
// compress 0 |
|
289 |
{ |
|
290 |
testCompress(helper, "compress0filtercmdcomposite2", |
|
291 |
"--compress=0:filter=^/java.base/java/lang/*"); |
|
292 |
} |
|
293 |
||
294 |
// compress 1 |
|
295 |
{ |
|
296 |
testCompress(helper, "compress1filtercmdcomposite2", |
|
297 |
"--compress=1:filter=^/java.base/java/lang/*"); |
|
298 |
} |
|
299 |
||
300 |
// compress 2 |
|
301 |
{ |
|
302 |
testCompress(helper, "compress2filtercmdcomposite2", |
|
303 |
"--compress=2:filter=^/java.base/java/lang/*"); |
|
304 |
} |
|
305 |
||
306 |
// invalid compress level |
|
307 |
{ |
|
308 |
String[] userOptions = {"--compress", "invalid"}; |
|
309 |
String moduleName = "invalidCompressLevel"; |
|
310 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36757
diff
changeset
|
311 |
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: Invalid compression level invalid"); |
36511 | 312 |
} |
313 |
||
41766 | 314 |
// orphan argument - JDK-8166810 |
36511 | 315 |
{ |
41766 | 316 |
String[] userOptions = {"--compress", "2", "foo" }; |
317 |
String moduleName = "orphanarg1"; |
|
36511 | 318 |
helper.generateDefaultJModule(moduleName, "composite2"); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
43495
diff
changeset
|
319 |
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: invalid argument: foo"); |
36511 | 320 |
} |
321 |
||
41766 | 322 |
// orphan argument - JDK-8166810 |
323 |
{ |
|
324 |
String[] userOptions = {"--output", "foo", "bar" }; |
|
325 |
String moduleName = "orphanarg2"; |
|
326 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
43495
diff
changeset
|
327 |
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: invalid argument: bar"); |
41766 | 328 |
} |
43495
8255aabd0e09
8173717: jlink --help fails with missing "plugin.opt.plugin-module-path" key in resource bundle
sundar
parents:
43185
diff
changeset
|
329 |
|
8255aabd0e09
8173717: jlink --help fails with missing "plugin.opt.plugin-module-path" key in resource bundle
sundar
parents:
43185
diff
changeset
|
330 |
// basic check for --help - JDK-8173717 |
8255aabd0e09
8173717: jlink --help fails with missing "plugin.opt.plugin-module-path" key in resource bundle
sundar
parents:
43185
diff
changeset
|
331 |
{ |
8255aabd0e09
8173717: jlink --help fails with missing "plugin.opt.plugin-module-path" key in resource bundle
sundar
parents:
43185
diff
changeset
|
332 |
JImageGenerator.getJLinkTask() |
8255aabd0e09
8173717: jlink --help fails with missing "plugin.opt.plugin-module-path" key in resource bundle
sundar
parents:
43185
diff
changeset
|
333 |
.option("--help") |
8255aabd0e09
8173717: jlink --help fails with missing "plugin.opt.plugin-module-path" key in resource bundle
sundar
parents:
43185
diff
changeset
|
334 |
.call().assertSuccess(); |
8255aabd0e09
8173717: jlink --help fails with missing "plugin.opt.plugin-module-path" key in resource bundle
sundar
parents:
43185
diff
changeset
|
335 |
} |
36511 | 336 |
} |
337 |
||
338 |
private static void testCompress(Helper helper, String moduleName, String... userOptions) throws IOException { |
|
339 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
340 |
Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); |
|
341 |
helper.checkImage(imageDir, moduleName, null, null); |
|
342 |
} |
|
343 |
} |