From 1cf0c7fe0ecc5d412910669520a7ab19988bcdee Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 7 Aug 2009 16:36:19 -0700 Subject: [PATCH] BUG 2042088 : SDK Updater: we want to keep getenv(TEMP_SDK_URL) Renamed the getenv and added one for user sources. Added a (naive) check to prevent duplicate URLs. Also fixed the repositoy.xml download error message, it was not displaying the reason of failure correctly. --- .../internal/repository/RepoSource.java | 22 ++++++++++++++- .../internal/repository/RepoSources.java | 19 ++++++++++++- .../repository/UpdaterWindowImpl.java | 27 +++++++++++++++++-- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java b/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java index cce65bd88..1d76655bd 100755 --- a/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java +++ b/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java @@ -56,6 +56,9 @@ public class RepoSource implements IDescription { /** * Constructs a new source for the given repository URL. + * @param url The source URL. Cannot be null. If the URL ends with a /, the default + * repository.xml filename will be appended automatically. + * @param userSource True if this a user source (add-ons & packages only.) */ public RepoSource(String url, boolean userSource) { @@ -72,6 +75,23 @@ public class RepoSource implements IDescription { setDefaultDescription(); } + /** + * Two repo source are equal if they have the same userSource flag and the same URL. + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof RepoSource) { + RepoSource rs = (RepoSource) obj; + return rs.isUserSource() == this.isUserSource() && rs.getUrl().equals(this.getUrl()); + } + return false; + } + + @Override + public int hashCode() { + return mUrl.hashCode() ^ Boolean.valueOf(mUserSource).hashCode(); + } + /** Returns true if this is a user source. We only load addon and extra packages * from a user source and ignore the rest. */ public boolean isUserSource() { @@ -176,7 +196,7 @@ public class RepoSource implements IDescription { } } - monitor.setResult("Failed to fetch URL %1$s, reason:", url, reason); + monitor.setResult("Failed to fetch URL %1$s, reason: %2$s", url, reason); } monitor.incProgress(1); diff --git a/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSources.java b/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSources.java index 7af6657ae..e0452b8e4 100755 --- a/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSources.java +++ b/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSources.java @@ -95,7 +95,10 @@ public class RepoSources { for (int i = 0; i < count; i++) { String url = props.getProperty(String.format("%s%02d", KEY_SRC, i)); //$NON-NLS-1$ if (url != null) { - mSources.add(new RepoSource(url, true /*userSource*/)); + RepoSource s = new RepoSource(url, true /*userSource*/); + if (!hasSource(s)) { + mSources.add(s); + } } } } @@ -119,6 +122,20 @@ public class RepoSources { } } + /** + * Returns true if there's already a similar source in the sources list. + *

+ * The search is O(N), which should be acceptable on the expectedly small source list. + */ + public boolean hasSource(RepoSource source) { + for (RepoSource s : mSources) { + if (s.equals(source)) { + return true; + } + } + return false; + } + /** * Saves all the user sources. * @param log diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java index 20f1abbe8..b9cf0a494 100755 --- a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java +++ b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java @@ -335,17 +335,40 @@ public class UpdaterWindowImpl { RepoSources sources = mUpdaterData.getSources(); sources.add(new RepoSource(SdkRepository.URL_GOOGLE_SDK_REPO_SITE, false /*userSource*/)); - String str = System.getenv("TEMP_SDK_URL"); // TODO STOPSHIP temporary remove before shipping + // SDK_UPDATER_URLS is a semicolon-separated list of URLs that can be used to + // seed the SDK Updater list for full repositories. + String str = System.getenv("SDK_UPDATER_URLS"); if (str != null) { String[] urls = str.split(";"); for (String url : urls) { - sources.add(new RepoSource(url, false /*userSource*/)); + if (url != null && url.length() > 0) { + RepoSource s = new RepoSource(url, false /*userSource*/); + if (!sources.hasSource(s)) { + sources.add(s); + } + } } } // Load user sources sources.loadUserSources(mUpdaterData.getSdkLog()); + // SDK_UPDATER_USER_URLS is a semicolon-separated list of URLs that can be used to + // seed the SDK Updater list for user-only repositories. User sources can only provide + // add-ons and extra packages. + str = System.getenv("SDK_UPDATER_USER_URLS"); + if (str != null) { + String[] urls = str.split(";"); + for (String url : urls) { + if (url != null && url.length() > 0) { + RepoSource s = new RepoSource(url, true /*userSource*/); + if (!sources.hasSource(s)) { + sources.add(s); + } + } + } + } + mRemotePackagesPage.onSdkChange(); }