1 /*
   2  * Copyright (c) 2012, 2019, 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 jdk.incubator.jpackage.internal;
  27 
  28 import java.io.File;
  29 import java.io.IOException;
  30 import java.util.*;
  31 import java.util.jar.Attributes;
  32 import java.util.jar.JarFile;
  33 import java.util.jar.Manifest;
  34 
  35 import static jdk.incubator.jpackage.internal.StandardBundlerParam.*;
  36 
  37 public class BundleParams {
  38 
  39     final protected Map<String, ? super Object> params;
  40 
  41     // RelativeFileSet
  42     public static final String PARAM_APP_RESOURCES      = "appResources";
  43 
  44     // String - Icon file name
  45     public static final String PARAM_ICON               = "icon";
  46 
  47     // String - Name of bundle file and native launcher
  48     public static final String PARAM_NAME               = "name";
  49 
  50     // String - application vendor, used by most of the bundlers
  51     public static final String PARAM_VENDOR             = "vendor";
  52 
  53     // String - email name and email, only used for debian */
  54     public static final String PARAM_EMAIL              = "email";
  55 
  56     // String - vendor <email>, only used for debian */
  57     public static final String PARAM_MAINTAINER         = "maintainer";
  58 
  59     /* String - Copyright. Used on Mac */
  60     public static final String PARAM_COPYRIGHT          = "copyright";
  61 
  62     // String - GUID on windows for MSI, CFBundleIdentifier on Mac
  63     // If not compatible with requirements then bundler either do not bundle
  64     // or autogenerate
  65     public static final String PARAM_IDENTIFIER         = "identifier";
  66 
  67     /* boolean - shortcut preferences */
  68     public static final String PARAM_SHORTCUT           = "shortcutHint";
  69     // boolean - menu shortcut preference
  70     public static final String PARAM_MENU               = "menuHint";
  71 
  72     // String - Application version. Format may differ for different bundlers
  73     public static final String PARAM_VERSION            = "appVersion";
  74 
  75     // String - Application release. Used on Linux.
  76     public static final String PARAM_RELEASE            = "appRelease";
  77 
  78     // String - Optional application description. Used by MSI and on Linux
  79     public static final String PARAM_DESCRIPTION        = "description";
  80 
  81     // String - License type. Needed on Linux (rpm)
  82     public static final String PARAM_LICENSE_TYPE       = "licenseType";
  83 
  84     // String - File with license. Format is OS/bundler specific
  85     public static final String PARAM_LICENSE_FILE       = "licenseFile";
  86 
  87     // String Main application class.
  88     // Not used directly but used to derive default values
  89     public static final String PARAM_APPLICATION_CLASS  = "applicationClass";
  90 
  91     // boolean - Adds a dialog to let the user choose a directory
  92     // where the product will be installed.
  93     public static final String PARAM_INSTALLDIR_CHOOSER = "installdirChooser";
  94 
  95     /**
  96      * create a new bundle with all default values
  97      */
  98     public BundleParams() {
  99         params = new HashMap<>();
 100     }
 101 
 102     /**
 103      * Create a bundle params with a copy of the params
 104      * @param params map of initial parameters to be copied in.
 105      */
 106     public BundleParams(Map<String, ?> params) {
 107         this.params = new HashMap<>(params);
 108     }
 109 
 110     public void addAllBundleParams(Map<String, ? super Object> params) {
 111         this.params.putAll(params);
 112     }
 113 
 114     // NOTE: we do not care about application parameters here
 115     // as they will be embeded into jar file manifest and
 116     // java launcher will take care of them!
 117 
 118     public Map<String, ? super Object> getBundleParamsAsMap() {
 119         return new HashMap<>(params);
 120     }
 121 
 122     public String getName() {
 123         return APP_NAME.fetchFrom(params);
 124     }
 125 
 126     public void setAppResourcesList(
 127             List<jdk.incubator.jpackage.internal.RelativeFileSet> rfs) {
 128         putUnlessNull(APP_RESOURCES_LIST.getID(), rfs);
 129     }
 130 
 131     private void putUnlessNull(String param, Object value) {
 132         if (value != null) {
 133             params.put(param, value);
 134         }
 135     }
 136 }