Browse Source

Fixes #40 (Allows to specify a JRE Version in case of trouble). Also added a 3-times retry system to JreDownloader in case of a weak Internet Connection

MeFisto94 9 years ago
parent
commit
ddf0d5c279

+ 3 - 1
jme3-desktop-executables/src/com/jme3/gde/desktop/executables/Bundle.properties

@@ -9,8 +9,10 @@ DesktopExeCustomizerPanel.jCheckBox1.text=Create Windows 32bit Application
 DesktopExeCustomizerPanel.jCheckBox2.text=Create Windows 64bit Application
 DesktopExeCustomizerPanel.jCheckBox3.text=Create Linux 32bit Application
 DesktopExeCustomizerPanel.jLabel1.text=Select platforms to create launchers for
-DesktopExeCustomizerPanel.jTextArea1.text=You can further configure the application launchers (icons etc.) by modifying the templates in the resources folder.\n\nWhen you select to bundle the JRE with the applications the SDK will download the JREs for each platform, wait until the JREs are downloaded before building your application.\n\nThe command line options entered in the "Run" tab (e.g. to set the memory limits for the application) will automatically be added to the launchers.\n\nNote that the Linux and Mac launcher zips contain extended file info (executable bit) that gets lost and breaks the application if you re-zip it on the Windows OS.
+DesktopExeCustomizerPanel.jTextArea1.text=You can further configure the application launchers (icons etc.) by modifying the templates in the resources folder.\n\nWhen you select to bundle the JRE with the applications the SDK will download the JREs for each platform, wait until the JREs are downloaded before building your application.\n\nThe command line options entered in the "Run" tab (e.g. to set the memory limits for the application) will automatically be added to the launchers.\n\nNote that the Linux and Mac launcher zips contain extended file info (executable bit) that gets lost and breaks the application if you re-zip it on the Windows OS.\n\nThe JRE Version Field: In most cases you can leave this blank.\nThe Installer will then download the JRE Version it is run with.\nIf you run an older JRE Version (i.e. with an outdated SDK) or\nif you want a specific Version to fight bugs, use the JRE Version Field above.\nUse a String like 1.8.0_73-b02 for the Version
 DesktopExeCustomizerPanel.jCheckBox4.text=Create Linux 64bit Application
 DesktopExeCustomizerPanel.jCheckBox5.text=Create MacOSX Application
 DesktopExeCustomizerPanel.jCheckBox6.text=Bundle JRE with Applications
 DesktopExeCustomizerPanel.jCheckBox6.toolTipText=Downloads a JRE for each platform that will be bundled with the Application so it can be run without a Java installation.
+DesktopExeCustomizerPanel.jTextField1.text=
+DesktopExeCustomizerPanel.jLabel2.text=JRE Version

+ 11 - 8
jme3-desktop-executables/src/com/jme3/gde/desktop/executables/DesktopExeCompositeProvider.java

@@ -34,7 +34,8 @@ public class DesktopExeCompositeProvider implements ProjectCustomizer.CompositeC
         "linux-x86.app.enabled",
         "linux-x64.app.enabled",
         "macosx-x64.app.enabled",
