diff options
author | Raphael <raphael@google.com> | 2012-01-10 14:20:02 -0800 |
---|---|---|
committer | Raphael <raphael@google.com> | 2012-01-10 14:26:02 -0800 |
commit | 55df5e74ffea1cc16e964807ec91fb39d462e118 (patch) | |
tree | baf09c61b2a28242f6a9e4e64fcfe02dbf03bf5d /sdkmanager/libs/sdkuilib | |
parent | f3d0c34a4626fb7086c1e1330fd4f540c1653177 (diff) | |
download | sdk-55df5e74ffea1cc16e964807ec91fb39d462e118.zip sdk-55df5e74ffea1cc16e964807ec91fb39d462e118.tar.gz sdk-55df5e74ffea1cc16e964807ec91fb39d462e118.tar.bz2 |
SDK Manager: fix missing label in Source categories.
When listing packages by "repository" (e.g. by source URL),
the name of external source isn't always set. It turns out
that when processing packages, we load local packages first
and only their source URL is known, not the "UI name" of the
source so this results in categories with no known UI name
*if* they have at least one local package installed.
This changes the package loader so that it will try to adjust
the label of a source even if it's loaded after the category
has been created.
Change-Id: I285fdefdae99c635d9fd139ca50d17706eea3ae6
Diffstat (limited to 'sdkmanager/libs/sdkuilib')
2 files changed, 46 insertions, 0 deletions
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java index e72c128..fde9b90 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java @@ -268,6 +268,8 @@ class PackagesDiffLogic { /** Creates the category for the given key and returns it. */ public abstract PkgCategory createCategory(Object catKey); + /** Adjust attributes of an existing category. */ + public abstract void adjustCategory(PkgCategory cat, Object catKey); /** Sorts the category list (but not the items within the categories.) */ public abstract void sortCategoryList(); @@ -565,6 +567,9 @@ class PackagesDiffLogic { cats.add(cat); } op.sortCategoryList(); + } else { + // Not a new category. Give op a chance to adjust the category attributes + op.adjustCategory(cat, catKey); } PkgItem item = new PkgItem(pkg, state); @@ -677,6 +682,11 @@ class PackagesDiffLogic { } @Override + public void adjustCategory(PkgCategory cat, Object catKey) { + // Pass. Nothing to do for API-sorted categories + } + + @Override public void sortCategoryList() { // Sort the categories list. // We always want categories in order tools..platforms..extras. @@ -767,12 +777,35 @@ class PackagesDiffLogic { } } + /** + * Create a new source category. + * <p/> + * One issue is that local archives are processed first and we don't have the + * full source information on them (e.g. we know the referral URL but not + * the referral name of the site). + * In this case this will just create {@link PkgCategorySource} where the label isn't + * known yet. + */ @Override public PkgCategory createCategory(Object catKey) { assert catKey instanceof SdkSource; PkgCategory cat = new PkgCategorySource((SdkSource) catKey, mUpdaterData); return cat; + } + /** + * Checks whether the category needs to be adjust. + * As mentioned in {@link #createCategory(Object)}, local archives are processed + * first and result in a {@link PkgCategorySource} where the label isn't known. + * Once we process the external source with the actual name, we'll update it. + */ + @Override + public void adjustCategory(PkgCategory cat, Object catKey) { + assert cat instanceof PkgCategorySource; + assert catKey instanceof SdkSource; + if (cat instanceof PkgCategorySource) { + ((PkgCategorySource) cat).adjustLabel((SdkSource) catKey); + } } @Override diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgCategorySource.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgCategorySource.java index bc37ff7..5b589d0 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgCategorySource.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgCategorySource.java @@ -31,6 +31,11 @@ class PkgCategorySource extends PkgCategory { new SdkRepoSource("http://no.source", "Local Packages"); private final SdkSource mSource; + /** + * Creates a new {@link PkgCategorySource}. + * This uses {@link SdkSource#toString()} to get the source's description. + * Note that if the name of the source isn't known, the description will use its URL. + */ public PkgCategorySource(SdkSource source, UpdaterData updaterData) { super( source, // the source is the key and it can be null @@ -52,4 +57,12 @@ class PkgCategorySource extends PkgCategory { public SdkSource getSource() { return mSource; } + + /** Sets the label to match the source's UI name if the label wasn't already set. */ + public void adjustLabel(SdkSource source) { + if (getLabel() == null || getLabel().startsWith("http")) { //$NON-NLS-1$ + setLabel(source == UNKNOWN_SOURCE ? "Local Packages" : source.toString()); + } + } + } |