From 1202d09966e9ad2bac7df79f1a3acce8ca6d7ac5 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Wed, 16 Jun 2010 13:29:41 +0000
Subject: [PATCH]     * FileUtil: Try to handle lack of unpack200 support more
 gracefully     * Update: Select old update URL if no unpack200 available

---
 INSTALL-headless.txt                          |  1 +
 INSTALL.txt                                   |  1 +
 README.txt                                    |  1 +
 .../i2p/router/web/ConfigUpdateHandler.java   | 27 ++++++++++++++++---
 core/java/src/net/i2p/util/FileUtil.java      | 20 +++++++++++++-
 history.txt                                   |  5 ++++
 .../src/net/i2p/router/RouterVersion.java     |  2 +-
 7 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/INSTALL-headless.txt b/INSTALL-headless.txt
index fac3980ff..c009bac20 100644
--- a/INSTALL-headless.txt
+++ b/INSTALL-headless.txt
@@ -27,6 +27,7 @@ run I2P for the first time.
 To run I2P explicitly:
    (*nix): sh i2prouter start
    (win*): I2P.exe
+   (Platforms unsupported by the wrapper - PPC, ARM, etc): sh runplain.sh
 
 To stop the router (gracefully):
    lynx http://localhost:7657/configservice.jsp ("Shutdown gracefully")
diff --git a/INSTALL.txt b/INSTALL.txt
index adbbc5ad5..acc220c5e 100644
--- a/INSTALL.txt
+++ b/INSTALL.txt
@@ -2,6 +2,7 @@ I2P source installation instructions
 
 Prerequisites to build from source:
 	Java SDK (preferably Sun) 1.5.0 or higher (1.6 recommended)
+	The SDK must have Pack200 support (java.util.jar.Pack200)
 	Apache Ant 1.7.0 or higher
 	Optional, For multilanguage support: The xgettext, msgfmt, and msgmerge tools installed
 	from the GNU gettext package http://www.gnu.org/software/gettext/
diff --git a/README.txt b/README.txt
index c5ddc12bd..c235f89ba 100644
--- a/README.txt
+++ b/README.txt
@@ -1,5 +1,6 @@
 Prerequisites to build from source:
 	Java SDK (preferably Sun) 1.5.0 or higher (1.6 recommended)