-        "bundle.jre.enabled"
+        "bundle.jre.enabled",
+        "bundle.jre.version"
     };
 
     public DesktopExeCompositeProvider() {
@@ -76,12 +77,12 @@ public class DesktopExeCompositeProvider implements ProjectCustomizer.CompositeC
                     || "true".equals(properties.getProperty("macosx-x64.app.enabled"))) {
                 desktopDeployment.loadTargets("nbres:/com/jme3/gde/desktop/executables/desktop-deployment-targets.xml");
                 desktopDeployment.checkExtension(project);
-                if("true".equals(properties.getProperty("bundle.jre.enabled"))){
+                if ("true".equals(properties.getProperty("bundle.jre.enabled"))) {
                     checkJreDownloads();
                 }
             } else {
                 desktopDeployment.removeExtension(project);
-                
+
             }
 
             try {
@@ -93,12 +94,14 @@ public class DesktopExeCompositeProvider implements ProjectCustomizer.CompositeC
 
         public void checkJreDownloads() {
             String projectPath = project.getProjectDirectory().getPath();
+            String jreVersion = properties.getProperty("bundle.jre.version");
+
             if ("true".equals(properties.getProperty("windows-x86.app.enabled"))) {
                 String jreName = projectPath + File.separator + "resources"
                         + File.separator + "desktop-deployment"
                         + File.separator + "jre-windows-x86.tar.gz";
                 if (!new File(jreName).exists()) {
-                    JreDownloader.downloadJre("windows-i586", jreName);
+                    JreDownloader.downloadJre(jreVersion, "windows-i586", jreName);
                 }
             }
             if ("true".equals(properties.getProperty("windows-x64.app.enabled"))) {
@@ -106,7 +109,7 @@ public class DesktopExeCompositeProvider implements ProjectCustomizer.CompositeC
                         + File.separator + "desktop-deployment"
                         + File.separator + "jre-windows-x64.tar.gz";
                 if (!new File(jreName).exists()) {
-                    JreDownloader.downloadJre("windows-x64", jreName);
+                    JreDownloader.downloadJre(jreVersion, "windows-x64", jreName);
                 }
             }
             if ("true".equals(properties.getProperty("linux-x86.app.enabled"))) {
@@ -114,7 +117,7 @@ public class DesktopExeCompositeProvider implements ProjectCustomizer.CompositeC
                         + File.separator + "desktop-deployment"
                         + File.separator + "jre-linux-x86.tar.gz";
                 if (!new File(jreName).exists()) {
-                    JreDownloader.downloadJre("linux-i586", jreName);
+                    JreDownloader.downloadJre(jreVersion, "linux-i586", jreName);
                 }
             }
             if ("true".equals(properties.getProperty("linux-x64.app.enabled"))) {
@@ -122,7 +125,7 @@ public class DesktopExeCompositeProvider implements ProjectCustomizer.CompositeC
                         + File.separator + "desktop-deployment"
                         + File.separator + "jre-linux-x64.tar.gz";
                 if (!new File(jreName).exists()) {
-                    JreDownloader.downloadJre("linux-x64", jreName);
+                    JreDownloader.downloadJre(jreVersion, "linux-x64", jreName);
                 }
             }
             if ("true".equals(properties.getProperty("macosx-x64.app.enabled"))) {
@@ -130,7 +133,7 @@ public class DesktopExeCompositeProvider implements ProjectCustomizer.CompositeC
                         + File.separator + "desktop-deployment"
                         + File.separator + "jre-macosx-x64.tar.gz";
                 if (!new File(jreName).exists()) {
-                    JreDownloader.downloadJre("macosx-x64", jreName);
+                    JreDownloader.downloadJre(jreVersion, "macosx-x64", jreName);
                 }
             }
         }

+ 27 - 1
jme3-desktop-executables/src/com/jme3/gde/desktop/executables/DesktopExeCustomizerPanel.form

@@ -32,6 +32,13 @@
               </Group>
               <EmptySpace max="-2" attributes="0"/>
           </Group>
+          <Group type="102" alignment="1" attributes="0">
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="jLabel2" min="-2" max="-2" attributes="0"/>
+              <EmptySpace type="separate" max="-2" attributes="0"/>
+              <Component id="jTextField1" min="-2" pref="200" max="-2" attributes="0"/>
+              <EmptySpace max="32767" attributes="0"/>
+          </Group>
       </Group>
     </DimensionLayout>
     <DimensionLayout dim="1">
@@ -51,7 +58,12 @@
               <EmptySpace max="-2" attributes="0"/>
               <Component id="jCheckBox6" min="-2" max="-2" attributes="0"/>
               <EmptySpace max="-2" attributes="0"/>
-              <Component id="jScrollPane1" pref="129" max="32767" attributes="0"/>
+              <Group type="103" groupAlignment="3" attributes="0">
+                  <Component id="jTextField1" alignment="3" min="-2" max="-2" attributes="0"/>
+                  <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
+              </Group>
+              <EmptySpace min="-2" pref="12" max="-2" attributes="0"/>
+              <Component id="jScrollPane1" pref="189" max="32767" attributes="0"/>
               <EmptySpace max="-2" attributes="0"/>
           </Group>
       </Group>
@@ -134,5 +146,19 @@
         </Property>
       </Properties>
     </Component>
+    <Component class="javax.swing.JTextField" name="jTextField1">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/desktop/executables/Bundle.properties" key="DesktopExeCustomizerPanel.jTextField1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JLabel" name="jLabel2">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/desktop/executables/Bundle.properties" key="DesktopExeCustomizerPanel.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+    </Component>
   </SubComponents>
 </Form>

+ 32 - 7
jme3-desktop-executables/src/com/jme3/gde/desktop/executables/DesktopExeCustomizerPanel.java

@@ -3,7 +3,7 @@
  * and open the template in the editor.
  */
 
-/*
+ /*
  * LwjglAppletCustomizerPanel.java
  *
  * Created on 11.11.2010, 16:56:53
@@ -23,7 +23,9 @@ public class DesktopExeCustomizerPanel extends javax.swing.JPanel implements Act
 
     private ProjectExtensionProperties properties;
 
-    /** Creates new form LwjglAppletCustomizerPanel */
+    /**
+     * Creates new form LwjglAppletCustomizerPanel
+     */
     public DesktopExeCustomizerPanel(ProjectExtensionProperties properties) {
         this.properties = properties;
         initComponents();
@@ -101,16 +103,21 @@ public class DesktopExeCustomizerPanel extends javax.swing.JPanel implements Act
         } else {
             properties.setProperty("bundle.jre.enabled", "");
         }
+        if (!jTextField1.getText().equals("")) {
+            properties.setProperty("bundle.jre.version", jTextField1.getText());
+        } else {
+            properties.setProperty("bundle.jre.version", null);
+        }
     }
 
     public void actionPerformed(ActionEvent e) {
         saveProperties();
     }
 
-    /** This method is called from within the constructor to
-     * initialize the form.
-     * WARNING: Do NOT modify this code. The content of this method is
-     * always regenerated by the Form Editor.
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
      */
     @SuppressWarnings("unchecked")
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@@ -125,6 +132,8 @@ public class DesktopExeCustomizerPanel extends javax.swing.JPanel implements Act
         jCheckBox4 = new javax.swing.JCheckBox();
         jCheckBox5 = new javax.swing.JCheckBox();
         jCheckBox6 = new javax.swing.JCheckBox();
+        jTextField1 = new javax.swing.JTextField();
+        jLabel2 = new javax.swing.JLabel();
 
         jCheckBox1.setText(org.openide.util.NbBundle.getMessage(DesktopExeCustomizerPanel.class, "DesktopExeCustomizerPanel.jCheckBox1.text")); // NOI18N
 
@@ -150,6 +159,10 @@ public class DesktopExeCustomizerPanel extends javax.swing.JPanel implements Act
         jCheckBox6.setText(org.openide.util.NbBundle.getMessage(DesktopExeCustomizerPanel.class, "DesktopExeCustomizerPanel.jCheckBox6.text")); // NOI18N
         jCheckBox6.setToolTipText(org.openide.util.NbBundle.getMessage(DesktopExeCustomizerPanel.class, "DesktopExeCustomizerPanel.jCheckBox6.toolTipText")); // NOI18N
 
+        jTextField1.setText(org.openide.util.NbBundle.getMessage(DesktopExeCustomizerPanel.class, "DesktopExeCustomizerPanel.jTextField1.text")); // NOI18N
+
+        jLabel2.setText(org.openide.util.NbBundle.getMessage(DesktopExeCustomizerPanel.class, "DesktopExeCustomizerPanel.jLabel2.text")); // NOI18N
+
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
         layout.setHorizontalGroup(
@@ -167,6 +180,12 @@ public class DesktopExeCustomizerPanel extends javax.swing.JPanel implements Act
                     .addComponent(jCheckBox5, javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE)
                     .addComponent(jCheckBox6, javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE))
                 .addContainerGap())
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(jLabel2)
+                .addGap(18, 18, 18)
+                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -185,7 +204,11 @@ public class DesktopExeCustomizerPanel extends javax.swing.JPanel implements Act
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jCheckBox6)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(jLabel2))
+                .addGap(12, 12, 12)
+                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                 .addContainerGap())
         );
     }// </editor-fold>//GEN-END:initComponents
