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.ByteArrayOutputStream; 29 import java.io.File; 30 import java.io.FileInputStream; 31 import java.io.IOException; 32 import java.io.InputStream; 33 import java.io.PrintStream; 34 import java.nio.file.Files; 35 import java.nio.file.Path; 36 import java.text.MessageFormat; 37 import java.util.List; 38 import java.util.Map; 39 import java.util.ResourceBundle; 40 import java.util.ArrayList; 41 42 import jdk.incubator.jpackage.internal.resources.ResourceLocator; 43 44 import static jdk.incubator.jpackage.internal.StandardBundlerParam.*; 45 46 /* 47 * AbstractAppImageBuilder 48 * This is sub-classed by each of the platform dependent AppImageBuilder 49 * classes, and contains resource processing code common to all platforms. 50 */ 51 52 public abstract class AbstractAppImageBuilder { 53 54 private static final ResourceBundle I18N = ResourceBundle.getBundle( 55 "jdk.incubator.jpackage.internal.resources.MainResources"); 56 57 private final Path root; 58 59 public AbstractAppImageBuilder(Map<String, Object> unused, Path root) { 60 this.root = root; 61 } 62 63 public InputStream getResourceAsStream(String name) { 64 return ResourceLocator.class.getResourceAsStream(name); 170 171 protected String getCfgRuntimeDir() { 172 return "$ROOTDIR" + File.separator + "runtime"; 173 } 174 175 String getCfgClassPath(String classpath) { 176 String cfgAppDir = getCfgAppDir(); 177 178 StringBuilder sb = new StringBuilder(); 179 for (String path : classpath.split("[:;]")) { 180 if (path.length() > 0) { 181 sb.append(cfgAppDir); 182 sb.append(path); 183 sb.append(File.pathSeparator); 184 } 185 } 186 if (sb.length() > 0) { 187 sb.deleteCharAt(sb.length() - 1); 188 } 189 return sb.toString(); 190 } 191 } | 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.io.InputStream; 31 import java.io.PrintStream; 32 import java.nio.file.Files; 33 import java.nio.file.Path; 34 import java.util.HashMap; 35 import java.util.List; 36 import java.util.Map; 37 import java.util.ResourceBundle; 38 import static jdk.incubator.jpackage.internal.OverridableResource.createResource; 39 import static jdk.incubator.jpackage.internal.StandardBundlerParam.*; 40 41 import jdk.incubator.jpackage.internal.resources.ResourceLocator; 42 43 44 /* 45 * AbstractAppImageBuilder 46 * This is sub-classed by each of the platform dependent AppImageBuilder 47 * classes, and contains resource processing code common to all platforms. 48 */ 49 50 public abstract class AbstractAppImageBuilder { 51 52 private static final ResourceBundle I18N = ResourceBundle.getBundle( 53 "jdk.incubator.jpackage.internal.resources.MainResources"); 54 55 private final Path root; 56 57 public AbstractAppImageBuilder(Map<String, Object> unused, Path root) { 58 this.root = root; 59 } 60 61 public InputStream getResourceAsStream(String name) { 62 return ResourceLocator.class.getResourceAsStream(name); 168 169 protected String getCfgRuntimeDir() { 170 return "$ROOTDIR" + File.separator + "runtime"; 171 } 172 173 String getCfgClassPath(String classpath) { 174 String cfgAppDir = getCfgAppDir(); 175 176 StringBuilder sb = new StringBuilder(); 177 for (String path : classpath.split("[:;]")) { 178 if (path.length() > 0) { 179 sb.append(cfgAppDir); 180 sb.append(path); 181 sb.append(File.pathSeparator); 182 } 183 } 184 if (sb.length() > 0) { 185 sb.deleteCharAt(sb.length() - 1); 186 } 187 return sb.toString(); 188 } 189 190 public static OverridableResource createIconResource(String defaultIconName, 191 BundlerParamInfo<File> iconParam, Map<String, ? super Object> params, 192 Map<String, ? super Object> mainParams) throws IOException { 193 194 if (mainParams != null) { 195 params = AddLauncherArguments.merge(mainParams, params, ICON.getID(), 196 iconParam.getID()); 197 } 198 199 final String resourcePublicName = APP_NAME.fetchFrom(params) 200 + IOUtils.getSuffix(Path.of(defaultIconName)); 201 202 IconType iconType = getLauncherIconType(params); 203 if (iconType == IconType.NoIcon) { 204 return null; 205 } 206 207 OverridableResource resource = createResource(defaultIconName, params) 208 .setCategory("icon") 209 .setExternal(iconParam.fetchFrom(params)) 210 .setPublicName(resourcePublicName); 211 212 if (iconType == IconType.DefaultOrResourceDirIcon && mainParams != null) { 213 // No icon explicitly configured for this launcher. 214 // Dry-run resource creation to figure out its source. 215 final Path nullPath = null; 216 if (resource.saveToFile(nullPath) 217 != OverridableResource.Source.ResourceDir) { 218 // No icon in resource dir for this launcher, inherit icon 219 // configured for the main launcher. 220 resource = createIconResource(defaultIconName, iconParam, 221 mainParams, null).setLogPublicName(resourcePublicName); 222 } 223 } 224 225 return resource; 226 } 227 228 private enum IconType { DefaultOrResourceDirIcon, CustomIcon, NoIcon }; 229 230 private static IconType getLauncherIconType(Map<String, ? super Object> params) { 231 File launcherIcon = ICON.fetchFrom(params); 232 if (launcherIcon == null) { 233 return IconType.DefaultOrResourceDirIcon; 234 } 235 236 if (launcherIcon.getName().isEmpty()) { 237 return IconType.NoIcon; 238 } 239 240 return IconType.CustomIcon; 241 } 242 } |