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
26 package jdk.jpackage.internal;
27
28 import java.io.File;
29 import java.nio.file.Files;
30 import java.text.MessageFormat;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collection;
34 import java.util.LinkedHashMap;
35 import java.util.LinkedHashSet;
36 import java.util.LinkedList;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.Set;
40 import java.util.TreeMap;
41 import java.util.TreeSet;
42
43 /**
44 * DeployParams
45 *
46 * This class is generated and used in Arguments.processArguments() as
47 * intermediate step in generating the BundleParams and ultimately the Bundles
48 */
49 public class DeployParams {
274 void setClasspath() {
275 String classpath = "";
276 for (RelativeFileSet resource : resources) {
277 for (String file : resource.getIncludedFiles()) {
278 if (file.endsWith(".jar")) {
279 classpath += file + File.pathSeparator;
280 }
281 }
282 }
283 addBundleArgument(
284 StandardBundlerParam.CLASSPATH.getID(), classpath);
285 }
286
287 private static File createFile(final File baseDir, final String path) {
288 final File testFile = new File(path);
289 return testFile.isAbsolute() ?
290 testFile : new File(baseDir == null ?
291 null : baseDir.getAbsolutePath(), path);
292 }
293
294 static void validateAppName(String s) throws PackagerException {
295 if (s == null || s.length() == 0) {
296 // empty or null string - there is no unsupported char
297 return;
298 }
299
300 int last = s.length() - 1;
301
302 char fc = s.charAt(0);
303 char lc = s.charAt(last);
304
305 // illegal to end in backslash escape char
306 if (lc == '\\') {
307 throw new PackagerException("ERR_InvalidCharacterInArgument", "--name");
308 }
309
310 for (int i = 0; i < s.length(); i++) {
311 char a = s.charAt(i);
312 // We check for ASCII codes first which we accept. If check fails,
313 // check if it is acceptable extended ASCII or unicode character.
314 if (a < ' ' || a > '~' || a == '%') {
315 // Reject '%', whitespaces and ISO Control.
316 // Accept anything else including special chars like copyright
317 // symbols. Note: space will be included by ASCII check above,
318 // but other whitespace like tabs or new line will be ignored.
319 if (Character.isISOControl(a) ||
320 Character.isWhitespace(a) || a == '%') {
321 throw new PackagerException(
322 "ERR_InvalidCharacterInArgument", "--name");
323 }
324 }
325 if (a == '"') {
326 throw new PackagerException(
327 "ERR_InvalidCharacterInArgument", "--name");
328 }
329 }
330 }
331
332 public void validate() throws PackagerException {
333 if (outdir == null) {
334 throw new PackagerException("ERR_MissingArgument", "--output");
335 }
336
337 boolean hasModule = (bundlerArguments.get(
338 Arguments.CLIOptions.MODULE.getId()) != null);
339 boolean hasImage = (bundlerArguments.get(
340 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null);
341 boolean hasClass = (bundlerArguments.get(
342 Arguments.CLIOptions.APPCLASS.getId()) != null);
343 boolean hasMain = (bundlerArguments.get(
344 Arguments.CLIOptions.MAIN_JAR.getId()) != null);
345 boolean hasRuntimeImage = (bundlerArguments.get(
346 Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null);
347 boolean hasInput = (bundlerArguments.get(
380 }
381 }
382
383 // if bundling non-modular image, or installer without app-image
384 // then we need some resources and a main class
385 if (!hasModule && !hasImage && !jreInstaller) {
386 if (resources.isEmpty()) {
387 throw new PackagerException("ERR_MissingAppResources");
388 }
389 if (!hasClass) {
390 throw new PackagerException("ERR_MissingArgument", "--class");
391 }
392 if (!hasMain) {
393 throw new PackagerException("ERR_MissingArgument",
394 "--main-jar");
395 }
396 }
397
398 String name = (String)bundlerArguments.get(
399 Arguments.CLIOptions.NAME.getId());
400 validateAppName(name);
401
402 // Validate app image if set
403 String appImage = (String)bundlerArguments.get(
404 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
405 if (appImage != null) {
406 File appImageDir = new File(appImage);
407 if (!appImageDir.exists()) {
408 throw new PackagerException("ERR_AppImageNotExist", appImage);
409 }
410
411 File appImageAppDir = new File(appImage + File.separator + "app");
412 File appImageRuntimeDir = new File(appImage
413 + File.separator + "runtime");
414 if (!appImageAppDir.exists() || !appImageRuntimeDir.exists()) {
415 throw new PackagerException("ERR_AppImageInvalid", appImage);
416 }
417 }
418
419 // Validate build-root
420 String root = (String)bundlerArguments.get(
|
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
26 package jdk.jpackage.internal;
27
28 import java.io.File;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.InvalidPathException;
32 import java.text.MessageFormat;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.Collection;
36 import java.util.LinkedHashMap;
37 import java.util.LinkedHashSet;
38 import java.util.LinkedList;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Set;
42 import java.util.TreeMap;
43 import java.util.TreeSet;
44
45 /**
46 * DeployParams
47 *
48 * This class is generated and used in Arguments.processArguments() as
49 * intermediate step in generating the BundleParams and ultimately the Bundles
50 */
51 public class DeployParams {
276 void setClasspath() {
277 String classpath = "";
278 for (RelativeFileSet resource : resources) {
279 for (String file : resource.getIncludedFiles()) {
280 if (file.endsWith(".jar")) {
281 classpath += file + File.pathSeparator;
282 }
283 }
284 }
285 addBundleArgument(
286 StandardBundlerParam.CLASSPATH.getID(), classpath);
287 }
288
289 private static File createFile(final File baseDir, final String path) {
290 final File testFile = new File(path);
291 return testFile.isAbsolute() ?
292 testFile : new File(baseDir == null ?
293 null : baseDir.getAbsolutePath(), path);
294 }
295
296 static void validateName(String s, boolean forApp)
297 throws PackagerException {
298
299 String exceptionKey = forApp ?
300 "ERR_InvalidAppName" : "ERR_InvalidSLName";
301
302 if (s == null) {
303 if (forApp) {
304 return;
305 } else {
306 throw new PackagerException(exceptionKey, s);
307 }
308 }
309 if (s.charAt(s.length() - 1) == '\\') {
310 throw new PackagerException(exceptionKey, s);
311 }
312 try {
313 // name must be valid path element for this file system
314 Path p = (new File(s)).toPath();
315 // and it must be a single name element in a path
316 if (p.getNameCount() != 1) {
317 throw new PackagerException(exceptionKey, s);
318 }
319 } catch (InvalidPathException ipe) {
320 throw new PackagerException(ipe, exceptionKey, s);
321 }
322
323 for (int i = 0; i < s.length(); i++) {
324 char a = s.charAt(i);
325 // We check for ASCII codes first which we accept. If check fails,
326 // check if it is acceptable extended ASCII or unicode character.
327 if (a < ' ' || a > '~') {
328 // Accept anything else including special chars like copyright
329 // symbols. Note: space will be included by ASCII check above,
330 // but other whitespace like tabs or new line will be rejected.
331 if (Character.isISOControl(a) ||
332 Character.isWhitespace(a)) {
333 throw new PackagerException(exceptionKey, s);
334 }
335 } else if (a == '"' || a == '%') {
336 throw new PackagerException(exceptionKey, s);
337 }
338 }
339 }
340
341 public void validate() throws PackagerException {
342 if (outdir == null) {
343 throw new PackagerException("ERR_MissingArgument", "--output");
344 }
345
346 boolean hasModule = (bundlerArguments.get(
347 Arguments.CLIOptions.MODULE.getId()) != null);
348 boolean hasImage = (bundlerArguments.get(
349 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null);
350 boolean hasClass = (bundlerArguments.get(
351 Arguments.CLIOptions.APPCLASS.getId()) != null);
352 boolean hasMain = (bundlerArguments.get(
353 Arguments.CLIOptions.MAIN_JAR.getId()) != null);
354 boolean hasRuntimeImage = (bundlerArguments.get(
355 Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null);
356 boolean hasInput = (bundlerArguments.get(
389 }
390 }
391
392 // if bundling non-modular image, or installer without app-image
393 // then we need some resources and a main class
394 if (!hasModule && !hasImage && !jreInstaller) {
395 if (resources.isEmpty()) {
396 throw new PackagerException("ERR_MissingAppResources");
397 }
398 if (!hasClass) {
399 throw new PackagerException("ERR_MissingArgument", "--class");
400 }
401 if (!hasMain) {
402 throw new PackagerException("ERR_MissingArgument",
403 "--main-jar");
404 }
405 }
406
407 String name = (String)bundlerArguments.get(
408 Arguments.CLIOptions.NAME.getId());
409 validateName(name, true);
410
411 // Validate app image if set
412 String appImage = (String)bundlerArguments.get(
413 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
414 if (appImage != null) {
415 File appImageDir = new File(appImage);
416 if (!appImageDir.exists()) {
417 throw new PackagerException("ERR_AppImageNotExist", appImage);
418 }
419
420 File appImageAppDir = new File(appImage + File.separator + "app");
421 File appImageRuntimeDir = new File(appImage
422 + File.separator + "runtime");
423 if (!appImageAppDir.exists() || !appImageRuntimeDir.exists()) {
424 throw new PackagerException("ERR_AppImageInvalid", appImage);
425 }
426 }
427
428 // Validate build-root
429 String root = (String)bundlerArguments.get(
|