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