aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2010-10-28 16:41:49 -0700
committerRaphael Moll <ralf@android.com>2010-10-28 16:47:49 -0700
commitca4d338fa41f41e45502842c06b9dfafe5936ba2 (patch)
tree6ac569d67c41b7422585da8c963e67897fda7057 /sdkmanager
parent7fe4b7b04a46c13355509559d88bad24fcc6a5dc (diff)
downloadsdk-ca4d338fa41f41e45502842c06b9dfafe5936ba2.zip
sdk-ca4d338fa41f41e45502842c06b9dfafe5936ba2.tar.gz
sdk-ca4d338fa41f41e45502842c06b9dfafe5936ba2.tar.bz2
SDK Manager: fix suggestions of new platforms.
I accidentally broke the way the SDK Manager was suggesting new platforms when I "optimized" the way it was fetching new sources when resolving dependencies. The fix is that even if we don't need to refresh or fetch a source, we still need to report the packages we know it contains. Also made the Archive and ArchiveInfo implement Comparable and defer their comparison to the one of Package. This way we can sort the archives in the install window. Change-Id: Ic3b39e49e8143541b19b00de09468c1b3f01b0d7
Diffstat (limited to 'sdkmanager')
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Archive.java14
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java24
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ArchiveInfo.java15
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java5
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterLogic.java53
5 files changed, 89 insertions, 22 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Archive.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Archive.java
index 8b61637..10e6424 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Archive.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Archive.java
@@ -44,7 +44,7 @@ import java.util.Properties;
* <p/>
* Packages are offered by a {@link SdkSource} (a download site).
*/
-public class Archive implements IDescription {
+public class Archive implements IDescription, Comparable<Archive> {
public static final int NUM_MONITOR_INC = 100;
private static final String PROP_OS = "Archive.Os"; //$NON-NLS-1$
@@ -1099,4 +1099,16 @@ public class Archive implements IDescription {
"chmod", "777", file.getAbsolutePath()
});
}
+
+ /**
+ * Archives are compared using their {@link Package} ordering.
+ *
+ * @see Package#compareTo(Package)
+ */
+ public int compareTo(Archive rhs) {
+ if (mPackage != null && rhs != null) {
+ return mPackage.compareTo(rhs.getParentPackage());
+ }
+ return 0;
+ }
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java
index a6c28a9..438b07b 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java
@@ -503,18 +503,18 @@ public abstract class Package implements IDescription, Comparable<Package> {
/**
- * Returns an ordering like this:
- * - Tools.
- * - Platform-Tools.
- * - Docs.
- * - Platform n preview
- * - Platform n
- * - Platform n-1
- * - Samples packages.
- * - Add-on based on n preview
- * - Add-on based on n
- * - Add-on based on n-1
- * - Extra packages.
+ * Returns an ordering like this: <br/>
+ * - Tools <br/>
+ * - Platform-Tools <br/>
+ * - Docs. <br/>
+ * - Platform n preview <br/>
+ * - Platform n <br/>
+ * - Platform n-1 <br/>
+ * - Samples packages <br/>
+ * - Add-on based on n preview <br/>
+ * - Add-on based on n <br/>
+ * - Add-on based on n-1 <br/>
+ * - Extra packages <br/>
*/
public int compareTo(Package other) {
int s1 = this.sortingScore();
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ArchiveInfo.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ArchiveInfo.java
index 15560b7..d01570d 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ArchiveInfo.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ArchiveInfo.java
@@ -42,7 +42,7 @@ import java.util.Collection;
*
* @see ArchiveInfo#ArchiveInfo(Archive, Archive, ArchiveInfo[])
*/
-class ArchiveInfo implements IDescription {
+class ArchiveInfo implements IDescription, Comparable<ArchiveInfo> {
private final Archive mNewArchive;
private final Archive mReplaced;
@@ -205,4 +205,17 @@ class ArchiveInfo implements IDescription {
}
return super.toString();
}
+
+ /**
+ * ArchiveInfos are compared using ther "new archive" ordering.
+ *
+ * @see Archive#compareTo(Archive)
+ */
+ public int compareTo(ArchiveInfo rhs) {
+ if (mNewArchive != null && rhs != null) {
+ return mNewArchive.compareTo(rhs.getNewArchive());
+ }
+ return 0;
+ }
+
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
index fe51f19..a1c089b 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
@@ -51,6 +51,7 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -639,6 +640,8 @@ class UpdaterData implements IUpdaterData {
// TODO if selectedArchives is null and archives.len==0, find if there are
// any new platform we can suggest to install instead.
+ Collections.sort(archives);
+
UpdateChooserDialog dialog = new UpdateChooserDialog(getWindowShell(), this, archives);
dialog.open();
@@ -680,6 +683,8 @@ class UpdaterData implements IUpdaterData {
getLocalSdkParser().getPackages(),
includeObsoletes);
+ Collections.sort(archives);
+
// Filter the selected archives to only keep the ones matching the filter
if (pkgFilter != null && pkgFilter.size() > 0 && archives != null && archives.size() > 0) {
// Map filter types to an SdkRepository Package type.
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterLogic.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterLogic.java
index 4380ca8..f57213c 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterLogic.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterLogic.java
@@ -962,7 +962,24 @@ class UpdaterLogic {
return new MissingPlatformArchiveInfo(new AndroidVersion(api, null /*codename*/));
}
- /** Fetch all remote packages only if really needed. */
+ /**
+ * Fetch all remote packages only if really needed.
+ * <p/>
+ * This method takes a list of sources. Each source is only fetched once -- that is each
+ * source keeps the list of packages that we fetched from the remote XML file. If the list
+ * is null, it means this source has never been fetched so we'll do it once here. Otherwise
+ * we rely on the cached list of packages from this source.
+ * <p/>
+ * This method also takes a remote package list as input, which it will fill out.
+ * If a source has already been fetched, we'll add its packages to the remote package list
+ * if they are not already present. Otherwise, the source will be fetched and the packages
+ * added to the list.
+ *
+ * @param remotePkgs An in-out list of packages available from remote sources.
+ * This list must not be null.
+ * It can be empty or already contain some packages.
+ * @param remoteSources A list of available remote sources to fetch from.
+ */
protected void fetchRemotePackages(
final ArrayList<Package> remotePkgs,
final SdkSource[] remoteSources) {
@@ -975,9 +992,27 @@ class UpdaterLogic {
// necessary.
boolean needsFetch = false;
for (final SdkSource remoteSrc : remoteSources) {
- needsFetch = remoteSrc.getPackages() == null;
- if (needsFetch) {
- break;
+ Package[] pkgs = remoteSrc.getPackages();
+ if (pkgs == null) {
+ // This source has never been fetched. We'll do it below.
+ needsFetch = true;
+ } else {
+ // This source has already been fetched and we know its package list.
+ // We still need to make sure all of its packages are present in the
+ // remotePkgs list.
+
+ nextPackage: for (Package pkg : pkgs) {
+ for (Archive a : pkg.getArchives()) {
+ // Only add a package if it contains at least one compatible archive
+ // and is not already in the remote package list.
+ if (a.isCompatible()) {
+ if (!remotePkgs.contains(pkg)) {
+ remotePkgs.add(pkg);
+ continue nextPackage;
+ }
+ }
+ }
+ }
}
}
@@ -1000,11 +1035,13 @@ class UpdaterLogic {
if (pkgs != null) {
nextPackage: for (Package pkg : pkgs) {
for (Archive a : pkg.getArchives()) {
- // Only add a package if it contains at least
- // one compatible archive
+ // Only add a package if it contains at least one compatible archive
+ // and is not already in the remote package list.
if (a.isCompatible()) {
- remotePkgs.add(pkg);
- continue nextPackage;
+ if (!remotePkgs.contains(pkg)) {
+ remotePkgs.add(pkg);
+ continue nextPackage;
+ }
}
}
}