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
\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
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
}\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
@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
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