109 imageBundleValidation(p);
110
111 if (WinResources.class.getResource(TOOL_ICON_SWAP) == null) {
112 throw new ConfigException(
113 I18N.getString("error.no-windows-resources"),
114 I18N.getString("error.no-windows-resources.advice"));
115 }
116
117 //validate runtime bit-architectire
118 testRuntimeBitArchitecture(p);
119
120 return true;
121 }
122
123 private static void testRuntimeBitArchitecture(Map<String, ? super Object> params) throws ConfigException {
124 if ("true".equalsIgnoreCase(System.getProperty("fxpackager.disableBitArchitectureMismatchCheck"))) {
125 Log.debug(I18N.getString("message.disable-bit-architecture-check"));
126 return;
127 }
128
129 if ((BIT_ARCH_64.fetchFrom(params) != BIT_ARCH_64_RUNTIME.fetchFrom(params)) && !"systemjre".equals(params.get(".runtime.autodetect"))) {
130 throw new ConfigException(
131 I18N.getString("error.bit-architecture-mismatch"),
132 I18N.getString("error.bit-architecture-mismatch.advice"));
133 }
134 }
135
136 //it is static for the sake of sharing with "Exe" bundles
137 // that may skip calls to validate/bundle in this class!
138 private static File getRootDir(File outDir, Map<String, ? super Object> p) {
139 return new File(outDir, APP_NAME.fetchFrom(p));
140 }
141
142 public static String getLauncherName(Map<String, ? super Object> p) {
143 return APP_NAME.fetchFrom(p) +".exe";
144 }
145
146 public static String getLauncherCfgName(Map<String, ? super Object> p) {
147 return "app\\" + APP_NAME.fetchFrom(p) +".cfg";
148 }
149
174
175 AbstractAppImageBuilder appBuilder = new WindowsAppImageBuilder(p, outputDirectory.toPath());
176 JLinkBundlerHelper.execute(p, appBuilder);
177
178 if (!dependentTask) {
179 Log.info(MessageFormat.format(I18N.getString("message.result-dir"), outputDirectory.getAbsolutePath()));
180 }
181
182 return rootDirectory;
183 } catch (IOException ex) {
184 Log.info(ex.toString());
185 Log.verbose(ex);
186 return null;
187 } catch (Exception ex) {
188 Log.info("Exception: "+ex);
189 Log.debug(ex);
190 return null;
191 }
192 }
193
194
195 public static void extractFlagsFromRuntime(Map<String, ? super Object> params) {
196 if (params.containsKey(".runtime.autodetect")) return;
197
198 params.put(".runtime.autodetect", "attempted");
199 RelativeFileSet runtime = WIN_RUNTIME.fetchFrom(params);
200 String commandline;
201 if (runtime == null) {
202 //System JRE, report nothing useful
203 params.put(".runtime.autodetect", "systemjre");
204 } else {
205 File runtimePath = runtime.getBaseDirectory();
206 File launcherPath = new File(runtimePath, "bin\\java");
207
208 ProcessBuilder pb = new ProcessBuilder(launcherPath.getAbsolutePath(), "-version");
209 try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
210 try (PrintStream pout = new PrintStream(baos)) {
211 IOUtils.exec(pb, Log.isDebug(), true, pout);
212 }
213
214 commandline = baos.toString();
215 } catch (IOException e) {
216 e.printStackTrace();
217 params.put(".runtime.autodetect", "failed");
218 return;
219 }
220 AbstractImageBundler.extractFlagsFromVersion(params, commandline);
221 params.put(".runtime.autodetect", "succeeded");
222 }
223 }
224
225
226 @Override
227 public String getName() {
228 return I18N.getString("bundler.name");
229 }
230
231 @Override
232 public String getDescription() {
233 return I18N.getString("bundler.description");
234 }
235
236 @Override
237 public String getID() {
238 return "windows.app";
239 }
240
241 @Override
242 public String getBundleType() {
243 return "IMAGE";
244 }
|
109 imageBundleValidation(p);
110
111 if (WinResources.class.getResource(TOOL_ICON_SWAP) == null) {
112 throw new ConfigException(
113 I18N.getString("error.no-windows-resources"),
114 I18N.getString("error.no-windows-resources.advice"));
115 }
116
117 //validate runtime bit-architectire
118 testRuntimeBitArchitecture(p);
119
120 return true;
121 }
122
123 private static void testRuntimeBitArchitecture(Map<String, ? super Object> params) throws ConfigException {
124 if ("true".equalsIgnoreCase(System.getProperty("fxpackager.disableBitArchitectureMismatchCheck"))) {
125 Log.debug(I18N.getString("message.disable-bit-architecture-check"));
126 return;
127 }
128
129 if ((BIT_ARCH_64.fetchFrom(params) != BIT_ARCH_64_RUNTIME.fetchFrom(params))) {
130 throw new ConfigException(
131 I18N.getString("error.bit-architecture-mismatch"),
132 I18N.getString("error.bit-architecture-mismatch.advice"));
133 }
134 }
135
136 //it is static for the sake of sharing with "Exe" bundles
137 // that may skip calls to validate/bundle in this class!
138 private static File getRootDir(File outDir, Map<String, ? super Object> p) {
139 return new File(outDir, APP_NAME.fetchFrom(p));
140 }
141
142 public static String getLauncherName(Map<String, ? super Object> p) {
143 return APP_NAME.fetchFrom(p) +".exe";
144 }
145
146 public static String getLauncherCfgName(Map<String, ? super Object> p) {
147 return "app\\" + APP_NAME.fetchFrom(p) +".cfg";
148 }
149
174
175 AbstractAppImageBuilder appBuilder = new WindowsAppImageBuilder(p, outputDirectory.toPath());
176 JLinkBundlerHelper.execute(p, appBuilder);
177
178 if (!dependentTask) {
179 Log.info(MessageFormat.format(I18N.getString("message.result-dir"), outputDirectory.getAbsolutePath()));
180 }
181
182 return rootDirectory;
183 } catch (IOException ex) {
184 Log.info(ex.toString());
185 Log.verbose(ex);
186 return null;
187 } catch (Exception ex) {
188 Log.info("Exception: "+ex);
189 Log.debug(ex);
190 return null;
191 }
192 }
193
194 private static final String RUNTIME_AUTO_DETECT = ".runtime.autodetect";
195
196 public static void extractFlagsFromRuntime(Map<String, ? super Object> params) {
197 if (params.containsKey(".runtime.autodetect")) return;
198
199 params.put(RUNTIME_AUTO_DETECT, "attempted");
200
201 String commandline;
202 File runtimePath = JLinkBundlerHelper.getJDKHome(params).toFile();
203 File launcherPath = new File(runtimePath, "bin\\java");
204
205 ProcessBuilder pb = new ProcessBuilder(launcherPath.getAbsolutePath(), "-version");
206 try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
207 try (PrintStream pout = new PrintStream(baos)) {
208 IOUtils.exec(pb, Log.isDebug(), true, pout);
209 }
210
211 commandline = baos.toString();
212 } catch (IOException e) {
213 e.printStackTrace();
214 params.put(RUNTIME_AUTO_DETECT, "failed");
215 return;
216 }
217
218 AbstractImageBundler.extractFlagsFromVersion(params, commandline);
219 params.put(RUNTIME_AUTO_DETECT, "succeeded");
220 }
221
222 @Override
223 public String getName() {
224 return I18N.getString("bundler.name");
225 }
226
227 @Override
228 public String getDescription() {
229 return I18N.getString("bundler.description");
230 }
231
232 @Override
233 public String getID() {
234 return "windows.app";
235 }
236
237 @Override
238 public String getBundleType() {
239 return "IMAGE";
240 }
|