Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Oberlies2012-04-12 09:55:29 -0400
committerTobias Oberlies2012-04-12 11:04:01 -0400
commitd104b01da65aa65a7b8cfa43287cef8dbebbe168 (patch)
treeb4d6217480d71c679876ae14f65e873e5cbef510 /bundles/org.eclipse.equinox.p2.repository
parent4e22e50e855a886d2d3b2e662f17d1d50d0808d1 (diff)
downloadrt.equinox.p2-d104b01da65aa65a7b8cfa43287cef8dbebbe168.tar.gz
rt.equinox.p2-d104b01da65aa65a7b8cfa43287cef8dbebbe168.tar.xz
rt.equinox.p2-d104b01da65aa65a7b8cfa43287cef8dbebbe168.zip
347319 Allow repository factories which load repositories by URNsv20120412-1504
- Fix the response of the artifact/metadata repository factories in case that the location to be loaded is not a URL: the factories must return null or throw a ProvisionException with status REPOSITORY_NOT_FOUND in order to make sure that the manager continues to ask other factories. This allows to register a custom factory which for example looks up instances from a registry by uniform resource *identifiers* which are not uniform resource *locators*. - Added a test for loading from a custom, registry based repository factory. Bug: 347319 - [repository] SimpleArtifactRepositoryFactory prevents loading repositories from non-URL URIs
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository')
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java16
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Messages.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java15
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/messages.properties3
4 files changed, 31 insertions, 7 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java
index 234b974a7..95afb681f 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,7 +13,7 @@
package org.eclipse.equinox.internal.p2.repository;
import java.io.*;
-import java.net.URI;
+import java.net.*;
import java.util.EventObject;
import java.util.HashSet;
import org.eclipse.core.runtime.*;
@@ -102,6 +102,9 @@ public class CacheManager {
* @throws OperationCanceledException - if user canceled
*/
public File createCache(URI repositoryLocation, String prefix, IProgressMonitor monitor) throws IOException, ProvisionException {
+ if (!isURL(repositoryLocation)) {
+ throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.CacheManager_CannotLoadNonUrlLocation, repositoryLocation), null));
+ }
SubMonitor submonitor = SubMonitor.convert(monitor, 1000);
try {
@@ -261,6 +264,15 @@ public class CacheManager {
return files;
}
+ private static boolean isURL(URI location) {
+ try {
+ new URL(location.toASCIIString());
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ return true;
+ }
+
/**
* Adds a {@link SynchronousProvisioningListener} to the event bus for
* deleting cache files when the corresponding repository is deleted.
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Messages.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Messages.java
index 61d8912b8..822f3c19f 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Messages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,6 +18,8 @@ public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.repository.messages"; //$NON-NLS-1$
public static String CacheManager_AuthenticationFaileFor_0;
+
+ public static String CacheManager_CannotLoadNonUrlLocation;
public static String CacheManager_FailedCommunicationWithRepo_0;
public static String CacheManager_Neither_0_nor_1_found;
public static String CacheManage_ErrorRenamingCache;
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 01b260288..207eebcee 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -689,8 +689,8 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
*/
private LocationProperties loadIndexFile(URI location, IProgressMonitor monitor) {
LocationProperties locationProperties = LocationProperties.createEmptyIndexFile();
- //Handle the case of local repos
- if ("memory".equals(location.getScheme())) //$NON-NLS-1$
+ //Handle the case of in-memory repos
+ if (!isURL(location))
return locationProperties;
if ("file".equals(location.getScheme())) { //$NON-NLS-1$
@@ -740,6 +740,15 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
return location;
}
+ private static boolean isURL(URI location) {
+ try {
+ new URL(location.toASCIIString());
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ return true;
+ }
+
private IRepository<T> loadRepository(URI location, String suffix, String type, int flags, SubMonitor monitor) throws ProvisionException {
IExtension[] providers = findMatchingRepositoryExtensions(suffix, type);
// Loop over the candidates and return the first one that successfully loads
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/messages.properties b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/messages.properties
index 4e59267be..ddd53d163 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/messages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2007, 2010 IBM Corporation and others.
+# Copyright (c) 2007, 2012 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -21,6 +21,7 @@ repo_loading = Loading the repository {0}
CacheManager_Neither_0_nor_1_found=Neither {0} nor {1} found.
CacheManager_AuthenticationFaileFor_0=Authentication failed for {0}.
+CacheManager_CannotLoadNonUrlLocation=Cannot load repository from non-URL location {0}
CacheManager_FailedCommunicationWithRepo_0=Communication with repository at {0} failed.
CacheManage_ErrorRenamingCache=An error occurred while downloading {0}. The cache file {1} could not be renamed to {1}.

Back to the top