aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2011-10-04 15:30:16 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-04 15:30:16 -0700
commit655ebafcd6c81a84aac06ce185592bf4dace3f8e (patch)
tree0d8aabe5d525c3288487b24338cb235e57f5dc95 /sdkmanager/libs
parent3be44163f2abefd23b481017254ac9a2a13aa8ed (diff)
parent8f4710850b3a01d6e5f1188440c59d6999646858 (diff)
downloadsdk-655ebafcd6c81a84aac06ce185592bf4dace3f8e.zip
sdk-655ebafcd6c81a84aac06ce185592bf4dace3f8e.tar.gz
sdk-655ebafcd6c81a84aac06ce185592bf4dace3f8e.tar.bz2
Merge "SDK: Use a different repository-N.xml for updating."
Diffstat (limited to 'sdkmanager/libs')
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkAddonSource.java4
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkRepoSource.java7
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkSource.java75
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepoConstants.java15
4 files changed, 84 insertions, 17 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkAddonSource.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkAddonSource.java
index b79cc90..42f7603 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkAddonSource.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkAddonSource.java
@@ -50,8 +50,8 @@ public class SdkAddonSource extends SdkSource {
}
@Override
- protected String getUrlDefaultXmlFile() {
- return SdkAddonConstants.URL_DEFAULT_FILENAME;
+ protected String[] getDefaultXmlFileUrls() {
+ return new String[] { SdkAddonConstants.URL_DEFAULT_FILENAME };
}
@Override
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkRepoSource.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkRepoSource.java
index d53bcc5..d35e365 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkRepoSource.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkRepoSource.java
@@ -64,8 +64,11 @@ public class SdkRepoSource extends SdkSource {
}
@Override
- protected String getUrlDefaultXmlFile() {
- return SdkRepoConstants.URL_DEFAULT_FILENAME;
+ protected String[] getDefaultXmlFileUrls() {
+ return new String[] {
+ SdkRepoConstants.URL_DEFAULT_FILENAME2,
+ SdkRepoConstants.URL_DEFAULT_FILENAME
+ };
}
@Override
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkSource.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkSource.java
index 5cc2cce..263bf15 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkSource.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SdkSource.java
@@ -86,7 +86,10 @@ public abstract class SdkSource implements IDescription, Comparable<SdkSource> {
// looked for. This way it will be obvious to the user which
// resource we are actually trying to fetch.
if (url.endsWith("/")) { //$NON-NLS-1$
- url += getUrlDefaultXmlFile();
+ String[] names = getDefaultXmlFileUrls();
+ if (names.length > 0) {
+ url += names[0];
+ }
}
mUrl = url;
@@ -100,8 +103,13 @@ public abstract class SdkSource implements IDescription, Comparable<SdkSource> {
*/
public abstract boolean isAddonSource();
- /** Returns SdkRepoConstants.URL_DEFAULT_XML_FILE or SdkAddonConstants.URL_DEFAULT_XML_FILE */
- protected abstract String getUrlDefaultXmlFile();
+ /**
+ * Returns the basename of the default URLs to try to download the
+ * XML manifest.
+ * E.g. this is typically SdkRepoConstants.URL_DEFAULT_XML_FILE
+ * or SdkAddonConstants.URL_DEFAULT_XML_FILE
+ */
+ protected abstract String[] getDefaultXmlFileUrls();
/** Returns SdkRepoConstants.NS_LATEST_VERSION or SdkAddonConstants.NS_LATEST_VERSION. */
protected abstract int getNsLatestVersion();
@@ -250,7 +258,7 @@ public abstract class SdkSource implements IDescription, Comparable<SdkSource> {
*/
public void load(ITaskMonitor monitor, boolean forceHttp) {
- monitor.setProgressMax(6);
+ monitor.setProgressMax(7);
setDefaultDescription();
@@ -266,28 +274,77 @@ public abstract class SdkSource implements IDescription, Comparable<SdkSource> {
Boolean[] validatorFound = new Boolean[] { Boolean.FALSE };
String[] validationError = new String[] { null };
Exception[] exception = new Exception[] { null };
- InputStream xml = fetchUrl(url, monitor.createSubMonitor(1), exception);
Document validatedDoc = null;
boolean usingAlternateXml = false;
boolean usingAlternateUrl = false;
String validatedUri = null;
+ String[] defaultNames = getDefaultXmlFileUrls();
+ String firstDefaultName = defaultNames.length > 0 ? defaultNames[0] : "";
+
+ InputStream xml = fetchUrl(url, monitor.createSubMonitor(1), exception);
+ if (xml != null) {
+ int version = getXmlSchemaVersion(xml);
+ if (version == 0) {
+ xml = null;
+ }
+ }
+
+ // FIXME: this is a quick fix to support an alternate upgrade path.
+ // The whole logic below needs to be updated.
+ if (xml == null && defaultNames.length > 0) {
+ ITaskMonitor subMonitor = monitor.createSubMonitor(1);
+ subMonitor.setProgressMax(defaultNames.length);
+
+ String baseUrl = url;
+ if (!baseUrl.endsWith("/")) {
+ int pos = baseUrl.lastIndexOf('/');
+ if (pos > 0) {
+ baseUrl = baseUrl.substring(0, pos + 1);
+ }
+ }
+
+ for(String name : defaultNames) {
+ String newUrl = baseUrl + name;
+ if (newUrl.equals(url)) {
+ continue;
+ }
+ xml = fetchUrl(newUrl, subMonitor.createSubMonitor(1), exception);
+ if (xml != null) {
+ int version = getXmlSchemaVersion(xml);
+ if (version == 0) {
+ xml = null;
+ } else {
+ url = newUrl;
+ subMonitor.incProgress(
+ subMonitor.getProgressMax() - subMonitor.getProgress());
+ break;
+ }
+ }
+ }
+ } else {
+ monitor.incProgress(1);
+ }
+
// If the original URL can't be fetched
// and the URL doesn't explicitly end with our filename
// and it wasn't an HTTP authentication operation canceled by the user
// then make another tentative after changing the URL.
if (xml == null
- && !url.endsWith(getUrlDefaultXmlFile())
+ && !url.endsWith(firstDefaultName)
&& !(exception[0] instanceof CanceledByUserException)) {
if (!url.endsWith("/")) { //$NON-NLS-1$
url += "/"; //$NON-NLS-1$
}
- url += getUrlDefaultXmlFile();
+ url += firstDefaultName;
xml = fetchUrl(url, monitor.createSubMonitor(1), exception);
usingAlternateUrl = true;
+ } else {
+ monitor.incProgress(1);
}
+ // FIXME this needs to revisited.
if (xml != null) {
monitor.setDescription("Validate XML: %1$s", url);
@@ -348,11 +405,11 @@ public abstract class SdkSource implements IDescription, Comparable<SdkSource> {
// If we haven't already tried the alternate URL, let's do it now.
// We don't capture any fetch exception that happen during the second
// fetch in order to avoid hidding any previous fetch errors.
- if (!url.endsWith(getUrlDefaultXmlFile())) {
+ if (!url.endsWith(firstDefaultName)) {
if (!url.endsWith("/")) { //$NON-NLS-1$
url += "/"; //$NON-NLS-1$
}
- url += getUrlDefaultXmlFile();
+ url += firstDefaultName;
xml = fetchUrl(url, subMonitor.createSubMonitor(1), null /* outException */);
subMonitor.incProgress(1);
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepoConstants.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepoConstants.java
index b7701fe..bbd5f7a 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepoConstants.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepoConstants.java
@@ -26,6 +26,10 @@ import java.io.InputStream;
*/
public class SdkRepoConstants extends RepoConstants {
+ /** The latest version of the sdk-repository XML Schema.
+ * Valid version numbers are between 1 and this number, included. */
+ public static final int NS_LATEST_VERSION = 5;
+
/** The URL of the official Google sdk-repository site. */
public static final String URL_GOOGLE_SDK_SITE =
"https://dl-ssl.google.com/android/repository/"; //$NON-NLS-1$
@@ -34,6 +38,13 @@ public class SdkRepoConstants extends RepoConstants {
* sdk-repository XML if the URL doesn't match an existing resource. */
public static final String URL_DEFAULT_FILENAME = "repository.xml"; //$NON-NLS-1$
+ /** The pattern name looked by {@link SdkSource} when trying to load
+ * the latest sdk-repository XML that is specific to the current XSD
+ * schema revision.
+ */
+ public static final String URL_DEFAULT_FILENAME2 =
+ String.format("repository-%d.xml", NS_LATEST_VERSION); //$NON-NLS-1$
+
/** The base of our sdk-repository XML namespace. */
private static final String NS_BASE =
"http://schemas.android.com/sdk/android/repository/"; //$NON-NLS-1$
@@ -44,10 +55,6 @@ public class SdkRepoConstants extends RepoConstants {
*/
public static final String NS_PATTERN = NS_BASE + "([1-9][0-9]*)"; //$NON-NLS-1$
- /** The latest version of the sdk-repository XML Schema.
- * Valid version numbers are between 1 and this number, included. */
- public static final int NS_LATEST_VERSION = 5;
-
/** The XML namespace of the latest sdk-repository XML. */
public static final String NS_URI = getSchemaUri(NS_LATEST_VERSION);