author | sundar |
Fri, 08 Jul 2016 17:11:51 +0530 | |
changeset 39505 | be0bbd76ae51 |
parent 39321 | c60f34e8c057 |
child 39834 | 53a6fb443c20 |
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.File; |
|
25 |
import java.io.IOException; |
|
26 |
import java.io.UncheckedIOException; |
|
27 |
import java.nio.file.Files; |
|
28 |
import java.nio.file.Path; |
|
29 |
import java.nio.file.Paths; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.Collections; |
|
32 |
import java.util.HashMap; |
|
33 |
import java.util.HashSet; |
|
34 |
import java.util.List; |
|
35 |
import java.util.Map; |
|
36 |
import java.util.Set; |
|
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
37 |
import java.util.function.Function; |
36511 | 38 |
import jdk.tools.jlink.Jlink; |
39 |
import jdk.tools.jlink.Jlink.JlinkConfiguration; |
|
40 |
import jdk.tools.jlink.Jlink.PluginsConfiguration; |
|
41 |
import jdk.tools.jlink.builder.DefaultImageBuilder; |
|
38320 | 42 |
import jdk.tools.jlink.plugin.ModulePool; |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
43 |
import jdk.tools.jlink.plugin.Plugin; |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
44 |
import jdk.tools.jlink.internal.ExecutableImage; |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
45 |
import jdk.tools.jlink.internal.PostProcessor; |
36511 | 46 |
import jdk.tools.jlink.internal.plugins.DefaultCompressPlugin; |
47 |
import jdk.tools.jlink.internal.plugins.StripDebugPlugin; |
|
48 |
||
49 |
import tests.Helper; |
|
50 |
import tests.JImageGenerator; |
|
51 |
||
52 |
/* |
|
53 |
* @test |
|
54 |
* @summary Test integration API |
|
55 |
* @author Jean-Francois Denise |
|
56 |
* @library ../lib |
|
57 |
* @modules java.base/jdk.internal.jimage |
|
58 |
* jdk.jdeps/com.sun.tools.classfile |
|
38320 | 59 |
* jdk.jlink/jdk.tools.jlink |
60 |
* jdk.jlink/jdk.tools.jlink.builder |
|
36511 | 61 |
* jdk.jlink/jdk.tools.jlink.internal |
62 |
* jdk.jlink/jdk.tools.jlink.internal.plugins |
|
63 |
* jdk.jlink/jdk.tools.jmod |
|
64 |
* jdk.jlink/jdk.tools.jimage |
|
65 |
* jdk.compiler |
|
66 |
* @build tests.* |
|
67 |
* @run main IntegrationTest |
|
68 |
*/ |
|
69 |
public class IntegrationTest { |
|
70 |
||
71 |
private static final List<Integer> ordered = new ArrayList<>(); |
|
72 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
73 |
public static class MyPostProcessor implements PostProcessor, Plugin { |
36511 | 74 |
|
75 |
public static final String NAME = "mypostprocessor"; |
|
76 |
||
77 |
@Override |
|
78 |
public List<String> process(ExecutableImage image) { |
|
79 |
try { |
|
80 |
Files.createFile(image.getHome().resolve("toto.txt")); |
|
81 |
return null; |
|
82 |
} catch (IOException ex) { |
|
83 |
throw new UncheckedIOException(ex); |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
@Override |
|
88 |
public String getName() { |
|
89 |
return NAME; |
|
90 |
} |
|
91 |
||
92 |
@Override |
|
39129
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
93 |
public Category getType() { |
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
94 |
return Category.PROCESSOR; |
36511 | 95 |
} |
96 |
||
97 |
@Override |
|
98 |
public void configure(Map<String, String> config) { |
|
99 |
throw new UnsupportedOperationException("Shouldn't be called"); |
|
100 |
} |
|
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
101 |
|
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
102 |
@Override |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
103 |
public void visit(ModulePool in, ModulePool out) { |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
104 |
in.transformAndCopy(Function.identity(), out); |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
105 |
} |
36511 | 106 |
} |
107 |
||
108 |
public static void main(String[] args) throws Exception { |
|
109 |
||
110 |
Helper helper = Helper.newHelper(); |
|
111 |
if (helper == null) { |
|
112 |
System.err.println("Test not run"); |
|
113 |
return; |
|
114 |
} |
|
115 |
apitest(); |
|
116 |
test(); |
|
117 |
} |
|
118 |
||
119 |
private static void apitest() throws Exception { |
|
120 |
boolean failed = false; |
|
121 |
Jlink jl = new Jlink(); |
|
122 |
||
123 |
try { |
|
124 |
jl.build(null); |
|
125 |
failed = true; |
|
126 |
} catch (Exception ex) { |
|
127 |
// XXX OK |
|
128 |
} |
|
129 |
if (failed) { |
|
130 |
throw new Exception("Should have failed"); |
|
131 |
} |
|
132 |
System.out.println(jl); |
|
133 |
||
134 |
JlinkConfiguration config |
|
135 |
= new JlinkConfiguration(null, null, null, null); |
|
136 |
||
137 |
System.out.println(config); |
|
138 |
||
139 |
Plugin p = Jlink.newPlugin("toto", Collections.emptyMap(), null); |
|
140 |
if (p != null) { |
|
141 |
throw new Exception("Plugin should be null"); |
|
142 |
} |
|
143 |
||
144 |
Plugin p2 = Jlink.newPlugin("compress", Collections.emptyMap(), null); |
|
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, |
|
162 |
modulePaths, mods, limits, null); |
|
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 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
186 |
DefaultImageBuilder builder = new DefaultImageBuilder(output); |
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 |
||
204 |
if (!Files.exists(output.resolve("toto.txt"))) { |
|
205 |
throw new AssertionError("Post processing not called"); |
|
206 |
} |
|
207 |
||
208 |
} |
|
209 |
} |