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.packager.bundlers.*;
  32 import com.sun.javafx.tools.packager.bundlers.Bundler.BundleType;
  33 import java.io.File;
  34 import java.util.ArrayList;
  35 import java.util.Arrays;
  36 import java.util.Collection;
  37 import java.util.LinkedHashMap;
  38 import java.util.LinkedHashSet;
  39 import java.util.LinkedList;
  40 import java.util.List;
  41 import java.util.Map;
  42 import java.util.Set;
  43 import java.util.TreeMap;
  44 import java.util.TreeSet;
  45 
  46 import jdk.packager.internal.JLinkBundlerHelper;
  47 
  48 import static com.oracle.tools.packager.jnlp.JNLPBundler.*;
  49 
  50 @Deprecated
  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     String addModules = null;
  81     String limitModules = null;
  82     Boolean stripNativeCommands = null;
  83     Boolean detectmods = null;
  84     String modulePath = null;
  85     String module = null;
  86     String debugPort = null;
  87     String 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 = null;
 120 
 121     //list of HTML templates to process
 122     List<Template> templates = new LinkedList<>();
 123 
 124     String jrePlatform = PackagerLib.JAVAFX_VERSION+"+";
 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 value) {
 257         if (addModules == null) {
 258             addModules = value;
 259         }
 260         else {
 261             addModules += "," + value;
 262         }
 263     }
 264 
 265     public void addLimitModule(String value) {
 266         if (limitModules == null) {
 267             limitModules = value;
 268         }
 269         else {
 270             limitModules += "," + value;
 271         }
 272     }
 273 
 274     public void setModulePath(String value) {
 275         this.modulePath = value;
 276     }
 277 
 278     public void setModule(String value) {
 279         this.module = value;
 280     }
 281 
 282     public void setDebug(String value) {
 283         this.debugPort = value;
 284     }
 285 
 286     public void setStripNativeCommands(boolean value) {
 287         this.stripNativeCommands = value;
 288     }
 289 
 290     public void setDetectModules(boolean value) {
 291         this.detectmods = value;
 292     }
 293 
 294     public void setDescription(String description) {
 295         this.description = description;
 296     }
 297 
 298     public void setEmbedJNLP(boolean embedJNLP) {
 299         this.embedJNLP = embedJNLP;
 300     }
 301 
 302     @Deprecated
 303     public void setEmbedCertifcates(boolean v) {
 304         if (v) {
 305             System.out.println("JavaFX Packager no longer supports embedding certificates in JNLP files.  Setting will be ignored.");
 306         }
 307     }
 308 
 309     public void setPlaceholder(String p) {
 310         placeholder = p;
 311     }
 312 
 313     public void setAppId(String id) {
 314         appId = id;
 315     }
 316 
 317     public void setHeight(int height) {
 318         this.height = height;
 319     }
 320 
 321     public void setHtmlParams(List<HtmlParam> htmlParams) {
 322         this.htmlParams = htmlParams;
 323     }
 324 
 325     public void setOutfile(String outfile) {
 326         this.outfile = outfile;
 327     }
 328 
 329     public void setParams(List<Param> params) {
 330         this.params = params;
 331     }
 332 
 333     public void setPreloader(String preloader) {
 334         this.preloader = preloader;
 335     }
 336 
 337     public void setTitle(String title) {
 338         this.title = title;
 339     }
 340 
 341     public void setUpdateMode(String updateMode) {
 342         this.updateMode = updateMode;
 343     }
 344 
 345     public void setVendor(String vendor) {
 346         this.vendor = vendor;
 347     }
 348 
 349     public void setEmail(String email) {
 350         this.email = email;
 351     }
 352 
 353     public void setWidth(int width) {
 354         this.width = width;
 355     }
 356 
 357     public void setExtension(boolean isExtension) {
 358         this.isExtension = isExtension;
 359     }
 360 
 361     public void setApplicationClass(String applicationClass) {
 362         this.applicationClass = applicationClass;
 363     }
 364 
 365     public void setIncludeDT(boolean doEmbed) {
 366         includeDT = doEmbed;
 367     }
 368 
 369     public void setJSCallbacks(List<JSCallback> list) {
 370         callbacks = list;
 371     }
 372 
 373     public void addCallback(String name, String cmd) {
 374         if (callbacks == null) {
 375             callbacks = new ArrayList<>();
 376         }
 377 
 378         callbacks.add(new JSCallback(name, cmd));
 379     }
 380 
 381     static class Template {
 382         File in;
 383         File out;
 384 
 385         Template(File in, File out) {
 386             this.in = in;
 387             this.out = out;
 388         }
 389     }
 390 
 391     public void addTemplate(File in, File out) {
 392         templates.add(new Template(in, out));
 393     }
 394 
 395     //we need to expand as in some cases
 396     // (most notably javapackager)
 397     //we may get "." as filename and assumption is we include
 398     // everything in the given folder
 399     // (IOUtils.copyfiles() have recursive behavior)
 400     List<File> expandFileset(File root) {
 401         List<File> files = new LinkedList<>();
 402         if (com.oracle.tools.packager.IOUtils.isNotSymbolicLink(root)) {
 403             if (root.isDirectory()) {
 404                 File[] children = root.listFiles();
 405                 if (children != null) {
 406                     for (File f : children) {
 407                         files.addAll(expandFileset(f));
 408                     }
 409                 }
 410             } else {
 411                 files.add(root);
 412             }
 413         }
 414         return files;
 415     }
 416 
 417     @Override
 418     public void addResource(File baseDir, String path) {
 419         File file = new File(baseDir, path);
 420         //normalize top level dir
 421         // to strip things like "." in the path
 422         // or it can confuse symlink detection logic
 423         file = file.getAbsoluteFile();
 424 
 425         if (baseDir == null) {
 426             baseDir = file.getParentFile();
 427         }
 428         resources.add(new RelativeFileSet(baseDir, new LinkedHashSet<>(expandFileset(file))));
 429     }
 430 
 431     @Override
 432     public void addResource(File baseDir, File file) {
 433         //normalize initial file
 434         // to strip things like "." in the path
 435         // or it can confuse symlink detection logic
 436         file = file.getAbsoluteFile();
 437 
 438         if (baseDir == null) {
 439             baseDir = file.getParentFile();
 440         }
 441         resources.add(new RelativeFileSet(baseDir, new LinkedHashSet<>(expandFileset(file))));
 442     }
 443 
 444     public void addResource(File baseDir, String path, String type) {
 445         addResource(baseDir, createFile(baseDir, path), type);
 446     }
 447 
 448     public void addResource(File baseDir, File file, String type) {
 449         addResource(baseDir, file, "eager", type, null, null);
 450     }
 451 
 452     public void addResource(File baseDir, File file, String mode, String type, String os, String arch) {
 453         Set<File> singleFile = new LinkedHashSet<>();
 454         singleFile.add(file);
 455         if (baseDir == null) {
 456             baseDir = file.getParentFile();
 457         }
 458         RelativeFileSet rfs = new RelativeFileSet(baseDir, singleFile);
 459         rfs.setArch(arch);
 460         rfs.setMode(mode);
 461         rfs.setOs(os);
 462         rfs.setType(parseTypeFromString(type, file));
 463         resources.add(rfs);
 464     }
 465 
 466     private RelativeFileSet.Type parseTypeFromString(String type, File file) {
 467         if (type == null) {
 468             if (file.getName().endsWith(".jar")) {
 469                 return RelativeFileSet.Type.jar;
 470             } else if (file.getName().endsWith(".jnlp")) {
 471                 return RelativeFileSet.Type.jnlp;
 472             } else {
 473                 return RelativeFileSet.Type.UNKNOWN;
 474             }
 475         } else {
 476             return RelativeFileSet.Type.valueOf(type);
 477         }
 478     }
 479 
 480     private static File createFile(final File baseDir, final String path) {
 481         final File testFile = new File(path);
 482         return testFile.isAbsolute()
 483                 ? testFile
 484                 : new File(baseDir == null
 485                     ? null
 486                     : baseDir.getAbsolutePath(),
 487                       path);
 488     }
 489 
 490 
 491     @Override
 492     public void validate() throws PackagerException {
 493         if (outdir == null) {
 494             throw new PackagerException("ERR_MissingArgument", "-outdir");
 495         }
 496 
 497         if (getBundleType() == BundleType.JNLP && outfile == null) {
 498             throw new PackagerException("ERR_MissingArgument", "-outfile");
 499         }
 500 
 501         if (module == null) {
 502             if (resources.isEmpty()) {
 503                 throw new PackagerException("ERR_MissingAppResources");
 504             }
 505             if (applicationClass == null) {
 506                 throw new PackagerException("ERR_MissingArgument", "-appclass");
 507             }
 508         }
 509     }
 510 
 511     public boolean validateForJNLP() {
 512         boolean result = false;
 513 
 514         // Success
 515         if (applicationClass != null && !applicationClass.isEmpty() &&
 516             (getBundleType() == BundleType.JNLP)) {
 517             result = true;
 518         }
 519 
 520         // Failed
 521         if ((module != null && !module.isEmpty()) ||
 522             (addModules != null && !addModules.isEmpty()) ||
 523             (limitModules != null && !limitModules.isEmpty()) |
 524             (modulePath != null && !modulePath.isEmpty()) ||
 525             getBundleType() == BundleType.INSTALLER ||
 526             getBundleType() == BundleType.NATIVE ||
 527             getBundleType() == BundleType.IMAGE) {
 528 
 529             result = false;
 530         }
 531 
 532         return result;
 533     }
 534 
 535     public boolean validateForBundle() {
 536         boolean result = false;
 537 
 538         // Success
 539         if (((applicationClass != null && !applicationClass.isEmpty()) ||
 540             (module != null && !module.isEmpty()))) {
 541             result = true;
 542         }
 543 
 544         return result;
 545     }
 546 
 547     //could be icon or splash
 548     static class Icon {
 549         final static int UNDEFINED = -1;
 550 
 551         String href;
 552         String kind;
 553         int width = UNDEFINED;
 554         int height = UNDEFINED;
 555         int depth = UNDEFINED;
 556         RunMode mode = RunMode.WEBSTART;
 557 
 558         Icon(String href, String kind, int w, int h, int d, RunMode m) {
 559             mode = m;
 560             this.href = href;
 561             this.kind = kind;
 562             if (w > 0) {
 563                 width = w;
 564             }
 565             if (h > 0) {
 566                 height = h;
 567             }
 568             if (d > 0) {
 569                 depth = d;
 570             }
 571         }
 572     }
 573 
 574     List<Icon> icons = new LinkedList<>();
 575 
 576     public void addIcon(String href, String kind, int w, int h, int d, RunMode m) {
 577         icons.add(new Icon(href, kind, w, h, d, m));
 578     }
 579 
 580     BundleType bundleType = BundleType.NONE;
 581     String targetFormat = null; //means any
 582 
 583     public void setBundleType(BundleType type) {
 584         bundleType = type;
 585     }
 586 
 587     public BundleType getBundleType() {
 588         return bundleType;
 589     }
 590 
 591     public void setTargetFormat(String t) {
 592         targetFormat = t;
 593     }
 594 
 595     public String getTargetFormat() {
 596         return targetFormat;
 597     }
 598 
 599     private String getArch() {
 600         String arch = System.getProperty("os.arch").toLowerCase();
 601 
 602         if ("x86".equals(arch) || "i386".equals(arch) || "i486".equals(arch)
 603                 || "i586".equals(arch) || "i686".equals(arch)) {
 604             arch = "x86";
 605         } else if ("x86_64".equals(arch) || "amd64".equals("arch")) {
 606             arch = "x86_64";
 607         }
 608 
 609         return arch;
 610     }
 611 
 612     static final Set<String> multi_args = new TreeSet<>(Arrays.asList(
 613             StandardBundlerParam.JVM_PROPERTIES.getID(),
 614             StandardBundlerParam.JVM_OPTIONS.getID(),
 615             StandardBundlerParam.USER_JVM_OPTIONS.getID(),
 616             StandardBundlerParam.ARGUMENTS.getID(),
 617             StandardBundlerParam.MODULE_PATH.getID(),
 618             StandardBundlerParam.ADD_MODULES.getID(),
 619             StandardBundlerParam.LIMIT_MODULES.getID(),
 620             StandardBundlerParam.STRIP_NATIVE_COMMANDS.getID(),
 621             JLinkBundlerHelper.DETECT_MODULES.getID()
 622     ));
 623 
 624     @SuppressWarnings("unchecked")
 625     public void addBundleArgument(String key, Object value) {
 626         // special hack for multi-line arguments
 627         if (multi_args.contains(key) && value instanceof String) {
 628             Object existingValue = bundlerArguments.get(key);
 629             if (existingValue instanceof String) {
 630                 bundlerArguments.put(key, existingValue + "\n\n" + value);
 631             } else if (existingValue instanceof List) {
 632                 ((List)existingValue).add(value);
 633             } else if (existingValue instanceof Map && ((String)value).contains("=")) {
 634                 String[] mapValues = ((String)value).split("=", 2);
 635                 ((Map)existingValue).put(mapValues[0], mapValues[1]);
 636             } else {
 637                 bundlerArguments.put(key, value);
 638             }
 639         } else {
 640             bundlerArguments.put(key, value);
 641         }
 642     }
 643 
 644     public BundleParams getBundleParams() {
 645         BundleParams bundleParams = new BundleParams();
 646 
 647         //construct app resources
 648         //  relative to output folder!
 649         String currentOS = System.getProperty("os.name").toLowerCase();
 650         String currentArch = getArch();
 651 
 652         for (RelativeFileSet rfs : resources) {
 653             String os = rfs.getOs();
 654             String arch = rfs.getArch();
 655             //skip resources for other OS
 656             // and nativelib jars (we are including raw libraries)
 657             if ((os == null || currentOS.contains(os.toLowerCase())) &&
 658                     (arch == null || currentArch.startsWith(arch.toLowerCase()))
 659                     && rfs.getType() != RelativeFileSet.Type.nativelib) {
 660                 if (rfs.getType() == RelativeFileSet.Type.license) {
 661                     for (String s : rfs.getIncludedFiles()) {
 662                         bundleParams.addLicenseFile(s);
 663                     }
 664                 }
 665             }
 666         }
 667 
 668         bundleParams.setAppResourcesList(resources);
 669 
 670         bundleParams.setIdentifier(id);
 671 
 672         if (javaRuntimeWasSet) {
 673             bundleParams.setRuntime(javaRuntimeToUse);
 674         }
 675         bundleParams.setApplicationClass(applicationClass);
 676         bundleParams.setPrelaoderClass(preloader);
 677         bundleParams.setName(this.appName);
 678         bundleParams.setAppVersion(version);
 679         bundleParams.setType(bundleType);
 680         bundleParams.setBundleFormat(targetFormat);
 681         bundleParams.setVendor(vendor);
 682         bundleParams.setEmail(email);
 683         bundleParams.setShortcutHint(needShortcut);
 684         bundleParams.setMenuHint(needMenu);
 685         putUnlessNull(INSTALL_HINT.getID(), needInstall);
 686         bundleParams.setSystemWide(systemWide);
 687         bundleParams.setServiceHint(serviceHint);
 688         bundleParams.setInstalldirChooser(installdirChooser);
 689         bundleParams.setSignBundle(signBundle);
 690         bundleParams.setCopyright(copyright);
 691         bundleParams.setApplicationCategory(category);
 692         bundleParams.setLicenseType(licenseType);
 693         bundleParams.setDescription(description);
 694         bundleParams.setTitle(title);
 695         if (verbose) bundleParams.setVerbose(true);
 696 
 697         bundleParams.setJvmProperties(properties);
 698         bundleParams.setJvmargs(jvmargs);
 699         bundleParams.setJvmUserArgs(jvmUserArgs);
 700         bundleParams.setArguments(arguments);
 701 
 702         if (addModules != null && !addModules.isEmpty()) {
 703             bundleParams.setAddModules(addModules);
 704         }
 705 
 706         if (limitModules != null && !limitModules.isEmpty()) {
 707             bundleParams.setLimitModules(limitModules);
 708         }
 709 
 710         if (stripNativeCommands != null) {
 711             bundleParams.setStripNativeCommands(stripNativeCommands);
 712         }
 713 
 714         bundleParams.setSrcDir(srcdir);
 715 
 716         if (modulePath != null && !modulePath.isEmpty()) {
 717             bundleParams.setModulePath(modulePath);
 718         }
 719 
 720         if (module != null && !module.isEmpty()) {
 721             bundleParams.setMainModule(module);
 722         }
 723 
 724         if (debugPort != null && !debugPort.isEmpty()) {
 725             bundleParams.setDebug(debugPort);
 726         }
 727 
 728         if (detectmods != null) {
 729             bundleParams.setDetectMods(detectmods);
 730         }
 731 
 732         File appIcon = null;
 733         List<Map<String, ? super Object>> bundlerIcons = new ArrayList<>();
 734         for (Icon ic: icons) {
 735             //NB: in theory we should be paying attention to RunMode but
 736             // currently everything is marked as webstart internally and runmode
 737             // is not publicly documented property
 738             if (/* (ic.mode == RunMode.ALL || ic.mode == RunMode.STANDALONE) && */
 739                 (ic.kind == null || ic.kind.equals("default")))
 740             {
 741                 //could be full path or something relative to the output folder
 742                 appIcon = new File(ic.href);
 743                 if (!appIcon.exists()) {
 744                     com.oracle.tools.packager.Log.debug("Icon [" + ic.href + "] is not valid absolute path. " +
 745                             "Assume it is relative to the output dir.");
 746                     appIcon = new File(outdir, ic.href);
 747                 }
 748             }
 749 
 750             Map<String, ? super Object> iconInfo = new TreeMap<>();
 751             if (ic.href != null) iconInfo.put(ICONS_HREF.getID(), ic.href);
 752             if (ic.kind != null) iconInfo.put(ICONS_KIND.getID(), ic.kind);
 753             if (ic.width > 0)    iconInfo.put(ICONS_WIDTH.getID(), Integer.toString(ic.width));
 754             if (ic.height > 0)   iconInfo.put(ICONS_HEIGHT.getID(), Integer.toString(ic.height));
 755             if (ic.depth > 0)    iconInfo.put(ICONS_DEPTH.getID(), Integer.toString(ic.depth));
 756 
 757             if (!iconInfo.isEmpty()) bundlerIcons.add(iconInfo);
 758         }
 759         putUnlessNullOrEmpty(ICONS.getID(), bundlerIcons);
 760 
 761         bundleParams.setIcon(appIcon);
 762 
 763         Map<String, String> paramsMap = new TreeMap<>();
 764         if (params != null) {
 765             for (Param p : params) {
 766                 paramsMap.put(p.name, p.value);
 767             }
 768         }
 769         putUnlessNullOrEmpty(JNLPBundler.APP_PARAMS.getID(), paramsMap);
 770 
 771         Map<String, String> unescapedHtmlParams = new TreeMap<>();
 772         Map<String, String> escapedHtmlParams = new TreeMap<>();
 773         if (htmlParams != null) {
 774             for (HtmlParam hp : htmlParams) {
 775                 if (hp.needEscape) {
 776                     escapedHtmlParams.put(hp.name, hp.value);
 777                 } else {
 778                     unescapedHtmlParams.put(hp.name, hp.value);
 779                 }
 780             }
 781         }
 782         putUnlessNullOrEmpty(JNLPBundler.APPLET_PARAMS.getID(), unescapedHtmlParams);
 783         putUnlessNullOrEmpty(ESCAPED_APPLET_PARAMS.getID(), escapedHtmlParams);
 784 
 785 
 786         putUnlessNull(WIDTH.getID(), width);
 787         putUnlessNull(HEIGHT.getID(), height);
 788         putUnlessNull(EMBEDDED_WIDTH.getID(), embeddedWidth);
 789         putUnlessNull(EMBEDDED_HEIGHT.getID(), embeddedHeight);
 790 
 791         putUnlessNull(CODEBASE.getID(), codebase);
 792         putUnlessNull(EMBED_JNLP.getID(), embedJNLP);
 793         // embedCertificates
 794         putUnlessNull(ALL_PERMISSIONS.getID(), allPermissions);
 795         putUnlessNull(UPDATE_MODE.getID(), updateMode);
 796         putUnlessNull(EXTENSION.getID(), isExtension);
 797         putUnlessNull(SWING_APP.getID(), isSwingApp);
 798 
 799         putUnlessNull(OUT_FILE.getID(), outfile);
 800         putUnlessNull(INCLUDE_DT.getID(), includeDT);
 801         putUnlessNull(PLACEHOLDER.getID(), placeholder);
 802         putUnlessNull(OFFLINE_ALLOWED.getID(), offlineAllowed);
 803 
 804         Map<String, String> callbacksMap = new TreeMap<>();
 805         if (callbacks != null) {
 806             for (JSCallback callback : callbacks) {
 807                 callbacksMap.put(callback.getName(), callback.getCmd());
 808             }
 809         }
 810         putUnlessNull(JS_CALLBACKS.getID(), callbacksMap);
 811 
 812         Map<File, File> templatesMap = new TreeMap<>();
 813         if (templates != null) {
 814             for (Template template : templates) {
 815                 templatesMap.put(template.in, template.out);
 816             }
 817         }
 818         putUnlessNull(TEMPLATES.getID(), templatesMap);
 819 
 820         putUnlessNull(FX_PLATFORM.getID(), fxPlatform);
 821         putUnlessNull(JRE_PLATFORM.getID(), jrePlatform);
 822 
 823         putUnlessNull(FALLBACK_APP.getID(), fallbackApp);
 824 
 825         // check for collisions
 826         TreeSet<String> keys = new TreeSet<>(bundlerArguments.keySet());
 827         keys.retainAll(bundleParams.getBundleParamsAsMap().keySet());
 828 
 829         if (!keys.isEmpty()) {
 830             throw new RuntimeException("Deploy Params and Bundler Arguments overlap in the following values:" + keys.toString());
 831         }
 832 
 833         bundleParams.addAllBundleParams(bundlerArguments);
 834 
 835         return bundleParams;
 836     }
 837 
 838     public void putUnlessNull(String param, Object value) {
 839         if (value != null) {
 840             bundlerArguments.put(param, value);
 841         }
 842     }
 843 
 844     public void putUnlessNullOrEmpty(String param, Map<?, ?> value) {
 845         if (value != null && !value.isEmpty()) {
 846             bundlerArguments.put(param, value);
 847         }
 848     }
 849 
 850     public void putUnlessNullOrEmpty(String param, Collection<?> value) {
 851         if (value != null && !value.isEmpty()) {
 852             bundlerArguments.put(param, value);
 853         }
 854     }
 855 }