diff options
author | Raphael <raphael@google.com> | 2012-03-09 11:18:42 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-03-09 11:18:42 -0800 |
commit | 7b4b54057e216904fc25989beb7b0b7bff874a64 (patch) | |
tree | 5a9a0c0aea261036f3dc029ba707f292c9806d30 /sdkmanager | |
parent | e19bfc666f085fd2bd10158d43735e9646663d44 (diff) | |
parent | 5b5bdeb7e691980a1174650ce926edbaa87a5a3e (diff) | |
download | sdk-7b4b54057e216904fc25989beb7b0b7bff874a64.zip sdk-7b4b54057e216904fc25989beb7b0b7bff874a64.tar.gz sdk-7b4b54057e216904fc25989beb7b0b7bff874a64.tar.bz2 |
Merge "NPW: Find samples in extras."
Diffstat (limited to 'sdkmanager')
4 files changed, 261 insertions, 76 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java index df3defc..fb7f0bf 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java @@ -16,6 +16,7 @@ package com.android.sdklib; +import com.android.annotations.NonNull; import com.android.annotations.VisibleForTesting; import com.android.annotations.VisibleForTesting.Visibility; import com.android.io.FileWrapper; @@ -24,6 +25,11 @@ import com.android.prefs.AndroidLocation.AndroidLocationException; import com.android.sdklib.AndroidVersion.AndroidVersionException; import com.android.sdklib.ISystemImage.LocationType; import com.android.sdklib.internal.project.ProjectProperties; +import com.android.sdklib.internal.repository.Archive; +import com.android.sdklib.internal.repository.ExtraPackage; +import com.android.sdklib.internal.repository.LocalSdkParser; +import com.android.sdklib.internal.repository.NullTaskMonitor; +import com.android.sdklib.internal.repository.Package; import com.android.sdklib.repository.PkgProps; import com.android.util.Pair; @@ -149,8 +155,8 @@ public class SdkManager { manager.setTargets(list.toArray(new IAndroidTarget[list.size()])); - // load the samples, after the targets have been set. - manager.loadSamples(log); + // Initialize the targets' sample paths, after the targets have been set. + manager.initializeSamplePaths(log); return manager; } catch (IllegalArgumentException e) { @@ -260,7 +266,7 @@ public class SdkManager { setTargets(list.toArray(new IAndroidTarget[list.size()])); // load the samples, after the targets have been set. - loadSamples(log); + initializeSamplePaths(log); } /** @@ -272,7 +278,7 @@ public class SdkManager { * version defined. * * @return The greatest {@link LayoutlibVersion} or null if none is found. - * @deprecated This does NOT solve the right problem and will be changed in Tools R15. + * @deprecated This does NOT solve the right problem and will be changed later. */ @Deprecated public LayoutlibVersion getMaxLayoutlibVersion() { @@ -293,6 +299,43 @@ public class SdkManager { } /** + * Returns a map of the <em>root samples directories</em> located in the SDK/extras packages. + * No guarantee is made that the extras' samples directory actually contain any valid samples. + * The only guarantee is that the root samples directory actually exists. + * The map is { File: Samples root directory => String: Extra package display name. } + * + * @return A non-null possibly empty map of extra samples directories and their associated + * extra package display name. + */ + public @NonNull Map<File, String> getExtraSamples() { + LocalSdkParser parser = new LocalSdkParser(); + Package[] packages = parser.parseSdk(mOsSdkPath, + this, + LocalSdkParser.PARSE_EXTRAS, + new NullTaskMonitor(new NullSdkLog())); + + Map<File, String> samples = new HashMap<File, String>(); + + for (Package pkg : packages) { + if (pkg instanceof ExtraPackage && pkg.isLocal()) { + // isLocal()==true implies there's a single locally-installed archive. + assert pkg.getArchives() != null && pkg.getArchives().length == 1; + Archive a = pkg.getArchives()[0]; + assert a != null; + File path = new File(a.getLocalOsPath(), SdkConstants.FD_SAMPLES); + if (path.isDirectory()) { + samples.put(path, pkg.getListDescription()); + } + } + } + + return samples; + } + + + // -------- private methods ---------- + + /** * Loads the Platforms from the SDK. * Creates the "platforms" folder if necessary. * @@ -994,11 +1037,15 @@ public class SdkManager { } /** - * Loads all samples from the {@link SdkConstants#FD_SAMPLES} directory. + * Initialize the sample folders for all known targets (platforms and addons). + * <p/> + * Samples used to be located at SDK/Target/samples. We then changed this to + * have a separate SDK/samples/samples-API directory. This parses either directories + * and sets the targets' sample path accordingly. * * @param log Logger. Cannot be null. */ - private void loadSamples(ISdkLog log) { + private void initializeSamplePaths(ISdkLog log) { File sampleFolder = new File(mOsSdkPath, SdkConstants.FD_SAMPLES); if (sampleFolder.isDirectory()) { File[] platforms = sampleFolder.listFiles(); diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ExtraPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ExtraPackage.java index a242c26..4e922c5 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ExtraPackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ExtraPackage.java @@ -552,6 +552,7 @@ public class ExtraPackage extends MinToolsPackage Package[] pkgs = localParser.parseSdk(
osSdkRoot,
sdkManager,
+ LocalSdkParser.PARSE_EXTRAS,
new NullTaskMonitor(new NullSdkLog()));
for (Package pkg : pkgs) {
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/LocalSdkParser.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/LocalSdkParser.java index 13be219..29ea5ff 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/LocalSdkParser.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/LocalSdkParser.java @@ -16,6 +16,7 @@ package com.android.sdklib.internal.repository;
+import com.android.annotations.NonNull;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.ISdkLog;
import com.android.sdklib.ISystemImage;
@@ -42,6 +43,33 @@ public class LocalSdkParser { private Package[] mPackages;
+ /** Parse all SDK folders. */
+ public static final int PARSE_ALL = 0xFFFF;
+ /** Parse the SDK/tools folder. */
+ public static final int PARSE_TOOLS = 0x0001;
+ /** Parse the SDK/platform-tools folder */
+ public static final int PARSE_PLATFORM_TOOLS = 0x0002;
+ /** Parse the SDK/docs folder. */
+ public static final int PARSE_DOCS = 0x0004;
+ /**
+ * Equivalent to parsing the SDK/platforms folder but does so
+ * by using the <em>valid</em> targets loaded by the {@link SdkManager}.
+ * Parsing the platforms also parses the SDK/system-images folder.
+ */
+ public static final int PARSE_PLATFORMS = 0x0010;
+ /**
+ * Equivalent to parsing the SDK/addons folder but does so
+ * by using the <em>valid</em> targets loaded by the {@link SdkManager}.
+ */
+ public static final int PARSE_ADDONS = 0x0020;
+ /** Parse the SDK/samples folder.
+ * Note: this will not detect samples located in the SDK/extras packages. */
+ public static final int PARSE_SAMPLES = 0x0100;
+ /** Parse the SDK/sources folder. */
+ public static final int PARSE_SOURCES = 0x0200;
+ /** Parse the SDK/extras folder. */
+ public static final int PARSE_EXTRAS = 0x0400;
+
public LocalSdkParser() {
// pass
}
@@ -69,115 +97,165 @@ public class LocalSdkParser { * <p/>
* Store the packages internally. You can use {@link #getPackages()} to retrieve them
* at any time later.
+ * <p/>
+ * Equivalent to calling {@code parseSdk(..., PARSE_ALL, ...); }
+ *
+ * @param osSdkRoot The path to the SDK folder, typically {@code sdkManager.getLocation()}.
+ * @param sdkManager An existing SDK manager to list current platforms and addons.
+ * @param monitor A monitor to track progress. Cannot be null.
+ * @return The packages found. Can be retrieved later using {@link #getPackages()}.
+ */
+ public @NonNull Package[] parseSdk(
+ @NonNull String osSdkRoot,
+ @NonNull SdkManager sdkManager,
+ @NonNull ITaskMonitor monitor) {
+ return parseSdk(osSdkRoot, sdkManager, PARSE_ALL, monitor);
+ }
+
+ /**
+ * Scan the give SDK to find all the packages already installed at this location.
+ * <p/>
+ * Store the packages internally. You can use {@link #getPackages()} to retrieve them
+ * at any time later.
*
* @param osSdkRoot The path to the SDK folder, typically {@code sdkManager.getLocation()}.
* @param sdkManager An existing SDK manager to list current platforms and addons.
+ * @param parseFilter Either {@link #PARSE_ALL} or an ORed combination of the other
+ * {@code PARSE_} constants to indicate what should be parsed.
* @param monitor A monitor to track progress. Cannot be null.
* @return The packages found. Can be retrieved later using {@link #getPackages()}.
*/
- public Package[] parseSdk(
- String osSdkRoot,
- SdkManager sdkManager,
- ITaskMonitor monitor) {
+ public @NonNull Package[] parseSdk(
+ @NonNull String osSdkRoot,
+ @NonNull SdkManager sdkManager,
+ int parseFilter,
+ @NonNull ITaskMonitor monitor) {
ArrayList<Package> packages = new ArrayList<Package>();
HashSet<File> visited = new HashSet<File>();
monitor.setProgressMax(10);
- File dir = new File(osSdkRoot, SdkConstants.FD_DOCS);
- Package pkg = scanDoc(dir, monitor);
- if (pkg != null) {
- packages.add(pkg);
- visited.add(dir);
+ File dir = null;
+ Package pkg = null;
+
+ if ((parseFilter & PARSE_DOCS) != 0) {
+ dir = new File(osSdkRoot, SdkConstants.FD_DOCS);
+ pkg = scanDoc(dir, monitor);
+ if (pkg != null) {
+ packages.add(pkg);
+ visited.add(dir);
+ }
}
monitor.incProgress(1);
- dir = new File(osSdkRoot, SdkConstants.FD_TOOLS);
- pkg = scanTools(dir, monitor);
- if (pkg != null) {
- packages.add(pkg);
- visited.add(dir);
+ if ((parseFilter & PARSE_TOOLS) != 0) {
+ dir = new File(osSdkRoot, SdkConstants.FD_TOOLS);
+ pkg = scanTools(dir, monitor);
+ if (pkg != null) {
+ packages.add(pkg);
+ visited.add(dir);
+ }
}
monitor.incProgress(1);
- dir = new File(osSdkRoot, SdkConstants.FD_PLATFORM_TOOLS);
- pkg = scanPlatformTools(dir, monitor);
- if (pkg != null) {
- packages.add(pkg);
- visited.add(dir);
+ if ((parseFilter & PARSE_PLATFORM_TOOLS) != 0) {
+ dir = new File(osSdkRoot, SdkConstants.FD_PLATFORM_TOOLS);
+ pkg = scanPlatformTools(dir, monitor);
+ if (pkg != null) {
+ packages.add(pkg);
+ visited.add(dir);
+ }
}
monitor.incProgress(1);
- File samplesRoot = new File(osSdkRoot, SdkConstants.FD_SAMPLES);
-
// for platforms, add-ons and samples, rely on the SdkManager parser
- for(IAndroidTarget target : sdkManager.getTargets()) {
- Properties props = parseProperties(new File(target.getLocation(),
- SdkConstants.FN_SOURCE_PROP));
+ if ((parseFilter & (PARSE_ADDONS | PARSE_PLATFORMS)) != 0) {
+ File samplesRoot = new File(osSdkRoot, SdkConstants.FD_SAMPLES);
- try {
- if (target.isPlatform()) {
- pkg = PlatformPackage.create(target, props);
-
- if (samplesRoot.isDirectory()) {
- // Get the samples dir for a platform if it is located in the new
- // root /samples dir. We purposely ignore "old" samples that are
- // located under the platform dir.
- File samplesDir = new File(target.getPath(IAndroidTarget.SAMPLES));
- if (samplesDir.exists() && samplesDir.getParentFile().equals(samplesRoot)) {
- Properties samplesProps = parseProperties(
- new File(samplesDir, SdkConstants.FN_SOURCE_PROP));
- if (samplesProps != null) {
- Package pkg2 = SamplePackage.create(target, samplesProps);
- packages.add(pkg2);
+ for(IAndroidTarget target : sdkManager.getTargets()) {
+ Properties props = parseProperties(new File(target.getLocation(),
+ SdkConstants.FN_SOURCE_PROP));
+
+ try {
+ pkg = null;
+ if (target.isPlatform() && (parseFilter & PARSE_PLATFORMS) != 0) {
+ pkg = PlatformPackage.create(target, props);
+
+ if (samplesRoot.isDirectory()) {
+ // Get the samples dir for a platform if it is located in the new
+ // root /samples dir. We purposely ignore "old" samples that are
+ // located under the platform dir.
+ File samplesDir = new File(target.getPath(IAndroidTarget.SAMPLES));
+ if (samplesDir.exists() &&
+ samplesDir.getParentFile().equals(samplesRoot)) {
+ Properties samplesProps = parseProperties(
+ new File(samplesDir, SdkConstants.FN_SOURCE_PROP));
+ if (samplesProps != null) {
+ Package pkg2 = SamplePackage.create(target, samplesProps);
+ packages.add(pkg2);
+ }
+ visited.add(samplesDir);
}
- visited.add(samplesDir);
}
+ } else if ((parseFilter & PARSE_ADDONS) != 0) {
+ pkg = AddonPackage.create(target, props);
}
- } else {
- pkg = AddonPackage.create(target, props);
- }
- for (ISystemImage systemImage : target.getSystemImages()) {
- if (systemImage.getLocationType() == LocationType.IN_SYSTEM_IMAGE) {
- File siDir = systemImage.getLocation();
- if (siDir.isDirectory()) {
- Properties siProps = parseProperties(
- new File(siDir, SdkConstants.FN_SOURCE_PROP));
- Package pkg2 = new SystemImagePackage(
- target.getVersion(),
- 0 /*revision*/, // this will use the one from siProps if any
- systemImage.getAbiType(),
- siProps,
- siDir.getAbsolutePath());
- packages.add(pkg2);
- visited.add(siDir);
+ if (pkg != null) {
+ for (ISystemImage systemImage : target.getSystemImages()) {
+ if (systemImage.getLocationType() == LocationType.IN_SYSTEM_IMAGE) {
+ File siDir = systemImage.getLocation();
+ if (siDir.isDirectory()) {
+ Properties siProps = parseProperties(
+ new File(siDir, SdkConstants.FN_SOURCE_PROP));
+ Package pkg2 = new SystemImagePackage(
+ target.getVersion(),
+ 0 /*rev*/, // this will use the one from siProps
+ systemImage.getAbiType(),
+ siProps,
+ siDir.getAbsolutePath());
+ packages.add(pkg2);
+ visited.add(siDir);
+ }
+ }
}
}
- }
- } catch (Exception e) {
- monitor.error(e, null);
- }
+ } catch (Exception e) {
+ monitor.error(e, null);
+ }
- if (pkg != null) {
- packages.add(pkg);
- visited.add(new File(target.getLocation()));
+ if (pkg != null) {
+ packages.add(pkg);
+ visited.add(new File(target.getLocation()));
+ }
}
}
monitor.incProgress(1);
- scanMissingSystemImages(sdkManager, visited, packages, monitor);
+ if ((parseFilter & PARSE_PLATFORMS) != 0) {
+ scanMissingSystemImages(sdkManager, visited, packages, monitor);
+ }
monitor.incProgress(1);
- scanMissingAddons(sdkManager, visited, packages, monitor);
+ if ((parseFilter & PARSE_ADDONS) != 0) {
+ scanMissingAddons(sdkManager, visited, packages, monitor);
+ }
monitor.incProgress(1);
- scanMissingSamples(sdkManager, visited, packages, monitor);
+ if ((parseFilter & PARSE_SAMPLES) != 0) {
+ scanMissingSamples(sdkManager, visited, packages, monitor);
+ }
monitor.incProgress(1);
- scanExtras(sdkManager, visited, packages, monitor);
+ if ((parseFilter & PARSE_EXTRAS) != 0) {
+ scanExtras(sdkManager, visited, packages, monitor);
+ }
monitor.incProgress(1);
- scanExtrasDirectory(osSdkRoot, visited, packages, monitor);
+ if ((parseFilter & PARSE_EXTRAS) != 0) {
+ scanExtrasDirectory(osSdkRoot, visited, packages, monitor);
+ }
monitor.incProgress(1);
- scanSources(sdkManager, visited, packages, monitor);
+ if ((parseFilter & PARSE_SOURCES) != 0) {
+ scanSources(sdkManager, visited, packages, monitor);
+ }
monitor.incProgress(1);
Collections.sort(packages);
diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/LocalSdkParserTest.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/LocalSdkParserTest.java index 017d17c..f66adb8 100755 --- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/LocalSdkParserTest.java +++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/LocalSdkParserTest.java @@ -40,6 +40,35 @@ public class LocalSdkParserTest extends SdkManagerTestCase { "Sources for Android SDK, API 0, revision 0]", Arrays.toString(parser.parseSdk(sdkman.getLocation(), sdkman, monitor))); + assertEquals( + "[SDK Platform Android 0.0, API 0, revision 1, " + + "Sources for Android SDK, API 0, revision 0]", + Arrays.toString(parser.parseSdk(sdkman.getLocation(), + sdkman, + LocalSdkParser.PARSE_PLATFORMS | LocalSdkParser.PARSE_SOURCES, + monitor))); + + assertEquals( + "[SDK Platform Android 0.0, API 0, revision 1]", + Arrays.toString(parser.parseSdk(sdkman.getLocation(), + sdkman, + LocalSdkParser.PARSE_PLATFORMS, + monitor))); + + assertEquals( + "[Sources for Android SDK, API 0, revision 0]", + Arrays.toString(parser.parseSdk(sdkman.getLocation(), + sdkman, + LocalSdkParser.PARSE_SOURCES, + monitor))); + + assertEquals( + "[]", + Arrays.toString(parser.parseSdk(sdkman.getLocation(), + sdkman, + LocalSdkParser.PARSE_TOOLS, + monitor))); + // Now add a few "platform subfolders" system images and reload the SDK. // This disables the "legacy" mode but it still doesn't create any system image package @@ -89,6 +118,36 @@ public class LocalSdkParserTest extends SdkManagerTestCase { "Sources for Android SDK, API 0, revision 0, " + "Broken Intel x86 Atom System Image, API 0]", Arrays.toString(parser.parseSdk(sdkman.getLocation(), sdkman, monitor))); + + assertEquals( + "[SDK Platform Android 0.0, API 0, revision 1, " + + "ARM EABI v7a System Image, Android API 0, revision 0, " + + "ARM EABI System Image, Android API 0, revision 0, " + + "Sources for Android SDK, API 0, revision 0, " + + "Broken Intel x86 Atom System Image, API 0]", + Arrays.toString(parser.parseSdk(sdkman.getLocation(), + sdkman, + LocalSdkParser.PARSE_ALL, + monitor))); + + assertEquals( + "[SDK Platform Android 0.0, API 0, revision 1, " + + "ARM EABI v7a System Image, Android API 0, revision 0, " + + "ARM EABI System Image, Android API 0, revision 0, " + + "Sources for Android SDK, API 0, revision 0, " + + "Broken Intel x86 Atom System Image, API 0]", + Arrays.toString(parser.parseSdk(sdkman.getLocation(), + sdkman, + LocalSdkParser.PARSE_PLATFORMS | // platform also loads system-images + LocalSdkParser.PARSE_SOURCES, + monitor))); + + assertEquals( + "[Sources for Android SDK, API 0, revision 0]", + Arrays.toString(parser.parseSdk(sdkman.getLocation(), + sdkman, + LocalSdkParser.PARSE_SOURCES, + monitor))); } } |