OSDN Git Service

BUG 2042088 : SDK Updater: we want to keep getenv(TEMP_SDK_URL)
authorRaphael <raphael@google.com>
Fri, 7 Aug 2009 23:36:19 +0000 (16:36 -0700)
committerRaphael <raphael@google.com>
Fri, 7 Aug 2009 23:36:19 +0000 (16:36 -0700)
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.

tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java
tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSources.java
tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java

index cce65bd..1d76655 100755 (executable)
@@ -56,6 +56,9 @@ public class RepoSource implements IDescription {
 \r
     /**\r
      * Constructs a new source for the given repository URL.\r
+     * @param url The source URL. Cannot be null. If the URL ends with a /, the default\r
+     *            repository.xml filename will be appended automatically.\r
+     * @param userSource True if this a user source (add-ons & packages only.)\r
      */\r
     public RepoSource(String url, boolean userSource) {\r
 \r
@@ -72,6 +75,23 @@ public class RepoSource implements IDescription {
         setDefaultDescription();\r
     }\r
 \r
+    /**\r
+     * Two repo source are equal if they have the same userSource flag and the same URL.\r
+     */\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (obj instanceof RepoSource) {\r
+            RepoSource rs = (RepoSource) obj;\r
+            return  rs.isUserSource() == this.isUserSource() && rs.getUrl().equals(this.getUrl());\r
+        }\r
+        return false;\r
+    }\r
+\r
+    @Override\r
+    public int hashCode() {\r
+        return mUrl.hashCode() ^ Boolean.valueOf(mUserSource).hashCode();\r
+    }\r
+\r
     /** Returns true if this is a user source. We only load addon and extra packages\r
      * from a user source and ignore the rest. */\r
     public boolean isUserSource() {\r
@@ -176,7 +196,7 @@ public class RepoSource implements IDescription {
                 }\r
             }\r
 \r
-            monitor.setResult("Failed to fetch URL %1$s, reason:", url, reason);\r
+            monitor.setResult("Failed to fetch URL %1$s, reason: %2$s", url, reason);\r
         }\r
 \r
         monitor.incProgress(1);\r
index 7af6657..e0452b8 100755 (executable)
@@ -95,7 +95,10 @@ public class RepoSources {
                 for (int i = 0; i < count; i++) {\r
                     String url = props.getProperty(String.format("%s%02d", KEY_SRC, i));  //$NON-NLS-1$\r
                     if (url != null) {\r
-                        mSources.add(new RepoSource(url, true /*userSource*/));\r
+                        RepoSource s = new RepoSource(url, true /*userSource*/);\r
+                        if (!hasSource(s)) {\r
+                            mSources.add(s);\r
+                        }\r
                     }\r
                 }\r
             }\r
@@ -120,6 +123,20 @@ public class RepoSources {
     }\r
 \r
     /**\r
+     * Returns true if there's already a similar source in the sources list.\r
+     * <p/>\r
+     * The search is O(N), which should be acceptable on the expectedly small source list.\r
+     */\r
+    public boolean hasSource(RepoSource source) {\r
+        for (RepoSource s : mSources) {\r
+            if (s.equals(source)) {\r
+                return true;\r
+            }\r
+        }\r
+        return false;\r
+    }\r
+\r
+    /**\r
      * Saves all the user sources.\r
      * @param log\r
      */\r
index 20f1abb..b9cf0a4 100755 (executable)
@@ -335,17 +335,40 @@ public class UpdaterWindowImpl {
         RepoSources sources = mUpdaterData.getSources();\r
         sources.add(new RepoSource(SdkRepository.URL_GOOGLE_SDK_REPO_SITE, false /*userSource*/));\r
 \r
-        String str = System.getenv("TEMP_SDK_URL"); // TODO STOPSHIP temporary remove before shipping\r
+        // SDK_UPDATER_URLS is a semicolon-separated list of URLs that can be used to\r
+        // seed the SDK Updater list for full repositories.\r
+        String str = System.getenv("SDK_UPDATER_URLS");\r
         if (str != null) {\r
             String[] urls = str.split(";");\r
             for (String url : urls) {\r
-                sources.add(new RepoSource(url, false /*userSource*/));\r
+                if (url != null && url.length() > 0) {\r
+                    RepoSource s = new RepoSource(url, false /*userSource*/);\r
+                    if (!sources.hasSource(s)) {\r
+                        sources.add(s);\r
+                    }\r
+                }\r
             }\r
         }\r
 \r
         // Load user sources\r
         sources.loadUserSources(mUpdaterData.getSdkLog());\r
 \r
+        // SDK_UPDATER_USER_URLS is a semicolon-separated list of URLs that can be used to\r
+        // seed the SDK Updater list for user-only repositories. User sources can only provide\r
+        // add-ons and extra packages.\r
+        str = System.getenv("SDK_UPDATER_USER_URLS");\r
+        if (str != null) {\r
+            String[] urls = str.split(";");\r
+            for (String url : urls) {\r
+                if (url != null && url.length() > 0) {\r
+                    RepoSource s = new RepoSource(url, true /*userSource*/);\r
+                    if (!sources.hasSource(s)) {\r
+                        sources.add(s);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+\r
         mRemotePackagesPage.onSdkChange();\r
     }\r
 \r