aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2009-10-29 12:56:16 -0700
committerRaphael <raphael@google.com>2009-10-29 12:56:16 -0700
commit02d31c8cf03cec16d9ed51ba0a7269bf9b392dc4 (patch)
treed71378d2822baec28a1d980e21fc63c7bbb6839f
parent6e7e10f057d74097a2a0619551b8994c1ecba4e0 (diff)
downloadsdk-02d31c8cf03cec16d9ed51ba0a7269bf9b392dc4.zip
sdk-02d31c8cf03cec16d9ed51ba0a7269bf9b392dc4.tar.gz
sdk-02d31c8cf03cec16d9ed51ba0a7269bf9b392dc4.tar.bz2
SDK Updater: don't load sdk-repo XML that failed to validate. DO NOT MERGE.
This also prints a more obvious message in case Java doesn't have an XML Schema validator. SDK BUGS 2219284 2198427 Change-Id: I28aa1104957d2fe7791dcf0377a42d37f777a19d
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java55
1 files changed, 40 insertions, 15 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java
index b0bc50c..573454d 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java
@@ -185,25 +185,34 @@ public class RepoSource implements IDescription {
}
}
- if (!validated) {
+ // If any exception was handled during the URL fetch, display it now.
+ if (exception[0] != null) {
mFetchError = "Failed to fetch URL";
- String reason = "Unknown";
- if (exception[0] != null) {
- if (exception[0] instanceof FileNotFoundException) {
- reason = "File not found";
- mFetchError += ": " + reason;
- } else if (exception[0] instanceof SSLKeyException) {
- reason = "HTTPS SSL error. You might want to force download through HTTP in the settings.";
- mFetchError += ": HTTPS SSL error";
- } else if (exception[0].getMessage() != null) {
- reason = exception[0].getMessage();
- }
+ String reason = null;
+ if (exception[0] instanceof FileNotFoundException) {
+ // FNF has no useful getMessage, so we need to special handle it.
+ reason = "File not found";
+ mFetchError += ": " + reason;
+ } else if (exception[0] instanceof SSLKeyException) {
+ // That's a common error and we have a pref for it.
+ reason = "HTTPS SSL error. You might want to force download through HTTP in the settings.";
+ mFetchError += ": HTTPS SSL error";
+ } else if (exception[0].getMessage() != null) {
+ reason = exception[0].getMessage();
+ } else {
+ // We don't know what's wrong. Let's give the exception class at least.
+ reason = String.format("Unknown (%1$s)", exception[0].getClass().getName());
}
monitor.setResult("Failed to fetch URL %1$s, reason: %2$s", url, reason);
}
+ // Stop here if we failed to validate the XML. We don't want to load it.
+ if (!validated) {
+ return;
+ }
+
monitor.incProgress(1);
if (xml != null) {
@@ -276,7 +285,7 @@ public class RepoSource implements IDescription {
}
}
- } catch (IOException e) {
+ } catch (Exception e) {
outException[0] = e;
}
@@ -291,14 +300,26 @@ public class RepoSource implements IDescription {
try {
Validator validator = getValidator();
+
+ if (validator == null) {
+ monitor.setResult(
+ "XML verification failed for %1$s.\nNo suitable XML Schema Validator could be found in your Java environment. Please consider updating your version of Java.",
+ url);
+ return false;
+ }
+
xml.reset();
validator.validate(new StreamSource(xml));
return true;
} catch (Exception e) {
+ String s = e.getMessage();
+ if (s == null) {
+ s = e.getClass().getName();
+ }
monitor.setResult("XML verification failed for %1$s.\nError: %2$s",
url,
- e.getMessage());
+ s);
}
return false;
@@ -311,10 +332,14 @@ public class RepoSource implements IDescription {
InputStream xsdStream = SdkRepository.getXsdStream();
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ if (factory == null) {
+ return null;
+ }
+
// This may throw a SAX Exception if the schema itself is not a valid XSD
Schema schema = factory.newSchema(new StreamSource(xsdStream));
- Validator validator = schema.newValidator();
+ Validator validator = schema == null ? null : schema.newValidator();
return validator;
}