// looked for. This way it will be obvious to the user which\r
// resource we are actually trying to fetch.\r
if (url.endsWith("/")) { //$NON-NLS-1$\r
- url += getUrlDefaultXmlFile();\r
+ String[] names = getDefaultXmlFileUrls();\r
+ if (names.length > 0) {\r
+ url += names[0];\r
+ }\r
}\r
\r
mUrl = url;\r
*/\r
public abstract boolean isAddonSource();\r
\r
- /** Returns SdkRepoConstants.URL_DEFAULT_XML_FILE or SdkAddonConstants.URL_DEFAULT_XML_FILE */\r
- protected abstract String getUrlDefaultXmlFile();\r
+ /**\r
+ * Returns the basename of the default URLs to try to download the\r
+ * XML manifest.\r
+ * E.g. this is typically SdkRepoConstants.URL_DEFAULT_XML_FILE\r
+ * or SdkAddonConstants.URL_DEFAULT_XML_FILE\r
+ */\r
+ protected abstract String[] getDefaultXmlFileUrls();\r
\r
/** Returns SdkRepoConstants.NS_LATEST_VERSION or SdkAddonConstants.NS_LATEST_VERSION. */\r
protected abstract int getNsLatestVersion();\r
*/\r
public void load(ITaskMonitor monitor, boolean forceHttp) {\r
\r
- monitor.setProgressMax(6);\r
+ monitor.setProgressMax(7);\r
\r
setDefaultDescription();\r
\r
Boolean[] validatorFound = new Boolean[] { Boolean.FALSE };\r
String[] validationError = new String[] { null };\r
Exception[] exception = new Exception[] { null };\r
- InputStream xml = fetchUrl(url, monitor.createSubMonitor(1), exception);\r
Document validatedDoc = null;\r
boolean usingAlternateXml = false;\r
boolean usingAlternateUrl = false;\r
String validatedUri = null;\r
\r
+ String[] defaultNames = getDefaultXmlFileUrls();\r
+ String firstDefaultName = defaultNames.length > 0 ? defaultNames[0] : "";\r
+\r
+ InputStream xml = fetchUrl(url, monitor.createSubMonitor(1), exception);\r
+ if (xml != null) {\r
+ int version = getXmlSchemaVersion(xml);\r
+ if (version == 0) {\r
+ xml = null;\r
+ }\r
+ }\r
+\r
+ // FIXME: this is a quick fix to support an alternate upgrade path.\r
+ // The whole logic below needs to be updated.\r
+ if (xml == null && defaultNames.length > 0) {\r
+ ITaskMonitor subMonitor = monitor.createSubMonitor(1);\r
+ subMonitor.setProgressMax(defaultNames.length);\r
+\r
+ String baseUrl = url;\r
+ if (!baseUrl.endsWith("/")) {\r
+ int pos = baseUrl.lastIndexOf('/');\r
+ if (pos > 0) {\r
+ baseUrl = baseUrl.substring(0, pos + 1);\r
+ }\r
+ }\r
+\r
+ for(String name : defaultNames) {\r
+ String newUrl = baseUrl + name;\r
+ if (newUrl.equals(url)) {\r
+ continue;\r
+ }\r
+ xml = fetchUrl(newUrl, subMonitor.createSubMonitor(1), exception);\r
+ if (xml != null) {\r
+ int version = getXmlSchemaVersion(xml);\r
+ if (version == 0) {\r
+ xml = null;\r
+ } else {\r
+ url = newUrl;\r
+ subMonitor.incProgress(\r
+ subMonitor.getProgressMax() - subMonitor.getProgress());\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ } else {\r
+ monitor.incProgress(1);\r
+ }\r
+\r
// If the original URL can't be fetched\r
// and the URL doesn't explicitly end with our filename\r
// and it wasn't an HTTP authentication operation canceled by the user\r
// then make another tentative after changing the URL.\r
if (xml == null\r
- && !url.endsWith(getUrlDefaultXmlFile())\r
+ && !url.endsWith(firstDefaultName)\r
&& !(exception[0] instanceof CanceledByUserException)) {\r
if (!url.endsWith("/")) { //$NON-NLS-1$\r
url += "/"; //$NON-NLS-1$\r
}\r
- url += getUrlDefaultXmlFile();\r
+ url += firstDefaultName;\r
\r
xml = fetchUrl(url, monitor.createSubMonitor(1), exception);\r
usingAlternateUrl = true;\r
+ } else {\r
+ monitor.incProgress(1);\r
}\r
\r
+ // FIXME this needs to revisited.\r
if (xml != null) {\r
monitor.setDescription("Validate XML: %1$s", url);\r
\r
// If we haven't already tried the alternate URL, let's do it now.\r
// We don't capture any fetch exception that happen during the second\r
// fetch in order to avoid hidding any previous fetch errors.\r
- if (!url.endsWith(getUrlDefaultXmlFile())) {\r
+ if (!url.endsWith(firstDefaultName)) {\r
if (!url.endsWith("/")) { //$NON-NLS-1$\r
url += "/"; //$NON-NLS-1$\r
}\r
- url += getUrlDefaultXmlFile();\r
+ url += firstDefaultName;\r
\r
xml = fetchUrl(url, subMonitor.createSubMonitor(1), null /* outException */);\r
subMonitor.incProgress(1);\r
*/\r
public class SdkRepoConstants extends RepoConstants {\r
\r
+ /** The latest version of the sdk-repository XML Schema.\r
+ * Valid version numbers are between 1 and this number, included. */\r
+ public static final int NS_LATEST_VERSION = 5;\r
+\r
/** The URL of the official Google sdk-repository site. */\r
public static final String URL_GOOGLE_SDK_SITE =\r
"https://dl-ssl.google.com/android/repository/"; //$NON-NLS-1$\r
* sdk-repository XML if the URL doesn't match an existing resource. */\r
public static final String URL_DEFAULT_FILENAME = "repository.xml"; //$NON-NLS-1$\r
\r
+ /** The pattern name looked by {@link SdkSource} when trying to load\r
+ * the latest sdk-repository XML that is specific to the current XSD\r
+ * schema revision.\r
+ */\r
+ public static final String URL_DEFAULT_FILENAME2 =\r
+ String.format("repository-%d.xml", NS_LATEST_VERSION); //$NON-NLS-1$\r
+\r
/** The base of our sdk-repository XML namespace. */\r
private static final String NS_BASE =\r
"http://schemas.android.com/sdk/android/repository/"; //$NON-NLS-1$\r
*/\r
public static final String NS_PATTERN = NS_BASE + "([1-9][0-9]*)"; //$NON-NLS-1$\r
\r
- /** The latest version of the sdk-repository XML Schema.\r
- * Valid version numbers are between 1 and this number, included. */\r
- public static final int NS_LATEST_VERSION = 5;\r
-\r
/** The XML namespace of the latest sdk-repository XML. */\r
public static final String NS_URI = getSchemaUri(NS_LATEST_VERSION);\r
\r