@@ -198,7 +221,9 @@ public class DesktopExeCustomizerPanel extends javax.swing.JPanel implements Act
     private javax.swing.JCheckBox jCheckBox5;
     private javax.swing.JCheckBox jCheckBox6;
     private javax.swing.JLabel jLabel1;
+    private javax.swing.JLabel jLabel2;
     private javax.swing.JScrollPane jScrollPane1;
     private javax.swing.JTextArea jTextArea1;
+    private javax.swing.JTextField jTextField1;
     // End of variables declaration//GEN-END:variables
 }

+ 29 - 10
jme3-desktop-executables/src/com/jme3/gde/desktop/executables/JreDownloader.java

@@ -31,6 +31,7 @@
  */
 package com.jme3.gde.desktop.executables;
 
+import com.jme3.gde.core.util.notify.MessageUtil;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.File;
@@ -64,21 +65,30 @@ public class JreDownloader {
      * Download a specific platforms JRE to the location specified, a tar.gz
      * file will be downloaded so the location parameter should end with tar.gz
      *
+     * @param jreVersion The Version to use. If null, we'll use the System JRE
+     * Version
      * @param platform The platform to download for (windows-i586, windows-x64,
      * linux-i586, linux-x64, maxosx-x64)
      * @param location The absolute file path to download to.
      */
-    public static void downloadJre(String platform, String location) {
-        String property = System.getProperty("java.runtime.version");
+    public static void downloadJre(String jreVersion, String platform, String location) {
+        String property; // The JRE Version
+
+        if (jreVersion == null) {
+            property = System.getProperty("java.runtime.version");
+        } else {
+            property = jreVersion;
+        }
+
         Matcher m = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)_(\\d+)\\-b(\\d+)").matcher(property);
         if (m.matches()) {
 //            "http://download.oracle.com/otn-pub/java/jdk/${jv.minor}u${jv.update}-b${jv.build}/jre-${jv.minor}u${jv.update}-${platform.durl}.tar.gz";
             String urlString = "http://download.oracle.com/otn-pub/java/jdk/" + m.group(2) + "u" + m.group(4) + "-b" + m.group(5) + "/jre-" + m.group(2) + "u" + m.group(4) + "-" + platform + ".tar.gz";
-            attemptDownload(urlString, new File(location));
+            attemptDownload(urlString, new File(location), 0);
         }
     }
 
-    private static void attemptDownload(String newUrl, File dest) {
+    private static void attemptDownload(String newUrl, File dest, int retry) {
         logger.log(Level.INFO, "Attempt to download JRE from {0}", newUrl);
         try {
             HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection();
@@ -88,11 +98,14 @@ public class JreDownloader {
             connection.connect();
             int status = connection.getResponseCode();
             if (status == HttpURLConnection.HTTP_OK) {
-                downloadFile(connection, dest);
+                downloadFile(connection, dest, retry);
             } else if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER) {
-                handleRedirect(connection, dest);
+                handleRedirect(connection, dest, retry);
+            } else if (status == HttpURLConnection.HTTP_NOT_FOUND) {
+                MessageUtil.error("Download of JRE failed because it was not found.\nMaybe you are running an old Version which isn't available for download anymore?");
+                MessageUtil.error("Go to download.oracle.com and alter the version field in the Project Properties accordingly.\nIf the Problem persists, download the .tar.gz files manually to\n" + dest.getAbsolutePath());
             } else {
-                logger.log(Level.WARNING, "Download of JRE from {0} failed", newUrl);
+                logger.log(Level.WARNING, "Download of JRE from {0} failed. HTTP Status Code {1} ", new Object[]{newUrl, status});
             }
         } catch (MalformedURLException ex) {
             logger.log(Level.SEVERE, "{0}", ex);
@@ -101,14 +114,14 @@ public class JreDownloader {
         }
     }
 
-    private static void handleRedirect(HttpURLConnection conn, File dest) {
+    private static void handleRedirect(HttpURLConnection conn, File dest, int retry) {
         String newUrl = conn.getHeaderField("Location");
         logger.log(Level.INFO, "JRE download redirected to {0}", newUrl);
         conn.disconnect();
-        attemptDownload(newUrl, dest);
+        attemptDownload(newUrl, dest, retry);
     }
 
-    private static void downloadFile(final HttpURLConnection connection, final File dest) {
+    private static void downloadFile(final HttpURLConnection connection, final File dest, final int retry) {
         logger.log(Level.INFO, "Downloading JRE from {0}", connection.getURL());
         Callable task = new Callable() {
 
@@ -129,6 +142,12 @@ public class JreDownloader {
                         progress.progress(i);
                         i++;
                     }
+
+                    if (i < length) {
+                        /* Download Error */
+                        logger.log(Level.WARNING, "Download of JRE got Interrupted. Retrying ({0} of 3)", retry + 1);
+                        attemptDownload(connection.getURL().toString(), dest, retry + 1);
+                    }
                 } catch (IOException ex) {
                     logger.log(Level.SEVERE, "{0}", ex);
                 } finally {