author | mchung |
Mon, 12 Dec 2016 18:56:50 -0800 | |
changeset 42670 | d833113eb7d7 |
parent 39834 | 53a6fb443c20 |
child 43185 | d75d9ff8d4e7 |
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.nio.file.Path; |
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.Collections; |
|
27 |
import java.util.EnumSet; |
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.List; |
|
30 |
import java.util.Map; |
|
31 |
import java.util.Set; |
|
32 |
import jdk.tools.jlink.internal.PluginRepository; |
|
33 |
import jdk.tools.jlink.plugin.Plugin; |
|
34 |
import jdk.tools.jlink.plugin.PluginException; |
|
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:
39321
diff
changeset
|
35 |
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:
39321
diff
changeset
|
36 |
import jdk.tools.jlink.plugin.ResourcePoolBuilder; |
36511 | 37 |
import tests.Helper; |
38 |
||
39 |
/* |
|
40 |
* @test |
|
41 |
* @summary Test plugins enabled by default |
|
42 |
* @author Jean-Francois Denise |
|
43 |
* @library ../lib |
|
44 |
* @modules java.base/jdk.internal.jimage |
|
45 |
* jdk.jdeps/com.sun.tools.classfile |
|
46 |
* jdk.jlink/jdk.tools.jlink.internal |
|
47 |
* jdk.jlink/jdk.tools.jmod |
|
48 |
* jdk.jlink/jdk.tools.jimage |
|
49 |
* jdk.compiler |
|
50 |
* @build tests.* |
|
51 |
* @run main/othervm DefaultProviderTest |
|
52 |
*/ |
|
53 |
public class DefaultProviderTest { |
|
54 |
private static final String NAME = "disable-toto"; |
|
55 |
private final static Map<String, Object> expectedOptions = new HashMap<>(); |
|
56 |
||
57 |
static { |
|
58 |
expectedOptions.put("disable-toto", "false"); |
|
59 |
expectedOptions.put("option1", "value1"); |
|
60 |
expectedOptions.put("option2", "value2"); |
|
61 |
} |
|
62 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
63 |
private static class Custom implements Plugin { |
36511 | 64 |
private boolean enabled = true; |
65 |
||
66 |
@Override |
|
38320 | 67 |
public Set<State> getState() { |
68 |
return enabled ? EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL) |
|
69 |
: EnumSet.of(State.DISABLED); |
|
36511 | 70 |
} |
71 |
||
72 |
@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:
39321
diff
changeset
|
73 |
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { |
36511 | 74 |
if (!enabled) { |
75 |
throw new PluginException(NAME + " was set"); |
|
76 |
} |
|
77 |
||
78 |
DefaultProviderTest.isNewPluginsCalled = true; |
|
38320 | 79 |
in.transformAndCopy(content -> { |
36511 | 80 |
return content; |
81 |
}, 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:
39321
diff
changeset
|
82 |
|
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
83 |
return out.build(); |
36511 | 84 |
} |
85 |
||
86 |
@Override |
|
87 |
public String getName() { |
|
88 |
return NAME; |
|
89 |
} |
|
90 |
||
91 |
@Override |
|
92 |
public String getDescription() { |
|
93 |
return NAME; |
|
94 |
} |
|
95 |
||
96 |
@Override |
|
97 |
public boolean hasArguments() { |
|
98 |
return true; |
|
99 |
} |
|
100 |
||
101 |
@Override |
|
102 |
public void configure(Map<String, String> config) { |
|
103 |
if (config.containsKey(NAME)) { |
|
104 |
enabled = !Boolean.parseBoolean(config.get(NAME)); |
|
105 |
} |
|
106 |
||
107 |
if (enabled) { |
|
108 |
DefaultProviderTest.receivedOptions = config; |
|
109 |
} else { |
|
110 |
DefaultProviderTest.receivedOptions = null; |
|
111 |
} |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
private static boolean isNewPluginsCalled; |
|
116 |
private static Map<String, String> receivedOptions; |
|
117 |
||
118 |
private static void reset() { |
|
119 |
isNewPluginsCalled = false; |
|
120 |
receivedOptions = null; |
|
121 |
} |
|
122 |
||
123 |
public static void main(String[] args) throws Exception { |
|
124 |
Helper helper = Helper.newHelper(); |
|
125 |
if (helper == null) { |
|
126 |
System.err.println("Test not run"); |
|
127 |
return; |
|
128 |
} |
|
129 |
helper.generateDefaultModules(); |
|
130 |
test(helper, new Custom()); |
|
131 |
} |
|
132 |
||
133 |
private static void test(Helper helper, Plugin plugin) throws Exception { |
|
134 |
PluginRepository.registerPlugin(plugin); |
|
135 |
||
136 |
{ |
|
137 |
String[] userOptions = {}; |
|
138 |
Path imageDir = helper.generateDefaultImage(userOptions, "composite2").assertSuccess(); |
|
139 |
helper.checkImage(imageDir, "composite2", null, null); |
|
140 |
if (!isNewPluginsCalled) { |
|
141 |
throw new Exception("Should have been called"); |
|
142 |
} |
|
143 |
reset(); |
|
144 |
} |
|
145 |
||
146 |
{ |
|
147 |
String[] userOptions = {"--disable-toto=false:option1=value1:option2=value2"}; |
|
148 |
Path imageDir = helper.generateDefaultImage(userOptions, "composite2").assertSuccess(); |
|
149 |
helper.checkImage(imageDir, "composite2", null, null); |
|
150 |
if (!isNewPluginsCalled) { |
|
151 |
throw new Exception("Should have been called"); |
|
152 |
} |
|
153 |
if (!receivedOptions.equals(expectedOptions)) { |
|
154 |
throw new Exception("Optional options " + receivedOptions + " are not expected one " |
|
155 |
+ expectedOptions); |
|
156 |
} |
|
157 |
System.err.println("OPTIONS " + receivedOptions); |
|
158 |
reset(); |
|
159 |
} |
|
160 |
||
161 |
{ |
|
162 |
String[] userOptions = {"--disable-toto=true:option1=value1"}; |
|
163 |
Path imageDir = helper.generateDefaultImage(userOptions, "composite2").assertSuccess(); |
|
164 |
helper.checkImage(imageDir, "composite2", null, null); |
|
165 |
if (isNewPluginsCalled) { |
|
166 |
throw new Exception("Should not have been called"); |
|
167 |
} |
|
168 |
if (receivedOptions != null) { |
|
169 |
throw new Exception("Optional options are not expected"); |
|
170 |
} |
|
171 |
reset(); |
|
172 |
} |
|
173 |
} |
|
174 |
} |