Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMykola Nikishov2017-02-03 12:28:10 +0000
committerAlexander Kurtakov2018-02-15 15:21:55 +0000
commitd97bcc18521fdf61df3f9ac6898489463b9cc12e (patch)
tree3c92153ca9a39fd71fefdf1e4f5eac0dd76bf98d /bundles
parent5eb7ab30ebf5658b2e910f97b15a989a1d89d9da (diff)
downloadrt.equinox.p2-d97bcc18521fdf61df3f9ac6898489463b9cc12e.tar.gz
rt.equinox.p2-d97bcc18521fdf61df3f9ac6898489463b9cc12e.tar.xz
rt.equinox.p2-d97bcc18521fdf61df3f9ac6898489463b9cc12e.zip
Bug 507657 - Refactor AbstractRepositoryManager's loadIndexFile(URI,I20180219-2000I20180218-2000I20180217-1500I20180216-2000I20180216-0415I20180215-2000
String, IProgressMonitor) - extract methods to load local and remote p2.index file - rename method isURL to isInMemoryRepository and drop explanation on the caller's side Change-Id: I9558d1746b4f4433a63040ab8c9cae18da4a6bdd Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java51
1 files changed, 25 insertions, 26 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java
index 0e190c9af..b744934a0 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java
@@ -705,38 +705,37 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
* a NullSafe version is returned.
*/
private LocationProperties loadIndexFile(URI location, IProgressMonitor monitor) {
- LocationProperties locationProperties = LocationProperties.createEmptyIndexFile();
- //Handle the case of in-memory repos
- if (!isURL(location))
- return locationProperties;
+ if (!isInMemoryRepository(location))
+ return LocationProperties.createEmptyIndexFile();
- if ("file".equals(location.getScheme())) { //$NON-NLS-1$
- InputStream localStream = null;
- try {
- try {
- File indexFile = URIUtil.toFile(getIndexFileURI(location));
- if (indexFile != null && indexFile.exists() && indexFile.canRead()) {
- localStream = new FileInputStream(indexFile);
- locationProperties = LocationProperties.create(localStream);
- }
- } finally {
- if (localStream != null)
- localStream.close();
- }
- } catch (IOException e) {
- //do nothing.
- }
- return locationProperties;
+ URI indexFile = getIndexFileURI(location);
+ if ("file".equals(indexFile.getScheme())) { //$NON-NLS-1$
+ return handleLocalIndexFile(indexFile);
}
+ return handleRemoteIndexFile(indexFile, monitor);
+ }
- //Handle non local repos (i.e. not file:)
+ private LocationProperties handleRemoteIndexFile(URI indexFileURI, IProgressMonitor monitor) {
ByteArrayOutputStream index = new ByteArrayOutputStream();
IStatus indexFileStatus = null;
- indexFileStatus = getTransport().download(getIndexFileURI(location), index, monitor);
+ indexFileStatus = getTransport().download(indexFileURI, index, monitor);
if (indexFileStatus != null && indexFileStatus.isOK())
- locationProperties = LocationProperties.create(new ByteArrayInputStream(index.toByteArray()));
+ return LocationProperties.create(new ByteArrayInputStream(index.toByteArray()));
+ return LocationProperties.createEmptyIndexFile();
+ }
- return locationProperties;
+ private LocationProperties handleLocalIndexFile(URI indexFileURI) {
+ try {
+ File indexFile = URIUtil.toFile(indexFileURI);
+ if (indexFile != null && indexFile.exists() && indexFile.canRead()) {
+ try (InputStream localStream = new FileInputStream(indexFile)) {
+ return LocationProperties.create(localStream);
+ }
+ }
+ } catch (IOException e) {
+ //do nothing.
+ }
+ return LocationProperties.createEmptyIndexFile();
}
/**
@@ -750,7 +749,7 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
return location;
}
- private static boolean isURL(URI location) {
+ private static boolean isInMemoryRepository(URI location) {
try {
new URL(location.toASCIIString());
} catch (MalformedURLException e) {

Back to the top