OSDN Git Service

SDK Manager: fix duplicated Extra Packages. Do not merge.
authorRaphael <raphael@google.com>
Fri, 14 Oct 2011 05:43:49 +0000 (22:43 -0700)
committerRaphael Moll <raphael@google.com>
Mon, 17 Oct 2011 17:53:33 +0000 (10:53 -0700)
(cherry picked from commit a0fcdd03d2a6475d59441443ec21888043514ca9)

Change-Id: I24dece735bd55a6f1a0f03c29218386ac4a31738

sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java
sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java

index 57de740..b99da5c 100755 (executable)
@@ -23,6 +23,7 @@ import com.android.sdklib.SdkManager;
 import com.android.sdklib.internal.repository.Archive.Arch;\r
 import com.android.sdklib.internal.repository.Archive.Os;\r
 import com.android.sdklib.repository.PkgProps;\r
+import com.android.sdklib.repository.SdkAddonConstants;\r
 import com.android.sdklib.repository.SdkRepoConstants;\r
 \r
 import org.w3c.dom.Node;\r
@@ -139,7 +140,11 @@ public abstract class Package implements IDescription, Comparable<Package> {
         // a package comes from.\r
         String srcUrl = getProperty(props, PkgProps.PKG_SOURCE_URL, null);\r
         if (props != null && source == null && srcUrl != null) {\r
-            if (this instanceof AddonPackage) {\r
+            // Both Addon and Extra packages can come from an addon source.\r
+            // For Extras, we can tell by looking at the source URL.\r
+            if (this instanceof AddonPackage ||\r
+                    ((this instanceof ExtraPackage) &&\r
+                     srcUrl.endsWith(SdkAddonConstants.URL_DEFAULT_FILENAME))) {\r
                 source = new SdkAddonSource(srcUrl, null /*uiName*/);\r
             } else {\r
                 source = new SdkRepoSource(srcUrl, null /*uiName*/);\r
index 2f440fb..d8f1d72 100755 (executable)
@@ -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;
 
@@ -566,15 +567,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
@@ -584,29 +585,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(