OSDN Git Service

Display a message in the SDK Manager when a new schema tool is available.
authorRaphael <raphael@google.com>
Thu, 19 Nov 2009 02:10:46 +0000 (18:10 -0800)
committerRaphael <raphael@google.com>
Thu, 19 Nov 2009 02:10:46 +0000 (18:10 -0800)
SDK BUG 2252825

sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java
sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/RepoSourcesAdapter.java

index b5a7c8d..1bebe22 100755 (executable)
@@ -159,19 +159,25 @@ public class RepoSource implements IDescription {
         monitor.incProgress(1);\r
 \r
         mFetchError = null;\r
+        String[] validationError = new String[] { null };\r
         Exception[] exception = new Exception[] { null };\r
         ByteArrayInputStream xml = fetchUrl(url, exception);\r
         Document validatedDoc = null;\r
+        boolean usingAlternateXml = false;\r
         String validatedUri = null;\r
         if (xml != null) {\r
             monitor.setDescription("Validate XML");\r
-            String uri = validateXml(xml, url, monitor);\r
+            String uri = validateXml(xml, url, validationError);\r
             if (uri != null) {\r
                 validatedDoc = getDocument(xml, monitor);\r
                 validatedUri = uri;\r
             } else {\r
                 validatedDoc = findAlternateToolsXml(xml);\r
-                validatedUri = SdkRepository.NS_SDK_REPOSITORY;\r
+                if (validatedDoc != null) {\r
+                    validationError[0] = null;  // remove error from XML validation\r
+                    validatedUri = SdkRepository.NS_SDK_REPOSITORY;\r
+                    usingAlternateXml = true;\r
+                }\r
             }\r
         }\r
 \r
@@ -185,13 +191,17 @@ public class RepoSource implements IDescription {
 \r
             xml = fetchUrl(url, exception);\r
             if (xml != null) {\r
-                String uri = validateXml(xml, url, monitor);\r
+                String uri = validateXml(xml, url, validationError);\r
                 if (uri != null) {\r
                     validatedDoc = getDocument(xml, monitor);\r
                     validatedUri = uri;\r
                 } else {\r
                     validatedDoc = findAlternateToolsXml(xml);\r
-                    validatedUri = SdkRepository.NS_SDK_REPOSITORY;\r
+                    if (validatedDoc != null) {\r
+                        validationError[0] = null;  // remove error from XML validation\r
+                        validatedUri = SdkRepository.NS_SDK_REPOSITORY;\r
+                        usingAlternateXml = true;\r
+                    }\r
                 }\r
             }\r
 \r
@@ -228,11 +238,21 @@ public class RepoSource implements IDescription {
             monitor.setResult("Failed to fetch URL %1$s, reason: %2$s", url, reason);\r
         }\r
 \r
+        if(validationError[0] != null) {\r
+            monitor.setResult("%s", validationError[0]);  //$NON-NLS-1$\r
+        }\r
+\r
         // Stop here if we failed to validate the XML. We don't want to load it.\r
         if (validatedDoc == null) {\r
             return;\r
         }\r
 \r
+        if (usingAlternateXml) {\r
+            String info = "This repository requires a more recent version of the Tools. Please update.";\r
+            mFetchError = mFetchError == null ? info : mFetchError + ". " + info;\r
+            mDescription = "This repository requires a more recent version of the Tools.\nYou must update it before you can see other new packages.";\r
+        }\r
+\r
         monitor.incProgress(1);\r
 \r
         if (xml != null) {\r
@@ -318,7 +338,7 @@ public class RepoSource implements IDescription {
      * If the XML was correctly validated, returns the schema that worked.\r
      * If no schema validated the XML, returns null.\r
      */\r
-    private String validateXml(ByteArrayInputStream xml, String url, ITaskMonitor monitor) {\r
+    private String validateXml(ByteArrayInputStream xml, String url, String[] outError) {\r
 \r
         String lastError = null;\r
         String extraError = null;\r
@@ -346,7 +366,7 @@ public class RepoSource implements IDescription {
         }\r
 \r
         if (lastError != null) {\r
-            monitor.setResult(lastError, url, extraError);\r
+            outError[0] = String.format(lastError, url, extraError);\r
         }\r
         return null;\r
     }\r
index fafa9c1..7a2b2cd 100755 (executable)
@@ -208,17 +208,23 @@ public class RepoSourcesAdapter {
                 packages = null;\r
             }\r
 \r
-            if (packages == null && source.getFetchError() != null) {\r
-                // Return a dummy entry to display the fetch error\r
-                return new Object[] { new RepoSourceError(source) };\r
+            ArrayList<Object> results = new ArrayList<Object>();\r
+\r
+            if (source.getFetchError() != null) {\r
+                // Insert a dummy entry to display the fetch error\r
+                results.add(new RepoSourceError(source));\r
             }\r
 \r
             // Either return a non-null package list or create a new empty node\r
             if (packages != null) {\r
-                return packages;\r
+                for (Package p : packages) {\r
+                    results.add(p);\r
+                }\r
             } else {\r
-                return new Object[] { new RepoSourceEmpty(source, !wasEmptyBeforeFilter) } ;\r
+                results.add(new RepoSourceEmpty(source, !wasEmptyBeforeFilter));\r
             }\r
+\r
+            return results.toArray();\r
         }\r
 \r
         /**\r