diff options
author | Raphael Moll <ralf@android.com> | 2011-05-02 14:24:26 -0700 |
---|---|---|
committer | Raphael Moll <ralf@android.com> | 2011-05-02 14:30:29 -0700 |
commit | a77c147c9e7ed3ef0c99cb2cdf986603e6d229cf (patch) | |
tree | eabee1ab84a53e372b122fa41f63fb866918e906 /sdkmanager | |
parent | b364b31e2f3a27f2b1c853ddffcfe598bed38657 (diff) | |
download | sdk-a77c147c9e7ed3ef0c99cb2cdf986603e6d229cf.zip sdk-a77c147c9e7ed3ef0c99cb2cdf986603e6d229cf.tar.gz sdk-a77c147c9e7ed3ef0c99cb2cdf986603e6d229cf.tar.bz2 |
SdkManager: handle missing platforms/ and add-ons/ folders.
A while ago, when we were dealing with monolithics SDKs,
the strategy was that we wanted to make sure that
the 'android' command was invoked from a properly setup
SDK folder. Consequently the SdkManager required at least
the platforms/ and add-ons/ folders to be present, even if
empty.
I don't think that behavior is really necessary anymore.
The 'android' tool is invoked with knowledge from its tools
folder, so we can safely assume the top parent is "the SDK
folder" and create these directories if they are missing.
We do however try to create them as early as possible if
they are missing, so that the tool aborts early if we can't
create them. The other alternative would be to just try to
create them when we're actually installing a package.
Change-Id: I8ea58f23add89c2dac0a22142f6fb5e71b8203aa
Diffstat (limited to 'sdkmanager')
-rwxr-xr-x | sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java | 2 | ||||
-rw-r--r-- | sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java | 44 |
2 files changed, 30 insertions, 16 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java b/sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java index cb2f981..4c72e1e 100755 --- a/sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java +++ b/sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java @@ -70,7 +70,7 @@ public class AboutPage extends Composite { "Revision %1$s\n" +
"Add-on XML Schema #%2$d\n" +
"Repository XML Schema #%3$d\n" +
- "Copyright (C) 2009-2010 The Android Open Source Project.",
+ "Copyright (C) 2009-2011 The Android Open Source Project.",
getRevision(),
SdkAddonConstants.NS_LATEST_VERSION,
SdkRepoConstants.NS_LATEST_VERSION));
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java index d6662c1..d924d3d 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java @@ -233,13 +233,17 @@ public class SdkManager { /** * Loads the Platforms from the SDK. + * Creates the "platforms" folder if necessary. + * * @param sdkOsPath Location of the SDK * @param list the list to fill with the platforms. * @param log the ISdkLog object receiving warning/error from the parsing. Cannot be null. + * @throws RuntimeException when the "platforms" folder is missing and cannot be created. */ private static void loadPlatforms(String sdkOsPath, ArrayList<IAndroidTarget> list, ISdkLog log) { File platformFolder = new File(sdkOsPath, SdkConstants.FD_PLATFORMS); + if (platformFolder.isDirectory()) { File[] platforms = platformFolder.listFiles(); @@ -257,15 +261,18 @@ public class SdkManager { return; } - String message = null; - if (platformFolder.exists() == false) { - message = "%s is missing."; + // Try to create it or complain if something else is in the way. + if (!platformFolder.exists()) { + if (!platformFolder.mkdir()) { + throw new RuntimeException( + String.format("Failed to create %1$s.", + platformFolder.getAbsolutePath())); + } } else { - message = "%s is not a folder."; + throw new RuntimeException( + String.format("%1$s is not a folder.", + platformFolder.getAbsolutePath())); } - - throw new IllegalArgumentException(String.format(message, - platformFolder.getAbsolutePath())); } /** @@ -388,7 +395,7 @@ public class SdkManager { * @return an array of strings containing all the abi names for the target */ private static String[] getAbiList(String path) { - ArrayList list = new ArrayList(); + ArrayList<String> list = new ArrayList<String>(); File imagesFolder = new File(path + File.separator + SdkConstants.OS_IMAGES_FOLDER); File[] files = imagesFolder.listFiles(); @@ -409,12 +416,16 @@ public class SdkManager { /** * Loads the Add-on from the SDK. + * Creates the "add-ons" folder if necessary. + * * @param osSdkPath Location of the SDK * @param list the list to fill with the add-ons. * @param log the ISdkLog object receiving warning/error from the parsing. Cannot be null. + * @throws RuntimeException when the "add-ons" folder is missing and cannot be created. */ private static void loadAddOns(String osSdkPath, ArrayList<IAndroidTarget> list, ISdkLog log) { File addonFolder = new File(osSdkPath, SdkConstants.FD_ADDONS); + if (addonFolder.isDirectory()) { File[] addons = addonFolder.listFiles(); @@ -433,15 +444,18 @@ public class SdkManager { return; } - String message = null; - if (addonFolder.exists() == false) { - message = "%s is missing."; + // Try to create it or complain if something else is in the way. + if (!addonFolder.exists()) { + if (!addonFolder.mkdir()) { + throw new RuntimeException( + String.format("Failed to create %1$s.", + addonFolder.getAbsolutePath())); + } } else { - message = "%s is not a folder."; + throw new RuntimeException( + String.format("%1$s is not a folder.", + addonFolder.getAbsolutePath())); } - - throw new IllegalArgumentException(String.format(message, - addonFolder.getAbsolutePath())); } /** |