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 | |
parent | e19bfc666f085fd2bd10158d43735e9646663d44 (diff) | |
parent | 5b5bdeb7e691980a1174650ce926edbaa87a5a3e (diff) | |
download | sdk-7b4b54057e216904fc25989beb7b0b7bff874a64.zip sdk-7b4b54057e216904fc25989beb7b0b7bff874a64.tar.gz sdk-7b4b54057e216904fc25989beb7b0b7bff874a64.tar.bz2 |
Merge "NPW: Find samples in extras."
8 files changed, 408 insertions, 113 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java index 6388644..2a1fba9 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java @@ -19,6 +19,7 @@ package com.android.ide.eclipse.adt.internal.sdk; import static com.android.ide.eclipse.adt.AdtConstants.DOT_XML; import static com.android.sdklib.SdkConstants.FD_RES; +import com.android.annotations.NonNull; import com.android.ddmlib.IDevice; import com.android.ide.common.rendering.LayoutLibrary; import com.android.ide.common.sdk.LoadStatus; @@ -303,6 +304,25 @@ public final class Sdk { } /** + * Returns a <em>new</em> {@link SdkManager} that can parse the SDK located + * at the current {@link #getSdkLocation()}. + * <p/> + * Implementation detail: The {@link Sdk} has its own internal manager with + * a custom logger which is not designed to be useful for outsiders. Callers + * who need their own {@link SdkManager} for parsing will often want to control + * the logger for their own need. + * <p/> + * This is just a convenient method equivalent to writing: + * <pre>SdkManager.createManager(Sdk.getCurrent().getSdkLocation(), log);</pre> + * + * @param log The logger for the {@link SdkManager}. + * @return A new {@link SdkManager} parsing the same location. + */ + public @NonNull SdkManager getNewSdkManager(@NonNull ISdkLog log) { + return SdkManager.createManager(getSdkLocation(), log); + } + + /** * Returns the URL to the local documentation. * Can return null if no documentation is found in the current SDK. * diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizardState.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizardState.java index 33f9884..264f09d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizardState.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizardState.java @@ -26,6 +26,7 @@ import com.android.sdklib.internal.project.ProjectProperties.PropertyType; import com.android.sdklib.xml.AndroidManifest; import com.android.sdklib.xml.ManifestData; import com.android.sdklib.xml.ManifestData.Activity; +import com.android.util.Pair; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Path; @@ -94,14 +95,12 @@ public class NewProjectWizardState { public String minSdk; /** True if the minimum SDK version has been manually edited by the user */ public boolean minSdkModifiedByUser; - /** - * The directory where the samples are found. This field is only applicable - * when the wizard is running in create-sample-mode. - */ - public File samplesDir; - /** A list of paths to each of the available samples for the current SDK */ - public List<File> samples = new ArrayList<File>(); + * A list of paths to each of the available samples for the current SDK. + * The pair is (String: sample display name => File: sample directory). + * Note we want a list, not a map since we might have duplicates. + * */ + public List<Pair<String, File>> samples = new ArrayList<Pair<String, File>>(); /** Path to the currently chosen sample */ public File chosenSample; @@ -396,4 +395,4 @@ public class NewProjectWizardState { */ ANY; } -}
\ No newline at end of file +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/SampleSelectionPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/SampleSelectionPage.java index d54697f..ef16d3d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/SampleSelectionPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/SampleSelectionPage.java @@ -18,6 +18,7 @@ package com.android.ide.eclipse.adt.internal.wizards.newproject; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectWizardState.Mode; import com.android.sdklib.IAndroidTarget; +import com.android.util.Pair; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; @@ -43,7 +44,6 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import java.io.File; -import java.util.regex.Pattern; /** Page where the user can select a sample to "instantiate" */ class SampleSelectionPage extends WizardPage implements SelectionListener, ModifyListener { @@ -125,21 +125,11 @@ class SampleSelectionPage extends WizardPage implements SelectionListener, Modif @Override public String getText(Object element) { - File file = (File) element; - String path = file.getPath(); - int n = mValues.samplesDir.getPath().length(); - if (path.length() > n) { - path = path.substring(n); - if (path.charAt(0) == File.separatorChar) { - path = path.substring(1); - } - if (path.endsWith(File.separator)) { - path = path.substring(0, path.length() - 1); - } - path = path.replaceAll(Pattern.quote(File.separator), " > "); + if (element instanceof Pair<?, ?>) { + Object name = ((Pair<?, ?>) element).getFirst(); + return name.toString(); } - - return path; + return element.toString(); // Fallback. Should not happen. } }; @@ -151,7 +141,7 @@ class SampleSelectionPage extends WizardPage implements SelectionListener, Modif mTableViewer.setInput(samples); mTable.select(0); - selectSample(mValues.samples.get(0)); + selectSample(mValues.samples.get(0).getSecond()); extractNamesFromAndroidManifest(); } } @@ -170,6 +160,7 @@ class SampleSelectionPage extends WizardPage implements SelectionListener, Modif } } + @SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e) { if (mIgnore) { @@ -181,7 +172,7 @@ class SampleSelectionPage extends WizardPage implements SelectionListener, Modif int index = mTable.getSelectionIndex(); if (index >= 0) { Object[] roots = (Object[]) mTableViewer.getInput(); - selectSample((File) roots[index]); + selectSample(((Pair<String, File>) roots[index]).getSecond()); } else { selectSample(null); } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/SdkSelectionPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/SdkSelectionPage.java index 11d0e95..2713f01 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/SdkSelectionPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/SdkSelectionPage.java @@ -15,17 +15,25 @@ */ package com.android.ide.eclipse.adt.internal.wizards.newproject; +import com.android.annotations.Nullable; import com.android.ide.common.sdk.LoadStatus; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.sdk.Sdk; import com.android.ide.eclipse.adt.internal.sdk.Sdk.ITargetChangeListener; import com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectWizardState.Mode; +import com.android.io.FileWrapper; import com.android.sdklib.AndroidVersion; import com.android.sdklib.IAndroidTarget; +import com.android.sdklib.NullSdkLog; import com.android.sdklib.SdkConstants; +import com.android.sdklib.SdkManager; +import com.android.sdklib.xml.AndroidManifestParser; +import com.android.sdklib.xml.ManifestData; import com.android.sdkuilib.internal.widgets.SdkTargetSelector; +import com.android.util.Pair; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -38,7 +46,11 @@ import org.eclipse.swt.widgets.Group; import java.io.File; import java.util.Collections; +import java.util.Comparator; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.regex.Pattern; /** A page in the New Project wizard where you select the target SDK */ class SdkSelectionPage extends WizardPage implements ITargetChangeListener { @@ -196,21 +208,43 @@ class SdkSelectionPage extends WizardPage implements ITargetChangeListener { // Get the sample root path and recompute the list of samples String samplesRootPath = target.getPath(IAndroidTarget.SAMPLES); - mValues.samplesDir = new File(samplesRootPath); - findSamplesManifests(mValues.samplesDir, mValues.samples); + File root = new File(samplesRootPath); + findSamplesManifests(root, root, null, null, mValues.samples); + + Sdk sdk = Sdk.getCurrent(); + if (sdk != null) { + // Parse the extras to see if we can find samples that are + // compatible with the selected target API. + // First we need an SdkManager that suppresses all output. + SdkManager sdkman = sdk.getNewSdkManager(new NullSdkLog()); + + Map<File, String> extras = sdkman.getExtraSamples(); + for (Entry<File, String> entry : extras.entrySet()) { + File path = entry.getKey(); + String name = entry.getValue(); + findSamplesManifests(path, path, name, + target.getVersion(), + mValues.samples); + } + } - if (mValues.samples.size() == 0) { + if (mValues.samples.isEmpty()) { return; } else { - Collections.sort(mValues.samples); + Collections.sort(mValues.samples, new Comparator<Pair<String, File>>() { + @Override + public int compare(Pair<String, File> o1, Pair<String, File> o2) { + // Compare the display name of the sample + return o1.getFirst().compareTo(o2.getFirst()); + } + }); } - // Recompute the description of each sample (the relative path - // to the sample root). Also try to find the old selection. + // Try to find the old selection. if (previouslyChosenSample != null) { String previouslyChosenName = previouslyChosenSample.getName(); for (int i = 0, n = mValues.samples.size(); i < n; i++) { - File file = mValues.samples.get(i); + File file = mValues.samples.get(i).getSecond(); if (file.getName().equals(previouslyChosenName)) { mValues.chosenSample = file; break; @@ -224,18 +258,61 @@ class SdkSelectionPage extends WizardPage implements ITargetChangeListener { * Recursively find potential sample directories under the given directory. * Actually lists any directory that contains an android manifest. * Paths found are added the samplesPaths list. + * + * @param rootDir The "samples" root directory. Doesn't change during recursion. + * @param currDir The directory being scanned. Caller must initially set it to {@code rootDir}. + * @param extraName Optional name appended to the samples display name. Typically used to + * indicate a sample comes from a given extra package. + * @param targetVersion Optional target version filter. If non null, only samples that are + * compatible with the given target will be listed. + * @param samplesPaths A non-null list filled by this method with all samples found. The + * pair is (String: sample display name => File: sample directory). */ - private void findSamplesManifests(File samplesDir, List<File> samplesPaths) { - if (!samplesDir.isDirectory()) { + private void findSamplesManifests( + File rootDir, + File currDir, + @Nullable String extraName, + @Nullable AndroidVersion targetVersion, + List<Pair<String, File>> samplesPaths) { + if (!currDir.isDirectory()) { return; } - for (File f : samplesDir.listFiles()) { + for (File f : currDir.listFiles()) { if (f.isDirectory()) { // Assume this is a sample if it contains an android manifest. File manifestFile = new File(f, SdkConstants.FN_ANDROID_MANIFEST_XML); if (manifestFile.isFile()) { - samplesPaths.add(f); + try { + ManifestData data = + AndroidManifestParser.parse(new FileWrapper(manifestFile)); + if (data != null) { + boolean accept = false; + if (targetVersion == null) { + accept = true; + } else if (targetVersion != null) { + int i = data.getMinSdkVersion(); + if (i != ManifestData.MIN_SDK_CODENAME) { + accept = i <= targetVersion.getApiLevel(); + } else { + String s = data.getMinSdkVersionString(); + if (s != null) { + accept = s.equals(targetVersion.getCodename()); + } + } + } + + if (accept) { + String name = getSampleDisplayName(extraName, rootDir, f); + samplesPaths.add(Pair.of(name, f)); + } + } + } catch (Exception e) { + // Ignore. Don't use a sample which manifest doesn't parse correctly. + AdtPlugin.log(IStatus.INFO, + "NPW ignoring malformed manifest %s", //$NON-NLS-1$ + manifestFile.getAbsolutePath()); + } } // Recurse in the project, to find embedded tests sub-projects @@ -245,12 +322,35 @@ class SdkSelectionPage extends WizardPage implements ITargetChangeListener { if (!SdkConstants.FD_SOURCES.equals(leaf) && !SdkConstants.FD_ASSETS.equals(leaf) && !SdkConstants.FD_RES.equals(leaf)) { - findSamplesManifests(f, samplesPaths); + findSamplesManifests(rootDir, f, extraName, targetVersion, samplesPaths); } } } } + /** + * Compute the sample name compared to its root directory. + */ + private String getSampleDisplayName(String extraName, File rootDir, File sampleDir) { + String path = sampleDir.getPath(); + int n = rootDir.getPath().length(); + if (path.length() > n) { + path = path.substring(n); + if (path.charAt(0) == File.separatorChar) { + path = path.substring(1); + } + if (path.endsWith(File.separator)) { + path = path.substring(0, path.length() - 1); + } + path = path.replaceAll(Pattern.quote(File.separator), " > "); //$NON-NLS-1$ + } + if (extraName != null) { + path = path + " [" + extraName + ']'; //$NON-NLS-1$ + } + + return path; + } + private void validatePage() { String error = null; 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))); } } |