1 /*
   2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  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 
  26 package com.sun.javafx.tools.packager;
  27 
  28 import com.oracle.tools.packager.*;
  29 import com.oracle.tools.packager.RelativeFileSet;
  30 import com.oracle.tools.packager.jnlp.JNLPBundler;
  31 import com.sun.javafx.tools.ant.Callback;
  32 import com.sun.javafx.tools.packager.bundlers.*;
  33 import com.sun.javafx.tools.packager.bundlers.Bundler.BundleType;
  34 import java.io.File;
  35 import java.util.ArrayList;
  36 import java.util.Arrays;
  37 import java.util.Collection;
  38 import java.util.LinkedHashMap;
  39 import java.util.LinkedHashSet;
  40 import java.util.LinkedList;
  41 import java.util.List;
  42 import java.util.Map;
  43 import java.util.Set;
  44 import java.util.TreeMap;
  45 import java.util.TreeSet;
  46 
  47 import jdk.packager.internal.JLinkBundlerHelper;
  48 
  49 import static com.oracle.tools.packager.jnlp.JNLPBundler.*;
  50 
  51 public class DeployParams extends CommonParams {
  52     public enum RunMode {
  53         WEBSTART, EMBEDDED, STANDALONE, ALL
  54     }
  55 
  56     final List<RelativeFileSet> resources = new ArrayList<>();
  57 
  58     String id;
  59     String title;
  60     String vendor;
  61     String email;
  62     String description;
  63     String category;
  64     String licenseType;
  65     String copyright;
  66     String version;
  67     Boolean systemWide;
  68     Boolean serviceHint;
  69     Boolean signBundle;
  70     Boolean installdirChooser;
  71 
  72     String applicationClass;
  73     String preloader;
  74 
  75     List<Param> params;
  76     List<HtmlParam> htmlParams;
  77     List<String> arguments; //unnamed arguments
  78 
  79     // Java 9 modules support
  80     Set<String> addModules = null;
  81     Set<String> limitModules = null;
  82     Boolean stripNativeCommands = null;
  83     Boolean detectmods = null;
  84     String modulePath = null;
  85     String module = null;
  86     String debugPort = null;
  87     File srcdir;
  88 
  89     int width;
  90     int height;
  91     String embeddedWidth = null;
  92     String embeddedHeight = null;
  93 
  94     String appName;
  95     String codebase;
  96 
  97     boolean embedJNLP = true;
  98     @Deprecated final boolean embedCertificates = false;
  99     boolean allPermissions = false;
 100     String updateMode = "background";
 101     boolean isExtension = false;
 102     boolean isSwingApp = false;
 103 
 104     Boolean needShortcut = null;
 105     Boolean needMenu = null;
 106     Boolean needInstall = null;
 107 
 108     String outfile;
 109     //if true then we cobundle js and image files needed
 110     // for web deployment with the application
 111     boolean includeDT;
 112 
 113     String placeholder = "'javafx-app-placeholder'";
 114     String appId = null;
 115 
 116     // didn't have a setter...
 117     boolean offlineAllowed = true;
 118 
 119     List<JSCallback> callbacks;
 120 
 121     //list of HTML templates to process
 122     List<Template> templates = new LinkedList<>();
 123 
 124     String jrePlatform = "1.8+";
 125     String fxPlatform = PackagerLib.JAVAFX_VERSION+"+";
 126     File javaRuntimeToUse = null;
 127     boolean javaRuntimeWasSet = false;
 128 
 129     //list of jvm args (in theory string can contain spaces and need to be escaped
 130     List<String> jvmargs = new LinkedList<>();
 131     Map<String, String> jvmUserArgs = new LinkedHashMap<>();
 132 
 133     //list of jvm properties (can also be passed as VM args
 134     // but keeping them separate make it a bit more convinient for JNLP generation)
 135     Map<String, String> properties = new LinkedHashMap<>();
 136 
 137     // raw arguments to the bundler
 138     Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
 139 
 140     String fallbackApp = null;
 141 
 142     public void setJavaRuntimeSource(File src) {
 143         javaRuntimeToUse = src;
 144         javaRuntimeWasSet = true;
 145     }
 146 
 147     public void setCodebase(String codebase) {
 148         this.codebase = codebase;
 149     }
 150 
 151     public void setId(String id) {
 152         this.id = id;
 153     }
 154 
 155     public void setCategory(String category) {
 156         this.category = category;
 157     }
 158 
 159     public void setLicenseType(String licenseType) {
 160         this.licenseType = licenseType;
 161     }
 162 
 163     public void setCopyright(String copyright) {
 164         this.copyright = copyright;
 165     }
 166 
 167     public void setVersion(String version) {
 168         this.version = version;
 169     }
 170 
 171     public void setSystemWide(Boolean systemWide) {
 172         this.systemWide = systemWide;
 173     }
 174 
 175     public void setServiceHint(Boolean serviceHint) {
 176         this.serviceHint = serviceHint;
 177     }
 178 
 179     public void setInstalldirChooser(Boolean installdirChooser) {
 180         this.installdirChooser = installdirChooser;
 181     }
 182 
 183     public void setSignBundle(Boolean signBundle) {
 184         this.signBundle = signBundle;
 185     }
 186 
 187     public void setJRE(String v) {
 188         jrePlatform = v;
 189     }
 190 
 191     public void setSwingAppWithEmbeddedJavaFX(boolean v) {
 192         isSwingApp = v;
 193     }
 194 
 195     public void setNeedInstall(boolean b) {
 196         needInstall = b;
 197     }
 198 
 199     public void setOfflineAllowed(boolean b) {
 200         offlineAllowed = b;
 201     }
 202 
 203     public void setNeedShortcut(Boolean b) {
 204         needShortcut = b;
 205     }
 206 
 207     public void setNeedMenu(Boolean b) {
 208         needMenu = b;
 209     }
 210 
 211     public void setEmbeddedDimensions(String w, String h) {
 212         embeddedWidth = w;
 213         embeddedHeight = h;
 214     }
 215 
 216     public void setFallback(String v) {
 217         if (v == null) {
 218             return;
 219         }
 220 
 221         if ("none".equals(v) || "null".equals(v)) {
 222             fallbackApp = null;
 223         } else {
 224             fallbackApp = v;
 225         }
 226     }
 227 
 228     public void setJavafx(String v) {
 229         fxPlatform = v;
 230     }
 231 
 232     public void addJvmArg(String v) {
 233         jvmargs.add(v);
 234     }
 235 
 236     public void addJvmUserArg(String n, String v) {
 237         jvmUserArgs.put(n, v);
 238     }
 239 
 240     public void addJvmProperty(String n, String v) {
 241         properties.put(n, v);
 242     }
 243 
 244     public void setAllPermissions(boolean allPermissions) {
 245         this.allPermissions = allPermissions;
 246     }
 247 
 248     public void setAppName(String appName) {
 249         this.appName = appName;
 250     }
 251 
 252     public void setArguments(List<String> args) {
 253         this.arguments = args;
 254     }
 255 
 256     public void addAddModule(String module) {
 257         if (addModules == null) {
 258             addModules = new LinkedHashSet<>();
 259         }
 260 
 261         addModules.add(module);
 262     }
 263 
 264     public void addLimitModule(String module) {
 265         if (limitModules == null) {
 266             limitModules = new LinkedHashSet<>();
 267         }
 268 
 269         limitModules.add(module);
 270     }
 271 
 272     public void setModulePath(String value) {
 273         this.modulePath = value;
 274     }
 275 
 276     public void setModule(String value) {
 277         this.module = value;
 278     }
 279 
 280     public void setDebugPort(String value) {
 281         this.debugPort = value;
 282     }
 283 
 284     public void setStripNativeCommands(boolean value) {
 285         this.stripNativeCommands = value;
 286     }
 287 
 288     public void setDetectModules(boolean value) {
 289         this.detectmods = value;
 290     }
 291 
 292     public void setDescription(String description) {
 293         this.description = description;
 294     }
 295 
 296     public void setEmbedJNLP(boolean embedJNLP) {
 297         this.embedJNLP = embedJNLP;
 298     }
 299 
 300     @Deprecated
 301     public void setEmbedCertifcates(boolean v) {
 302         if (v) {
 303             System.out.println("JavaFX Packager no longer supports embedding certificates in JNLP files.  Setting will be ignored.");
 304         }
 305     }
 306 
 307     public void setPlaceholder(String p) {
 308         placeholder = p;
 309     }
 310 
 311     public void setAppId(String id) {
 312         appId = id;
 313     }
 314 
 315     public void setHeight(int height) {
 316         this.height = height;
 317     }
 318 
 319     public void setHtmlParams(List<HtmlParam> htmlParams) {
 320         this.htmlParams = htmlParams;
 321     }
 322 
 323     public void setOutfile(String outfile) {
 324         this.outfile = outfile;
 325     }
 326 
 327     public void setParams(List<Param> params) {
 328         this.params = params;
 329     }
 330 
 331     public void setPreloader(String preloader) {
 332         this.preloader = preloader;
 333     }
 334 
 335     public void setTitle(String title) {
 336         this.title = title;
 337     }
 338 
 339     public void setUpdateMode(String updateMode) {
 340         this.updateMode = updateMode;
 341     }
 342 
 343     public void setVendor(String vendor) {
 344         this.vendor = vendor;
 345     }
 346 
 347     public void setEmail(String email) {
 348         this.email = email;
 349     }
 350 
 351     public void setWidth(int width) {
 352         this.width = width;
 353     }
 354 
 355     public void setExtension(boolean isExtension) {
 356         this.isExtension = isExtension;
 357     }
 358 
 359     public void setApplicationClass(String applicationClass) {
 360         this.applicationClass = applicationClass;
 361     }
 362 
 363     public void setIncludeDT(boolean doEmbed) {
 364         includeDT = doEmbed;
 365     }
 366 
 367     public void setJSCallbacks(List<JSCallback> list) {
 368         callbacks = list;
 369     }
 370 
 371     public void setCallbacks(List<Callback> list) {
 372         List<JSCallback> jslist = new ArrayList<>(list.size());
 373         for (Callback cb: list) {
 374             jslist.add(new JSCallback(cb.getName(), cb.getCmd()));
 375         }
 376         callbacks = jslist;
 377     }
 378 
 379     static class Template {
 380         File in;
 381         File out;
 382 
 383         Template(File in, File out) {
 384             this.in = in;
 385             this.out = out;
 386         }
 387     }
 388 
 389     public void addTemplate(File in, File out) {
 390         templates.add(new Template(in, out));
 391     }
 392 
 393     //we need to expand as in some cases
 394     // (most notably javapackager)
 395     //we may get "." as filename and assumption is we include
 396     // everything in the given folder
 397     // (IOUtils.copyfiles() have recursive behavior)
 398     List<File> expandFileset(File root) {
 399         List<File> files = new LinkedList<>();
 400         if (com.oracle.tools.packager.IOUtils.isNotSymbolicLink(root)) {
 401             if (root.isDirectory()) {
 402                 File[] children = root.listFiles();
 403                 if (children != null) {
 404                     for (File f : children) {
 405                         files.addAll(expandFileset(f));
 406                     }
 407                 }
 408             } else {
 409                 files.add(root);
 410             }
 411         }
 412         return files;
 413     }
 414 
 415     @Override
 416     public void addResource(File baseDir, String path) {
 417         File file = new File(baseDir, path);
 418         //normalize top level dir
 419         // to strip things like "." in the path
 420         // or it can confuse symlink detection logic
 421         file = file.getAbsoluteFile();
 422 
 423         if (baseDir == null) {
 424             baseDir = file.getParentFile();
 425         }
 426         resources.add(new RelativeFileSet(baseDir, new LinkedHashSet<>(expandFileset(file))));
 427     }
 428 
 429     @Override
 430     public void addResource(File baseDir, File file) {
 431         //normalize initial file
 432         // to strip things like "." in the path
 433         // or it can confuse symlink detection logic
 434         file = file.getAbsoluteFile();
 435 
 436         if (baseDir == null) {
 437             baseDir = file.getParentFile();
 438         }
 439         resources.add(new RelativeFileSet(baseDir, new LinkedHashSet<>(expandFileset(file))));
 440     }
 441 
 442     public void addResource(File baseDir, String path, String type) {
 443         addResource(baseDir, createFile(baseDir, path), type);
 444     }
 445 
 446     public void addResource(File baseDir, File file, String type) {
 447         addResource(baseDir, file, "eager", type, null, null);
 448     }
 449 
 450     public void addResource(File baseDir, File file, String mode, String type, String os, String arch) {
 451         Set<File> singleFile = new LinkedHashSet<>();
 452         singleFile.add(file);
 453         if (baseDir == null) {
 454             baseDir = file.getParentFile();
 455         }
 456         RelativeFileSet rfs = new RelativeFileSet(baseDir, singleFile);
 457         rfs.setArch(arch);
 458         rfs.setMode(mode);
 459         rfs.setOs(os);
 460         rfs.setType(parseTypeFromString(type, file));
 461         resources.add(rfs);
 462     }
 463 
 464     private RelativeFileSet.Type parseTypeFromString(String type, File file) {
 465         if (type == null) {
 466             if (file.getName().endsWith(".jar")) {
 467                 return RelativeFileSet.Type.jar;
 468             } else if (file.getName().endsWith(".jnlp")) {
 469                 return RelativeFileSet.Type.jnlp;
 470             } else {
 471                 return RelativeFileSet.Type.UNKNOWN;
 472             }
 473         } else {
 474             return RelativeFileSet.Type.valueOf(type);
 475         }
 476     }
 477 
 478     private static File createFile(final File baseDir, final String path) {
 479         final File testFile = new File(path);
 480         return testFile.isAbsolute()
 481                 ? testFile
 482                 : new File(baseDir == null
 483                     ? null
 484                     : baseDir.getAbsolutePath(),
 485                       path);
 486     }
 487 
 488 
 489     @Override
 490     public void validate() throws PackagerException {
 491         if (outdir == null) {
 492             throw new PackagerException("ERR_MissingArgument", "-outdir");
 493         }
 494         if (outfile == null) {
 495             throw new PackagerException("ERR_MissingArgument", "-outfile");
 496         }
 497         if (resources.isEmpty()) {
 498             throw new PackagerException("ERR_MissingAppResources");
 499         }
 500         if (applicationClass == null && module == null) { //TODO better error here for mainmodule
 501             throw new PackagerException("ERR_MissingArgument", "-appclass");
 502         }
 503     }
 504 
 505     public boolean validateForJNLP() {
 506         boolean result = false;
 507 
 508         // Success
 509         if (applicationClass != null && !applicationClass.isEmpty() &&
 510             (getBundleType() == BundleType.JNLP || getBundleType() == BundleType.ALL)) {
 511             result = true;
 512         }
 513 
 514         // Failed
 515         if ((module != null && !module.isEmpty()) ||
 516             (addModules != null && !addModules.isEmpty()) ||
 517             (limitModules != null && !limitModules.isEmpty()) |
 518             (modulePath != null && !modulePath.isEmpty()) ||
 519             getBundleType() == BundleType.INSTALLER ||
 520             getBundleType() == BundleType.NATIVE ||
 521             getBundleType() == BundleType.IMAGE) {
 522 
 523             result = false;
 524         }
 525 
 526         return result;
 527     }
 528 
 529     public boolean validateForBundle() {
 530         boolean result = false;
 531 
 532         // Success
 533         if (((applicationClass != null && !applicationClass.isEmpty()) ||
 534             !module.isEmpty())) {
 535             result = true;
 536         }
 537 
 538         return result;
 539     }
 540 
 541     //could be icon or splash
 542     static class Icon {
 543         final static int UNDEFINED = -1;
 544 
 545         String href;
 546         String kind;
 547         int width = UNDEFINED;
 548         int height = UNDEFINED;
 549         int depth = UNDEFINED;
 550         RunMode mode = RunMode.WEBSTART;
 551 
 552         Icon(String href, String kind, int w, int h, int d, RunMode m) {
 553             mode = m;
 554             this.href = href;
 555             this.kind = kind;
 556             if (w > 0) {
 557                 width = w;
 558             }
 559             if (h > 0) {
 560                 height = h;
 561             }
 562             if (d > 0) {
 563                 depth = d;
 564             }
 565         }
 566     }
 567 
 568     List<Icon> icons = new LinkedList<>();
 569 
 570     public void addIcon(String href, String kind, int w, int h, int d, RunMode m) {
 571         icons.add(new Icon(href, kind, w, h, d, m));
 572     }
 573 
 574     BundleType bundleType = BundleType.NONE;
 575     String targetFormat = null; //means any
 576 
 577     public void setBundleType(BundleType type) {
 578         bundleType = type;
 579     }
 580 
 581     public BundleType getBundleType() {
 582         return bundleType;
 583     }
 584 
 585     public void setTargetFormat(String t) {
 586         targetFormat = t;
 587     }
 588 
 589     public String getTargetFormat() {
 590         return targetFormat;
 591     }
 592 
 593     private String getArch() {
 594         String arch = System.getProperty("os.arch").toLowerCase();
 595 
 596         if ("x86".equals(arch) || "i386".equals(arch) || "i486".equals(arch)
 597                 || "i586".equals(arch) || "i686".equals(arch)) {
 598             arch = "x86";
 599         } else if ("x86_64".equals(arch) || "amd64".equals("arch")) {
 600             arch = "x86_64";
 601         }
 602 
 603         return arch;
 604     }
 605 
 606     static final Set<String> multi_args = new TreeSet<>(Arrays.asList(
 607             StandardBundlerParam.JVM_PROPERTIES.getID(),
 608             StandardBundlerParam.JVM_OPTIONS.getID(),
 609             StandardBundlerParam.USER_JVM_OPTIONS.getID(),
 610             StandardBundlerParam.ARGUMENTS.getID(),
 611             JLinkBundlerHelper.MODULE_PATH.getID(),
 612             JLinkBundlerHelper.ADD_MODULES.getID(),
 613             JLinkBundlerHelper.LIMIT_MODULES.getID(),
 614             JLinkBundlerHelper.STRIP_NATIVE_COMMANDS.getID(),
 615             JLinkBundlerHelper.DETECT_MODULES.getID()
 616     ));
 617 
 618     @SuppressWarnings("unchecked")
 619     public void addBundleArgument(String key, Object value) {
 620         // special hack for multi-line arguments
 621         if (multi_args.contains(key) && value instanceof String) {
 622             Object existingValue = bundlerArguments.get(key);
 623             if (existingValue instanceof String) {
 624                 bundlerArguments.put(key, existingValue + "\n\n" + value);
 625             } else if (existingValue instanceof List) {
 626                 ((List)existingValue).add(value);
 627             } else if (existingValue instanceof Map && ((String)value).contains("=")) {
 628                 String[] mapValues = ((String)value).split("=", 2);
 629                 ((Map)existingValue).put(mapValues[0], mapValues[1]);
 630             } else {
 631                 bundlerArguments.put(key, value);
 632             }
 633         } else {
 634             bundlerArguments.put(key, value);
 635         }
 636     }
 637 
 638     public BundleParams getBundleParams() {
 639         BundleParams bundleParams = new BundleParams();
 640 
 641         //construct app resources
 642         //  relative to output folder!
 643         String currentOS = System.getProperty("os.name").toLowerCase();
 644         String currentArch = getArch();
 645 
 646         for (RelativeFileSet rfs : resources) {
 647             String os = rfs.getOs();
 648             String arch = rfs.getArch();
 649             //skip resources for other OS
 650             // and nativelib jars (we are including raw libraries)
 651             if ((os == null || currentOS.contains(os.toLowerCase())) &&
 652                     (arch == null || currentArch.startsWith(arch.toLowerCase()))
 653                     && rfs.getType() != RelativeFileSet.Type.nativelib) {
 654                 if (rfs.getType() == RelativeFileSet.Type.license) {
 655                     for (String s : rfs.getIncludedFiles()) {
 656                         bundleParams.addLicenseFile(s);
 657                     }
 658                 }
 659             }
 660         }
 661 
 662         bundleParams.setAppResourcesList(resources);
 663 
 664         bundleParams.setIdentifier(id);
 665 
 666         if (javaRuntimeWasSet) {
 667             bundleParams.setRuntime(javaRuntimeToUse);
 668         }
 669         bundleParams.setApplicationClass(applicationClass);
 670         bundleParams.setPrelaoderClass(preloader);
 671         bundleParams.setName(this.appName);
 672         bundleParams.setAppVersion(version);
 673         bundleParams.setType(bundleType);
 674         bundleParams.setBundleFormat(targetFormat);
 675         bundleParams.setVendor(vendor);
 676         bundleParams.setEmail(email);
 677         bundleParams.setShortcutHint(needShortcut);
 678         bundleParams.setMenuHint(needMenu);
 679         putUnlessNull(INSTALL_HINT.getID(), needInstall);
 680         bundleParams.setSystemWide(systemWide);
 681         bundleParams.setServiceHint(serviceHint);
 682         bundleParams.setInstalldirChooser(installdirChooser);
 683         bundleParams.setSignBundle(signBundle);
 684         bundleParams.setCopyright(copyright);
 685         bundleParams.setApplicationCategory(category);
 686         bundleParams.setLicenseType(licenseType);
 687         bundleParams.setDescription(description);
 688         bundleParams.setTitle(title);
 689         if (verbose) bundleParams.setVerbose(true);
 690 
 691         bundleParams.setJvmProperties(properties);
 692         bundleParams.setJvmargs(jvmargs);
 693         bundleParams.setJvmUserArgs(jvmUserArgs);
 694         bundleParams.setArguments(arguments);
 695 
 696         if (addModules != null && !addModules.isEmpty()) {
 697             bundleParams.setAddModules(addModules);
 698         }
 699 
 700         if (limitModules != null && !limitModules.isEmpty()) {
 701             bundleParams.setLimitModules(limitModules);
 702         }
 703 
 704         if (stripNativeCommands != null) {
 705             bundleParams.setStripNativeCommands(stripNativeCommands);
 706         }
 707 
 708         bundleParams.setSrcDir(srcdir);
 709 
 710         if (modulePath != null && !modulePath.isEmpty()) {
 711             bundleParams.setModulePath(modulePath);
 712         }
 713 
 714         if (module != null && !module.isEmpty()) {
 715             bundleParams.setMainModule(module);
 716         }
 717 
 718         if (debugPort != null && !debugPort.isEmpty()) {
 719             bundleParams.setDebugPort(debugPort);
 720         }
 721 
 722         if (detectmods != null) {
 723             bundleParams.setDetectMods(detectmods);
 724         }
 725 
 726         File appIcon = null;
 727         List<Map<String, ? super Object>> bundlerIcons = new ArrayList<>();
 728         for (Icon ic: icons) {
 729             //NB: in theory we should be paying attention to RunMode but
 730             // currently everything is marked as webstart internally and runmode
 731             // is not publicly documented property
 732             if (/* (ic.mode == RunMode.ALL || ic.mode == RunMode.STANDALONE) && */
 733                 (ic.kind == null || ic.kind.equals("default")))
 734             {
 735                 //could be full path or something relative to the output folder
 736                 appIcon = new File(ic.href);
 737                 if (!appIcon.exists()) {
 738                     com.oracle.tools.packager.Log.debug("Icon [" + ic.href + "] is not valid absolute path. " +
 739                             "Assume it is relative to the output dir.");
 740                     appIcon = new File(outdir, ic.href);
 741                 }
 742             }
 743 
 744             Map<String, ? super Object> iconInfo = new TreeMap<>();
 745             if (ic.href != null) iconInfo.put(ICONS_HREF.getID(), ic.href);
 746             if (ic.kind != null) iconInfo.put(ICONS_KIND.getID(), ic.kind);
 747             if (ic.width > 0)    iconInfo.put(ICONS_WIDTH.getID(), Integer.toString(ic.width));
 748             if (ic.height > 0)   iconInfo.put(ICONS_HEIGHT.getID(), Integer.toString(ic.height));
 749             if (ic.depth > 0)    iconInfo.put(ICONS_DEPTH.getID(), Integer.toString(ic.depth));
 750 
 751             if (!iconInfo.isEmpty()) bundlerIcons.add(iconInfo);
 752         }
 753         putUnlessNullOrEmpty(ICONS.getID(), bundlerIcons);
 754 
 755         bundleParams.setIcon(appIcon);
 756 
 757         Map<String, String> paramsMap = new TreeMap<>();
 758         if (params != null) {
 759             for (Param p : params) {
 760                 paramsMap.put(p.name, p.value);
 761             }
 762         }
 763         putUnlessNullOrEmpty(JNLPBundler.APP_PARAMS.getID(), paramsMap);
 764 
 765         Map<String, String> unescapedHtmlParams = new TreeMap<>();
 766         Map<String, String> escapedHtmlParams = new TreeMap<>();
 767         if (htmlParams != null) {
 768             for (HtmlParam hp : htmlParams) {
 769                 if (hp.needEscape) {
 770                     escapedHtmlParams.put(hp.name, hp.value);
 771                 } else {
 772                     unescapedHtmlParams.put(hp.name, hp.value);
 773                 }
 774             }
 775         }
 776         putUnlessNullOrEmpty(JNLPBundler.APPLET_PARAMS.getID(), unescapedHtmlParams);
 777         putUnlessNullOrEmpty(ESCAPED_APPLET_PARAMS.getID(), escapedHtmlParams);
 778 
 779 
 780         putUnlessNull(WIDTH.getID(), width);
 781         putUnlessNull(HEIGHT.getID(), height);
 782         putUnlessNull(EMBEDDED_WIDTH.getID(), embeddedWidth);
 783         putUnlessNull(EMBEDDED_HEIGHT.getID(), embeddedHeight);
 784 
 785         putUnlessNull(CODEBASE.getID(), codebase);
 786         putUnlessNull(EMBED_JNLP.getID(), embedJNLP);
 787         // embedCertificates
 788         putUnlessNull(ALL_PERMISSIONS.getID(), allPermissions);
 789         putUnlessNull(UPDATE_MODE.getID(), updateMode);
 790         putUnlessNull(EXTENSION.getID(), isExtension);
 791         putUnlessNull(SWING_APP.getID(), isSwingApp);
 792 
 793         putUnlessNull(OUT_FILE.getID(), outfile);
 794         putUnlessNull(INCLUDE_DT.getID(), includeDT);
 795         putUnlessNull(PLACEHOLDER.getID(), placeholder);
 796         putUnlessNull(OFFLINE_ALLOWED.getID(), offlineAllowed);
 797 
 798         Map<String, String> callbacksMap = new TreeMap<>();
 799         if (callbacks != null) {
 800             for (JSCallback callback : callbacks) {
 801                 callbacksMap.put(callback.getName(), callback.getCmd());
 802             }
 803         }
 804         putUnlessNull(JS_CALLBACKS.getID(), callbacksMap);
 805 
 806         Map<File, File> templatesMap = new TreeMap<>();
 807         if (templates != null) {
 808             for (Template template : templates) {
 809                 templatesMap.put(template.in, template.out);
 810             }
 811         }
 812         putUnlessNull(TEMPLATES.getID(), templatesMap);
 813 
 814         putUnlessNull(FX_PLATFORM.getID(), fxPlatform);
 815         putUnlessNull(JRE_PLATFORM.getID(), jrePlatform);
 816 
 817         putUnlessNull(FALLBACK_APP.getID(), fallbackApp);
 818 
 819         // check for collisions
 820         TreeSet<String> keys = new TreeSet<>(bundlerArguments.keySet());
 821         keys.retainAll(bundleParams.getBundleParamsAsMap().keySet());
 822 
 823         if (!keys.isEmpty()) {
 824             throw new RuntimeException("Deploy Params and Bundler Arguments overlap in the following values:" + keys.toString());
 825         }
 826 
 827         bundleParams.addAllBundleParams(bundlerArguments);
 828 
 829         return bundleParams;
 830     }
 831 
 832     public void putUnlessNull(String param, Object value) {
 833         if (value != null) {
 834             bundlerArguments.put(param, value);
 835         }
 836     }
 837 
 838     public void putUnlessNullOrEmpty(String param, Map<?, ?> value) {
 839         if (value != null && !value.isEmpty()) {
 840             bundlerArguments.put(param, value);
 841         }
 842     }
 843 
 844     public void putUnlessNullOrEmpty(String param, Collection<?> value) {
 845         if (value != null && !value.isEmpty()) {
 846             bundlerArguments.put(param, value);
 847         }
 848     }
 849 }