author | sundar |
Tue, 21 Jun 2016 19:05:34 +0530 | |
changeset 39129 | 4b2086305b68 |
parent 38320 | e24c7029e8ba |
child 39321 | c60f34e8c057 |
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.UncheckedIOException; |
|
26 |
import java.nio.file.Files; |
|
27 |
import java.nio.file.Path; |
|
28 |
import java.util.Collections; |
|
29 |
import java.util.List; |
|
30 |
import java.util.Map; |
|
31 |
||
32 |
import jdk.tools.jlink.internal.PluginRepository; |
|
33 |
import jdk.tools.jlink.plugin.ExecutableImage; |
|
34 |
import jdk.tools.jlink.plugin.PostProcessorPlugin; |
|
35 |
import tests.Helper; |
|
36 |
||
37 |
/* |
|
38 |
* @test |
|
39 |
* @summary Test post processing |
|
40 |
* @author Jean-Francois Denise |
|
41 |
* @library ../lib |
|
42 |
* @modules java.base/jdk.internal.jimage |
|
43 |
* jdk.jdeps/com.sun.tools.classfile |
|
44 |
* jdk.jlink/jdk.tools.jlink.internal |
|
45 |
* jdk.jlink/jdk.tools.jmod |
|
46 |
* jdk.jlink/jdk.tools.jimage |
|
47 |
* jdk.compiler |
|
48 |
* @build tests.* |
|
49 |
* @run main/othervm JLinkPostProcessingTest |
|
50 |
*/ |
|
51 |
public class JLinkPostProcessingTest { |
|
52 |
||
53 |
private static class PPPlugin implements PostProcessorPlugin { |
|
54 |
||
55 |
private static ExecutableImage called; |
|
56 |
private static final String NAME = "pp"; |
|
57 |
||
58 |
@Override |
|
59 |
public List<String> process(ExecutableImage image) { |
|
60 |
called = image; |
|
61 |
Path gen = image.getHome().resolve("lib").resolve("toto.txt"); |
|
62 |
try { |
|
63 |
Files.createFile(gen); |
|
64 |
} catch (IOException ex) { |
|
65 |
throw new UncheckedIOException(ex); |
|
66 |
} |
|
67 |
return null; |
|
68 |
} |
|
69 |
||
70 |
@Override |
|
71 |
public String getName() { |
|
72 |
return NAME; |
|
73 |
} |
|
74 |
||
75 |
@Override |
|
39129
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
76 |
public Category getType() { |
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
77 |
return Category.PROCESSOR; |
36511 | 78 |
} |
79 |
||
80 |
@Override |
|
81 |
public String getDescription() { |
|
82 |
return NAME; |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
public static void main(String[] args) throws Exception { |
|
87 |
||
88 |
Helper helper = Helper.newHelper(); |
|
89 |
if (helper == null) { |
|
90 |
System.err.println("Test not run"); |
|
91 |
return; |
|
92 |
} |
|
93 |
helper.generateDefaultModules(); |
|
94 |
||
95 |
PluginRepository.registerPlugin(new PPPlugin()); |
|
96 |
||
97 |
// Generate an image and post-process in same jlink execution. |
|
98 |
{ |
|
99 |
String[] userOptions = {"--pp"}; |
|
100 |
String moduleName = "postprocessing1"; |
|
101 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
102 |
String[] res = {}; |
|
103 |
String[] files = {}; |
|
104 |
Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); |
|
105 |
helper.checkImage(imageDir, moduleName, res, files); |
|
106 |
||
107 |
test(imageDir); |
|
108 |
} |
|
109 |
||
110 |
// Generate an image, post-process in 2 jlink executions. |
|
111 |
{ |
|
112 |
String[] userOptions = {}; |
|
113 |
String moduleName = "postprocessing2"; |
|
114 |
helper.generateDefaultJModule(moduleName, "composite2"); |
|
115 |
String[] res = {}; |
|
116 |
String[] files = {}; |
|
117 |
Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); |
|
118 |
helper.checkImage(imageDir, moduleName, res, files); |
|
119 |
||
120 |
String[] ppOptions = {"--pp"}; |
|
121 |
helper.postProcessImage(imageDir, ppOptions); |
|
122 |
test(imageDir); |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
private static void test(Path imageDir) |
|
127 |
throws Exception { |
|
128 |
if (PPPlugin.called == null) { |
|
129 |
throw new Exception("Post processor not called."); |
|
130 |
} |
|
131 |
if (!PPPlugin.called.getHome().equals(imageDir)) { |
|
132 |
throw new Exception("Not right imageDir " + PPPlugin.called.getHome()); |
|
133 |
} |
|
134 |
if (PPPlugin.called.getExecutionArgs().isEmpty()) { |
|
135 |
throw new Exception("No arguments to run java..."); |
|
136 |
} |
|
137 |
Path gen = imageDir.resolve("lib").resolve("toto.txt"); |
|
138 |
if (!Files.exists(gen)) { |
|
139 |
throw new Exception("Generated file doesn;t exist"); |
|
140 |
} |
|
141 |
PPPlugin.called = null; |
|
142 |
} |
|
143 |
} |