Support a new env var SDK_TEST_BASE_URL that should
be set to the root of an alternate repo. When set
it will completly override the built-in default
repository base URL.
(cherry picked from commit
b0ac9620f74f0b3817a8847178ca53d876b78a09)
Change-Id: I029d322a22b6c24c14880c8ffcf8529198bbebde
import com.android.annotations.VisibleForTesting;\r
import com.android.annotations.VisibleForTesting.Visibility;\r
import com.android.sdklib.repository.SdkAddonsListConstants;\r
+import com.android.sdklib.repository.SdkRepoConstants;\r
\r
import org.w3c.dom.Document;\r
import org.w3c.dom.NamedNodeMap;\r
@VisibleForTesting(visibility=Visibility.PRIVATE)\r
protected Site[] parseAddonsList(Document doc, String nsUri, ITaskMonitor monitor) {\r
\r
+ String baseUrl = System.getenv("SDK_TEST_BASE_URL"); //$NON-NLS-1$\r
+ if (baseUrl != null) {\r
+ if (baseUrl.length() <= 0 || !baseUrl.endsWith("/")) { //$NON-NLS-1$\r
+ baseUrl = null;\r
+ }\r
+ }\r
+\r
Node root = getFirstChild(doc, nsUri, SdkAddonsListConstants.NODE_SDK_ADDONS_LIST);\r
if (root != null) {\r
ArrayList<Site> sites = new ArrayList<Site>();\r
String strUrl = url.getTextContent().trim();\r
String strName = name.getTextContent().trim();\r
\r
+ if (baseUrl != null &&\r
+ strUrl.startsWith(SdkRepoConstants.URL_GOOGLE_SDK_SITE)) {\r
+ strUrl = baseUrl +\r
+ strUrl.substring(SdkRepoConstants.URL_GOOGLE_SDK_SITE.length());\r
+ }\r
+\r
if (strUrl.length() > 0 && strName.length() > 0) {\r
sites.add(new Site(strUrl, strName));\r
}\r
\r
/** The URL where to find the official addons list fle. */\r
public static final String URL_ADDON_LIST =\r
- "https://dl-ssl.google.com/android/repository/addons_list.xml"; //$NON-NLS-1$\r
+ SdkRepoConstants.URL_GOOGLE_SDK_SITE + "addons_list.xml"; //$NON-NLS-1$\r
\r
/** The canonical URL filename for addons-list XML files. */\r
public static final String URL_DEFAULT_FILENAME = "addons_list.xml"; //$NON-NLS-1$\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
+ /** The URL of the official Google sdk-repository site.\r
+ * The URL ends with a /, allowing easy concatenation. */\r
public static final String URL_GOOGLE_SDK_SITE =\r
"https://dl-ssl.google.com/android/repository/"; //$NON-NLS-1$\r
\r
// there's an env var asking to do so anyway.\r
if (sources.getAllSources().length == 0 ||\r
System.getenv("SDK_MIX_WITH_TEST_URLS") != null) {\r
+\r
+ String baseUrl = System.getenv("SDK_TEST_BASE_URL"); //$NON-NLS-1$\r
+ if (baseUrl == null || baseUrl.length() <= 0 || !baseUrl.endsWith("/")) { //$NON-NLS-1$\r
+ baseUrl = SdkRepoConstants.URL_GOOGLE_SDK_SITE;\r
+ }\r
+\r
sources.add(SdkSourceCategory.ANDROID_REPO,\r
- new SdkRepoSource(SdkRepoConstants.URL_GOOGLE_SDK_SITE,\r
+ new SdkRepoSource(baseUrl,\r
SdkSourceCategory.ANDROID_REPO.getUiName()));\r
\r
// Load user sources\r
} else if (u.endsWith(SdkAddonsListConstants.URL_DEFAULT_FILENAME)) {\r
url = u;\r
break;\r
+ } else {\r
+ monitor.logError("Ignoring invalid SDK_TEST_URLS: %1$s", u); //$NON-NLS-1$\r
}\r
+\r
}\r
}\r
\r
if (url != null) {\r
+\r
+ // We override SdkRepoConstants.URL_GOOGLE_SDK_SITE if this is defined\r
+ String baseUrl = System.getenv("SDK_TEST_BASE_URL"); //$NON-NLS-1$\r
+ if (baseUrl != null) {\r
+ if (baseUrl.length() > 0 && baseUrl.endsWith("/")) { //$NON-NLS-1$\r
+ if (url.startsWith(SdkRepoConstants.URL_GOOGLE_SDK_SITE)) {\r
+ url = baseUrl +\r
+ url.substring(SdkRepoConstants.URL_GOOGLE_SDK_SITE.length());\r
+ }\r
+ } else {\r
+ monitor.logError("Ignoring invalid SDK_TEST_BASE_URL: %1$s", baseUrl); //$NON-NLS-1$\r
+ }\r
+ }\r
+\r
if (getSettingsController().getForceHttp()) {\r
url = url.replaceAll("https://", "http://"); //$NON-NLS-1$ //$NON-NLS-2$\r
}\r