66import ca .weblite .jdeploy .installer .npm .NPMPackage ;
77import ca .weblite .jdeploy .installer .npm .NPMPackageVersion ;
88import 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 .*;
1310import ca .weblite .tools .platform .Platform ;
1411import com .izforge .izpack .util .os .ShellLink ;
1512import net .coobird .thumbnailator .Thumbnails ;
@@ -304,6 +301,23 @@ private File findAppBundle() {
304301 return start ;
305302 }
306303
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+
307321 private static String extractVersionFromFileName (String fileName ) {
308322 int pos = fileName .lastIndexOf ("_" );
309323 if (pos < 0 ) return null ;
@@ -337,9 +351,15 @@ private static String extractJDeployBundleCodeFromFileName(String fileName) {
337351
338352 }
339353
340- private static URL getJDeployBundleURLForCode (String code , String version ) {
354+ private static URL getJDeployBundleURLForCode (String code , String version , File appBundle ) {
341355 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+ );
343363 } catch (UnsupportedEncodingException ex ) {
344364 throw new RuntimeException ("UTF-8 Encoding doesn't seem to be supported on this platform." , ex );
345365 } catch (MalformedURLException e ) {
@@ -358,7 +378,7 @@ private static File findDirectoryByNameRecursive(File startDirectory, String nam
358378 return null ;
359379 }
360380
361- private static File downloadJDeployBundleForCode (String code , String version ) throws IOException {
381+ private static File downloadJDeployBundleForCode (String code , String version , File appBundle ) throws IOException {
362382 File destDirectory = File .createTempFile ("jdeploy-files-download" , ".tmp" );
363383 destDirectory .delete ();
364384 Runtime .getRuntime ().addShutdownHook (new Thread (()->{
@@ -367,7 +387,7 @@ private static File downloadJDeployBundleForCode(String code, String version) th
367387 } catch (Exception ex ){}
368388 }));
369389 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 ))) {
371391 FileUtils .copyInputStreamToFile (inputStream , destFile );
372392 }
373393
@@ -408,7 +428,7 @@ private File findInstallFilesDir(File startDir) {
408428 return null ;
409429 }
410430 try {
411- return downloadJDeployBundleForCode (code , version );
431+ return downloadJDeployBundleForCode (code , version , appBundle );
412432 } catch (IOException ex ) {
413433 System .err .println ("Failed to download bundle from the network for code " +code +"." );
414434 ex .printStackTrace (System .err );
0 commit comments