50 import java.util.Map; 51 import java.util.Objects; 52 import java.util.ResourceBundle; 53 import java.util.Set; 54 55 import static com.oracle.tools.packager.StandardBundlerParam.*; 56 57 /** 58 * 59 */ 60 public class LinuxAppImageBuilder extends AbstractAppImageBuilder { 61 62 private static final ResourceBundle I18N = 63 ResourceBundle.getBundle(LinuxAppImageBuilder.class.getName()); 64 65 protected static final String LINUX_BUNDLER_PREFIX = 66 BUNDLER_PREFIX + "linux" + File.separator; 67 private static final String EXECUTABLE_NAME = "JavaAppLauncher"; 68 private static final String LIBRARY_NAME = "libpackager.so"; 69 70 public static final BundlerParamInfo<File> ICON_PNG = new StandardBundlerParam<>( 71 I18N.getString("param.icon-png.name"), 72 I18N.getString("param.icon-png.description"), 73 "icon.png", 74 File.class, 75 params -> { 76 File f = ICON.fetchFrom(params); 77 if (f != null && !f.getName().toLowerCase().endsWith(".png")) { 78 Log.info(MessageFormat.format(I18N.getString("message.icon-not-png"), f)); 79 return null; 80 } 81 return f; 82 }, 83 (s, p) -> new File(s)); 84 85 // public static final BundlerParamInfo<URL> RAW_EXECUTABLE_URL = new StandardBundlerParam<>( 86 // I18N.getString("param.raw-executable-url.name"), 87 // I18N.getString("param.raw-executable-url.description"), 88 // "linux.launcher.url", 89 // URL.class, 90 // params -> LinuxResources.class.getResource(EXECUTABLE_NAME), 91 // (s, p) -> { 92 // try { 93 // return new URL(s); 94 // } catch (MalformedURLException e) { 95 // Log.info(e.toString()); 96 // return null; 97 // } 98 // }); 99 // 100 101 private final Path root; 102 private final Path appDir; 103 private final Path runtimeRoot; 104 private final Path mdir; 105 private final String jimage; 106 107 private final Map<String, ? super Object> params; 108 109 public LinuxAppImageBuilder(Map<String, Object> config, Path imageOutDir) throws IOException { 110 super(config, imageOutDir.resolve(APP_NAME.fetchFrom(config) + "/runtime")); 111 112 Objects.requireNonNull(imageOutDir); 113 114 @SuppressWarnings("unchecked") 115 String img = (String) config.get("jimage.name"); // FIXME constant 116 jimage = img == null ? "bootmodules.jimage" : img; //FIXME constant 117 118 this.root = imageOutDir.resolve(APP_NAME.fetchFrom(config)); 119 this.appDir = root.resolve("app"); 120 this.runtimeRoot = root.resolve("runtime"); 121 this.mdir = runtimeRoot.resolve("lib").resolve("modules"); 122 this.params = new HashMap<String, Object>(); 123 config.entrySet().stream().forEach(e -> params.put(e.getKey().toString(), e.getValue())); 124 Files.createDirectories(mdir); 125 Files.createDirectories(appDir); 126 } 127 128 private Path destFile(String dir, String filename) { 129 return runtimeRoot.resolve(dir).resolve(filename); 130 } 131 132 private void writeEntry(InputStream in, Path dstFile) throws IOException { 133 Files.createDirectories(dstFile.getParent()); 134 Files.copy(in, dstFile); 135 } 136 137 private void writeSymEntry(Path dstFile, Path target) throws IOException { 138 Files.createDirectories(dstFile.getParent()); 139 Files.createLink(dstFile, target); 140 } 141 142 /** 143 * chmod ugo+x file 144 */ | 50 import java.util.Map; 51 import java.util.Objects; 52 import java.util.ResourceBundle; 53 import java.util.Set; 54 55 import static com.oracle.tools.packager.StandardBundlerParam.*; 56 57 /** 58 * 59 */ 60 public class LinuxAppImageBuilder extends AbstractAppImageBuilder { 61 62 private static final ResourceBundle I18N = 63 ResourceBundle.getBundle(LinuxAppImageBuilder.class.getName()); 64 65 protected static final String LINUX_BUNDLER_PREFIX = 66 BUNDLER_PREFIX + "linux" + File.separator; 67 private static final String EXECUTABLE_NAME = "JavaAppLauncher"; 68 private static final String LIBRARY_NAME = "libpackager.so"; 69 70 private final Path root; 71 private final Path appDir; 72 private final Path runtimeRoot; 73 private final Path mdir; 74 75 private final Map<String, ? super Object> params; 76 77 public static final BundlerParamInfo<File> ICON_PNG = new StandardBundlerParam<>( 78 I18N.getString("param.icon-png.name"), 79 I18N.getString("param.icon-png.description"), 80 "icon.png", 81 File.class, 82 params -> { 83 File f = ICON.fetchFrom(params); 84 if (f != null && !f.getName().toLowerCase().endsWith(".png")) { 85 Log.info(MessageFormat.format(I18N.getString("message.icon-not-png"), f)); 86 return null; 87 } 88 return f; 89 }, 90 (s, p) -> new File(s)); 91 92 // public static final BundlerParamInfo<URL> RAW_EXECUTABLE_URL = new StandardBundlerParam<>( 93 // I18N.getString("param.raw-executable-url.name"), 94 // I18N.getString("param.raw-executable-url.description"), 95 // "linux.launcher.url", 96 // URL.class, 97 // params -> LinuxResources.class.getResource(EXECUTABLE_NAME), 98 // (s, p) -> { 99 // try { 100 // return new URL(s); 101 // } catch (MalformedURLException e) { 102 // Log.info(e.toString()); 103 // return null; 104 // } 105 // }); 106 // 107 108 public LinuxAppImageBuilder(Map<String, Object> config, Path imageOutDir) throws IOException { 109 super(config, imageOutDir.resolve(APP_NAME.fetchFrom(config) + "/runtime")); 110 111 Objects.requireNonNull(imageOutDir); 112 113 //@SuppressWarnings("unchecked") 114 //String img = (String) config.get("jimage.name"); // FIXME constant 115 116 this.root = imageOutDir.resolve(APP_NAME.fetchFrom(config)); 117 this.appDir = root.resolve("app"); 118 this.runtimeRoot = root.resolve("runtime"); 119 this.mdir = runtimeRoot.resolve("lib"); 120 this.params = new HashMap<String, Object>(); 121 config.entrySet().stream().forEach(e -> params.put(e.getKey().toString(), e.getValue())); 122 Files.createDirectories(appDir); 123 } 124 125 private Path destFile(String dir, String filename) { 126 return runtimeRoot.resolve(dir).resolve(filename); 127 } 128 129 private void writeEntry(InputStream in, Path dstFile) throws IOException { 130 Files.createDirectories(dstFile.getParent()); 131 Files.copy(in, dstFile); 132 } 133 134 private void writeSymEntry(Path dstFile, Path target) throws IOException { 135 Files.createDirectories(dstFile.getParent()); 136 Files.createLink(dstFile, target); 137 } 138 139 /** 140 * chmod ugo+x file 141 */ |