From 68ce843e28c93465c48db84de09821347cdc8f6a Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 5 Oct 2011 13:36:29 -0700 Subject: [PATCH] SDK Manager: fix handling of source URLs. Do not merge. This changes how source URLs are handled. Packages from different sources were previously treated as separate if the packages were the same (e.g. same platform API) but the source URLs were different. Instead this checks the hostname+domain name of the URL is different, as well as the type of the source (that is a sdk repository vs addon repository). (cherry picked from commit d66d4b7804ce5585bed335168a0c7f3f178a11b0) Change-Id: Ic127c4111e5028d467ad89c987c5f39cb8f8e8d7 --- .../repository/sdkman2/PackagesDiffLogic.java | 27 ++++++++- .../repository/sdkman2/PackagesDiffLogicTest.java | 70 ++++++++++++---------- 2 files changed, 63 insertions(+), 34 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 ab2d43984..3a7029420 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 @@ -19,14 +19,15 @@ package com.android.sdkuilib.internal.repository.sdkman2; import com.android.sdklib.IAndroidTarget; import com.android.sdklib.internal.repository.IPackageVersion; import com.android.sdklib.internal.repository.Package; -import com.android.sdklib.internal.repository.Package.UpdateInfo; import com.android.sdklib.internal.repository.PlatformPackage; 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.sdkuilib.internal.repository.UpdaterData; import com.android.sdkuilib.internal.repository.sdkman2.PkgItem.PkgState; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -562,9 +563,14 @@ class PackagesDiffLogic { // Only process items matching the current source. if (currentSource == newItemSource) { - // Same source. accept it. + // Object identity, so definitely the 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; @@ -576,7 +582,7 @@ class PackagesDiffLogic { return true; } else if (currentSource != null && currentSource.getUrl().startsWith("file://")) { - // Probably a manual local install. Accept it. + // Heuristic: Probably a manual local install. Accept it. return true; } else { @@ -584,6 +590,21 @@ class PackagesDiffLogic { // 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 + } + } + return false; } } diff --git a/sdkmanager/libs/sdkuilib/tests/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogicTest.java b/sdkmanager/libs/sdkuilib/tests/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogicTest.java index 5444dff48..eeec34187 100755 --- a/sdkmanager/libs/sdkuilib/tests/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogicTest.java +++ b/sdkmanager/libs/sdkuilib/tests/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogicTest.java @@ -339,8 +339,8 @@ public class PackagesDiffLogicTest extends TestCase { } public void testSortByApi_CompleteUpdate() { - SdkSource src1 = new SdkRepoSource("http://example.com/url1", "repo1"); - SdkSource src2 = new SdkRepoSource("http://example.com/url2", "repo2"); + SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); + SdkSource src2 = new SdkRepoSource("http://2.example.com/url2", "repo2"); // Resulting categories are sorted by Tools, descending platform API and finally Extras. // Addons are sorted by name within their API. @@ -675,8 +675,8 @@ public class PackagesDiffLogicTest extends TestCase { } public void testSortBySource_CompleteUpdate() { - SdkSource src1 = new SdkRepoSource("http://example.com/url1", "repo1"); - SdkSource src2 = new SdkRepoSource("http://example.com/url2", "repo2"); + SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); + SdkSource src2 = new SdkRepoSource("http://2.example.com/url2", "repo2"); // First update has the typical tools and a couple extras m.updateStart(); @@ -695,7 +695,7 @@ public class PackagesDiffLogicTest extends TestCase { assertTrue(m.updateEnd(false /*sortByApi*/)); assertEquals( - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + "-- \n" + "-- \n" + @@ -735,7 +735,7 @@ public class PackagesDiffLogicTest extends TestCase { assertTrue(m.updateEnd(false /*sortByApi*/)); assertEquals( - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + "-- \n" + "-- \n" + @@ -743,7 +743,7 @@ public class PackagesDiffLogicTest extends TestCase { "-- \n" + "-- \n" + "-- \n" + - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + "-- \n" + "-- \n", @@ -783,7 +783,7 @@ public class PackagesDiffLogicTest extends TestCase { assertTrue(m.updateEnd(false /*sortByApi*/)); assertEquals( - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + "-- \n" + "-- \n" + @@ -791,7 +791,7 @@ public class PackagesDiffLogicTest extends TestCase { "-- \n" + "-- \n" + "-- \n" + - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + "-- \n" + "-- \n", @@ -857,8 +857,8 @@ public class PackagesDiffLogicTest extends TestCase { // Populate the list with typical items: tools, platforms tools, extras, 2 platforms. // With nothing installed, this should pick the tools, extras and the top platform. - SdkSource src1 = new SdkRepoSource("http://example.com/url1", "repo1"); - SdkSource src2 = new SdkRepoSource("http://example.com/url2", "repo2"); + SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); + SdkSource src2 = new SdkRepoSource("http://2.example.com/url2", "repo2"); m.updateStart(); MockPlatformPackage p1; @@ -895,13 +895,13 @@ public class PackagesDiffLogicTest extends TestCase { "-- < * NEW, pkg:Carrier Custom Rom package, revision 1>\n", getTree(m, true /*displaySortByApi*/)); assertEquals( - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- < * NEW, pkg:Android SDK Tools, revision 10>\n" + "-- < * NEW, pkg:Android SDK Platform-tools, revision 3>\n" + "-- < * NEW, pkg:SDK Platform Android android-2, API 2, revision 4>\n" + "-- \n" + "-- < * NEW, pkg:Android USB Driver package, revision 5>\n" + - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- < * NEW, pkg:addon B by vendor 2, Android API 2, revision 7>\n" + "-- \n" + "-- < * NEW, pkg:Carrier Custom Rom package, revision 1>\n", @@ -947,13 +947,13 @@ public class PackagesDiffLogicTest extends TestCase { "-- < * NEW, pkg:Carrier Custom Rom package, revision 1>\n", getTree(m, true /*displaySortByApi*/)); assertEquals( - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + "-- < * NEW, pkg:Android SDK Platform-tools, revision 3>\n" + "-- < * NEW, pkg:SDK Platform Android android-2, API 2, revision 4>\n" + "-- < * NEW, pkg:SDK Platform Android android-1, API 1, revision 2>\n" + "-- < * NEW, pkg:Android USB Driver package, revision 5>\n" + - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- < * NEW, pkg:addon B by vendor 2, Android API 2, revision 7>\n" + "-- \n" + "-- < * NEW, pkg:Carrier Custom Rom package, revision 1>\n", @@ -1084,11 +1084,14 @@ public class PackagesDiffLogicTest extends TestCase { public void testSourceDups() { // This tests an edge case were 2 remote repositories are giving the // same kind of packages. We don't want to merge them together or treat - // them as upgrades to each other. + // them as upgrades to each other, unless they have the same hostname. + // repo1, 2 and 3 have the same hostname so redundancy is ok SdkSource src1 = new SdkRepoSource("http://example.com/url1", "repo1"); SdkSource src2 = new SdkRepoSource("http://example.com/url2", "repo2"); SdkSource src3 = new SdkRepoSource("http://example.com/url3", "repo3"); + // repo4 has a different hostname so its packages won't hide the ones from the other repos + SdkSource src4 = new SdkRepoSource("http://4.example.com/url4", "repo4"); MockPlatformPackage p1 = null; m.updateStart(); @@ -1105,6 +1108,10 @@ public class PackagesDiffLogicTest extends TestCase { new MockAddonPackage(src3, "addon A", p1, 5), // same as addon A rev 5 from src2 new MockAddonPackage(src3, "addon B", p1, 7), // upgrades addon B rev 6 from src2 }); + m.updateSourcePackages(true /*sortByApi*/, src4, new Package[] { + new MockAddonPackage(src4, "addon A", p1, 5), // same as addon A rev 5 from src2 + new MockAddonPackage(src4, "addon B", p1, 7), // upgrades addon B rev 6 from src2 + }); m.updateEnd(true /*sortByApi*/); // The remote packages in rev 3 are hidden by the local packages in rev 5 @@ -1114,10 +1121,10 @@ public class PackagesDiffLogicTest extends TestCase { "-- \n" + "PkgCategoryApi \n" + "-- \n" + - "-- \n" + - "-- \n" + - "-- \n" + - "-- \n" + + "-- \n" + // from src2+3 + "-- \n" + // from scr4 + "-- \n" + // from src2+3 + "-- \n" + // from src4 "PkgCategoryApi \n", getTree(m, true /*displaySortByApi*/)); assertEquals( @@ -1125,10 +1132,11 @@ public class PackagesDiffLogicTest extends TestCase { "-- \n" + "-- \n" + "-- \n" + - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + - "-- \n" + - "PkgCategorySource \n" + + "PkgCategorySource \n" + + "-- \n" + + "PkgCategorySource \n" + "-- \n" + "-- \n", getTree(m, false /*displaySortByApi*/)); @@ -1193,8 +1201,8 @@ public class PackagesDiffLogicTest extends TestCase { public void testBrokenAddon() { - SdkSource src1 = new SdkRepoSource("http://example.com/url1", "repo1"); - SdkSource src2 = new SdkRepoSource("http://example.com/url2", "repo2"); + SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); + SdkSource src2 = new SdkRepoSource("http://2.example.com/url2", "repo2"); MockPlatformPackage p1 = null; MockAddonPackage a1 = null; @@ -1220,9 +1228,9 @@ public class PackagesDiffLogicTest extends TestCase { "PkgCategoryApi \n", getTree(m, true /*displaySortByApi*/)); assertEquals( - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n", getTree(m, false /*displaySortByApi*/)); @@ -1248,9 +1256,9 @@ public class PackagesDiffLogicTest extends TestCase { "-- \n", getTree(m, true /*displaySortByApi*/)); assertEquals( - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + "PkgCategorySource \n" + "-- \n", @@ -1277,9 +1285,9 @@ public class PackagesDiffLogicTest extends TestCase { "PkgCategoryApi \n", getTree(m, true /*displaySortByApi*/)); assertEquals( - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n" + - "PkgCategorySource \n" + + "PkgCategorySource \n" + "-- \n", getTree(m, false /*displaySortByApi*/)); } -- 2.11.0