46 "jdk.jpackage.internal.resources.LinuxResources"); |
46 "jdk.jpackage.internal.resources.LinuxResources"); |
47 |
47 |
48 private static final String LIBRARY_NAME = "libapplauncher.so"; |
48 private static final String LIBRARY_NAME = "libapplauncher.so"; |
49 final static String DEFAULT_ICON = "java32.png"; |
49 final static String DEFAULT_ICON = "java32.png"; |
50 |
50 |
51 private final Path root; |
51 private final ApplicationLayout appLayout; |
52 private final Path appDir; |
|
53 private final Path appModsDir; |
|
54 private final Path runtimeDir; |
|
55 private final Path binDir; |
|
56 private final Path mdir; |
|
57 |
52 |
58 public static final BundlerParamInfo<File> ICON_PNG = |
53 public static final BundlerParamInfo<File> ICON_PNG = |
59 new StandardBundlerParam<>( |
54 new StandardBundlerParam<>( |
60 "icon.png", |
55 "icon.png", |
61 File.class, |
56 File.class, |
68 } |
63 } |
69 return f; |
64 return f; |
70 }, |
65 }, |
71 (s, p) -> new File(s)); |
66 (s, p) -> new File(s)); |
72 |
67 |
|
68 private static ApplicationLayout createAppLayout(Map<String, Object> params, |
|
69 Path imageOutDir) { |
|
70 return ApplicationLayout.linuxApp().resolveAt( |
|
71 imageOutDir.resolve(APP_NAME.fetchFrom(params))); |
|
72 } |
|
73 |
73 public LinuxAppImageBuilder(Map<String, Object> params, Path imageOutDir) |
74 public LinuxAppImageBuilder(Map<String, Object> params, Path imageOutDir) |
74 throws IOException { |
75 throws IOException { |
75 super(params, |
76 super(params, createAppLayout(params, imageOutDir).runtimeDirectory()); |
76 imageOutDir.resolve(APP_NAME.fetchFrom(params) + "/runtime")); |
77 |
77 |
78 appLayout = createAppLayout(params, imageOutDir); |
78 Objects.requireNonNull(imageOutDir); |
|
79 |
|
80 this.root = imageOutDir.resolve(APP_NAME.fetchFrom(params)); |
|
81 this.appDir = root.resolve("app"); |
|
82 this.appModsDir = appDir.resolve("mods"); |
|
83 this.runtimeDir = root.resolve("runtime"); |
|
84 this.binDir = root.resolve("bin"); |
|
85 this.mdir = runtimeDir.resolve("lib"); |
|
86 Files.createDirectories(appDir); |
|
87 Files.createDirectories(runtimeDir); |
|
88 } |
|
89 |
|
90 public LinuxAppImageBuilder(String appName, Path imageOutDir) |
|
91 throws IOException { |
|
92 super(null, imageOutDir.resolve(appName)); |
|
93 |
|
94 Objects.requireNonNull(imageOutDir); |
|
95 |
|
96 this.root = imageOutDir.resolve(appName); |
|
97 this.appDir = null; |
|
98 this.appModsDir = null; |
|
99 this.runtimeDir = null; |
|
100 this.binDir = null; |
|
101 this.mdir = null; |
|
102 } |
79 } |
103 |
80 |
104 private void writeEntry(InputStream in, Path dstFile) throws IOException { |
81 private void writeEntry(InputStream in, Path dstFile) throws IOException { |
105 Files.createDirectories(dstFile.getParent()); |
82 Files.createDirectories(dstFile.getParent()); |
106 Files.copy(in, dstFile); |
83 Files.copy(in, dstFile); |
108 |
85 |
109 public static String getLauncherName(Map<String, ? super Object> params) { |
86 public static String getLauncherName(Map<String, ? super Object> params) { |
110 return APP_NAME.fetchFrom(params); |
87 return APP_NAME.fetchFrom(params); |
111 } |
88 } |
112 |
89 |
113 public static String getLauncherCfgName( |
90 private Path getLauncherCfgPath(Map<String, ? super Object> params) { |
114 Map<String, ? super Object> params) { |
91 return appLayout.appDirectory().resolve( |
115 return "app" + File.separator + APP_NAME.fetchFrom(params) + ".cfg"; |
92 APP_NAME.fetchFrom(params) + ".cfg"); |
116 } |
93 } |
117 |
94 |
118 @Override |
95 @Override |
119 public Path getAppDir() { |
96 public Path getAppDir() { |
120 return appDir; |
97 return appLayout.appDirectory(); |
121 } |
98 } |
122 |
99 |
123 @Override |
100 @Override |
124 public Path getAppModsDir() { |
101 public Path getAppModsDir() { |
125 return appModsDir; |
102 return appLayout.appModsDirectory(); |
|
103 } |
|
104 |
|
105 @Override |
|
106 protected String getCfgAppDir() { |
|
107 return Path.of("$APPDIR").resolve( |
|
108 ApplicationLayout.linuxApp().appDirectory()).toString() + File.separator; |
|
109 } |
|
110 |
|
111 @Override |
|
112 protected String getCfgRuntimeDir() { |
|
113 return Path.of("$APPDIR").resolve( |
|
114 ApplicationLayout.linuxApp().runtimeDirectory()).toString(); |
126 } |
115 } |
127 |
116 |
128 @Override |
117 @Override |
129 public void prepareApplicationFiles(Map<String, ? super Object> params) |
118 public void prepareApplicationFiles(Map<String, ? super Object> params) |
130 throws IOException { |
119 throws IOException { |
131 Map<String, ? super Object> originalParams = new HashMap<>(params); |
120 Map<String, ? super Object> originalParams = new HashMap<>(params); |
132 |
121 |
133 try { |
122 appLayout.roots().stream().forEach(dir -> { |
134 IOUtils.writableOutputDir(root); |
123 try { |
135 IOUtils.writableOutputDir(binDir); |
124 IOUtils.writableOutputDir(dir); |
136 } catch (PackagerException pe) { |
125 } catch (PackagerException pe) { |
137 throw new RuntimeException(pe); |
126 throw new RuntimeException(pe); |
138 } |
127 } |
|
128 }); |
139 |
129 |
140 // create the primary launcher |
130 // create the primary launcher |
141 createLauncherForEntryPoint(params); |
131 createLauncherForEntryPoint(params); |
142 |
132 |
143 // Copy library to the launcher folder |
133 // Copy library to the launcher folder |
144 try (InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) { |
134 try (InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) { |
145 writeEntry(is_lib, binDir.resolve(LIBRARY_NAME)); |
135 writeEntry(is_lib, appLayout.dllDirectory().resolve(LIBRARY_NAME)); |
146 } |
136 } |
147 |
137 |
148 // create the additional launchers, if any |
138 // create the additional launchers, if any |
149 List<Map<String, ? super Object>> entryPoints |
139 List<Map<String, ? super Object>> entryPoints |
150 = StandardBundlerParam.ADD_LAUNCHERS.fetchFrom(params); |
140 = StandardBundlerParam.ADD_LAUNCHERS.fetchFrom(params); |
164 public void prepareJreFiles(Map<String, ? super Object> params) |
154 public void prepareJreFiles(Map<String, ? super Object> params) |
165 throws IOException {} |
155 throws IOException {} |
166 |
156 |
167 private void createLauncherForEntryPoint( |
157 private void createLauncherForEntryPoint( |
168 Map<String, ? super Object> params) throws IOException { |
158 Map<String, ? super Object> params) throws IOException { |
169 // Copy executable to Linux folder |
159 // Copy executable to launchers folder |
170 Path executableFile = binDir.resolve(getLauncherName(params)); |
160 Path executableFile = appLayout.launchersDirectory().resolve(getLauncherName(params)); |
171 try (InputStream is_launcher = |
161 try (InputStream is_launcher = |
172 getResourceAsStream("jpackageapplauncher")) { |
162 getResourceAsStream("jpackageapplauncher")) { |
173 writeEntry(is_launcher, executableFile); |
163 writeEntry(is_launcher, executableFile); |
174 } |
164 } |
175 |
165 |
176 executableFile.toFile().setExecutable(true, false); |
166 executableFile.toFile().setExecutable(true, false); |
177 executableFile.toFile().setWritable(true, true); |
167 executableFile.toFile().setWritable(true, true); |
178 |
168 |
179 writeCfgFile(params, root.resolve(getLauncherCfgName(params)).toFile()); |
169 writeCfgFile(params, getLauncherCfgPath(params).toFile()); |
180 } |
170 } |
181 |
171 |
182 private void copyIcon(Map<String, ? super Object> params) |
172 private void copyIcon(Map<String, ? super Object> params) |
183 throws IOException { |
173 throws IOException { |
184 |
174 |
185 File icon = ICON_PNG.fetchFrom(params); |
175 File icon = ICON_PNG.fetchFrom(params); |
186 File iconTarget = binDir.resolve(APP_NAME.fetchFrom(params) + ".png").toFile(); |
176 File iconTarget = appLayout.destktopIntegrationDirectory().resolve( |
|
177 APP_NAME.fetchFrom(params) + ".png").toFile(); |
187 |
178 |
188 InputStream in = locateResource( |
179 InputStream in = locateResource( |
189 iconTarget.getName(), |
180 iconTarget.getName(), |
190 "icon", |
181 "icon", |
191 DEFAULT_ICON, |
182 DEFAULT_ICON, |
203 if (appResources == null) { |
194 if (appResources == null) { |
204 throw new RuntimeException("Null app resources?"); |
195 throw new RuntimeException("Null app resources?"); |
205 } |
196 } |
206 File srcdir = appResources.getBaseDirectory(); |
197 File srcdir = appResources.getBaseDirectory(); |
207 for (String fname : appResources.getIncludedFiles()) { |
198 for (String fname : appResources.getIncludedFiles()) { |
208 copyEntry(appDir, srcdir, fname); |
199 copyEntry(appLayout.appDirectory(), srcdir, fname); |
209 } |
200 } |
210 } |
201 } |
211 } |
202 } |
212 |
203 |
213 } |
204 } |