From a0fcdd03d2a6475d59441443ec21888043514ca9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 13 Oct 2011 22:43:49 -0700 Subject: [PATCH] SDK Manager: fix duplicated Extra Packages. Change-Id: I0518515a2095b63099cb69d67d110330b148d5a2 --- .../sdklib/internal/repository/Package.java | 7 ++- .../repository/sdkman2/PackagesDiffLogic.java | 55 +++++++++++++--------- 2 files changed, 39 insertions(+), 23 deletions(-) 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 57de7406f..b99da5c35 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 @@ -23,6 +23,7 @@ import com.android.sdklib.SdkManager; import com.android.sdklib.internal.repository.Archive.Arch; import com.android.sdklib.internal.repository.Archive.Os; import com.android.sdklib.repository.PkgProps; +import com.android.sdklib.repository.SdkAddonConstants; import com.android.sdklib.repository.SdkRepoConstants; import org.w3c.dom.Node; @@ -139,7 +140,11 @@ public abstract class Package implements IDescription, Comparable { // a package comes from. String srcUrl = getProperty(props, PkgProps.PKG_SOURCE_URL, null); if (props != null && source == null && srcUrl != null) { - if (this instanceof AddonPackage) { + // Both Addon and Extra packages can come from an addon source. + // For Extras, we can tell by looking at the source URL. + if (this instanceof AddonPackage || + ((this instanceof ExtraPackage) && + srcUrl.endsWith(SdkAddonConstants.URL_DEFAULT_FILENAME))) { source = new SdkAddonSource(srcUrl, null /*uiName*/); } else { source = new SdkRepoSource(srcUrl, null /*uiName*/); 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 0d517d5a2..dc1c73a42 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 @@ -24,6 +24,7 @@ import com.android.sdklib.internal.repository.PlatformToolPackage; import com.android.sdklib.internal.repository.SdkSource; import com.android.sdklib.internal.repository.ToolPackage; import com.android.sdklib.internal.repository.Package.UpdateInfo; +import com.android.sdklib.repository.SdkRepoConstants; import com.android.sdkuilib.internal.repository.UpdaterData; import com.android.sdkuilib.internal.repository.sdkman2.PkgItem.PkgState; @@ -569,15 +570,15 @@ class PackagesDiffLogic { // Object identity, so definitely the same source. Accept it. return true; + } else if (currentSource != null && currentSource.equals(newItemSource)) { + // Same source. Accept it. + return true; + } else if (currentSource != null && newItemSource != null && !currentSource.getClass().equals(newItemSource.getClass())) { // Both sources don't have the same type (e.g. sdk repository versus add-on repository) return false; - } else if (currentSource != null && currentSource.equals(newItemSource)) { - // Same source. Accept it. - return true; - } else if (currentSource == null && currentItem.getState() == PkgState.INSTALLED) { // Accept it. // If a locally installed item has no source, it probably has been @@ -587,29 +588,39 @@ class PackagesDiffLogic { } else if (currentSource != null && currentSource.getUrl().startsWith("file://")) { // Heuristic: Probably a manual local install. Accept it. return true; + } - } else { - // Reject the source mismatch. The idea is that if two remote repositories - // have similar packages, we don't want to merge them together and have - // one hide the other. This is a design error from the repository owners - // and we want the case to be blatant so that we can get it fixed. - - if (currentSource != null && newItemSource != null) { - try { - URL url1 = new URL(currentSource.getUrl()); - URL url2 = new URL(newItemSource.getUrl()); - - // Make an exception if both URLs have the same host name & domain name. - if (url1.sameFile(url2) || url1.getHost().equals(url2.getHost())) { - return true; - } - } catch (Exception ignore) { - // Ignore MalformedURLException or other exceptions + // Reject the source mismatch. The idea is that if two remote repositories + // have similar packages, we don't want to merge them together and have + // one hide the other. This is a design error from the repository owners + // and we want the case to be blatant so that we can get it fixed. + + if (currentSource != null && newItemSource != null) { + try { + String str1 = rewriteUrl(currentSource.getUrl()); + String str2 = rewriteUrl(newItemSource.getUrl()); + + URL url1 = new URL(str1); + URL url2 = new URL(str2); + + // Make an exception if both URLs have the same host name & domain name. + if (url1.sameFile(url2) || url1.getHost().equals(url2.getHost())) { + return true; } + } catch (Exception ignore) { + // Ignore MalformedURLException or other exceptions } + } - return false; + return false; + } + + private String rewriteUrl(String url) { + if (url != null && url.startsWith(SdkRepoConstants.URL_GOOGLE_SDK_SITE)) { + url = url.replaceAll("repository-[0-9]+\\.xml^", //$NON-NLS-1$ + "repository.xml"); //$NON-NLS-1$ } + return url; } private PkgCategory findCurrentCategory( -- 2.11.0