author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45004 | jdk/test/tools/jlink/IntegrationTest.java@ea3137042a61 |
child 47464 | 36de9c637393 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
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.File; |
|
40111
0fc6d1871da6
8159487: Add JAVA_VERSION, OS_NAME, OS_ARCH properties in release file
sundar
parents:
39834
diff
changeset
|
25 |
import java.io.FileReader; |
36511 | 26 |
import java.io.IOException; |
27 |
import java.io.UncheckedIOException; |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
28 |
import java.nio.ByteOrder; |
36511 | 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.HashMap; |
|
35 |
import java.util.HashSet; |
|
36 |
import java.util.List; |
|
37 |
import java.util.Map; |
|
40111
0fc6d1871da6
8159487: Add JAVA_VERSION, OS_NAME, OS_ARCH properties in release file
sundar
parents:
39834
diff
changeset
|
38 |
import java.util.Properties; |
36511 | 39 |
import java.util.Set; |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
40 |
import java.util.function.Function; |
41559
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
40939
diff
changeset
|
41 |
import jdk.tools.jlink.internal.Jlink; |
36511 | 42 |
import jdk.tools.jlink.builder.DefaultImageBuilder; |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39505
diff
changeset
|
43 |
import jdk.tools.jlink.plugin.ResourcePool; |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39505
diff
changeset
|
44 |
import jdk.tools.jlink.plugin.ResourcePoolBuilder; |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
45 |
import jdk.tools.jlink.plugin.Plugin; |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
46 |
import jdk.tools.jlink.internal.ExecutableImage; |
41559
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
40939
diff
changeset
|
47 |
import jdk.tools.jlink.internal.Jlink.JlinkConfiguration; |
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
40939
diff
changeset
|
48 |
import jdk.tools.jlink.internal.Jlink.PluginsConfiguration; |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
49 |
import jdk.tools.jlink.internal.PostProcessor; |
36511 | 50 |
import jdk.tools.jlink.internal.plugins.DefaultCompressPlugin; |
51 |
import jdk.tools.jlink.internal.plugins.StripDebugPlugin; |
|
52 |
||
53 |
import tests.Helper; |
|
54 |
import tests.JImageGenerator; |
|
55 |
||
56 |
/* |
|
57 |
* @test |
|
58 |
* @summary Test integration API |
|
59 |
* @author Jean-Francois Denise |
|
60 |
* @library ../lib |
|
61 |
* @modules java.base/jdk.internal.jimage |
|
62 |
* jdk.jdeps/com.sun.tools.classfile |
|
38320 | 63 |
* jdk.jlink/jdk.tools.jlink.builder |
36511 | 64 |
* jdk.jlink/jdk.tools.jlink.internal |
65 |
* jdk.jlink/jdk.tools.jlink.internal.plugins |
|
43185 | 66 |
* jdk.jlink/jdk.tools.jlink.plugin |
36511 | 67 |
* jdk.jlink/jdk.tools.jmod |
68 |
* jdk.jlink/jdk.tools.jimage |
|
69 |
* jdk.compiler |
|
70 |
* @build tests.* |
|
71 |
* @run main IntegrationTest |
|
72 |
*/ |
|
73 |
public class IntegrationTest { |
|
74 |
||
75 |
private static final List<Integer> ordered = new ArrayList<>(); |
|
76 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
77 |
public static class MyPostProcessor implements PostProcessor, Plugin { |
36511 | 78 |
|
79 |
public static final String NAME = "mypostprocessor"; |
|
80 |
||
81 |
@Override |
|
82 |
public List<String> process(ExecutableImage image) { |
|
83 |
try { |
|
84 |
Files.createFile(image.getHome().resolve("toto.txt")); |
|
85 |
return null; |
|
86 |
} catch (IOException ex) { |
|
87 |
throw new UncheckedIOException(ex); |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
@Override |
|
92 |
public String getName() { |
|
93 |
return NAME; |
|
94 |
} |
|
95 |
||
96 |
@Override |
|
39129
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
97 |
public Category getType() { |
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
98 |
return Category.PROCESSOR; |
36511 | 99 |
} |
100 |
||
101 |
@Override |
|
102 |
public void configure(Map<String, String> config) { |
|
103 |
throw new UnsupportedOperationException("Shouldn't be called"); |
|
104 |
} |
|
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
105 |
|
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
106 |
@Override |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39505
diff
changeset
|
107 |
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
108 |
in.transformAndCopy(Function.identity(), out); |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39505
diff
changeset
|
109 |
return out.build(); |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
110 |
} |
36511 | 111 |
} |
112 |
||
113 |
public static void main(String[] args) throws Exception { |
|
114 |
||
115 |
Helper helper = Helper.newHelper(); |
|
116 |
if (helper == null) { |
|
117 |
System.err.println("Test not run"); |
|
118 |
return; |
|
119 |
} |
|
120 |
apitest(); |
|
121 |
test(); |
|
122 |
} |
|
123 |
||
124 |
private static void apitest() throws Exception { |
|
125 |
boolean failed = false; |
|
126 |
Jlink jl = new Jlink(); |
|
127 |
||
128 |
try { |
|
129 |
jl.build(null); |
|
130 |
failed = true; |
|
131 |
} catch (Exception ex) { |
|
132 |
// XXX OK |
|
133 |
} |
|
134 |
if (failed) { |
|
135 |
throw new Exception("Should have failed"); |
|
136 |
} |
|
137 |
System.out.println(jl); |
|
138 |
||
139 |
Plugin p = Jlink.newPlugin("toto", Collections.emptyMap(), null); |
|
140 |
if (p != null) { |
|
141 |
throw new Exception("Plugin should be null"); |
|
142 |
} |
|
143 |
||
43791 | 144 |
Plugin p2 = Jlink.newPlugin("compress", Map.of("compress", "1"), null); |
36511 | 145 |
if (p2 == null) { |
146 |
throw new Exception("Plugin should not be null"); |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
private static void test() throws Exception { |
|
151 |
Jlink jlink = new Jlink(); |
|
152 |
Path output = Paths.get("integrationout"); |
|
153 |
List<Path> modulePaths = new ArrayList<>(); |
|
154 |
File jmods |
|
155 |
= JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk"))); |
|
156 |
modulePaths.add(jmods.toPath()); |
|
157 |
Set<String> mods = new HashSet<>(); |
|
158 |
mods.add("java.management"); |
|
159 |
Set<String> limits = new HashSet<>(); |
|
160 |
limits.add("java.management"); |
|
161 |
JlinkConfiguration config = new Jlink.JlinkConfiguration(output, |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
162 |
modulePaths, mods, limits, ByteOrder.nativeOrder()); |
36511 | 163 |
|
164 |
List<Plugin> lst = new ArrayList<>(); |
|
165 |
||
166 |
//Strip debug |
|
167 |
{ |
|
168 |
Map<String, String> config1 = new HashMap<>(); |
|
169 |
config1.put(StripDebugPlugin.NAME, ""); |
|
170 |
Plugin strip = Jlink.newPlugin("strip-debug", config1, null); |
|
171 |
lst.add(strip); |
|
172 |
} |
|
173 |
// compress |
|
174 |
{ |
|
175 |
Map<String, String> config1 = new HashMap<>(); |
|
176 |
config1.put(DefaultCompressPlugin.NAME, "2"); |
|
177 |
Plugin compress |
|
178 |
= Jlink.newPlugin("compress", config1, null); |
|
179 |
lst.add(compress); |
|
180 |
} |
|
181 |
// Post processor |
|
182 |
{ |
|
183 |
lst.add(new MyPostProcessor()); |
|
184 |
} |
|
185 |
// Image builder |
|
42762 | 186 |
DefaultImageBuilder builder = new DefaultImageBuilder(output, Collections.emptyMap()); |
36511 | 187 |
PluginsConfiguration plugins |
188 |
= new Jlink.PluginsConfiguration(lst, builder, null); |
|
189 |
||
190 |
jlink.build(config, plugins); |
|
191 |
||
192 |
if (!Files.exists(output)) { |
|
193 |
throw new AssertionError("Directory not created"); |
|
194 |
} |
|
195 |
File jimage = new File(output.toString(), "lib" + File.separator + "modules"); |
|
196 |
if (!jimage.exists()) { |
|
197 |
throw new AssertionError("jimage not generated"); |
|
198 |
} |
|
199 |
File release = new File(output.toString(), "release"); |
|
200 |
if (!release.exists()) { |
|
201 |
throw new AssertionError("release not generated"); |
|
202 |
} |
|
203 |
||
40111
0fc6d1871da6
8159487: Add JAVA_VERSION, OS_NAME, OS_ARCH properties in release file
sundar
parents:
39834
diff
changeset
|
204 |
Properties props = new Properties(); |
0fc6d1871da6
8159487: Add JAVA_VERSION, OS_NAME, OS_ARCH properties in release file
sundar
parents:
39834
diff
changeset
|
205 |
try (FileReader reader = new FileReader(release)) { |
0fc6d1871da6
8159487: Add JAVA_VERSION, OS_NAME, OS_ARCH properties in release file
sundar
parents:
39834
diff
changeset
|
206 |
props.load(reader); |
0fc6d1871da6
8159487: Add JAVA_VERSION, OS_NAME, OS_ARCH properties in release file
sundar
parents:
39834
diff
changeset
|
207 |
} |
0fc6d1871da6
8159487: Add JAVA_VERSION, OS_NAME, OS_ARCH properties in release file
sundar
parents:
39834
diff
changeset
|
208 |
|
40939
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
209 |
checkReleaseProperty(props, "JAVA_VERSION"); |
40111
0fc6d1871da6
8159487: Add JAVA_VERSION, OS_NAME, OS_ARCH properties in release file
sundar
parents:
39834
diff
changeset
|
210 |
|
36511 | 211 |
if (!Files.exists(output.resolve("toto.txt"))) { |
212 |
throw new AssertionError("Post processing not called"); |
|
213 |
} |
|
214 |
||
215 |
} |
|
40939
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
216 |
|
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
217 |
static void checkReleaseProperty(Properties props, String name) { |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
218 |
if (! props.containsKey(name)) { |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
219 |
throw new AssertionError("release file does not contain property : " + name); |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
220 |
} |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
221 |
|
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
222 |
// property value is of min. length 3 and double quoted at the ends. |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
223 |
String value = props.getProperty(name); |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
224 |
if (value.length() < 3 || |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
225 |
value.charAt(0) != '"' || |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
226 |
value.charAt(value.length() - 1) != '"') { |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
227 |
throw new AssertionError("release property " + name + " is not quoted property"); |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
228 |
} |
7262d01be07b
8163320: JAVA_VERSION in release file should come from java.base module
sundar
parents:
40111
diff
changeset
|
229 |
} |
36511 | 230 |
} |