OSDN Git Service

SDK Updater: Install samples in correct directory.
authorRaphael <raphael@google.com>
Mon, 25 Jan 2010 22:54:40 +0000 (14:54 -0800)
committerRaphael <raphael@google.com>
Mon, 25 Jan 2010 23:36:56 +0000 (15:36 -0800)
Also makes sure root directories exist before trying to
install into them

SDK Bug: 2384690

Change-Id: I9ed9f1b206debfc051d7b627afd5fd1fac96dd88

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

index de51015..218ced0 100755 (executable)
@@ -280,6 +280,19 @@ public class AddonPackage extends Package
         return null;\r
     }\r
 \r
+    /**\r
+     * Makes sure the base /add-ons folder exists before installing.\r
+     */\r
+    @Override\r
+    public void preInstallHook(String osSdkRoot, Archive archive) {\r
+        super.preInstallHook(osSdkRoot, archive);\r
+\r
+        File addonsRoot = new File(osSdkRoot, SdkConstants.FD_ADDONS);\r
+        if (!addonsRoot.isDirectory()) {\r
+            addonsRoot.mkdir();\r
+        }\r
+    }\r
+\r
     @Override\r
     public boolean sameItemAs(Package pkg) {\r
         if (pkg instanceof AddonPackage) {\r
index 8765905..7c0eef5 100755 (executable)
@@ -405,11 +405,18 @@ public class Archive implements IDescription {
 \r
         archiveFile = downloadFile(osSdkRoot, monitor, forceHttp);\r
         if (archiveFile != null) {\r
-            if (unarchive(osSdkRoot, archiveFile, sdkManager, monitor)) {\r
-                monitor.setResult("Installed %1$s", name);\r
-                // Delete the temp archive if it exists, only on success\r
-                deleteFileOrFolder(archiveFile);\r
-                return true;\r
+            boolean installSuccess = false;\r
+            try {\r
+                pkg.preInstallHook(osSdkRoot, this);\r
+                if (unarchive(osSdkRoot, archiveFile, sdkManager, monitor)) {\r
+                    monitor.setResult("Installed %1$s", name);\r
+                    // Delete the temp archive if it exists, only on success\r
+                    deleteFileOrFolder(archiveFile);\r
+                    installSuccess = true;\r
+                    return true;\r
+                }\r
+            } finally {\r
+                pkg.postInstallHook(this, installSuccess);\r
             }\r
         }\r
 \r
index bbc59ff..9a2b93a 100755 (executable)
@@ -403,6 +403,28 @@ public abstract class Package implements IDescription, Comparable<Package> {
             String osSdkRoot, String suggestedDir, SdkManager sdkManager);\r
 \r
     /**\r
+     * Hook called right before an archive is installed. The archive has already\r
+     * been downloaded succesfully and will be installed in the directory specified by\r
+     * {@link #getInstallFolder(String, String, SdkManager)} when this call returns.\r
+     *\r
+     * @param osSdkRoot The OS path of the SDK root folder.\r
+     * @param archive The archive that will be installed\r
+     */\r
+    public void preInstallHook(String osSdkRoot, Archive archive) {\r
+        // Nothing to do in base class.\r
+    }\r
+\r
+    /**\r
+     * Hook called right after an archive has been installed.\r
+     *\r
+     * @param archive The archive that has been installed\r
+     * @param installSuccess True if the archive was successfully installed.\r
+     */\r
+    public void postInstallHook(Archive archive, boolean installSuccess) {\r
+        // Nothing to do in base class.\r
+    }\r
+\r
+    /**\r
      * Returns whether the give package represents the same item as the current package.\r
      * <p/>\r
      * Two packages are considered the same if they represent the same thing, except for the\r
index 311499e..3d13c93 100755 (executable)
@@ -179,11 +179,25 @@ public class PlatformPackage extends MinToolsPackage implements IPackageVersion
         }\r
 \r
         File platforms = new File(osSdkRoot, SdkConstants.FD_PLATFORMS);\r
-        File folder = new File(platforms, String.format("android-%s", getVersionName())); //$NON-NLS-1$\r
+        File folder = new File(platforms,\r
+                String.format("android-%s", getVersion().getApiString())); //$NON-NLS-1$\r
 \r
         return folder;\r
     }\r
 \r
+    /**\r
+     * Makes sure the base /platforms folder exists before installing.\r
+     */\r
+    @Override\r
+    public void preInstallHook(String osSdkRoot, Archive archive) {\r
+        super.preInstallHook(osSdkRoot, archive);\r
+\r
+        File platformsRoot = new File(osSdkRoot, SdkConstants.FD_PLATFORMS);\r
+        if (!platformsRoot.isDirectory()) {\r
+            platformsRoot.mkdir();\r
+        }\r
+    }\r
+\r
     @Override\r
     public boolean sameItemAs(Package pkg) {\r
         if (pkg instanceof PlatformPackage) {\r
index 5a0f8fc..afb91e1 100755 (executable)
@@ -206,6 +206,9 @@ public class SamplePackage extends MinToolsPackage
     @Override\r
     public File getInstallFolder(String osSdkRoot, String suggestedDir, SdkManager sdkManager) {\r
 \r
+        // The /samples dir at the root of the SDK\r
+        File samplesRoot = new File(osSdkRoot, SdkConstants.FD_SAMPLES);\r
+\r
         // First find if this platform is already installed. If so, reuse the same directory.\r
         for (IAndroidTarget target : sdkManager.getTargets()) {\r
             if (target.isPlatform() &&\r
@@ -213,25 +216,42 @@ public class SamplePackage extends MinToolsPackage
                 String p = target.getPath(IAndroidTarget.SAMPLES);\r
                 File f = new File(p);\r
                 if (f.isDirectory()) {\r
-                    return f;\r
+                    // We *only* use this directory if it's using the "new" location\r
+                    // under SDK/samples. We explicitly do not reuse the "old" location\r
+                    // under SDK/platform/android-N/samples.\r
+                    if (f.getParentFile().equals(samplesRoot)) {\r
+                        return f;\r
+                    }\r
                 }\r
             }\r
         }\r
 \r
         // Otherwise, get a suitable default\r
-        File samples = new File(osSdkRoot, SdkConstants.FD_SAMPLES);\r
-        File folder = new File(samples,\r
-                String.format("android-%d", getVersion().getApiLevel())); //$NON-NLS-1$\r
+        File folder = new File(samplesRoot,\r
+                String.format("android-%s", getVersion().getApiString())); //$NON-NLS-1$\r
 \r
         for (int n = 1; folder.exists(); n++) {\r
             // Keep trying till we find an unused directory.\r
-            folder = new File(samples,\r
-                    String.format("android-%d_%d", getVersion().getApiLevel(), n)); //$NON-NLS-1$\r
+            folder = new File(samplesRoot,\r
+                    String.format("android-%s_%d", getVersion().getApiString(), n)); //$NON-NLS-1$\r
         }\r
 \r
         return folder;\r
     }\r
 \r
+    /**\r
+     * Makes sure the base /samples folder exists before installing.\r
+     */\r
+    @Override\r
+    public void preInstallHook(String osSdkRoot, Archive archive) {\r
+        super.preInstallHook(osSdkRoot, archive);\r
+\r
+        File samplesRoot = new File(osSdkRoot, SdkConstants.FD_SAMPLES);\r
+        if (!samplesRoot.isDirectory()) {\r
+            samplesRoot.mkdir();\r
+        }\r
+    }\r
+\r
     @Override\r
     public boolean sameItemAs(Package pkg) {\r
         if (pkg instanceof SamplePackage) {\r