author | mchung |
Wed, 31 Jan 2018 15:15:09 -0800 | |
changeset 48692 | 60c19c384333 |
parent 48543 | 7067fe4e054e |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48327
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package jdk.tools.jlink.internal; |
|
26 |
||
48223
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
27 |
import java.io.BufferedInputStream; |
36511 | 28 |
import java.io.File; |
29 |
import java.io.IOException; |
|
30 |
import java.io.PrintWriter; |
|
31 |
import java.io.UncheckedIOException; |
|
32 |
import java.lang.module.Configuration; |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42762
diff
changeset
|
33 |
import java.lang.module.FindException; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
34 |
import java.lang.module.ModuleDescriptor; |
36511 | 35 |
import java.lang.module.ModuleFinder; |
36 |
import java.lang.module.ModuleReference; |
|
37 |
import java.lang.module.ResolutionException; |
|
38 |
import java.lang.module.ResolvedModule; |
|
39 |
import java.net.URI; |
|
40 |
import java.nio.ByteOrder; |
|
41 |
import java.nio.file.Files; |
|
42 |
import java.nio.file.Path; |
|
43 |
import java.nio.file.Paths; |
|
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
44 |
import java.util.ArrayList; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
45 |
import java.util.Arrays; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
46 |
import java.util.Comparator; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
47 |
import java.util.Date; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
48 |
import java.util.HashMap; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
49 |
import java.util.HashSet; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
50 |
import java.util.List; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
51 |
import java.util.Locale; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
52 |
import java.util.Map; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
53 |
import java.util.Objects; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
54 |
import java.util.Optional; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
55 |
import java.util.Set; |
36511 | 56 |
import java.util.stream.Collectors; |
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
57 |
import java.util.stream.Stream; |
36511 | 58 |
|
59 |
import jdk.tools.jlink.internal.TaskHelper.BadArgs; |
|
60 |
import static jdk.tools.jlink.internal.TaskHelper.JLINK_BUNDLE; |
|
41559
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
41484
diff
changeset
|
61 |
import jdk.tools.jlink.internal.Jlink.JlinkConfiguration; |
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
41484
diff
changeset
|
62 |
import jdk.tools.jlink.internal.Jlink.PluginsConfiguration; |
36511 | 63 |
import jdk.tools.jlink.internal.TaskHelper.Option; |
64 |
import jdk.tools.jlink.internal.TaskHelper.OptionsHelper; |
|
65 |
import jdk.tools.jlink.internal.ImagePluginStack.ImageProvider; |
|
66 |
import jdk.tools.jlink.plugin.PluginException; |
|
67 |
import jdk.tools.jlink.builder.DefaultImageBuilder; |
|
68 |
import jdk.tools.jlink.plugin.Plugin; |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
69 |
import jdk.internal.module.ModulePath; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
70 |
import jdk.internal.module.ModuleResolution; |
36511 | 71 |
|
72 |
/** |
|
73 |
* Implementation for the jlink tool. |
|
74 |
* |
|
75 |
* ## Should use jdk.joptsimple some day. |
|
76 |
*/ |
|
77 |
public class JlinkTask { |
|
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
|
78 |
static final boolean DEBUG = Boolean.getBoolean("jlink.debug"); |
36511 | 79 |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
80 |
// jlink API ignores by default. Remove when signing is implemented. |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
81 |
static final boolean IGNORE_SIGNING_DEFAULT = true; |
36511 | 82 |
|
83 |
private static final TaskHelper taskHelper |
|
84 |
= new TaskHelper(JLINK_BUNDLE); |
|
85 |
||
39308 | 86 |
private static final Option<?>[] recognizedOptions = { |
36511 | 87 |
new Option<JlinkTask>(false, (task, opt, arg) -> { |
88 |
task.options.help = true; |
|
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48327
diff
changeset
|
89 |
}, "--help", "-h", "-?"), |
36511 | 90 |
new Option<JlinkTask>(true, (task, opt, arg) -> { |
41212
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
91 |
// if used multiple times, the last one wins! |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
92 |
// So, clear previous values, if any. |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
93 |
task.options.modulePath.clear(); |
36511 | 94 |
String[] dirs = arg.split(File.pathSeparator); |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39834
diff
changeset
|
95 |
int i = 0; |
39125
e97953d38291
8155955: packager needs to determine the root modules to create JRE image
mchung
parents:
38869
diff
changeset
|
96 |
Arrays.stream(dirs) |
e97953d38291
8155955: packager needs to determine the root modules to create JRE image
mchung
parents:
38869
diff
changeset
|
97 |
.map(Paths::get) |
e97953d38291
8155955: packager needs to determine the root modules to create JRE image
mchung
parents:
38869
diff
changeset
|
98 |
.forEach(task.options.modulePath::add); |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39834
diff
changeset
|
99 |
}, "--module-path", "-p"), |
36511 | 100 |
new Option<JlinkTask>(true, (task, opt, arg) -> { |
41212
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
101 |
// if used multiple times, the last one wins! |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
102 |
// So, clear previous values, if any. |
54a8bb41b174
8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents:
40261
diff
changeset
|
103 |
task.options.limitMods.clear(); |
36511 | 104 |
for (String mn : arg.split(",")) { |
105 |
if (mn.isEmpty()) { |
|
106 |
throw taskHelper.newBadArgs("err.mods.must.be.specified", |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39834
diff
changeset
|
107 |
"--limit-modules"); |
36511 | 108 |
} |
109 |
task.options.limitMods.add(mn); |
|
110 |
} |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39834
diff
changeset
|
111 |
}, "--limit-modules"), |
36511 | 112 |
new Option<JlinkTask>(true, (task, opt, arg) -> { |
113 |
for (String mn : arg.split(",")) { |
|
114 |
if (mn.isEmpty()) { |
|
115 |
throw taskHelper.newBadArgs("err.mods.must.be.specified", |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39834
diff
changeset
|
116 |
"--add-modules"); |
36511 | 117 |
} |
118 |
task.options.addMods.add(mn); |
|
119 |
} |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39834
diff
changeset
|
120 |
}, "--add-modules"), |
36511 | 121 |
new Option<JlinkTask>(true, (task, opt, arg) -> { |
122 |
Path path = Paths.get(arg); |
|
123 |
task.options.output = path; |
|
124 |
}, "--output"), |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
125 |
new Option<JlinkTask>(false, (task, opt, arg) -> { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
126 |
task.options.bindServices = true; |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
127 |
}, "--bind-services"), |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
128 |
new Option<JlinkTask>(false, (task, opt, arg) -> { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
129 |
task.options.suggestProviders = true; |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
130 |
}, "--suggest-providers", "", true), |
36511 | 131 |
new Option<JlinkTask>(true, (task, opt, arg) -> { |
42762 | 132 |
String[] values = arg.split("="); |
133 |
// check values |
|
134 |
if (values.length != 2 || values[0].isEmpty() || values[1].isEmpty()) { |
|
135 |
throw taskHelper.newBadArgs("err.launcher.value.format", arg); |
|
136 |
} else { |
|
137 |
String commandName = values[0]; |
|
138 |
String moduleAndMain = values[1]; |
|
139 |
int idx = moduleAndMain.indexOf("/"); |
|
140 |
if (idx != -1) { |
|
141 |
if (moduleAndMain.substring(0, idx).isEmpty()) { |
|
142 |
throw taskHelper.newBadArgs("err.launcher.module.name.empty", arg); |
|
143 |
} |
|
144 |
||
145 |
if (moduleAndMain.substring(idx + 1).isEmpty()) { |
|
146 |
throw taskHelper.newBadArgs("err.launcher.main.class.empty", arg); |
|
147 |
} |
|
148 |
} |
|
149 |
task.options.launchers.put(commandName, moduleAndMain); |
|
150 |
} |
|
151 |
}, "--launcher"), |
|
152 |
new Option<JlinkTask>(true, (task, opt, arg) -> { |
|
36511 | 153 |
if ("little".equals(arg)) { |
154 |
task.options.endian = ByteOrder.LITTLE_ENDIAN; |
|
155 |
} else if ("big".equals(arg)) { |
|
156 |
task.options.endian = ByteOrder.BIG_ENDIAN; |
|
157 |
} else { |
|
158 |
throw taskHelper.newBadArgs("err.unknown.byte.order", arg); |
|
159 |
} |
|
160 |
}, "--endian"), |
|
161 |
new Option<JlinkTask>(false, (task, opt, arg) -> { |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
162 |
task.options.verbose = true; |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
163 |
}, "--verbose", "-v"), |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
164 |
new Option<JlinkTask>(false, (task, opt, arg) -> { |
36511 | 165 |
task.options.version = true; |
166 |
}, "--version"), |
|
167 |
new Option<JlinkTask>(true, (task, opt, arg) -> { |
|
168 |
Path path = Paths.get(arg); |
|
169 |
if (Files.exists(path)) { |
|
170 |
throw taskHelper.newBadArgs("err.dir.exists", path); |
|
171 |
} |
|
172 |
task.options.packagedModulesPath = path; |
|
173 |
}, true, "--keep-packaged-modules"), |
|
174 |
new Option<JlinkTask>(true, (task, opt, arg) -> { |
|
175 |
task.options.saveoptsfile = arg; |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
39834
diff
changeset
|
176 |
}, "--save-opts"), |
36511 | 177 |
new Option<JlinkTask>(false, (task, opt, arg) -> { |
178 |
task.options.fullVersion = true; |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
179 |
}, true, "--full-version"), |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
180 |
new Option<JlinkTask>(false, (task, opt, arg) -> { |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
181 |
task.options.ignoreSigning = true; |
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41919
diff
changeset
|
182 |
}, "--ignore-signing-information"),}; |
36511 | 183 |
|
184 |
private static final String PROGNAME = "jlink"; |
|
185 |
private final OptionsValues options = new OptionsValues(); |
|
186 |
||
187 |
private static final OptionsHelper<JlinkTask> optionsHelper |
|
188 |
= taskHelper.newOptionsHelper(JlinkTask.class, recognizedOptions); |
|
189 |
private PrintWriter log; |
|
190 |
||
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41212
diff
changeset
|
191 |
void setLog(PrintWriter out, PrintWriter err) { |
36511 | 192 |
log = out; |
193 |
taskHelper.setLog(log); |
|
194 |
} |
|
195 |
||
196 |
/** |
|
197 |
* Result codes. |
|
198 |
*/ |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
199 |
static final int |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
200 |
EXIT_OK = 0, // Completed with no errors. |
36511 | 201 |
EXIT_ERROR = 1, // Completed but reported errors. |
202 |
EXIT_CMDERR = 2, // Bad command-line arguments |
|
203 |
EXIT_SYSERR = 3, // System error or resource exhaustion. |
|
204 |
EXIT_ABNORMAL = 4;// terminated abnormally |
|
205 |
||
206 |
static class OptionsValues { |
|
207 |
boolean help; |
|
208 |
String saveoptsfile; |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
209 |
boolean verbose; |
36511 | 210 |
boolean version; |
211 |
boolean fullVersion; |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
212 |
final List<Path> modulePath = new ArrayList<>(); |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
213 |
final Set<String> limitMods = new HashSet<>(); |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
214 |
final Set<String> addMods = new HashSet<>(); |
36511 | 215 |
Path output; |
42762 | 216 |
final Map<String, String> launchers = new HashMap<>(); |
36511 | 217 |
Path packagedModulesPath; |
218 |
ByteOrder endian = ByteOrder.nativeOrder(); |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
219 |
boolean ignoreSigning = false; |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
220 |
boolean bindServices = false; |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
221 |
boolean suggestProviders = false; |
36511 | 222 |
} |
223 |
||
224 |
int run(String[] args) { |
|
225 |
if (log == null) { |
|
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41212
diff
changeset
|
226 |
setLog(new PrintWriter(System.out, true), |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
41212
diff
changeset
|
227 |
new PrintWriter(System.err, true)); |
36511 | 228 |
} |
229 |
try { |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
230 |
List<String> remaining = optionsHelper.handleOptions(this, args); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
231 |
if (remaining.size() > 0 && !options.suggestProviders) { |
48692
60c19c384333
8196310: jlink --suggest-providers fails with missing resource if --output specified
mchung
parents:
48543
diff
changeset
|
232 |
throw taskHelper.newBadArgs("err.orphan.arguments", |
60c19c384333
8196310: jlink --suggest-providers fails with missing resource if --output specified
mchung
parents:
48543
diff
changeset
|
233 |
remaining.stream().collect(Collectors.joining(" "))) |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
234 |
.showUsage(true); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
235 |
} |
36511 | 236 |
if (options.help) { |
237 |
optionsHelper.showHelp(PROGNAME); |
|
238 |
return EXIT_OK; |
|
239 |
} |
|
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39308
diff
changeset
|
240 |
if (optionsHelper.shouldListPlugins()) { |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39308
diff
changeset
|
241 |
optionsHelper.listPlugins(); |
36511 | 242 |
return EXIT_OK; |
243 |
} |
|
244 |
if (options.version || options.fullVersion) { |
|
245 |
taskHelper.showVersion(options.fullVersion); |
|
246 |
return EXIT_OK; |
|
247 |
} |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
248 |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
249 |
if (taskHelper.getExistingImage() != null) { |
36511 | 250 |
postProcessOnly(taskHelper.getExistingImage()); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
251 |
return EXIT_OK; |
36511 | 252 |
} |
253 |
||
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
254 |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
255 |
if (options.modulePath.isEmpty()) { |
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
256 |
// no --module-path specified - try to set $JAVA_HOME/jmods if that exists |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
257 |
Path jmods = getDefaultModulePath(); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
258 |
if (jmods != null) { |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
259 |
options.modulePath.add(jmods); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
260 |
} |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
261 |
|
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
262 |
if (options.modulePath.isEmpty()) { |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
263 |
throw taskHelper.newBadArgs("err.modulepath.must.be.specified") |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
264 |
.showUsage(true); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
265 |
} |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
266 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
267 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
268 |
JlinkConfiguration config = initJlinkConfig(); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
269 |
if (options.suggestProviders) { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
270 |
suggestProviders(config, remaining); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
271 |
} else { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
272 |
createImage(config); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
273 |
if (options.saveoptsfile != null) { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
274 |
Files.write(Paths.get(options.saveoptsfile), getSaveOpts().getBytes()); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
275 |
} |
36511 | 276 |
} |
277 |
||
278 |
return EXIT_OK; |
|
41561
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
279 |
} catch (PluginException | IllegalArgumentException | |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42762
diff
changeset
|
280 |
UncheckedIOException |IOException | FindException | ResolutionException e) { |
36511 | 281 |
log.println(taskHelper.getMessage("error.prefix") + " " + e.getMessage()); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
282 |
if (DEBUG) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
283 |
e.printStackTrace(log); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
284 |
} |
36511 | 285 |
return EXIT_ERROR; |
286 |
} catch (BadArgs e) { |
|
287 |
taskHelper.reportError(e.key, e.args); |
|
288 |
if (e.showUsage) { |
|
289 |
log.println(taskHelper.getMessage("main.usage.summary", PROGNAME)); |
|
290 |
} |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
291 |
if (DEBUG) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
292 |
e.printStackTrace(log); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
293 |
} |
36511 | 294 |
return EXIT_CMDERR; |
295 |
} catch (Throwable x) { |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
296 |
log.println(taskHelper.getMessage("error.prefix") + " " + x.getMessage()); |
36511 | 297 |
x.printStackTrace(log); |
298 |
return EXIT_ABNORMAL; |
|
299 |
} finally { |
|
300 |
log.flush(); |
|
301 |
} |
|
302 |
} |
|
303 |
||
304 |
/* |
|
305 |
* Jlink API entry point. |
|
306 |
*/ |
|
307 |
public static void createImage(JlinkConfiguration config, |
|
39125
e97953d38291
8155955: packager needs to determine the root modules to create JRE image
mchung
parents:
38869
diff
changeset
|
308 |
PluginsConfiguration plugins) |
36511 | 309 |
throws Exception { |
310 |
Objects.requireNonNull(config); |
|
311 |
Objects.requireNonNull(config.getOutput()); |
|
312 |
plugins = plugins == null ? new PluginsConfiguration() : plugins; |
|
313 |
||
314 |
// First create the image provider |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
315 |
ImageProvider imageProvider = |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
316 |
createImageProvider(config, |
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
317 |
null, |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
318 |
IGNORE_SIGNING_DEFAULT, |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
319 |
false, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
320 |
false, |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
321 |
null); |
36511 | 322 |
|
323 |
// Then create the Plugin Stack |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
324 |
ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(plugins); |
36511 | 325 |
|
326 |
//Ask the stack to proceed; |
|
327 |
stack.operate(imageProvider); |
|
328 |
} |
|
329 |
||
330 |
/* |
|
331 |
* Jlink API entry point. |
|
332 |
*/ |
|
333 |
public static void postProcessImage(ExecutableImage image, List<Plugin> postProcessorPlugins) |
|
334 |
throws Exception { |
|
335 |
Objects.requireNonNull(image); |
|
336 |
Objects.requireNonNull(postProcessorPlugins); |
|
337 |
PluginsConfiguration config = new PluginsConfiguration(postProcessorPlugins); |
|
338 |
ImagePluginStack stack = ImagePluginConfiguration. |
|
339 |
parseConfiguration(config); |
|
340 |
||
341 |
stack.operate((ImagePluginStack stack1) -> image); |
|
342 |
} |
|
343 |
||
344 |
private void postProcessOnly(Path existingImage) throws Exception { |
|
42762 | 345 |
PluginsConfiguration config = taskHelper.getPluginsConfig(null, null); |
36511 | 346 |
ExecutableImage img = DefaultImageBuilder.getExecutableImage(existingImage); |
347 |
if (img == null) { |
|
348 |
throw taskHelper.newBadArgs("err.existing.image.invalid"); |
|
349 |
} |
|
350 |
postProcessImage(img, config.getPlugins()); |
|
351 |
} |
|
352 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
353 |
// the token for "all modules on the module path" |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
354 |
private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH"; |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
355 |
private JlinkConfiguration initJlinkConfig() throws BadArgs { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
356 |
Set<String> roots = new HashSet<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
357 |
for (String mod : options.addMods) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
358 |
if (mod.equals(ALL_MODULE_PATH)) { |
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
359 |
ModuleFinder finder = newModuleFinder(options.modulePath, options.limitMods, Set.of()); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
360 |
// all observable modules are roots |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
361 |
finder.findAll() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
362 |
.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
363 |
.map(ModuleReference::descriptor) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
364 |
.map(ModuleDescriptor::name) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
365 |
.forEach(mn -> roots.add(mn)); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
366 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
367 |
roots.add(mod); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
368 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
369 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
370 |
|
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
371 |
ModuleFinder finder = newModuleFinder(options.modulePath, options.limitMods, roots); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
372 |
if (!finder.find("java.base").isPresent()) { |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
373 |
Path defModPath = getDefaultModulePath(); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
374 |
if (defModPath != null) { |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
375 |
options.modulePath.add(defModPath); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
376 |
} |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
377 |
finder = newModuleFinder(options.modulePath, options.limitMods, roots); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
378 |
} |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
379 |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
380 |
return new JlinkConfiguration(options.output, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
381 |
roots, |
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
382 |
options.endian, |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
383 |
finder); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
384 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
385 |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
386 |
private void createImage(JlinkConfiguration config) throws Exception { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
387 |
if (options.output == null) { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
388 |
throw taskHelper.newBadArgs("err.output.must.be.specified").showUsage(true); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
389 |
} |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
390 |
if (options.addMods.isEmpty()) { |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
391 |
throw taskHelper.newBadArgs("err.mods.must.be.specified", "--add-modules") |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
392 |
.showUsage(true); |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
393 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
394 |
|
36511 | 395 |
// First create the image provider |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
396 |
ImageProvider imageProvider = createImageProvider(config, |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41919
diff
changeset
|
397 |
options.packagedModulesPath, |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
398 |
options.ignoreSigning, |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
399 |
options.bindServices, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
400 |
options.verbose, |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
401 |
log); |
36511 | 402 |
|
403 |
// Then create the Plugin Stack |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
404 |
ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration( |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
405 |
taskHelper.getPluginsConfig(options.output, options.launchers)); |
36511 | 406 |
|
407 |
//Ask the stack to proceed |
|
408 |
stack.operate(imageProvider); |
|
409 |
} |
|
410 |
||
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
411 |
/** |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
412 |
* @return the system module path or null |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
413 |
*/ |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
414 |
public static Path getDefaultModulePath() { |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
415 |
Path jmods = Paths.get(System.getProperty("java.home"), "jmods"); |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
416 |
return Files.isDirectory(jmods)? jmods : null; |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
417 |
} |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
418 |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
419 |
/* |
41817
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
420 |
* Returns a module finder of the given module path that limits |
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
421 |
* the observable modules to those in the transitive closure of |
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
422 |
* the modules specified in {@code limitMods} plus other modules |
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
423 |
* specified in the {@code roots} set. |
47737
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
424 |
* |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
425 |
* @throws IllegalArgumentException if java.base module is present |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
426 |
* but its descriptor has no version |
41817
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
427 |
*/ |
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
428 |
public static ModuleFinder newModuleFinder(List<Path> paths, |
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
429 |
Set<String> limitMods, |
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
430 |
Set<String> roots) |
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
431 |
{ |
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
432 |
if (Objects.requireNonNull(paths).isEmpty()) { |
48071
a5cadeee8763
8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents:
47737
diff
changeset
|
433 |
throw new IllegalArgumentException(taskHelper.getMessage("err.empty.module.path")); |
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
434 |
} |
47737
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
435 |
|
41817
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
436 |
Path[] entries = paths.toArray(new Path[0]); |
47737
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
437 |
Runtime.Version version = Runtime.version(); |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
438 |
ModuleFinder finder = ModulePath.of(version, true, entries); |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
439 |
|
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
440 |
if (finder.find("java.base").isPresent()) { |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
441 |
// use the version of java.base module, if present, as |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
442 |
// the release version for multi-release JAR files |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
443 |
ModuleDescriptor.Version v = finder.find("java.base").get() |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
444 |
.descriptor().version().orElseThrow(() -> |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
445 |
new IllegalArgumentException("No version in java.base descriptor") |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
446 |
); |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
447 |
|
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
448 |
// java.base version is different than the current runtime version |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
449 |
version = Runtime.Version.parse(v.toString()); |
48327 | 450 |
if (Runtime.version().feature() != version.feature() || |
451 |
Runtime.version().interim() != version.interim()) |
|
452 |
{ |
|
48071
a5cadeee8763
8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents:
47737
diff
changeset
|
453 |
// jlink version and java.base version do not match. |
a5cadeee8763
8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents:
47737
diff
changeset
|
454 |
// We do not (yet) support this mode. |
a5cadeee8763
8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents:
47737
diff
changeset
|
455 |
throw new IllegalArgumentException(taskHelper.getMessage("err.jlink.version.mismatch", |
48327 | 456 |
Runtime.version().feature(), Runtime.version().interim(), |
457 |
version.feature(), version.interim())); |
|
47737
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
458 |
} |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
459 |
} |
41817
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
460 |
|
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
461 |
// if limitmods is specified then limit the universe |
47464
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
462 |
if (limitMods != null && !limitMods.isEmpty()) { |
36de9c637393
8189777: jlink --module-path default value and automatic addition of $JAVA_HOME/jmods if java.base is missing
sundar
parents:
47399
diff
changeset
|
463 |
finder = limitFinder(finder, limitMods, Objects.requireNonNull(roots)); |
41817
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
464 |
} |
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
465 |
return finder; |
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
466 |
} |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
467 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
468 |
private static Path toPathLocation(ResolvedModule m) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
469 |
Optional<URI> ouri = m.reference().location(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
470 |
if (!ouri.isPresent()) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
471 |
throw new InternalError(m + " does not have a location"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
472 |
URI uri = ouri.get(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
473 |
return Paths.get(uri); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
474 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
475 |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
476 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
477 |
private static ImageProvider createImageProvider(JlinkConfiguration config, |
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
478 |
Path retainModulesPath, |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
479 |
boolean ignoreSigning, |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
480 |
boolean bindService, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
481 |
boolean verbose, |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
482 |
PrintWriter log) |
36511 | 483 |
throws IOException |
484 |
{ |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
485 |
Configuration cf = bindService ? config.resolveAndBind() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
486 |
: config.resolve(); |
36511 | 487 |
|
47399
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
488 |
cf.modules().stream() |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
489 |
.map(ResolvedModule::reference) |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
490 |
.filter(mref -> mref.descriptor().isAutomatic()) |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
491 |
.findAny() |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
492 |
.ifPresent(mref -> { |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
493 |
String loc = mref.location().map(URI::toString).orElse("<unknown>"); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
494 |
throw new IllegalArgumentException( |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
495 |
taskHelper.getMessage("err.automatic.module", mref.descriptor().name(), loc)); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
496 |
}); |
fb677b3f0888
8189671: jlink should clearly report error when an automatic module is used
sundar
parents:
47216
diff
changeset
|
497 |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
498 |
if (verbose && log != null) { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
499 |
// print modules to be linked in |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
500 |
cf.modules().stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
501 |
.sorted(Comparator.comparing(ResolvedModule::name)) |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
502 |
.forEach(rm -> log.format("%s %s%n", |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
503 |
rm.name(), rm.reference().location().get())); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
504 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
505 |
// print provider info |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
506 |
Set<ModuleReference> references = cf.modules().stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
507 |
.map(ResolvedModule::reference).collect(Collectors.toSet()); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
508 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
509 |
String msg = String.format("%n%s:", taskHelper.getMessage("providers.header")); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
510 |
printProviders(log, msg, references); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
511 |
} |
36511 | 512 |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
513 |
// emit a warning for any incubating modules in the configuration |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
514 |
if (log != null) { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
515 |
String im = cf.modules() |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
516 |
.stream() |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
517 |
.map(ResolvedModule::reference) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
518 |
.filter(ModuleResolution::hasIncubatingWarning) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
519 |
.map(ModuleReference::descriptor) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
520 |
.map(ModuleDescriptor::name) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
521 |
.collect(Collectors.joining(", ")); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
522 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
523 |
if (!"".equals(im)) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
524 |
log.println("WARNING: Using incubator modules: " + im); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
525 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42339
diff
changeset
|
526 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
527 |
Map<String, Path> mods = cf.modules().stream() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
528 |
.collect(Collectors.toMap(ResolvedModule::name, JlinkTask::toPathLocation)); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
529 |
return new ImageHelper(cf, mods, config.getByteOrder(), retainModulesPath, ignoreSigning); |
36511 | 530 |
} |
531 |
||
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
532 |
/* |
36511 | 533 |
* Returns a ModuleFinder that limits observability to the given root |
534 |
* modules, their transitive dependences, plus a set of other modules. |
|
535 |
*/ |
|
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
536 |
public static ModuleFinder limitFinder(ModuleFinder finder, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
537 |
Set<String> roots, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
538 |
Set<String> otherMods) { |
36511 | 539 |
|
540 |
// resolve all root modules |
|
541 |
Configuration cf = Configuration.empty() |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42762
diff
changeset
|
542 |
.resolve(finder, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42762
diff
changeset
|
543 |
ModuleFinder.of(), |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42762
diff
changeset
|
544 |
roots); |
36511 | 545 |
|
546 |
// module name -> reference |
|
547 |
Map<String, ModuleReference> map = new HashMap<>(); |
|
548 |
cf.modules().forEach(m -> { |
|
549 |
ModuleReference mref = m.reference(); |
|
550 |
map.put(mref.descriptor().name(), mref); |
|
551 |
}); |
|
552 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
553 |
// add the other modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
554 |
otherMods.stream() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
555 |
.map(finder::find) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
556 |
.flatMap(Optional::stream) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
557 |
.forEach(mref -> map.putIfAbsent(mref.descriptor().name(), mref)); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
558 |
|
36511 | 559 |
// set of modules that are observable |
560 |
Set<ModuleReference> mrefs = new HashSet<>(map.values()); |
|
561 |
||
562 |
return new ModuleFinder() { |
|
563 |
@Override |
|
564 |
public Optional<ModuleReference> find(String name) { |
|
565 |
return Optional.ofNullable(map.get(name)); |
|
566 |
} |
|
567 |
||
568 |
@Override |
|
569 |
public Set<ModuleReference> findAll() { |
|
570 |
return mrefs; |
|
571 |
} |
|
572 |
}; |
|
573 |
} |
|
574 |
||
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
575 |
/* |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
576 |
* Returns a map of each service type to the modules that use it |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
577 |
* It will include services that are provided by a module but may not used |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
578 |
* by any of the observable modules. |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
579 |
*/ |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
580 |
private static Map<String, Set<String>> uses(Set<ModuleReference> modules) { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
581 |
// collects the services used by the modules and print uses |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
582 |
Map<String, Set<String>> services = new HashMap<>(); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
583 |
modules.stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
584 |
.map(ModuleReference::descriptor) |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
585 |
.forEach(md -> { |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
586 |
// include services that may not be used by any observable modules |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
587 |
md.provides().forEach(p -> |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
588 |
services.computeIfAbsent(p.service(), _k -> new HashSet<>())); |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
589 |
md.uses().forEach(s -> services.computeIfAbsent(s, _k -> new HashSet<>()) |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
590 |
.add(md.name())); |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
591 |
}); |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
592 |
return services; |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
593 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
594 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
595 |
private static void printProviders(PrintWriter log, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
596 |
String header, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
597 |
Set<ModuleReference> modules) { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
598 |
printProviders(log, header, modules, uses(modules)); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
599 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
600 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
601 |
/* |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
602 |
* Prints the providers that are used by the specified services. |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
603 |
* |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
604 |
* The specified services maps a service type name to the modules |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
605 |
* using the service type which may be empty if no observable module uses |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
606 |
* that service. |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
607 |
*/ |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
608 |
private static void printProviders(PrintWriter log, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
609 |
String header, |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
610 |
Set<ModuleReference> modules, |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
611 |
Map<String, Set<String>> serviceToUses) { |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
612 |
if (modules.isEmpty()) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
613 |
return; |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
614 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
615 |
// Build a map of a service type to the provider modules |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
616 |
Map<String, Set<ModuleDescriptor>> providers = new HashMap<>(); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
617 |
modules.stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
618 |
.map(ModuleReference::descriptor) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
619 |
.forEach(md -> { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
620 |
md.provides().stream() |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
621 |
.filter(p -> serviceToUses.containsKey(p.service())) |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
622 |
.forEach(p -> providers.computeIfAbsent(p.service(), _k -> new HashSet<>()) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
623 |
.add(md)); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
624 |
}); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
625 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
626 |
if (!providers.isEmpty()) { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
627 |
log.println(header); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
628 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
629 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
630 |
// print the providers of the service types used by the specified modules |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
631 |
// sorted by the service type name and then provider's module name |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
632 |
providers.entrySet().stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
633 |
.sorted(Map.Entry.comparingByKey()) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
634 |
.forEach(e -> { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
635 |
String service = e.getKey(); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
636 |
e.getValue().stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
637 |
.sorted(Comparator.comparing(ModuleDescriptor::name)) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
638 |
.forEach(md -> |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
639 |
md.provides().stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
640 |
.filter(p -> p.service().equals(service)) |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
641 |
.forEach(p -> { |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
642 |
String usedBy; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
643 |
if (serviceToUses.get(p.service()).isEmpty()) { |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
644 |
usedBy = "not used by any observable module"; |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
645 |
} else { |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
646 |
usedBy = serviceToUses.get(p.service()).stream() |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
647 |
.sorted() |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
648 |
.collect(Collectors.joining(",", "used by ", "")); |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
649 |
} |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
650 |
log.format(" %s provides %s %s%n", |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
651 |
md.name(), p.service(), usedBy); |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
652 |
}) |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
653 |
); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
654 |
}); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
655 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
656 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
657 |
private void suggestProviders(JlinkConfiguration config, List<String> args) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
658 |
throws BadArgs |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
659 |
{ |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
660 |
if (args.size() > 1) { |
48692
60c19c384333
8196310: jlink --suggest-providers fails with missing resource if --output specified
mchung
parents:
48543
diff
changeset
|
661 |
List<String> arguments = args.get(0).startsWith("-") |
60c19c384333
8196310: jlink --suggest-providers fails with missing resource if --output specified
mchung
parents:
48543
diff
changeset
|
662 |
? args |
60c19c384333
8196310: jlink --suggest-providers fails with missing resource if --output specified
mchung
parents:
48543
diff
changeset
|
663 |
: args.subList(1, args.size()); |
60c19c384333
8196310: jlink --suggest-providers fails with missing resource if --output specified
mchung
parents:
48543
diff
changeset
|
664 |
throw taskHelper.newBadArgs("err.invalid.arg.for.option", |
60c19c384333
8196310: jlink --suggest-providers fails with missing resource if --output specified
mchung
parents:
48543
diff
changeset
|
665 |
"--suggest-providers", |
60c19c384333
8196310: jlink --suggest-providers fails with missing resource if --output specified
mchung
parents:
48543
diff
changeset
|
666 |
arguments.stream().collect(Collectors.joining(" "))); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
667 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
668 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
669 |
if (options.bindServices) { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
670 |
log.println(taskHelper.getMessage("no.suggested.providers")); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
671 |
return; |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
672 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
673 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
674 |
ModuleFinder finder = config.finder(); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
675 |
if (args.isEmpty()) { |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
676 |
// print providers used by the observable modules without service binding |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
677 |
Set<ModuleReference> mrefs = finder.findAll(); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
678 |
// print uses of the modules that would be linked into the image |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
679 |
mrefs.stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
680 |
.sorted(Comparator.comparing(mref -> mref.descriptor().name())) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
681 |
.forEach(mref -> { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
682 |
ModuleDescriptor md = mref.descriptor(); |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
683 |
log.format("%s %s%n", md.name(), |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
684 |
mref.location().get()); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
685 |
md.uses().stream().sorted() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
686 |
.forEach(s -> log.format(" uses %s%n", s)); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
687 |
}); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
688 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
689 |
String msg = String.format("%n%s:", taskHelper.getMessage("suggested.providers.header")); |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
690 |
printProviders(log, msg, mrefs, uses(mrefs)); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
691 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
692 |
} else { |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
693 |
// comma-separated service types, if specified |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
694 |
Set<String> names = Stream.of(args.get(0).split(",")) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
695 |
.collect(Collectors.toSet()); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
696 |
// find the modules that provide the specified service |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
697 |
Set<ModuleReference> mrefs = finder.findAll().stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
698 |
.filter(mref -> mref.descriptor().provides().stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
699 |
.map(ModuleDescriptor.Provides::service) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
700 |
.anyMatch(names::contains)) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
701 |
.collect(Collectors.toSet()); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
702 |
|
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
703 |
// find the modules that uses the specified services |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
704 |
Map<String, Set<String>> uses = new HashMap<>(); |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
705 |
names.forEach(s -> uses.computeIfAbsent(s, _k -> new HashSet<>())); |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
706 |
finder.findAll().stream() |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
707 |
.map(ModuleReference::descriptor) |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
708 |
.forEach(md -> md.uses().stream() |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
709 |
.filter(names::contains) |
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
710 |
.forEach(s -> uses.get(s).add(md.name()))); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
711 |
|
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
712 |
// check if any name given on the command line are not provided by any module |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
713 |
mrefs.stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
714 |
.flatMap(mref -> mref.descriptor().provides().stream() |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
715 |
.map(ModuleDescriptor.Provides::service)) |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
716 |
.forEach(names::remove); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
717 |
if (!names.isEmpty()) { |
44747
dc7378149f20
8178404: jlink --suggest-providers should list providers from observable modules
mchung
parents:
44367
diff
changeset
|
718 |
log.println(taskHelper.getMessage("warn.provider.notfound", |
48692
60c19c384333
8196310: jlink --suggest-providers fails with missing resource if --output specified
mchung
parents:
48543
diff
changeset
|
719 |
names.stream().sorted().collect(Collectors.joining(",")))); |
44367
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
720 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
721 |
|
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
722 |
String msg = String.format("%n%s:", taskHelper.getMessage("suggested.providers.header")); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
723 |
printProviders(log, msg, mrefs, uses); |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
724 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
725 |
} |
a81c9c6619fb
8174826: jlink support for linking in service provider modules
mchung
parents:
44359
diff
changeset
|
726 |
|
36511 | 727 |
private String getSaveOpts() { |
728 |
StringBuilder sb = new StringBuilder(); |
|
729 |
sb.append('#').append(new Date()).append("\n"); |
|
730 |
for (String c : optionsHelper.getInputCommand()) { |
|
731 |
sb.append(c).append(" "); |
|
732 |
} |
|
733 |
||
734 |
return sb.toString(); |
|
735 |
} |
|
736 |
||
737 |
private static String getBomHeader() { |
|
738 |
StringBuilder sb = new StringBuilder(); |
|
739 |
sb.append("#").append(new Date()).append("\n"); |
|
740 |
sb.append("#Please DO NOT Modify this file").append("\n"); |
|
741 |
return sb.toString(); |
|
742 |
} |
|
743 |
||
744 |
private String genBOMContent() throws IOException { |
|
745 |
StringBuilder sb = new StringBuilder(); |
|
746 |
sb.append(getBomHeader()); |
|
747 |
StringBuilder command = new StringBuilder(); |
|
748 |
for (String c : optionsHelper.getInputCommand()) { |
|
749 |
command.append(c).append(" "); |
|
750 |
} |
|
751 |
sb.append("command").append(" = ").append(command); |
|
752 |
sb.append("\n"); |
|
753 |
||
754 |
return sb.toString(); |
|
755 |
} |
|
756 |
||
757 |
private static String genBOMContent(JlinkConfiguration config, |
|
758 |
PluginsConfiguration plugins) |
|
759 |
throws IOException { |
|
760 |
StringBuilder sb = new StringBuilder(); |
|
761 |
sb.append(getBomHeader()); |
|
762 |
sb.append(config); |
|
763 |
sb.append(plugins); |
|
764 |
return sb.toString(); |
|
765 |
} |
|
766 |
||
767 |
private static class ImageHelper implements ImageProvider { |
|
768 |
final ByteOrder order; |
|
769 |
final Path packagedModulesPath; |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
770 |
final boolean ignoreSigning; |
47737
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
771 |
final Runtime.Version version; |
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
772 |
final Set<Archive> archives; |
36511 | 773 |
|
774 |
ImageHelper(Configuration cf, |
|
775 |
Map<String, Path> modsPaths, |
|
776 |
ByteOrder order, |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
777 |
Path packagedModulesPath, |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
778 |
boolean ignoreSigning) throws IOException { |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
779 |
this.order = order; |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
780 |
this.packagedModulesPath = packagedModulesPath; |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
781 |
this.ignoreSigning = ignoreSigning; |
47737
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
782 |
|
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
783 |
// use the version of java.base module, if present, as |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
784 |
// the release version for multi-release JAR files |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
785 |
this.version = cf.findModule("java.base") |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
786 |
.map(ResolvedModule::reference) |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
787 |
.map(ModuleReference::descriptor) |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
788 |
.flatMap(ModuleDescriptor::version) |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
789 |
.map(ModuleDescriptor.Version::toString) |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
790 |
.map(Runtime.Version::parse) |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
791 |
.orElse(Runtime.version()); |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
792 |
|
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
793 |
this.archives = modsPaths.entrySet().stream() |
36511 | 794 |
.map(e -> newArchive(e.getKey(), e.getValue())) |
795 |
.collect(Collectors.toSet()); |
|
796 |
} |
|
797 |
||
798 |
private Archive newArchive(String module, Path path) { |
|
799 |
if (path.toString().endsWith(".jmod")) { |
|
800 |
return new JmodArchive(module, path); |
|
801 |
} else if (path.toString().endsWith(".jar")) { |
|
47737
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
47464
diff
changeset
|
802 |
ModularJarArchive modularJarArchive = new ModularJarArchive(module, path, version); |
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
803 |
|
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
804 |
Stream<Archive.Entry> signatures = modularJarArchive.entries().filter((entry) -> { |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
805 |
String name = entry.name().toUpperCase(Locale.ENGLISH); |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
806 |
|
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
807 |
return name.startsWith("META-INF/") && name.indexOf('/', 9) == -1 && ( |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
808 |
name.endsWith(".SF") || |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
809 |
name.endsWith(".DSA") || |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
810 |
name.endsWith(".RSA") || |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
811 |
name.endsWith(".EC") || |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
812 |
name.startsWith("META-INF/SIG-") |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
813 |
); |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
814 |
}); |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
815 |
|
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
816 |
if (signatures.count() != 0) { |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
817 |
if (ignoreSigning) { |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
818 |
System.err.println(taskHelper.getMessage("warn.signing", path)); |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
819 |
} else { |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
820 |
throw new IllegalArgumentException(taskHelper.getMessage("err.signing", path)); |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
821 |
} |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
822 |
} |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
823 |
|
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
824 |
return modularJarArchive; |
36511 | 825 |
} else if (Files.isDirectory(path)) { |
48223
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
826 |
Path modInfoPath = path.resolve("module-info.class"); |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
827 |
if (Files.isRegularFile(modInfoPath)) { |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
828 |
return new DirArchive(path, findModuleName(modInfoPath)); |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
829 |
} else { |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
830 |
throw new IllegalArgumentException( |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
831 |
taskHelper.getMessage("err.not.a.module.directory", path)); |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
832 |
} |
36511 | 833 |
} else { |
41919
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
834 |
throw new IllegalArgumentException( |
612b698f8b8f
8159393: jlink should print a warning that a signed modular JAR will be treated as unsigned
jlaskey
parents:
41831
diff
changeset
|
835 |
taskHelper.getMessage("err.not.modular.format", module, path)); |
36511 | 836 |
} |
837 |
} |
|
838 |
||
48223
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
839 |
private static String findModuleName(Path modInfoPath) { |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
840 |
try (BufferedInputStream bis = new BufferedInputStream( |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
841 |
Files.newInputStream(modInfoPath))) { |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
842 |
return ModuleDescriptor.read(bis).name(); |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
843 |
} catch (IOException exp) { |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
844 |
throw new IllegalArgumentException(taskHelper.getMessage( |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
845 |
"err.cannot.read.module.info", modInfoPath), exp); |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
846 |
} |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
847 |
} |
962b4324320c
8192986: Inconsistent handling of exploded modules in jlink
sundar
parents:
48071
diff
changeset
|
848 |
|
36511 | 849 |
@Override |
850 |
public ExecutableImage retrieve(ImagePluginStack stack) throws IOException { |
|
851 |
ExecutableImage image = ImageFileCreator.create(archives, order, stack); |
|
852 |
if (packagedModulesPath != null) { |
|
853 |
// copy the packaged modules to the given path |
|
854 |
Files.createDirectories(packagedModulesPath); |
|
855 |
for (Archive a : archives) { |
|
856 |
Path file = a.getPath(); |
|
857 |
Path dest = packagedModulesPath.resolve(file.getFileName()); |
|
858 |
Files.copy(file, dest); |
|
859 |
} |
|
860 |
} |
|
861 |
return image; |
|
862 |
} |
|
863 |
} |
|
864 |
} |