+	The SDK must have Pack200 support (java.util.jar.Pack200)
 	Apache Ant 1.7.0 or higher
 	Optional, For multilanguage support: The xgettext, msgfmt, and msgmerge tools installed
 	from the GNU gettext package http://www.gnu.org/software/gettext/
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java
index cc8e01bc0..b407fe494 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java
@@ -43,15 +43,34 @@ public class ConfigUpdateHandler extends FormHandler {
     
     public static final String PROP_UPDATE_URL = "router.updateURL";
     /**
-     *  Changed as of release 0.7.14 from .sud to .su2
-     *  Update hosts must maintain both for several releases
+     *  Changed as of release 0.8 to support both .sud and .su2
+     *  Some JVMs (IcedTea) don't have pack200
+     *  Update hosts must maintain both
      */
-    public static final String DEFAULT_UPDATE_URL =
+    private static final String PACK200_URLS =
     "http://echelon.i2p/i2p/i2pupdate.su2\r\n" +
     "http://stats.i2p/i2p/i2pupdate.su2\r\n" +
     "http://www.i2p2.i2p/_static/i2pupdate.su2\r\n" +
     "http://update.postman.i2p/i2pupdate.su2" ;
-    
+
+    private static final String NO_PACK200_URLS =
+    "http://echelon.i2p/i2p/i2pupdate.sud\r\n" +
+    "http://stats.i2p/i2p/i2pupdate.sud\r\n" +
+    "http://www.i2p2.i2p/_static/i2pupdate.sud\r\n" +
+    "http://update.postman.i2p/i2pupdate.sud" ;
+
+    public static final String DEFAULT_UPDATE_URL;
+    static {
+        String foo;
+        try {
+            Class.forName("java.util.jar.Pack200", false, ClassLoader.getSystemClassLoader());
+            foo = PACK200_URLS;
+        } catch (ClassNotFoundException cnfe) {
+            foo = NO_PACK200_URLS;
+        }
+        DEFAULT_UPDATE_URL = foo;
+    }
+
     public static final String PROP_TRUSTED_KEYS = "router.trustedUpdateKeys";
     
     
diff --git a/core/java/src/net/i2p/util/FileUtil.java b/core/java/src/net/i2p/util/FileUtil.java
index ef7311301..ec759e0f2 100644
--- a/core/java/src/net/i2p/util/FileUtil.java
+++ b/core/java/src/net/i2p/util/FileUtil.java
@@ -133,9 +133,16 @@ public class FileUtil {
                         }
                         in.close();
                     } catch (IOException ioe) {
-                        System.err.println("ERROR: Error extracting the zip entry (" + entry.getName() + "]");
+                        System.err.println("ERROR: Error extracting the zip entry (" + entry.getName() + ')');
+                        if (ioe.getMessage() != null && ioe.getMessage().indexOf("CAFED00D") >= 0)
+                            System.err.println("This may be caused by a packed library that requires Java 1.6, your Java version is: " +
+                                               System.getProperty("java.version"));
                         ioe.printStackTrace();
                         return false;
+                    } catch (Exception e) {  // ClassNotFoundException but compiler not happy with that
+                        System.err.println("ERROR: Error unpacking the zip entry (" + entry.getName() +
+                                           "), your JVM does not support unpack200");
+                        return false;
                     }
                 }
             }
@@ -170,6 +177,7 @@ public class FileUtil {
             byte buf[] = new byte[16*1024];
             zip = new ZipFile(zipfile);
             Enumeration entries = zip.entries();
+            boolean p200TestRequired = true;
             while (entries.hasMoreElements()) {
                 ZipEntry entry = (ZipEntry)entries.nextElement();
                 if (entry.getName().indexOf("..") != -1) {
@@ -179,6 +187,16 @@ public class FileUtil {
                 if (entry.isDirectory()) {
                     // noop
                 } else {
+                    if (p200TestRequired &&
+                        (entry.getName().endsWith(".jar.pack") || entry.getName().endsWith(".war.pack"))) {
+                        try {
+                            Class.forName("java.util.jar.Pack200", false, ClassLoader.getSystemClassLoader());
+                        } catch (Exception e) {  // ClassNotFoundException but compiler not happy with that
+                            System.err.println("ERROR: Zip verify failed, your JVM does not support unpack200");
+                            return false;
+                        }
+                        p200TestRequired = false;
+                    }
                     try {
                         InputStream in = zip.getInputStream(entry);
                         int read = 0;
diff --git a/history.txt b/history.txt
index 2b317f138..381738c06 100644
--- a/history.txt
+++ b/history.txt
@@ -1,3 +1,8 @@
+2010-06-16 zzz
+    * Console: Sort countries with selected locale
+    * FileUtil: Try to handle lack of unpack200 support more gracefully
+    * Update: Select old update URL if no unpack200 available
+
 2010-06-13 zzz
     * Console: Add some divs for languages to news and readmes
     * HTTP Proxy: Pass different User Agent to outproxy
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index 87e5bffca..282c18b42 100644
--- a/router/java/src/net/i2p/router/RouterVersion.java
+++ b/router/java/src/net/i2p/router/RouterVersion.java
@@ -18,7 +18,7 @@ public class RouterVersion {
     /** deprecated */
     public final static String ID = "Monotone";
     public final static String VERSION = CoreVersion.VERSION;
-    public final static long BUILD = 1;
+    public final static long BUILD = 2;
 
     /** for example "-test" */
     public final static String EXTRA = "";
-- 
GitLab