OSDN Git Service

SDK Updater: fix for new archives.
authorRaphael <raphael@google.com>
Tue, 9 Jun 2009 04:47:04 +0000 (21:47 -0700)
committerRaphael <raphael@google.com>
Tue, 9 Jun 2009 04:47:04 +0000 (21:47 -0700)
Fix for detecting MacOS platforms correctly.

Fix to account for new archives with a root folder
(the root folder is ignored).

Display why archives are not compatible (print
which OS was not compatible.)

sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java
sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Archive.java

index 761c236..0c666d2 100755 (executable)
@@ -191,6 +191,7 @@ public class AddonPackage extends Package {
 \r
         String name = String.format("%s-%d", getName(), getApiLevel()); // $NON-NLS-1$\r
 \r
+        name = name.toLowerCase();\r
         name = name.replaceAll("[^a-zA-Z0-9_-]+", "_");                 // $NON-NLS-1$\r
         name = name.replaceAll("_+", "_");                              // $NON-NLS-1$\r
 \r
index bd6b5be..a67d6b2 100755 (executable)
@@ -82,8 +82,8 @@ public class Archive implements IDescription {
             mUiName = uiName;\r
         }\r
 \r
-        @Override\r
-        public String toString() {\r
+        /** Returns the UI name of the OS. */\r
+        public String getUiName() {\r
             return mUiName;\r
         }\r
 \r
@@ -92,7 +92,7 @@ public class Archive implements IDescription {
          */\r
         public static Os getCurrentOs() {\r
             String os = System.getProperty("os.name");          //$NON-NLS-1$\r
-            if (os.startsWith("Mac OS")) {                      //$NON-NLS-1$\r
+            if (os.startsWith("Mac")) {                         //$NON-NLS-1$\r
                 return Os.MACOSX;\r
 \r
             } else if (os.startsWith("Windows")) {              //$NON-NLS-1$\r
@@ -119,8 +119,8 @@ public class Archive implements IDescription {
             mUiName = uiName;\r
         }\r
 \r
-        @Override\r
-        public String toString() {\r
+        /** Returns the UI name of the architecture. */\r
+        public String getUiName() {\r
             return mUiName;\r
         }\r
 \r
@@ -223,24 +223,34 @@ public class Archive implements IDescription {
     }\r
 \r
     /**\r
-     * Generates a short description for this archive.\r
+     * Generates a description for this archive of the OS/Arch supported by this archive.\r
      */\r
-    public String getShortDescription() {\r
+    public String getOsDescription() {\r
         String os;\r
         if (mOs == null) {\r
             os = "unknown OS";\r
         } else if (mOs == Os.ANY) {\r
             os = "any OS";\r
         } else {\r
-            os = mOs.toString();\r
+            os = mOs.getUiName();\r
         }\r
 \r
-        String arch = "";\r
+        String arch = "";                               //$NON-NLS-1$\r
         if (mArch != null && mArch != Arch.ANY) {\r
-            arch = mArch.toString();\r
+            arch = mArch.getUiName();\r
         }\r
 \r
-        return String.format("Archive for %1$s %2$s", os, arch);\r
+        return String.format("%1$s%2$s%3$s",\r
+                os,\r
+                arch.length() > 0 ? " " : "",           //$NON-NLS-2$\r
+                arch);\r
+    }\r
+\r
+    /**\r
+     * Generates a short description for this archive.\r
+     */\r
+    public String getShortDescription() {\r
+        return String.format("Archive for %1$s", getOsDescription());\r
     }\r
 \r
     /**\r
@@ -294,7 +304,9 @@ public class Archive implements IDescription {
 \r
             // TODO: we should not see this test fail if we had the filter UI above.\r
             if (!isCompatible()) {\r
-                monitor.setResult("Skipping incompatible archive: %1$s", name);\r
+                monitor.setResult("Skipping incompatible archive: %1$s for %2$s",\r
+                        name,\r
+                        getOsDescription());\r
                 return false;\r
             }\r
 \r
@@ -603,6 +615,16 @@ public class Archive implements IDescription {
                 // implementations can be expected to do that.\r
                 name = name.replace('\\', '/');\r
 \r
+                // Zip entries are always packages in a top-level directory\r
+                // (e.g. docs/index.html). However we want to use our top-level\r
+                // directory so we drop the first segment of the path name.\r
+                int pos = name.indexOf('/');\r
+                if (pos < 0 || pos == name.length() - 1) {\r
+                    continue;\r
+                } else {\r
+                    name = name.substring(pos + 1);\r
+                }\r
+\r
                 File destFile = new File(unzipDestFolder, name);\r
 \r
                 if (name.endsWith("/")) {  //$NON-NLS-1$\r