author | alanb |
Sat, 09 Feb 2019 08:54:02 +0000 | |
branch | niosocketimpl-branch |
changeset 57170 | 52bc64277201 |
parent 47216 | 71c04702a3d5 |
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 |
/* |
|
25 |
* @test |
|
26 |
* @summary Test image creation |
|
27 |
* @author Jean-Francois Denise |
|
28 |
* @library ../lib |
|
29 |
* @modules java.base/jdk.internal.jimage |
|
30 |
* jdk.jdeps/com.sun.tools.classfile |
|
31 |
* jdk.jlink/jdk.tools.jlink.internal |
|
43185 | 32 |
* jdk.jlink/jdk.tools.jlink.plugin |
36511 | 33 |
* jdk.jlink/jdk.tools.jmod |
34 |
* jdk.jlink/jdk.tools.jimage |
|
35 |
* jdk.compiler |
|
36 |
* @build tests.* |
|
37 |
* @run main/othervm -verbose:gc -Xmx1g JLink2Test |
|
38 |
*/ |
|
39 |
import java.io.File; |
|
40 |
import java.io.FileOutputStream; |
|
41 |
import java.io.IOException; |
|
42 |
import java.nio.file.Files; |
|
43 |
import java.nio.file.Path; |
|
44 |
import java.util.ArrayList; |
|
45 |
import java.util.Arrays; |
|
46 |
import java.util.Collections; |
|
47 |
import java.util.List; |
|
48 |
import java.util.jar.JarEntry; |
|
49 |
import java.util.jar.JarOutputStream; |
|
50 |
import jdk.tools.jlink.internal.PluginRepository; |
|
51 |
import jdk.tools.jlink.plugin.Plugin; |
|
52 |
||
53 |
import tests.Helper; |
|
54 |
import tests.JImageGenerator; |
|
55 |
import tests.JImageValidator; |
|
56 |
||
57 |
public class JLink2Test { |
|
58 |
||
59 |
public static void main(String[] args) throws Exception { |
|
60 |
Helper helper = Helper.newHelper(); |
|
61 |
if (helper == null) { |
|
62 |
System.err.println("Test not run"); |
|
63 |
return; |
|
64 |
} |
|
65 |
helper.generateDefaultModules(); |
|
66 |
||
67 |
// This test case must be first one, the JlinkTask is clean |
|
68 |
// and reveals possible bug related to plugin options in defaults |
|
69 |
testSameNames(helper); |
|
70 |
testOptions(); |
|
71 |
} |
|
72 |
||
73 |
private static void testSameNames(Helper helper) throws Exception { |
|
74 |
// Multiple modules with the same name in modulepath, take the first one in the path. |
|
75 |
// First jmods then jars. So jmods are found, jars are hidden. |
|
76 |
String[] jarClasses = {"amodule.jar.Main"}; |
|
77 |
String[] jmodsClasses = {"amodule.jmods.Main"}; |
|
78 |
helper.generateDefaultJarModule("amodule", Arrays.asList(jarClasses)); |
|
79 |
helper.generateDefaultJModule("amodule", Arrays.asList(jmodsClasses)); |
|
80 |
List<String> okLocations = new ArrayList<>(); |
|
81 |
okLocations.addAll(Helper.toLocation("amodule", Arrays.asList(jmodsClasses))); |
|
82 |
Path image = helper.generateDefaultImage(new String[0], "amodule").assertSuccess(); |
|
83 |
JImageValidator validator = new JImageValidator("amodule", okLocations, |
|
84 |
image.toFile(), Collections.emptyList(), Collections.emptyList()); |
|
85 |
validator.validate(); |
|
86 |
} |
|
87 |
||
88 |
private static void testOptions() throws Exception { |
|
89 |
List<Plugin> builtInPlugins = new ArrayList<>(); |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
43328
diff
changeset
|
90 |
builtInPlugins.addAll(PluginRepository.getPlugins(ModuleLayer.boot())); |
36511 | 91 |
if(builtInPlugins.isEmpty()) { |
92 |
throw new Exception("No builtin plugins"); |
|
93 |
} |
|
94 |
List<String> options = new ArrayList<>(); |
|
95 |
for (Plugin p : builtInPlugins) { |
|
96 |
if (p.getOption() == null) { |
|
97 |
throw new Exception("Null option for " + p.getName()); |
|
98 |
} |
|
99 |
if (options.contains(p.getName())) { |
|
100 |
throw new Exception("Option " + p.getOption() + " used more than once"); |
|
101 |
} |
|
102 |
options.add(p.getName()); |
|
103 |
} |
|
104 |
} |
|
105 |
} |