diff options
author | Mykola Nikishov | 2018-03-24 13:02:33 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2018-06-13 11:07:04 +0000 |
commit | 69069b9f60e8c0675f2500be6388822b5f967d98 (patch) | |
tree | 8b265a79c4cc22f1084768d02adf093a321def93 | |
parent | 43e2105b58b2e2cc002bf979c6ed88e7d8b3b144 (diff) | |
download | rt.equinox.p2-69069b9f60e8c0675f2500be6388822b5f967d98.tar.gz rt.equinox.p2-69069b9f60e8c0675f2500be6388822b5f967d98.tar.xz rt.equinox.p2-69069b9f60e8c0675f2500be6388822b5f967d98.zip |
Refactor internal MirrorSelector's computeMirrors(String, IProgressMonitor)
Change-Id: I38bd174a92d89945b96e380d866aa0ef1d963d16
Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
-rw-r--r-- | bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java index 73fb34692..8d6075d7b 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java @@ -252,27 +252,13 @@ public class MirrorSelector { */ private MirrorInfo[] computeMirrors(String mirrorsURL, IProgressMonitor monitor) { try { - String countryCode = Activator.getContext().getProperty("eclipse.p2.countryCode"); //$NON-NLS-1$ - if (countryCode == null || countryCode.trim().length() == 0) - countryCode = Locale.getDefault().getCountry().toLowerCase(); - String timeZone = Activator.getContext().getProperty("eclipse.p2.timeZone"); //$NON-NLS-1$ - if (timeZone == null || timeZone.trim().length() == 0) - timeZone = Integer.toString(new GregorianCalendar().get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)); - - if (mirrorsURL.indexOf('?') != -1) { - mirrorsURL = mirrorsURL + '&'; - } else { - mirrorsURL = mirrorsURL + '?'; - } - mirrorsURL = mirrorsURL + "countryCode=" + countryCode + "&timeZone=" + timeZone + "&format=xml"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - + mirrorsURL = enrichWithClientLocation(mirrorsURL); DocumentBuilderFactory domFactory = SecureXMLUtil.newSecureDocumentBuilderFactory(); DocumentBuilder builder = domFactory.newDocumentBuilder(); - Document document = null; // Use Transport to read the mirrors list (to benefit from proxy support, authentication, etc) InputSource input = new InputSource(mirrorsURL); input.setByteStream(transport.stream(URIUtil.fromString(mirrorsURL), monitor)); - document = builder.parse(input); + Document document = builder.parse(input); if (document == null) return null; NodeList mirrorNodes = document.getElementsByTagName("mirror"); //$NON-NLS-1$ @@ -298,6 +284,22 @@ public class MirrorSelector { } } + private String enrichWithClientLocation(String baseURL) { + String countryCode = Activator.getContext().getProperty("eclipse.p2.countryCode"); //$NON-NLS-1$ + if (countryCode == null || countryCode.trim().length() == 0) + countryCode = Locale.getDefault().getCountry().toLowerCase(); + String timeZone = Activator.getContext().getProperty("eclipse.p2.timeZone"); //$NON-NLS-1$ + if (timeZone == null || timeZone.trim().length() == 0) + timeZone = Integer.toString(new GregorianCalendar().get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)); + + if (baseURL.indexOf('?') != -1) { + baseURL = baseURL + '&'; + } else { + baseURL = baseURL + '?'; + } + return baseURL + "countryCode=" + countryCode + "&timeZone=" + timeZone + "&format=xml"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + /** * Returns an equivalent location for the given artifact location in the base * repository. Always falls back to the given input location in case of failure |