1 /* 2 * Copyright (c) 2014, 2018, 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.packager.internal.windows; 27 28 import jdk.packager.internal.BundlerParamInfo; 29 import jdk.packager.internal.StandardBundlerParam; 30 import jdk.packager.internal.Arguments; 31 import jdk.packager.internal.RelativeFileSet; 32 import jdk.packager.internal.bundlers.BundleParams; 33 34 import java.util.Map; 35 import java.util.ResourceBundle; 36 import java.util.function.BiFunction; 37 import java.util.function.Function; 38 39 public class WindowsBundlerParam<T> extends StandardBundlerParam<T> { 40 41 private static final ResourceBundle I18N = ResourceBundle.getBundle( 42 "jdk.packager.internal.resources.windows.WindowsBundlerParam"); 43 44 public WindowsBundlerParam(String name, String description, String id, 45 Class<T> valueType, 46 Function<Map<String, ? super Object>, T> defaultValueFunction, 47 BiFunction<String, 48 Map<String, ? super Object>, T> stringConverter) { 49 super(name, description, id, valueType, 50 defaultValueFunction, stringConverter); 51 } 52 53 public static final BundlerParamInfo<String> INSTALLER_FILE_NAME = 54 new StandardBundlerParam<> ( 55 I18N.getString("param.installer-name.name"), 56 I18N.getString("param.installer-name.description"), 57 "win.installerName", 58 String.class, 59 params -> { 60 String nm = APP_NAME.fetchFrom(params); 61 if (nm == null) return null; 62 63 String version = VERSION.fetchFrom(params); 64 if (version == null) { 65 return nm; 66 } else { 67 return nm + "-" + version; 68 } 69 }, 70 (s, p) -> s); 71 72 public static final BundlerParamInfo<String> APP_REGISTRY_NAME = 73 new StandardBundlerParam<> ( 74 I18N.getString("param.registry-name.name"), 75 I18N.getString("param.registry-name.description"), 76 Arguments.CLIOptions.WIN_REGISTRY_NAME.getId(), 77 String.class, 78 params -> { 79 String nm = APP_NAME.fetchFrom(params); 80 if (nm == null) return null; 81 82 return nm.replaceAll("[^-a-zA-Z\\.0-9]", ""); 83 }, 84 (s, p) -> s); 85 86 public static final StandardBundlerParam<String> MENU_GROUP = 87 new StandardBundlerParam<>( 88 I18N.getString("param.menu-group.name"), 89 I18N.getString("param.menu-group.description"), 90 Arguments.CLIOptions.WIN_MENU_GROUP.getId(), 91 String.class, 92 params -> params.containsKey(VENDOR.getID()) 93 ? VENDOR.fetchFrom(params) 94 : params.containsKey(CATEGORY.getID()) 95 ? CATEGORY.fetchFrom(params) 96 : I18N.getString("param.menu-group.default"), 97 (s, p) -> s 98 ); 99 100 public static final StandardBundlerParam<Boolean> BIT_ARCH_64 = 101 new StandardBundlerParam<>( 102 I18N.getString("param.64-bit.name"), 103 I18N.getString("param.64-bit.description"), 104 "win.64Bit", 105 Boolean.class, 106 params -> System.getProperty("os.arch").contains("64"), 107 (s, p) -> Boolean.valueOf(s) 108 ); 109 110 public static final StandardBundlerParam<Boolean> BIT_ARCH_64_RUNTIME = 111 new StandardBundlerParam<>( 112 I18N.getString("param.runtime-64-bit.name"), 113 I18N.getString("param.runtime-64-bit.description"), 114 "win.64BitJreRuntime", 115 Boolean.class, 116 params -> { 117 WinAppBundler.extractFlagsFromRuntime(params); 118 return "64".equals(params.get(".runtime.bit-arch")); 119 }, 120 (s, p) -> Boolean.valueOf(s) 121 ); 122 123 public static final BundlerParamInfo<Boolean> INSTALLDIR_CHOOSER = 124 new StandardBundlerParam<> ( 125 I18N.getString("param.installdir-chooser.name"), 126 I18N.getString("param.installdir-chooser.description"), 127 Arguments.CLIOptions.WIN_DIR_CHOOSER.getId(), 128 Boolean.class, 129 params -> Boolean.FALSE, 130 (s, p) -> Boolean.valueOf(s) 131 ); 132 }