6
6
import ca .weblite .jdeploy .installer .npm .NPMPackage ;
7
7
import ca .weblite .jdeploy .installer .npm .NPMPackageVersion ;
8
8
import ca .weblite .jdeploy .installer .npm .NPMRegistry ;
9
- import ca .weblite .tools .io .ArchiveUtil ;
10
- import ca .weblite .tools .io .FileUtil ;
11
- import ca .weblite .tools .io .IOUtil ;
12
- import ca .weblite .tools .io .URLUtil ;
9
+ import ca .weblite .tools .io .*;
13
10
import ca .weblite .tools .platform .Platform ;
14
11
import com .izforge .izpack .util .os .ShellLink ;
15
12
import net .coobird .thumbnailator .Thumbnails ;
@@ -304,6 +301,23 @@ private File findAppBundle() {
304
301
return start ;
305
302
}
306
303
304
+ private static File findBundleAppXml (File appBundle ) {
305
+ return new File (appBundle , "Contents" + File .separator + "app.xml" );
306
+ }
307
+
308
+ private static boolean isPrerelease (File appBundle ) {
309
+ if (!findBundleAppXml (appBundle ).exists ()) {
310
+ return false ;
311
+ }
312
+ try (InputStream inputStream = new FileInputStream (findBundleAppXml (appBundle ))) {
313
+ Document doc = XMLUtil .parse (inputStream );
314
+ return "true" .equals (doc .getDocumentElement ().getAttribute ("prerelease" ));
315
+ } catch (Exception ex ) {
316
+ return false ;
317
+ }
318
+
319
+ }
320
+
307
321
private static String extractVersionFromFileName (String fileName ) {
308
322
int pos = fileName .lastIndexOf ("_" );
309
323
if (pos < 0 ) return null ;
@@ -337,9 +351,15 @@ private static String extractJDeployBundleCodeFromFileName(String fileName) {
337
351
338
352
}
339
353
340
- private static URL getJDeployBundleURLForCode (String code , String version ) {
354
+ private static URL getJDeployBundleURLForCode (String code , String version , File appBundle ) {
341
355
try {
342
- return new URL (JDEPLOY_REGISTRY + "download.php?code=" + URLEncoder .encode (code , "UTF-8" )+"&version=" +URLEncoder .encode (version , "UTF-8" ));
356
+ String prerelease = isPrerelease (appBundle ) ? "&prerelease=true" : "" ;
357
+ return new URL (JDEPLOY_REGISTRY + "download.php?code=" +
358
+ URLEncoder .encode (code , "UTF-8" ) +
359
+ "&version=" +URLEncoder .encode (version , "UTF-8" ) +
360
+ "&jdeploy_files=true&platform=*" +
361
+ prerelease
362
+ );
343
363
} catch (UnsupportedEncodingException ex ) {
344
364
throw new RuntimeException ("UTF-8 Encoding doesn't seem to be supported on this platform." , ex );
345
365
} catch (MalformedURLException e ) {
@@ -358,7 +378,7 @@ private static File findDirectoryByNameRecursive(File startDirectory, String nam
358
378
return null ;
359
379
}
360
380
361
- private static File downloadJDeployBundleForCode (String code , String version ) throws IOException {
381
+ private static File downloadJDeployBundleForCode (String code , String version , File appBundle ) throws IOException {
362
382
File destDirectory = File .createTempFile ("jdeploy-files-download" , ".tmp" );
363
383
destDirectory .delete ();
364
384
Runtime .getRuntime ().addShutdownHook (new Thread (()->{
@@ -367,7 +387,7 @@ private static File downloadJDeployBundleForCode(String code, String version) th
367
387
} catch (Exception ex ){}
368
388
}));
369
389
File destFile = new File (destDirectory , "jdeploy-files.zip" );
370
- try (InputStream inputStream = URLUtil .openStream (getJDeployBundleURLForCode (code , version ))) {
390
+ try (InputStream inputStream = URLUtil .openStream (getJDeployBundleURLForCode (code , version , appBundle ))) {
371
391
FileUtils .copyInputStreamToFile (inputStream , destFile );
372
392
}
373
393
@@ -408,7 +428,7 @@ private File findInstallFilesDir(File startDir) {
408
428
return null ;
409
429
}
410
430
try {
411
- return downloadJDeployBundleForCode (code , version );
431
+ return downloadJDeployBundleForCode (code , version , appBundle );
412
432
} catch (IOException ex ) {
413
433
System .err .println ("Failed to download bundle from the network for code " +code +"." );
414
434
ex .printStackTrace (System .err );
0 commit comments