diff options
author | John Arthorne | 2008-10-09 03:22:47 +0000 |
---|---|---|
committer | John Arthorne | 2008-10-09 03:22:47 +0000 |
commit | 773624727040c3a294359169f0f8d4aa22a7071d (patch) | |
tree | f51675a1f16deb759720dc7c3a4daa379935fdbd | |
parent | dfe94e43cf371e39d46b07c9f0e6c6b28eeb000e (diff) | |
download | rt.equinox.p2-773624727040c3a294359169f0f8d4aa22a7071d.tar.gz rt.equinox.p2-773624727040c3a294359169f0f8d4aa22a7071d.tar.xz rt.equinox.p2-773624727040c3a294359169f0f8d4aa22a7071d.zip |
Bug 237776 Replace URL by URI
179 files changed, 2284 insertions, 2236 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/jardelta/Application.java b/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/jardelta/Application.java index 09069629d..c66d2a8c2 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/jardelta/Application.java +++ b/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/jardelta/Application.java @@ -9,7 +9,7 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.optimizers.jardelta; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; @@ -24,7 +24,7 @@ import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; */ public class Application implements IApplication { - private URL artifactRepositoryLocation; + private URI artifactRepositoryLocation; private int width = 1; private int depth = 1; @@ -36,7 +36,7 @@ public class Application implements IApplication { return null; } - private IArtifactRepository setupRepository(URL location) throws ProvisionException { + private IArtifactRepository setupRepository(URI location) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) // TODO log here @@ -64,7 +64,7 @@ public class Application implements IApplication { String arg = args[++i]; if (args[i - 1].equalsIgnoreCase("-artifactRepository") || args[i - 1].equalsIgnoreCase("-ar")) //$NON-NLS-1$ //$NON-NLS-2$ - artifactRepositoryLocation = new URL(arg); + artifactRepositoryLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-depth")) //$NON-NLS-1$ depth = Integer.parseInt(arg); diff --git a/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/jbdiff/Application.java b/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/jbdiff/Application.java index bd2b08cb9..c5289ea13 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/jbdiff/Application.java +++ b/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/jbdiff/Application.java @@ -9,7 +9,7 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.optimizers.jbdiff; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; @@ -24,7 +24,7 @@ import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; */ public class Application implements IApplication { - private URL artifactRepositoryLocation; + private URI artifactRepositoryLocation; private int width = 1; private int depth = 1; private boolean nosar; @@ -37,7 +37,7 @@ public class Application implements IApplication { return null; } - private IArtifactRepository setupRepository(URL location) throws ProvisionException { + private IArtifactRepository setupRepository(URI location) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) // TODO log here @@ -68,7 +68,7 @@ public class Application implements IApplication { String arg = args[++i]; if (args[i - 1].equalsIgnoreCase("-artifactRepository") || args[i - 1].equalsIgnoreCase("-ar")) //$NON-NLS-1$ //$NON-NLS-2$ - artifactRepositoryLocation = new URL(arg); + artifactRepositoryLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-depth")) //$NON-NLS-1$ depth = Integer.parseInt(arg); diff --git a/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/pack200/Application.java b/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/pack200/Application.java index 93e9ab25a..f6ddeb69f 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/pack200/Application.java +++ b/bundles/org.eclipse.equinox.p2.artifact.optimizers/src/org/eclipse/equinox/internal/p2/artifact/optimizers/pack200/Application.java @@ -9,7 +9,7 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.optimizers.pack200; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; @@ -27,7 +27,7 @@ public class Application implements IApplication { private static final String ARTIFACT_REPOSITORY_ARG = "-artifactRepository"; //$NON-NLS-1$ private static final String ARTIFACT_REPOSITORY_SHORT_ARG = "-ar"; //$NON-NLS-1$ - private URL artifactRepositoryLocation; + private URI artifactRepositoryLocation; public Object start(IApplicationContext context) throws Exception { Map args = context.getArguments(); @@ -39,7 +39,7 @@ public class Application implements IApplication { return null; } - private IArtifactRepository setupRepository(URL location) throws ProvisionException { + private IArtifactRepository setupRepository(URI location) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) // TODO log here @@ -63,7 +63,7 @@ public class Application implements IApplication { String arg = args[++i]; if (args[i - 1].equalsIgnoreCase(ARTIFACT_REPOSITORY_ARG) || args[i - 1].equalsIgnoreCase(ARTIFACT_REPOSITORY_SHORT_ARG)) - artifactRepositoryLocation = new URL(arg); + artifactRepositoryLocation = new URI(arg); } } } diff --git a/bundles/org.eclipse.equinox.p2.artifact.processors/src/org/eclipse/equinox/internal/p2/artifact/processors/AbstractDeltaProcessorStep.java b/bundles/org.eclipse.equinox.p2.artifact.processors/src/org/eclipse/equinox/internal/p2/artifact/processors/AbstractDeltaProcessorStep.java index fb6630c2a..58fe5871c 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.processors/src/org/eclipse/equinox/internal/p2/artifact/processors/AbstractDeltaProcessorStep.java +++ b/bundles/org.eclipse.equinox.p2.artifact.processors/src/org/eclipse/equinox/internal/p2/artifact/processors/AbstractDeltaProcessorStep.java @@ -11,7 +11,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.processors; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.equinox.internal.p2.artifact.optimizers.AbstractDeltaStep; @@ -47,7 +47,7 @@ public abstract class AbstractDeltaProcessorStep extends AbstractDeltaStep { return; } - URL[] repositories = repoMgr.getKnownRepositories(IArtifactRepositoryManager.REPOSITORIES_LOCAL); + URI[] repositories = repoMgr.getKnownRepositories(IArtifactRepositoryManager.REPOSITORIES_LOCAL); for (int i = 0; i < repositories.length; i++) { try { IArtifactRepository currentRepo = repoMgr.loadRepository(repositories[i], null); diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java index 8d045dccc..11f6de445 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.mirror; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; @@ -26,8 +26,8 @@ import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; */ public class MirrorApplication implements IApplication { - private URL sourceLocation; - private URL destinationLocation; + private URI sourceLocation; + private URI destinationLocation; private IArtifactRepository source; private IArtifactRepository destination; private boolean append = false; @@ -84,7 +84,7 @@ public class MirrorApplication implements IApplication { //must execute before initializeDestination is called source = getManager().loadRepository(sourceLocation, null); - destination = initializeDestination(); + destination = initializeDestination(); } private IArtifactRepository initializeDestination() throws ProvisionException { @@ -129,9 +129,9 @@ public class MirrorApplication implements IApplication { String arg = args[++i]; if (args[i - 1].equalsIgnoreCase("-source")) //$NON-NLS-1$ - sourceLocation = new URL(arg); + sourceLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-destination")) //$NON-NLS-1$ - destinationLocation = new URL(arg); + destinationLocation = new URI(arg); } } } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java index 22ce65441..656ba2499 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java @@ -10,7 +10,7 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.*; @@ -41,7 +41,7 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme return new MirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties); } - public IArtifactRepository createRepository(URL location, String name, String type, Map properties) throws ProvisionException { + public IArtifactRepository createRepository(URI location, String name, String type, Map properties) throws ProvisionException { synchronized (repositoryLock) { boolean loaded = false; try { @@ -67,7 +67,7 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme } } - protected IRepository factoryLoad(URL location, IExtension extension, SubMonitor monitor) throws ProvisionException { + protected IRepository factoryLoad(URI location, IExtension extension, SubMonitor monitor) throws ProvisionException { IArtifactRepositoryFactory factory = (IArtifactRepositoryFactory) createExecutableExtension(extension, EL_FACTORY); if (factory == null) return null; @@ -97,11 +97,11 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme return IRepository.TYPE_ARTIFACT; } - public IArtifactRepository loadRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public IArtifactRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException { return (IArtifactRepository) loadRepository(location, monitor, null); } - public IArtifactRepository refreshRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public IArtifactRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException { return (IArtifactRepository) basicRefreshRepository(location, monitor); } @@ -115,7 +115,7 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme // TODO should do something here since we are failing to restore. return; try { - loadRepository(location.getArtifactRepositoryURL(), null); + loadRepository(location.getArtifactRepositoryURI(), null); return; } catch (ProvisionException e) { // log but still continue and try to create a new one @@ -125,7 +125,7 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme try { Map properties = new HashMap(1); properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); - createRepository(location.getArtifactRepositoryURL(), "download cache", TYPE_SIMPLE_REPOSITORY, properties); //$NON-NLS-1$ + createRepository(location.getArtifactRepositoryURI(), "download cache", TYPE_SIMPLE_REPOSITORY, properties); //$NON-NLS-1$ } catch (ProvisionException e) { LogHelper.log(e); } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java index ff0d0b0ef..ccb54b24a 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java @@ -74,7 +74,7 @@ public class MirrorRequest extends ArtifactRequest { else if (ProcessingStepHandler.canProcess(descriptors[i])) optimized = descriptors[i]; } - boolean chooseCanonical = source.getLocation().getProtocol().equals("file"); //$NON-NLS-1$ + boolean chooseCanonical = source.getLocation().getScheme().equals("file"); //$NON-NLS-1$ // If the source repo is local then look for a canonical descriptor so we don't waste processing time. descriptor = chooseCanonical ? canonical : optimized; // if the descriptor is still null then we could not find our first choice of format so switch the logic. 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 d72daab92..becb2a8fa 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 @@ -10,12 +10,14 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; -import java.net.*; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.core.helpers.*; +import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; +import org.eclipse.equinox.internal.p2.core.helpers.Tracing; import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; import org.w3c.dom.*; @@ -101,9 +103,9 @@ public class MirrorSelector { if (base != null) { this.baseURI = new URI(base); } else { - URL repositoryURL = repository.getLocation(); - if (repositoryURL != null) - this.baseURI = URLUtil.toURI(repositoryURL); + URI repositoryLocation = repository.getLocation(); + if (repositoryLocation != null) + this.baseURI = repositoryLocation; } } catch (URISyntaxException e) { log("Error initializing mirrors for: " + repository.getLocation(), e); //$NON-NLS-1$ @@ -181,8 +183,8 @@ public class MirrorSelector { if (Tracing.DEBUG_MIRRORS) Tracing.debug("Selected mirror for artifact " + inputLocation + ": " + selectedMirror); //$NON-NLS-1$ //$NON-NLS-2$ try { - return new URL(selectedMirror.locationString + relativeLocation.getPath()).toExternalForm(); - } catch (MalformedURLException e) { + return new URI(selectedMirror.locationString + relativeLocation.getPath()).toString(); + } catch (URISyntaxException e) { log("Unable to make location " + inputLocation + " relative to mirror " + selectedMirror.locationString, e); //$NON-NLS-1$ //$NON-NLS-2$ } return inputLocation; diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java index 9d769aadb..8b24c78d6 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java @@ -11,10 +11,12 @@ package org.eclipse.equinox.internal.p2.artifact.repository.simple; import java.io.*; +import java.net.URI; import java.net.URL; import java.util.Iterator; import java.util.Set; import org.eclipse.core.runtime.Assert; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; /** * Blob store which maps UUIDs to blobs on disk. The UUID is mapped @@ -22,7 +24,7 @@ import org.eclipse.core.runtime.Assert; * the blobs are split among 255 directories with the names 00 to FF. */ public class BlobStore { - protected URL store; + protected URI store; protected boolean fileBased; /** Limits the range of directories' names. */ @@ -37,12 +39,12 @@ public class BlobStore { * This number must be power of 2 and do not exceed 256. The location * should be an existing valid directory. */ - public BlobStore(URL store, int limit) { + public BlobStore(URI store, int limit) { Assert.isNotNull(store); this.store = store; - fileBased = "file".equalsIgnoreCase(store.getProtocol()); //$NON-NLS-1$ + fileBased = "file".equalsIgnoreCase(store.getScheme()); //$NON-NLS-1$ if (fileBased) - Assert.isTrue(!new File(store.getPath()).isFile()); + Assert.isTrue(!URIUtil.toFile(store).isFile()); Assert.isTrue(limit == 256 || limit == 128 || limit == 64 || limit == 32 || limit == 16 || limit == 8 || limit == 4 || limit == 2 || limit == 1); mask = (byte) (limit - 1); } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java index 95217866d..57ced2bd2 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java @@ -10,8 +10,8 @@ package org.eclipse.equinox.internal.p2.artifact.repository.simple; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; @@ -19,8 +19,7 @@ import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.equinox.internal.p2.artifact.repository.*; import org.eclipse.equinox.internal.p2.artifact.repository.Messages; -import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.internal.p2.core.helpers.*; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -216,13 +215,13 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } } - public static URL getActualLocation(URL base, boolean compress) { + public static URI getActualLocation(URI base, boolean compress) { return getActualLocation(base, compress ? JAR_EXTENSION : XML_EXTENSION); } - private static URL getActualLocation(URL base, String extension) { + private static URI getActualLocation(URI base, String extension) { final String name = CONTENT_FILENAME + extension; - String spec = base.toExternalForm(); + String spec = base.toString(); if (spec.endsWith(name)) return base; if (spec.endsWith("/")) //$NON-NLS-1$ @@ -230,23 +229,14 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme else spec += "/" + name; //$NON-NLS-1$ try { - return new URL(spec); - } catch (MalformedURLException e) { + return new URI(spec); + } catch (URISyntaxException e) { return null; } } - public static URL getBlobStoreLocation(URL base) { - String spec = base.toExternalForm(); - if (spec.endsWith("/")) //$NON-NLS-1$ - spec += BLOBSTORE; - else - spec += "/" + BLOBSTORE; //$NON-NLS-1$ - try { - return new URL(spec); - } catch (MalformedURLException e) { - return null; - } + public static URI getBlobStoreLocation(URI base) { + return URIUtil.append(base, BLOBSTORE); } /* @@ -281,7 +271,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme artifactMap.remove(key); } - public SimpleArtifactRepository(String repositoryName, URL location, Map properties) { + public SimpleArtifactRepository(String repositoryName, URI location, Map properties) { super(repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties); initializeAfterLoad(location); if (properties != null) { @@ -384,7 +374,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme if (descriptor.getProcessingSteps().length == 0) { descriptor.setProperty(ARTIFACT_UUID, null); IArtifactKey key = descriptor.getArtifactKey(); - String result = mapper.map(location.toExternalForm(), key.getClassifier(), key.getId(), key.getVersion().toString(), descriptor.getProperty(IArtifactDescriptor.FORMAT)); + String result = mapper.map(location.toString(), key.getClassifier(), key.getId(), key.getVersion().toString(), descriptor.getProperty(IArtifactDescriptor.FORMAT)); if (result != null) { if (isFolderBased(descriptor) && result.endsWith(JAR_EXTENSION)) return result.substring(0, result.lastIndexOf(JAR_EXTENSION)); @@ -620,7 +610,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme */ private String getLocationForPackedButFlatArtifacts(IArtifactDescriptor descriptor) { IArtifactKey key = descriptor.getArtifactKey(); - return mapper.map(location.toExternalForm(), key.getClassifier(), key.getId(), key.getVersion().toString(), descriptor.getProperty(IArtifactDescriptor.FORMAT)); + return mapper.map(location.toString(), key.getClassifier(), key.getId(), key.getVersion().toString(), descriptor.getProperty(IArtifactDescriptor.FORMAT)); } public synchronized String getLocation(IArtifactDescriptor descriptor) { @@ -643,7 +633,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme // if the descriptor is complete then use the mapping rules... if (descriptor.getProcessingSteps().length == 0) { IArtifactKey key = descriptor.getArtifactKey(); - String result = mapper.map(location.toExternalForm(), key.getClassifier(), key.getId(), key.getVersion().toString(), descriptor.getProperty(IArtifactDescriptor.FORMAT)); + String result = mapper.map(location.toString(), key.getClassifier(), key.getId(), key.getVersion().toString(), descriptor.getProperty(IArtifactDescriptor.FORMAT)); if (result != null) { if (isFolderBased(descriptor) && result.endsWith(JAR_EXTENSION)) return result.substring(0, result.lastIndexOf(JAR_EXTENSION)); @@ -674,7 +664,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme assertModifiable(); // Check if the artifact is already in this repository if (contains(descriptor)) { - String msg = NLS.bind(Messages.available_already_in, getLocation().toExternalForm()); + String msg = NLS.bind(Messages.available_already_in, getLocation().toString()); throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.ARTIFACT_EXISTS, msg, null)); } @@ -687,8 +677,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme String newLocation = createLocation(newDescriptor); String file = null; try { - file = new URL(newLocation).getFile(); - } catch (MalformedURLException e1) { + file = URIUtil.toFile(new URI(newLocation)).getAbsolutePath(); + } catch (URISyntaxException e1) { // This should not happen Assert.isTrue(false, "Unexpected failure: " + e1); //$NON-NLS-1$ } @@ -728,7 +718,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } private ProvisionException failedWrite(Exception e) throws ProvisionException { - String msg = NLS.bind(Messages.repoFailedWrite, getLocation().toExternalForm()); + String msg = NLS.bind(Messages.repoFailedWrite, getLocation()); throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_WRITE, msg, e)); } @@ -741,7 +731,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } // use this method to setup any transient fields etc after the object has been restored from a stream - public synchronized void initializeAfterLoad(URL location) { + public synchronized void initializeAfterLoad(URI location) { this.location = location; blobStore = new BlobStore(getBlobStoreLocation(location), 128); initializeMapper(); @@ -771,7 +761,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } private boolean isLocal() { - return "file".equalsIgnoreCase(location.getProtocol()); //$NON-NLS-1$ + return "file".equalsIgnoreCase(location.getScheme()); //$NON-NLS-1$ } public boolean isModifiable() { @@ -843,9 +833,9 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme OutputStream os = null; try { try { - URL actualLocation = getActualLocation(location, false); - File artifactsFile = new File(actualLocation.getPath()); - File jarFile = new File(getActualLocation(location, true).getPath()); + URI actualLocation = getActualLocation(location, false); + File artifactsFile = URIUtil.toFile(actualLocation); + File jarFile = URIUtil.toFile(getActualLocation(location, true)); if (!compress) { if (jarFile.exists()) { jarFile.delete(); @@ -865,7 +855,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme jarFile.createNewFile(); } JarOutputStream jOs = new JarOutputStream(new FileOutputStream(jarFile)); - jOs.putNextEntry(new JarEntry(new Path(actualLocation.getFile()).lastSegment())); + jOs.putNextEntry(new JarEntry(new Path(artifactsFile.getAbsolutePath()).lastSegment())); os = jOs; } super.setProperty(IRepository.PROP_TIMESTAMP, Long.toString(System.currentTimeMillis())); @@ -909,6 +899,6 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public String toString() { - return location.toExternalForm(); + return location.toString(); } } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepositoryManager.java index c83634c62..b6c999636 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/IArtifactRepositoryManager.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.artifact.repository; -import java.net.URL; +import java.net.URI; import java.util.Map; import java.util.Properties; import org.eclipse.core.runtime.IProgressMonitor; @@ -50,7 +50,7 @@ public interface IArtifactRepositoryManager extends IRepositoryManager { * the given location. * <p> * The resulting repository is added to the list of repositories tracked by - * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URL)} + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} * if they do not want the repository manager to remember the repository for subsequent * load attempts. * </p> @@ -67,7 +67,7 @@ public interface IArtifactRepositoryManager extends IRepositoryManager { * <li>A repository already exists at that location.</li> * </ul> */ - public IArtifactRepository createRepository(URL location, String name, String type, Map properties) throws ProvisionException; + public IArtifactRepository createRepository(URI location, String name, String type, Map properties) throws ProvisionException; /** * Loads the repository at the given location. The location is expected to contain @@ -75,7 +75,7 @@ public interface IArtifactRepositoryManager extends IRepositoryManager { * already knows a repository at the given location then that repository is returned. * <p> * The resulting repository is added to the list of repositories tracked by - * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URL)} + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} * if they do not want the repository manager to remember the repository for subsequent * load attempts. * </p> @@ -90,7 +90,7 @@ public interface IArtifactRepositoryManager extends IRepositoryManager { * <li>The repository at that location could not be read.</li> * </ul> */ - public IArtifactRepository loadRepository(URL location, IProgressMonitor monitor) throws ProvisionException; + public IArtifactRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException; /** * Refreshes the repository corresponding to the given URL. This method discards @@ -109,6 +109,6 @@ public interface IArtifactRepositoryManager extends IRepositoryManager { * <li>The repository at that location could not be read.</li> * </ul> */ - public IArtifactRepository refreshRepository(URL location, IProgressMonitor monitor) throws ProvisionException; + public IArtifactRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException; }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/AbstractArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/AbstractArtifactRepository.java index a84c85a3a..ffa6feeea 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/AbstractArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/AbstractArtifactRepository.java @@ -11,12 +11,12 @@ package org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository; import java.io.OutputStream; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.repository.Activator; import org.eclipse.equinox.internal.p2.artifact.repository.Messages; -import org.eclipse.equinox.internal.p2.core.helpers.URLUtil; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; @@ -25,7 +25,7 @@ import org.eclipse.osgi.util.NLS; public abstract class AbstractArtifactRepository extends AbstractRepository implements IArtifactRepository { - protected AbstractArtifactRepository(String name, String type, String version, URL location, String description, String provider, Map properties) { + protected AbstractArtifactRepository(String name, String type, String version, URI location, String description, String provider, Map properties) { super(name, type, version, location, description, provider, properties); } @@ -43,7 +43,7 @@ public abstract class AbstractArtifactRepository extends AbstractRepository impl public OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException { if (!isModifiable()) - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.repoReadOnly, getLocation().toExternalForm()))); + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.repoReadOnly, getLocation()))); return null; } @@ -74,7 +74,7 @@ public abstract class AbstractArtifactRepository extends AbstractRepository impl if (!(o instanceof AbstractArtifactRepository)) { return false; } - if (URLUtil.sameURL(getLocation(), ((AbstractArtifactRepository) o).getLocation())) + if (URIUtil.sameURI(getLocation(), ((AbstractArtifactRepository) o).getLocation())) return true; return false; } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/IArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/IArtifactRepositoryFactory.java index 0e7f50b40..2a918ca6f 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/IArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/IArtifactRepositoryFactory.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; @@ -34,7 +34,7 @@ public interface IArtifactRepositoryFactory { * <li>A repository already exists at that location.</li> * </ul> */ - public IArtifactRepository create(URL location, String name, String type, Map properties) throws ProvisionException; + public IArtifactRepository create(URI location, String name, String type, Map properties) throws ProvisionException; /** * Loads the repository at the given location. The location is expected to contain @@ -51,5 +51,5 @@ public interface IArtifactRepositoryFactory { * <li>The repository at that location could not be read.</li> * </ul> */ - public IArtifactRepository load(URL location, IProgressMonitor monitor) throws ProvisionException; + public IArtifactRepository load(URI location, IProgressMonitor monitor) throws ProvisionException; } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java index 639386d0c..1205541bd 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository; import java.io.*; -import java.net.URL; +import java.net.URI; import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; @@ -20,13 +20,14 @@ import org.eclipse.equinox.internal.p2.artifact.repository.*; import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryIO; import org.eclipse.equinox.internal.p2.core.helpers.Tracing; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.osgi.util.NLS; public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFactory { - public IArtifactRepository load(URL location, IProgressMonitor monitor) throws ProvisionException { + public IArtifactRepository load(URI location, IProgressMonitor monitor) throws ProvisionException { final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ long time = 0; final String debugMsg = "Restoring artifact repository "; //$NON-NLS-1$ @@ -41,7 +42,7 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto OutputStream artifacts = null; // try with compressed boolean compress = true; - if (PROTOCOL_FILE.equals(location.getProtocol())) { + if (PROTOCOL_FILE.equals(location.getScheme())) { local = true; localFile = new File(SimpleArtifactRepository.getActualLocation(location, true).getPath()); if (!localFile.exists()) { @@ -53,11 +54,11 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto localFile = File.createTempFile("artifacts", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ try { artifacts = new BufferedOutputStream(new FileOutputStream(localFile)); - IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100)); + IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toString(), artifacts, sub.newChild(100)); if (!status.isOK()) { // retry uncompressed compress = false; - status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100)); + status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toString(), artifacts, sub.newChild(100)); if (!status.isOK()) throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, status.getMessage(), null)); } @@ -70,15 +71,15 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto try { descriptorStream = new BufferedInputStream(new FileInputStream(localFile)); if (compress) { - URL actualFile = SimpleArtifactRepository.getActualLocation(location, false); + URI actualLocation = SimpleArtifactRepository.getActualLocation(location, false); JarInputStream jInStream = new JarInputStream(descriptorStream); JarEntry jarEntry = jInStream.getNextJarEntry(); - String filename = new Path(actualFile.getFile()).lastSegment(); - while (jarEntry != null && !(filename.equals(jarEntry.getName()))) { + String filename = URIUtil.lastSegment(actualLocation); + while (jarEntry != null && filename != null && !(filename.equals(jarEntry.getName()))) { jarEntry = jInStream.getNextJarEntry(); } if (jarEntry == null) { - throw new FileNotFoundException("Repository not found in " + actualFile.getPath()); //$NON-NLS-1$ + throw new FileNotFoundException("Repository not found in " + actualLocation.getPath()); //$NON-NLS-1$ } descriptorStream = jInStream; } @@ -106,7 +107,7 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto } } - public IArtifactRepository create(URL location, String name, String type, Map properties) { + public IArtifactRepository create(URI location, String name, String type, Map properties) { return new SimpleArtifactRepository(name, location, properties); } diff --git a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java index 7826ee343..d7ed6bd5b 100644 --- a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java +++ b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java @@ -10,8 +10,8 @@ package org.eclipse.equinox.internal.p2.console; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; @@ -65,7 +65,7 @@ public class ProvCommandProvider implements CommandProvider { interpreter.println(); return; } - URL repoURL = toURL(interpreter, urlString); + URI repoURL = toURI(interpreter, urlString); if (repoURL == null) return; if (ProvisioningHelper.addMetadataRepository(repoURL) == null) @@ -79,7 +79,7 @@ public class ProvCommandProvider implements CommandProvider { interpreter.println(); return; } - URL repoURL = toURL(interpreter, urlString); + URI repoURL = toURI(interpreter, urlString); if (repoURL == null) return; ProvisioningHelper.removeMetadataRepository(repoURL); @@ -92,7 +92,7 @@ public class ProvCommandProvider implements CommandProvider { interpreter.println(); return; } - URL repoURL = toURL(interpreter, urlString); + URI repoURL = toURI(interpreter, urlString); if (repoURL == null) return; if (ProvisioningHelper.addArtifactRepository(repoURL) == null) @@ -106,7 +106,7 @@ public class ProvCommandProvider implements CommandProvider { interpreter.println(); return; } - URL repoURL = toURL(interpreter, urlString); + URI repoURL = toURI(interpreter, urlString); if (repoURL == null) return; ProvisioningHelper.removeArtifactRepository(repoURL); @@ -185,9 +185,9 @@ public class ProvCommandProvider implements CommandProvider { String urlString = processArgument(interpreter.nextArgument()); String id = processArgument(interpreter.nextArgument()); String version = processArgument(interpreter.nextArgument()); - URL repoURL = null; + URI repoURL = null; if (urlString != null && !urlString.equals(WILDCARD_ANY)) - repoURL = toURL(interpreter, urlString); + repoURL = toURI(interpreter, urlString); IInstallableUnit[] units = sort(ProvisioningHelper.getInstallableUnits(repoURL, new InstallableUnitQuery(id, new VersionRange(version)), null)); for (int i = 0; i < units.length; i++) println(interpreter, units[i]); @@ -204,16 +204,16 @@ public class ProvCommandProvider implements CommandProvider { String id = processArgument(interpreter.nextArgument()); String version = processArgument(interpreter.nextArgument()); if (urlString == null) { - URL[] repositories = ProvisioningHelper.getMetadataRepositories(); + URI[] repositories = ProvisioningHelper.getMetadataRepositories(); if (repositories != null) for (int i = 0; i < repositories.length; i++) interpreter.println(repositories[i]); return; } - URL repoURL = toURL(interpreter, urlString); - if (repoURL == null) + URI repoLocation = toURI(interpreter, urlString); + if (repoLocation == null) return; - IInstallableUnit[] units = sort(ProvisioningHelper.getInstallableUnits(repoURL, new InstallableUnitQuery(id, new VersionRange(version)), null)); + IInstallableUnit[] units = sort(ProvisioningHelper.getInstallableUnits(repoLocation, new InstallableUnitQuery(id, new VersionRange(version)), null)); for (int i = 0; i < units.length; i++) println(interpreter, units[i]); } @@ -232,7 +232,7 @@ public class ProvCommandProvider implements CommandProvider { if (queryable == null) return; } else { - URL repoURL = toURL(interpreter, urlString); + URI repoURL = toURI(interpreter, urlString); if (repoURL == null) return; queryable = ProvisioningHelper.getMetadataRepository(repoURL); @@ -254,14 +254,14 @@ public class ProvCommandProvider implements CommandProvider { public void _provlar(CommandInterpreter interpreter) { String urlString = processArgument(interpreter.nextArgument()); if (urlString == null) { - URL[] repositories = ProvisioningHelper.getArtifactRepositories(); + URI[] repositories = ProvisioningHelper.getArtifactRepositories(); if (repositories == null) return; for (int i = 0; i < repositories.length; i++) interpreter.println(repositories[i]); return; } - URL repoURL = toURL(interpreter, urlString); + URI repoURL = toURI(interpreter, urlString); if (repoURL == null) return; IArtifactRepository repo = ProvisioningHelper.getArtifactRepository(repoURL); @@ -294,10 +294,10 @@ public class ProvCommandProvider implements CommandProvider { * Returns the given string as an URL, or <code>null</code> if the string * could not be interpreted as an URL. */ - private URL toURL(CommandInterpreter interpreter, String urlString) { + private URI toURI(CommandInterpreter interpreter, String urlString) { try { - return new URL(urlString); - } catch (MalformedURLException e) { + return new URI(urlString); + } catch (URISyntaxException e) { interpreter.print(e.getMessage()); interpreter.println(); return null; diff --git a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java index b814b3ee1..6704898f2 100644 --- a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java +++ b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.p2.console; import java.io.IOException; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -32,7 +32,7 @@ import org.osgi.framework.Version; public class ProvisioningHelper { - public static IMetadataRepository addMetadataRepository(URL location) { + public static IMetadataRepository addMetadataRepository(URI location) { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) throw new IllegalStateException("No metadata repository manager found"); //$NON-NLS-1$ @@ -51,7 +51,7 @@ public class ProvisioningHelper { } } - public static IMetadataRepository getMetadataRepository(URL location) { + public static IMetadataRepository getMetadataRepository(URI location) { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) throw new IllegalStateException("No metadata repository manager found"); @@ -62,14 +62,14 @@ public class ProvisioningHelper { } } - public static void removeMetadataRepository(URL location) { + public static void removeMetadataRepository(URI location) { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) throw new IllegalStateException("No metadata repository manager found"); manager.removeRepository(location); } - public static IArtifactRepository addArtifactRepository(URL location) { + public static IArtifactRepository addArtifactRepository(URI location) { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) // TODO log here @@ -88,7 +88,7 @@ public class ProvisioningHelper { } } - public static void removeArtifactRepository(URL location) { + public static void removeArtifactRepository(URI location) { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) // TODO log here @@ -153,11 +153,11 @@ public class ProvisioningHelper { * @param monitor A progress monitor, or <code>null</code> * @return The IUs that match the query */ - public static Collector getInstallableUnits(URL location, Query query, IProgressMonitor monitor) { + public static Collector getInstallableUnits(URI location, Query query, IProgressMonitor monitor) { return getInstallableUnits(location, query, new Collector(), monitor); } - public static Collector getInstallableUnits(URL location, Query query, Collector collector, IProgressMonitor monitor) { + public static Collector getInstallableUnits(URI location, Query query, Collector collector, IProgressMonitor monitor) { IQueryable queryable = null; if (location == null) { queryable = (IQueryable) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName()); @@ -167,12 +167,12 @@ public class ProvisioningHelper { return queryable.query(query, collector, monitor); } - public static URL[] getMetadataRepositories() { + public static URI[] getMetadataRepositories() { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) // TODO log here return null; - URL[] repos = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL); + URI[] repos = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL); if (repos.length > 0) return repos; return null; @@ -189,7 +189,7 @@ public class ProvisioningHelper { StringBuffer error = new StringBuffer(); error.append("Installable unit not found: " + unitId + ' ' + version + '\n'); error.append("Repositories searched:\n"); - URL[] repos = getMetadataRepositories(); + URI[] repos = getMetadataRepositories(); if (repos != null) { for (int i = 0; i < repos.length; i++) error.append(repos[i] + "\n"); @@ -245,18 +245,18 @@ public class ProvisioningHelper { } } - public static URL[] getArtifactRepositories() { + public static URI[] getArtifactRepositories() { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) // TODO log here return null; - URL[] repos = manager.getKnownRepositories(IArtifactRepositoryManager.REPOSITORIES_ALL); + URI[] repos = manager.getKnownRepositories(IArtifactRepositoryManager.REPOSITORIES_ALL); if (repos.length > 0) return repos; return null; } - public static IArtifactRepository getArtifactRepository(URL repoURL) { + public static IArtifactRepository getArtifactRepository(URI repoURL) { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); try { if (manager != null) diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/BasicLocation.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/BasicLocation.java index ba818793c..d430c70e6 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/BasicLocation.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/BasicLocation.java @@ -10,8 +10,8 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.core; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; /** @@ -71,18 +71,20 @@ public class BasicLocation implements AgentLocation { return lock; } - public URL getArtifactRepositoryURL() { + public URI getArtifactRepositoryURI() { //the cache is a co-located repository - return getMetadataRepositoryURL(); + return getMetadataRepositoryURI(); } - public URL getMetadataRepositoryURL() { + public URI getMetadataRepositoryURI() { try { - return new URL(getDataArea(Activator.ID), "cache/"); //$NON-NLS-1$ + return URIUtil.toURI(new URL(getDataArea(Activator.ID), "cache/")); //$NON-NLS-1$ } catch (MalformedURLException e) { // TODO Auto-generated catch block - return null; + } catch (URISyntaxException e) { + // TODO Auto-generated catch block } + return null; } public URL getDataArea(String touchpointId) { diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/AbstractRepositoryManager.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/AbstractRepositoryManager.java index d99ad0b9e..20bc58490 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/AbstractRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/AbstractRepositoryManager.java @@ -11,8 +11,7 @@ package org.eclipse.equinox.internal.p2.core.helpers; import java.lang.ref.SoftReference; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.preferences.ConfigurationScope; @@ -33,7 +32,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P public String description; public boolean isEnabled = true; public boolean isSystem = false; - public URL location; + public URI location; public String name; public SoftReference repository; public String suffix; @@ -54,13 +53,14 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P public static final String KEY_SYSTEM = "isSystem"; //$NON-NLS-1$ public static final String KEY_TYPE = "type"; //$NON-NLS-1$ public static final String KEY_URL = "url"; //$NON-NLS-1$ + public static final String KEY_URI = "uri"; //$NON-NLS-1$ public static final String KEY_VERSION = "version"; //$NON-NLS-1$ public static final String NODE_REPOSITORIES = "repositories"; //$NON-NLS-1$ /** * Map of String->RepositoryInfo, where String is the repository key - * obtained via getKey(URL). + * obtained via getKey(URI). */ protected Map repositories = null; @@ -112,9 +112,9 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } /* (non-Javadoc) - * @see org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager#addRepository(java.net.URL) + * @see org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager#addRepository(java.net.URI) */ - public void addRepository(URL location) { + public void addRepository(URI location) { //add the repository, or enable it if already known if (!addRepository(location, true, true)) setEnabled(location, true); @@ -128,7 +128,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * @return <code>true</code> if the repository was actually added, and * <code>false</code> otherwise. */ - private boolean addRepository(URL location, boolean isEnabled, boolean signalAdd) { + private boolean addRepository(URI location, boolean isEnabled, boolean signalAdd) { RepositoryInfo info = new RepositoryInfo(); info.location = location; info.isEnabled = isEnabled; @@ -147,7 +147,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P return added; } - protected IRepository basicGetRepository(URL location) { + protected IRepository basicGetRepository(URI location) { synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); @@ -162,7 +162,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } } - public IRepository basicRefreshRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public IRepository basicRefreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException { clearNotFound(location); boolean wasEnabled = isEnabled(location); //remove the repository so event is broadcast and repositories can clear their caches @@ -179,7 +179,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } } - private void broadcastChangeEvent(URL location, int repositoryType, int kind, boolean isEnabled) { + private void broadcastChangeEvent(URI location, int repositoryType, int kind, boolean isEnabled) { IProvisioningEventBus bus = (IProvisioningEventBus) ServiceHelper.getService(Activator.getContext(), IProvisioningEventBus.class.getName()); if (bus != null) bus.publishEvent(new RepositoryEvent(location, repositoryType, kind, isEnabled)); @@ -190,7 +190,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * to find anything. Returns <code>true</code> if the repository was not * found, and <code>false</code> otherwise. */ - private boolean checkNotFound(URL location) { + private boolean checkNotFound(URI location) { if (unavailableRepositories == null) return false; List badRepos = (List) unavailableRepositories.get(); @@ -202,7 +202,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P /** * Clear the fact that we tried to load a repository at this location and did not find anything. */ - protected void clearNotFound(URL location) { + protected void clearNotFound(URI location) { List badRepos; if (unavailableRepositories != null) { badRepos = (List) unavailableRepositories.get(); @@ -216,7 +216,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P /** * TODO make private once API is available. See bug 248269. */ - public boolean contains(URL location) { + public boolean contains(URI location) { synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); @@ -249,9 +249,9 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * Loads and returns a repository using the given repository factory extension. Returns * null if no factory could be found associated with that extension. */ - protected abstract IRepository factoryLoad(URL location, IExtension extension, SubMonitor monitor) throws ProvisionException; + protected abstract IRepository factoryLoad(URI location, IExtension extension, SubMonitor monitor) throws ProvisionException; - protected void fail(URL location, int code) throws ProvisionException { + protected void fail(URI location, int code) throws ProvisionException { String msg = null; switch (code) { case ProvisionException.REPOSITORY_EXISTS : @@ -329,10 +329,10 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P /* * Return a string key based on the given repository location which * is suitable for use as a preference node name. - * TODO: convert local file system URL to canonical form + * TODO: convert local file system URI to canonical form */ - private String getKey(URL location) { - String key = location.toExternalForm().replace('/', '_'); + private String getKey(URI location) { + String key = location.toString().replace('/', '_'); //remove trailing slash if (key.endsWith("_")) //$NON-NLS-1$ key = key.substring(0, key.length() - 1); @@ -342,7 +342,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager#getKnownRepositories(int) */ - public URL[] getKnownRepositories(int flags) { + public URI[] getKnownRepositories(int flags) { synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); @@ -353,7 +353,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P if (matchesFlags(info, flags)) result.add(info.location); } - return (URL[]) result.toArray(new URL[result.size()]); + return (URI[]) result.toArray(new URI[result.size()]); } } @@ -365,9 +365,9 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } /*(non-Javadoc) - * @see org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager#getRepositoryProperty(java.net.URL, java.lang.String) + * @see org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager#getRepositoryProperty(java.net.URI, java.lang.String) */ - public String getRepositoryProperty(URL location, String key) { + public String getRepositoryProperty(URI location, String key) { synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); @@ -402,9 +402,9 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P protected abstract int getRepositoryType(); /* (non-Javadoc) - * @see org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager#isEnabled(java.net.URL) + * @see org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager#isEnabled(java.net.URI) */ - public boolean isEnabled(URL location) { + public boolean isEnabled(URI location) { synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); @@ -416,7 +416,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } } - protected IRepository loadRepository(URL location, IProgressMonitor monitor, String type) throws ProvisionException { + protected IRepository loadRepository(URI location, IProgressMonitor monitor, String type) throws ProvisionException { boolean added = false; IRepository result = null; synchronized (repositoryLock) { @@ -460,7 +460,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P return result; } - private IRepository loadRepository(URL location, String suffix, String type, SubMonitor monitor) { + private IRepository loadRepository(URI location, String suffix, String type, SubMonitor monitor) { IExtension[] providers = findMatchingRepositoryExtensions(suffix, type); // Loop over the candidates and return the first one that successfully loads monitor.beginTask("", providers.length * 10); //$NON-NLS-1$ @@ -494,7 +494,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P return false; } if ((flags & REPOSITORIES_LOCAL) == REPOSITORIES_LOCAL) - return "file".equals(info.location.getProtocol()); //$NON-NLS-1$ + return "file".equals(info.location.getScheme()); //$NON-NLS-1$ return true; } @@ -530,7 +530,8 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P private void remember(IRepository repository, String suffix) { boolean changed = false; Preferences node = getPreferences().node(getKey(repository.getLocation())); - changed |= putValue(node, KEY_URL, repository.getLocation().toExternalForm()); + changed |= putValue(node, KEY_URI, repository.getLocation().toString()); + changed |= putValue(node, KEY_URL, null); changed |= putValue(node, KEY_DESCRIPTION, repository.getDescription()); changed |= putValue(node, KEY_NAME, repository.getName()); changed |= putValue(node, KEY_PROVIDER, repository.getProvider()); @@ -548,7 +549,8 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P private boolean remember(RepositoryInfo info) { boolean changed = false; Preferences node = getPreferences().node(getKey(info.location)); - changed |= putValue(node, KEY_URL, info.location.toExternalForm()); + changed |= putValue(node, KEY_URI, info.location.toString()); + changed |= putValue(node, KEY_URL, null); changed |= putValue(node, KEY_SYSTEM, Boolean.toString(info.isSystem)); changed |= putValue(node, KEY_DESCRIPTION, info.description); changed |= putValue(node, KEY_NAME, info.name); @@ -562,7 +564,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P /** * Cache the fact that we tried to load a repository at this location and did not find anything. */ - private void rememberNotFound(URL location) { + private void rememberNotFound(URI location) { List badRepos; if (unavailableRepositories != null) { badRepos = (List) unavailableRepositories.get(); @@ -576,11 +578,11 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P unavailableRepositories = new SoftReference(badRepos); } - public boolean removeRepository(URL toRemove) { + public boolean removeRepository(URI toRemove) { return removeRepository(toRemove, true); } - private boolean removeRepository(URL toRemove, boolean signalRemove) { + private boolean removeRepository(URI toRemove, boolean signalRemove) { Assert.isNotNull(toRemove); final String repoKey = getKey(toRemove); synchronized (repositoryLock) { @@ -617,34 +619,55 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } for (int i = 0; i < children.length; i++) { Preferences child = node.node(children[i]); - String locationString = child.get(KEY_URL, null); - if (locationString == null) + URI location = getRepositoryLocation(child); + if (location == null) continue; - try { - RepositoryInfo info = new RepositoryInfo(); - info.location = new URL(locationString); - info.name = child.get(KEY_NAME, null); - info.description = child.get(KEY_DESCRIPTION, null); - info.isSystem = child.getBoolean(KEY_SYSTEM, false); - info.isEnabled = child.getBoolean(KEY_ENABLED, true); - info.suffix = child.get(KEY_SUFFIX, null); - repositories.put(getKey(info.location), info); - } catch (MalformedURLException e) { - log("Error while restoring repository: " + locationString, e); //$NON-NLS-1$ - } + RepositoryInfo info = new RepositoryInfo(); + info.location = location; + info.name = child.get(KEY_NAME, null); + info.description = child.get(KEY_DESCRIPTION, null); + info.isSystem = child.getBoolean(KEY_SYSTEM, false); + info.isEnabled = child.getBoolean(KEY_ENABLED, true); + info.suffix = child.get(KEY_SUFFIX, null); + repositories.put(getKey(info.location), info); } // now that we have loaded everything, remember them saveToPreferences(); } + /** + * Restores a repository location from the preferences. + */ + private URI getRepositoryLocation(Preferences node) { + //prefer the location stored in URI form + String locationString = node.get(KEY_URI, null); + try { + if (locationString != null) + return new URI(locationString); + } catch (URISyntaxException e) { + log("Error while restoring repository: " + locationString, e); //$NON-NLS-1$ + } + //we used to store the repository as a URL, so try old key for backwards compatibility + locationString = node.get(KEY_URL, null); + try { + if (locationString != null) + return URIUtil.toURI(new URL(locationString)); + } catch (MalformedURLException e) { + log("Error while restoring repository: " + locationString, e); //$NON-NLS-1$ + } catch (URISyntaxException e) { + log("Error while restoring repository: " + locationString, e); //$NON-NLS-1$ + } + return null; + } + private void restoreFromSystemProperty() { String locationString = Activator.getContext().getProperty(getRepositorySystemProperty()); if (locationString != null) { StringTokenizer tokenizer = new StringTokenizer(locationString, ","); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { try { - addRepository(new URL(tokenizer.nextToken()), true, true); - } catch (MalformedURLException e) { + addRepository(new URI(tokenizer.nextToken()), true, true); + } catch (URISyntaxException e) { log("Error while restoring repository " + locationString, e); //$NON-NLS-1$ } } @@ -682,9 +705,9 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } /* (non-Javadoc) - * @see org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager#setEnabled(java.net.URL, boolean) + * @see org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager#setEnabled(java.net.URI, boolean) */ - public void setEnabled(URL location, boolean enablement) { + public void setEnabled(URI location, boolean enablement) { synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); @@ -701,7 +724,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * Optimize the order in which repository suffixes are searched by trying * the last successfully loaded suffix first. */ - private String[] sortSuffixes(String[] suffixes, URL location) { + private String[] sortSuffixes(String[] suffixes, URI location) { synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/URIUtil.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/URIUtil.java new file mode 100644 index 000000000..677f7a601 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/URIUtil.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2008 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.internal.p2.core.helpers; + +import java.io.File; +import java.net.*; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.Path; + +/** + * A utility class for manipulating URIs. This class works around some of the + * broken behavior of the java.net.URI class. + */ +public class URIUtil { + + private static final String SCHEME_FILE = "file"; //$NON-NLS-1$ + + /** + * Appends the given extension to the path of the give base URI and returns + * the corresponding new path. + * @param base The base URI to append to + * @param extension The path extension to be added + * @return The appended URI + */ + public static URI append(URI base, String extension) { + try { + String path = base.getPath(); + if (path == null) + return appendOpaque(base, extension); + //if the base is already a directory then resolve will just do the right thing + if (path.endsWith("/")) //$NON-NLS-1$ + return base.resolve(extension); + path = path + "/" + extension; //$NON-NLS-1$ + return new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), path, base.getQuery(), base.getFragment()); + } catch (URISyntaxException e) { + //shouldn't happen because we started from a valid URI + throw new RuntimeException(e); + } + } + + /** + * Special case of appending to an opaque URI. Since opaque URIs + * have no path segment the best we can do is append to the scheme-specific part + */ + private static URI appendOpaque(URI base, String extension) throws URISyntaxException { + String ssp = base.getSchemeSpecificPart(); + if (ssp.endsWith("/")) //$NON-NLS-1$ + ssp += extension; + else + ssp = ssp + "/" + extension; //$NON-NLS-1$ + return new URI(base.getScheme(), ssp, base.getFragment()); + } + + /** + * Returns a URI corresponding to the given unencoded string. + * @throws URISyntaxException If the string cannot be formed into a valid URI + */ + public static URI fromString(String uriString) throws URISyntaxException { + int colon = uriString.indexOf(':'); + int hash = uriString.lastIndexOf('#'); + boolean noHash = hash < 0; + if (noHash) + hash = uriString.length(); + String scheme = colon < 0 ? null : uriString.substring(0, colon); + String ssp = uriString.substring(colon + 1, hash); + String fragment = noHash ? null : uriString.substring(hash + 1); + //use java.io.File for contructing file: URIs + if (scheme != null && scheme.equals(SCHEME_FILE)) + return new File(uriString.substring(5)).toURI(); + return new URI(scheme, ssp, fragment); + } + + /** + * Returns the last segment of the given URI. For a hierarchical URL this returns + * the last segment of the path. For opaque URIs this treats the scheme-specific + * part as a path and returns the last segment. Returns null if the URI has no + * path or the path is empty. + */ + public static String lastSegment(URI location) { + String path = location.getPath(); + if (path == null) + return new Path(location.getSchemeSpecificPart()).lastSegment(); + return new Path(path).lastSegment(); + } + + /* + * Compares two URI for equality. + * Return false if one of them is null + */ + public static boolean sameURI(URI url1, URI url2) { + if (url1 == url2) + return true; + if (url1 == null || url2 == null) + return false; + if (url1.equals(url2)) + return true; + + // check if we have two local file references that are case variants + File file1 = toFile(url1); + return file1 == null ? false : file1.equals(toFile(url2)); + } + + /** + * Returns the canonical form of the given URL. This eliminates extra slashes + * and converts local file system paths to canonical form for file: URLs. If any + * failure occurs while converting to canonical form the original URL is returned. + * @param location The location to convert to canonical form; must not be null + * @return The location in canonical form + */ + public static URI toCanonicalURL2(URI location) { + Assert.isNotNull(location); + File file = toFile(location); + if (file != null) { + try { + return file.getCanonicalFile().toURI(); + } catch (Exception e) { + //we made a best effort, just return the original location + return location; + } + } + //non-local URL, just remove trailing slash + String external = location.toString(); + if (!external.endsWith("/")) //$NON-NLS-1$ + return location; + try { + return new URI(external.substring(0, external.length() - 1)); + } catch (URISyntaxException e) { + //ignore and return original location + return location; + } + } + + /** + * Returns the URI as a local file, or <code>null</code> if the given + * URI does not represent a local file. + * @param uri The URI to return the file for + * @return The local file corresponding to the given URI, or <code>null</code> + */ + public static File toFile(URI uri) { + try { + if (!SCHEME_FILE.equalsIgnoreCase(uri.getScheme())) + return null; + //assume all illegal characters have been properly encoded, so use URI class to unencode + return new File(uri); + } catch (Exception e) { + //URL contains unencoded characters + String path = uri.getPath(); + //path is null for non-hierarchical URI such as file:c:/tmp + if (path == null) + path = uri.getSchemeSpecificPart(); + return new File(path); + } + } + + /** + * Returns the URL as a URI. This method will handle broken URLs that are + * not properly encoded (for example they contain unencoded space characters). + */ + public static URI toURI(URL url) throws URISyntaxException { + //go through java.io.File for file: URLs to ensure they are properly encoded + File file = URLUtil.toFile(url); + if (file != null) + return file.toURI(); + try { + return new URI(url.toExternalForm()); + } catch (URISyntaxException e) { + //try multi-argument URI constructor to perform encoding + return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); + } + } + + /** + * Returns the URI as a URL. + * @throws MalformedURLException + */ + public static URL toURL(URI uri) throws MalformedURLException { + return new URL(uri.toString()); + } +} diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/URLUtil.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/URLUtil.java index a03abb33a..b6693d146 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/URLUtil.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/URLUtil.java @@ -13,12 +13,43 @@ package org.eclipse.equinox.internal.p2.core.helpers; import java.io.File; import java.net.*; +import org.eclipse.core.runtime.Assert; /** * A utility class for manipulating URLs. This class works around some of the * broken behavior of the java.net.URL class. */ public class URLUtil { + /** + * Returns the canonical form of the given URL. This eliminates extra slashes + * and converts local file system paths to canonical form for file: URLs. If any + * failure occurs while converting to canonical form the original URL is returned. + * @param location The location to convert to canonical form; must not be null + * @return The location in canonical form + */ + public static URL toCanonicalURL2(URL location) { + Assert.isNotNull(location); + File file = URLUtil.toFile(location); + if (file != null) { + try { + return file.getCanonicalFile().toURL(); + } catch (Exception e) { + //we made a best effort, just return the original location + return location; + } + } + //non-local URL, just remove trailing slash + String external = location.toExternalForm(); + if (!external.endsWith("/")) //$NON-NLS-1$ + return location; + try { + return new URL(external.substring(0, external.length() - 1)); + } catch (MalformedURLException e) { + //ignore and return original location + return location; + } + } + /* * Compares two URL for equality. * Return false if one of them is null diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/location/AgentLocation.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/location/AgentLocation.java index 7a0df74d5..aacd84ac4 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/location/AgentLocation.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/location/AgentLocation.java @@ -10,14 +10,15 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.core.location; +import java.net.URI; import java.net.URL; public interface AgentLocation { public static final String SERVICE_NAME = AgentLocation.class.getName(); - public URL getArtifactRepositoryURL(); + public URI getArtifactRepositoryURI(); - public URL getMetadataRepositoryURL(); + public URI getMetadataRepositoryURI(); /** * Returns the location where the bundle with the given namespace diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/IRepository.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/IRepository.java index 453186523..ca073d239 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/IRepository.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/IRepository.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.core.repository; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.IAdaptable; @@ -109,7 +109,7 @@ public interface IRepository extends IAdaptable { * to be installed in Java. Can the URL have any protocol? * @return the URL of the repository. */ - public URL getLocation(); + public URI getLocation(); /** * Returns the name of the repository. diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/IRepositoryManager.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/IRepositoryManager.java index 4d5c7e948..fe24e0298 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/IRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/IRepositoryManager.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.core.repository; -import java.net.URL; +import java.net.URI; /** * The common base class for metadata and artifact repository managers. @@ -63,9 +63,9 @@ public interface IRepositoryManager { * there is a known, enabled repository at the given location when this method returns. * * @param location The location of the metadata repository to add - * @see #isEnabled(URL) + * @see #isEnabled(URI) */ - public void addRepository(URL location); + public void addRepository(URI location); /** * Returns the artifact repository locations known to the repository manager. @@ -86,10 +86,10 @@ public interface IRepositoryManager { * @see #REPOSITORIES_LOCAL * @see #REPOSITORIES_DISABLED */ - public URL[] getKnownRepositories(int flags); + public URI[] getKnownRepositories(int flags); /** - * Returns the property associated with the repository at the given URL, + * Returns the property associated with the repository at the given URI, * without loading the repository. * <p> * Note that some properties for a repository can only be @@ -101,7 +101,7 @@ public interface IRepositoryManager { * regardless of the cost of retrieving it, the client should load the * repository and then retrieve the property from the repository itself. * - * @param location the URL of the repository in question + * @param location the URI of the repository in question * @param key the String key of the property desired * @return the value of the property, or <code>null</code> if the repository * does not exist, the value does not exist, or the property value @@ -109,7 +109,7 @@ public interface IRepositoryManager { * * @see IRepository#getProperties() */ - public String getRepositoryProperty(URL location, String key); + public String getRepositoryProperty(URI location, String key); /** * Returns the enablement value of a repository. Disabled repositories are known @@ -126,9 +126,9 @@ public interface IRepositoryManager { * <code>false</code> if it is not enabled, or if the repository location * is not known to the repository manager. * @see #REPOSITORIES_DISABLED - * @see #setEnabled(URL, boolean) + * @see #setEnabled(URI, boolean) */ - public boolean isEnabled(URL location); + public boolean isEnabled(URI location); /** * Removes the repository at the given location from the list of @@ -140,7 +140,7 @@ public interface IRepositoryManager { * @return <code>true</code> if a repository was removed, and * <code>false</code> otherwise. */ - public boolean removeRepository(URL location); + public boolean removeRepository(URI location); /** * Sets the enablement of a repository. Disabled repositories are known @@ -159,8 +159,8 @@ public interface IRepositoryManager { * @param enablement <code>true</code>to enable the repository, and * <code>false</code> to disable the repository * @see #REPOSITORIES_DISABLED - * @see #isEnabled(URL) + * @see #isEnabled(URI) */ - public void setEnabled(URL location, boolean enablement); + public void setEnabled(URI location, boolean enablement); } diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/RepositoryEvent.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/RepositoryEvent.java index 2ed68baf1..c8d2680bc 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/RepositoryEvent.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/repository/RepositoryEvent.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.core.repository; -import java.net.URL; +import java.net.URI; import java.util.EventObject; /** @@ -70,7 +70,7 @@ public class RepositoryEvent extends EventObject { * @param kind the kind of change that occurred. * @param enabled whether the repository is enabled */ - public RepositoryEvent(URL location, int repositoryType, int kind, boolean enabled) { + public RepositoryEvent(URI location, int repositoryType, int kind, boolean enabled) { super(location); this.kind = kind; this.type = repositoryType; @@ -95,8 +95,8 @@ public class RepositoryEvent extends EventObject { * * @return the location of the repository associated with this event. */ - public URL getRepositoryLocation() { - return (URL) getSource(); + public URI getRepositoryLocation() { + return (URI) getSource(); } /** diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/spi/p2/core/repository/AbstractRepository.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/spi/p2/core/repository/AbstractRepository.java index b617ce2fe..793c0bbc3 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/spi/p2/core/repository/AbstractRepository.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/spi/p2/core/repository/AbstractRepository.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.spi.p2.core.repository; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; @@ -25,14 +25,14 @@ import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; */ public abstract class AbstractRepository extends PlatformObject implements IRepository { protected String description; - protected transient URL location; + protected transient URI location; protected String name; protected Map properties = new OrderedProperties(); protected String provider; protected String type; protected String version; - protected AbstractRepository(String name, String type, String version, URL location, String description, String provider, Map properties) { + protected AbstractRepository(String name, String type, String version, URI location, String description, String provider, Map properties) { this.name = name; this.type = type; this.version = version; @@ -67,7 +67,7 @@ public abstract class AbstractRepository extends PlatformObject implements IRepo * to be installed in Java. Can the URL have any protocol? * @return the URL of the repository. */ - public synchronized URL getLocation() { + public synchronized URI getLocation() { return location; } diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Application.java b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Application.java index ae4bb44c6..56c641f0f 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Application.java +++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Application.java @@ -12,8 +12,8 @@ package org.eclipse.equinox.internal.p2.director.app; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.app.IApplication; @@ -57,9 +57,9 @@ public class Application implements IApplication { private Path destination; - private URL[] artifactRepositoryLocations; + private URI[] artifactRepositoryLocations; - private URL[] metadataRepositoryLocations; + private URI[] metadataRepositoryLocations; private String root; private Version version = null; @@ -165,7 +165,6 @@ public class Application implements IApplication { } private void initializeRepositories(boolean throwException) throws CoreException { - if (artifactRepositoryLocations == null) { if (throwException) missingArgument("artifactRepository"); //$NON-NLS-1$ @@ -182,7 +181,7 @@ public class Application implements IApplication { anyValid = true; } catch (ProvisionException e) { //one of the repositories did not load - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, artifactRepositoryLocations[i].getPath() + " failed to load", e)); //$NON-NLS-1$ + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, artifactRepositoryLocations[i].toString() + " failed to load", e)); //$NON-NLS-1$ } } if (throwException && !anyValid) @@ -207,7 +206,7 @@ public class Application implements IApplication { anyValid = true; } catch (ProvisionException e) { //one of the repositories did not load - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, metadataRepositoryLocations[i].getPath() + " failed to load", e)); //$NON-NLS-1$ + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, metadataRepositoryLocations[i].toString() + " failed to load", e)); //$NON-NLS-1$ } } if (throwException && !anyValid) @@ -500,19 +499,19 @@ public class Application implements IApplication { return engine.perform(profile, new DefaultPhaseSet(), result.getOperands(), new ProvisioningContext(), new NullProgressMonitor()); } - private static URL[] getURLs(String spec) { + private static URI[] getURLs(String spec) { if (spec == null) return null; String[] urlSpecs = getArrayFromString(spec, ","); //$NON-NLS-1$ ArrayList result = new ArrayList(urlSpecs.length); for (int i = 0; i < urlSpecs.length; i++) { try { - result.add(new URL(urlSpecs[i])); - } catch (MalformedURLException e) { + result.add(new URI(urlSpecs[i])); + } catch (URISyntaxException e) { NLS.bind(Messages.Ignored_repo, urlSpecs[i]); } } - return (URL[]) result.toArray(new URL[result.size()]); + return (URI[]) result.toArray(new URI[result.size()]); } /** diff --git a/bundles/org.eclipse.equinox.p2.director.app/src_ant/org/eclipse/equinox/p2/director/app/ant/DirectorTask.java b/bundles/org.eclipse.equinox.p2.director.app/src_ant/org/eclipse/equinox/p2/director/app/ant/DirectorTask.java index a13ed31bd..28d3b5fd3 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/src_ant/org/eclipse/equinox/p2/director/app/ant/DirectorTask.java +++ b/bundles/org.eclipse.equinox.p2.director.app/src_ant/org/eclipse/equinox/p2/director/app/ant/DirectorTask.java @@ -11,8 +11,8 @@ package org.eclipse.equinox.p2.director.app.ant; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import org.apache.tools.ant.*; @@ -30,7 +30,7 @@ public class DirectorTask extends Task { boolean list; String profile, flavor, os, ws, nl, arch, installIU, uninstallIU; File destination, bundlePool; - URL metadataRepository, artifactRepository; + URI metadataRepository, artifactRepository; Version version; /* @@ -64,11 +64,11 @@ public class DirectorTask extends Task { } if (metadataRepository != null) { result.add("-metadataRepository"); - result.add(metadataRepository.toExternalForm()); + result.add(metadataRepository.toString()); } if (artifactRepository != null) { result.add("-artifactRepository"); - result.add(artifactRepository.toExternalForm()); + result.add(artifactRepository.toString()); } if (flavor != null) { result.add("-flavor"); @@ -114,8 +114,8 @@ public class DirectorTask extends Task { public void setArtifactRepository(String value) { try { - artifactRepository = new URL(value); - } catch (MalformedURLException e) { + artifactRepository = new URI(value); + } catch (URISyntaxException e) { log("Error setting the artifact repository.", e, Project.MSG_ERR); } } @@ -142,8 +142,8 @@ public class DirectorTask extends Task { public void setMetadataRepository(String value) { try { - metadataRepository = new URL(value); - } catch (MalformedURLException e) { + metadataRepository = new URI(value); + } catch (URISyntaxException e) { log("Error setting the metadata repository.", e, Project.MSG_ERR); } } diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java index 7a3489275..29d3d1a29 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java @@ -8,10 +8,10 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.director; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.p2.rollback.FormerState; import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; import org.eclipse.equinox.internal.provisional.p2.director.*; @@ -40,13 +40,16 @@ public class SimpleDirector implements IDirector { new FormerState(getRollbackRepositoryLocation()); } - public URL getRollbackRepositoryLocation() { + public URI getRollbackRepositoryLocation() { AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(DirectorActivator.context, AgentLocation.class.getName()); try { - return new URL(agentLocation.getDataArea(DirectorActivator.PI_DIRECTOR), ROLLBACK_LOCATION); + return URIUtil.toURI(new URL(agentLocation.getDataArea(DirectorActivator.PI_DIRECTOR), ROLLBACK_LOCATION)); } catch (MalformedURLException e) { //we know this can't happen because the above URL is well-formed return null; + } catch (URISyntaxException e) { + //we know this can't happen because the above URL is well-formed + return null; } } diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java index 4f05b17b0..c172db756 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java @@ -10,7 +10,7 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.director; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.*; @@ -170,7 +170,7 @@ public class SimplePlanner implements IPlanner { return result; } - public static IInstallableUnit[] gatherAvailableInstallableUnits(IInstallableUnit[] additionalSource, URL[] repositories, ProvisioningContext context, IProgressMonitor monitor) { + public static IInstallableUnit[] gatherAvailableInstallableUnits(IInstallableUnit[] additionalSource, URI[] repositories, ProvisioningContext context, IProgressMonitor monitor) { Map resultsMap = new HashMap(); if (additionalSource != null) { for (int i = 0; i < additionalSource.length; i++) { @@ -228,7 +228,7 @@ public class SimplePlanner implements IPlanner { IInstallableUnit[] allIUs = updatePlannerInfo(profileChangeRequest); - URL[] metadataRepositories = (context != null) ? context.getMetadataRepositories() : null; + URI[] metadataRepositories = (context != null) ? context.getMetadataRepositories() : null; Dictionary newSelectionContext = createSelectionContext(profileChangeRequest.getProfileProperties()); List extraIUs = new ArrayList(Arrays.asList(profileChangeRequest.getAddedInstallableUnits())); @@ -381,7 +381,7 @@ public class SimplePlanner implements IPlanner { Map resultsMap = new HashMap(); IMetadataRepositoryManager repoMgr = (IMetadataRepositoryManager) ServiceHelper.getService(DirectorActivator.context, IMetadataRepositoryManager.class.getName()); - URL[] repositories = context.getMetadataRepositories(); + URI[] repositories = context.getMetadataRepositories(); if (repositories == null) repositories = repoMgr.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL); diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java index e39cfdde9..5d46f6918 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java @@ -8,7 +8,7 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.rollback; -import java.net.URL; +import java.net.URI; import java.util.*; import java.util.Map.Entry; import org.eclipse.core.runtime.*; @@ -35,7 +35,7 @@ public class FormerState { public static final String IUPROP_PREFIX = "---IUPROPERTY---"; //$NON-NLS-1$ public static final String IUPROP_POSTFIX = "---IUPROPERTYKEY---"; //$NON-NLS-1$ private static long lastTimestamp; - URL location = null; + URI location = null; Hashtable generatedIUs = new Hashtable(); //key profile id, value the iu representing this profile @@ -58,7 +58,7 @@ public class FormerState { return timestamp; } - public FormerState(URL repoLocation) { + public FormerState(URI repoLocation) { if (repoLocation == null) throw new IllegalArgumentException("Repository location can't be null"); //$NON-NLS-1$ IProvisioningEventBus eventBus = (IProvisioningEventBus) ServiceHelper.getService(DirectorActivator.context, IProvisioningEventBus.SERVICE_NAME); diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IDirector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IDirector.java index ce844edb0..c11d25e55 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IDirector.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IDirector.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.director; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; @@ -54,5 +54,5 @@ public interface IDirector { * Returns the location of the director's rollback repository, where information about * previous profile states is stored. */ - public URL getRollbackRepositoryLocation(); + public URI getRollbackRepositoryLocation(); } diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Activator.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Activator.java index 63f3ad864..54c196c30 100644 --- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Activator.java +++ b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Activator.java @@ -12,8 +12,7 @@ package org.eclipse.equinox.internal.provisional.p2.directorywatcher; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; @@ -48,17 +47,13 @@ public class Activator implements BundleActivator { return (IMetadataRepositoryManager) ServiceHelper.getService(context, IMetadataRepositoryManager.class.getName()); } - public static URL getDefaultRepositoryLocation(Object object, String repositoryName) { + public static URI getDefaultRepositoryLocation(Object object, String repositoryName) { PackageAdmin packageAdmin = (PackageAdmin) ServiceHelper.getService(context, PackageAdmin.class.getName()); Bundle bundle = packageAdmin.getBundle(object.getClass()); BundleContext context = bundle.getBundleContext(); File base = context.getDataFile(""); //$NON-NLS-1$ File result = new File(base, "listener_" + repositoryName.hashCode()); //$NON-NLS-1$ result.mkdirs(); - try { - return result.toURL(); - } catch (MalformedURLException e) { - return null; - } + return result.toURI(); } } diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/CachingArtifactRepository.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/CachingArtifactRepository.java index e08d5259a..8abed2915 100644 --- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/CachingArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/CachingArtifactRepository.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.provisional.p2.directorywatcher; import java.io.File; import java.io.OutputStream; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; @@ -172,7 +172,7 @@ public class CachingArtifactRepository implements IArtifactRepository, IFileArti return innerRepo.getDescription(); } - public URL getLocation() { + public URI getLocation() { return innerRepo.getLocation(); } diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java index 807c8527d..aac31ef40 100644 --- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java +++ b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java @@ -12,7 +12,7 @@ package org.eclipse.equinox.internal.provisional.p2.directorywatcher; import java.io.File; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; @@ -57,8 +57,8 @@ public class RepositoryListener extends DirectoryChangeListener { * @param hidden <code>true</code> if the repository should be hidden, <code>false</code> if not. */ public RepositoryListener(String repositoryName, boolean hidden) { - URL location = Activator.getDefaultRepositoryLocation(this, repositoryName); - metadataRepository = initiailzeMetadataRepository(repositoryName, location, hidden); + URI location = Activator.getDefaultRepositoryLocation(this, repositoryName); + metadataRepository = initializeMetadataRepository(repositoryName, location, hidden); artifactRepository = initializeArtifactRepository(repositoryName, location, hidden); initializePublisher(); } @@ -77,7 +77,7 @@ public class RepositoryListener extends DirectoryChangeListener { info.setArtifactOptions(IPublisherInfo.A_INDEX); } - protected CachingArtifactRepository initializeArtifactRepository(String repositoryName, URL repositoryLocation, boolean hidden) { + protected CachingArtifactRepository initializeArtifactRepository(String repositoryName, URI repositoryLocation, boolean hidden) { IArtifactRepositoryManager manager = Activator.getArtifactRepositoryManager(); if (manager == null) throw new IllegalStateException(Messages.artifact_repo_manager_not_registered); @@ -103,7 +103,7 @@ public class RepositoryListener extends DirectoryChangeListener { } } - protected IMetadataRepository initiailzeMetadataRepository(String repositoryName, URL repositoryLocation, boolean hidden) { + protected IMetadataRepository initializeMetadataRepository(String repositoryName, URI repositoryLocation, boolean hidden) { IMetadataRepositoryManager manager = Activator.getMetadataRepositoryManager(); if (manager == null) throw new IllegalStateException(Messages.metadata_repo_manager_not_registered); @@ -156,7 +156,7 @@ public class RepositoryListener extends DirectoryChangeListener { if (bundleDescription == null) return false; try { - advice.setProperties(file, file.lastModified(), file.toURL(), null); + advice.setProperties(file, file.lastModified(), file.toURL()); } catch (MalformedURLException e) { // should never happen } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java index 4a83a263f..412ced5ff 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java @@ -11,7 +11,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -31,11 +31,11 @@ public class DownloadManager { private static final Comparator LOCAL_FIRST_COMPARATOR = new Comparator() { public int compare(Object arg0, Object arg1) { - Assert.isTrue(arg0 instanceof URL); - Assert.isTrue(arg1 instanceof URL); + Assert.isTrue(arg0 instanceof URI); + Assert.isTrue(arg1 instanceof URI); - String protocol0 = ((URL) arg0).getProtocol(); - String protocol1 = ((URL) arg1).getProtocol(); + String protocol0 = ((URI) arg0).getScheme(); + String protocol1 = ((URI) arg1).getScheme(); if (protocol0.equals(FILE_PROTOCOL) && !protocol1.equals(FILE_PROTOCOL)) return -1; @@ -84,7 +84,7 @@ public class DownloadManager { return Status.OK_STATUS; IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) ServiceHelper.getService(EngineActivator.getContext(), IArtifactRepositoryManager.class.getName()); - URL[] repositories = null; + URI[] repositories = null; if (provContext == null || provContext.getArtifactRepositories() == null) repositories = repoMgr.getKnownRepositories(IArtifactRepositoryManager.REPOSITORIES_ALL); else @@ -99,7 +99,7 @@ public class DownloadManager { } } - private void fetch(IArtifactRepositoryManager repoMgr, URL[] repositories, SubMonitor monitor) { + private void fetch(IArtifactRepositoryManager repoMgr, URI[] repositories, SubMonitor monitor) { for (int i = 0; i < repositories.length && !requestsToProcess.isEmpty() && !monitor.isCanceled(); i++) { try { IArtifactRepository current = repoMgr.loadRepository(repositories[i], monitor.newChild(0)); diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/MetadataCache.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/MetadataCache.java index 0b5b52a45..f3d2ff65b 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/MetadataCache.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/MetadataCache.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -29,14 +29,14 @@ public class MetadataCache { static final private String REPOSITORY_NAME = "Agent Metadata Cache"; //$NON-NLS-1$ private ServiceReference busReference; private IProvisioningEventBus bus; - private URL location; + private URI location; //tracks the IUs that have been installed but not yet committed //TODO: This will work if a single profile is being modified but we should consider how to handle multiple concurrent profile changes.OD final ArrayList toAdd = new ArrayList(); public MetadataCache() { AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(EngineActivator.getContext(), AgentLocation.class.getName()); - location = (agentLocation != null ? agentLocation.getMetadataRepositoryURL() : null); + location = (agentLocation != null ? agentLocation.getMetadataRepositoryURI() : null); hookListener(); } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IProfile.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IProfile.java index c509ca0d4..f4c371a17 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IProfile.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/IProfile.java @@ -93,22 +93,20 @@ public interface IProfile extends IQueryable { public String[] getSubProfileIds(); /** - * Get the stored value associated with the given key. - * If the profile is a sub-profile and there is no value - * locally associated with the key, then the chain - * of parent profiles will be traversed to get an associated - * value from the nearest ancestor. + * Get the stored value associated with the given key. + * If the profile is a sub-profile and there is no value + * locally associated with the key, then the chain + * of parent profiles will be traversed to get an associated + * value from the nearest ancestor. * - * <code>null</code> is return if none of this profile - * or its ancestors associates a value with the key. + * <code>null</code> is return if none of this profile + * or its ancestors associates a value with the key. */ public String getProperty(String key); /** - * Get the stored value associated with the given key - * in this profile. - * No traversal of the ancestor hierarchy is done - * for sub-profiles. + * Get the stored value associated with the given key in this profile. + * No traversal of the ancestor hierarchy is done for sub-profiles. */ public String getLocalProperty(String key); diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProvisioningContext.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProvisioningContext.java index deefdf1c4..21b9cc5a8 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProvisioningContext.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/ProvisioningContext.java @@ -10,12 +10,12 @@ ******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.engine; -import java.net.URL; +import java.net.URI; import java.util.*; public class ProvisioningContext { - private URL[] metadataRepositories; //metadata repositories to consult - private URL[] artifactRepositories; //artifact repositories to consult + private URI[] metadataRepositories; //metadata repositories to consult + private URI[] artifactRepositories; //artifact repositories to consult private Properties properties = new Properties(); private List extraIUs = new ArrayList(); @@ -25,7 +25,7 @@ public class ProvisioningContext { artifactRepositories = null; } - public ProvisioningContext(URL[] metadataRepositories) { + public ProvisioningContext(URI[] metadataRepositories) { this.metadataRepositories = metadataRepositories; } @@ -33,15 +33,15 @@ public class ProvisioningContext { * Artifact repositories to consult when performing an operation. * @param artifactRepositories array of URLs */ - public void setArtifactRepositories(URL[] artifactRepositories) { + public void setArtifactRepositories(URI[] artifactRepositories) { this.artifactRepositories = artifactRepositories; } - public URL[] getMetadataRepositories() { + public URI[] getMetadataRepositories() { return metadataRepositories; } - public URL[] getArtifactRepositories() { + public URI[] getArtifactRepositories() { return artifactRepositories; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Sizing.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Sizing.java index 25d53b000..853c0de0e 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Sizing.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/phases/Sizing.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.engine.phases; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -67,7 +67,7 @@ public class Sizing extends InstallableUnitPhase { return Status.CANCEL_STATUS; IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) ServiceHelper.getService(EngineActivator.getContext(), IArtifactRepositoryManager.class.getName()); - URL[] repositories = null; + URI[] repositories = null; if (provContext == null || provContext.getArtifactRepositories() == null) repositories = repoMgr.getKnownRepositories(IArtifactRepositoryManager.REPOSITORIES_ALL); else diff --git a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/Activator.java b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/Activator.java index b587effcf..efe4c1d02 100644 --- a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/Activator.java +++ b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/Activator.java @@ -11,9 +11,9 @@ package org.eclipse.equinox.internal.p2.extensionlocation; import java.io.File; +import java.net.URI; import java.net.URL; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.p2.core.helpers.URLUtil; +import org.eclipse.equinox.internal.p2.core.helpers.*; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IFileArtifactRepository; import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; @@ -92,8 +92,8 @@ public class Activator implements BundleActivator { /** * Returns a reasonable human-readable repository name for the given location. */ - public static String getRepositoryName(URL location) { - File file = URLUtil.toFile(location); - return file == null ? location.toExternalForm() : file.getAbsolutePath(); + public static String getRepositoryName(URI location) { + File file = URIUtil.toFile(location); + return file == null ? location.toString() : file.getAbsolutePath(); } } diff --git a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationArtifactRepository.java b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationArtifactRepository.java index 15df198d8..51fd96120 100644 --- a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationArtifactRepository.java @@ -13,10 +13,10 @@ package org.eclipse.equinox.internal.p2.extensionlocation; import java.io.File; import java.io.OutputStream; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; @@ -37,24 +37,19 @@ public class ExtensionLocationArtifactRepository extends AbstractRepository impl * Return the location of a local repository based on * the given URL. */ - public static URL getLocalRepositoryLocation(URL location) { + public static URI getLocalRepositoryLocation(URI location) { BundleContext context = Activator.getContext(); - String stateDirName = Integer.toString(location.toExternalForm().hashCode()); + String stateDirName = Integer.toString(location.toString().hashCode()); File bundleData = context.getDataFile(null); File stateDir = new File(bundleData, stateDirName); - try { - return stateDir.toURL(); - } catch (MalformedURLException e) { - // unexpected - return null; - } + return stateDir.toURI(); } /* * Constructor for the class. Return a new extension location repository based on * the given url and nested repository. */ - public ExtensionLocationArtifactRepository(URL location, IFileArtifactRepository repository, IProgressMonitor monitor) throws ProvisionException { + public ExtensionLocationArtifactRepository(URI location, IFileArtifactRepository repository, IProgressMonitor monitor) throws ProvisionException { super(Activator.getRepositoryName(location), TYPE, VERSION.toString(), location, null, null, null); this.artifactRepository = repository; this.base = getBaseDirectory(location); @@ -84,12 +79,12 @@ public class ExtensionLocationArtifactRepository extends AbstractRepository impl state = value; } - public static void validate(URL location, IProgressMonitor monitor) throws ProvisionException { + public static void validate(URI location, IProgressMonitor monitor) throws ProvisionException { File base = getBaseDirectory(location); if (new File(base, EXTENSION_LOCATION).exists()) return; if (containsUpdateSiteFile(base)) { - String message = NLS.bind(Messages.error_update_site, location.toExternalForm()); + String message = NLS.bind(Messages.error_update_site, location.toString()); throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, message, null)); } } @@ -105,17 +100,17 @@ public class ExtensionLocationArtifactRepository extends AbstractRepository impl return false; } - public static File getBaseDirectory(URL url) throws ProvisionException { - if (!FILE.equals(url.getProtocol())) + public static File getBaseDirectory(URI uri) throws ProvisionException { + if (!FILE.equals(uri.getScheme())) throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, Messages.not_file_protocol, null)); - String path = url.getPath(); + String path = URIUtil.toFile(uri).getAbsolutePath(); if (path.endsWith(EXTENSION_LOCATION)) path = path.substring(0, path.length() - EXTENSION_LOCATION.length()); File base = new File(path); if (!base.isDirectory()) - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.not_directory, url.toExternalForm()), null)); + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.not_directory, uri.toString()), null)); if (isBaseDirectory(base)) return base; @@ -124,7 +119,7 @@ public class ExtensionLocationArtifactRepository extends AbstractRepository impl if (isBaseDirectory(eclipseBase)) return eclipseBase; - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.not_eclipse_extension, url.toExternalForm()), null)); + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.not_eclipse_extension, uri.toString()), null)); } private static boolean isBaseDirectory(File base) { diff --git a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationArtifactRepositoryFactory.java index fdf2ec168..3c66167e7 100644 --- a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationArtifactRepositoryFactory.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.extensionlocation; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; @@ -25,12 +25,12 @@ public class ExtensionLocationArtifactRepositoryFactory implements IArtifactRepo /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.IArtifactRepositoryFactory#create(java.net.URL, java.lang.String, java.lang.String, java.util.Map) */ - public IArtifactRepository create(URL location, String name, String type, Map properties) throws ProvisionException { + public IArtifactRepository create(URI location, String name, String type, Map properties) throws ProvisionException { // TODO proper progress monitoring IStatus status = validate(location, null); if (!status.isOK()) throw new ProvisionException(status); - URL repoLocation = ExtensionLocationArtifactRepository.getLocalRepositoryLocation(location); + URI repoLocation = ExtensionLocationArtifactRepository.getLocalRepositoryLocation(location); // unexpected if (repoLocation == null) throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, Messages.failed_create_local_artifact_repository)); @@ -44,7 +44,7 @@ public class ExtensionLocationArtifactRepositoryFactory implements IArtifactRepo // expected } if (failed) { - String msg = NLS.bind(Messages.repo_already_exists, location.toExternalForm()); + String msg = NLS.bind(Messages.repo_already_exists, location); throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_EXISTS, msg, null)); } IFileArtifactRepository repo = (IFileArtifactRepository) new SimpleArtifactRepositoryFactory().create(repoLocation, name, type, properties); @@ -54,12 +54,12 @@ public class ExtensionLocationArtifactRepositoryFactory implements IArtifactRepo /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.IArtifactRepositoryFactory#load(java.net.URL, org.eclipse.core.runtime.IProgressMonitor) */ - public IArtifactRepository load(URL location, IProgressMonitor monitor) throws ProvisionException { + public IArtifactRepository load(URI location, IProgressMonitor monitor) throws ProvisionException { // TODO proper progress monitoring IStatus status = validate(location, null); if (!status.isOK()) throw new ProvisionException(status); - URL repoLocation = ExtensionLocationArtifactRepository.getLocalRepositoryLocation(location); + URI repoLocation = ExtensionLocationArtifactRepository.getLocalRepositoryLocation(location); // unexpected if (repoLocation == null) throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, Messages.failed_create_local_artifact_repository)); @@ -72,7 +72,7 @@ public class ExtensionLocationArtifactRepositoryFactory implements IArtifactRepo } } - public IStatus validate(URL location, IProgressMonitor monitor) { + public IStatus validate(URI location, IProgressMonitor monitor) { try { ExtensionLocationArtifactRepository.validate(location, monitor); } catch (ProvisionException e) { diff --git a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepository.java b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepository.java index b1bd34fce..87ea1cdaf 100644 --- a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepository.java @@ -12,10 +12,10 @@ package org.eclipse.equinox.internal.p2.extensionlocation; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; @@ -37,24 +37,18 @@ public class ExtensionLocationMetadataRepository extends AbstractMetadataReposit /* * Return the URL for this repo's nested local repository. */ - public static URL getLocalRepositoryLocation(URL location) { + public static URI getLocalRepositoryLocation(URI location) { BundleContext context = Activator.getContext(); - String stateDirName = Integer.toString(location.toExternalForm().hashCode()); + String stateDirName = Integer.toString(location.toString().hashCode()); File bundleData = context.getDataFile(null); - File stateDir = new File(bundleData, stateDirName); - try { - return stateDir.toURL(); - } catch (MalformedURLException e) { - // unexpected - return null; - } + return new File(bundleData, stateDirName).toURI(); } /* * Constructor for the class. Return a new extension location repository based on the * given location and specified nested repo. */ - public ExtensionLocationMetadataRepository(URL location, IMetadataRepository repository, IProgressMonitor monitor) throws ProvisionException { + public ExtensionLocationMetadataRepository(URI location, IMetadataRepository repository, IProgressMonitor monitor) throws ProvisionException { super(Activator.getRepositoryName(location), TYPE, VERSION.toString(), location, null, null, null); this.metadataRepository = repository; this.base = getBaseDirectory(location); @@ -113,12 +107,12 @@ public class ExtensionLocationMetadataRepository extends AbstractMetadataReposit return metadataRepository.query(query, collector, monitor); } - public static void validate(URL location, IProgressMonitor monitor) throws ProvisionException { + public static void validate(URI location, IProgressMonitor monitor) throws ProvisionException { File base = getBaseDirectory(location); if (new File(base, EXTENSION_LOCATION).exists()) return; if (containsUpdateSiteFile(base)) { - String message = NLS.bind(Messages.error_update_site, location.toExternalForm()); + String message = NLS.bind(Messages.error_update_site, location.toString()); throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, message, null)); } } @@ -134,17 +128,17 @@ public class ExtensionLocationMetadataRepository extends AbstractMetadataReposit return false; } - public static File getBaseDirectory(URL url) throws ProvisionException { - if (!FILE.equals(url.getProtocol())) + public static File getBaseDirectory(URI uri) throws ProvisionException { + if (!FILE.equals(uri.getScheme())) throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, Messages.not_file_protocol, null)); - String path = url.getPath(); + File base = URIUtil.toFile(uri); + String path = base.getAbsolutePath(); if (path.endsWith(EXTENSION_LOCATION)) - path = path.substring(0, path.length() - EXTENSION_LOCATION.length()); - File base = new File(path); + base = new File(path.substring(0, path.length() - EXTENSION_LOCATION.length())); if (!base.isDirectory()) - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.not_directory, url.toExternalForm()), null)); + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.not_directory, uri.toString()), null)); if (isBaseDirectory(base)) return base; @@ -153,7 +147,7 @@ public class ExtensionLocationMetadataRepository extends AbstractMetadataReposit if (isBaseDirectory(eclipseBase)) return eclipseBase; - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.not_eclipse_extension, url.toExternalForm()), null)); + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.not_eclipse_extension, uri.toString()), null)); } private static boolean isBaseDirectory(File base) { diff --git a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepositoryFactory.java index 7e6db6867..ce3a4fcae 100644 --- a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepositoryFactory.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.extensionlocation; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -24,12 +24,12 @@ public class ExtensionLocationMetadataRepositoryFactory implements IMetadataRepo /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory#create(java.net.URL, java.lang.String, java.lang.String, java.util.Map) */ - public IMetadataRepository create(URL location, String name, String type, Map properties) throws ProvisionException { + public IMetadataRepository create(URI location, String name, String type, Map properties) throws ProvisionException { // TODO proper progress monitoring IStatus status = validate(location, null); if (!status.isOK()) throw new ProvisionException(status); - URL repoLocation = ExtensionLocationMetadataRepository.getLocalRepositoryLocation(location); + URI repoLocation = ExtensionLocationMetadataRepository.getLocalRepositoryLocation(location); // unexpected if (repoLocation == null) throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, Messages.failed_create_local_artifact_repository)); @@ -43,7 +43,7 @@ public class ExtensionLocationMetadataRepositoryFactory implements IMetadataRepo // expected } if (failed) { - String msg = NLS.bind(Messages.repo_already_exists, location.toExternalForm()); + String msg = NLS.bind(Messages.repo_already_exists, location.toString()); throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_EXISTS, msg, null)); } IMetadataRepository repository = new SimpleMetadataRepositoryFactory().create(repoLocation, name, null, properties); @@ -53,12 +53,12 @@ public class ExtensionLocationMetadataRepositoryFactory implements IMetadataRepo /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory#load(java.net.URL, org.eclipse.core.runtime.IProgressMonitor) */ - public IMetadataRepository load(URL location, IProgressMonitor monitor) throws ProvisionException { + public IMetadataRepository load(URI location, IProgressMonitor monitor) throws ProvisionException { // TODO proper progress monitoring IStatus status = validate(location, null); if (!status.isOK()) throw new ProvisionException(status); - URL repoLocation = ExtensionLocationMetadataRepository.getLocalRepositoryLocation(location); + URI repoLocation = ExtensionLocationMetadataRepository.getLocalRepositoryLocation(location); // unexpected if (repoLocation == null) throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, Messages.failed_create_local_artifact_repository)); @@ -74,7 +74,7 @@ public class ExtensionLocationMetadataRepositoryFactory implements IMetadataRepo /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory#validate(java.net.URL, org.eclipse.core.runtime.IProgressMonitor) */ - public IStatus validate(URL location, IProgressMonitor monitor) { + public IStatus validate(URI location, IProgressMonitor monitor) { try { ExtensionLocationMetadataRepository.validate(location, monitor); } catch (ProvisionException e) { diff --git a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/SiteListener.java b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/SiteListener.java index adacd5608..722b827b4 100644 --- a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/SiteListener.java +++ b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/SiteListener.java @@ -12,13 +12,13 @@ package org.eclipse.equinox.internal.p2.extensionlocation; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.core.helpers.URLUtil; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.p2.publisher.eclipse.FeatureParser; import org.eclipse.equinox.internal.p2.update.Site; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -42,7 +42,7 @@ public class SiteListener extends DirectoryChangeListener { private String policy; private String[] list; - private String url; + private String siteLocation; private DirectoryChangeListener delegate; private String[] managedFiles; private String[] toBeRemoved; @@ -97,7 +97,7 @@ public class SiteListener extends DirectoryChangeListener { // read-only wrappers. DirectoryChangeListener listener = new RepositoryListener(metadataRepository.metadataRepository, artifactRepository.artifactRepository); if (metadataRepository.getProperties().get(SiteListener.SITE_POLICY) != null) - listener = new SiteListener(metadataRepository.getProperties(), metadataRepository.getLocation().toExternalForm(), new BundlePoolFilteredListener(listener)); + listener = new SiteListener(metadataRepository.getProperties(), metadataRepository.getLocation().toString(), new BundlePoolFilteredListener(listener)); watcher.addListener(listener); watcher.poll(); artifactRepository.state(INITIALIZED); @@ -108,7 +108,7 @@ public class SiteListener extends DirectoryChangeListener { * Create a new site listener on the given site. */ public SiteListener(Map properties, String url, DirectoryChangeListener delegate) { - this.url = url; + this.siteLocation = url; this.delegate = delegate; this.policy = (String) properties.get(SITE_POLICY); Collection listCollection = new HashSet(); @@ -219,7 +219,7 @@ public class SiteListener extends DirectoryChangeListener { // ignore } } - String urlString = url; + String urlString = siteLocation; if (urlString.endsWith(Constants.EXTENSION_LOCATION)) urlString = urlString.substring(0, urlString.length() - Constants.EXTENSION_LOCATION.length()); List result = new ArrayList(); @@ -244,15 +244,15 @@ public class SiteListener extends DirectoryChangeListener { if (managedFiles != null) return managedFiles; List result = new ArrayList(); - File siteLocation; + File siteFile; try { - siteLocation = URLUtil.toFile(new URL(url)); - } catch (MalformedURLException e) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Unable to create a URL from site location: " + url, e)); //$NON-NLS-1$ + siteFile = URIUtil.toFile(new URI(siteLocation)); + } catch (URISyntaxException e) { + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Unable to create a URL from site location: " + siteLocation, e)); //$NON-NLS-1$ return new String[0]; } - Map pluginCache = getPlugins(siteLocation); - Map featureCache = getFeatures(siteLocation); + Map pluginCache = getPlugins(siteFile); + Map featureCache = getFeatures(siteFile); for (Iterator iter = featureCache.keySet().iterator(); iter.hasNext();) { File featureFile = (File) iter.next(); // add the feature path diff --git a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/InstallDescriptionParser.java b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/InstallDescriptionParser.java index 843107d63..8d879d396 100644 --- a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/InstallDescriptionParser.java +++ b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/InstallDescriptionParser.java @@ -12,8 +12,7 @@ package org.eclipse.equinox.internal.p2.installer; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; @@ -151,23 +150,23 @@ public class InstallDescriptionParser { } /** - * Returns an array of URLs from the given comma-separated list + * Returns an array of URIs from the given comma-separated list * of URLs. Returns null if the given spec does not contain any URLs. - * @return An array of URLs in the given spec, or <code>null</code> + * @return An array of URIs in the given spec, or <code>null</code> */ - private static URL[] getURLs(String spec) { + private static URI[] getURLs(String spec) { String[] urlSpecs = getArrayFromString(spec, ","); //$NON-NLS-1$ ArrayList result = new ArrayList(urlSpecs.length); for (int i = 0; i < urlSpecs.length; i++) { try { - result.add(new URL(urlSpecs[i])); - } catch (MalformedURLException e) { + result.add(new URI(urlSpecs[i])); + } catch (URISyntaxException e) { LogHelper.log(new Status(IStatus.ERROR, InstallerActivator.PI_INSTALLER, "Invalid URL in install description: " + urlSpecs[i], e)); //$NON-NLS-1$ } } if (result.isEmpty()) return null; - return (URL[]) result.toArray(new URL[result.size()]); + return (URI[]) result.toArray(new URI[result.size()]); } private static void safeClose(InputStream in) { diff --git a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/InstallUpdateProductOperation.java b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/InstallUpdateProductOperation.java index f71c743be..f9f11aca6 100644 --- a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/InstallUpdateProductOperation.java +++ b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/InstallUpdateProductOperation.java @@ -11,7 +11,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.installer; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -87,6 +87,7 @@ public class InstallUpdateProductOperation implements IInstallOperation { EnvironmentInfo info = (EnvironmentInfo) ServiceHelper.getService(InstallerActivator.getDefault().getContext(), EnvironmentInfo.class.getName()); String env = "osgi.os=" + info.getOS() + ",osgi.ws=" + info.getWS() + ",osgi.arch=" + info.getOSArch(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ properties.put(IProfile.PROP_ENVIRONMENTS, env); + properties.put(IProfile.PROP_NAME, installDescription.getProductName()); properties.putAll(installDescription.getProfileProperties()); IPath location = installDescription.getBundleLocation(); if (location != null) @@ -249,7 +250,7 @@ public class InstallUpdateProductOperation implements IInstallOperation { } private void prepareArtifactRepositories() throws ProvisionException { - URL[] repos = installDescription.getArtifactRepositories(); + URI[] repos = installDescription.getArtifactRepositories(); if (repos == null) return; for (int i = 0; i < repos.length; i++) @@ -257,7 +258,7 @@ public class InstallUpdateProductOperation implements IInstallOperation { } private void prepareMetadataRepositories() throws ProvisionException { - URL[] repos = installDescription.getMetadataRepositories(); + URI[] repos = installDescription.getMetadataRepositories(); if (repos == null) return; for (int i = 0; i < repos.length; i++) diff --git a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/provisional/p2/installer/InstallDescription.java b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/provisional/p2/installer/InstallDescription.java index f260973ee..94284fc99 100644 --- a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/provisional/p2/installer/InstallDescription.java +++ b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/provisional/p2/installer/InstallDescription.java @@ -11,7 +11,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.installer; -import java.net.URL; +import java.net.URI; import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.IPath; @@ -23,13 +23,13 @@ import org.eclipse.equinox.internal.p2.installer.VersionedName; * be installed, and where it will be installed. */ public class InstallDescription { - private URL[] artifactRepos; + private URI[] artifactRepos; private IPath installLocation; private IPath agentLocation; private IPath bundleLocation; private boolean isAutoStart; private String launcherName; - private URL[] metadataRepos; + private URI[] metadataRepos; private String productName; private VersionedName[] roots; private final Map profileProperties = new HashMap(); @@ -46,7 +46,7 @@ public class InstallDescription { * Returns the locations of the artifact repositories to install from * @return a list of artifact repository URLs */ - public URL[] getArtifactRepositories() { + public URI[] getArtifactRepositories() { return artifactRepos; } @@ -78,7 +78,7 @@ public class InstallDescription { * Returns the locations of the metadata repositories to install from * @return a list of metadata repository URLs */ - public URL[] getMetadataRepositories() { + public URI[] getMetadataRepositories() { return metadataRepos; } @@ -111,7 +111,7 @@ public class InstallDescription { this.agentLocation = agentLocation; } - public void setArtifactRepositories(URL[] value) { + public void setArtifactRepositories(URI[] value) { this.artifactRepos = value; } @@ -131,7 +131,7 @@ public class InstallDescription { this.launcherName = name; } - public void setMetadataRepositories(URL[] value) { + public void setMetadataRepositories(URI[] value) { this.metadataRepos = value; } diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/EclipseGeneratorApplication.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/EclipseGeneratorApplication.java index c226a073c..60ba86b80 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/EclipseGeneratorApplication.java +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/EclipseGeneratorApplication.java @@ -11,8 +11,7 @@ package org.eclipse.equinox.internal.p2.metadata.generator; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.IStatus; @@ -21,6 +20,7 @@ import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRepositoryManager; import org.eclipse.equinox.internal.p2.core.ProvisioningEventBus; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; @@ -105,10 +105,10 @@ public class EclipseGeneratorApplication implements IApplication { if (artifactLocation == null) return; IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.context, IArtifactRepositoryManager.class.getName()); - URL location; + URI location; try { - location = new URL(artifactLocation); - } catch (MalformedURLException e) { + location = new URI(artifactLocation); + } catch (URISyntaxException e) { throw new IllegalArgumentException(NLS.bind(Messages.exception_artifactRepoLocationURL, artifactLocation)); } @@ -136,7 +136,7 @@ public class EclipseGeneratorApplication implements IApplication { if (provider.reuseExistingPack200Files()) repository.setProperty(PUBLISH_PACK_FILES_AS_SIBLINGS, "true"); //$NON-NLS-1$ if (!provider.append()) { - File repoLocation = new File(location.getPath()); + File repoLocation = URIUtil.toFile(location); if (repoLocation.isFile()) repoLocation = repoLocation.getParentFile(); if (repoLocation.equals(provider.getBaseLocation())) @@ -167,10 +167,10 @@ public class EclipseGeneratorApplication implements IApplication { private void initializeMetadataRepository(EclipseInstallGeneratorInfoProvider provider) throws ProvisionException { if (metadataLocation == null) return; - URL location; + URI location; try { - location = new URL(metadataLocation); - } catch (MalformedURLException e) { + location = new URI(metadataLocation); + } catch (URISyntaxException e) { throw new IllegalArgumentException(NLS.bind(Messages.exception_metadataRepoLocationURL, metadataLocation)); } diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java index 444b8c0ef..ec8e24f04 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java @@ -9,8 +9,7 @@ package org.eclipse.equinox.internal.provisional.p2.metadata.generator; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.*; import java.util.Map.Entry; import org.eclipse.core.runtime.*; @@ -1102,11 +1101,11 @@ public class Generator { private void generateSiteReference(String location, String featureId, boolean isEnabled) { IMetadataRepository metadataRepo = info.getMetadataRepository(); try { - URL associateLocation = new URL(location); + URI associateLocation = new URI(location); int flags = isEnabled ? IRepository.ENABLED : IRepository.NONE; metadataRepo.addReference(associateLocation, IRepository.TYPE_METADATA, flags); metadataRepo.addReference(associateLocation, IRepository.TYPE_ARTIFACT, flags); - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { String message = "Invalid site reference: " + location; //$NON-NLS-1$ if (featureId != null) message = message + " in feature: " + featureId; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java index ec8bd95ca..b4ea8b305 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.metadata.mirror; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; @@ -27,8 +27,8 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadata public class MirrorApplication implements IApplication { private String[] rootSpecs; - private URL sourceLocation; - private URL destinationLocation; + private URI sourceLocation; + private URI destinationLocation; private IMetadataRepository source; private IMetadataRepository destination; private boolean transitive = false; @@ -146,9 +146,9 @@ public class MirrorApplication implements IApplication { String arg = args[++i]; if (args[i - 1].equalsIgnoreCase("-source")) //$NON-NLS-1$ - sourceLocation = new URL(arg); + sourceLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-destination")) //$NON-NLS-1$ - destinationLocation = new URL(arg); + destinationLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-roots")) //$NON-NLS-1$ rootSpecs = getArrayArgsFromString(arg, ","); //$NON-NLS-1$ if (args[i - 1].equalsIgnoreCase("-transitive")) //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CacheManager.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CacheManager.java index 72678305d..e2a966b56 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CacheManager.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CacheManager.java @@ -11,6 +11,7 @@ package org.eclipse.equinox.internal.p2.metadata.repository; import java.io.*; +import java.net.URI; import java.net.URL; import java.util.EventObject; import org.eclipse.core.runtime.*; @@ -41,9 +42,8 @@ public class CacheManager { /** * Returns a hash of the URL. */ - private int computeHash(URL repositoryLocation) { - //don't use URL#hashCode because it performs DNS lookups - return repositoryLocation.toExternalForm().hashCode(); + private int computeHash(URI repositoryLocation) { + return repositoryLocation.hashCode(); } /** @@ -57,17 +57,17 @@ public class CacheManager { * @throws IOException * @throws ProvisionException */ - public File createCache(URL repositoryLocation, IProgressMonitor monitor) throws IOException, ProvisionException { + public File createCache(URI repositoryLocation, IProgressMonitor monitor) throws IOException, ProvisionException { File cacheFile = getCache(repositoryLocation); - URL jarLocation = URLMetadataRepository.getActualLocation(repositoryLocation, JAR_EXTENSION); - URL xmlLocation = URLMetadataRepository.getActualLocation(repositoryLocation, XML_EXTENSION); + URI jarLocation = URLMetadataRepository.getActualLocation(repositoryLocation, JAR_EXTENSION); + URI xmlLocation = URLMetadataRepository.getActualLocation(repositoryLocation, XML_EXTENSION); AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); URL dataArea = agentLocation.getDataArea(Activator.ID + "/cache/"); //$NON-NLS-1$ File dataAreaFile = URLUtil.toFile(dataArea); int hashCode = computeHash(repositoryLocation); if (cacheFile == null || isCacheStale(repositoryLocation, cacheFile)) { long lastModifiedRemote = getTransport().getLastModified(jarLocation); - URL remoteFile; + URI remoteFile; if (lastModifiedRemote != 0) { cacheFile = new File(dataAreaFile, CONTENT_FILENAME + hashCode + JAR_EXTENSION); remoteFile = jarLocation; @@ -82,7 +82,7 @@ public class CacheManager { cacheFile.getParentFile().mkdirs(); OutputStream metadata = new BufferedOutputStream(new FileOutputStream(cacheFile)); try { - IStatus result = getTransport().download(remoteFile.toExternalForm(), metadata, monitor); + IStatus result = getTransport().download(remoteFile.toString(), metadata, monitor); if (!result.isOK()) { throw new ProvisionException(result); } @@ -97,7 +97,7 @@ public class CacheManager { * Deletes the local cache file for the given repository * @param repositoryLocation */ - void deleteCache(URL repositoryLocation) { + void deleteCache(URI repositoryLocation) { File cacheFile = getCache(repositoryLocation); if (cacheFile != null) safeDelete(cacheFile); @@ -109,7 +109,7 @@ public class CacheManager { * @return A {@link File} pointing to the cache file or <code>null</code> if * the cache file does not exist. */ - private File getCache(URL repositoryLocation) { + private File getCache(URI repositoryLocation) { AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); URL dataArea = agentLocation.getDataArea(Activator.ID + "/cache/"); //$NON-NLS-1$ File dataAreaFile = URLUtil.toFile(dataArea); @@ -144,10 +144,10 @@ public class CacheManager { * if the cache file is in sync with the repository. The cache file is * considered stale if there is no local cache file. */ - private boolean isCacheStale(URL repositoryLocation, File cacheFile) { + private boolean isCacheStale(URI repositoryLocation, File cacheFile) { long lastModified = cacheFile.lastModified(); String name = cacheFile.getName(); - URL metadataLocation = null; + URI metadataLocation = null; if (name.endsWith(XML_EXTENSION)) { metadataLocation = URLMetadataRepository.getActualLocation(repositoryLocation, XML_EXTENSION); } else if (name.endsWith(JAR_EXTENSION)) { diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java index 4816a199d..90373c4e0 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/ECFMetadataTransport.java @@ -125,8 +125,8 @@ public class ECFMetadataTransport { * @return A <code>long</code> representing the date. Returns <code>0</code> if the file is not found or an error occurred. * @exception OperationCanceledException if the request was canceled. */ - public long getLastModified(URL location) throws ProvisionException { - String locationString = location.toExternalForm(); + public long getLastModified(URI location) throws ProvisionException { + String locationString = location.toString(); try { IConnectContext context = getConnectionContext(locationString, false); for (int i = 0; i < LOGIN_RETRIES; i++) { diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java index c89c1cc89..7ff4170ce 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java @@ -12,13 +12,12 @@ package org.eclipse.equinox.internal.p2.metadata.repository; import java.io.*; -import java.net.URL; +import java.net.URI; import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.internal.p2.core.helpers.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; @@ -46,18 +45,22 @@ public class LocalMetadataRepository extends AbstractMetadataRepository { protected HashSet units = new LinkedHashSet(); protected HashSet repositories = new HashSet(); - private static File getActualLocation(URL location, String extension) { - String spec = location.getFile(); - if (spec.endsWith(CONTENT_FILENAME + extension)) - return new File(spec + extension); - if (spec.endsWith("/")) //$NON-NLS-1$ - spec += CONTENT_FILENAME; + private static File getActualLocation(URI location, String extension) { + File spec = URIUtil.toFile(location); + String path = spec.getAbsolutePath(); + if (path.endsWith(CONTENT_FILENAME + extension)) { + //todo this is the old code that doesn't look right + // return new File(spec + extension); + return spec; + } + if (path.endsWith("/")) //$NON-NLS-1$ + path += CONTENT_FILENAME; else - spec += "/" + CONTENT_FILENAME; //$NON-NLS-1$ - return new File(spec + extension); + path += "/" + CONTENT_FILENAME; //$NON-NLS-1$ + return new File(path + extension); } - public static File getActualLocation(URL location) { + public static File getActualLocation(URI location) { return getActualLocation(location, XML_EXTENSION); } @@ -73,9 +76,9 @@ public class LocalMetadataRepository extends AbstractMetadataRepository { * @param location The location of the repository * @param name The name of the repository */ - public LocalMetadataRepository(URL location, String name, Map properties) { - super(name == null ? (location != null ? location.toExternalForm() : "") : name, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties); //$NON-NLS-1$ - if (!location.getProtocol().equals("file")) //$NON-NLS-1$ + public LocalMetadataRepository(URI location, String name, Map properties) { + super(name == null ? (location != null ? location.toString() : "") : name, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties); //$NON-NLS-1$ + if (!location.getScheme().equals("file")) //$NON-NLS-1$ throw new IllegalArgumentException("Invalid local repository location: " + location); //$NON-NLS-1$ //when creating a repository, we must ensure it exists on disk so a subsequent load will succeed save(); @@ -88,7 +91,7 @@ public class LocalMetadataRepository extends AbstractMetadataRepository { save(); } - public synchronized void addReference(URL repositoryLocation, int repositoryType, int options) { + public synchronized void addReference(URI repositoryLocation, int repositoryType, int options) { assertModifiable(); repositories.add(new RepositoryReference(repositoryLocation, repositoryType, options)); } @@ -131,7 +134,7 @@ public class LocalMetadataRepository extends AbstractMetadataRepository { } // use this method to setup any transient fields etc after the object has been restored from a stream - public synchronized void initializeAfterLoad(URL aLocation) { + public synchronized void initializeAfterLoad(URI aLocation) { this.location = aLocation; } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryIO.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryIO.java index 3d854830f..2c029399a 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryIO.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryIO.java @@ -160,7 +160,7 @@ public class MetadataRepositoryIO { private void writeRepositoryReference(RepositoryReference reference) { start(REPOSITORY_REFERENCE_ELEMENT); - attribute(URL_ATTRIBUTE, reference.Location.toExternalForm()); + attribute(URL_ATTRIBUTE, reference.Location.toString()); attribute(TYPE_ATTRIBUTE, Integer.toString(reference.Type)); attribute(OPTIONS_ATTRIBUTE, Integer.toString(reference.Options)); end(REPOSITORY_REFERENCE_ELEMENT); diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryManager.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryManager.java index ad3deacc9..91c291a4e 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryManager.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.metadata.repository; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.AbstractRepositoryManager; @@ -39,7 +39,7 @@ public class MetadataRepositoryManager extends AbstractRepositoryManager impleme /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager#createRepository(java.net.URL, java.lang.String, java.lang.String, java.util.Map) */ - public IMetadataRepository createRepository(URL location, String name, String type, Map properties) throws ProvisionException { + public IMetadataRepository createRepository(URI location, String name, String type, Map properties) throws ProvisionException { Assert.isNotNull(name); Assert.isNotNull(type); boolean loaded = false; @@ -67,7 +67,7 @@ public class MetadataRepositoryManager extends AbstractRepositoryManager impleme return result; } - protected IRepository factoryLoad(URL location, IExtension extension, SubMonitor monitor) throws ProvisionException { + protected IRepository factoryLoad(URI location, IExtension extension, SubMonitor monitor) throws ProvisionException { IMetadataRepositoryFactory factory = (IMetadataRepositoryFactory) createExecutableExtension(extension, EL_FACTORY); if (factory == null) return null; @@ -82,7 +82,7 @@ public class MetadataRepositoryManager extends AbstractRepositoryManager impleme return "content.xml"; //$NON-NLS-1$ } - public IMetadataRepository getRepository(URL location) { + public IMetadataRepository getRepository(URI location) { return (IMetadataRepository) basicGetRepository(location); } @@ -101,7 +101,7 @@ public class MetadataRepositoryManager extends AbstractRepositoryManager impleme return IRepository.TYPE_METADATA; } - public IMetadataRepository loadRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public IMetadataRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException { return (IMetadataRepository) loadRepository(location, monitor, null); } @@ -126,7 +126,7 @@ public class MetadataRepositoryManager extends AbstractRepositoryManager impleme * @return The collector argument */ public Collector query(Query query, Collector collector, IProgressMonitor monitor) { - URL[] locations = getKnownRepositories(REPOSITORIES_ALL); + URI[] locations = getKnownRepositories(REPOSITORIES_ALL); SubMonitor sub = SubMonitor.convert(monitor, locations.length * 10); for (int i = 0; i < locations.length; i++) { try { @@ -141,17 +141,17 @@ public class MetadataRepositoryManager extends AbstractRepositoryManager impleme return collector; } - public IMetadataRepository refreshRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public IMetadataRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException { return (IMetadataRepository) basicRefreshRepository(location, monitor); } - public IStatus validateRepositoryLocation(URL location, IProgressMonitor monitor) { + public IStatus validateRepositoryLocation(URI location, IProgressMonitor monitor) { IMetadataRepository result = getRepository(location); if (result != null) return Status.OK_STATUS; String[] suffixes = getAllSuffixes(); SubMonitor sub = SubMonitor.convert(monitor, Messages.repo_loading, suffixes.length * 100); - IStatus status = new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.repoMan_notExists, location.toExternalForm()), null); + IStatus status = new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.repoMan_notExists, location.toString()), null); for (int i = 0; i < suffixes.length; i++) { SubMonitor loopMonitor = sub.newChild(100); IExtension[] providers = findMatchingRepositoryExtensions(suffixes[i], null); diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/URLMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/URLMetadataRepository.java index 28f88e4bf..de9b5e048 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/URLMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/URLMetadataRepository.java @@ -11,10 +11,10 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.metadata.repository; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.provisional.p2.query.Collector; import org.eclipse.equinox.internal.provisional.p2.query.Query; import org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.AbstractMetadataRepository; @@ -29,46 +29,30 @@ public class URLMetadataRepository extends AbstractMetadataRepository { private static final String REPOSITORY_TYPE = URLMetadataRepository.class.getName(); private static final Integer REPOSITORY_VERSION = new Integer(1); - transient protected URL content; + transient protected URI content; protected HashSet units = new LinkedHashSet(); - public static URL getActualLocation(URL base) { + public static URI getActualLocation(URI base) { return getActualLocation(base, XML_EXTENSION); } - public static URL getActualLocation(URL base, String extension) { - if (extension == null) { + public static URI getActualLocation(URI base, String extension) { + if (extension == null) extension = XML_EXTENSION; - } - String spec = base.toExternalForm(); - if (spec.endsWith(CONTENT_FILENAME + extension)) - try { - return new URL(spec + extension); - } catch (MalformedURLException e1) { - return null; - } - if (spec.endsWith("/")) //$NON-NLS-1$ - spec += CONTENT_FILENAME; - else - spec += "/" + CONTENT_FILENAME; //$NON-NLS-1$ - try { - return new URL(spec + extension); - } catch (MalformedURLException e) { - return null; - } + return URIUtil.append(base, CONTENT_FILENAME + extension); } public URLMetadataRepository() { super(); } - public URLMetadataRepository(URL location, String name, Map properties) { - super(name == null ? (location != null ? location.toExternalForm() : "") : name, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties); //$NON-NLS-1$ + public URLMetadataRepository(URI location, String name, Map properties) { + super(name == null ? (location != null ? location.toString() : "") : name, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties); //$NON-NLS-1$ content = getActualLocation(location); } // this is synchronized because content can be initialized in initializeAfterLoad - protected synchronized URL getContentURL() { + protected synchronized URI getContentURL() { return content; } @@ -84,7 +68,7 @@ public class URLMetadataRepository extends AbstractMetadataRepository { } // Use this method to setup any transient fields etc after the object has been restored from a stream - public synchronized void initializeAfterLoad(URL repoLocation) { + public synchronized void initializeAfterLoad(URI repoLocation) { this.location = repoLocation; content = getActualLocation(location); } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java index 35c404803..999093c3b 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java @@ -11,8 +11,8 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.metadata.repository.io; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; import org.eclipse.equinox.internal.p2.metadata.ArtifactKey; @@ -64,8 +64,8 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { try { int type = checkInteger(elementHandled, TYPE_ATTRIBUTE, values[1]); int options = checkInteger(elementHandled, OPTIONS_ATTRIBUTE, values[2]); - references.add(new RepositoryReference(new URL(values[0]), type, options)); - } catch (MalformedURLException e) { + references.add(new RepositoryReference(new URI(values[0]), type, options)); + } catch (URISyntaxException e) { invalidAttributeValue(elementHandled, URL_ATTRIBUTE, values[0]); } } @@ -355,10 +355,10 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { protected void finished() { if (children != null) { - scopes.add(children.getRequiredCapabilities()); - } + scopes.add(children.getRequiredCapabilities()); } } + } protected class RequirementsChangeHandler extends AbstractHandler { private List requirementChanges; diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/p2/metadata/repository/IMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/p2/metadata/repository/IMetadataRepository.java index 867fc84ed..f952a2ef5 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/p2/metadata/repository/IMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/p2/metadata/repository/IMetadataRepository.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.metadata.repository; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; @@ -54,9 +54,9 @@ public interface IMetadataRepository extends IRepository, IQueryable { * or {@link IRepository#TYPE_ARTIFACT}). * @param options bit-wise or of option constants (currently either * {@link IRepository#ENABLED} or {@link IRepository#NONE}). - * @see IMetadataRepositoryManager#setEnabled(URL, boolean) + * @see IMetadataRepositoryManager#setEnabled(URI, boolean) */ - public void addReference(URL location, int type, int options); + public void addReference(URI location, int type, int options); /** * Removes all installable units that match the given query from this repository. diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/p2/metadata/repository/IMetadataRepositoryManager.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/p2/metadata/repository/IMetadataRepositoryManager.java index 2dd0d554f..042a30829 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/p2/metadata/repository/IMetadataRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/p2/metadata/repository/IMetadataRepositoryManager.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.metadata.repository; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -37,7 +37,7 @@ public interface IMetadataRepositoryManager extends IRepositoryManager, IQueryab * the given location. * <p> * The resulting repository is added to the list of repositories tracked by - * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URL)} + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} * if they do not want the repository manager to remember the repository for subsequent * load attempts. * </p> @@ -54,7 +54,7 @@ public interface IMetadataRepositoryManager extends IRepositoryManager, IQueryab * <li>A repository already exists at that location.</li> * </ul> */ - public IMetadataRepository createRepository(URL location, String name, String type, Map properties) throws ProvisionException; + public IMetadataRepository createRepository(URI location, String name, String type, Map properties) throws ProvisionException; /** * Loads a repository corresponding to the given URL. If a repository has @@ -62,7 +62,7 @@ public interface IMetadataRepositoryManager extends IRepositoryManager, IQueryab * may be returned. * <p> * The resulting repository is added to the list of repositories tracked by - * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URL)} + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} * if they do not want the repository manager to remember the repository for subsequent * load attempts. * </p> @@ -77,7 +77,7 @@ public interface IMetadataRepositoryManager extends IRepositoryManager, IQueryab * <li>The repository at that location could not be read.</li> * </ul> */ - public IMetadataRepository loadRepository(URL location, IProgressMonitor monitor) throws ProvisionException; + public IMetadataRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException; /** * Refreshes the repository corresponding to the given URL. This method discards @@ -96,7 +96,7 @@ public interface IMetadataRepositoryManager extends IRepositoryManager, IQueryab * <li>The repository at that location could not be read.</li> * </ul> */ - public IMetadataRepository refreshRepository(URL location, IProgressMonitor monitor) throws ProvisionException; + public IMetadataRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException; /** * Validates a given URL and returns a status indicating whether a valid repository is likely @@ -117,5 +117,5 @@ public interface IMetadataRepositoryManager extends IRepositoryManager, IQueryab * <li>The repository at that location could not be read.</li> * </ul> */ - public IStatus validateRepositoryLocation(URL location, IProgressMonitor monitor); + public IStatus validateRepositoryLocation(URI location, IProgressMonitor monitor); } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/AbstractMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/AbstractMetadataRepository.java index 4ad53ad7e..6d8644789 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/AbstractMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/AbstractMetadataRepository.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; @@ -33,7 +33,7 @@ public abstract class AbstractMetadataRepository extends AbstractRepository impl public Version Version; public String Provider; public String Description; - public URL Location; + public URI Location; public Map Properties; public IInstallableUnit[] Units; public RepositoryReference[] Repositories; @@ -45,7 +45,7 @@ public abstract class AbstractMetadataRepository extends AbstractRepository impl public abstract void initialize(RepositoryState state); - protected AbstractMetadataRepository(String name, String type, String version, URL location, String description, String provider, Map properties) { + protected AbstractMetadataRepository(String name, String type, String version, URI location, String description, String provider, Map properties) { super(name, type, version, location, description, provider, properties); } @@ -53,7 +53,7 @@ public abstract class AbstractMetadataRepository extends AbstractRepository impl assertModifiable(); } - public void addReference(URL repositoryLocation, int repositoryType, int options) { + public void addReference(URI repositoryLocation, int repositoryType, int options) { assertModifiable(); } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/IMetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/IMetadataRepositoryFactory.java index 203c1cbe7..639cdad3b 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/IMetadataRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/IMetadataRepositoryFactory.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -34,7 +34,7 @@ public interface IMetadataRepositoryFactory { * <li>There was an error writing to the given repository location.</li> * </ul> */ - public IMetadataRepository create(URL location, String name, String type, Map properties) throws ProvisionException; + public IMetadataRepository create(URI location, String name, String type, Map properties) throws ProvisionException; /** * Loads a repository corresponding to the given URL. @@ -49,7 +49,7 @@ public interface IMetadataRepositoryFactory { * <li>The repository at that location could not be read.</li> * </ul> */ - public IMetadataRepository load(URL location, IProgressMonitor monitor) throws ProvisionException; + public IMetadataRepository load(URI location, IProgressMonitor monitor) throws ProvisionException; /** * Validates a candidate repository URL and returns a status indicating the @@ -73,5 +73,5 @@ public interface IMetadataRepositoryFactory { * <li>The repository at that location could not be read.</li> * </ul> */ - public IStatus validate(URL location, IProgressMonitor monitor); + public IStatus validate(URI location, IProgressMonitor monitor); } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/RepositoryReference.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/RepositoryReference.java index c9c985e52..83f9dbab8 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/RepositoryReference.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/RepositoryReference.java @@ -10,17 +10,17 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository; -import java.net.URL; +import java.net.URI; /** * Serialization helper class for repository references. */ public class RepositoryReference { - public URL Location; + public URI Location; public int Type; public int Options; - public RepositoryReference(URL location, int type, int options) { + public RepositoryReference(URI location, int type, int options) { this.Location = location; this.Type = type; this.Options = options; diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/SimpleMetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/SimpleMetadataRepositoryFactory.java index d7bf00358..6bbb6d1d1 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/SimpleMetadataRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/SimpleMetadataRepositoryFactory.java @@ -11,12 +11,13 @@ package org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository; import java.io.*; -import java.net.URL; +import java.net.URI; import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.Tracing; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.p2.metadata.repository.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; @@ -28,8 +29,8 @@ public class SimpleMetadataRepositoryFactory implements IMetadataRepositoryFacto private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ - public IMetadataRepository create(URL location, String name, String type, Map properties) { - if (location.getProtocol().equals("file")) //$NON-NLS-1$ + public IMetadataRepository create(URI location, String name, String type, Map properties) { + if (location.getScheme().equals("file")) //$NON-NLS-1$ return new LocalMetadataRepository(location, name, properties); return new URLMetadataRepository(location, name, properties); } @@ -38,18 +39,18 @@ public class SimpleMetadataRepositoryFactory implements IMetadataRepositoryFacto * Returns a file in the local file system that contains the contents of the * metadata repository at the given location. */ - private File getLocalFile(URL location, IProgressMonitor monitor) throws IOException, ProvisionException { + private File getLocalFile(URI location, IProgressMonitor monitor) throws IOException, ProvisionException { File localFile = null; - URL jarLocation = URLMetadataRepository.getActualLocation(location, JAR_EXTENSION); - URL xmlLocation = URLMetadataRepository.getActualLocation(location, XML_EXTENSION); + URI jarLocation = URLMetadataRepository.getActualLocation(location, JAR_EXTENSION); + URI xmlLocation = URLMetadataRepository.getActualLocation(location, XML_EXTENSION); // If the repository is local, we can return the repository file directly - if (PROTOCOL_FILE.equals(xmlLocation.getProtocol())) { + if (PROTOCOL_FILE.equals(xmlLocation.getScheme())) { //look for a compressed local file - localFile = new File(jarLocation.getPath()); + localFile = URIUtil.toFile(jarLocation); if (localFile.exists()) return localFile; //look for an uncompressed local file - localFile = new File(xmlLocation.getPath()); + localFile = URIUtil.toFile(xmlLocation); if (localFile.exists()) return localFile; String msg = NLS.bind(Messages.io_failedRead, location); @@ -69,7 +70,7 @@ public class SimpleMetadataRepositoryFactory implements IMetadataRepositoryFacto * (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory#validate(java.net.URL, org.eclipse.core.runtime.IProgressMonitor) */ - public IStatus validate(URL location, IProgressMonitor monitor) { + public IStatus validate(URI location, IProgressMonitor monitor) { try { validateAndLoad(location, false, monitor); } catch (ProvisionException e) { @@ -81,11 +82,11 @@ public class SimpleMetadataRepositoryFactory implements IMetadataRepositoryFacto /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory#load(java.net.URL, org.eclipse.core.runtime.IProgressMonitor) */ - public IMetadataRepository load(URL location, IProgressMonitor monitor) throws ProvisionException { + public IMetadataRepository load(URI location, IProgressMonitor monitor) throws ProvisionException { return validateAndLoad(location, true, monitor); } - protected IMetadataRepository validateAndLoad(URL location, boolean doLoad, IProgressMonitor monitor) throws ProvisionException { + protected IMetadataRepository validateAndLoad(URI location, boolean doLoad, IProgressMonitor monitor) throws ProvisionException { long time = 0; final String debugMsg = "Validating and loading metadata repository "; //$NON-NLS-1$ if (Tracing.DEBUG_METADATA_PARSING) { diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/RequiredCapability.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/RequiredCapability.java index 64058a478..4dbc9bfe6 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/RequiredCapability.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/provisional/p2/metadata/RequiredCapability.java @@ -36,6 +36,9 @@ public class RequiredCapability { private final VersionRange range;//never null private String[] selectors = NO_SELECTORS;//never null + /** + * TODO replace booleans with int options flag. + */ RequiredCapability(String namespace, String name, VersionRange range, String filter, boolean optional, boolean multiple) { Assert.isNotNull(namespace); Assert.isNotNull(name); diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java index 84599adaa..06c760ae8 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java @@ -10,8 +10,8 @@ ******************************************************************************/ package org.eclipse.equinox.p2.publisher; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Collection; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -44,10 +44,10 @@ public class Publisher { * @throws ProvisionException */ public static IMetadataRepository createMetadataRepository(String location, String name, boolean append, boolean compress) throws ProvisionException { - URL url; + URI url; try { - url = new URL(location); - } catch (MalformedURLException e) { + url = new URI(location); + } catch (URISyntaxException e) { throw new IllegalArgumentException(NLS.bind(Messages.exception_metadataRepoLocationURL, location)); } IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.context, IMetadataRepositoryManager.class.getName()); @@ -89,10 +89,10 @@ public class Publisher { */ public static IArtifactRepository createArtifactRepository(String location, String name, boolean append, boolean compress, boolean reusePackedFiles) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.context, IArtifactRepositoryManager.class.getName()); - URL url; + URI url; try { - url = new URL(location); - } catch (MalformedURLException e) { + url = new URI(location); + } catch (URISyntaxException e) { throw new IllegalArgumentException(NLS.bind(Messages.exception_artifactRepoLocationURL, location)); } try { @@ -139,17 +139,17 @@ public class Publisher { SubMonitor sub = SubMonitor.convert(monitor, actions.length); try { - // run all the actions + // run all the actions MultiStatus finalStatus = new MultiStatus("this", 0, "publishing result", null); //$NON-NLS-1$//$NON-NLS-2$ - for (int i = 0; i < actions.length; i++) { + for (int i = 0; i < actions.length; i++) { if (sub.isCanceled()) return Status.CANCEL_STATUS; IStatus status = actions[i].perform(info, results, monitor); - finalStatus.merge(status); + finalStatus.merge(status); sub.worked(1); - } - if (!finalStatus.isOK()) - return finalStatus; + } + if (!finalStatus.isOK()) + return finalStatus; } finally { sub.done(); } diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/FeaturesAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/FeaturesAction.java index 1cba1c0ec..571794448 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/FeaturesAction.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/FeaturesAction.java @@ -11,8 +11,8 @@ package org.eclipse.equinox.p2.publisher.eclipse; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; @@ -195,10 +195,10 @@ public class FeaturesAction extends AbstractPublisherAction { */ private void generateSiteReference(String location, String featureId, IMetadataRepository metadataRepo) { try { - URL associateLocation = new URL(location); + URI associateLocation = new URI(location); metadataRepo.addReference(associateLocation, IRepository.TYPE_METADATA, IRepository.NONE); metadataRepo.addReference(associateLocation, IRepository.TYPE_ARTIFACT, IRepository.NONE); - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { String message = "Invalid site reference: " + location; //$NON-NLS-1$ if (featureId != null) message = message + " in feature: " + featureId; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java index 7e16fd5fd..811145609 100644 --- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java +++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java @@ -10,8 +10,7 @@ package org.eclipse.equinox.internal.p2.reconciler.dropins; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRepositoryManager; @@ -48,7 +47,7 @@ public class Activator implements BundleActivator { private final static Set repositories = new HashSet(); /** - * Helper method to create an extension location metadata repository at the given URL. + * Helper method to create an extension location metadata repository at the given URI. * If one already exists at that location then an exception will be thrown. * * This method never returns <code>null</code>. @@ -56,7 +55,7 @@ public class Activator implements BundleActivator { * @throws IllegalStateException * @throws ProvisionException */ - public static IMetadataRepository createExtensionLocationMetadataRepository(URL location, String name, Map properties) throws ProvisionException { + public static IMetadataRepository createExtensionLocationMetadataRepository(URI location, String name, Map properties) throws ProvisionException { BundleContext context = getContext(); IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(context, IMetadataRepositoryManager.class.getName()); if (manager == null) @@ -74,7 +73,7 @@ public class Activator implements BundleActivator { * @throws IllegalStateException * @throws ProvisionException */ - public static IMetadataRepository loadMetadataRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public static IMetadataRepository loadMetadataRepository(URI location, IProgressMonitor monitor) throws ProvisionException { BundleContext context = getContext(); IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(context, IMetadataRepositoryManager.class.getName()); if (manager == null) @@ -91,7 +90,7 @@ public class Activator implements BundleActivator { * @throws IllegalStateException * @throws ProvisionException */ - public static IArtifactRepository createExtensionLocationArtifactRepository(URL location, String name, Map properties) throws ProvisionException { + public static IArtifactRepository createExtensionLocationArtifactRepository(URI location, String name, Map properties) throws ProvisionException { BundleContext context = getContext(); IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(context, IArtifactRepositoryManager.class.getName()); if (manager == null) @@ -109,7 +108,7 @@ public class Activator implements BundleActivator { * @throws IllegalStateException * @throws ProvisionException */ - public static IArtifactRepository loadArtifactRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public static IArtifactRepository loadArtifactRepository(URI location, IProgressMonitor monitor) throws ProvisionException { BundleContext context = getContext(); IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(context, IArtifactRepositoryManager.class.getName()); if (manager == null) @@ -364,10 +363,10 @@ public class Activator implements BundleActivator { URL osgiInstallArea = getOSGiInstallArea(); if (osgiInstallArea == null) return; - URL location = null; + URI location = null; try { - location = new URL(getOSGiInstallArea(), ".pooled"); //$NON-NLS-1$ - } catch (MalformedURLException e) { + location = new URI(getOSGiInstallArea().toString() + ".pooled"); //$NON-NLS-1$ + } catch (URISyntaxException e) { LogHelper.log(new Status(IStatus.ERROR, ID, "Error occurred while removing old repositories.", e)); //$NON-NLS-1$ return; } diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/DropinsRepositoryListener.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/DropinsRepositoryListener.java index f21dc3d95..50eee4835 100644 --- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/DropinsRepositoryListener.java +++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/DropinsRepositoryListener.java @@ -12,8 +12,8 @@ package org.eclipse.equinox.internal.p2.reconciler.dropins; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -65,20 +65,20 @@ public class DropinsRepositoryListener extends RepositoryListener { } private void addRepository(File file) { - URL repositoryURL = createRepositoryURL(file); + URI repoLocation = createRepositoryLocation(file); Properties properties = new Properties(); try { // if the file pointed to a link file, keep track of the attribute // so we can add it to the repo later - URL linkURL = getLinkRepository(file, false); - if (linkURL != null) + URI linkLocation = getLinkRepository(file, false); + if (linkLocation != null) properties.put(Site.PROP_LINK_FILE, file.getAbsolutePath()); } catch (IOException e) { // ignore } - if (repositoryURL != null) { - getMetadataRepository(repositoryURL, properties); - getArtifactRepository(repositoryURL, properties); + if (repoLocation != null) { + getMetadataRepository(repoLocation, properties); + getArtifactRepository(repoLocation, properties); } } @@ -111,7 +111,7 @@ public class DropinsRepositoryListener extends RepositoryListener { return path; } - private URL createRepositoryURL(File file) { + private URI createRepositoryLocation(File file) { try { file = file.getCanonicalFile(); String fileName = file.getName(); @@ -124,29 +124,31 @@ public class DropinsRepositoryListener extends RepositoryListener { // This extra check on the features directory is done to avoid adding the parent URL twice if (file.getName().equals(PLUGINS)) { File parentFile = file.getParentFile(); - return (parentFile != null) ? parentFile.toURL() : null; + return (parentFile != null) ? parentFile.toURI() : null; } if (file.getName().equals(FEATURES)) { File parentFile = file.getParentFile(); if (parentFile == null || new File(parentFile, PLUGINS).isDirectory()) return null; - return parentFile.toURL(); + return parentFile.toURI(); } - return file.toURL(); + return file.toURI(); } if (fileName.endsWith(ZIP) || fileName.endsWith(JAR)) - return new URL("jar:" + file.toURL().toExternalForm() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$ + return new URI("jar:" + file.toURI() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$ // last resort -- we'll try to interpret the file as a link return getLinkRepository(file, false); + } catch (URISyntaxException e) { + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while building repository location from file: " + file.getAbsolutePath(), e)); //$NON-NLS-1$ } catch (IOException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while building repository location from file: " + file.getAbsolutePath(), e)); //$NON-NLS-1$ } return null; } - private URL getLinkRepository(File file, boolean logMissingLink) throws IOException { + private URI getLinkRepository(File file, boolean logMissingLink) throws IOException { String path = getLinkPath(file); if (path == null) { if (logMissingLink) @@ -160,11 +162,10 @@ public class DropinsRepositoryListener extends RepositoryListener { if (root != null) linkedFile = new File(root, path); } - File canonicalFile = linkedFile.getCanonicalFile(); - return canonicalFile.toURL(); + return linkedFile.getCanonicalFile().toURI(); } - public void getMetadataRepository(URL repoURL, Properties extraProperties) { + public void getMetadataRepository(URI repoURL, Properties extraProperties) { try { IMetadataRepository repository = null; try { @@ -173,7 +174,7 @@ public class DropinsRepositoryListener extends RepositoryListener { properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); if (extraProperties != null) properties.putAll(extraProperties); - repository = Activator.createExtensionLocationMetadataRepository(repoURL, "dropins metadata repo: " + repoURL.toExternalForm(), properties); //$NON-NLS-1$ + repository = Activator.createExtensionLocationMetadataRepository(repoURL, "dropins metadata repo: " + repoURL, properties); //$NON-NLS-1$ } catch (ProvisionException e) { repository = Activator.loadMetadataRepository(repoURL, null); } @@ -183,7 +184,7 @@ public class DropinsRepositoryListener extends RepositoryListener { } } - public void getArtifactRepository(URL repoURL, Properties extraProperties) { + public void getArtifactRepository(URI repoURL, Properties extraProperties) { try { IArtifactRepository repository = null; try { @@ -192,7 +193,7 @@ public class DropinsRepositoryListener extends RepositoryListener { properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); if (extraProperties != null) properties.putAll(extraProperties); - repository = Activator.createExtensionLocationArtifactRepository(repoURL, "dropins artifact repo: " + repoURL.toExternalForm(), properties); //$NON-NLS-1$ + repository = Activator.createExtensionLocationArtifactRepository(repoURL, "dropins artifact repo: " + repoURL, properties); //$NON-NLS-1$ // fall through here and call the load which then adds the repo to the manager's list } catch (ProvisionException ex) { repository = Activator.loadArtifactRepository(repoURL, null); @@ -213,8 +214,7 @@ public class DropinsRepositoryListener extends RepositoryListener { List currentRepositories = new ArrayList(); for (Iterator it = metadataRepositories.iterator(); it.hasNext();) { IMetadataRepository repository = (IMetadataRepository) it.next(); - String urlString = repository.getLocation().toExternalForm(); - currentRepositories.add(urlString); + currentRepositories.add(repository.getLocation().toString()); } List previousRepositories = getListRepositoryProperty(getMetadataRepository(), DROPIN_METADATA_REPOSITORIES); for (Iterator iterator = previousRepositories.iterator(); iterator.hasNext();) { @@ -230,8 +230,8 @@ public class DropinsRepositoryListener extends RepositoryListener { if (manager == null) throw new IllegalStateException(Messages.metadata_repo_manager_not_registered); try { - manager.removeRepository(new URL(urlString)); - } catch (MalformedURLException e) { + manager.removeRepository(new URI(urlString)); + } catch (URISyntaxException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while creating URL from: " + urlString, e)); //$NON-NLS-1$ } } @@ -240,8 +240,7 @@ public class DropinsRepositoryListener extends RepositoryListener { List currentRepositories = new ArrayList(); for (Iterator it = artifactRepositories.iterator(); it.hasNext();) { IArtifactRepository repository = (IArtifactRepository) it.next(); - String urlString = repository.getLocation().toExternalForm(); - currentRepositories.add(urlString); + currentRepositories.add(repository.getLocation().toString()); } List previousRepositories = getListRepositoryProperty(getArtifactRepository(), DROPIN_ARTIFACT_REPOSITORIES); for (Iterator iterator = previousRepositories.iterator(); iterator.hasNext();) { @@ -257,8 +256,8 @@ public class DropinsRepositoryListener extends RepositoryListener { if (manager == null) throw new IllegalStateException(Messages.artifact_repo_manager_not_registered); try { - manager.removeRepository(new URL(urlString)); - } catch (MalformedURLException e) { + manager.removeRepository(new URI(urlString)); + } catch (URISyntaxException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while creating URL from: " + urlString, e)); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java index d3e9b53cb..a6be7d115 100644 --- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java +++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java @@ -11,12 +11,12 @@ package org.eclipse.equinox.internal.p2.reconciler.dropins; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.core.helpers.URLUtil; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.p2.extensionlocation.*; import org.eclipse.equinox.internal.p2.update.*; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; @@ -155,21 +155,21 @@ public class PlatformXmlListener extends DirectoryChangeListener { IPath urlPath = new Path(urlString).makeAbsolute(); for (Iterator iter = repositoryList.iterator(); iter.hasNext();) { IMetadataRepository repo = (IMetadataRepository) iter.next(); - Path repoPath = new Path(repo.getLocation().toExternalForm()); + Path repoPath = new Path(URIUtil.toFile(repo.getLocation()).getAbsolutePath()); if (repoPath.makeAbsolute().equals(urlPath)) return repo; // normalize the URLs to be the same if (repo instanceof ExtensionLocationMetadataRepository) { try { File one = ExtensionLocationMetadataRepository.getBaseDirectory(repo.getLocation()); - File two = ExtensionLocationMetadataRepository.getBaseDirectory(new URL(urlString)); + File two = ExtensionLocationMetadataRepository.getBaseDirectory(new URI(urlString)); if (one.equals(two)) return repo; } catch (ProvisionException e) { // Skip the repo if it's not found. Log all other errors. if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND) LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while comparing repository locations.", e)); //$NON-NLS-1$ - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while comparing repository locations.", e)); //$NON-NLS-1$ } } @@ -199,7 +199,7 @@ public class PlatformXmlListener extends DirectoryChangeListener { } } String eclipseExtensionURL = siteURL + Constants.EXTENSION_LOCATION; - URL location = new URL(eclipseExtensionURL); + URI location = new URI(eclipseExtensionURL); Map properties = new HashMap(); properties.put(SiteListener.SITE_POLICY, site.getPolicy()); @@ -215,15 +215,15 @@ public class PlatformXmlListener extends DirectoryChangeListener { // deal with the metadata repository IMetadataRepository metadataRepository = null; try { - metadataRepository = Activator.createExtensionLocationMetadataRepository(location, "extension location metadata repository: " + location.toExternalForm(), properties); //$NON-NLS-1$ + metadataRepository = Activator.createExtensionLocationMetadataRepository(location, "extension location metadata repository: " + location.toString(), properties); //$NON-NLS-1$ } catch (ProvisionException ex) { try { metadataRepository = Activator.loadMetadataRepository(location, null); } catch (ProvisionException inner) { // handle the case where someone has removed the extension location from // disk. Note: we use the siteURL not the eclipseextensionURL - URL fileURL = new URL(siteURL); - File file = URLUtil.toFile(fileURL); + URI fileURI = new URI(siteURL); + File file = URIUtil.toFile(fileURI); if (file != null && !file.exists()) { toBeRemoved.add(site); continue; @@ -246,7 +246,7 @@ public class PlatformXmlListener extends DirectoryChangeListener { // now the artifact repository try { - Activator.createExtensionLocationArtifactRepository(location, "extension location artifact repository: " + location.toExternalForm(), properties); //$NON-NLS-1$ + Activator.createExtensionLocationArtifactRepository(location, "extension location artifact repository: " + location, properties); //$NON-NLS-1$ } catch (ProvisionException ex) { IArtifactRepository artifactRepository = Activator.loadArtifactRepository(location, null); // set the repository properties here in case they have changed since the last time we loaded @@ -261,7 +261,7 @@ public class PlatformXmlListener extends DirectoryChangeListener { if (artifactRepository instanceof ExtensionLocationArtifactRepository) ((ExtensionLocationArtifactRepository) artifactRepository).ensureInitialized(); } - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.errorLoadingRepository, siteURL), e)); } catch (ProvisionException e) { // Skip the repo if it's not found. Log all other errors. diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java index efd593361..9ce8fc0ed 100644 --- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java +++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java @@ -10,8 +10,8 @@ package org.eclipse.equinox.internal.p2.reconciler.dropins; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import java.util.Map.Entry; import org.eclipse.core.runtime.*; @@ -64,7 +64,7 @@ public class ProfileSynchronizer { this.repositoryMap = new HashMap(); for (Iterator it = repositories.iterator(); it.hasNext();) { IMetadataRepository repository = (IMetadataRepository) it.next(); - repositoryMap.put(repository.getLocation().toExternalForm(), repository); + repositoryMap.put(repository.getLocation().toString(), repository); } } @@ -204,13 +204,13 @@ public class ProfileSynchronizer { ArrayList repoURLs = new ArrayList(); for (Iterator iterator = repositoryMap.keySet().iterator(); iterator.hasNext();) { try { - repoURLs.add(new URL((String) iterator.next())); - } catch (MalformedURLException e) { + repoURLs.add(new URI((String) iterator.next())); + } catch (URISyntaxException e) { //ignore } } - ProvisioningContext result = new ProvisioningContext((URL[]) repoURLs.toArray(new URL[repoURLs.size()])); - result.setArtifactRepositories(new URL[0]); + ProvisioningContext result = new ProvisioningContext((URI[]) repoURLs.toArray(new URI[repoURLs.size()])); + result.setArtifactRepositories(new URI[0]); return result; } @@ -232,7 +232,7 @@ public class ProfileSynchronizer { for (Iterator it = repositories.iterator(); it.hasNext();) { String repositoryId = (String) it.next(); try { - IArtifactRepository repository = Activator.loadArtifactRepository(new URL(repositoryId), null); + IArtifactRepository repository = Activator.loadArtifactRepository(new URI(repositoryId), null); if (repository instanceof IFileArtifactRepository) { currentExtensions.add(repositoryId); @@ -242,7 +242,7 @@ public class ProfileSynchronizer { } } catch (ProvisionException e) { // ignore - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { // unexpected e.printStackTrace(); } @@ -263,7 +263,7 @@ public class ProfileSynchronizer { Operand operand = new PropertyOperand(CACHE_EXTENSIONS, previousExtensionsProperty, currentExtensionsProperty); - return executeOperands(new ProvisioningContext(new URL[0]), new Operand[] {operand}, null); + return executeOperands(new ProvisioningContext(new URI[0]), new Operand[] {operand}, null); } public ProfileChangeRequest createProfileChangeRequest(ProvisioningContext context) { 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 72678305d..e2a966b56 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 @@ -11,6 +11,7 @@ package org.eclipse.equinox.internal.p2.metadata.repository; import java.io.*; +import java.net.URI; import java.net.URL; import java.util.EventObject; import org.eclipse.core.runtime.*; @@ -41,9 +42,8 @@ public class CacheManager { /** * Returns a hash of the URL. */ - private int computeHash(URL repositoryLocation) { - //don't use URL#hashCode because it performs DNS lookups - return repositoryLocation.toExternalForm().hashCode(); + private int computeHash(URI repositoryLocation) { + return repositoryLocation.hashCode(); } /** @@ -57,17 +57,17 @@ public class CacheManager { * @throws IOException * @throws ProvisionException */ - public File createCache(URL repositoryLocation, IProgressMonitor monitor) throws IOException, ProvisionException { + public File createCache(URI repositoryLocation, IProgressMonitor monitor) throws IOException, ProvisionException { File cacheFile = getCache(repositoryLocation); - URL jarLocation = URLMetadataRepository.getActualLocation(repositoryLocation, JAR_EXTENSION); - URL xmlLocation = URLMetadataRepository.getActualLocation(repositoryLocation, XML_EXTENSION); + URI jarLocation = URLMetadataRepository.getActualLocation(repositoryLocation, JAR_EXTENSION); + URI xmlLocation = URLMetadataRepository.getActualLocation(repositoryLocation, XML_EXTENSION); AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); URL dataArea = agentLocation.getDataArea(Activator.ID + "/cache/"); //$NON-NLS-1$ File dataAreaFile = URLUtil.toFile(dataArea); int hashCode = computeHash(repositoryLocation); if (cacheFile == null || isCacheStale(repositoryLocation, cacheFile)) { long lastModifiedRemote = getTransport().getLastModified(jarLocation); - URL remoteFile; + URI remoteFile; if (lastModifiedRemote != 0) { cacheFile = new File(dataAreaFile, CONTENT_FILENAME + hashCode + JAR_EXTENSION); remoteFile = jarLocation; @@ -82,7 +82,7 @@ public class CacheManager { cacheFile.getParentFile().mkdirs(); OutputStream metadata = new BufferedOutputStream(new FileOutputStream(cacheFile)); try { - IStatus result = getTransport().download(remoteFile.toExternalForm(), metadata, monitor); + IStatus result = getTransport().download(remoteFile.toString(), metadata, monitor); if (!result.isOK()) { throw new ProvisionException(result); } @@ -97,7 +97,7 @@ public class CacheManager { * Deletes the local cache file for the given repository * @param repositoryLocation */ - void deleteCache(URL repositoryLocation) { + void deleteCache(URI repositoryLocation) { File cacheFile = getCache(repositoryLocation); if (cacheFile != null) safeDelete(cacheFile); @@ -109,7 +109,7 @@ public class CacheManager { * @return A {@link File} pointing to the cache file or <code>null</code> if * the cache file does not exist. */ - private File getCache(URL repositoryLocation) { + private File getCache(URI repositoryLocation) { AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); URL dataArea = agentLocation.getDataArea(Activator.ID + "/cache/"); //$NON-NLS-1$ File dataAreaFile = URLUtil.toFile(dataArea); @@ -144,10 +144,10 @@ public class CacheManager { * if the cache file is in sync with the repository. The cache file is * considered stale if there is no local cache file. */ - private boolean isCacheStale(URL repositoryLocation, File cacheFile) { + private boolean isCacheStale(URI repositoryLocation, File cacheFile) { long lastModified = cacheFile.lastModified(); String name = cacheFile.getName(); - URL metadataLocation = null; + URI metadataLocation = null; if (name.endsWith(XML_EXTENSION)) { metadataLocation = URLMetadataRepository.getActualLocation(repositoryLocation, XML_EXTENSION); } else if (name.endsWith(JAR_EXTENSION)) { diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/AddColocatedRepositoryOperationTest.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/AddColocatedRepositoryOperationTest.java index fdc7fd8e6..c0e34fe70 100644 --- a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/AddColocatedRepositoryOperationTest.java +++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/AddColocatedRepositoryOperationTest.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.p2.tests.ui.operations; -import java.net.URL; +import java.net.URI; import java.util.Arrays; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IStatus; @@ -25,9 +25,9 @@ import org.eclipse.equinox.p2.tests.*; */ public class AddColocatedRepositoryOperationTest extends AbstractProvisioningTest { public void testAddSingleRepository() { - URL repoLocation = null; + URI repoLocation = null; try { - repoLocation = TestData.getFile("artifactRepo", "").toURL(); + repoLocation = TestData.getFile("artifactRepo", "").toURI(); } catch (Exception e) { fail("0.99", e); } @@ -47,7 +47,7 @@ public class AddColocatedRepositoryOperationTest extends AbstractProvisioningTes } IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); - URL[] repos = manager.getKnownRepositories(0); + URI[] repos = manager.getKnownRepositories(0); assertTrue("2.0", Arrays.asList(repos).contains(repoLocation)); assertTrue("2.1", manager.isEnabled(repoLocation)); @@ -58,9 +58,9 @@ public class AddColocatedRepositoryOperationTest extends AbstractProvisioningTes } public void testUndoRedo() { - URL repoLocation = null; + URI repoLocation = null; try { - repoLocation = TestData.getFile("artifactRepo", "").toURL(); + repoLocation = TestData.getFile("artifactRepo", "").toURI(); } catch (Exception e) { fail("0.99", e); } @@ -83,7 +83,7 @@ public class AddColocatedRepositoryOperationTest extends AbstractProvisioningTes } IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); - URL[] repos = metadataManager.getKnownRepositories(0); + URI[] repos = metadataManager.getKnownRepositories(0); assertTrue("2.0", !Arrays.asList(repos).contains(repoLocation)); assertTrue("2.1", !metadataManager.isEnabled(repoLocation)); diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/RemoveColocatedRepositoryOperationTest.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/RemoveColocatedRepositoryOperationTest.java index b217a1caf..b20129aeb 100644 --- a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/RemoveColocatedRepositoryOperationTest.java +++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/RemoveColocatedRepositoryOperationTest.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.p2.tests.ui.operations; -import java.net.URL; +import java.net.URI; import java.util.Arrays; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IStatus; @@ -25,9 +25,9 @@ import org.eclipse.equinox.p2.tests.*; */ public class RemoveColocatedRepositoryOperationTest extends AbstractProvisioningTest { public void testRemoveSingleRepository() { - URL repoLocation = null; + URI repoLocation = null; try { - repoLocation = TestData.getFile("artifactRepo", "").toURL(); + repoLocation = TestData.getFile("artifactRepo", "").toURI(); } catch (Exception e) { fail("0.99", e); } @@ -47,7 +47,7 @@ public class RemoveColocatedRepositoryOperationTest extends AbstractProvisioning } IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); - URL[] repos = manager.getKnownRepositories(0); + URI[] repos = manager.getKnownRepositories(0); assertTrue("2.0", Arrays.asList(repos).contains(repoLocation)); assertTrue("2.1", manager.isEnabled(repoLocation)); @@ -58,9 +58,9 @@ public class RemoveColocatedRepositoryOperationTest extends AbstractProvisioning } public void testUndoRedo() { - URL repoLocation = null; + URI repoLocation = null; try { - repoLocation = TestData.getFile("artifactRepo", "").toURL(); + repoLocation = TestData.getFile("artifactRepo", "").toURI(); } catch (Exception e) { fail("0.99", e); } @@ -83,7 +83,7 @@ public class RemoveColocatedRepositoryOperationTest extends AbstractProvisioning } IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); - URL[] repos = metadataManager.getKnownRepositories(0); + URI[] repos = metadataManager.getKnownRepositories(0); assertTrue("2.0", !Arrays.asList(repos).contains(repoLocation)); assertTrue("2.1", !metadataManager.isEnabled(repoLocation)); diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/AnyRequiredCapabilityTest.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/AnyRequiredCapabilityTest.java index 24bd1e433..71a7b9cc6 100644 --- a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/AnyRequiredCapabilityTest.java +++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/AnyRequiredCapabilityTest.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.p2.tests.ui.query; -import java.net.URL; +import java.net.URI; import java.util.ArrayList; import java.util.List; import org.eclipse.equinox.internal.p2.ui.query.AnyRequiredCapabilityQuery; @@ -42,9 +42,9 @@ public class AnyRequiredCapabilityTest extends QueryTest { } public void testExistingRepository() { - URL location; + URI location; try { - location = TestData.getFile("metadataRepo", "good").toURL(); + location = TestData.getFile("metadataRepo", "good").toURI(); } catch (Exception e) { fail("0.99", e); return; diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/IUPropertyUtilsTest.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/IUPropertyUtilsTest.java index 6b732223a..7162dcff0 100644 --- a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/IUPropertyUtilsTest.java +++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/IUPropertyUtilsTest.java @@ -11,8 +11,7 @@ package org.eclipse.equinox.p2.tests.ui.query; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.*; @@ -30,12 +29,7 @@ public class IUPropertyUtilsTest extends QueryTest { public void testFeatureProperties() { IMetadataRepositoryManager repoMan = (IMetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); File site = getTestData("0.1", "/testData/metadataRepo/externalized"); - URL location = null; - try { - location = site.toURL(); - } catch (MalformedURLException e) { - fail("0.99", e); - } + URI location = site.toURI(); IMetadataRepository repository; try { repository = repoMan.loadRepository(location, getMonitor()); diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/QueryableMetadataRepositoryManagerTest.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/QueryableMetadataRepositoryManagerTest.java index fde8581e6..249504dd6 100644 --- a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/QueryableMetadataRepositoryManagerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/QueryableMetadataRepositoryManagerTest.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.p2.tests.ui.query; import java.io.File; -import java.net.URL; +import java.net.URI; import java.util.Collection; import org.eclipse.core.tests.harness.CancelingProgressMonitor; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; @@ -32,9 +32,9 @@ public class QueryableMetadataRepositoryManagerTest extends QueryTest { * Tests querying against a non-existent repository */ public void testBrokenRepository() { - URL brokenRepo; + URI brokenRepo; try { - brokenRepo = TestData.getFile("metadataRepo", "bad").toURL(); + brokenRepo = TestData.getFile("metadataRepo", "bad").toURI(); } catch (Exception e) { fail("0.99", e); return; @@ -54,9 +54,9 @@ public class QueryableMetadataRepositoryManagerTest extends QueryTest { * Tests canceling a load */ public void testCancelLoad() { - URL location; + URI location; try { - location = TestData.getFile("metadataRepo", "good").toURL(); + location = TestData.getFile("metadataRepo", "good").toURI(); } catch (Exception e) { fail("0.99", e); return; @@ -73,11 +73,11 @@ public class QueryableMetadataRepositoryManagerTest extends QueryTest { } public void testCancelQuery() { - URL existing, nonExisting, broken; + URI existing, nonExisting, broken; try { - existing = TestData.getFile("metadataRepo", "good").toURL(); - nonExisting = new File("does/not/exist/testNotFoundRepository").toURL(); - broken = TestData.getFile("metadataRepo", "bad").toURL(); + existing = TestData.getFile("metadataRepo", "good").toURI(); + nonExisting = new File("does/not/exist/testNotFoundRepository").toURI(); + broken = TestData.getFile("metadataRepo", "bad").toURI(); } catch (Exception e) { fail("0.99", e); return; @@ -97,9 +97,9 @@ public class QueryableMetadataRepositoryManagerTest extends QueryTest { } public void testExistingRepository() { - URL location; + URI location; try { - location = TestData.getFile("metadataRepo", "good").toURL(); + location = TestData.getFile("metadataRepo", "good").toURI(); } catch (Exception e) { fail("0.99", e); return; @@ -118,10 +118,10 @@ public class QueryableMetadataRepositoryManagerTest extends QueryTest { * Tests querying against a non-existent repository */ public void testNotFoundRepository() { - URL existing, nonExisting; + URI existing, nonExisting; try { - existing = TestData.getFile("metadataRepo", "good").toURL(); - nonExisting = new File("does/not/exist/testNotFoundRepository").toURL(); + existing = TestData.getFile("metadataRepo", "good").toURI(); + nonExisting = new File("does/not/exist/testNotFoundRepository").toURI(); } catch (Exception e) { fail("0.99", e); return; @@ -139,11 +139,11 @@ public class QueryableMetadataRepositoryManagerTest extends QueryTest { } public void testQuery() { - URL existing, nonExisting, broken; + URI existing, nonExisting, broken; try { - existing = TestData.getFile("metadataRepo", "good").toURL(); - nonExisting = new File("does/not/exist/testNotFoundRepository").toURL(); - broken = TestData.getFile("metadataRepo", "bad").toURL(); + existing = TestData.getFile("metadataRepo", "good").toURI(); + nonExisting = new File("does/not/exist/testNotFoundRepository").toURI(); + broken = TestData.getFile("metadataRepo", "bad").toURI(); } catch (Exception e) { fail("0.99", e); return; diff --git a/bundles/org.eclipse.equinox.p2.tests/All p2 Tests.launch b/bundles/org.eclipse.equinox.p2.tests/All p2 Tests.launch index 28dd1ed70..2eda901c8 100644 --- a/bundles/org.eclipse.equinox.p2.tests/All p2 Tests.launch +++ b/bundles/org.eclipse.equinox.p2.tests/All p2 Tests.launch @@ -6,7 +6,6 @@ <booleanAttribute key="automaticAdd" value="true"/> <booleanAttribute key="automaticValidate" value="false"/> <stringAttribute key="bootstrap" value=""/> -<stringAttribute key="checked" value="[NONE]"/> <booleanAttribute key="clearConfig" value="true"/> <booleanAttribute key="clearws" value="true"/> <booleanAttribute key="clearwslog" value="false"/> @@ -57,7 +56,7 @@ <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consolelog"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.equinox.p2.tests"/> <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> -<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dorg.eclipse.equinox.p2.reconciler.tests.platform.archive=c:/builds/eclipse-platform-3.4-win32.zip"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dorg.eclipse.equinox.p2.reconciler.tests.platform.archive=c:/builds/eclipse-platform-I20081007-1600-win32.zip"/> <stringAttribute key="pde.version" value="3.3"/> <stringAttribute key="product" value="org.eclipse.sdk.ide"/> <booleanAttribute key="show_selected_only" value="false"/> diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java index 9eba3daa8..dbbce1cd5 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java @@ -9,6 +9,7 @@ package org.eclipse.equinox.p2.tests; import java.io.*; +import java.net.URI; import java.net.URL; import java.util.*; import junit.framework.AssertionFailedError; @@ -639,7 +640,7 @@ public abstract class AbstractProvisioningTest extends TestCase { metadataRepos.add(repo); } - protected IArtifactRepository createArtifactRepository(URL location, Map properties) throws ProvisionException { + protected IArtifactRepository createArtifactRepository(URI location, Map properties) throws ProvisionException { IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager(); IArtifactRepository repo = artifactRepositoryManager.createRepository(location, "artifact", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); artifactRepositoryManager.removeRepository(repo.getLocation()); @@ -650,7 +651,7 @@ public abstract class AbstractProvisioningTest extends TestCase { return (IArtifactRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IArtifactRepositoryManager.class.getName()); } - protected IMetadataRepository createMetadataRepository(URL location, Map properties) throws ProvisionException { + protected IMetadataRepository createMetadataRepository(URI location, Map properties) throws ProvisionException { IMetadataRepositoryManager metadataRepositoryManager = getMetadataRepositoryManager(); IMetadataRepository repo = metadataRepositoryManager.createRepository(location, "metadata", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); metadataRepos.add(repo); @@ -710,10 +711,10 @@ public abstract class AbstractProvisioningTest extends TestCase { } metadataRepos.clear(); } - URL[] urls = repoMan.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); + URI[] urls = repoMan.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); for (int i = 0; i < urls.length; i++) { try { - if (urls[i].toExternalForm().indexOf("cache") != -1 || urls[i].toExternalForm().indexOf("rollback") != -1) + if (urls[i].toString().indexOf("cache") != -1 || urls[i].toString().indexOf("rollback") != -1) repoMan.loadRepository(urls[i], null).removeAll(); } catch (ProvisionException e) { //if the repository didn't load, then it doesn't exist and we don't need to clear it up @@ -793,7 +794,7 @@ public abstract class AbstractProvisioningTest extends TestCase { protected void setUp() throws Exception { super.setUp(); MetadataRepositoryManager repoMan = (MetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); - URL[] repos = repoMan.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); + URI[] repos = repoMan.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); for (int i = 0; i < repos.length; i++) { repoMan.removeRepository(repos[i]); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestArtifactRepository.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestArtifactRepository.java index 86a47556c..dcd287d12 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestArtifactRepository.java @@ -11,7 +11,8 @@ package org.eclipse.equinox.p2.tests; import java.io.*; -import java.net.*; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import junit.framework.Assert; import org.eclipse.core.runtime.*; @@ -109,7 +110,7 @@ public class TestArtifactRepository extends AbstractArtifactRepository { } } - public void initialize(URL repoURL, InputStream descriptorFile) throws RepositoryCreationException { + public void initialize(URI repoURL, InputStream descriptorFile) throws RepositoryCreationException { location = repoURL; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestMetadataRepository.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestMetadataRepository.java index 0092456d7..f35638817 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestMetadataRepository.java @@ -8,8 +8,8 @@ ******************************************************************************/ package org.eclipse.equinox.p2.tests; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import junit.framework.Assert; import org.eclipse.core.runtime.IProgressMonitor; @@ -37,11 +37,11 @@ public class TestMetadataRepository extends AbstractMetadataRepository { private final List units = new ArrayList(); protected HashSet repositories = new HashSet(); - private static URL createLocation() { + private static URI createLocation() { try { //Just need a unique URL - we don't need to read/write this location - return new URL("http://TestMetadataRepository.com/" + Long.toString(System.currentTimeMillis())); - } catch (MalformedURLException e) { + return new URI("http://TestMetadataRepository.com/" + Long.toString(System.currentTimeMillis())); + } catch (URISyntaxException e) { Assert.fail(e.getMessage()); } return null; @@ -96,7 +96,7 @@ public class TestMetadataRepository extends AbstractMetadataRepository { this.repositories.addAll(Arrays.asList(state.Repositories)); } - public synchronized void addReference(URL repositoryLocation, int repositoryType, int options) { + public synchronized void addReference(URI repositoryLocation, int repositoryType, int options) { assertModifiable(); repositories.add(new RepositoryReference(repositoryLocation, repositoryType, options)); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestRepositoryListener.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestRepositoryListener.java index 8ca698d79..0552beebc 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestRepositoryListener.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestRepositoryListener.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.p2.tests; -import java.net.URL; +import java.net.URI; import java.util.EventObject; import junit.framework.Assert; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener; @@ -25,10 +25,10 @@ public class TestRepositoryListener implements ProvisioningListener { public boolean lastEnablement; public int lastKind; public int lastRepoType; - private URL repoLocation; + private URI repoLocation; private boolean wasCalled; - public TestRepositoryListener(URL location) { + public TestRepositoryListener(URI location) { this.repoLocation = location; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactOutputStreamTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactOutputStreamTest.java index a4453488f..f5d99257c 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactOutputStreamTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactOutputStreamTest.java @@ -39,7 +39,7 @@ public class ArtifactOutputStreamTest extends TestCase { tempWritableLocation = File.createTempFile("artifact", ".repo"); tempWritableLocation.delete(); tempWritableLocation.mkdirs(); - sar = new SimpleArtifactRepository("name", tempWritableLocation.toURL(), null); + sar = new SimpleArtifactRepository("name", tempWritableLocation.toURI(), null); destination = new Destination(); ak = new ArtifactKey("classifier", "id", new Version("1.0")); ad = new ArtifactDescriptor(ak); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactRepositoryManagerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactRepositoryManagerTest.java index fc18250bf..be0423f16 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactRepositoryManagerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactRepositoryManagerTest.java @@ -12,8 +12,8 @@ package org.eclipse.equinox.p2.tests.artifact.repository; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.core.runtime.IStatus; @@ -37,8 +37,8 @@ public class ArtifactRepositoryManagerTest extends AbstractProvisioningTest { * Returns whether {@link IArtifactRepositoryManager} contains a reference * to a repository at the given location. */ - private boolean managerContains(URL location) { - URL[] locations = manager.getKnownRepositories(IArtifactRepositoryManager.REPOSITORIES_ALL); + private boolean managerContains(URI location) { + URI[] locations = manager.getKnownRepositories(IArtifactRepositoryManager.REPOSITORIES_ALL); for (int i = 0; i < locations.length; i++) { if (locations[i].equals(location)) return true; @@ -56,7 +56,7 @@ public class ArtifactRepositoryManagerTest extends AbstractProvisioningTest { */ public void testLoadMissingRepository() throws IOException { File tempFile = File.createTempFile("testLoadMissingArtifactRepository", null); - URL location = tempFile.toURL(); + URI location = tempFile.toURI(); try { manager.loadRepository(location, null); fail("1.0");//should fail @@ -73,16 +73,35 @@ public class ArtifactRepositoryManagerTest extends AbstractProvisioningTest { public void testLoadMissingRepositoryElement() { File site = getTestData("Update site", "/testData/artifactRepo/broken/"); try { - URL location = site.toURL(); + URI location = site.toURI(); manager.loadRepository(location, null); //should have failed fail("1.0"); } catch (ProvisionException e) { //expected - } catch (MalformedURLException e) { - fail("2.99", e); } + } + public void testPathWithSpaces() { + File site = getTestData("Repository", "/testData/artifactRepo/simple with spaces/"); + URI location = site.toURI(); + try { + IArtifactRepository repository = manager.loadRepository(location, getMonitor()); + assertEquals("1.0", 2, repository.getArtifactKeys().length); + } catch (ProvisionException e) { + fail("=.99", e); + } + } + + public void testUpdateSitePathWithSpaces() { + File site = getTestData("Repository", "/testData/updatesite/site with spaces/"); + URI location = site.toURI(); + try { + IArtifactRepository repository = manager.loadRepository(location, getMonitor()); + assertEquals("1.0", 3, repository.getArtifactKeys().length); + } catch (ProvisionException e) { + fail("=.99", e); + } } /** @@ -90,13 +109,13 @@ public class ArtifactRepositoryManagerTest extends AbstractProvisioningTest { */ public void testTrailingSlashes() { File site = getTestData("Repository", "/testData/artifactRepo/simple/"); - URL locationSlash, locationNoSlash; + URI locationSlash, locationNoSlash; try { - locationSlash = site.toURL(); - String locationString = locationSlash.toExternalForm(); + locationSlash = site.toURI(); + String locationString = locationSlash.toString(); locationString = locationString.substring(0, locationString.length() - 1); - locationNoSlash = new URL(locationString); - } catch (MalformedURLException e) { + locationNoSlash = new URI(locationString); + } catch (URISyntaxException e) { fail("0.99", e); return; } @@ -112,9 +131,9 @@ public class ArtifactRepositoryManagerTest extends AbstractProvisioningTest { } - public void testBasicAddRemove() throws MalformedURLException { + public void testBasicAddRemove() { File tempFile = new File(System.getProperty("java.io.tmpdir")); - URL location = tempFile.toURL(); + URI location = tempFile.toURI(); assertTrue(!managerContains(location)); manager.addRepository(location); assertTrue(managerContains(location)); @@ -122,9 +141,9 @@ public class ArtifactRepositoryManagerTest extends AbstractProvisioningTest { assertTrue(!managerContains(location)); } - public void testEnablement() throws MalformedURLException { + public void testEnablement() { File site = getTestData("Repository", "/testData/artifactRepo/simple/"); - URL location = site.toURL(); + URI location = site.toURI(); manager.addRepository(location); assertEquals("1.0", true, manager.isEnabled(location)); TestRepositoryListener listener = new TestRepositoryListener(location); @@ -147,9 +166,9 @@ public class ArtifactRepositoryManagerTest extends AbstractProvisioningTest { * Tests that adding a repository that is already known but disabled * causes the repository to be enabled. See bug 241307 for discussion. */ - public void testEnablementOnAdd() throws MalformedURLException { + public void testEnablementOnAdd() throws URISyntaxException { File site = getTestData("Repository", "/testData/artifactRepo/simple/"); - URL location = site.toURL(); + URI location = site.toURI(); manager.addRepository(location); manager.setEnabled(location, false); TestRepositoryListener listener = new TestRepositoryListener(location); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/FoldersRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/FoldersRepositoryTest.java index 92173a4f0..b2cadd7f6 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/FoldersRepositoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/FoldersRepositoryTest.java @@ -52,8 +52,8 @@ public class FoldersRepositoryTest extends TestCase { AbstractProvisioningTest.delete(testRepo); testRepo.mkdir(); - manager.removeRepository(testRepo.toURL()); - IArtifactRepository repo = manager.createRepository(testRepo.toURL(), "testRepo", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + manager.removeRepository(testRepo.toURI()); + IArtifactRepository repo = manager.createRepository(testRepo.toURI(), "testRepo", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); File pluginsFolder = new File(testRepo, "plugins"); pluginsFolder.mkdir(); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/JarURLRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/JarURLRepositoryTest.java index 6289d35a5..792ff58c5 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/JarURLRepositoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/JarURLRepositoryTest.java @@ -10,9 +10,9 @@ *******************************************************************************/ package org.eclipse.equinox.p2.tests.artifact.repository; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import junit.framework.TestCase; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.p2.metadata.ArtifactKey; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; @@ -44,7 +44,7 @@ public class JarURLRepositoryTest extends TestCase { TestActivator.getContext().ungetService(managerRef); } - public void testJarURLRepository() throws ProvisionException { + public void testJarURLRepository() throws ProvisionException, URISyntaxException { URL engineJar = TestActivator.getContext().getBundle().getEntry("/testData/enginerepo.jar"); URL jarRepoURL = null; try { @@ -52,7 +52,7 @@ public class JarURLRepositoryTest extends TestCase { } catch (MalformedURLException e) { fail(e.getMessage()); } - IArtifactRepository repo = manager.loadRepository(jarRepoURL, null); + IArtifactRepository repo = manager.loadRepository(URIUtil.toURI(jarRepoURL), null); assertTrue(repo.contains(new ArtifactKey("osgi.bundle", "testdata", new Version("1.0.0.1")))); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java index 69de5fb75..fd44bbb54 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java @@ -12,8 +12,8 @@ package org.eclipse.equinox.p2.tests.artifact.repository; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.NullProgressMonitor; @@ -30,14 +30,14 @@ import org.osgi.framework.Version; public class SimpleArtifactRepositoryTest extends AbstractProvisioningTest { //artifact repository to remove on tear down private File repositoryFile = null; - private URL repositoryURL = null; + private URI repositoryURI = null; protected void tearDown() throws Exception { super.tearDown(); //repository location is not used by all tests - if (repositoryURL != null) { - getArtifactRepositoryManager().removeRepository(repositoryURL); - repositoryURL = null; + if (repositoryURI != null) { + getArtifactRepositoryManager().removeRepository(repositoryURI); + repositoryURI = null; } if (repositoryFile != null) { delete(repositoryFile); @@ -45,45 +45,45 @@ public class SimpleArtifactRepositoryTest extends AbstractProvisioningTest { } } - public void testGetActualLocation1() throws MalformedURLException { - URL base = new URL("http://localhost/artifactRepository"); - assertEquals(new URL(base + "/artifacts.xml"), SimpleArtifactRepository.getActualLocation(base, false)); + public void testGetActualLocation1() throws URISyntaxException { + URI base = new URI("http://localhost/artifactRepository"); + assertEquals(new URI(base + "/artifacts.xml"), SimpleArtifactRepository.getActualLocation(base, false)); } - public void testGetActualLocation2() throws MalformedURLException { - URL base = new URL("http://localhost/artifactRepository/"); - assertEquals(new URL(base + "artifacts.xml"), SimpleArtifactRepository.getActualLocation(base, false)); + public void testGetActualLocation2() throws URISyntaxException { + URI base = new URI("http://localhost/artifactRepository/"); + assertEquals(new URI(base + "artifacts.xml"), SimpleArtifactRepository.getActualLocation(base, false)); } - public void testGetActualLocation3() throws MalformedURLException { - URL base = new URL("http://localhost/artifactRepository/artifacts.xml"); + public void testGetActualLocation3() throws URISyntaxException { + URI base = new URI("http://localhost/artifactRepository/artifacts.xml"); assertEquals(base, SimpleArtifactRepository.getActualLocation(base, false)); } - public void testGetActualLocationCompressed1() throws MalformedURLException { - URL base = new URL("http://localhost/artifactRepository"); - assertEquals(new URL(base + "/artifacts.jar"), SimpleArtifactRepository.getActualLocation(base, true)); + public void testGetActualLocationCompressed1() throws URISyntaxException { + URI base = new URI("http://localhost/artifactRepository"); + assertEquals(new URI(base + "/artifacts.jar"), SimpleArtifactRepository.getActualLocation(base, true)); } - public void testGetActualLocationCompressed2() throws MalformedURLException { - URL base = new URL("http://localhost/artifactRepository/"); - assertEquals(new URL(base + "artifacts.jar"), SimpleArtifactRepository.getActualLocation(base, true)); + public void testGetActualLocationCompressed2() throws URISyntaxException { + URI base = new URI("http://localhost/artifactRepository/"); + assertEquals(new URI(base + "artifacts.jar"), SimpleArtifactRepository.getActualLocation(base, true)); } - public void testGetActualLocationCompressed3() throws MalformedURLException { - URL base = new URL("http://localhost/artifactRepository/artifacts.jar"); + public void testGetActualLocationCompressed3() throws URISyntaxException { + URI base = new URI("http://localhost/artifactRepository/artifacts.jar"); assertEquals(base, SimpleArtifactRepository.getActualLocation(base, true)); } - public void testCompressedRepository() throws MalformedURLException, ProvisionException { + public void testCompressedRepository() throws URISyntaxException, ProvisionException { IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager(); String tempDir = System.getProperty("java.io.tmpdir"); repositoryFile = new File(tempDir, "SimpleArtifactRepositoryTest"); delete(repositoryFile); - repositoryURL = repositoryFile.toURL(); + repositoryURI = repositoryFile.toURI(); Map properties = new HashMap(); properties.put(IRepository.PROP_COMPRESSED, "true"); - IArtifactRepository repo = artifactRepositoryManager.createRepository(repositoryURL, "artifact name", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); + IArtifactRepository repo = artifactRepositoryManager.createRepository(repositoryURI, "artifact name", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); IArtifactKey key = PublisherHelper.createBinaryArtifactKey("testKeyId", new Version("1.2.3")); IArtifactDescriptor descriptor = PublisherHelper.createArtifactDescriptor(key, null); @@ -108,15 +108,15 @@ public class SimpleArtifactRepositoryTest extends AbstractProvisioningTest { fail("Repository should not create artifact.xml"); } - public void testUncompressedRepository() throws MalformedURLException, ProvisionException { + public void testUncompressedRepository() throws URISyntaxException, ProvisionException { IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager(); String tempDir = System.getProperty("java.io.tmpdir"); repositoryFile = new File(tempDir, "SimpleArtifactRepositoryTest"); delete(repositoryFile); - repositoryURL = repositoryFile.toURL(); + repositoryURI = repositoryFile.toURI(); Map properties = new HashMap(); properties.put(IRepository.PROP_COMPRESSED, "false"); - IArtifactRepository repo = artifactRepositoryManager.createRepository(repositoryURL, "artifact name", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); + IArtifactRepository repo = artifactRepositoryManager.createRepository(repositoryURI, "artifact name", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); IArtifactKey key = PublisherHelper.createBinaryArtifactKey("testKeyId", new Version("1.2.3")); IArtifactDescriptor descriptor = PublisherHelper.createArtifactDescriptor(key, null); @@ -143,12 +143,8 @@ public class SimpleArtifactRepositoryTest extends AbstractProvisioningTest { public void test_248772() { SimpleArtifactRepositoryFactory factory = new SimpleArtifactRepositoryFactory(); - URL location = null; - try { - location = new File(getTempFolder(), getUniqueString()).toURL(); - } catch (MalformedURLException e) { - fail("1.0", e); - } + URI location = null; + location = new File(getTempFolder(), getUniqueString()).toURI(); factory.create(location, "test type", null, null); try { factory.load(location, new NullProgressMonitor()); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/AllTests.java index cbcf6f376..ade5b0dfd 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/AllTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/AllTests.java @@ -21,6 +21,7 @@ public class AllTests extends TestCase { TestSuite suite = new TestSuite(AllTests.class.getName()); suite.addTestSuite(FileUtilsTest.class); suite.addTestSuite(OrderedPropertiesTest.class); + suite.addTestSuite(URIUtilTest.class); suite.addTestSuite(URLUtilTest.class); return suite; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/URIUtilTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/URIUtilTest.java new file mode 100644 index 000000000..d1247a3a0 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/URIUtilTest.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2008 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.tests.core; + +import java.io.File; +import java.net.*; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; +import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; + +/** + * Tests for the {@link URLUtil} class. + */ +public class URIUtilTest extends AbstractProvisioningTest { + private static final String[] testPaths = new String[] {"abc", "with spaces", "with%percent"}; + + /** + * Tests for {@link URLUtil#toFile(URL)}. + */ + public void testToFile() { + File base = new File(System.getProperty("java.io.tmpdir")); + for (int i = 0; i < testPaths.length; i++) { + File original = new File(base, testPaths[i]); + URI uri = original.toURI(); + File result = URIUtil.toFile(uri); + assertEquals("1." + i, original, result); + } + } + + /** + * Tests for {@link URIUtil#fromString(String)}. + */ + public void testFromString() throws URISyntaxException { + //spaces + assertEquals("1.1", new URI("http://foo.bar/a%20b"), URIUtil.fromString("http://foo.bar/a b")); + assertEquals("1.2", new URI("http://foo.bar/a#b%20c"), URIUtil.fromString("http://foo.bar/a#b c")); + assertEquals("1.3", new URI("foo.bar/a%20b"), URIUtil.fromString("foo.bar/a b")); + assertEquals("1.4", new URI("#a%20b"), URIUtil.fromString("#a b")); + } + + /** + * Tests for {@link URIUtil#toURI(java.net.URL)}. + */ + public void testURLtoURI() throws MalformedURLException, URISyntaxException { + //spaces + assertEquals("1.1", new URI("http://foo.bar/a%20b"), URIUtil.toURI(new URL("http://foo.bar/a b"))); + assertEquals("1.2", new URI("http://foo.bar/a#b%20c"), URIUtil.toURI(new URL("http://foo.bar/a#b c"))); + + //missing slash + assertEquals("1.1", new URI("file:/c:/foo/bar.txt"), URIUtil.toURI(new URL("file:c:/foo/bar.txt"))); + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/RollbackTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/RollbackTest.java index 64ccd3579..1ea24f733 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/RollbackTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/RollbackTest.java @@ -8,13 +8,13 @@ ******************************************************************************/ package org.eclipse.equinox.p2.tests.director; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.p2.director.DirectorActivator; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; @@ -70,10 +70,13 @@ public class RollbackTest extends AbstractProvisioningTest { try { IMetadataRepositoryManager repoMan = (IMetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); URL location = ((AgentLocation) ServiceHelper.getService(DirectorActivator.context, AgentLocation.class.getName())).getDataArea(DirectorActivator.PI_DIRECTOR); - return repoMan.loadRepository(new URL(location, "rollback"), null); + return repoMan.loadRepository(URIUtil.toURI(new URL(location, "rollback")), null); } catch (MalformedURLException e) { fail("0.02", e); return null; + } catch (URISyntaxException e) { + fail("0.03", e); + return null; } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/DownloadManagerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/DownloadManagerTest.java index d72e07cd2..cf299acc3 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/DownloadManagerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/DownloadManagerTest.java @@ -10,8 +10,8 @@ *******************************************************************************/ package org.eclipse.equinox.p2.tests.engine; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.core.runtime.IStatus; @@ -131,7 +131,7 @@ public class DownloadManagerTest extends AbstractProvisioningTest { public void testEmptyArtifactRepositoryListContext() { ProvisioningContext context = new ProvisioningContext(); - context.setArtifactRepositories(new URL[0]); + context.setArtifactRepositories(new URI[0]); DownloadManager manager = new DownloadManager(context); IArtifactRequest[] requests = new IArtifactRequest[] {createArtifactRequest()}; @@ -142,11 +142,11 @@ public class DownloadManagerTest extends AbstractProvisioningTest { public void testFileFirstArtifactRepositoryListContext() { ProvisioningContext context = new ProvisioningContext(); - URL[] artifactRepos = new URL[2]; + URI[] artifactRepos = new URI[2]; try { - artifactRepos[0] = new URL("file:/test"); - artifactRepos[1] = new URL("jar:file:/test!/"); - } catch (MalformedURLException e) { + artifactRepos[0] = new URI("file:/test"); + artifactRepos[1] = new URI("jar:file:/test!/"); + } catch (URISyntaxException e) { fail(e.getMessage()); } @@ -161,11 +161,11 @@ public class DownloadManagerTest extends AbstractProvisioningTest { public void testFileLastArtifactRepositoryListContext() { ProvisioningContext context = new ProvisioningContext(); - URL[] artifactRepos = new URL[2]; + URI[] artifactRepos = new URI[2]; try { - artifactRepos[0] = new URL("jar:file:/test!/"); - artifactRepos[1] = new URL("file:/test"); - } catch (MalformedURLException e) { + artifactRepos[0] = new URI("jar:file:/test!/"); + artifactRepos[1] = new URI("file:/test"); + } catch (URISyntaxException e) { fail(e.getMessage()); } @@ -180,11 +180,11 @@ public class DownloadManagerTest extends AbstractProvisioningTest { public void testNoFileArtifactRepositoryListContext() { ProvisioningContext context = new ProvisioningContext(); - URL[] artifactRepos = new URL[2]; + URI[] artifactRepos = new URI[2]; try { - artifactRepos[0] = new URL("jar:file:/test1!/"); - artifactRepos[1] = new URL("jar:file:/test2!/"); - } catch (MalformedURLException e) { + artifactRepos[0] = new URI("jar:file:/test1!/"); + artifactRepos[1] = new URI("jar:file:/test2!/"); + } catch (URISyntaxException e) { fail(e.getMessage()); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/extensionlocation/ExtensionLocationArtifactRepositoryFactoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/extensionlocation/ExtensionLocationArtifactRepositoryFactoryTest.java index 761b6ecae..d70829f39 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/extensionlocation/ExtensionLocationArtifactRepositoryFactoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/extensionlocation/ExtensionLocationArtifactRepositoryFactoryTest.java @@ -12,8 +12,7 @@ package org.eclipse.equinox.p2.tests.extensionlocation; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import org.eclipse.core.runtime.FileLocator; import org.eclipse.equinox.internal.p2.extensionlocation.ExtensionLocationArtifactRepositoryFactory; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; @@ -52,12 +51,12 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv public void testNonFileURL() { try { - URL nonFileURL = new URL("http://www.eclipse.org"); + URI nonFileURL = new URI("http://www.eclipse.org"); factory.load(nonFileURL, getMonitor()); fail("0.1"); } catch (ProvisionException e) { assertEquals("0.5", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { fail("0.99", e); } } @@ -66,12 +65,10 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv File directory = new File(tempDirectory, "nonexistent"); delete(directory); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); fail("0.1"); } catch (ProvisionException e) { assertEquals("0.5", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -79,7 +76,7 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv File file = new File(tempDirectory, "exists.file"); try { file.createNewFile(); - factory.load(file.toURL(), getMonitor()); + factory.load(file.toURI(), getMonitor()); fail("0.1"); } catch (ProvisionException e) { assertEquals("0.5", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); @@ -94,12 +91,10 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv File directory = new File(tempDirectory, "exists"); directory.mkdirs(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { if (e.getStatus().getCode() == ProvisionException.REPOSITORY_NOT_FOUND) return; - } catch (MalformedURLException e) { - fail("0.99", e); } fail("1.0"); } @@ -110,11 +105,9 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv new File(directory, "plugins").mkdir(); new File(directory, "features").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.1", e); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -123,11 +116,9 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv directory.mkdirs(); new File(directory, "features").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.1", e); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -136,11 +127,9 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv directory.mkdirs(); new File(directory, "plugins").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.1", e); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -152,11 +141,9 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv new File(eclipseDirectory, "plugins").mkdir(); new File(eclipseDirectory, "features").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.1", e); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -168,12 +155,10 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv new File(eclipseDirectory, "plugins").mkdir(); new File(eclipseDirectory, "features").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { if (e.getStatus().getCode() == ProvisionException.REPOSITORY_NOT_FOUND) return; - } catch (MalformedURLException e) { - fail("0.99", e); } fail("1.0"); } @@ -182,17 +167,13 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv File directory = new File(tempDirectory, "exists"); directory.mkdirs(); copy("1.0", getTestData("1.1", "/testData/extensionlocation"), directory); + URI location = directory.toURI(); try { - URL location = directory.toURL(); - try { - IArtifactRepository repo = factory.load(location, getMonitor()); - if (repo.getArtifactKeys().length != 2) - fail("2.1"); - } catch (ProvisionException ex) { - fail("2.0"); - } - } catch (MalformedURLException e) { - fail("3.99", e); + IArtifactRepository repo = factory.load(location, getMonitor()); + if (repo.getArtifactKeys().length != 2) + fail("2.1"); + } catch (ProvisionException ex) { + fail("2.0"); } } @@ -202,17 +183,13 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv File features = new File(directory, "features"); features.mkdir(); copy("1.0", getTestData("1.1", "/testData/extensionlocation/features"), features); + URI location = directory.toURI(); try { - URL location = directory.toURL(); - try { - IArtifactRepository repo = factory.load(location, getMonitor()); - if (repo.getArtifactKeys().length != 1) - fail("2.1"); - } catch (ProvisionException ex) { - fail("2.0"); - } - } catch (MalformedURLException e) { - fail("3.99", e); + IArtifactRepository repo = factory.load(location, getMonitor()); + if (repo.getArtifactKeys().length != 1) + fail("2.1"); + } catch (ProvisionException ex) { + fail("2.0"); } } @@ -222,17 +199,13 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv File plugins = new File(directory, "plugins"); plugins.mkdir(); copy("1.0", getTestData("1.1", "/testData/extensionlocation/plugins"), plugins); + URI location = directory.toURI(); try { - URL location = directory.toURL(); - try { - IArtifactRepository repo = factory.load(location, getMonitor()); - if (repo.getArtifactKeys().length != 1) - fail("2.1"); - } catch (ProvisionException ex) { - fail("2.0"); - } - } catch (MalformedURLException e) { - fail("3.99", e); + IArtifactRepository repo = factory.load(location, getMonitor()); + if (repo.getArtifactKeys().length != 1) + fail("2.1"); + } catch (ProvisionException ex) { + fail("2.0"); } } @@ -242,25 +215,21 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv File eclipseDirectory = new File(directory, "eclipse"); copy("1.1", getTestData("1.1", "/testData/extensionlocation"), eclipseDirectory); try { - IArtifactRepository repo = factory.load(directory.toURL(), getMonitor()); + IArtifactRepository repo = factory.load(directory.toURI(), getMonitor()); if (repo.getArtifactKeys().length != 2) fail("1.0"); } catch (ProvisionException e) { fail("0.5", e); - } catch (MalformedURLException e) { - fail("0.99", e); } } public void testUpdateSiteXMLURL() { File site = getTestData("0.1", "/testData/updatesite/site"); try { - factory.load(site.toURL(), getMonitor()); + factory.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { if (e.getStatus().getCode() == ProvisionException.REPOSITORY_NOT_FOUND) return; - } catch (MalformedURLException e) { - fail("0.99", e); } fail("1.0"); } @@ -268,12 +237,10 @@ public class ExtensionLocationArtifactRepositoryFactoryTest extends AbstractProv public void testXXXSiteXXXXMLURL() { File site = getTestData("0.1", "/testData/updatesite/xxxsitexxx"); try { - factory.load(site.toURL(), getMonitor()); + factory.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { if (e.getStatus().getCode() == ProvisionException.REPOSITORY_NOT_FOUND) return; - } catch (MalformedURLException e) { - fail("0.99", e); } fail("1.0"); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/extensionlocation/ExtensionLocationMetadataRepositoryFactoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/extensionlocation/ExtensionLocationMetadataRepositoryFactoryTest.java index 882d16401..4a9e3bd85 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/extensionlocation/ExtensionLocationMetadataRepositoryFactoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/extensionlocation/ExtensionLocationMetadataRepositoryFactoryTest.java @@ -12,8 +12,7 @@ package org.eclipse.equinox.p2.tests.extensionlocation; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import org.eclipse.equinox.internal.p2.extensionlocation.ExtensionLocationMetadataRepositoryFactory; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; @@ -46,12 +45,12 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv public void testNonFileURL() { try { - URL nonFileURL = new URL("http://www.eclipse.org"); + URI nonFileURL = new URI("http://www.eclipse.org"); factory.load(nonFileURL, getMonitor()); fail("0.1"); } catch (ProvisionException e) { assertEquals("0.2", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { fail("0.3", e); } } @@ -60,12 +59,10 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv File directory = new File(tempDirectory, "nonexistent"); delete(directory); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); fail("0.1"); } catch (ProvisionException e) { assertEquals("0.2", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); - } catch (MalformedURLException e) { - fail("0.3", e); } } @@ -73,7 +70,7 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv File file = new File(tempDirectory, "exists.file"); try { file.createNewFile(); - factory.load(file.toURL(), getMonitor()); + factory.load(file.toURI(), getMonitor()); fail("0.1"); } catch (ProvisionException e) { assertEquals("0.2", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); @@ -88,12 +85,10 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv File directory = new File(tempDirectory, "exists"); directory.mkdirs(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); fail("0.1"); } catch (ProvisionException e) { assertEquals("0.2", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); - } catch (MalformedURLException e) { - fail("0.3", e); } } @@ -103,11 +98,9 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv new File(directory, "plugins").mkdir(); new File(directory, "features").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.1"); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -116,11 +109,9 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv directory.mkdirs(); new File(directory, "features").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.1"); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -129,11 +120,9 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv directory.mkdirs(); new File(directory, "plugins").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.1"); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -145,11 +134,9 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv new File(eclipseDirectory, "plugins").mkdir(); new File(eclipseDirectory, "features").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.1"); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -161,12 +148,10 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv new File(eclipseDirectory, "plugins").mkdir(); new File(eclipseDirectory, "features").mkdir(); try { - factory.load(directory.toURL(), getMonitor()); + factory.load(directory.toURI(), getMonitor()); fail("0.1"); } catch (ProvisionException e) { assertEquals("0.2", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); - } catch (MalformedURLException e) { - fail("0.99", e); } } @@ -174,17 +159,13 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv File directory = new File(tempDirectory, "exists"); directory.mkdirs(); copy("1.0", getTestData("1.1", "/testData/extensionlocation"), directory); + URI location = directory.toURI(); try { - URL location = directory.toURL(); - try { - IMetadataRepository repo = factory.load(location, getMonitor()); - if (repo.query(InstallableUnitQuery.ANY, new Collector(), null).toCollection().size() != 3) - fail("2.99"); - } catch (ProvisionException ex) { - fail("2.0"); - } - } catch (MalformedURLException e) { - fail("4.99", e); + IMetadataRepository repo = factory.load(location, getMonitor()); + if (repo.query(InstallableUnitQuery.ANY, new Collector(), null).toCollection().size() != 3) + fail("2.99"); + } catch (ProvisionException ex) { + fail("2.0"); } } @@ -194,17 +175,13 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv File features = new File(directory, "features"); features.mkdir(); copy("1.0", getTestData("1.1", "/testData/extensionlocation/features"), features); + URI location = directory.toURI(); try { - URL location = directory.toURL(); - try { - IMetadataRepository repo = factory.load(location, getMonitor()); - if (repo.query(InstallableUnitQuery.ANY, new Collector(), null).toCollection().size() != 2) - fail("3.0"); - } catch (ProvisionException ex) { - fail("2.0"); - } - } catch (MalformedURLException e) { - fail("4.99", e); + IMetadataRepository repo = factory.load(location, getMonitor()); + if (repo.query(InstallableUnitQuery.ANY, new Collector(), null).toCollection().size() != 2) + fail("3.0"); + } catch (ProvisionException ex) { + fail("2.0"); } } @@ -214,17 +191,13 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv File plugins = new File(directory, "plugins"); plugins.mkdir(); copy("1.0", getTestData("1.1", "/testData/extensionlocation/plugins"), plugins); + URI location = directory.toURI(); try { - URL location = directory.toURL(); - try { - IMetadataRepository repo = factory.load(location, getMonitor()); - if (repo.query(InstallableUnitQuery.ANY, new Collector(), null).toCollection().size() != 1) - fail("3.0"); - } catch (ProvisionException ex) { - fail("2.0"); - } - } catch (MalformedURLException e) { - fail("4.99", e); + IMetadataRepository repo = factory.load(location, getMonitor()); + if (repo.query(InstallableUnitQuery.ANY, new Collector(), null).toCollection().size() != 1) + fail("3.0"); + } catch (ProvisionException ex) { + fail("2.0"); } } @@ -234,25 +207,21 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv File eclipseDirectory = new File(directory, "eclipse"); copy("1.0", getTestData("1.1", "/testData/extensionlocation"), eclipseDirectory); try { - IMetadataRepository repo = factory.load(directory.toURL(), getMonitor()); + IMetadataRepository repo = factory.load(directory.toURI(), getMonitor()); if (repo.query(InstallableUnitQuery.ANY, new Collector(), null).toCollection().size() != 3) fail("3.0"); } catch (ProvisionException e) { fail("2.0"); - } catch (MalformedURLException e) { - fail("2.99", e); } } public void testUpdateSiteXMLURL() { File site = getTestData("0.1", "/testData/updatesite/site"); try { - factory.load(site.toURL(), getMonitor()); + factory.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { if (e.getStatus().getCode() == ProvisionException.REPOSITORY_NOT_FOUND) return; - } catch (MalformedURLException e) { - fail("0.99", e); } fail("1.0"); } @@ -260,12 +229,10 @@ public class ExtensionLocationMetadataRepositoryFactoryTest extends AbstractProv public void testXXXSiteXXXXMLURL() { File site = getTestData("0.1", "/testData/updatesite/xxxsitexxx"); try { - factory.load(site.toURL(), getMonitor()); + factory.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { if (e.getStatus().getCode() == ProvisionException.REPOSITORY_NOT_FOUND) return; - } catch (MalformedURLException e) { - fail("0.99", e); } fail("1.0"); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/DirectorTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/DirectorTest.java index 816f09135..b0c7ca8c9 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/DirectorTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/DirectorTest.java @@ -18,7 +18,8 @@ import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; import org.eclipse.equinox.internal.provisional.p2.director.IDirector; import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest; -import org.eclipse.equinox.internal.provisional.p2.engine.*; +import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; +import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; @@ -108,9 +109,9 @@ public class DirectorTest extends AbstractProvisioningTest { private void ensureFragmentAssociationIsNotPersisted(IMetadataRepositoryManager mgr) throws ProvisionException { //Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=177661 AgentLocation location = (AgentLocation) ServiceHelper.getService(TestActivator.getContext(), AgentLocation.class.getName()); - mgr.removeRepository(location.getMetadataRepositoryURL()); + mgr.removeRepository(location.getMetadataRepositoryURI()); IMetadataRepository repo = null; - repo = mgr.loadRepository(location.getMetadataRepositoryURL(), null); + repo = mgr.loadRepository(location.getMetadataRepositoryURI(), null); Iterator it = repo.query(new InstallableUnitQuery("org.eclipse.equinox.simpleconfigurator", VersionRange.emptyRange), new Collector(), null).iterator(); if (!it.hasNext()) return; diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/End2EndTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/End2EndTest.java index 9df8f9fe4..54309a3d0 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/End2EndTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/End2EndTest.java @@ -10,8 +10,8 @@ package org.eclipse.equinox.p2.tests.full; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; @@ -83,7 +83,7 @@ public class End2EndTest extends AbstractProvisioningTest { //Add repository of the release try { - URL location = new URL("http://download.eclipse.org/eclipse/updates/3.4"); + URI location = new URI("http://download.eclipse.org/eclipse/updates/3.4"); metadataRepoManager.addRepository(location); metadataRepoManager.setEnabled(location, true); metadataRepoManager.loadRepository(location, new NullProgressMonitor()); @@ -91,8 +91,8 @@ public class End2EndTest extends AbstractProvisioningTest { artifactRepoManager.setEnabled(location, true); } catch (ProvisionException e) { fail("Exception loading the repository.", e); - } catch (MalformedURLException e) { - //Ignore + } catch (URISyntaxException e) { + fail("Invalid repository location", e); } installPlatform(profile2, installFolder); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/RepoValidator.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/RepoValidator.java index 95b67f32a..938af9845 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/RepoValidator.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/RepoValidator.java @@ -1,7 +1,7 @@ package org.eclipse.equinox.p2.tests.full; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -20,8 +20,8 @@ import org.eclipse.equinox.p2.tests.TestActivator; import org.osgi.framework.ServiceReference; public class RepoValidator extends AbstractProvisioningTest { - public void testValidate() throws ProvisionException, MalformedURLException { - URL repoLoc = new URL("file:d:/ganymedeM5"); + public void testValidate() throws ProvisionException, URISyntaxException { + URI repoLoc = new URI("file:d:/ganymedeM5"); ServiceReference sr = TestActivator.context.getServiceReference(IPlanner.class.getName()); if (sr == null) { throw new RuntimeException("Planner service not available"); @@ -59,7 +59,7 @@ public class RepoValidator extends AbstractProvisioningTest { q = InstallableUnitQuery.ANY; Collector iusToTest = validatedRepo.query(q, new Collector(), null); - ProvisioningContext pc = new ProvisioningContext(new URL[] {repoLoc}); + ProvisioningContext pc = new ProvisioningContext(new URI[] {repoLoc}); for (Iterator iterator = iusToTest.iterator(); iterator.hasNext();) { try { IInstallableUnit isInstallable = (IInstallableUnit) iterator.next(); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/installer/InstallDescriptionParserTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/installer/InstallDescriptionParserTest.java index a6b6995df..0d849f76a 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/installer/InstallDescriptionParserTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/installer/InstallDescriptionParserTest.java @@ -12,8 +12,7 @@ package org.eclipse.equinox.p2.tests.installer; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.equinox.internal.p2.installer.InstallDescriptionParser; @@ -89,14 +88,14 @@ public class InstallDescriptionParserTest extends AbstractProvisioningTest { */ public void testLoadGoodDescription() { InstallDescription description = loadDescription("good.properties"); - URL[] artifactRepositories = description.getArtifactRepositories(); + URI[] artifactRepositories = description.getArtifactRepositories(); assertEquals("1.0", 2, artifactRepositories.length); - assertEquals("1.1", "http://update.eclipse.org/eclipse/someUpdateSite/", artifactRepositories[0].toExternalForm()); - assertEquals("1.1", "http://update.eclipse.org/eclipse/someArtifacts/", artifactRepositories[1].toExternalForm()); - URL[] metadataRepositories = description.getMetadataRepositories(); + assertEquals("1.1", "http://update.eclipse.org/eclipse/someUpdateSite/", artifactRepositories[0].toString()); + assertEquals("1.1", "http://update.eclipse.org/eclipse/someArtifacts/", artifactRepositories[1].toString()); + URI[] metadataRepositories = description.getMetadataRepositories(); assertEquals("1.2", 2, metadataRepositories.length); - assertEquals("1.3", "http://update.eclipse.org/eclipse/someUpdateSite/", metadataRepositories[0].toExternalForm()); - assertEquals("1.3", "http://update.eclipse.org/eclipse/someMetadata/", metadataRepositories[1].toExternalForm()); + assertEquals("1.3", "http://update.eclipse.org/eclipse/someUpdateSite/", metadataRepositories[0].toString()); + assertEquals("1.3", "http://update.eclipse.org/eclipse/someMetadata/", metadataRepositories[1].toString()); assertEquals("1.4", "testFlavor", description.getProfileProperties().get("eclipse.p2.flavor")); assertEquals("1.5", "Test Profile Name", description.getProductName()); assertEquals("1.5", "testLauncherName", description.getLauncherName()); @@ -137,12 +136,12 @@ public class InstallDescriptionParserTest extends AbstractProvisioningTest { */ public void testLoadSDKDescription() { InstallDescription description = loadDescription("sdk-installer.properties"); - URL[] artifactRepositories = description.getArtifactRepositories(); + URI[] artifactRepositories = description.getArtifactRepositories(); assertEquals("1.0", 1, artifactRepositories.length); - assertEquals("1.1", "http://update.eclipse.org/eclipse/testUpdates/", artifactRepositories[0].toExternalForm()); - URL[] metadataRepositories = description.getMetadataRepositories(); + assertEquals("1.1", "http://update.eclipse.org/eclipse/testUpdates/", artifactRepositories[0].toString()); + URI[] metadataRepositories = description.getMetadataRepositories(); assertEquals("1.2", 1, metadataRepositories.length); - assertEquals("1.3", "http://update.eclipse.org/eclipse/testUpdates/", metadataRepositories[0].toExternalForm()); + assertEquals("1.3", "http://update.eclipse.org/eclipse/testUpdates/", metadataRepositories[0].toString()); assertEquals("1.4", "tooling", description.getProfileProperties().get("eclipse.p2.flavor")); assertEquals("1.5", "Eclipse SDK", description.getProductName()); assertEquals("1.5", "eclipse", description.getLauncherName()); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/JarURLRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/JarURLRepositoryTest.java index 37014119e..42a7221f7 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/JarURLRepositoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/JarURLRepositoryTest.java @@ -12,8 +12,8 @@ package org.eclipse.equinox.p2.tests.metadata.repository; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; @@ -55,7 +55,7 @@ public class JarURLRepositoryTest extends TestCase { testRepo.mkdir(); Map properties = new HashMap(); properties.put(IRepository.PROP_COMPRESSED, "true"); - IMetadataRepository repo = manager.createRepository(testRepo.toURL(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); + IMetadataRepository repo = manager.createRepository(testRepo.toURI(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); InstallableUnitDescription descriptor = new MetadataFactory.InstallableUnitDescription(); descriptor.setId("testIuId"); @@ -75,14 +75,14 @@ public class JarURLRepositoryTest extends TestCase { } public void testJarURLRepository() throws ProvisionException { - URL jarRepoURL = null; + URI jarRepoLocation = null; try { - jarRepoURL = new URL("jar:" + testRepoJar.toURL().toString() + "!/"); - } catch (MalformedURLException e) { + jarRepoLocation = new URI("jar:" + testRepoJar.toURI() + "!/"); + } catch (URISyntaxException e) { fail(e.getMessage()); } - IMetadataRepository repo = manager.loadRepository(jarRepoURL, null); + IMetadataRepository repo = manager.loadRepository(jarRepoLocation, null); assertTrue(!repo.query(InstallableUnitQuery.ANY, new Collector(), null).isEmpty()); - manager.removeRepository(jarRepoURL); + manager.removeRepository(jarRepoLocation); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/LocalMetadataRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/LocalMetadataRepositoryTest.java index 0b6775cfb..e247785bc 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/LocalMetadataRepositoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/LocalMetadataRepositoryTest.java @@ -13,7 +13,7 @@ package org.eclipse.equinox.p2.tests.metadata.repository; import java.io.File; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener; @@ -45,7 +45,7 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { } protected void tearDown() throws Exception { - getMetadataRepositoryManager().removeRepository(repoLocation.toURL()); + getMetadataRepositoryManager().removeRepository(repoLocation.toURI()); delete(repoLocation); super.tearDown(); } @@ -54,7 +54,7 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { IMetadataRepositoryManager manager = getMetadataRepositoryManager(); Map properties = new HashMap(); properties.put(IRepository.PROP_COMPRESSED, "true"); - IMetadataRepository repo = manager.createRepository(repoLocation.toURL(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); + IMetadataRepository repo = manager.createRepository(repoLocation.toURI(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); InstallableUnitDescription descriptor = new MetadataFactory.InstallableUnitDescription(); descriptor.setId("testIuId"); @@ -84,7 +84,7 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { public void testGetProperties() throws MalformedURLException, ProvisionException { IMetadataRepositoryManager manager = getMetadataRepositoryManager(); - IMetadataRepository repo = manager.createRepository(repoLocation.toURL(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + IMetadataRepository repo = manager.createRepository(repoLocation.toURI(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); Map properties = repo.getProperties(); //attempting to modify the properties should fail try { @@ -97,7 +97,7 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { public void testSetProperty() throws MalformedURLException, ProvisionException { IMetadataRepositoryManager manager = getMetadataRepositoryManager(); - IMetadataRepository repo = manager.createRepository(repoLocation.toURL(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + IMetadataRepository repo = manager.createRepository(repoLocation.toURI(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); Map properties = repo.getProperties(); assertTrue("1.0", !properties.containsKey(TEST_KEY)); repo.setProperty(TEST_KEY, TEST_VALUE); @@ -108,7 +108,7 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { assertTrue("1.2", properties.containsKey(TEST_KEY)); //going back to repo manager, should still get the new property - repo = manager.loadRepository(repoLocation.toURL(), null); + repo = manager.loadRepository(repoLocation.toURI(), null); properties = repo.getProperties(); assertTrue("1.3", properties.containsKey(TEST_KEY)); @@ -122,7 +122,7 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { IMetadataRepositoryManager manager = getMetadataRepositoryManager(); Map properties = new HashMap(); properties.put(IRepository.PROP_COMPRESSED, "false"); - IMetadataRepository repo = manager.createRepository(repoLocation.toURL(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); + IMetadataRepository repo = manager.createRepository(repoLocation.toURI(), "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); InstallableUnitDescription descriptor = new MetadataFactory.InstallableUnitDescription(); descriptor.setId("testIuId"); @@ -153,9 +153,9 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { IMetadataRepositoryManager manager = getMetadataRepositoryManager(); Map properties = new HashMap(); properties.put(IRepository.PROP_COMPRESSED, "false"); - final URL repoURL = repoLocation.toURL(); - IMetadataRepository repo = manager.createRepository(repoURL, "testLoadSelfReference", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); - repo.addReference(repoURL, IRepository.TYPE_METADATA, IRepository.NONE); + final URI repoURI = repoLocation.toURI(); + IMetadataRepository repo = manager.createRepository(repoURI, "testLoadSelfReference", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); + repo.addReference(repoURI, IRepository.TYPE_METADATA, IRepository.NONE); //adding a reference doesn't save the repository, but setting a property does repo.setProperty("changed", "false"); @@ -169,7 +169,7 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { RepositoryEvent event = (RepositoryEvent) o; if (event.getKind() != RepositoryEvent.ADDED) return; - if (!event.getRepositoryLocation().equals(repoURL)) + if (!event.getRepositoryLocation().equals(repoURI)) return; wasEnabled[0] = event.isRepositoryEnabled(); callCount[0]++; @@ -178,9 +178,9 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { getEventBus().addListener(listener); try { //now remove and reload the repository - manager.removeRepository(repoURL); - repo = manager.loadRepository(repoURL, null); - assertTrue("1.0", manager.isEnabled(repoURL)); + manager.removeRepository(repoURI); + repo = manager.loadRepository(repoURI, null); + assertTrue("1.0", manager.isEnabled(repoURI)); assertTrue("1.1", wasEnabled[0]); assertEquals("1.2", 1, callCount[0]); } finally { @@ -188,12 +188,12 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest { } } - public void testRefreshSelfReference() throws MalformedURLException, ProvisionException { + public void testRefreshSelfReference() throws ProvisionException { //setup a repository that has a reference to itself in disabled state IMetadataRepositoryManager manager = getMetadataRepositoryManager(); Map properties = new HashMap(); properties.put(IRepository.PROP_COMPRESSED, "false"); - final URL repoURL = repoLocation.toURL(); + final URI repoURL = repoLocation.toURI(); IMetadataRepository repo = manager.createRepository(repoURL, "testRefreshSelfReference", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); repo.addReference(repoURL, IRepository.TYPE_METADATA, IRepository.NONE); //adding a reference doesn't save the repository, but setting a property does diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java index 16c4c199f..f2a0b0344 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java @@ -12,8 +12,7 @@ package org.eclipse.equinox.p2.tests.metadata.repository; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.*; import junit.framework.Test; import junit.framework.TestSuite; @@ -23,8 +22,11 @@ import org.eclipse.equinox.internal.p2.core.helpers.URLUtil; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; +import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.query.Collector; import org.eclipse.equinox.p2.tests.*; /** @@ -53,9 +55,9 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { toDelete.clear(); } - public void testBasicAddRemove() throws MalformedURLException { + public void testBasicAddRemove() { File tempFile = new File(System.getProperty("java.io.tmpdir")); - URL location = tempFile.toURL(); + URI location = tempFile.toURI(); assertTrue(!managerContains(location)); manager.addRepository(location); assertTrue(managerContains(location)); @@ -63,9 +65,9 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { assertTrue(!managerContains(location)); } - public void testEnablement() throws MalformedURLException { + public void testEnablement() { File site = getTestData("Repositoy", "/testData/metadataRepo/good/"); - URL location = site.toURL(); + URI location = site.toURI(); manager.addRepository(location); assertEquals("1.0", true, manager.isEnabled(location)); TestRepositoryListener listener = new TestRepositoryListener(location); @@ -88,9 +90,9 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { * Tests that adding a repository that is already known but disabled * causes the repository to be enabled. See bug 241307 for discussion. */ - public void testEnablementOnAdd() throws MalformedURLException { + public void testEnablementOnAdd() { File site = getTestData("Repositoy", "/testData/metadataRepo/good/"); - URL location = site.toURL(); + URI location = site.toURI(); manager.addRepository(location); manager.setEnabled(location, false); TestRepositoryListener listener = new TestRepositoryListener(location); @@ -103,18 +105,18 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { assertEquals("1.1", true, manager.isEnabled(location)); } - public void testGetKnownRepositories() throws MalformedURLException, ProvisionException { - int nonSystemCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_NON_SYSTEM).length; - int systemCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_SYSTEM).length; - int allCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL).length; + public void testGetKnownRepositories() throws ProvisionException { + int nonSystemCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_NON_SYSTEM).length; + int systemCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_SYSTEM).length; + int allCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL).length; assertEquals("1.0", allCount, nonSystemCount + systemCount); //create a new repository File repoLocation = getTempLocation(); - IMetadataRepository testRepo = manager.createRepository(repoLocation.toURL(), "MetadataRepositoryManagerTest", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); - int newNonSystemCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_NON_SYSTEM).length; - int newSystemCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_SYSTEM).length; - int newAllCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL).length; + IMetadataRepository testRepo = manager.createRepository(repoLocation.toURI(), "MetadataRepositoryManagerTest", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + int newNonSystemCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_NON_SYSTEM).length; + int newSystemCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_SYSTEM).length; + int newAllCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL).length; //there should be one more non-system repository assertEquals("2.0", nonSystemCount + 1, newNonSystemCount); @@ -125,29 +127,29 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { testRepo.setProperty(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); //there should be one more system repository - newNonSystemCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_NON_SYSTEM).length; - newSystemCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_SYSTEM).length; - newAllCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL).length; + newNonSystemCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_NON_SYSTEM).length; + newSystemCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_SYSTEM).length; + newAllCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL).length; assertEquals("3.0", nonSystemCount, newNonSystemCount); assertEquals("3.1", systemCount + 1, newSystemCount); assertEquals("3.2", allCount + 1, newAllCount); - int disabledCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_DISABLED).length; + int disabledCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED).length; allCount = newAllCount; //mark the repository as disabled manager.setEnabled(testRepo.getLocation(), false); //should be one less enabled repository and one more disabled repository - int newDisabledCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_DISABLED).length; - newAllCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL).length; + int newDisabledCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED).length; + newAllCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL).length; assertEquals("4.0", disabledCount + 1, newDisabledCount); assertEquals("4.1", allCount - 1, newAllCount); //re-loading the repository should not change anything manager.loadRepository(testRepo.getLocation(), null); - newDisabledCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_DISABLED).length; - newAllCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL).length; + newDisabledCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED).length; + newAllCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL).length; assertEquals("5.0", disabledCount + 1, newDisabledCount); assertEquals("5.1", allCount - 1, newAllCount); @@ -155,8 +157,8 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { manager.setEnabled(testRepo.getLocation(), true); //should be back to the original counts - newDisabledCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_DISABLED).length; - newAllCount = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL).length; + newDisabledCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED).length; + newAllCount = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL).length; assertEquals("6.0", disabledCount, newDisabledCount); assertEquals("6.1", allCount, newAllCount); } @@ -166,7 +168,7 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { */ public void testLoadMissingRepository() throws IOException { File tempFile = File.createTempFile("testLoadMissingArtifactRepository", null); - URL location = tempFile.toURL(); + URI location = tempFile.toURI(); try { manager.loadRepository(location, null); fail("1.0");//should fail @@ -179,7 +181,7 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { /** * Tests that we don't create a local cache when contacting a local metadata repository. */ - public void testMetadataCachingLocalRepo() throws MalformedURLException, ProvisionException { + public void testMetadataCachingLocalRepo() throws ProvisionException { File repoLocation = getTempLocation(); AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(TestActivator.getContext(), AgentLocation.class.getName()); URL dataArea = agentLocation.getDataArea("org.eclipse.equinox.p2.metadata.repository/cache/"); @@ -188,8 +190,8 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { File cacheFileJAR = new File(dataAreaFile, "content" + repoLocation.hashCode() + ".jar"); // create a local repository - manager.createRepository(repoLocation.toURL(), "MetadataRepositoryCachingTest", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); - manager.loadRepository(repoLocation.toURL(), null); + manager.createRepository(repoLocation.toURI(), "MetadataRepositoryCachingTest", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + manager.loadRepository(repoLocation.toURI(), null); // check that a local cache was not created assertFalse("Cache file was created.", cacheFileXML.exists() || cacheFileJAR.exists()); @@ -199,15 +201,15 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { * Tests that local caching of remote metadata repositories works, and that the * cache is updated when it becomes stale. */ - public void testMetadataCachingRemoteRepo() throws MalformedURLException, ProvisionException { - URL repoLocation = new URL("http://download.eclipse.org/eclipse/updates/3.4milestones/"); + public void testMetadataCachingRemoteRepo() throws URISyntaxException, ProvisionException { + URI repoLocation = new URI("http://download.eclipse.org/eclipse/updates/3.4milestones/"); if (!repoAvailable(repoLocation)) return; AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(TestActivator.getContext(), AgentLocation.class.getName()); URL dataArea = agentLocation.getDataArea("org.eclipse.equinox.p2.metadata.repository/cache/"); File dataAreaFile = URLUtil.toFile(dataArea); - File cacheFileXML = new File(dataAreaFile, "content" + repoLocation.toExternalForm().hashCode() + ".xml"); - File cacheFileJAR = new File(dataAreaFile, "content" + repoLocation.toExternalForm().hashCode() + ".jar"); + File cacheFileXML = new File(dataAreaFile, "content" + repoLocation.hashCode() + ".xml"); + File cacheFileJAR = new File(dataAreaFile, "content" + repoLocation.hashCode() + ".jar"); File cacheFile; // load a remote repository and check that a local cache was created @@ -233,18 +235,30 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { cacheFile.delete(); } + public void testPathWithSpaces() { + File site = getTestData("Repository", "/testData/metadataRepo/good with spaces/"); + URI location = site.toURI(); + try { + IMetadataRepository repository = manager.loadRepository(location, getMonitor()); + Collector result = repository.query(new InstallableUnitQuery("test.bundle"), new Collector(), getMonitor()); + assertEquals("1.0", 1, result.size()); + } catch (ProvisionException e) { + fail("=.99", e); + } + } + /** * Tests that trailing slashes do not affect repository identity. */ public void testTrailingSlashes() { File site = getTestData("Repository", "/testData/metadataRepo/good/"); - URL locationSlash, locationNoSlash; + URI locationSlash, locationNoSlash; try { - locationSlash = site.toURL(); - String locationString = locationSlash.toExternalForm(); + locationSlash = site.toURI(); + String locationString = locationSlash.toString(); locationString = locationString.substring(0, locationString.length() - 1); - locationNoSlash = new URL(locationString); - } catch (MalformedURLException e) { + locationNoSlash = new URI(locationString); + } catch (URISyntaxException e) { fail("0.99", e); return; } @@ -259,9 +273,9 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { } } - private boolean repoAvailable(URL repoLocation) { + private boolean repoAvailable(URI repoLocation) { try { - repoLocation.openStream().close(); + repoLocation.toURL().openStream().close(); } catch (IOException e) { return false; } @@ -299,8 +313,8 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { * Returns whether {@link IMetadataRepositoryManager} contains a reference * to a repository at the given location. */ - private boolean managerContains(URL location) { - URL[] locations = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL); + private boolean managerContains(URI location) { + URI[] locations = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); for (int i = 0; i < locations.length; i++) { if (locations[i].equals(location)) return true; diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java index a6bb7c7c1..2b155159d 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java @@ -12,7 +12,7 @@ package org.eclipse.equinox.p2.tests.mirror; import java.io.File; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.HashMap; import java.util.Map; import org.eclipse.equinox.app.IApplicationContext; @@ -60,11 +60,11 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { */ protected void tearDown() throws Exception { //remove all the repositories - getManager().removeRepository(destRepoLocation.toURL()); - getManager().removeRepository(sourceRepoLocation.toURL()); - getManager().removeRepository(sourceRepo2Location.toURL()); - getManager().removeRepository(sourceRepo3Location.toURL()); - getManager().removeRepository(sourceRepo4Location.toURL()); + getManager().removeRepository(destRepoLocation.toURI()); + getManager().removeRepository(sourceRepoLocation.toURI()); + getManager().removeRepository(sourceRepo2Location.toURI()); + getManager().removeRepository(sourceRepo3Location.toURI()); + getManager().removeRepository(sourceRepo4Location.toURI()); //delete the destination location (no left over files for the next test) delete(destRepoLocation); @@ -118,9 +118,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { /** * runs mirror application with default arguments. source is the source repo, destination is the destination repo, append is if the "-append" argument is needed */ - private void basicRunMirrorApplication(String message, URL source, URL destination, boolean append) throws Exception { + private void basicRunMirrorApplication(String message, URI source, URI destination, boolean append) throws Exception { //set the default arguments - String[] args = new String[] {"-source", source.toExternalForm(), "-destination", destination.toExternalForm(), append ? "-append" : ""}; + String[] args = new String[] {"-source", source.toString(), "-destination", destination.toString(), append ? "-append" : ""}; //run the mirror application runMirrorApplication(message, args); } @@ -130,7 +130,7 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { */ private void runMirrorApplication(String message, File source, File destination, boolean append) { try { - basicRunMirrorApplication(message, source.toURL(), destination.toURL(), append); + basicRunMirrorApplication(message, source.toURI(), destination.toURI(), append); } catch (Exception e) { fail(message, e); } @@ -157,11 +157,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup ensure setup completes successfully - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //mirror test data @@ -179,11 +177,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify contents - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //mirror test data @@ -201,11 +197,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify contents - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //mirror test data @@ -223,11 +217,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //mirror duplicate data @@ -245,11 +237,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //Setup: populate destination with duplicate artifacts @@ -257,12 +247,10 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify - assertContains(message + ".5", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContains(message + ".6", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains(message + ".5", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContains(message + ".6", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".7", e); - } catch (MalformedURLException e) { - fail(message + ".8", e); } //mirror duplicate data @@ -276,20 +264,14 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { private File artifactMirrorEmpty(String message, boolean append) { //Setup: Create an empty repository File emptyRepository = new File(getTempFolder(), getUniqueString()); - try { - //Setup: remove repository if it exists - getManager().removeRepository(emptyRepository.toURL()); - } catch (MalformedURLException e1) { - fail(message + ".0", e1); - } + //Setup: remove repository if it exists + getManager().removeRepository(emptyRepository.toURI()); //Setup: delete any data that may be in the folder delete(emptyRepository); try { - getManager().createRepository(emptyRepository.toURL(), "Empty Repository", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + getManager().createRepository(emptyRepository.toURI(), "Empty Repository", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); } catch (ProvisionException e) { fail(message + ".1", e); - } catch (MalformedURLException e) { - fail(message + ".2", e); } runMirrorApplication(message + ".0", emptyRepository, destRepoLocation, append); @@ -318,11 +300,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("1.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("1.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("1.2", e); - } catch (MalformedURLException e) { - fail("1.3", e); } } @@ -337,11 +317,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("2.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("2.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("2.2", e); - } catch (MalformedURLException e) { - fail("2.3", e); } } @@ -356,11 +334,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("3.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("3.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("3.2", e); - } catch (MalformedURLException e) { - fail("3.3", e); } } @@ -375,11 +351,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("4.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("4.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("4.2", e); - } catch (MalformedURLException e) { - fail("4.3", e); } } @@ -394,14 +368,12 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContains("5.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContains("5.2", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains("5.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContains("5.2", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); //checks that the destination has the correct number of keys (no extras) - assertEquals("5.3", getManager().loadRepository(sourceRepoLocation.toURL(), null).getArtifactKeys().length + getManager().loadRepository(sourceRepo2Location.toURL(), null).getArtifactKeys().length, getManager().loadRepository(destRepoLocation.toURL(), null).getArtifactKeys().length); + assertEquals("5.3", getManager().loadRepository(sourceRepoLocation.toURI(), null).getArtifactKeys().length + getManager().loadRepository(sourceRepo2Location.toURI(), null).getArtifactKeys().length, getManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); } catch (ProvisionException e) { fail("5.4", e); - } catch (MalformedURLException e) { - fail("5.5", e); } } @@ -416,11 +388,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("6.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("6.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("6.2", e); - } catch (MalformedURLException e) { - fail("6.3", e); } } @@ -435,11 +405,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("7.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("7.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("7.2", e); - } catch (MalformedURLException e) { - fail("7.3", e); } } @@ -454,11 +422,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("8.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("8.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("8.2", e); - } catch (MalformedURLException e) { - fail("8.3", e); } } @@ -473,11 +439,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("9.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("9.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("9.2", e); - } catch (MalformedURLException e) { - fail("9.3", e); } } @@ -492,11 +456,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("10.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("10.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("10.2", e); - } catch (MalformedURLException e) { - fail("10.3", e); } } @@ -511,14 +473,12 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContains("11.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContains("11.2", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains("11.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContains("11.2", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); //checks that the destination has the correct number of keys (no extras) - assertEquals("11.3", getManager().loadRepository(sourceRepo2Location.toURL(), null).getArtifactKeys().length + getManager().loadRepository(sourceRepo3Location.toURL(), null).getArtifactKeys().length, getManager().loadRepository(destRepoLocation.toURL(), null).getArtifactKeys().length); + assertEquals("11.3", getManager().loadRepository(sourceRepo2Location.toURI(), null).getArtifactKeys().length + getManager().loadRepository(sourceRepo3Location.toURI(), null).getArtifactKeys().length, getManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); } catch (ProvisionException e) { fail("11.4", e); - } catch (MalformedURLException e) { - fail("11.5", e); } } @@ -533,11 +493,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("12.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("12.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("12.2", e); - } catch (MalformedURLException e) { - fail("12.3", e); } } @@ -549,7 +507,7 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { delete(invalidRepository); try { - basicRunMirrorApplication("13.1", invalidRepository.toURL(), destRepoLocation.toURL(), true); + basicRunMirrorApplication("13.1", invalidRepository.toURI(), destRepoLocation.toURI(), true); //we expect a provision exception to be thrown. We should never get here. fail("13.0 ProvisionExpection not thrown"); } catch (ProvisionException e) { @@ -565,10 +523,10 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { public void testArtifactMirrorToInvalid() { try { //Setup: create a URL pointing to an unmodifiable place - URL invalidDestRepository = new URL("http://foobar.com/abcdefg"); + URI invalidDestRepository = new URI("http://foobar.com/abcdefg"); //run the application with the modifiable destination - basicRunMirrorApplication("14.1", sourceRepoLocation.toURL(), invalidDestRepository, true); + basicRunMirrorApplication("14.1", sourceRepoLocation.toURI(), invalidDestRepository, true); //we're expecting an UnsupportedOperationException so we should never get here fail("14.0 UnsupportedOperationException not thrown"); } catch (UnsupportedOperationException e) { @@ -589,8 +547,8 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: create a URL pointing to an unmodifiable place - URL invalidDestRepository = new URL("http://foobar.com/abcdefg"); - basicRunMirrorApplication("15.1", invalidRepository.toURL(), invalidDestRepository, true); + URI invalidDestRepository = new URI("http://foobar.com/abcdefg"); + basicRunMirrorApplication("15.1", invalidRepository.toURI(), invalidDestRepository, true); //We expect the ProvisionException to be thrown fail("15.0 ProvisionException not thrown"); } catch (ProvisionException e) { @@ -611,22 +569,13 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("16.1", getManager().loadRepository(emptyRepository.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("16.1", getManager().loadRepository(emptyRepository.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("16.2", e); - } catch (MalformedURLException e) { - fail("16.3", e); } - //Cleanup - try { - //remove the emptyRepository - getManager().removeRepository(emptyRepository.toURL()); - } catch (MalformedURLException e1) { - //delete any leftover data - delete(emptyRepository); - fail("16.4", e1); - } + //remove the emptyRepository + getManager().removeRepository(emptyRepository.toURI()); //delete any left over data delete(emptyRepository); } @@ -642,23 +591,14 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContains("17.1", getManager().loadRepository(emptyRepository.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContentEquals("17.2", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains("17.1", getManager().loadRepository(emptyRepository.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContentEquals("17.2", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("17.3", e); - } catch (MalformedURLException e) { - fail("17.4", e); } - //Cleanup - try { - //remove the empty repository - getManager().removeRepository(emptyRepository.toURL()); - } catch (MalformedURLException e1) { - //delete any leftover data - delete(emptyRepository); - fail("17.5", e1); - } + //remove the empty repository + getManager().removeRepository(emptyRepository.toURI()); //remove any leftover data delete(emptyRepository); } @@ -674,22 +614,13 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("18.1", getManager().loadRepository(emptyRepository.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("18.1", getManager().loadRepository(emptyRepository.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("18.2", e); - } catch (MalformedURLException e) { - fail("18.3", e); } - //Cleanup - try { - //remove the empty repository - getManager().removeRepository(emptyRepository.toURL()); - } catch (MalformedURLException e1) { - //delete any leftover data - delete(emptyRepository); - fail("18.4", e1); - } + //remove the empty repository + getManager().removeRepository(emptyRepository.toURI()); //delete any leftover data delete(emptyRepository); } @@ -709,11 +640,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("19.2", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("19.2", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("19.3", e); - } catch (MalformedURLException e) { - fail("19.4", e); } } @@ -732,14 +661,12 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContains("20.2", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContains("20.3", getManager().loadRepository(sourceRepo4Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains("20.2", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContains("20.3", getManager().loadRepository(sourceRepo4Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); //checks that the destination has the correct number of keys (no extras) - assertEquals("20.4", getManager().loadRepository(sourceRepoLocation.toURL(), null).getArtifactKeys().length + getManager().loadRepository(sourceRepo4Location.toURL(), null).getArtifactKeys().length, getManager().loadRepository(destRepoLocation.toURL(), null).getArtifactKeys().length); + assertEquals("20.4", getManager().loadRepository(sourceRepoLocation.toURI(), null).getArtifactKeys().length + getManager().loadRepository(sourceRepo4Location.toURI(), null).getArtifactKeys().length, getManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); } catch (ProvisionException e) { fail("20.5", e); - } catch (MalformedURLException e) { - fail("20.6", e); } } @@ -815,14 +742,12 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { artifactMirrorToEmpty("24.0", true); try { - IArtifactRepository sourceRepository = getManager().loadRepository(sourceRepoLocation.toURL(), null); - IArtifactRepository destinationRepository = getManager().loadRepository(destRepoLocation.toURL(), null); + IArtifactRepository sourceRepository = getManager().loadRepository(sourceRepoLocation.toURI(), null); + IArtifactRepository destinationRepository = getManager().loadRepository(destRepoLocation.toURI(), null); assertEquals("24.1", sourceRepository.getName(), destinationRepository.getName()); assertRepositoryProperties("24.2", sourceRepository.getProperties(), destinationRepository.getProperties()); } catch (ProvisionException e) { fail("24.3", e); - } catch (MalformedURLException e) { - fail("24.4", e); } } @@ -835,24 +760,20 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest { Map properties = null; //default properties try { //create the repository and get the resulting properties - properties = getManager().createRepository(destRepoLocation.toURL(), name, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties).getProperties(); + properties = getManager().createRepository(destRepoLocation.toURI(), name, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties).getProperties(); } catch (ProvisionException e) { fail("25.0", e); - } catch (MalformedURLException e) { - fail("25.1", e); } //run the mirror application artifactMirrorToEmpty("25.2", true); try { - IArtifactRepository repository = getManager().loadRepository(destRepoLocation.toURL(), null); + IArtifactRepository repository = getManager().loadRepository(destRepoLocation.toURI(), null); assertEquals("25.3", name, repository.getName()); assertRepositoryProperties("25.4", properties, repository.getProperties()); } catch (ProvisionException e) { fail("25.5", e); - } catch (MalformedURLException e) { - fail("25.6", e); } } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactRepositoryCleanupTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactRepositoryCleanupTest.java index d89121351..42149bbda 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactRepositoryCleanupTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactRepositoryCleanupTest.java @@ -11,17 +11,15 @@ package org.eclipse.equinox.p2.tests.mirror; import java.io.File; -import java.net.MalformedURLException; +import java.net.URI; import java.util.HashMap; import java.util.Map; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.equinox.internal.p2.artifact.mirror.MirrorApplication; import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRepositoryManager; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; -import org.eclipse.equinox.p2.tests.TestActivator; import org.osgi.framework.Bundle; /** @@ -33,9 +31,9 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { protected File bystanderRepoLocation; //anotherfeature //TODO change to an abstracted type when API is available - private ArtifactRepositoryManager getConcreteArtifactRepositoryManager() { - return (ArtifactRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IArtifactRepositoryManager.class.getName()); - } + // private ArtifactRepositoryManager getArtifactRepositoryManager() { + // return (ArtifactRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IArtifactRepositoryManager.class.getName()); + // } protected void setUp() throws Exception { super.setUp(); @@ -51,9 +49,9 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { protected void tearDown() throws Exception { //remove all the repositories - getArtifactRepositoryManager().removeRepository(destRepoLocation.toURL()); - getArtifactRepositoryManager().removeRepository(sourceRepoLocation.toURL()); - getArtifactRepositoryManager().removeRepository(bystanderRepoLocation.toURL()); + getArtifactRepositoryManager().removeRepository(destRepoLocation.toURI()); + getArtifactRepositoryManager().removeRepository(sourceRepoLocation.toURI()); + getArtifactRepositoryManager().removeRepository(bystanderRepoLocation.toURI()); //delete the destination location (no left over files for the next test) delete(destRepoLocation); @@ -61,6 +59,13 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { } /** + * Returns whether the artifact repository manager contains a repository at the given location. + */ + protected boolean contains(URI location) { + return ((ArtifactRepositoryManager) getArtifactRepositoryManager()).contains(location); + } + + /** * runs default mirror. source is the source repo, destination is the destination repo */ private void runMirrorApplication(final File source, final File destination, final boolean append) throws Exception { @@ -73,12 +78,7 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { public Map getArguments() { Map arguments = new HashMap(); - try { - arguments.put(IApplicationContext.APPLICATION_ARGS, new String[] {"-source", source.toURL().toExternalForm(), "-destination", destination.toURL().toExternalForm(), append ? "-append" : ""}); - - } catch (MalformedURLException e) { - fail("invalid URL for source or target repo"); - } + arguments.put(IApplicationContext.APPLICATION_ARGS, new String[] {"-source", source.toURI().toString(), "-destination", destination.toURI().toString(), append ? "-append" : ""}); return arguments; } @@ -120,14 +120,10 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { fail("1.0", e); } - try { - //TODO modify the contains statement once the API is available - assertFalse(getConcreteArtifactRepositoryManager().contains(sourceRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteArtifactRepositoryManager().contains(destRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("1.1", e); - } + //TODO modify the contains statement once the API is available + assertFalse(contains(sourceRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(destRepoLocation.toURI())); } /** @@ -137,11 +133,9 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { public void testArtifactMirrorRemovesReposWithSourceLoaded() { try { //Load the source - getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null); + getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); } catch (ProvisionException e) { fail("2.0", e); - } catch (MalformedURLException e) { - fail("2.1", e); } try { @@ -150,14 +144,10 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { fail("2.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(sourceRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteArtifactRepositoryManager().contains(destRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("2.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(sourceRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(destRepoLocation.toURI())); } /** @@ -167,12 +157,10 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { public void testArtifactMirrorRemovesReposWithDestinationLoaded() { try { //Load (by creating) the destination - String repositoryName = destRepoLocation.toURL() + " - artifacts"; //$NON-NLS-1$ - getConcreteArtifactRepositoryManager().createRepository(destRepoLocation.toURL(), repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + String repositoryName = destRepoLocation.toURI() + " - artifacts"; //$NON-NLS-1$ + getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); } catch (ProvisionException e) { fail("3.0", e); - } catch (MalformedURLException e) { - fail("3.1", e); } try { @@ -181,14 +169,10 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { fail("3.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(destRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteArtifactRepositoryManager().contains(sourceRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("3.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(destRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(sourceRepoLocation.toURI())); } /** @@ -198,14 +182,12 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { public void testArtifactMirrorRemovesReposWithBothLoaded() { try { //Load (by creating) the destination - String repositoryName = destRepoLocation.toURL() + " - artifacts"; //$NON-NLS-1$ - getConcreteArtifactRepositoryManager().createRepository(destRepoLocation.toURL(), repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + String repositoryName = destRepoLocation.toURI() + " - artifacts"; //$NON-NLS-1$ + getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); //Load the source - getConcreteArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null); + getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); } catch (ProvisionException e) { fail("4.0", e); - } catch (MalformedURLException e) { - fail("4.1", e); } try { @@ -214,14 +196,10 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { fail("4.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(destRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(sourceRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("4.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(destRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertTrue(contains(sourceRepoLocation.toURI())); } /** @@ -233,11 +211,9 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { public void testArtifactMirrorRemovesReposWithBystanderLoaded() { try { //Load the bystander repository. This should not be effected by the mirror application - getConcreteArtifactRepositoryManager().loadRepository(bystanderRepoLocation.toURL(), null); + getArtifactRepositoryManager().loadRepository(bystanderRepoLocation.toURI(), null); } catch (ProvisionException e) { fail("5.0", e); - } catch (MalformedURLException e) { - fail("5.1", e); } try { @@ -246,17 +222,13 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { fail("5.2", e); } - try { - //TODO modify the contains statement once the API is available - assertFalse(getConcreteArtifactRepositoryManager().contains(sourceRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteArtifactRepositoryManager().contains(destRepoLocation.toURL())); - //Ensure bystander was not effected by the mirror application - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(bystanderRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("5.3", e); - } + //TODO modify the contains statement once the API is available + assertFalse(contains(sourceRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(destRepoLocation.toURI())); + //Ensure bystander was not effected by the mirror application + //TODO modify the contains statement once the API is available + assertTrue(contains(bystanderRepoLocation.toURI())); } /** @@ -268,13 +240,11 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { public void testArtifactMirrorRemovesReposWithSourceAndBystanderLoaded() { try { //Load the bystander repository. This should not be effected by the mirror application - getConcreteArtifactRepositoryManager().loadRepository(bystanderRepoLocation.toURL(), null); + getArtifactRepositoryManager().loadRepository(bystanderRepoLocation.toURI(), null); //Load the source - getConcreteArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null); + getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); } catch (ProvisionException e) { fail("6.0", e); - } catch (MalformedURLException e) { - fail("6.1", e); } try { @@ -283,17 +253,13 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { fail("6.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(sourceRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteArtifactRepositoryManager().contains(destRepoLocation.toURL())); - //Ensure bystander was not effected by the mirror application - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(bystanderRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("6.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(sourceRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(destRepoLocation.toURI())); + //Ensure bystander was not effected by the mirror application + //TODO modify the contains statement once the API is available + assertTrue(contains(bystanderRepoLocation.toURI())); } /** @@ -305,14 +271,12 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { public void testArtifactMirrorRemovesReposWithDestinationAndBystanderLoaded() { try { //Load the bystander repository. This should not be effected by the mirror application - getArtifactRepositoryManager().loadRepository(bystanderRepoLocation.toURL(), null); + getArtifactRepositoryManager().loadRepository(bystanderRepoLocation.toURI(), null); //Load (by creating) the destination - String repositoryName = destRepoLocation.toURL() + " - artifacts"; //$NON-NLS-1$ - getArtifactRepositoryManager().createRepository(destRepoLocation.toURL(), repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + String repositoryName = destRepoLocation.toURI() + " - artifacts"; //$NON-NLS-1$ + getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); } catch (ProvisionException e) { fail("7.0", e); - } catch (MalformedURLException e) { - fail("7.1", e); } try { @@ -321,17 +285,13 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { fail("7.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(destRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteArtifactRepositoryManager().contains(sourceRepoLocation.toURL())); - //Ensure bystander was not effected by the mirror application - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(bystanderRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("7.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(destRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(sourceRepoLocation.toURI())); + //Ensure bystander was not effected by the mirror application + //TODO modify the contains statement once the API is available + assertTrue(contains(bystanderRepoLocation.toURI())); } /** @@ -343,16 +303,14 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { public void testArtifactMirrorRemovesReposWithBothAndBystanderLoaded() { try { //Load the bystander repository. This should not be effected by the mirror application - getConcreteArtifactRepositoryManager().loadRepository(bystanderRepoLocation.toURL(), null); + getArtifactRepositoryManager().loadRepository(bystanderRepoLocation.toURI(), null); //Load (by creating) the destination - String repositoryName = destRepoLocation.toURL() + " - artifacts"; //$NON-NLS-1$ - getConcreteArtifactRepositoryManager().createRepository(destRepoLocation.toURL(), repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + String repositoryName = destRepoLocation.toURI() + " - artifacts"; //$NON-NLS-1$ + getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); //Load the source - getConcreteArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null); + getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); } catch (ProvisionException e) { fail("8.0", e); - } catch (MalformedURLException e) { - fail("8.1", e); } try { @@ -361,16 +319,12 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest { fail("8.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(destRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(sourceRepoLocation.toURL())); - //Ensure bystander was not effected by the mirror application - //TODO modify the contains statement once the API is available - assertTrue(getConcreteArtifactRepositoryManager().contains(bystanderRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("8.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(destRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertTrue(contains(sourceRepoLocation.toURI())); + //Ensure bystander was not effected by the mirror application + //TODO modify the contains statement once the API is available + assertTrue(contains(bystanderRepoLocation.toURI())); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java index 39d8a9cdb..7962011e8 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java @@ -12,7 +12,7 @@ package org.eclipse.equinox.p2.tests.mirror; import java.io.File; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.HashMap; import java.util.Map; import org.eclipse.equinox.app.IApplicationContext; @@ -63,11 +63,11 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { */ protected void tearDown() throws Exception { //remove all the repositories - getManager().removeRepository(destRepoLocation.toURL()); - getManager().removeRepository(sourceRepoLocation.toURL()); - getManager().removeRepository(sourceRepo2Location.toURL()); - getManager().removeRepository(sourceRepo3Location.toURL()); - getManager().removeRepository(sourceRepo4Location.toURL()); + getManager().removeRepository(destRepoLocation.toURI()); + getManager().removeRepository(sourceRepoLocation.toURI()); + getManager().removeRepository(sourceRepo2Location.toURI()); + getManager().removeRepository(sourceRepo3Location.toURI()); + getManager().removeRepository(sourceRepo4Location.toURI()); //delete the destination location (no left over files for the next test) delete(destRepoLocation); @@ -121,9 +121,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { /** * runs mirror application with default arguments. source is the source repo, destination is the destination repo, append is if the "-append" argument is needed */ - private void basicRunMirrorApplication(String message, URL source, URL destination, boolean append) throws Exception { + private void basicRunMirrorApplication(String message, URI source, URI destination, boolean append) throws Exception { //set the default arguments - String[] args = new String[] {"-source", source.toExternalForm(), "-destination", destination.toExternalForm(), append ? "-append" : ""}; + String[] args = new String[] {"-source", source.toString(), "-destination", destination.toString(), append ? "-append" : ""}; //run the mirror application runMirrorApplication(message, args); } @@ -133,7 +133,7 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { */ private void runMirrorApplication(String message, File source, File destination, boolean append) { try { - basicRunMirrorApplication(message, source.toURL(), destination.toURL(), append); + basicRunMirrorApplication(message, source.toURI(), destination.toURI(), append); } catch (Exception e) { fail(message, e); } @@ -181,11 +181,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: ensure setup completed successfully - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //mirror test data @@ -204,11 +202,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify contents - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //mirror test data @@ -226,11 +222,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify contents - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //mirror test data @@ -248,11 +242,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //mirror duplicate data @@ -270,11 +262,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify - assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals(message + ".1", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".2", e); - } catch (MalformedURLException e) { - fail(message + ".3", e); } //Setup: populate destination with duplicate metadata @@ -282,12 +272,10 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //Setup: verify - assertContains(message + ".5", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContains(message + ".6", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains(message + ".5", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContains(message + ".6", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail(message + ".7", e); - } catch (MalformedURLException e) { - fail(message + ".8", e); } //mirror duplicate data @@ -302,20 +290,14 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { private File metadataMirrorEmpty(String message, boolean append) { //Setup: Create an empty repository File emptyRepository = new File(getTempFolder(), getUniqueString()); - try { - //Setup: remove repository if it exists - getManager().removeRepository(emptyRepository.toURL()); - } catch (MalformedURLException e1) { - fail(message + ".0", e1); - } + //Setup: remove repository if it exists + getManager().removeRepository(emptyRepository.toURI()); //Setup: delete any data that may be in the folder AbstractProvisioningTest.delete(emptyRepository); try { - getManager().createRepository(emptyRepository.toURL(), "Empty Repository", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + getManager().createRepository(emptyRepository.toURI(), "Empty Repository", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); } catch (ProvisionException e) { fail(message + ".1", e); - } catch (MalformedURLException e) { - fail(message + ".2", e); } runMirrorApplication(message + ".0", emptyRepository, destRepoLocation, append); @@ -344,11 +326,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("1.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("1.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("1.2", e); - } catch (MalformedURLException e) { - fail("1.3", e); } } @@ -363,11 +343,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("2.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("2.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("2.2", e); - } catch (MalformedURLException e) { - fail("2.3", e); } } @@ -382,11 +360,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("3.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("3.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("3.2", e); - } catch (MalformedURLException e) { - fail("3.3", e); } } @@ -401,11 +377,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("4.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("4.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("4.2", e); - } catch (MalformedURLException e) { - fail("4.3", e); } } @@ -420,14 +394,12 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContains("5.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContains("5.2", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains("5.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContains("5.2", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); //checks that the destination has the correct number of keys (no extras) - assertEquals("5.3", getNumUnique(getManager().loadRepository(sourceRepoLocation.toURL(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getManager().loadRepository(sourceRepo2Location.toURL(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getManager().loadRepository(destRepoLocation.toURL(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); + assertEquals("5.3", getNumUnique(getManager().loadRepository(sourceRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getManager().loadRepository(sourceRepo2Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); } catch (ProvisionException e) { fail("5.4", e); - } catch (MalformedURLException e) { - fail("5.5", e); } } @@ -442,11 +414,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("6.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("6.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("6.2", e); - } catch (MalformedURLException e) { - fail("6.3", e); } } @@ -461,11 +431,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("7.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("7.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("7.2", e); - } catch (MalformedURLException e) { - fail("7.3", e); } } @@ -480,11 +448,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("8.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("8.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("8.2", e); - } catch (MalformedURLException e) { - fail("8.3", e); } } @@ -499,11 +465,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("9.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("9.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("9.2", e); - } catch (MalformedURLException e) { - fail("9.3", e); } } @@ -518,11 +482,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("10.1", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("10.1", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("10.2", e); - } catch (MalformedURLException e) { - fail("10.3", e); } } @@ -537,14 +499,12 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContains("11.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContains("11.2", getManager().loadRepository(sourceRepo2Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains("11.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContains("11.2", getManager().loadRepository(sourceRepo2Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); //checks that the destination has the correct number of keys (no extras) - assertEquals("11.3", getNumUnique(getManager().loadRepository(sourceRepo2Location.toURL(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getManager().loadRepository(sourceRepo3Location.toURL(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getManager().loadRepository(destRepoLocation.toURL(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); + assertEquals("11.3", getNumUnique(getManager().loadRepository(sourceRepo2Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getManager().loadRepository(sourceRepo3Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); } catch (ProvisionException e) { fail("11.4", e); - } catch (MalformedURLException e) { - fail("11.5", e); } } @@ -559,11 +519,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("12.1", getManager().loadRepository(sourceRepo3Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("12.1", getManager().loadRepository(sourceRepo3Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("12.2", e); - } catch (MalformedURLException e) { - fail("12.3", e); } } @@ -577,7 +535,7 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { delete(invalidRepository); try { - basicRunMirrorApplication("13.1", invalidRepository.toURL(), destRepoLocation.toURL(), true); + basicRunMirrorApplication("13.1", invalidRepository.toURI(), destRepoLocation.toURI(), true); //we expect a provisioning exception to be thrown and should never get here fail("13.0 ProvisionExpection not thrown"); } catch (ProvisionException e) { @@ -591,10 +549,10 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { * Tests MirrorApplication's behaviour when given an invalid destination repository with "-append" */ public void testMetadataMirrorToInvalid() { - URL invalidDestRepository; + URI invalidDestRepository; try { - invalidDestRepository = new URL("http://foobar.com/abcdefg"); - basicRunMirrorApplication("14.1", sourceRepoLocation.toURL(), invalidDestRepository, true); + invalidDestRepository = new URI("http://foobar.com/abcdefg"); + basicRunMirrorApplication("14.1", sourceRepoLocation.toURI(), invalidDestRepository, true); //we expect an illegal state exception to be thrown and should never get here fail("14.0 IllegalStateExpection not thrown"); } catch (IllegalStateException e) { @@ -612,8 +570,8 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { delete(invalidRepository); try { - URL invalidDestRepository = new URL("http://foobar.com/abcdefg"); - basicRunMirrorApplication("15.1", invalidRepository.toURL(), invalidDestRepository, true); + URI invalidDestRepository = new URI("http://foobar.com/abcdefg"); + basicRunMirrorApplication("15.1", invalidRepository.toURI(), invalidDestRepository, true); //we expect a provisioning exception to be thrown and should never get here fail("15.0 ProvisionExpection not thrown"); } catch (ProvisionException e) { @@ -634,22 +592,13 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("16.1", getManager().loadRepository(emptyRepository.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("16.1", getManager().loadRepository(emptyRepository.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("16.2", e); - } catch (MalformedURLException e) { - fail("16.3", e); } - //Cleanup - try { - //remove the empty repository - getManager().removeRepository(emptyRepository.toURL()); - } catch (MalformedURLException e) { - //delete any leftover data - delete(emptyRepository); - fail("16.4", e); - } + //remove the empty repository + getManager().removeRepository(emptyRepository.toURI()); //delete any leftover data delete(emptyRepository); } @@ -665,23 +614,14 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContains("17.1", getManager().loadRepository(emptyRepository.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContentEquals("17.2", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains("17.1", getManager().loadRepository(emptyRepository.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContentEquals("17.2", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("17.3", e); - } catch (MalformedURLException e) { - fail("17.4", e); } - //Cleanup - try { - //remove the empty repository - getManager().removeRepository(emptyRepository.toURL()); - } catch (MalformedURLException e1) { - //delete any leftover data - delete(emptyRepository); - fail("17.5", e1); - } + //remove the empty repository + getManager().removeRepository(emptyRepository.toURI()); //delete any leftover data delete(emptyRepository); } @@ -697,22 +637,13 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("18.1", getManager().loadRepository(emptyRepository.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("18.1", getManager().loadRepository(emptyRepository.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("18.2", e); - } catch (MalformedURLException e) { - fail("18.3", e); } - //Cleanup - try { - //remove the empty repository - getManager().removeRepository(emptyRepository.toURL()); - } catch (MalformedURLException e1) { - //delete any leftover data - delete(emptyRepository); - fail("18.4", e1); - } + //remove the empty repository + getManager().removeRepository(emptyRepository.toURI()); //delete any leftover data delete(emptyRepository); } @@ -732,11 +663,9 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContentEquals("19.2", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContentEquals("19.2", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); } catch (ProvisionException e) { fail("19.3", e); - } catch (MalformedURLException e) { - fail("19.4", e); } } @@ -755,14 +684,12 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { try { //verify destination's content - assertContains("20.2", getManager().loadRepository(sourceRepoLocation.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); - assertContains("20.3", getManager().loadRepository(sourceRepo4Location.toURL(), null), getManager().loadRepository(destRepoLocation.toURL(), null)); + assertContains("20.2", getManager().loadRepository(sourceRepoLocation.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); + assertContains("20.3", getManager().loadRepository(sourceRepo4Location.toURI(), null), getManager().loadRepository(destRepoLocation.toURI(), null)); //checks that the destination has the correct number of keys (no extras) - assertEquals("20.4", getNumUnique(getManager().loadRepository(sourceRepoLocation.toURL(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getManager().loadRepository(sourceRepo4Location.toURL(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getManager().loadRepository(destRepoLocation.toURL(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); + assertEquals("20.4", getNumUnique(getManager().loadRepository(sourceRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getManager().loadRepository(sourceRepo4Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); } catch (ProvisionException e) { fail("20.5", e); - } catch (MalformedURLException e) { - fail("20.6", e); } } @@ -834,18 +761,16 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { * Ensures that a repository created by the mirror application is a copy of the source */ public void testNewArtifactRepoProperties() { - //run mirror application with source not preexisting + //run mirror application with source not pre-existing metadataMirrorToEmpty("24.0", true); try { - IMetadataRepository sourceRepository = getManager().loadRepository(sourceRepoLocation.toURL(), null); - IMetadataRepository destinationRepository = getManager().loadRepository(destRepoLocation.toURL(), null); + IMetadataRepository sourceRepository = getManager().loadRepository(sourceRepoLocation.toURI(), null); + IMetadataRepository destinationRepository = getManager().loadRepository(destRepoLocation.toURI(), null); assertEquals("24.1", sourceRepository.getName(), destinationRepository.getName()); assertRepositoryProperties("24.2", sourceRepository.getProperties(), destinationRepository.getProperties()); } catch (ProvisionException e) { fail("24.3", e); - } catch (MalformedURLException e) { - fail("24.4", e); } } @@ -858,24 +783,20 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest { Map properties = null; //default properties try { //create the repository and get the resulting properties - properties = getManager().createRepository(destRepoLocation.toURL(), name, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties).getProperties(); + properties = getManager().createRepository(destRepoLocation.toURI(), name, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties).getProperties(); } catch (ProvisionException e) { fail("25.0", e); - } catch (MalformedURLException e) { - fail("25.1", e); } //run the mirror application metadataMirrorToEmpty("25.2", true); try { - IMetadataRepository repository = getManager().loadRepository(destRepoLocation.toURL(), null); + IMetadataRepository repository = getManager().loadRepository(destRepoLocation.toURI(), null); assertEquals("25.3", name, repository.getName()); assertRepositoryProperties("25.4", properties, repository.getProperties()); } catch (ProvisionException e) { fail("25.5", e); - } catch (MalformedURLException e) { - fail("25.6", e); } } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataRepositoryCleanupTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataRepositoryCleanupTest.java index d1ba57835..eba88d6ec 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataRepositoryCleanupTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataRepositoryCleanupTest.java @@ -11,17 +11,15 @@ package org.eclipse.equinox.p2.tests.mirror; import java.io.File; -import java.net.MalformedURLException; +import java.net.URI; import java.util.HashMap; import java.util.Map; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.equinox.internal.p2.artifact.mirror.MirrorApplication; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; -import org.eclipse.equinox.p2.tests.TestActivator; import org.osgi.framework.Bundle; /** @@ -32,9 +30,11 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { protected File sourceRepoLocation; //helloworldfeature protected File bystanderRepoLocation; //anotherfeature - //TODO change to an abstracted type when API is available - private MetadataRepositoryManager getConcreteMetadataRepositoryManager() { - return (MetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); + /** + * Returns whether the artifact repository manager contains a repository at the given location. + */ + protected boolean contains(URI location) { + return ((MetadataRepositoryManager) getMetadataRepositoryManager()).contains(location); } protected void setUp() throws Exception { @@ -51,9 +51,9 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { protected void tearDown() throws Exception { //remove all the repositories - getMetadataRepositoryManager().removeRepository(destRepoLocation.toURL()); - getMetadataRepositoryManager().removeRepository(sourceRepoLocation.toURL()); - getMetadataRepositoryManager().removeRepository(bystanderRepoLocation.toURL()); + getMetadataRepositoryManager().removeRepository(destRepoLocation.toURI()); + getMetadataRepositoryManager().removeRepository(sourceRepoLocation.toURI()); + getMetadataRepositoryManager().removeRepository(bystanderRepoLocation.toURI()); //delete the destination location (no left over files for the next test) delete(destRepoLocation); @@ -72,14 +72,7 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { public Map getArguments() { Map arguments = new HashMap(); - - try { - arguments.put(IApplicationContext.APPLICATION_ARGS, new String[] {"-source", source.toURL().toExternalForm(), "-destination", destination.toURL().toExternalForm(), append ? "-append" : ""}); - - } catch (MalformedURLException e) { - fail("invalid URL for source or target repo"); - } - + arguments.put(IApplicationContext.APPLICATION_ARGS, new String[] {"-source", source.toURI().toString(), "-destination", destination.toURI().toString(), append ? "-append" : ""}); return arguments; } @@ -120,14 +113,10 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { fail("1.0", e); } - try { - //TODO modify the contains statement once the API is available - assertFalse(getConcreteMetadataRepositoryManager().contains(sourceRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteMetadataRepositoryManager().contains(destRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("1.1", e); - } + //TODO modify the contains statement once the API is available + assertFalse(contains(sourceRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(destRepoLocation.toURI())); } /** @@ -137,11 +126,9 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { public void testMetadataMirrorRemovesReposWithSourceLoaded() { try { //Load the source - getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null); + getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); } catch (ProvisionException e) { fail("2.0", e); - } catch (MalformedURLException e) { - fail("2.1", e); } try { @@ -150,14 +137,10 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { fail("2.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(sourceRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteMetadataRepositoryManager().contains(destRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("2.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(sourceRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(destRepoLocation.toURI())); } /** @@ -167,12 +150,10 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { public void testMetadataMirrorRemovesReposWithDestinationLoaded() { try { //Load (by creating) the destination - String repositoryName = destRepoLocation.toURL() + " - metadata"; //$NON-NLS-1$ - getMetadataRepositoryManager().createRepository(destRepoLocation.toURL(), repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + String repositoryName = destRepoLocation.toURI() + " - metadata"; //$NON-NLS-1$ + getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); } catch (ProvisionException e) { fail("3.0", e); - } catch (MalformedURLException e) { - fail("3.1", e); } try { @@ -181,14 +162,10 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { fail("3.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(destRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteMetadataRepositoryManager().contains(sourceRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("3.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(destRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(sourceRepoLocation.toURI())); } /** @@ -198,14 +175,12 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { public void testMetadataMirrorRemovesReposWithBothLoaded() { try { //Load (by creating) the destination - String repositoryName = destRepoLocation.toURL() + " - metadata"; //$NON-NLS-1$ - getMetadataRepositoryManager().createRepository(destRepoLocation.toURL(), repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + String repositoryName = destRepoLocation.toURI() + " - metadata"; //$NON-NLS-1$ + getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); //Load the source - getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null); + getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); } catch (ProvisionException e) { fail("4.0", e); - } catch (MalformedURLException e) { - fail("4.1", e); } try { @@ -214,14 +189,10 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { fail("4.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(destRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(sourceRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("4.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(destRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertTrue(contains(sourceRepoLocation.toURI())); } /** @@ -233,12 +204,10 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { public void testMetadataMirrorRemovesReposWithBystanderLoaded() { //Load the bystander repository. This should not be effected by the mirror application try { - getMetadataRepositoryManager().loadRepository(bystanderRepoLocation.toURL(), null); + getMetadataRepositoryManager().loadRepository(bystanderRepoLocation.toURI(), null); } catch (ProvisionException e) { // TODO Auto-generated catch block fail("5.0", e); - } catch (MalformedURLException e) { - fail("5.1", e); } try { @@ -247,17 +216,13 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { fail("5.2", e); } - try { - //TODO modify the contains statement once the API is available - assertFalse(getConcreteMetadataRepositoryManager().contains(sourceRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteMetadataRepositoryManager().contains(destRepoLocation.toURL())); - //Ensure bystander was not effected by the mirror application - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(bystanderRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("5.3", e); - } + //TODO modify the contains statement once the API is available + assertFalse(contains(sourceRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(destRepoLocation.toURI())); + //Ensure bystander was not effected by the mirror application + //TODO modify the contains statement once the API is available + assertTrue(contains(bystanderRepoLocation.toURI())); } /** @@ -269,13 +234,11 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { public void testMetadataMirrorRemovesReposWithSourceAndBystanderLoaded() { try { //Load the bystander repository. This should not be effected by the mirror application - getMetadataRepositoryManager().loadRepository(bystanderRepoLocation.toURL(), null); + getMetadataRepositoryManager().loadRepository(bystanderRepoLocation.toURI(), null); //Load the source - getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null); + getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); } catch (ProvisionException e) { fail("6.0", e); - } catch (MalformedURLException e) { - fail("6.1", e); } try { @@ -284,17 +247,13 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { fail("6.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(sourceRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteMetadataRepositoryManager().contains(destRepoLocation.toURL())); - //Ensure bystander was not effected by the mirror application - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(bystanderRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("6.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(sourceRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(destRepoLocation.toURI())); + //Ensure bystander was not effected by the mirror application + //TODO modify the contains statement once the API is available + assertTrue(contains(bystanderRepoLocation.toURI())); } /** @@ -306,14 +265,12 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { public void testMetadataMirrorRemovesReposWithDestinationAndBystanderLoaded() { try { //Load the bystander repository. This should not be effected by the mirror application - getMetadataRepositoryManager().loadRepository(bystanderRepoLocation.toURL(), null); + getMetadataRepositoryManager().loadRepository(bystanderRepoLocation.toURI(), null); //Load (by creating) the destination - String repositoryName = destRepoLocation.toURL() + " - metadata"; //$NON-NLS-1$ - getMetadataRepositoryManager().createRepository(destRepoLocation.toURL(), repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + String repositoryName = destRepoLocation.toURI() + " - metadata"; //$NON-NLS-1$ + getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); } catch (ProvisionException e) { fail("7.0", e); - } catch (MalformedURLException e) { - fail("7.1", e); } try { @@ -322,17 +279,13 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { fail("7.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(destRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertFalse(getConcreteMetadataRepositoryManager().contains(sourceRepoLocation.toURL())); - //Ensure bystander was not effected by the mirror application - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(bystanderRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("7.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(destRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertFalse(contains(sourceRepoLocation.toURI())); + //Ensure bystander was not effected by the mirror application + //TODO modify the contains statement once the API is available + assertTrue(contains(bystanderRepoLocation.toURI())); } /** @@ -344,16 +297,14 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { public void testMetadataMirrorRemovesReposWithBothAndBystanderLoaded() { try { //Load the bystander repository. This should not be effected by the mirror application - getMetadataRepositoryManager().loadRepository(bystanderRepoLocation.toURL(), null); + getMetadataRepositoryManager().loadRepository(bystanderRepoLocation.toURI(), null); //Load (by creating) the destination - String repositoryName = destRepoLocation.toURL() + " - metadata"; //$NON-NLS-1$ - getMetadataRepositoryManager().createRepository(destRepoLocation.toURL(), repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); + String repositoryName = destRepoLocation.toURI() + " - metadata"; //$NON-NLS-1$ + getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); //Load the source - getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null); + getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); } catch (ProvisionException e) { fail("8.0", e); - } catch (MalformedURLException e) { - fail("8.1", e); } try { @@ -362,16 +313,12 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest { fail("8.2", e); } - try { - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(destRepoLocation.toURL())); - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(sourceRepoLocation.toURL())); - //Ensure bystander was not effected by the mirror application - //TODO modify the contains statement once the API is available - assertTrue(getConcreteMetadataRepositoryManager().contains(bystanderRepoLocation.toURL())); - } catch (MalformedURLException e) { - fail("8.3", e); - } + //TODO modify the contains statement once the API is available + assertTrue(contains(destRepoLocation.toURI())); + //TODO modify the contains statement once the API is available + assertTrue(contains(sourceRepoLocation.toURI())); + //Ensure bystander was not effected by the mirror application + //TODO modify the contains statement once the API is available + assertTrue(contains(bystanderRepoLocation.toURI())); } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AllOrbit.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AllOrbit.java index 394fddf7f..21375e69a 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AllOrbit.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AllOrbit.java @@ -33,7 +33,7 @@ public class AllOrbit extends AbstractProvisioningTest { protected void setUp() throws Exception { super.setUp(); IMetadataRepositoryManager repoMan = (MetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); - repo = repoMan.loadRepository(getTestData("repository for wsdl test", "testData/orbitRepo/").toURL(), new NullProgressMonitor()); + repo = repoMan.loadRepository(getTestData("repository for wsdl test", "testData/orbitRepo/").toURI(), new NullProgressMonitor()); profile1 = createProfile("TestProfile." + getName()); planner = createPlanner(); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/TwoVersionsOfWSDL.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/TwoVersionsOfWSDL.java index dd396abb9..c782621ba 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/TwoVersionsOfWSDL.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/TwoVersionsOfWSDL.java @@ -34,7 +34,7 @@ public class TwoVersionsOfWSDL extends AbstractProvisioningTest { protected void setUp() throws Exception { super.setUp(); IMetadataRepositoryManager repoMan = (MetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); - IMetadataRepository repo = repoMan.loadRepository(getTestData("repository for wsdl test", "testData/metadataRepo/wsdlTestRepo/").toURL(), new NullProgressMonitor()); + IMetadataRepository repo = repoMan.loadRepository(getTestData("repository for wsdl test", "testData/metadataRepo/wsdlTestRepo/").toURI(), new NullProgressMonitor()); wsdl15 = (IInstallableUnit) repo.query(new InstallableUnitQuery("javax.wsdl", new VersionRange("[1.5, 1.6)")), new Collector(), null).iterator().next(); wsdl14 = (IInstallableUnit) repo.query(new InstallableUnitQuery("javax.wsdl", new VersionRange("[1.4, 1.5)")), new Collector(), null).iterator().next(); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/TestArtifactRepository.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/TestArtifactRepository.java index 59fbdd647..bd9676ca5 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/TestArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/TestArtifactRepository.java @@ -10,7 +10,7 @@ package org.eclipse.equinox.p2.tests.publisher; import java.io.*; -import java.net.URL; +import java.net.URI; import java.util.*; import java.util.zip.ZipInputStream; import org.eclipse.core.runtime.*; @@ -112,7 +112,7 @@ public class TestArtifactRepository implements IArtifactRepository { public OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException { // Check if the artifact is already in this repository if (contains(descriptor)) { - String msg = NLS.bind(Messages.available_already_in, getLocation().toExternalForm()); + String msg = NLS.bind(Messages.available_already_in, getLocation()); throw new ProvisionException(new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, ProvisionException.ARTIFACT_EXISTS, msg, null)); } return new ArtifactOutputStream(new ByteArrayOutputStream(500), descriptor); @@ -216,7 +216,7 @@ public class TestArtifactRepository implements IArtifactRepository { return description; } - public URL getLocation() { + public URI getLocation() { return null; } @@ -283,4 +283,8 @@ public class TestArtifactRepository implements IArtifactRepository { public byte[] getBytes(IArtifactDescriptor artifactDescriptor) { return (byte[]) repo.get(artifactDescriptor); } + + public IStatus getRawArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { + return getArtifact(descriptor, destination, monitor); + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java index f3e1687ae..a3c4e57b4 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java @@ -402,12 +402,12 @@ public class AbstractReconcilerTest extends AbstractProvisioningTest { /* * Create and return a new site object with the given parameters. */ - public Site createSite(String policy, boolean enabled, boolean updateable, String url, String[] plugins) { + public Site createSite(String policy, boolean enabled, boolean updateable, String uri, String[] plugins) { Site result = new Site(); result.setPolicy(policy); result.setEnabled(enabled); result.setUpdateable(updateable); - result.setUrl(url); + result.setUrl(uri); if (plugins != null) for (int i = 0; i < plugins.length; i++) result.addPlugin(plugins[i]); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AllTests.java index 2d53d2e8b..b973045d5 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AllTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AllTests.java @@ -14,7 +14,7 @@ import junit.framework.*; /** * To run the reconciler tests, you must perform some manual setup steps: - * 1) Download the platform runtime binary zip (any build, such as 3.4.0). + * 1) Download the platform runtime binary zip (latest build or the one you want to test). * 2) Set the following system property to the file system path of the binary zip. For example: * * -Dorg.eclipse.equinox.p2.reconciler.tests.platform.archive=c:/tmp/eclipse-platform-3.4-win32.zip diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/ConfigurationTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/ConfigurationTests.java index 480b3ca7e..1fd71d5c2 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/ConfigurationTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/ConfigurationTests.java @@ -11,7 +11,6 @@ package org.eclipse.equinox.p2.tests.reconciler.dropins; import java.io.File; -import java.net.MalformedURLException; import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.equinox.internal.p2.update.*; @@ -85,11 +84,7 @@ public class ConfigurationTests extends AbstractReconcilerTest { File temp = getTempFolder(); toRemove.add(temp); String siteLocation = null; - try { - siteLocation = new File(temp, "eclipse").toURL().toExternalForm(); - } catch (MalformedURLException e) { - fail("0.9", e); - } + siteLocation = new File(temp, "eclipse").toURI().toString(); // copy the data to the temp folder File source = getTestData("1.0", "testData/reconciler/247095"); @@ -145,11 +140,7 @@ public class ConfigurationTests extends AbstractReconcilerTest { File temp = getTempFolder(); toRemove.add(temp); String siteLocation = null; - try { - siteLocation = new File(temp, "eclipse").toURL().toExternalForm(); - } catch (MalformedURLException e) { - fail("0.9", e); - } + siteLocation = new File(temp, "eclipse").toURI().toString(); // copy the data to the temp folder File source = getTestData("1.0", "testData/reconciler/247095"); @@ -209,11 +200,7 @@ public class ConfigurationTests extends AbstractReconcilerTest { File temp = getTempFolder(); toRemove.add(temp); String siteLocation = null; - try { - siteLocation = new File(temp, "eclipse").toURL().toExternalForm(); - } catch (MalformedURLException e) { - fail("0.99", e); - } + siteLocation = new File(temp, "eclipse").toURI().toString(); // copy the data to the temp folder File source = getTestData("1.0", "testData/reconciler/247095"); @@ -253,12 +240,7 @@ public class ConfigurationTests extends AbstractReconcilerTest { Configuration configuration = getConfiguration(); File temp = getTempFolder(); toRemove.add(temp); - String siteLocation = null; - try { - siteLocation = new File(temp, "eclipse").toURL().toExternalForm(); - } catch (MalformedURLException e) { - fail("0.9", e); - } + String siteLocation = new File(temp, "eclipse").toURI().toString(); // copy the data to the temp folder File source = getTestData("1.0", "testData/reconciler/247095"); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/UtilTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/UtilTest.java index 537d03120..2f40a11a1 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/UtilTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/UtilTest.java @@ -43,7 +43,7 @@ public class UtilTest extends AbstractProvisioningTest { public void testDefaultBundlePool() throws MalformedURLException { IProfile profile = createProfile("test"); AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); - assertEquals(agentLocation.getDataArea("org.eclipse.equinox.p2.touchpoint.eclipse").toExternalForm(), Util.getBundlePoolLocation(profile).toExternalForm()); + assertEquals(agentLocation.getDataArea("org.eclipse.equinox.p2.touchpoint.eclipse").toExternalForm(), Util.getBundlePoolLocation(profile).toString()); } public void testExplicitBundlePool() throws MalformedURLException { @@ -51,6 +51,6 @@ public class UtilTest extends AbstractProvisioningTest { File cacheDir = new File(System.getProperty("java.io.tmpdir"), "cache"); props.put(IProfile.PROP_CACHE, cacheDir.toString()); IProfile profile = createProfile("test", null, props); - assertEquals(cacheDir.toURL().toExternalForm(), Util.getBundlePoolLocation(profile).toExternalForm()); + assertEquals(cacheDir.toURL().toExternalForm(), Util.getBundlePoolLocation(profile).toString()); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java index 72d0f6a62..f60a778cf 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java @@ -12,8 +12,8 @@ package org.eclipse.equinox.p2.tests.updatesite; import java.io.ByteArrayOutputStream; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Map; import junit.framework.Test; import junit.framework.TestSuite; @@ -56,11 +56,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/siteurl"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { @@ -76,12 +74,10 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File siteDirectory = getTestData("0.1", "/testData/updatesite/siteurl2/siteurl/"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); - updatesite.getSite().setLocationURLString(siteDirectory.toURL().toExternalForm()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); + updatesite.getSite().setLocationURIString(siteDirectory.toURI().toString()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { @@ -96,11 +92,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/digest"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { @@ -115,11 +109,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/digesturl"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { @@ -135,12 +127,10 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File digestDirectory = getTestData("0.1", "/testData/updatesite/digesturl2/digesturl/"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); - updatesite.getSite().setDigestURLString(digestDirectory.toURL().toExternalForm()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); + updatesite.getSite().setDigestURIString(digestDirectory.toURI().toString()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { @@ -159,11 +149,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/site"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -177,12 +165,10 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File base = getTestData("0.1", "/testData/updatesite"); UpdateSite updatesite = null; try { - URL siteURL = new URL(base.toURL(), "site"); + URI siteURL = base.toURI().resolve("site"); updatesite = UpdateSite.load(siteURL, getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -196,11 +182,25 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/site/site.xml"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); + } catch (ProvisionException e) { + fail("0.2", e); + } + try { + int featureCount = updatesite.loadFeatures(getMonitor()).length; + assertEquals(1, featureCount); + } catch (ProvisionException e) { + fail("0.4", e); + } + } + + public void testSiteWithSpaces() { + File site = getTestData("0.1", "/testData/updatesite/site with spaces/"); + UpdateSite updatesite = null; + try { + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -214,11 +214,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/xxxsitexxx/xxxsitexxx.xml"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -232,12 +230,10 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File siteDir = getTestData("0.1", "/testData/updatesite/xxxsitexxx"); File site = new File(siteDir, "site.xml"); try { - UpdateSite.load(site.toURL(), getMonitor()); + UpdateSite.load(site.toURI(), getMonitor()); fail("0.2"); } catch (ProvisionException e) { // expected - } catch (MalformedURLException e) { - fail("0.3", e); } } @@ -245,11 +241,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/baddigestgoodsite"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { updatesite.loadFeatures(new NullProgressMonitor()); @@ -261,12 +255,10 @@ public class UpdateSiteTest extends AbstractProvisioningTest { public void testBadDigestBadSite() { File site = getTestData("0.1", "/testData/updatesite/baddigestbadsite"); try { - UpdateSite.load(site.toURL(), getMonitor()); + UpdateSite.load(site.toURI(), getMonitor()); fail("0.2"); } catch (ProvisionException e) { // expected - } catch (MalformedURLException e) { - fail("0.3", e); } } @@ -274,12 +266,10 @@ public class UpdateSiteTest extends AbstractProvisioningTest { // handle the case where the site.xml doesn't parse correctly File site = getTestData("0.1", "/testData/updatesite/badSiteXML"); try { - UpdateSite.load(site.toURL(), getMonitor()); + UpdateSite.load(site.toURI(), getMonitor()); fail("0.2"); } catch (ProvisionException e) { // expected exception - } catch (MalformedURLException e) { - fail("0.3", e); } } @@ -291,12 +281,10 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File temp = getTempFolder(); temp.mkdirs(); try { - UpdateSite.load(temp.toURL(), getMonitor()); + UpdateSite.load(temp.toURI(), getMonitor()); fail("0.2"); } catch (ProvisionException e) { // we expect an exception - } catch (MalformedURLException e) { - fail("0.1", e); } } @@ -312,11 +300,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/badfeatureurl"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -330,11 +316,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/goodfeatureurl"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -344,15 +328,27 @@ public class UpdateSiteTest extends AbstractProvisioningTest { } } + public void testGetFileURI() throws URISyntaxException { + URI rootNoSlash = new URI("http://eclipse.org/eclipse/updates"); + URI rootSlash = new URI("http://eclipse.org/eclipse/updates/"); + URI rootSiteXML = new URI("http://eclipse.org/eclipse/updates/site.xml"); + URI rootSiteXML2 = new URI("http://eclipse.org/eclipse/updates/site_old.xml"); + URI[] allURIs = new URI[] {rootNoSlash, rootSlash, rootSiteXML, rootSiteXML2}; + for (URI uri : allURIs) { + assertEquals("1." + uri, new URI("http://eclipse.org/eclipse/updates/digest.zip"), UpdateSite.getFileURI(uri, "digest.zip")); + } + + URI rootEmpty = new URI("http://update.eclemma.org"); + assertEquals("2.1", new URI("http://update.eclemma.org/digest.zip"), UpdateSite.getFileURI(rootEmpty, "digest.zip")); + } + public void testIncludedFeature() { File site = getTestData("0.1", "/testData/updatesite/includedfeature"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -366,11 +362,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/includedfeaturearchive"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -384,11 +378,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/badincludedfeaturearchive"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -402,11 +394,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("0.1", "/testData/updatesite/nofeatureidandversion"); UpdateSite updatesite = null; try { - updatesite = UpdateSite.load(site.toURL(), getMonitor()); + updatesite = UpdateSite.load(site.toURI(), getMonitor()); } catch (ProvisionException e) { fail("0.2", e); - } catch (MalformedURLException e) { - fail("0.3", e); } try { int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length; @@ -425,11 +415,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("Update site", "/testData/updatesite/UpdateSite243422/"); IMetadataRepository metadataRepo = null; try { - metadataRepo = repoMan.loadRepository(site.toURL(), null); + metadataRepo = repoMan.loadRepository(site.toURI(), null); } catch (ProvisionException e) { fail("Can't load repository UpdateSite243422"); - } catch (MalformedURLException e) { - fail("Can't load repository UpdateSite243422"); } InstallableUnitQuery query = new InstallableUnitQuery("org.eclipse.jdt.astview.feature.feature.group", new Version("1.0.1")); Collector result = metadataRepo.query(query, new Collector(), null); @@ -449,11 +437,9 @@ public class UpdateSiteTest extends AbstractProvisioningTest { File site = getTestData("Update site", "/testData/updatesite/240121/UpdateSite240121/"); IArtifactRepository artifactRepo = null; try { - artifactRepo = repoMan.loadRepository(site.toURL(), null); + artifactRepo = repoMan.loadRepository(site.toURI(), null); } catch (ProvisionException e) { fail("Can't load repository UpdateSite240121"); - } catch (MalformedURLException e) { - fail("Can't load repository UpdateSite240121"); } IArtifactKey[] keys = artifactRepo.getArtifactKeys(); for (int i = 0; i < keys.length; i++) { @@ -472,12 +458,8 @@ public class UpdateSiteTest extends AbstractProvisioningTest { public void testFeatureJarUnzipInstruction() { IMetadataRepositoryManager repoMan = (IMetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName()); File site = getTestData("0.1", "/testData/updatesite/site"); - URL location = null; - try { - location = site.toURL(); - } catch (MalformedURLException e) { - fail("0.99", e); - } + URI location = null; + location = site.toURI(); IMetadataRepository repository; try { repository = repoMan.loadRepository(location, getMonitor()); diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/artifacts.xml b/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/artifacts.xml new file mode 100644 index 000000000..6c73323c4 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/artifacts.xml @@ -0,0 +1,28 @@ +<?xml version='1.0' encoding='UTF-8'?> +<?artifactRepository class='org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository' version='1.0.0'?> +<repository name='file:/C:/1target/provmiddle/aaTestSite/ - artifacts' type='org.eclipse.equinox.p2.artifact.repository.simpleRepository' version='1'> + <properties size='2'> + <property name='p2.compressed' value='false'/> + <property name='p2.timestamp' value='1218734853468'/> + </properties> + <mappings size='3'> + <rule filter='(& (classifier=osgi.bundle))' output='${repoUrl}/plugins/${id}_${version}.jar'/> + <rule filter='(& (classifier=binary))' output='${repoUrl}/binary/${id}_${version}'/> + <rule filter='(& (classifier=org.eclipse.update.feature))' output='${repoUrl}/features/${id}_${version}.jar'/> + </mappings> + <artifacts size='2'> + <artifact classifier='osgi.bundle' id='aaPlugin' version='1.0.0'> + <properties size='3'> + <property name='artifact.size' value='469'/> + <property name='download.size' value='469'/> + <property name='download.contentType' value='application/zip'/> + </properties> + </artifact> + <artifact classifier='org.eclipse.update.feature' id='aaFeature' version='1.0.0'> + <properties size='2'> + <property name='artifact.size' value='670'/> + <property name='download.size' value='670'/> + </properties> + </artifact> + </artifacts> +</repository> diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/features/aaFeature_1.0.0.jar b/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/features/aaFeature_1.0.0.jar Binary files differnew file mode 100644 index 000000000..f800a9ad2 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/features/aaFeature_1.0.0.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/plugins/aaPlugin_1.0.0.jar b/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/plugins/aaPlugin_1.0.0.jar Binary files differnew file mode 100644 index 000000000..65ff62b79 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/plugins/aaPlugin_1.0.0.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/readme.txt b/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/readme.txt new file mode 100644 index 000000000..6fcc19b18 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/artifactRepo/simple with spaces/readme.txt @@ -0,0 +1,2 @@ +This is a very simple artifact repository containing a single group IU (a feature), and +a single bundle IU. This repository is used by ArtifactRepositoryManagerTest
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/metadataRepo/good with spaces/content.xml b/bundles/org.eclipse.equinox.p2.tests/testData/metadataRepo/good with spaces/content.xml new file mode 100644 index 000000000..fd315dbb3 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/metadataRepo/good with spaces/content.xml @@ -0,0 +1,128 @@ +<?xml version='1.0' encoding='UTF-8'?> +<?metadataRepository class='org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository' version='1.0.0'?> +<repository name='update site: file:/C:/1target/provmiddle/org.eclipse.equinox.p2.tests/testData/updatesite/site' type='org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository' version='1'> + <properties size='3'> + <property name='p2.system' value='true'/> + <property name='p2.timestamp' value='1221680367875'/> + <property name='site.checksum' value='2404093275'/> + </properties> + <units size='5'> + <unit id='test.feature.feature.jar' version='1.0.0'> + <provides size='3'> + <provided namespace='org.eclipse.equinox.p2.iu' name='test.feature.feature.jar' version='1.0.0'/> + <provided namespace='org.eclipse.equinox.p2.eclipse.type' name='feature' version='1.0.0'/> + <provided namespace='org.eclipse.update.feature' name='test.feature' version='1.0.0'/> + </provides> + <filter> + (org.eclipse.update.install.features=true) + </filter> + <artifacts size='1'> + <artifact classifier='org.eclipse.update.feature' id='test.feature' version='1.0.0'/> + </artifacts> + <touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/> + <touchpointData size='1'> + <instructions size='1'> + <instruction key='zipped'> + true + </instruction> + </instructions> + </touchpointData> + <licenses size='1'> + <license url='http://www.example.com/license'> + [Enter License Description here.] + </license> + </licenses> + <copyright url='http://www.example.com/copyright'> + [Enter Copyright Description here.] + </copyright> + </unit> + <unit id='test.bundle' version='1.0.0' singleton='false'> + <update id='test.bundle' range='[0.0.0,1.0.0)' severity='0'/> + <properties size='1'> + <property name='org.eclipse.equinox.p2.partial.iu' value='true'/> + </properties> + <provides size='3'> + <provided namespace='org.eclipse.equinox.p2.iu' name='test.bundle' version='1.0.0'/> + <provided namespace='osgi.bundle' name='test.bundle' version='1.0.0'/> + <provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/> + </provides> + <artifacts size='1'> + <artifact classifier='osgi.bundle' id='test.bundle' version='1.0.0'/> + </artifacts> + <touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/> + <touchpointData size='1'> + <instructions size='1'> + <instruction key='manifest'> + </instruction> + </instructions> + </touchpointData> + </unit> + <unit id='test.fragment' version='1.0.0' singleton='false'> + <update id='test.fragment' range='[0.0.0,1.0.0)' severity='0'/> + <properties size='1'> + <property name='org.eclipse.equinox.p2.partial.iu' value='true'/> + </properties> + <provides size='3'> + <provided namespace='org.eclipse.equinox.p2.iu' name='test.fragment' version='1.0.0'/> + <provided namespace='osgi.bundle' name='test.fragment' version='1.0.0'/> + <provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/> + </provides> + <artifacts size='1'> + <artifact classifier='osgi.bundle' id='test.fragment' version='1.0.0'/> + </artifacts> + <touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/> + <touchpointData size='1'> + <instructions size='1'> + <instruction key='manifest'> + </instruction> + </instructions> + </touchpointData> + </unit> + <unit id='test.feature.feature.group' version='1.0.0' singleton='false'> + <update id='test.feature.feature.group' range='[0.0.0,1.0.0)' severity='0'/> + <properties size='5'> + <property name='org.eclipse.equinox.p2.name' value='%featurename'/> + <property name='org.eclipse.equinox.p2.description' value='[Enter Feature Description here.]'/> + <property name='org.eclipse.equinox.p2.description.url' value='http://www.example.com/description'/> + <property name='org.eclipse.equinox.p2.type.group' value='true'/> + <property name='df_LT.featurename' value='j the feature'/> + </properties> + <provides size='2'> + <provided namespace='org.eclipse.equinox.p2.iu' name='test.feature.feature.group' version='1.0.0'/> + <provided namespace='org.eclipse.equinox.p2.localization' name='df_LT' version='1.0.0'/> + </provides> + <requires size='3'> + <required namespace='org.eclipse.equinox.p2.iu' name='test.bundle' range='[1.0.0,1.0.0]'/> + <required namespace='org.eclipse.equinox.p2.iu' name='test.fragment' range='[1.0.0,1.0.0]'/> + <required namespace='org.eclipse.equinox.p2.iu' name='test.feature.feature.jar' range='[1.0.0,1.0.0]'> + <filter> + (org.eclipse.update.install.features=true) + </filter> + </required> + </requires> + <touchpoint id='null' version='0.0.0'/> + <licenses size='1'> + <license url='http://www.example.com/license'> + [Enter License Description here.] + </license> + </licenses> + <copyright url='http://www.example.com/copyright'> + [Enter Copyright Description here.] + </copyright> + </unit> + <unit id='Default' version='0.0.0'> + <properties size='3'> + <property name='org.eclipse.equinox.p2.name' value='Uncategorized'/> + <property name='org.eclipse.equinox.p2.description' value='Default category for otherwise uncategorized features'/> + <property name='org.eclipse.equinox.p2.type.category' value='true'/> + </properties> + <provides size='1'> + <provided namespace='org.eclipse.equinox.p2.iu' name='Default' version='0.0.0'/> + </provides> + <requires size='1'> + <required namespace='org.eclipse.equinox.p2.iu' name='test.feature.feature.group' range='[1.0.0,1.0.0]'/> + </requires> + <touchpoint id='null' version='0.0.0'/> + </unit> + </units> +</repository> diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/features/test.feature_1.0.0.jar b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/features/test.feature_1.0.0.jar Binary files differnew file mode 100644 index 000000000..80bbc69fd --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/features/test.feature_1.0.0.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/plugins/test.bundle_1.0.0.jar b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/plugins/test.bundle_1.0.0.jar Binary files differnew file mode 100644 index 000000000..00dd829d8 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/plugins/test.bundle_1.0.0.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/plugins/test.fragment_1.0.0.jar b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/plugins/test.fragment_1.0.0.jar Binary files differnew file mode 100644 index 000000000..d033e2eda --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/plugins/test.fragment_1.0.0.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/site.xml b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/site.xml new file mode 100644 index 000000000..4e619773e --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/site with spaces/site.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<site> + <feature url="features/test.feature_1.0.0.jar" id="test.feature" version="1.0.0"/> +</site> diff --git a/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/MetadataCompareApplication.java b/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/MetadataCompareApplication.java index b544f6946..6c5d761bb 100644 --- a/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/MetadataCompareApplication.java +++ b/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/MetadataCompareApplication.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.tools; -import java.net.URL; +import java.net.URI; import java.util.Arrays; import java.util.Comparator; import org.eclipse.core.runtime.NullProgressMonitor; @@ -43,8 +43,8 @@ public class MetadataCompareApplication implements IApplication { } }; - private URL sourceLocation; - private URL targetLocation; + private URI sourceLocation; + private URI targetLocation; private boolean compare = false; private boolean list = false; @@ -61,7 +61,7 @@ public class MetadataCompareApplication implements IApplication { return IApplication.EXIT_OK; } - private void list(URL location) throws ProvisionException { + private void list(URI location) throws ProvisionException { if (location == null) return; IMetadataRepository locationRepo = repoManager.getRepository(location); @@ -79,7 +79,7 @@ public class MetadataCompareApplication implements IApplication { } private void compareMetadataRepositories() throws ProvisionException { - System.out.println("\n" + sourceLocation.toExternalForm() + " -> " + targetLocation.toExternalForm()); //$NON-NLS-1$ //$NON-NLS-2$ + System.out.println("\n" + sourceLocation + " -> " + targetLocation); //$NON-NLS-1$ //$NON-NLS-2$ compare(sourceRepo, targetRepo); } @@ -226,9 +226,9 @@ public class MetadataCompareApplication implements IApplication { String arg = args[++i]; if (args[i - 1].equalsIgnoreCase("-source")) //$NON-NLS-1$ - sourceLocation = new URL(arg); + sourceLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-target")) //$NON-NLS-1$ - targetLocation = new URL(arg); + targetLocation = new URI(arg); } } diff --git a/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/mirror/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/mirror/MirrorApplication.java index dd6e9e9f2..749507c33 100644 --- a/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/mirror/MirrorApplication.java +++ b/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/mirror/MirrorApplication.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.tools.mirror; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; @@ -24,10 +24,10 @@ public class MirrorApplication implements IApplication { private static final String COMMA_SEPARATOR = ","; //$NON-NLS-1$ private String[] iuSpecs; private String[] artifactSpecs; - private URL metadataSourceLocation; - private URL metadataDestinationLocation; - private URL artifactSourceLocation; - private URL artifactDestinationLocation; + private URI metadataSourceLocation; + private URI metadataDestinationLocation; + private URI artifactSourceLocation; + private URI artifactDestinationLocation; private boolean referencedIUs = false; private boolean raw = false; private boolean overwrite = false; @@ -112,21 +112,21 @@ public class MirrorApplication implements IApplication { String arg = args[++i]; if (args[i - 1].equalsIgnoreCase("-source")) { //$NON-NLS-1$ - metadataSourceLocation = new URL(arg); - artifactSourceLocation = new URL(arg); + metadataSourceLocation = new URI(arg); + artifactSourceLocation = new URI(arg); } if (args[i - 1].equalsIgnoreCase("-destination")) { //$NON-NLS-1$ - metadataDestinationLocation = new URL(arg); - artifactDestinationLocation = new URL(arg); + metadataDestinationLocation = new URI(arg); + artifactDestinationLocation = new URI(arg); } if (args[i - 1].equalsIgnoreCase("-metadatadestination")) //$NON-NLS-1$ - metadataDestinationLocation = new URL(arg); + metadataDestinationLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-metadatasource")) //$NON-NLS-1$ - metadataSourceLocation = new URL(arg); + metadataSourceLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-artifactdestination")) //$NON-NLS-1$ - artifactDestinationLocation = new URL(arg); + artifactDestinationLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-artifactsource")) //$NON-NLS-1$ - artifactSourceLocation = new URL(arg); + artifactSourceLocation = new URI(arg); if (args[i - 1].equalsIgnoreCase("-ius")) //$NON-NLS-1$ if (arg.equalsIgnoreCase("all")) //$NON-NLS-1$ iuSpecs = new String[0]; diff --git a/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/mirror/RepositoryMirroring.java b/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/mirror/RepositoryMirroring.java index 59d852747..987a439c5 100644 --- a/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/mirror/RepositoryMirroring.java +++ b/bundles/org.eclipse.equinox.p2.tools/src/org/eclipse/equinox/internal/p2/tools/mirror/RepositoryMirroring.java @@ -12,7 +12,7 @@ package org.eclipse.equinox.internal.p2.tools.mirror; import java.io.IOException; import java.io.OutputStream; -import java.net.URL; +import java.net.URI; import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.NullProgressMonitor; @@ -50,7 +50,7 @@ public class RepositoryMirroring { private boolean verbose = false; private boolean compressed = false; - public RepositoryMirroring(URL metadataSourceLocation, URL metadataDestinationLocation, URL artifactSourceLocation, URL artifactDestinationLocation, boolean overwrite, boolean compressed) throws ProvisionException { + public RepositoryMirroring(URI metadataSourceLocation, URI metadataDestinationLocation, URI artifactSourceLocation, URI artifactDestinationLocation, boolean overwrite, boolean compressed) throws ProvisionException { this.overwrite = overwrite; this.compressed = compressed; if (metadataSourceLocation != null && metadataDestinationLocation != null) { @@ -181,7 +181,7 @@ public class RepositoryMirroring { return true; } - private IMetadataRepository initializeMetadataDestination(MetadataRepositoryManager manager, URL destinationLocation) throws ProvisionException { + private IMetadataRepository initializeMetadataDestination(MetadataRepositoryManager manager, URI destinationLocation) throws ProvisionException { IMetadataRepository repository; try { String repositoryName = destinationLocation + " - metadata"; //$NON-NLS-1$ @@ -206,7 +206,7 @@ public class RepositoryMirroring { return repository; } - private IArtifactRepository initializeArtifactDestination(ArtifactRepositoryManager repoManager, URL destinationLocation) throws ProvisionException { + private IArtifactRepository initializeArtifactDestination(ArtifactRepositoryManager repoManager, URI destinationLocation) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); IArtifactRepository repository; try { diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java index 611e90230..315695d8c 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java @@ -12,7 +12,7 @@ package org.eclipse.equinox.internal.p2.touchpoint.eclipse; import java.io.File; import java.io.IOException; -import java.net.URL; +import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; @@ -87,7 +87,7 @@ public class EclipseTouchpoint extends Touchpoint { touchpointParameters.put(PARM_MANIPULATOR, manipulator); touchpointParameters.put(PARM_SOURCE_BUNDLES, new SourceManipulator(profile)); File configLocation = Util.getConfigurationFolder(profile); - URL poolURL = Util.getBundlePoolLocation(profile); + URI poolURL = Util.getBundlePoolLocation(profile); touchpointParameters.put(PARM_PLATFORM_CONFIGURATION, new PlatformConfigurationWrapper(configLocation, poolURL, manipulator)); return null; } diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java index 952eb6386..2c9b328c4 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java @@ -11,11 +11,11 @@ package org.eclipse.equinox.internal.p2.touchpoint.eclipse; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.Iterator; import java.util.List; import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.p2.update.*; import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator; @@ -32,7 +32,7 @@ public class PlatformConfigurationWrapper { private Configuration configuration = null; private Site poolSite = null; private File configFile; - private URL poolURL; + private URI poolURI; private Manipulator manipulator; private static String FEATURES = "features/"; //$NON-NLS-1$ @@ -67,10 +67,10 @@ public class PlatformConfigurationWrapper { return parentFolder.toFile(); } - public PlatformConfigurationWrapper(File configDir, URL featurePool, Manipulator manipulator) { + public PlatformConfigurationWrapper(File configDir, URI featurePool, Manipulator manipulator) { this.configuration = null; this.configFile = new File(configDir, "/org.eclipse.update/platform.xml"); //$NON-NLS-1$ - this.poolURL = featurePool; + this.poolURI = featurePool; this.manipulator = manipulator; } @@ -88,12 +88,12 @@ public class PlatformConfigurationWrapper { // TODO: Make this a real message throw new IllegalStateException(Messages.error_parsing_configuration); } - if (poolURL == null) + if (poolURI == null) throw new IllegalStateException("Error creating platform configuration. No bundle pool defined."); //$NON-NLS-1$ - poolSite = getSite(poolURL); + poolSite = getSite(poolURI); if (poolSite == null) { - poolSite = createSite(poolURL, getDefaultPolicy()); + poolSite = createSite(poolURI, getDefaultPolicy()); configuration.add(poolSite); } } @@ -115,9 +115,9 @@ public class PlatformConfigurationWrapper { /* * Create and return a site object based on the given location. */ - private Site createSite(URL location, String policy) { + private Site createSite(URI location, String policy) { Site result = new Site(); - result.setUrl(location.toExternalForm()); + result.setUrl(location.toString()); result.setPolicy(policy); result.setEnabled(true); return result; @@ -127,13 +127,17 @@ public class PlatformConfigurationWrapper { * Look in the configuration and return the site object whose location matches * the given URL. Return null if there is no match. */ - private Site getSite(URL url) { + private Site getSite(URI url) { List sites = configuration.getSites(); + File file = URIUtil.toFile(url); for (Iterator iter = sites.iterator(); iter.hasNext();) { Site nextSite = (Site) iter.next(); - String nextURL = nextSite.getUrl(); - if (new Path(nextURL).equals(new Path(url.toExternalForm()))) { - return nextSite; + try { + File nextFile = URIUtil.toFile(new URI(nextSite.getUrl())); + if (nextFile.equals(file)) + return nextSite; + } catch (URISyntaxException e) { + //ignore incorrectly formed site } } return null; @@ -164,19 +168,15 @@ public class PlatformConfigurationWrapper { if (configuration == null) return new Status(IStatus.WARNING, Activator.ID, Messages.platform_config_unavailable, null); - URL fileURL = null; - try { - File featureDir = file.getParentFile(); - if (featureDir == null || !featureDir.getName().equals("features")) //$NON-NLS-1$ - return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.parent_dir_features, file.getAbsolutePath()), null); - File locationDir = featureDir.getParentFile(); - if (locationDir == null) - return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.cannot_calculate_extension_location, file.getAbsolutePath()), null); - - fileURL = locationDir.toURL(); - } catch (MalformedURLException e) { - return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.cannot_create_url_from_file, file.getAbsolutePath()), e); - } + URI fileURL = null; + File featureDir = file.getParentFile(); + if (featureDir == null || !featureDir.getName().equals("features")) //$NON-NLS-1$ + return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.parent_dir_features, file.getAbsolutePath()), null); + File locationDir = featureDir.getParentFile(); + if (locationDir == null) + return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.cannot_calculate_extension_location, file.getAbsolutePath()), null); + + fileURL = locationDir.toURI(); Site site = getSite(fileURL); if (site == null) { site = createSite(fileURL, getDefaultPolicy()); diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java index 0e2c9dec7..d17c5b6db 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java @@ -14,8 +14,7 @@ package org.eclipse.equinox.internal.p2.touchpoint.eclipse; import java.io.ByteArrayInputStream; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.*; @@ -64,24 +63,24 @@ public class Util { return (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); } - public static URL getBundlePoolLocation(IProfile profile) { + public static URI getBundlePoolLocation(IProfile profile) { String path = profile.getProperty(IProfile.PROP_CACHE); if (path != null) - try { - // create a file url - return new File(path).toURL(); - } catch (MalformedURLException e) { - // unexpected, URLs should be pre-checked - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e)); - } + return new File(path).toURI(); AgentLocation location = getAgentLocation(); if (location == null) return null; - return location.getDataArea(Activator.ID); + try { + return URIUtil.toURI(location.getDataArea(Activator.ID)); + } catch (URISyntaxException e) { + // unexpected, URLs should be pre-checked + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e)); + throw new RuntimeException(e); + } } public static synchronized IFileArtifactRepository getBundlePoolRepository(IProfile profile) { - URL location = getBundlePoolLocation(profile); + URI location = getBundlePoolLocation(profile); if (location == null) return null; IArtifactRepositoryManager manager = getArtifactRepositoryManager(); @@ -114,15 +113,12 @@ public class Util { String sharedCache = profile.getProperty(IProfile.PROP_SHARED_CACHE); if (sharedCache != null) { try { - URL repoURL = new File(sharedCache).toURL(); - IArtifactRepository repository = manager.loadRepository(repoURL, null); + URI repoLocation = new File(sharedCache).toURI(); + IArtifactRepository repository = manager.loadRepository(repoLocation, null); if (repository != null && repository instanceof IFileArtifactRepository && !bundleRepositories.contains(repository)) bundleRepositories.add(repository); } catch (ProvisionException e) { //skip repository if it could not be read - } catch (MalformedURLException e) { - // unexpected, URLs should be pre-checked - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e)); } } } @@ -138,13 +134,13 @@ public class Util { for (Iterator iterator = repos.iterator(); iterator.hasNext();) { try { String repo = (String) iterator.next(); - URL repoURL = new URL(repo); - IArtifactRepository repository = manager.loadRepository(repoURL, null); + URI repoLocation = new URI(repo); + IArtifactRepository repository = manager.loadRepository(repoLocation, null); if (repository != null && repository instanceof IFileArtifactRepository && !bundleRepositories.contains(repository)) bundleRepositories.add(repository); } catch (ProvisionException e) { //skip repositories that could not be read - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { // unexpected, URLs should be pre-checked LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e)); } diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java index 991725cf4..48f772c2c 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.p2.touchpoint.natives; import java.io.File; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -162,7 +162,7 @@ public class NativeTouchpoint extends Touchpoint { } static private IFileArtifactRepository getDownloadCacheRepo() throws ProvisionException { - URL location = getDownloadCacheLocation(); + URI location = getDownloadCacheLocation(); if (location == null) throw new IllegalStateException(Messages.could_not_obtain_download_cache); IArtifactRepositoryManager manager = getArtifactRepositoryManager(); @@ -185,9 +185,9 @@ public class NativeTouchpoint extends Touchpoint { return downloadCache; } - static private URL getDownloadCacheLocation() { + static private URI getDownloadCacheLocation() { AgentLocation location = getAgentLocation(); - return (location != null ? location.getArtifactRepositoryURL() : null); + return (location != null ? location.getArtifactRepositoryURI() : null); } public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) { diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoriesView.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoriesView.java index df183e6fe..9e1ae8a0f 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoriesView.java +++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoriesView.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.admin; -import java.net.URL; +import java.net.URI; import java.util.ArrayList; import org.eclipse.equinox.internal.p2.ui.admin.dialogs.AddArtifactRepositoryDialog; import org.eclipse.equinox.internal.p2.ui.admin.preferences.PreferenceConstants; @@ -58,12 +58,12 @@ public class ArtifactRepositoriesView extends RepositoriesView { } protected ProvisioningOperation getRemoveOperation(Object[] elements) { - ArrayList urls = new ArrayList(); + ArrayList locations = new ArrayList(); for (int i = 0; i < elements.length; i++) { if (elements[i] instanceof IRepositoryElement) - urls.add(((IRepositoryElement) elements[i]).getLocation()); + locations.add(((IRepositoryElement) elements[i]).getLocation()); } - return new RemoveArtifactRepositoryOperation(ProvAdminUIMessages.ArtifactRepositoriesView_RemoveRepositoryOperationLabel, (URL[]) urls.toArray(new URL[urls.size()])); + return new RemoveArtifactRepositoryOperation(ProvAdminUIMessages.ArtifactRepositoriesView_RemoveRepositoryOperationLabel, (URI[]) locations.toArray(new URI[locations.size()])); } protected int getRepoFlags() { diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoriesView.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoriesView.java index 7699c416c..bc29dbb36 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoriesView.java +++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoriesView.java @@ -12,7 +12,7 @@ package org.eclipse.equinox.internal.p2.ui.admin; import java.lang.reflect.InvocationTargetException; -import java.net.URL; +import java.net.URI; import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; @@ -133,12 +133,12 @@ public class MetadataRepositoriesView extends RepositoriesView { } protected ProvisioningOperation getRemoveOperation(Object[] elements) { - ArrayList urls = new ArrayList(); + ArrayList locations = new ArrayList(); for (int i = 0; i < elements.length; i++) { if (elements[i] instanceof IRepositoryElement) - urls.add(((IRepositoryElement) elements[i]).getLocation()); + locations.add(((IRepositoryElement) elements[i]).getLocation()); } - return new RemoveMetadataRepositoryOperation(ProvAdminUIMessages.ArtifactRepositoriesView_RemoveRepositoryOperationLabel, (URL[]) urls.toArray(new URL[urls.size()])); + return new RemoveMetadataRepositoryOperation(ProvAdminUIMessages.ArtifactRepositoriesView_RemoveRepositoryOperationLabel, (URI[]) locations.toArray(new URI[locations.size()])); } protected void makeActions() { diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddArtifactRepositoryDialog.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddArtifactRepositoryDialog.java index c3a37207f..44a7d7b45 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddArtifactRepositoryDialog.java +++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddArtifactRepositoryDialog.java @@ -10,14 +10,14 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.admin.dialogs; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.ui.admin.ProvAdminUIActivator; import org.eclipse.equinox.internal.p2.ui.admin.ProvAdminUIMessages; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.ui.dialogs.AddRepositoryDialog; import org.eclipse.equinox.internal.provisional.p2.ui.operations.*; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.URLValidator; +import org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryLocationValidator; import org.eclipse.swt.widgets.Shell; /** @@ -32,22 +32,22 @@ public class AddArtifactRepositoryDialog extends AddRepositoryDialog { super(parentShell, repoFlags); } - protected ProvisioningOperation getOperation(URL url) { - return new AddArtifactRepositoryOperation(ProvAdminUIMessages.AddArtifactRepositoryDialog_OperationLabel, url); + protected ProvisioningOperation getOperation(URI location) { + return new AddArtifactRepositoryOperation(ProvAdminUIMessages.AddArtifactRepositoryDialog_OperationLabel, location); } - protected URLValidator createURLValidator() { - return new URLValidator() { - public IStatus validateRepositoryURL(URL location, boolean contactRepositories, IProgressMonitor monitor) { + protected RepositoryLocationValidator createURLValidator() { + return new RepositoryLocationValidator() { + public IStatus validateRepositoryLocation(URI location, boolean contactRepositories, IProgressMonitor monitor) { IStatus duplicateStatus = Status.OK_STATUS; - URL[] knownRepositories; + URI[] knownRepositories; try { knownRepositories = ProvisioningUtil.getArtifactRepositories(repoFlag); } catch (ProvisionException e) { - knownRepositories = new URL[0]; + knownRepositories = new URI[0]; } for (int i = 0; i < knownRepositories.length; i++) { - if (knownRepositories[i].toExternalForm().equalsIgnoreCase(location.toExternalForm())) { + if (knownRepositories[i].equals(location)) { duplicateStatus = new Status(IStatus.ERROR, ProvAdminUIActivator.PLUGIN_ID, LOCAL_VALIDATION_ERROR, ProvAdminUIMessages.AddArtifactRepositoryDialog_DuplicateURL, null); break; } diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddMetadataRepositoryDialog.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddMetadataRepositoryDialog.java index d852dc054..7dc22d60c 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddMetadataRepositoryDialog.java +++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddMetadataRepositoryDialog.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.admin.dialogs; -import java.net.URL; +import java.net.URI; import org.eclipse.equinox.internal.p2.ui.admin.ProvAdminUIMessages; import org.eclipse.equinox.internal.provisional.p2.ui.dialogs.AddRepositoryDialog; import org.eclipse.equinox.internal.provisional.p2.ui.operations.AddMetadataRepositoryOperation; @@ -29,7 +29,7 @@ public class AddMetadataRepositoryDialog extends AddRepositoryDialog { super(parentShell, repoFlags); } - protected ProvisioningOperation getOperation(URL url) { - return new AddMetadataRepositoryOperation(ProvAdminUIMessages.AddMetadataRepositoryDialog_OperationLabel, url); + protected ProvisioningOperation getOperation(URI location) { + return new AddMetadataRepositoryOperation(ProvAdminUIMessages.AddMetadataRepositoryDialog_OperationLabel, location); } } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ColocatedRepositoryManipulator.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ColocatedRepositoryManipulator.java index dbaa72d7d..df4af78bb 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ColocatedRepositoryManipulator.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ColocatedRepositoryManipulator.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui; -import java.net.URL; +import java.net.URI; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.ui.dialogs.RepositoryManipulationDialog; import org.eclipse.equinox.internal.provisional.p2.ui.operations.*; @@ -54,8 +54,8 @@ public class ColocatedRepositoryManipulator extends RepositoryManipulator { * (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryManipulator#getAddOperation(java.net.URL) */ - public ProvisioningOperation getAddOperation(URL repoURL) { - return new AddColocatedRepositoryOperation(getAddOperationLabel(), repoURL); + public ProvisioningOperation getAddOperation(URI repoLocation) { + return new AddColocatedRepositoryOperation(getAddOperationLabel(), repoLocation); } /* @@ -70,11 +70,11 @@ public class ColocatedRepositoryManipulator extends RepositoryManipulator { * (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryManipulator#getKnownRepositories() */ - public URL[] getKnownRepositories() { + public URI[] getKnownRepositories() { try { return ProvisioningUtil.getMetadataRepositories(policy.getQueryContext().getMetadataRepositoryFlags()); } catch (ProvisionException e) { - return new URL[0]; + return new URI[0]; } } @@ -82,7 +82,7 @@ public class ColocatedRepositoryManipulator extends RepositoryManipulator { * (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryManipulator#getRemoveOperation(java.net.URL[]) */ - public ProvisioningOperation getRemoveOperation(URL[] reposToRemove) { + public ProvisioningOperation getRemoveOperation(URI[] reposToRemove) { return new RemoveColocatedRepositoryOperation(getRemoveOperationLabel(), reposToRemove); } @@ -98,7 +98,7 @@ public class ColocatedRepositoryManipulator extends RepositoryManipulator { * (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryManipulator#getURLValidator(org.eclipse.swt.widgets.Shell) */ - public URLValidator getURLValidator(Shell shell) { + public RepositoryLocationValidator getRepositoryLocationValidator(Shell shell) { DefaultMetadataURLValidator validator = new DefaultMetadataURLValidator(); validator.setKnownRepositoriesFlag(policy.getQueryContext().getMetadataRepositoryFlags()); return validator; diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/DefaultMetadataURLValidator.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/DefaultMetadataURLValidator.java index fa75d8920..4baced2e0 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/DefaultMetadataURLValidator.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/DefaultMetadataURLValidator.java @@ -11,18 +11,18 @@ package org.eclipse.equinox.internal.p2.ui; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager; import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProvisioningUtil; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.URLValidator; +import org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryLocationValidator; /** * @since 3.4 * */ -public class DefaultMetadataURLValidator extends URLValidator { +public class DefaultMetadataURLValidator extends RepositoryLocationValidator { protected int repoFlag; @@ -37,16 +37,16 @@ public class DefaultMetadataURLValidator extends URLValidator { /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.ui.dialogs.URLValidator#validateRepositoryURL(boolean) */ - public IStatus validateRepositoryURL(URL location, boolean contactRepositories, IProgressMonitor monitor) { + public IStatus validateRepositoryLocation(URI location, boolean contactRepositories, IProgressMonitor monitor) { IStatus duplicateStatus = Status.OK_STATUS; - URL[] knownRepositories; + URI[] knownRepositories; try { knownRepositories = ProvisioningUtil.getMetadataRepositories(repoFlag); } catch (ProvisionException e) { - knownRepositories = new URL[0]; + knownRepositories = new URI[0]; } for (int i = 0; i < knownRepositories.length; i++) { - if (knownRepositories[i].toExternalForm().equalsIgnoreCase(location.toExternalForm())) { + if (knownRepositories[i].equals(location)) { duplicateStatus = new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, LOCAL_VALIDATION_ERROR, ProvUIMessages.AddRepositoryDialog_DuplicateURL, null); break; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/DefaultQueryProvider.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/DefaultQueryProvider.java index f993af7c2..f4fcbf64d 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/DefaultQueryProvider.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/DefaultQueryProvider.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui; +import java.net.URI; import java.net.URL; import org.eclipse.equinox.internal.p2.ui.model.*; import org.eclipse.equinox.internal.p2.ui.query.*; @@ -61,7 +62,7 @@ public class DefaultQueryProvider extends QueryProvider { return new ElementQueryDescriptor(queryable, null, new Collector() { public boolean accept(Object object) { if (object instanceof URL) - return super.accept(new ArtifactRepositoryElement(element, (URL) object)); + return super.accept(new ArtifactRepositoryElement(element, (URI) object)); return true; } }); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AddColocatedRepositoryDialog.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AddColocatedRepositoryDialog.java index 733438d54..cc4da0ad9 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AddColocatedRepositoryDialog.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AddColocatedRepositoryDialog.java @@ -10,9 +10,8 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.dialogs; +import java.net.URI; import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; - -import java.net.URL; import org.eclipse.equinox.internal.provisional.p2.ui.dialogs.AddRepositoryDialog; import org.eclipse.equinox.internal.provisional.p2.ui.operations.AddColocatedRepositoryOperation; import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProvisioningOperation; @@ -33,7 +32,7 @@ public class AddColocatedRepositoryDialog extends AddRepositoryDialog { } - protected ProvisioningOperation getOperation(URL url) { + protected ProvisioningOperation getOperation(URI url) { return new AddColocatedRepositoryOperation(getShell().getText(), url); } } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/RepositoryManipulatorDropTarget.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/RepositoryManipulatorDropTarget.java index 8c67dca53..aef77290b 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/RepositoryManipulatorDropTarget.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/RepositoryManipulatorDropTarget.java @@ -1,17 +1,16 @@ package org.eclipse.equinox.internal.p2.ui.dialogs; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.URLValidator; - -import org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryManipulator; - -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; -import org.eclipse.equinox.internal.provisional.p2.ui.*; +import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; +import org.eclipse.equinox.internal.provisional.p2.ui.ProvisioningOperationRunner; import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProvisioningOperation; +import org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryManipulator; +import org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryLocationValidator; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DropTargetEvent; @@ -41,30 +40,30 @@ public class RepositoryManipulatorDropTarget extends URLDropAdapter { protected void handleDrop(String urlText, final DropTargetEvent event) { event.detail = DND.DROP_NONE; - final URL[] url = new URL[1]; + final URI[] location = new URI[1]; try { - url[0] = new URL(urlText); - } catch (MalformedURLException e) { - ProvUI.reportStatus(URLValidator.getInvalidURLStatus(urlText), StatusManager.SHOW | StatusManager.LOG); + location[0] = new URI(urlText); + } catch (URISyntaxException e) { + ProvUI.reportStatus(RepositoryLocationValidator.getInvalidURLStatus(urlText), StatusManager.SHOW | StatusManager.LOG); return; } - if (url[0] == null) + if (location[0] == null) return; Job job = new WorkbenchJob(ProvUIMessages.RepositoryManipulatorDropTarget_DragAndDropJobLabel) { public IStatus runInUIThread(IProgressMonitor monitor) { - IStatus status = manipulator.getURLValidator(control.getShell()).validateRepositoryURL(url[0], false, monitor); + IStatus status = manipulator.getRepositoryLocationValidator(control.getShell()).validateRepositoryLocation(location[0], false, monitor); if (status.isOK()) { - ProvisioningOperation addOperation = manipulator.getAddOperation(url[0]); + ProvisioningOperation addOperation = manipulator.getAddOperation(location[0]); ProvisioningOperationRunner.schedule(addOperation, control.getShell(), StatusManager.SHOW | StatusManager.LOG); event.detail = DND.DROP_LINK; - } else if (status.getCode() == URLValidator.ALTERNATE_ACTION_TAKEN) { + } else if (status.getCode() == RepositoryLocationValidator.ALTERNATE_ACTION_TAKEN) { event.detail = DND.DROP_COPY; } else if (status.getSeverity() == IStatus.CANCEL) { event.detail = DND.DROP_NONE; } else { - status = new MultiStatus(ProvUIActivator.PLUGIN_ID, 0, new IStatus[] {status}, NLS.bind(ProvUIMessages.RepositoryManipulatorDropTarget_DragSourceNotValid, url[0].toExternalForm()), null); + status = new MultiStatus(ProvUIActivator.PLUGIN_ID, 0, new IStatus[] {status}, NLS.bind(ProvUIMessages.RepositoryManipulatorDropTarget_DragSourceNotValid, location[0]), null); event.detail = DND.DROP_NONE; } return status; diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/StructuredIUGroup.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/StructuredIUGroup.java index 452b34c97..b197ddf89 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/StructuredIUGroup.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/StructuredIUGroup.java @@ -41,7 +41,9 @@ public abstract class StructuredIUGroup { /** * Create a group that represents the available IU's. * + * @param policy The application policy to use in the group * @param parent the parent composite for the group + * to retrieve elements in the viewer. * @param font The font to use for calculating pixel sizes. This font is * not managed by the receiver. */ diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/URLDropAdapter.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/URLDropAdapter.java index e3c14a340..321ca9ded 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/URLDropAdapter.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/URLDropAdapter.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.p2.ui.dialogs; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.URLValidator; +import org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryLocationValidator; import org.eclipse.swt.dnd.*; @@ -62,7 +62,7 @@ public abstract class URLDropAdapter extends DropTargetAdapter { if (convertFileToURL && FileTransfer.getInstance().isSupportedType(event.currentDataType)) { String[] names = (String[]) FileTransfer.getInstance().nativeToJava(event.currentDataType); if (names != null && names.length == 1) - return URLValidator.makeJarURLString(names[0]); + return RepositoryLocationValidator.makeJarURLString(names[0]); } return null; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ArtifactRepositoryElement.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ArtifactRepositoryElement.java index 187895a27..d92f13c46 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ArtifactRepositoryElement.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ArtifactRepositoryElement.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.model; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; @@ -33,17 +33,17 @@ import org.eclipse.ui.progress.IElementCollector; */ public class ArtifactRepositoryElement extends ProvElement implements IDeferredWorkbenchAdapter, IRepositoryElement { - URL url; + URI location; IArtifactRepository repo; boolean isEnabled; - public ArtifactRepositoryElement(Object parent, URL url) { - this(parent, url, true); + public ArtifactRepositoryElement(Object parent, URI location) { + this(parent, location, true); } - public ArtifactRepositoryElement(Object parent, URL url, boolean isEnabled) { + public ArtifactRepositoryElement(Object parent, URI location, boolean isEnabled) { super(parent); - this.url = url; + this.location = location; this.isEnabled = isEnabled; } @@ -76,15 +76,15 @@ public class ArtifactRepositoryElement extends ProvElement implements IDeferredW if (name != null && name.length() > 0) { return name; } - return getLocation().toExternalForm(); + return getLocation().toString(); } public IRepository getRepository(IProgressMonitor monitor) { if (repo == null) try { - repo = ProvisioningUtil.loadArtifactRepository(url, monitor); + repo = ProvisioningUtil.loadArtifactRepository(location, monitor); } catch (ProvisionException e) { - handleException(e, NLS.bind(ProvUIMessages.MetadataRepositoryElement_RepositoryLoadError, url)); + handleException(e, NLS.bind(ProvUIMessages.MetadataRepositoryElement_RepositoryLoadError, location)); } return repo; } @@ -108,8 +108,8 @@ public class ArtifactRepositoryElement extends ProvElement implements IDeferredW /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.ui.model.RepositoryElement#getURL() */ - public URL getLocation() { - return url; + public URI getLocation() { + return location; } /* @@ -118,7 +118,7 @@ public class ArtifactRepositoryElement extends ProvElement implements IDeferredW */ public String getName() { try { - String name = ProvisioningUtil.getArtifactRepositoryProperty(url, IRepository.PROP_NAME); + String name = ProvisioningUtil.getArtifactRepositoryProperty(location, IRepository.PROP_NAME); if (name == null) return ""; //$NON-NLS-1$ return name; @@ -133,7 +133,7 @@ public class ArtifactRepositoryElement extends ProvElement implements IDeferredW */ public String getDescription() { try { - String description = ProvisioningUtil.getArtifactRepositoryProperty(url, IRepository.PROP_DESCRIPTION); + String description = ProvisioningUtil.getArtifactRepositoryProperty(location, IRepository.PROP_DESCRIPTION); if (description == null) return ""; //$NON-NLS-1$ return description; diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ElementUtils.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ElementUtils.java index 93af5abfd..3e390d404 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ElementUtils.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ElementUtils.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.p2.ui.model; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; @@ -34,24 +34,24 @@ public class ElementUtils { public IStatus run(IProgressMonitor monitor) { ProvUI.startBatchOperation(); try { - URL[] currentlyEnabled = ProvisioningUtil.getMetadataRepositories(IRepositoryManager.REPOSITORIES_ALL); - URL[] currentlyDisabled = ProvisioningUtil.getMetadataRepositories(IRepositoryManager.REPOSITORIES_DISABLED); + URI[] currentlyEnabled = ProvisioningUtil.getMetadataRepositories(IRepositoryManager.REPOSITORIES_ALL); + URI[] currentlyDisabled = ProvisioningUtil.getMetadataRepositories(IRepositoryManager.REPOSITORIES_DISABLED); for (int i = 0; i < elements.length; i++) { - URL location = elements[i].getLocation(); + URI location = elements[i].getLocation(); if (elements[i].isEnabled()) { - if (containsURL(currentlyDisabled, location)) + if (containsURI(currentlyDisabled, location)) // It should be enabled and is not currently ProvisioningUtil.setColocatedRepositoryEnablement(location, true); - else if (!containsURL(currentlyEnabled, location)) { + else if (!containsURI(currentlyEnabled, location)) { // It is not known as enabled or disabled. Add it. ProvisioningUtil.addMetadataRepository(location); ProvisioningUtil.addArtifactRepository(location); } } else { - if (containsURL(currentlyEnabled, location)) + if (containsURI(currentlyEnabled, location)) // It should be disabled, and is currently enabled ProvisioningUtil.setColocatedRepositoryEnablement(location, false); - else if (!containsURL(currentlyDisabled, location)) { + else if (!containsURI(currentlyDisabled, location)) { // It is not known as enabled or disabled. Add it and then disable it. ProvisioningUtil.addMetadataRepository(location); ProvisioningUtil.addArtifactRepository(location); @@ -70,9 +70,9 @@ public class ElementUtils { job.schedule(); } - static boolean containsURL(URL[] locations, URL url) { + static boolean containsURI(URI[] locations, URI url) { for (int i = 0; i < locations.length; i++) - if (locations[i].toExternalForm().equals(url.toExternalForm())) + if (locations[i].equals(url)) return true; return false; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/MetadataRepositoryElement.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/MetadataRepositoryElement.java index 9911ee073..db173c296 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/MetadataRepositoryElement.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/MetadataRepositoryElement.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.model; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -38,17 +38,17 @@ import org.eclipse.ui.statushandlers.StatusManager; */ public class MetadataRepositoryElement extends RemoteQueriedElement implements IRepositoryElement { - URL url; + URI location; boolean isEnabled; boolean alreadyReportedNotFound = false; - public MetadataRepositoryElement(Object parent, URL url) { - this(parent, url, true); + public MetadataRepositoryElement(Object parent, URI location) { + this(parent, location, true); } - public MetadataRepositoryElement(Object parent, URL url, boolean isEnabled) { + public MetadataRepositoryElement(Object parent, URI location, boolean isEnabled) { super(parent); - this.url = url; + this.location = location; this.isEnabled = isEnabled; } @@ -73,7 +73,7 @@ public class MetadataRepositoryElement extends RemoteQueriedElement implements I if (name != null && name.length() > 0) { return name; } - return getLocation().toExternalForm(); + return getLocation().toString(); } /* @@ -94,7 +94,7 @@ public class MetadataRepositoryElement extends RemoteQueriedElement implements I private IMetadataRepository getMetadataRepository(IProgressMonitor monitor) { if (queryable == null) try { - queryable = ProvisioningUtil.loadMetadataRepository(url, monitor); + queryable = ProvisioningUtil.loadMetadataRepository(location, monitor); } catch (ProvisionException e) { // If repository could not be found, report to the user, but only once. // If the user refreshes the repositories, new elements will be created and @@ -103,12 +103,12 @@ public class MetadataRepositoryElement extends RemoteQueriedElement implements I if (!alreadyReportedNotFound) { // report the status, not the exception, to the user because we // do not want to show them stack trace and exception detail. - ProvUI.reportNotFoundStatus(url, e.getStatus(), StatusManager.SHOW); + ProvUI.reportNotFoundStatus(location, e.getStatus(), StatusManager.SHOW); alreadyReportedNotFound = true; } } else // handle other exceptions the normal way - handleException(e, NLS.bind(ProvUIMessages.MetadataRepositoryElement_RepositoryLoadError, url)); + handleException(e, NLS.bind(ProvUIMessages.MetadataRepositoryElement_RepositoryLoadError, location)); } return (IMetadataRepository) queryable; @@ -121,14 +121,14 @@ public class MetadataRepositoryElement extends RemoteQueriedElement implements I * @see org.eclipse.equinox.internal.provisional.p2.ui.query.QueriedElement#knowsQueryable() */ public boolean knowsQueryable() { - return url != null; + return location != null; } /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.ui.model.RepositoryElement#getURL() */ - public URL getLocation() { - return url; + public URI getLocation() { + return location; } /* @@ -137,7 +137,7 @@ public class MetadataRepositoryElement extends RemoteQueriedElement implements I */ public String getName() { try { - String name = ProvisioningUtil.getMetadataRepositoryProperty(url, IRepository.PROP_NAME); + String name = ProvisioningUtil.getMetadataRepositoryProperty(location, IRepository.PROP_NAME); if (name == null) return ""; //$NON-NLS-1$ return name; @@ -154,7 +154,7 @@ public class MetadataRepositoryElement extends RemoteQueriedElement implements I if (alreadyReportedNotFound) return ProvUIMessages.MetadataRepositoryElement_NotFound; try { - String description = ProvisioningUtil.getMetadataRepositoryProperty(url, IRepository.PROP_DESCRIPTION); + String description = ProvisioningUtil.getMetadataRepositoryProperty(location, IRepository.PROP_DESCRIPTION); if (description == null) return ""; //$NON-NLS-1$ return description; @@ -190,12 +190,12 @@ public class MetadataRepositoryElement extends RemoteQueriedElement implements I public boolean hasQueryable() { if (queryable != null) return true; - if (url == null) + if (location == null) return false; IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null || !(manager instanceof MetadataRepositoryManager)) return false; - IMetadataRepository repo = ((MetadataRepositoryManager) manager).getRepository(url); + IMetadataRepository repo = ((MetadataRepositoryManager) manager).getRepository(location); if (repo == null) return false; queryable = repo; diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/RollbackRepositoryElement.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/RollbackRepositoryElement.java index 5a891c1e0..d43cea39d 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/RollbackRepositoryElement.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/RollbackRepositoryElement.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.model; -import java.net.URL; +import java.net.URI; /** * Element wrapper class for a rollback repository. @@ -21,8 +21,8 @@ public class RollbackRepositoryElement extends MetadataRepositoryElement { String profileId; - public RollbackRepositoryElement(URL url, String profileId) { - super(null, url); + public RollbackRepositoryElement(URI location, String profileId) { + super(null, location); this.profileId = profileId; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/MetadataRepositoryElementCollector.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/MetadataRepositoryElementCollector.java index 7ad555c4a..71185903e 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/MetadataRepositoryElementCollector.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/MetadataRepositoryElementCollector.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.query; -import java.net.URL; +import java.net.URI; import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement; import org.eclipse.equinox.internal.p2.ui.model.QueriedElementCollector; import org.eclipse.equinox.internal.provisional.p2.query.IQueryable; @@ -36,8 +36,8 @@ public class MetadataRepositoryElementCollector extends QueriedElementCollector * or <code>false</code> to indicate the query should stop. */ public boolean accept(Object match) { - if (!(match instanceof URL)) + if (!(match instanceof URI)) return true; - return super.accept(new MetadataRepositoryElement(parent, (URL) match, ProvisioningUtil.getMetadataRepositoryEnablement((URL) match))); + return super.accept(new MetadataRepositoryElement(parent, (URI) match, ProvisioningUtil.getMetadataRepositoryEnablement((URI) match))); } } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/ProvUI.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/ProvUI.java index 9fab26fd6..41817a034 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/ProvUI.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/ProvUI.java @@ -12,7 +12,7 @@ package org.eclipse.equinox.internal.provisional.p2.ui; import java.lang.reflect.InvocationTargetException; -import java.net.URL; +import java.net.URI; import java.util.*; import java.util.List; import org.eclipse.core.commands.*; @@ -53,6 +53,10 @@ public class ProvUI { static ObjectUndoContext provisioningUndoContext; private static final int DEFAULT_COLUMN_WIDTH = 200; private static IUColumnConfig[] iuColumnConfig = new IUColumnConfig[] {new IUColumnConfig(ProvUIMessages.ProvUI_NameColumnTitle, IUColumnConfig.COLUMN_NAME, DEFAULT_COLUMN_WIDTH), new IUColumnConfig(ProvUIMessages.ProvUI_VersionColumnTitle, IUColumnConfig.COLUMN_VERSION, DEFAULT_COLUMN_WIDTH)}; + + /** + * List<URI> of repositories that have already been reported to the user as not found. + */ private static final List reposNotFound = Collections.synchronizedList(new ArrayList()); // These values rely on the command markup in org.eclipse.ui.ide that defines the update commands @@ -90,32 +94,24 @@ public class ProvUI { return status; } - public static void reportNotFoundStatus(URL url, IStatus status, int style) { - if (!hasNotFoundStatusBeenReported(url)) { - reposNotFound.add(url); + public static void reportNotFoundStatus(URI location, IStatus status, int style) { + if (!hasNotFoundStatusBeenReported(location)) { + reposNotFound.add(location); reportStatus(status, style); } } // This assumes that callers already checked whether it *should* // be reported so that we don't need to loop through the list - // when the caller just has done so in order to know whether - // to report. - public static void notFoundStatusReported(URL url) { - reposNotFound.add(url); + // when the caller just has done so in order to know whether to report. + public static void notFoundStatusReported(URI location) { + reposNotFound.add(location); } - // We don't simply use a set data structure to keep the URLs unique - // because using equals() for URLs is notoriously slow // We don't check for things like case variants or end slash variants // because we know that the repository managers already did this. - public static boolean hasNotFoundStatusBeenReported(URL url) { - synchronized (reposNotFound) { - for (int i = 0; i < reposNotFound.size(); i++) - if (reposNotFound.get(i) instanceof URL && ((URL) reposNotFound.get(i)).toExternalForm().equals(url.toExternalForm())) - return true; - } - return false; + public static boolean hasNotFoundStatusBeenReported(URI location) { + return reposNotFound.contains(location); } public static void clearRepositoriesNotFound() { diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/QueryableArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/QueryableArtifactRepositoryManager.java index 9273c620a..9dbd1b3db 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/QueryableArtifactRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/QueryableArtifactRepositoryManager.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; @@ -58,13 +58,13 @@ public class QueryableArtifactRepositoryManager implements IQueryable { ProvUI.reportStatus(new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, ProvUIMessages.ProvisioningUtil_NoRepositoryManager), StatusManager.SHOW | StatusManager.LOG); return result; } - URL[] repoURLs = manager.getKnownRepositories(flags); + URI[] repoLocations = manager.getKnownRepositories(flags); if (monitor == null) monitor = new NullProgressMonitor(); - monitor.beginTask(ProvUIMessages.QueryableArtifactRepositoryManager_RepositoryQueryProgress, repoURLs.length); - for (int i = 0; i < repoURLs.length; i++) { - if (query == null || query.isMatch(repoURLs[i])) - result.accept(repoURLs[i]); + monitor.beginTask(ProvUIMessages.QueryableArtifactRepositoryManager_RepositoryQueryProgress, repoLocations.length); + for (int i = 0; i < repoLocations.length; i++) { + if (query == null || query.isMatch(repoLocations[i])) + result.accept(repoLocations[i]); monitor.worked(1); } monitor.done(); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/QueryableMetadataRepositoryManager.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/QueryableMetadataRepositoryManager.java index e82b1d0ec..c30796057 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/QueryableMetadataRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/QueryableMetadataRepositoryManager.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -29,15 +29,23 @@ import org.eclipse.ui.statushandlers.StatusManager; /** * An object that adds queryable support to a metadata repository * manager. It can be constructed to iterate over a specific array - * of repositories named by URL, or filtered according to repository filter + * of repositories named by URI, or filtered according to repository filter * flags. When a query is provided, the object being queried is the loaded * repository, and collectors should be prepared to accept IInstallableUnits that - * meet the query criteria. Callers interested in only the resulting repository URL's - * should specify a null query, in which case the collector will be accepting the URL's. + * meet the query criteria. Callers interested in only the resulting repository URI + * should specify a null query, in which case the collector will be accepting the URI's. */ public class QueryableMetadataRepositoryManager implements IQueryable { + /** + * List<URI> of locations of repositories that were not found + */ private ArrayList notFound = new ArrayList(); + + /** + * Map<URI,IMetadataRepository> of loaded repositories. + */ private HashMap loaded = new HashMap(); + private MultiStatus accumulatedNotFound = null; private boolean includeDisabledRepos; private Policy policy; @@ -71,32 +79,32 @@ public class QueryableMetadataRepositoryManager implements IQueryable { ProvUI.reportStatus(new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, ProvUIMessages.ProvisioningUtil_NoRepositoryManager), StatusManager.SHOW | StatusManager.LOG); return result; } - List repoURLs = getRepoLocations(manager); + List repoLocations = getRepoLocations(manager); - SubMonitor sub = SubMonitor.convert(monitor, ProvUIMessages.QueryableMetadataRepositoryManager_RepositoryQueryProgress, repoURLs.size() * 2); + SubMonitor sub = SubMonitor.convert(monitor, ProvUIMessages.QueryableMetadataRepositoryManager_RepositoryQueryProgress, repoLocations.size() * 2); if (sub.isCanceled()) return result; - for (int i = 0; i < repoURLs.size(); i++) { + for (int i = 0; i < repoLocations.size(); i++) { if (sub.isCanceled()) return result; if (query == null) { - result.accept(repoURLs.get(i)); + result.accept(repoLocations.get(i)); sub.worked(2); } else { - URL url = (URL) repoURLs.get(i); + URI location = (URI) repoLocations.get(i); try { - Object alreadyLoaded = loaded.get(url.toExternalForm()); + Object alreadyLoaded = loaded.get(location); IMetadataRepository repo; if (alreadyLoaded == null) { - repo = manager.loadRepository(url, sub.newChild(1)); + repo = manager.loadRepository(location, sub.newChild(1)); } else repo = (IMetadataRepository) alreadyLoaded; repo.query(query, result, sub.newChild(1)); } catch (ProvisionException e) { if (e.getStatus().getCode() == ProvisionException.REPOSITORY_NOT_FOUND) - handleNotFound(e, url); + handleNotFound(e, location); else - ProvUI.handleException(e, NLS.bind(ProvUIMessages.ProvisioningUtil_LoadRepositoryFailure, repoURLs.get(i)), StatusManager.LOG); + ProvUI.handleException(e, NLS.bind(ProvUIMessages.ProvisioningUtil_LoadRepositoryFailure, repoLocations.get(i)), StatusManager.LOG); } reportAccumulatedStatus(); } @@ -114,32 +122,35 @@ public class QueryableMetadataRepositoryManager implements IQueryable { ProvUI.reportStatus(new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, ProvUIMessages.ProvisioningUtil_NoRepositoryManager), StatusManager.SHOW | StatusManager.LOG); return; } - List repoURLs = getRepoLocations(manager); - SubMonitor sub = SubMonitor.convert(monitor, ProvUIMessages.QueryableMetadataRepositoryManager_RepositoryQueryProgress, repoURLs.size()); + List repoLocations = getRepoLocations(manager); + SubMonitor sub = SubMonitor.convert(monitor, ProvUIMessages.QueryableMetadataRepositoryManager_RepositoryQueryProgress, repoLocations.size()); if (sub.isCanceled()) return; - for (int i = 0; i < repoURLs.size(); i++) { + for (int i = 0; i < repoLocations.size(); i++) { if (sub.isCanceled()) return; - URL url = (URL) repoURLs.get(i); + URI location = (URI) repoLocations.get(i); try { - Object repo = loaded.get(url.toExternalForm()); + Object repo = loaded.get(location); if (repo == null) { SubMonitor mon = sub.newChild(1); - mon.setTaskName(NLS.bind(ProvUIMessages.QueryableMetadataRepositoryManager_LoadRepositoryProgress, url.toExternalForm())); - loaded.put(url.toExternalForm(), manager.loadRepository(url, mon)); + mon.setTaskName(NLS.bind(ProvUIMessages.QueryableMetadataRepositoryManager_LoadRepositoryProgress, location.toString())); + loaded.put(location, manager.loadRepository(location, mon)); } } catch (ProvisionException e) { if (e.getStatus().getCode() == ProvisionException.REPOSITORY_NOT_FOUND) - handleNotFound(e, url); + handleNotFound(e, location); else - ProvUI.handleException(e, NLS.bind(ProvUIMessages.ProvisioningUtil_LoadRepositoryFailure, repoURLs.get(i)), StatusManager.LOG); + ProvUI.handleException(e, NLS.bind(ProvUIMessages.ProvisioningUtil_LoadRepositoryFailure, repoLocations.get(i)), StatusManager.LOG); } } reportAccumulatedStatus(); } + /** + * Returns a List<URI> of repository locations. + */ private List getRepoLocations(IMetadataRepositoryManager manager) { ArrayList locations = new ArrayList(); locations.addAll(Arrays.asList(manager.getKnownRepositories(policy.getQueryContext().getMetadataRepositoryFlags()))); @@ -149,18 +160,18 @@ public class QueryableMetadataRepositoryManager implements IQueryable { return locations; } - private void handleNotFound(ProvisionException e, URL missingRepo) { + private void handleNotFound(ProvisionException e, URI missingRepo) { // If we thought we had loaded it, get rid of the reference - loaded.remove(missingRepo.toExternalForm()); + loaded.remove(missingRepo); // If we've already reported a URL is not found, don't report again. - if (notFound.contains(missingRepo.toExternalForm())) + if (notFound.contains(missingRepo)) return; // If someone else reported a URL is not found, don't report again. if (ProvUI.hasNotFoundStatusBeenReported(missingRepo)) { - notFound.add(missingRepo.toExternalForm()); + notFound.add(missingRepo); return; } - notFound.add(missingRepo.toExternalForm()); + notFound.add(missingRepo); ProvUI.notFoundStatusReported(missingRepo); // Empty multi statuses have a severity OK. The platform status handler doesn't handle // this well. We correct this by recreating a status with error severity @@ -208,8 +219,8 @@ public class QueryableMetadataRepositoryManager implements IQueryable { MetadataRepositoryManager mgr = (MetadataRepositoryManager) manager; List repoURLs = getRepoLocations(mgr); for (int i = 0; i < repoURLs.size(); i++) { - if (repoURLs.get(i) instanceof URL) { - IMetadataRepository repo = mgr.getRepository((URL) repoURLs.get(i)); + if (repoURLs.get(i) instanceof URI) { + IMetadataRepository repo = mgr.getRepository((URI) repoURLs.get(i)); if (repo == null) return false; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/UpdateManagerCompatibility.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/UpdateManagerCompatibility.java index 059b0da8f..6f22b599a 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/UpdateManagerCompatibility.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/UpdateManagerCompatibility.java @@ -11,8 +11,8 @@ package org.eclipse.equinox.internal.provisional.p2.ui; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Vector; import javax.xml.parsers.*; @@ -96,10 +96,10 @@ public class UpdateManagerCompatibility { } private static void createSite(Node child, Vector bookmarks) { - URL url = null; + URI url = null; try { - url = new URL(getAttribute(child, "url")); //$NON-NLS-1$ - } catch (MalformedURLException e) { + url = new URI(getAttribute(child, "url")); //$NON-NLS-1$ + } catch (URISyntaxException e) { logFail(e); return; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/actions/ColocatedRepositoryAction.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/actions/ColocatedRepositoryAction.java index f14ebfbc4..7f9a53b61 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/actions/ColocatedRepositoryAction.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/actions/ColocatedRepositoryAction.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.provisional.p2.ui.actions; -import java.net.URL; +import java.net.URI; import java.util.ArrayList; import java.util.List; import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement; @@ -34,16 +34,16 @@ public abstract class ColocatedRepositoryAction extends ProvisioningAction { protected abstract ProvisioningOperation getOperation(); - protected URL[] getSelectedURLs(Object[] selectionArray) { + protected URI[] getSelectedLocations(Object[] selectionArray) { List urls = new ArrayList(); for (int i = 0; i < selectionArray.length; i++) { if (selectionArray[i] instanceof MetadataRepositoryElement) urls.add(((MetadataRepositoryElement) selectionArray[i]).getLocation()); } - return (URL[]) urls.toArray(new URL[urls.size()]); + return (URI[]) urls.toArray(new URI[urls.size()]); } protected void checkEnablement(Object[] selectionArray) { - setEnabled(getSelectedURLs(selectionArray).length > 0); + setEnabled(getSelectedLocations(selectionArray).length > 0); } } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/actions/RemoveColocatedRepositoryAction.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/actions/RemoveColocatedRepositoryAction.java index 4ede33b65..00e008ce6 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/actions/RemoveColocatedRepositoryAction.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/actions/RemoveColocatedRepositoryAction.java @@ -12,7 +12,6 @@ package org.eclipse.equinox.internal.provisional.p2.ui.actions; import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; - import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProvisioningOperation; import org.eclipse.equinox.internal.provisional.p2.ui.operations.RemoveColocatedRepositoryOperation; import org.eclipse.jface.viewers.ISelectionProvider; @@ -25,6 +24,6 @@ public class RemoveColocatedRepositoryAction extends ColocatedRepositoryAction { } protected ProvisioningOperation getOperation() { - return new RemoveColocatedRepositoryOperation(ProvUIMessages.RemoveColocatedRepositoryAction_OperationLabel, getSelectedURLs(getStructuredSelection().toArray())); + return new RemoveColocatedRepositoryOperation(ProvUIMessages.RemoveColocatedRepositoryAction_OperationLabel, getSelectedLocations(getStructuredSelection().toArray())); } } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AddRepositoryDialog.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AddRepositoryDialog.java index fb6b68c4c..9c4ddbdce 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AddRepositoryDialog.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AddRepositoryDialog.java @@ -10,21 +10,18 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.dialogs; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.URLValidator; - -import org.eclipse.equinox.internal.p2.ui.dialogs.TextURLDropAdapter; - -import org.eclipse.equinox.internal.p2.ui.DefaultMetadataURLValidator; - -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; -import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; +import org.eclipse.equinox.internal.p2.ui.*; +import org.eclipse.equinox.internal.p2.ui.DefaultMetadataURLValidator; +import org.eclipse.equinox.internal.p2.ui.dialogs.TextURLDropAdapter; import org.eclipse.equinox.internal.provisional.p2.ui.IProvHelpContextIds; import org.eclipse.equinox.internal.provisional.p2.ui.ProvisioningOperationRunner; import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProvisioningOperation; +import org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryLocationValidator; import org.eclipse.jface.dialogs.*; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; @@ -50,7 +47,7 @@ public abstract class AddRepositoryDialog extends StatusDialog { Button okButton; Text url; - URLValidator urlValidator; + RepositoryLocationValidator urlValidator; static final String[] ARCHIVE_EXTENSIONS = new String[] {"*.jar;*.zip"}; //$NON-NLS-1$ static String lastLocalLocation = null; static String lastArchiveLocation = null; @@ -115,7 +112,7 @@ public abstract class AddRepositoryDialog extends StatusDialog { String path = dialog.open(); if (path != null) { lastLocalLocation = path; - url.setText(URLValidator.makeFileURLString(path)); + url.setText(RepositoryLocationValidator.makeFileURLString(path)); validateRepositoryURL(false); } } @@ -132,7 +129,7 @@ public abstract class AddRepositoryDialog extends StatusDialog { String path = dialog.open(); if (path != null) { lastArchiveLocation = path; - url.setText(URLValidator.makeJarURLString(path)); + url.setText(RepositoryLocationValidator.makeJarURLString(path)); validateRepositoryURL(false); } } @@ -142,13 +139,13 @@ public abstract class AddRepositoryDialog extends StatusDialog { return comp; } - protected URLValidator createURLValidator() { + protected RepositoryLocationValidator createURLValidator() { DefaultMetadataURLValidator validator = new DefaultMetadataURLValidator(); validator.setKnownRepositoriesFlag(repoFlag); return validator; } - protected URLValidator getURLValidator() { + protected RepositoryLocationValidator getURLValidator() { return urlValidator; } @@ -160,30 +157,30 @@ public abstract class AddRepositoryDialog extends StatusDialog { } /** - * Get the URL as currently typed in by the user. Return null if there + * Get the repository location as currently typed in by the user. Return null if there * is a problem with the URL. * * @return the URL currently typed in by the user. */ - protected URL getUserURL() { - URL userURL; + protected URI getUserLocation() { + URI userLocation; try { - userURL = new URL(url.getText().trim()); - } catch (MalformedURLException e) { + userLocation = URIUtil.fromString(url.getText().trim()); + } catch (URISyntaxException e) { return null; } - return userURL; + return userLocation; } protected IStatus addRepository() { IStatus status = validateRepositoryURL(false); if (status.isOK()) { - ProvisioningOperationRunner.schedule(getOperation(getUserURL()), getShell(), StatusManager.SHOW | StatusManager.LOG); + ProvisioningOperationRunner.schedule(getOperation(getUserLocation()), getShell(), StatusManager.SHOW | StatusManager.LOG); } return status; } - protected abstract ProvisioningOperation getOperation(URL repoURL); + protected abstract ProvisioningOperation getOperation(URI repositoryLocation); /** * Validate the repository URL, returning a status that is appropriate @@ -195,16 +192,16 @@ public abstract class AddRepositoryDialog extends StatusDialog { if (url == null || url.isDisposed()) return Status.OK_STATUS; final IStatus[] status = new IStatus[1]; - status[0] = URLValidator.getInvalidURLStatus(url.getText().trim()); - final URL userURL = getUserURL(); + status[0] = RepositoryLocationValidator.getInvalidURLStatus(url.getText().trim()); + final URI userLocation = getUserLocation(); if (url.getText().length() == 0) - status[0] = new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, URLValidator.LOCAL_VALIDATION_ERROR, ProvUIMessages.RepositoryGroup_URLRequired, null); - else if (userURL == null) - status[0] = new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, URLValidator.LOCAL_VALIDATION_ERROR, ProvUIMessages.AddRepositoryDialog_InvalidURL, null); + status[0] = new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, RepositoryLocationValidator.LOCAL_VALIDATION_ERROR, ProvUIMessages.RepositoryGroup_URLRequired, null); + else if (userLocation == null) + status[0] = new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, RepositoryLocationValidator.LOCAL_VALIDATION_ERROR, ProvUIMessages.AddRepositoryDialog_InvalidURL, null); else { BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { public void run() { - status[0] = getURLValidator().validateRepositoryURL(userURL, contactRepositories, null); + status[0] = getURLValidator().validateRepositoryLocation(userLocation, contactRepositories, null); } }); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AvailableIUGroup.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AvailableIUGroup.java index 36e2fbb10..41a40ad2f 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AvailableIUGroup.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AvailableIUGroup.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.dialogs; -import java.net.URL; +import java.net.URI; import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.*; @@ -292,7 +292,7 @@ public class AvailableIUGroup extends StructuredIUGroup { * Refresh the available view completely. */ public void refresh() { - URL[] urls = provisioningContext.getMetadataRepositories(); + URI[] urls = provisioningContext.getMetadataRepositories(); ProvisioningOperation op; if (urls == null) op = new RefreshColocatedRepositoriesOperation(ProvUIMessages.AvailableIUGroup_RefreshOperationLabel, refreshRepoFlags); @@ -306,7 +306,7 @@ public class AvailableIUGroup extends StructuredIUGroup { /* * Make the repository with the specified location visible in the viewer. */ - void makeRepositoryVisible(final URL location) { + void makeRepositoryVisible(final URI location) { // First reset the input so that the new repo shows up display.asyncExec(new Runnable() { public void run() { @@ -324,7 +324,7 @@ public class AvailableIUGroup extends StructuredIUGroup { // We don't know if loading will be a fast or slow operation. // We do it in a job to be safe, and when it's done, we update // the UI. - Job job = new Job(NLS.bind(ProvUIMessages.AvailableIUGroup_LoadingRepository, location.toExternalForm())) { + Job job = new Job(NLS.bind(ProvUIMessages.AvailableIUGroup_LoadingRepository, location.toString())) { protected IStatus run(IProgressMonitor monitor) { try { ProvisioningUtil.loadMetadataRepository(location, null); @@ -353,8 +353,8 @@ public class AvailableIUGroup extends StructuredIUGroup { TreeItem[] items = tree.getItems(); for (int i = 0; i < items.length; i++) { if (items[i].getData() instanceof IRepositoryElement) { - URL url = ((IRepositoryElement) items[i].getData()).getLocation(); - if (url.toExternalForm().equals(location.toExternalForm())) { + URI url = ((IRepositoryElement) items[i].getData()).getLocation(); + if (url.equals(location)) { treeViewer.expandToLevel(items[i].getData(), AbstractTreeViewer.ALL_LEVELS); tree.select(items[i]); return; diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/RepositoryPropertyPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/RepositoryPropertyPage.java index f7611fb92..23f7a1a14 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/RepositoryPropertyPage.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/RepositoryPropertyPage.java @@ -10,10 +10,9 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.dialogs; -import org.eclipse.equinox.internal.provisional.p2.ui.model.IRepositoryElement; - import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; +import org.eclipse.equinox.internal.provisional.p2.ui.model.IRepositoryElement; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -81,7 +80,7 @@ public class RepositoryPropertyPage extends PropertyPage { // Shouldn't happen since we checked this before creating any controls if (repositoryElement == null) return; - url.setText(repositoryElement.getLocation().toExternalForm()); + url.setText(repositoryElement.getLocation().toString()); name.setText(repositoryElement.getName()); description.setText(repositoryElement.getDescription()); } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/model/IRepositoryElement.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/model/IRepositoryElement.java index 53c84440b..39f455c9b 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/model/IRepositoryElement.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/model/IRepositoryElement.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.model; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; @@ -21,7 +21,7 @@ import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; */ public interface IRepositoryElement { - public URL getLocation(); + public URI getLocation(); public String getName(); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddArtifactRepositoryOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddArtifactRepositoryOperation.java index 4b7e43a33..26b0f2c51 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddArtifactRepositoryOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddArtifactRepositoryOperation.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -23,21 +23,21 @@ public class AddArtifactRepositoryOperation extends RepositoryOperation { boolean added = false; - public AddArtifactRepositoryOperation(String label, URL url) { - super(label, new URL[] {url}); + public AddArtifactRepositoryOperation(String label, URI location) { + super(label, new URI[] {location}); } protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.addArtifactRepository(urls[i]); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.addArtifactRepository(locations[i]); } added = true; return okStatus(); } protected IStatus doBatchedUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.removeArtifactRepository(urls[i], monitor); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.removeArtifactRepository(locations[i], monitor); } // assume the best if no exception is thrown; added = false; diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddColocatedRepositoryOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddColocatedRepositoryOperation.java index 01f2161ef..b78984c77 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddColocatedRepositoryOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddColocatedRepositoryOperation.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -24,27 +24,27 @@ public class AddColocatedRepositoryOperation extends RepositoryOperation { boolean added = false; - public AddColocatedRepositoryOperation(String label, URL url) { - super(label, new URL[] {url}); + public AddColocatedRepositoryOperation(String label, URI url) { + super(label, new URI[] {url}); } - public AddColocatedRepositoryOperation(String label, URL[] urls) { + public AddColocatedRepositoryOperation(String label, URI[] urls) { super(label, urls); } protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.addMetadataRepository(urls[i]); - ProvisioningUtil.addArtifactRepository(urls[i]); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.addMetadataRepository(locations[i]); + ProvisioningUtil.addArtifactRepository(locations[i]); } added = true; return okStatus(); } protected IStatus doBatchedUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.removeMetadataRepository(urls[i], monitor); - ProvisioningUtil.removeArtifactRepository(urls[i], monitor); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.removeMetadataRepository(locations[i], monitor); + ProvisioningUtil.removeArtifactRepository(locations[i], monitor); } added = false; return okStatus(); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddMetadataRepositoryOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddMetadataRepositoryOperation.java index 400e117db..1ef06425d 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddMetadataRepositoryOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/AddMetadataRepositoryOperation.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -23,21 +23,21 @@ public class AddMetadataRepositoryOperation extends RepositoryOperation { boolean added = false; - public AddMetadataRepositoryOperation(String label, URL url) { - super(label, new URL[] {url}); + public AddMetadataRepositoryOperation(String label, URI location) { + super(label, new URI[] {location}); } protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.addMetadataRepository(urls[i]); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.addMetadataRepository(locations[i]); } added = true; return okStatus(); } protected IStatus doBatchedUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.removeMetadataRepository(urls[i], monitor); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.removeMetadataRepository(locations[i], monitor); } added = false; return okStatus(); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/ProvisioningUtil.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/ProvisioningUtil.java index 6e65adebb..377f5779d 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/ProvisioningUtil.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/ProvisioningUtil.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import java.util.ArrayList; import java.util.Map; import org.eclipse.core.runtime.*; @@ -36,49 +36,49 @@ import org.eclipse.osgi.util.NLS; */ public class ProvisioningUtil { - public static void addMetadataRepository(URL location) throws ProvisionException { + public static void addMetadataRepository(URI location) throws ProvisionException { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); manager.addRepository(location); } - public static String getMetadataRepositoryProperty(URL location, String key) throws ProvisionException { + public static String getMetadataRepositoryProperty(URI location, String key) throws ProvisionException { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); return manager.getRepositoryProperty(location, key); } - public static boolean getMetadataRepositoryEnablement(URL location) { + public static boolean getMetadataRepositoryEnablement(URI location) { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) return false; return manager.isEnabled(location); } - public static boolean getArtifactRepositoryEnablement(URL location) { + public static boolean getArtifactRepositoryEnablement(URI location) { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) return false; return manager.isEnabled(location); } - public static IMetadataRepository loadMetadataRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public static IMetadataRepository loadMetadataRepository(URI location, IProgressMonitor monitor) throws ProvisionException { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); return manager.loadRepository(location, monitor); } - public static IStatus validateMetadataRepositoryLocation(URL location, IProgressMonitor monitor) { + public static IStatus validateMetadataRepositoryLocation(URI location, IProgressMonitor monitor) { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) return new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, ProvUIMessages.ProvisioningUtil_NoRepositoryManager); return manager.validateRepositoryLocation(location, monitor); } - public static URL getRollbackRepositoryURL() throws ProvisionException { + public static URI getRollbackRepositoryURL() throws ProvisionException { IDirector director = getDirector(); IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) @@ -86,7 +86,7 @@ public class ProvisioningUtil { return director.getRollbackRepositoryLocation(); } - public static void removeMetadataRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public static void removeMetadataRepository(URI location, IProgressMonitor monitor) throws ProvisionException { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) { throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); @@ -94,7 +94,7 @@ public class ProvisioningUtil { manager.removeRepository(location); } - public static void addArtifactRepository(URL location) throws ProvisionException { + public static void addArtifactRepository(URI location) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) { throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); @@ -102,7 +102,7 @@ public class ProvisioningUtil { manager.addRepository(location); } - public static String getArtifactRepositoryProperty(URL location, String key) throws ProvisionException { + public static String getArtifactRepositoryProperty(URI location, String key) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) { throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); @@ -110,18 +110,18 @@ public class ProvisioningUtil { return manager.getRepositoryProperty(location, key); } - public static IArtifactRepository loadArtifactRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public static IArtifactRepository loadArtifactRepository(URI location, IProgressMonitor monitor) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); IArtifactRepository repo = manager.loadRepository(location, monitor); if (repo == null) { - throw new ProvisionException(NLS.bind(ProvUIMessages.ProvisioningUtil_LoadRepositoryFailure, location.toExternalForm())); + throw new ProvisionException(NLS.bind(ProvUIMessages.ProvisioningUtil_LoadRepositoryFailure, location)); } return repo; } - public static void removeArtifactRepository(URL location, IProgressMonitor monitor) throws ProvisionException { + public static void removeArtifactRepository(URI location, IProgressMonitor monitor) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) { throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); @@ -161,7 +161,7 @@ public class ProvisioningUtil { return profileRegistry.getProfile(id); } - public static URL[] getMetadataRepositories(int flags) throws ProvisionException { + public static URI[] getMetadataRepositories(int flags) throws ProvisionException { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) { throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); @@ -169,7 +169,7 @@ public class ProvisioningUtil { return manager.getKnownRepositories(flags); } - public static void refreshMetadataRepositories(URL[] urls, IProgressMonitor monitor) throws ProvisionException { + public static void refreshMetadataRepositories(URI[] urls, IProgressMonitor monitor) throws ProvisionException { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) { throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); @@ -184,7 +184,7 @@ public class ProvisioningUtil { } } - public static URL[] getArtifactRepositories(int flags) throws ProvisionException { + public static URI[] getArtifactRepositories(int flags) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) { throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); @@ -192,7 +192,7 @@ public class ProvisioningUtil { return manager.getKnownRepositories(flags); } - public static void refreshArtifactRepositories(URL[] urls, IProgressMonitor monitor) throws ProvisionException { + public static void refreshArtifactRepositories(URI[] urls, IProgressMonitor monitor) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) { throw new ProvisionException(ProvUIMessages.ProvisioningUtil_NoRepositoryManager); @@ -294,7 +294,7 @@ public class ProvisioningUtil { return director; } - public static void setColocatedRepositoryEnablement(URL location, boolean enabled) { + public static void setColocatedRepositoryEnablement(URI location, boolean enabled) { IMetadataRepositoryManager metaManager = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); if (metaManager != null) metaManager.setEnabled(location, enabled); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshArtifactRepositoriesOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshArtifactRepositoriesOperation.java index 761e810fb..684ad6d7b 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshArtifactRepositoriesOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshArtifactRepositoriesOperation.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; @@ -25,16 +25,16 @@ public class RefreshArtifactRepositoriesOperation extends RepositoryOperation { /** * @param label - * @param urls + * @param locations */ - public RefreshArtifactRepositoriesOperation(String label, URL[] urls) { - super(label, urls); + public RefreshArtifactRepositoriesOperation(String label, URI[] locations) { + super(label, locations); } public RefreshArtifactRepositoriesOperation(String label, int flags) { - super(label, new URL[0]); + super(label, new URI[0]); try { - this.urls = ProvisioningUtil.getArtifactRepositories(flags); + this.locations = ProvisioningUtil.getArtifactRepositories(flags); } catch (ProvisionException e) { ProvUI.handleException(e, null, StatusManager.LOG); } @@ -45,7 +45,7 @@ public class RefreshArtifactRepositoriesOperation extends RepositoryOperation { * @see org.eclipse.equinox.internal.provisional.p2.ui.operations.RepositoryOperation#doBatchedExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) */ protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - ProvisioningUtil.refreshArtifactRepositories(urls, monitor); + ProvisioningUtil.refreshArtifactRepositories(locations, monitor); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshColocatedRepositoriesOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshColocatedRepositoriesOperation.java index 09a56bee9..402bc4654 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshColocatedRepositoriesOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshColocatedRepositoriesOperation.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; @@ -24,19 +24,19 @@ public class RefreshColocatedRepositoriesOperation extends RepositoryOperation { /** * @param label - * @param urls + * @param locations */ - public RefreshColocatedRepositoriesOperation(String label, URL[] urls) { - super(label, urls); + public RefreshColocatedRepositoriesOperation(String label, URI[] locations) { + super(label, locations); } public RefreshColocatedRepositoriesOperation(String label, int flags) { - super(label, new URL[0]); + super(label, new URI[0]); try { // We use the list of metadata repositories since this is what drives // what the user sees, but we will refresh both the artifact and metadata // repositories. - this.urls = ProvisioningUtil.getMetadataRepositories(flags); + this.locations = ProvisioningUtil.getMetadataRepositories(flags); } catch (ProvisionException e) { ProvUI.handleException(e, null, StatusManager.LOG); } @@ -45,8 +45,8 @@ public class RefreshColocatedRepositoriesOperation extends RepositoryOperation { protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { // Clear the not found cache so that repos not found are reported again. ProvUI.clearRepositoriesNotFound(); - ProvisioningUtil.refreshMetadataRepositories(urls, monitor); - ProvisioningUtil.refreshArtifactRepositories(urls, monitor); + ProvisioningUtil.refreshMetadataRepositories(locations, monitor); + ProvisioningUtil.refreshArtifactRepositories(locations, monitor); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshMetadataRepositoriesOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshMetadataRepositoriesOperation.java index 15af09cf2..6de1cabd7 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshMetadataRepositoriesOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RefreshMetadataRepositoriesOperation.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; @@ -25,16 +25,16 @@ public class RefreshMetadataRepositoriesOperation extends RepositoryOperation { /** * @param label - * @param urls + * @param locations */ - public RefreshMetadataRepositoriesOperation(String label, URL[] urls) { - super(label, urls); + public RefreshMetadataRepositoriesOperation(String label, URI[] locations) { + super(label, locations); } public RefreshMetadataRepositoriesOperation(String label, int flags) { - super(label, new URL[0]); + super(label, new URI[0]); try { - this.urls = ProvisioningUtil.getMetadataRepositories(flags); + this.locations = ProvisioningUtil.getMetadataRepositories(flags); } catch (ProvisionException e) { ProvUI.handleException(e, null, StatusManager.LOG); } @@ -43,7 +43,7 @@ public class RefreshMetadataRepositoriesOperation extends RepositoryOperation { protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { // Clear the not found cache so that repos not found are reported again. ProvUI.clearRepositoriesNotFound(); - ProvisioningUtil.refreshMetadataRepositories(urls, monitor); + ProvisioningUtil.refreshMetadataRepositories(locations, monitor); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveArtifactRepositoryOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveArtifactRepositoryOperation.java index 3bfc30a16..758a0cd80 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveArtifactRepositoryOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveArtifactRepositoryOperation.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -23,13 +23,13 @@ public class RemoveArtifactRepositoryOperation extends RepositoryOperation { private boolean removed = false; - public RemoveArtifactRepositoryOperation(String label, URL[] repoURLs) { - super(label, repoURLs); + public RemoveArtifactRepositoryOperation(String label, URI[] repoLocations) { + super(label, repoLocations); } protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.removeArtifactRepository(urls[i], monitor); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.removeArtifactRepository(locations[i], monitor); } removed = true; return okStatus(); @@ -54,8 +54,8 @@ public class RemoveArtifactRepositoryOperation extends RepositoryOperation { } protected IStatus doBatchedUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.addArtifactRepository(urls[i]); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.addArtifactRepository(locations[i]); } removed = false; return okStatus(); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveColocatedRepositoryOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveColocatedRepositoryOperation.java index 120239df0..69ee76100 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveColocatedRepositoryOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveColocatedRepositoryOperation.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -23,14 +23,14 @@ public class RemoveColocatedRepositoryOperation extends RepositoryOperation { private boolean removed = false; - public RemoveColocatedRepositoryOperation(String label, URL[] repoURLs) { - super(label, repoURLs); + public RemoveColocatedRepositoryOperation(String label, URI[] repoLocations) { + super(label, repoLocations); } protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.removeMetadataRepository(urls[i], monitor); - ProvisioningUtil.removeArtifactRepository(urls[i], monitor); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.removeMetadataRepository(locations[i], monitor); + ProvisioningUtil.removeArtifactRepository(locations[i], monitor); } removed = true; return okStatus(); @@ -55,9 +55,9 @@ public class RemoveColocatedRepositoryOperation extends RepositoryOperation { } protected IStatus doBatchedUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.addMetadataRepository(urls[i]); - ProvisioningUtil.addArtifactRepository(urls[i]); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.addMetadataRepository(locations[i]); + ProvisioningUtil.addArtifactRepository(locations[i]); } removed = false; return okStatus(); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveMetadataRepositoryOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveMetadataRepositoryOperation.java index 70faa52ea..095625ac3 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveMetadataRepositoryOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RemoveMetadataRepositoryOperation.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -23,13 +23,13 @@ public class RemoveMetadataRepositoryOperation extends RepositoryOperation { private boolean removed = false; - public RemoveMetadataRepositoryOperation(String label, URL[] repoURLs) { - super(label, repoURLs); + public RemoveMetadataRepositoryOperation(String label, URI[] repoLocations) { + super(label, repoLocations); } protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.removeMetadataRepository(urls[i], monitor); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.removeMetadataRepository(locations[i], monitor); } removed = true; return okStatus(); @@ -54,8 +54,8 @@ public class RemoveMetadataRepositoryOperation extends RepositoryOperation { } protected IStatus doBatchedUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { - for (int i = 0; i < urls.length; i++) { - ProvisioningUtil.addMetadataRepository(urls[i]); + for (int i = 0; i < locations.length; i++) { + ProvisioningUtil.addMetadataRepository(locations[i]); } removed = false; return okStatus(); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RepositoryOperation.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RepositoryOperation.java index 2451a5fee..5a4be6670 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RepositoryOperation.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/operations/RepositoryOperation.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.operations; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; @@ -22,19 +22,19 @@ import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; */ abstract class RepositoryOperation extends UndoableProvisioningOperation { - URL[] urls; + URI[] locations; - RepositoryOperation(String label, URL[] urls) { + RepositoryOperation(String label, URI[] urls) { super(label); - this.urls = urls; + this.locations = urls; } public boolean canExecute() { - return urls != null; + return locations != null; } public boolean canUndo() { - return urls != null; + return locations != null; } /* @@ -43,7 +43,7 @@ abstract class RepositoryOperation extends UndoableProvisioningOperation { * @see org.eclipse.core.commands.operations.IAdvancedUndoableOperation#getAffectedObjects() */ public Object[] getAffectedObjects() { - return urls; + return locations; } /* @@ -56,7 +56,7 @@ abstract class RepositoryOperation extends UndoableProvisioningOperation { protected IStatus doExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { boolean batched = false; - if (urls != null && urls.length > 1) { + if (locations != null && locations.length > 1) { ProvUI.startBatchOperation(); batched = true; } @@ -68,7 +68,7 @@ abstract class RepositoryOperation extends UndoableProvisioningOperation { protected IStatus doUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException { boolean batched = false; - if (urls != null && urls.length > 1) { + if (locations != null && locations.length > 1) { ProvUI.startBatchOperation(); batched = true; } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/policy/URLValidator.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/policy/RepositoryLocationValidator.java index 139ff8b75..9f1fddced 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/policy/URLValidator.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/policy/RepositoryLocationValidator.java @@ -11,7 +11,7 @@ package org.eclipse.equinox.internal.provisional.p2.ui.policy; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; @@ -19,14 +19,14 @@ import org.eclipse.osgi.util.NLS; /** * - * URLValidator can be used to validate a repository URL. Validation may + * RepositoryLocationValidator can be used to validate a repository URL. Validation may * involve rules known by the validator itself or contact with a repository * manager. * * @since 3.4 * */ -public abstract class URLValidator { +public abstract class RepositoryLocationValidator { public static final String FILE_PROTOCOL = "file"; //$NON-NLS-1$ public static final String FILE_PROTOCOL_PREFIX = "file:"; //$NON-NLS-1$ public static final String JAR_PATH_PREFIX = "jar:";//$NON-NLS-1$ @@ -41,8 +41,8 @@ public abstract class URLValidator { return new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, LOCAL_VALIDATION_ERROR, NLS.bind(ProvUIMessages.URLValidator_UnrecognizedURL, urlText), null); } - public static boolean isFileURL(URL url) { - return url.getProtocol().equals(FILE_PROTOCOL); + public static boolean isFileURL(URI url) { + return url.getScheme().equals(FILE_PROTOCOL); } public static String makeJarURLString(String path) { @@ -62,5 +62,5 @@ public abstract class URLValidator { return result.toString(); } - public abstract IStatus validateRepositoryURL(URL url, boolean contactRepositories, IProgressMonitor monitor); + public abstract IStatus validateRepositoryLocation(URI url, boolean contactRepositories, IProgressMonitor monitor); } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/policy/RepositoryManipulator.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/policy/RepositoryManipulator.java index 66c05ef93..bf88ac6c6 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/policy/RepositoryManipulator.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/policy/RepositoryManipulator.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.policy; -import java.net.URL; +import java.net.URI; import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProvisioningOperation; import org.eclipse.swt.widgets.Shell; @@ -40,13 +40,13 @@ public abstract class RepositoryManipulator { /** * Return an array of URLs containing the repositories already known. */ - public abstract URL[] getKnownRepositories(); + public abstract URI[] getKnownRepositories(); /** * Return an operation that could be used to add the specified URL as * a repository. */ - public abstract ProvisioningOperation getAddOperation(URL repoURL); + public abstract ProvisioningOperation getAddOperation(URI repoLocation); /** * Return a String describing a possible add operation. This is used @@ -58,7 +58,7 @@ public abstract class RepositoryManipulator { * Return an operation that could be used to remove the specified URL as * a repositories. */ - public abstract ProvisioningOperation getRemoveOperation(URL[] repoURLs); + public abstract ProvisioningOperation getRemoveOperation(URI[] repoLocations); /** * Return a String describing a possible remove operation. This is used @@ -74,5 +74,5 @@ public abstract class RepositoryManipulator { * @return the validator to be used. */ - public abstract URLValidator getURLValidator(Shell shell); + public abstract RepositoryLocationValidator getRepositoryLocationValidator(Shell shell); } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/viewers/ProvElementComparer.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/viewers/ProvElementComparer.java index 4e7fa492b..3f4c11c96 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/viewers/ProvElementComparer.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/viewers/ProvElementComparer.java @@ -10,15 +10,13 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.ui.viewers; -import org.eclipse.equinox.internal.provisional.p2.ui.model.ProfileElement; - -import org.eclipse.equinox.internal.provisional.p2.ui.model.IRepositoryElement; - -import java.net.URL; -import org.eclipse.equinox.internal.p2.ui.model.*; +import java.net.URI; +import org.eclipse.equinox.internal.p2.ui.model.CategoryElement; import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; +import org.eclipse.equinox.internal.provisional.p2.ui.model.IRepositoryElement; +import org.eclipse.equinox.internal.provisional.p2.ui.model.ProfileElement; import org.eclipse.jface.viewers.IElementComparer; public class ProvElementComparer implements IElementComparer { @@ -37,10 +35,10 @@ public class ProvElementComparer implements IElementComparer { String p2 = getProfileId(b); if (p1 != null && p2 != null) return p1.equals(p2); - URL r1 = getRepositoryLocation(a); - URL r2 = getRepositoryLocation(b); + URI r1 = getRepositoryLocation(a); + URI r2 = getRepositoryLocation(b); if (r1 != null && r2 != null) - return r1.toExternalForm().equals(r2.toExternalForm()); + return r1.equals(r2); return a.equals(b); } @@ -53,9 +51,9 @@ public class ProvElementComparer implements IElementComparer { String profileId = getProfileId(element); if (profileId != null) return profileId.hashCode(); - URL url = getRepositoryLocation(element); - if (url != null) - return url.toExternalForm().hashCode(); + URI location = getRepositoryLocation(element); + if (location != null) + return location.hashCode(); return element.hashCode(); } @@ -72,7 +70,7 @@ public class ProvElementComparer implements IElementComparer { return profile.getProfileId(); } - private URL getRepositoryLocation(Object obj) { + private URI getRepositoryLocation(Object obj) { if (obj instanceof IRepositoryElement) return ((IRepositoryElement) obj).getLocation(); return null; diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/viewers/ProvElementLabelProvider.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/viewers/ProvElementLabelProvider.java index e9cba07e7..b9909ce3a 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/viewers/ProvElementLabelProvider.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/viewers/ProvElementLabelProvider.java @@ -11,10 +11,7 @@ package org.eclipse.equinox.internal.provisional.p2.ui.viewers; -import org.eclipse.equinox.internal.provisional.p2.ui.model.IRepositoryElement; - import org.eclipse.equinox.internal.p2.ui.model.IUElement; - import org.eclipse.equinox.internal.p2.ui.model.ProvElement; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; @@ -24,6 +21,7 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.*; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; import org.eclipse.equinox.internal.provisional.p2.ui.ProvUIImages; +import org.eclipse.equinox.internal.provisional.p2.ui.model.IRepositoryElement; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; @@ -56,14 +54,14 @@ public class ProvElementLabelProvider extends LabelProvider implements ITableLab if (name != null && name.length() > 0) { return name; } - return ((IRepository) obj).getLocation().toExternalForm(); + return ((IRepository) obj).getLocation().toString(); } if (obj instanceof IRepositoryElement) { String name = ((IRepositoryElement) obj).getName(); if (name != null && name.length() > 0) { return name; } - return ((IRepositoryElement) obj).getLocation().toExternalForm(); + return ((IRepositoryElement) obj).getLocation().toString(); } if (obj instanceof IArtifactKey) { IArtifactKey key = (IArtifactKey) obj; @@ -129,10 +127,10 @@ public class ProvElementLabelProvider extends LabelProvider implements ITableLab return iu.getVersion().toString(); } if (element instanceof IRepository) { - return ((IRepository) element).getLocation().toExternalForm(); + return ((IRepository) element).getLocation().toString(); } if (element instanceof IRepositoryElement) { - return ((IRepositoryElement) element).getLocation().toExternalForm(); + return ((IRepositoryElement) element).getLocation().toString(); } if (element instanceof IArtifactKey) { IArtifactKey key = (IArtifactKey) element; diff --git a/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/p2/updatechecker/UpdateChecker.java b/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/p2/updatechecker/UpdateChecker.java index 761126214..4aac49489 100644 --- a/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/p2/updatechecker/UpdateChecker.java +++ b/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/p2/updatechecker/UpdateChecker.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.updatechecker; -import java.net.URL; +import java.net.URI; import java.text.SimpleDateFormat; import java.util.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -134,9 +134,9 @@ public class UpdateChecker implements IUpdateChecker { /** * Returns the list of metadata repositories that are currently available. */ - private URL[] getAvailableRepositories() { + private URI[] getAvailableRepositories() { IMetadataRepositoryManager repoMgr = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName()); - URL[] repositories = repoMgr.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL); + URI[] repositories = repoMgr.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL); ArrayList available = new ArrayList(); for (int i = 0; i < repositories.length; i++) { try { @@ -146,7 +146,7 @@ public class UpdateChecker implements IUpdateChecker { //ignore unavailable repository } } - return (URL[]) available.toArray(new URL[available.size()]); + return (URI[]) available.toArray(new URI[available.size()]); } void log(String string, Throwable e) { diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DefaultSiteParser.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DefaultSiteParser.java index dac965cdb..268e7ffe1 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DefaultSiteParser.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DefaultSiteParser.java @@ -677,7 +677,7 @@ public class DefaultSiteParser extends DefaultHandler { if (!siteURL.endsWith("/") && !siteURL.endsWith(File.separator)) { //$NON-NLS-1$ siteURL += "/"; //$NON-NLS-1$ } - site.setLocationURLString(siteURL); + site.setLocationURIString(siteURL); } // provide default description URL @@ -702,7 +702,7 @@ public class DefaultSiteParser extends DefaultHandler { //Since we are parsing the site at p2 generation time and the //mirrors may change, there is no point doing the mirror expansion now - site.setMirrorsURLString(mirrorsURL); + site.setMirrorsURIString(mirrorsURL); } String pack200 = attributes.getValue("pack200"); //$NON-NLS-1$ @@ -712,7 +712,7 @@ public class DefaultSiteParser extends DefaultHandler { String digestURL = attributes.getValue("digestURL"); //$NON-NLS-1$ if (digestURL != null) - site.setDigestURLString(digestURL); + site.setDigestURIString(digestURL); // TODO: Digest locales // if ((attributes.getValue("availableLocales") != null) && (!attributes.getValue("availableLocales").trim().equals(""))) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/ECFTransport.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/ECFTransport.java index 4ba2a6639..ea7d4b170 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/ECFTransport.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/ECFTransport.java @@ -111,8 +111,8 @@ public class ECFTransport { * @return A <code>long</code> representing the date. Returns <code>0</code> if the file is not found or an error occurred. * @exception OperationCanceledException if the request was canceled. */ - public long getLastModified(URL location) throws ProvisionException { - String locationString = location.toExternalForm(); + public long getLastModified(URI location) throws ProvisionException { + String locationString = location.toString(); try { IConnectContext context = getConnectionContext(locationString, false); for (int i = 0; i < LOGIN_RETRIES; i++) { diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java index 11e90f016..a25837683 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java @@ -11,7 +11,6 @@ package org.eclipse.equinox.internal.p2.updatesite; import java.io.File; -import java.net.MalformedURLException; import java.util.ArrayList; import org.eclipse.core.runtime.*; import org.eclipse.equinox.p2.publisher.*; @@ -41,7 +40,7 @@ public class LocalUpdateSiteAction implements IPublisherAction { public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) { IPublisherAction[] actions = createActions(); - MultiStatus finalStatus = new MultiStatus(LocalUpdateSiteAction.class.getName(), 0, NLS.bind(Messages.Error_Generation, source != null ? source : (updateSite != null ? updateSite.getLocation().toExternalForm() : "Unknown")), null); //$NON-NLS-1$ + MultiStatus finalStatus = new MultiStatus(LocalUpdateSiteAction.class.getName(), 0, NLS.bind(Messages.Error_Generation, source != null ? source : (updateSite != null ? updateSite.getLocation().toString() : "Unknown")), null); //$NON-NLS-1$ for (int i = 0; i < actions.length; i++) { if (monitor.isCanceled()) return Status.CANCEL_STATUS; @@ -65,14 +64,8 @@ public class LocalUpdateSiteAction implements IPublisherAction { private IPublisherAction createSiteXMLAction() { if (updateSite != null) return new SiteXMLAction(updateSite); - if (source != null) { - try { - return new SiteXMLAction(new File(source, "site.xml").toURL()); //$NON-NLS-1$ - } catch (MalformedURLException e) { - // never happens - return null; - } - } + if (source != null) + return new SiteXMLAction(new File(source, "site.xml").toURI()); //$NON-NLS-1$ return null; } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java index d0dd3a12c..62e35dc52 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java @@ -10,8 +10,8 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.updatesite; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import org.eclipse.core.runtime.*; import org.eclipse.equinox.p2.publisher.*; @@ -36,7 +36,7 @@ public class RemoteUpdateSiteAction implements IPublisherAction { public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) { IPublisherAction[] actions = createActions(); - MultiStatus finalStatus = new MultiStatus(this.getClass().getName(), 0, NLS.bind(Messages.Error_Generation, source != null ? source : (updateSite != null ? updateSite.getLocation().toExternalForm() : "Unknown")), null); //$NON-NLS-1$ + MultiStatus finalStatus = new MultiStatus(this.getClass().getName(), 0, NLS.bind(Messages.Error_Generation, source != null ? source : (updateSite != null ? updateSite.getLocation().toString() : "Unknown")), null); //$NON-NLS-1$ for (int i = 0; i < actions.length; i++) { if (monitor.isCanceled()) return Status.CANCEL_STATUS; @@ -59,8 +59,8 @@ public class RemoteUpdateSiteAction implements IPublisherAction { return new SiteXMLAction(updateSite); if (source != null) { try { - return new SiteXMLAction(new URL(source + "/site.xml")); //$NON-NLS-1$ - } catch (MalformedURLException e) { + return new SiteXMLAction(new URI(source + "/site.xml")); //$NON-NLS-1$ + } catch (URISyntaxException e) { // never happens return null; } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java index 1dba49b86..d0bd69475 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java @@ -10,8 +10,8 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.updatesite; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.equinox.p2.publisher.eclipse.URLEntry; @@ -32,13 +32,13 @@ public class SiteModel { * Map of String (feature id) -> SiteFeature */ private List features; - private URL locationURL; - private String locationURLString; - private String mirrorsURLString; + private URI locationURI; + private String locationURIString; + private String mirrorsURIString; private boolean supportsPack200; private String type; private URLEntry[] associateSites; - private String digestURLString; + private String digestURIString; private List messageKeys; private Map localizations; @@ -162,28 +162,28 @@ public class SiteModel { } /** - * Returns the resolved URL for the site. + * Returns the resolved URI for the site. * * @return url, or <code>null</code> */ - public URL getLocationURL() { - if (locationURL == null && locationURLString != null) { + public URI getLocationURI() { + if (locationURI == null && locationURIString != null) { try { - locationURL = new URL(locationURLString); - } catch (MalformedURLException e) { + locationURI = new URI(locationURIString); + } catch (URISyntaxException e) { //ignore and return null } } - return locationURL; + return locationURI; } /** - * Returns the unresolved URL string for the site. + * Returns the unresolved URI string for the site. * * @return url string, or <code>null</code> */ - public String getLocationURLString() { - return locationURLString; + public String getLocationURIString() { + return locationURIString; } /** @@ -197,12 +197,12 @@ public class SiteModel { } /** - * Returns the URL from which the list of mirrors of this site can be retrieved. + * Returns the URI from which the list of mirrors of this site can be retrieved. * * @since org.eclipse.equinox.p2.metadata.generator 1.0 */ - public String getMirrorsURL() { - return mirrorsURLString; + public String getMirrorsURI() { + return mirrorsURIString; } /** @@ -249,13 +249,13 @@ public class SiteModel { } /** - * Sets the unresolved URL for the site. + * Sets the unresolved URI for the site. * - * @param locationURLString url for the site (as a string) + * @param locationURIString url for the site (as a string) * @since 2.0 */ - public void setLocationURLString(String locationURLString) { - this.locationURLString = locationURLString; + public void setLocationURIString(String locationURIString) { + this.locationURIString = locationURIString; } /** @@ -273,11 +273,11 @@ public class SiteModel { * This method is complementary to setMirrorsiteEntryModels(), and only one of these * methods should be called. * - * @param mirrorsURL additional update site mirrors + * @param mirrorsURI additional update site mirrors * @since 3.1 */ - public void setMirrorsURLString(String mirrorsURL) { - this.mirrorsURLString = mirrorsURL; + public void setMirrorsURIString(String mirrorsURI) { + this.mirrorsURIString = mirrorsURI; } public void setSupportsPack200(boolean value) { @@ -304,11 +304,11 @@ public class SiteModel { this.associateSites = associateSites; } - public void setDigestURLString(String digestURLString) { - this.digestURLString = digestURLString; + public void setDigestURIString(String digestURIString) { + this.digestURIString = digestURIString; } - public String getDigestURLString() { - return digestURLString; + public String getDigestURIString() { + return digestURIString; } } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java index aaeb89366..5557cb300 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java @@ -11,11 +11,12 @@ package org.eclipse.equinox.internal.p2.updatesite; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; import org.eclipse.equinox.internal.provisional.p2.metadata.*; @@ -35,13 +36,12 @@ import org.osgi.framework.Version; */ public class SiteXMLAction extends AbstractPublisherAction { - private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ private UpdateSite updateSite; private SiteCategory defaultCategory; private HashSet defaultCategorySet; - private URL location; + private URI location; - public SiteXMLAction(URL location) { + public SiteXMLAction(URI location) { this.location = location; } @@ -127,7 +127,7 @@ public class SiteXMLAction extends AbstractPublisherAction { return mappings; //copy mirror information from update site to p2 repositories - String mirrors = site.getMirrorsURL(); + String mirrors = site.getMirrorsURI(); if (mirrors != null) { //remove site.xml file reference int index = mirrors.indexOf("site.xml"); //$NON-NLS-1$ @@ -145,19 +145,16 @@ public class SiteXMLAction extends AbstractPublisherAction { for (int i = 0; i < associatedSites.length; i++) generateSiteReference(associatedSites[i].getURL(), null, info.getMetadataRepository()); - if (PROTOCOL_FILE.equals(updateSite.getLocation().getProtocol())) { - File siteFile = new File(updateSite.getLocation().getFile()); - if (siteFile.exists()) { - File siteParent = siteFile.getParentFile(); - - List messageKeys = site.getMessageKeys(); - if (siteParent.isDirectory()) { - String[] keyStrings = (String[]) messageKeys.toArray(new String[messageKeys.size()]); - site.setLocalizations(LocalizationHelper.getDirPropertyLocalizations(siteParent, "site", null, keyStrings)); //$NON-NLS-1$ - } else if (siteFile.getName().endsWith(".jar")) { //$NON-NLS-1$ - String[] keyStrings = (String[]) messageKeys.toArray(new String[messageKeys.size()]); - site.setLocalizations(LocalizationHelper.getJarPropertyLocalizations(siteParent, "site", null, keyStrings)); //$NON-NLS-1$ - } + File siteFile = URIUtil.toFile(updateSite.getLocation()); + if (siteFile != null && siteFile.exists()) { + File siteParent = siteFile.getParentFile(); + List messageKeys = site.getMessageKeys(); + if (siteParent.isDirectory()) { + String[] keyStrings = (String[]) messageKeys.toArray(new String[messageKeys.size()]); + site.setLocalizations(LocalizationHelper.getDirPropertyLocalizations(siteParent, "site", null, keyStrings)); //$NON-NLS-1$ + } else if (siteFile.getName().endsWith(".jar")) { //$NON-NLS-1$ + String[] keyStrings = (String[]) messageKeys.toArray(new String[messageKeys.size()]); + site.setLocalizations(LocalizationHelper.getJarPropertyLocalizations(siteParent, "site", null, keyStrings)); //$NON-NLS-1$ } } @@ -184,10 +181,10 @@ public class SiteXMLAction extends AbstractPublisherAction { */ private void generateSiteReference(String location, String featureId, IMetadataRepository metadataRepo) { try { - URL associateLocation = new URL(location); + URI associateLocation = new URI(location); metadataRepo.addReference(associateLocation, IRepository.TYPE_METADATA, IRepository.ENABLED); metadataRepo.addReference(associateLocation, IRepository.TYPE_ARTIFACT, IRepository.ENABLED); - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { String message = "Invalid site reference: " + location; //$NON-NLS-1$ if (featureId != null) message = message + " in feature: " + featureId; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java index e8ce3a9bb..b16bed174 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java @@ -11,14 +11,13 @@ package org.eclipse.equinox.internal.p2.updatesite; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.HashMap; import java.util.Map; import java.util.zip.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.core.helpers.URLUtil; +import org.eclipse.equinox.internal.p2.core.helpers.URIUtil; import org.eclipse.equinox.internal.p2.publisher.eclipse.FeatureParser; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.p2.publisher.eclipse.*; @@ -36,69 +35,58 @@ public class UpdateSite { private static final String PLUGIN_DIR = "plugins/"; //$NON-NLS-1$ private static final String FEATURE_TEMP_FILE = "feature"; //$NON-NLS-1$ private static final String SITE_FILE = "site.xml"; //$NON-NLS-1$ - private static final String DIR_SEPARATOR = "/"; //$NON-NLS-1$ private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ private static final int RETRY_COUNT = 2; private static final String DOT_XML = ".xml"; //$NON-NLS-1$ private static final String SITE = "site"; //$NON-NLS-1$ private String checksum; - private URL location; + private URI location; private SiteModel site; /* * Some variables for caching. */ - // map of String (URL.toExternalForm()) to UpdateSite + // map of String (URI.toString()) to UpdateSite private static Map siteCache = new HashMap(); // map of String (featureID_featureVersion) to Feature private Map featureCache = new HashMap(); /* - * Return a new URL for the given file which is based from the specified root. + * Return a new URI for the given file which is based from the specified root. */ - public static URL getFileURL(URL root, String fileName) throws MalformedURLException { - String path = root.getPath(); - if (path.endsWith(fileName)) + public static URI getFileURI(URI root, String fileName) { + String segment = URIUtil.lastSegment(root); + if (segment != null && segment.endsWith(fileName)) return root; - - if (constainsUpdateSiteFileName(path)) - return new URL(root, fileName); - - if (path.endsWith(DIR_SEPARATOR)) - return new URL(root.toExternalForm() + fileName); - return new URL(root.toExternalForm() + DIR_SEPARATOR + fileName); + if (constainsUpdateSiteFileName(segment)) + return root.resolve(fileName); + return URIUtil.append(root, fileName); } /* - * Return a URL based on the given URL, which points to a site.xml file. + * Return a URI based on the given URI, which points to a site.xml file. */ - private static URL getSiteURL(URL url) throws MalformedURLException { - String path = url.getPath(); - if (constainsUpdateSiteFileName(path)) - return url; - - if (path.endsWith(DIR_SEPARATOR)) - return new URL(url.toExternalForm() + SITE_FILE); - return new URL(url.toExternalForm() + DIR_SEPARATOR + SITE_FILE); + private static URI getSiteURI(URI baseLocation) { + String segment = URIUtil.lastSegment(baseLocation); + if (constainsUpdateSiteFileName(segment)) + return baseLocation; + return URIUtil.append(baseLocation, SITE_FILE); } - private static boolean constainsUpdateSiteFileName(String path) { - if (path.endsWith(DOT_XML)) { - int lastSlash = path.lastIndexOf('/'); - String lastSegment = lastSlash == -1 ? path : path.substring(lastSlash + 1); - if (lastSegment.indexOf(SITE) != -1) - return true; - } - return false; + /** + * Be lenient about accepting any location with *site*.xml at the end. + */ + private static boolean constainsUpdateSiteFileName(String segment) { + return segment != null && segment.endsWith(DOT_XML) && segment.indexOf(SITE) != -1; } /* * Load and return an update site object from the given location. */ - public static synchronized UpdateSite load(URL location, IProgressMonitor monitor) throws ProvisionException { + public static synchronized UpdateSite load(URI location, IProgressMonitor monitor) throws ProvisionException { if (location == null) return null; - UpdateSite result = (UpdateSite) siteCache.get(location.toExternalForm()); + UpdateSite result = (UpdateSite) siteCache.get(location.toString()); if (result != null) return result; InputStream input = null; @@ -109,8 +97,8 @@ public class UpdateSite { input = new CheckedInputStream(new BufferedInputStream(new FileInputStream(siteFile)), checksum); SiteModel siteModel = siteParser.parse(input); String checksumString = Long.toString(checksum.getValue()); - result = new UpdateSite(siteModel, getSiteURL(location), checksumString); - siteCache.put(location.toExternalForm(), result); + result = new UpdateSite(siteModel, getSiteURI(location), checksumString); + siteCache.put(location.toString(), result); return result; } catch (SAXException e) { String msg = NLS.bind(Messages.ErrorReadingSite, location); @@ -125,7 +113,7 @@ public class UpdateSite { } catch (IOException e) { // ignore } - if (!PROTOCOL_FILE.equals(location.getProtocol())) + if (!PROTOCOL_FILE.equals(location.getScheme())) siteFile.delete(); } } @@ -133,15 +121,15 @@ public class UpdateSite { /** * Returns a local file containing the contents of the update site at the given location. */ - private static File loadSiteFile(URL location, IProgressMonitor monitor) throws ProvisionException { + private static File loadSiteFile(URI location, IProgressMonitor monitor) throws ProvisionException { Throwable failure; File siteFile = null; IStatus transferResult; boolean deleteSiteFile = false; try { - URL actualLocation = getSiteURL(location); - if (PROTOCOL_FILE.equals(actualLocation.getProtocol())) { - siteFile = new File(actualLocation.getPath()); + URI actualLocation = getSiteURI(location); + if (PROTOCOL_FILE.equals(actualLocation.getScheme())) { + siteFile = URIUtil.toFile(actualLocation); if (siteFile.exists()) transferResult = Status.OK_STATUS; else { @@ -153,7 +141,7 @@ public class UpdateSite { deleteSiteFile = true; siteFile = File.createTempFile("site", ".xml"); //$NON-NLS-1$//$NON-NLS-2$ OutputStream destination = new BufferedOutputStream(new FileOutputStream(siteFile)); - transferResult = getTransport().download(actualLocation.toExternalForm(), destination, monitor); + transferResult = getTransport().download(actualLocation.toString(), destination, monitor); } if (monitor.isCanceled()) throw new OperationCanceledException(); @@ -178,10 +166,10 @@ public class UpdateSite { * Parse the feature.xml specified by the given input stream and return the feature object. * In case of failure, the failure is logged and null is returned */ - private static Feature parseFeature(FeatureParser featureParser, URL featureURL, IProgressMonitor monitor) { + private static Feature parseFeature(FeatureParser featureParser, URI featureURI, IProgressMonitor monitor) { File featureFile = null; - if (PROTOCOL_FILE.equals(featureURL.getProtocol())) { - featureFile = new File(featureURL.getPath()); + if (PROTOCOL_FILE.equals(featureURI.getScheme())) { + featureFile = URIUtil.toFile(featureURI); return featureParser.parse(featureFile); } try { @@ -192,7 +180,7 @@ public class UpdateSite { if (monitor.isCanceled()) throw new OperationCanceledException(); OutputStream destination = new BufferedOutputStream(new FileOutputStream(featureFile)); - transferResult = getTransport().download(featureURL.toExternalForm(), destination, monitor); + transferResult = getTransport().download(featureURI.toString(), destination, monitor); if (transferResult.isOK()) break; } @@ -204,7 +192,7 @@ public class UpdateSite { } return featureParser.parse(featureFile); } catch (IOException e) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURL), e)); + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURI), e)); } finally { if (featureFile != null) featureFile.delete(); @@ -213,26 +201,21 @@ public class UpdateSite { } /* - * Throw an exception if the site pointed to by the given URL is not valid. + * Throw an exception if the site pointed to by the given URI is not valid. */ - public static void validate(URL url, IProgressMonitor monitor) throws ProvisionException { - try { - URL siteURL = getSiteURL(url); - long lastModified = getTransport().getLastModified(siteURL); - if (lastModified == 0) { - String msg = NLS.bind(Messages.ErrorReadingSite, url); - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, null)); - } - } catch (MalformedURLException e) { + public static void validate(URI url, IProgressMonitor monitor) throws ProvisionException { + URI siteURI = getSiteURI(url); + long lastModified = getTransport().getLastModified(siteURI); + if (lastModified == 0) { String msg = NLS.bind(Messages.ErrorReadingSite, url); - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, null)); } } /* * Constructor for the class. */ - private UpdateSite(SiteModel site, URL location, String checksum) { + private UpdateSite(SiteModel site, URI location, String checksum) { super(); this.site = site; this.location = location; @@ -240,15 +223,15 @@ public class UpdateSite { } /* - * Iterate over the archive entries in this site and return the matching URL string for + * Iterate over the archive entries in this site and return the matching URI string for * the given identifier, if there is one. */ - private URL getArchiveURL(URL base, String identifier) { + private URI getArchiveURI(URI base, String identifier) { URLEntry[] archives = site.getArchives(); for (int i = 0; archives != null && i < archives.length; i++) { URLEntry entry = archives[i]; if (identifier.equals(entry.getAnnotation())) - return internalGetURL(base, entry.getURL()); + return internalGetURI(base, entry.getURL()); } return null; } @@ -261,53 +244,49 @@ public class UpdateSite { } /* - * Return a URL which represents the location of the given feature. + * Return a URI which represents the location of the given feature. */ - public URL getSiteFeatureURL(SiteFeature siteFeature) { + public URI getSiteFeatureURI(SiteFeature siteFeature) { URL url = siteFeature.getURL(); - if (url != null) - return url; - - URL base = getBaseURL(); - String featureURLString = siteFeature.getURLString(); - return internalGetURL(base, featureURLString); + try { + if (url != null) + return URIUtil.toURI(url); + } catch (URISyntaxException e) { + //fall through and resolve the URI ourselves + } + URI base = getBaseURI(); + String featureURIString = siteFeature.getURLString(); + return internalGetURI(base, featureURIString); } /* - * Return a URL which represents the location of the given feature. + * Return a URI which represents the location of the given feature. */ - public URL getFeatureURL(String id, String version) { + public URI getFeatureURI(String id, String version) { SiteFeature[] entries = site.getFeatures(); for (int i = 0; i < entries.length; i++) { if (id.equals(entries[i].getFeatureIdentifier()) && version.equals(entries[i].getFeatureVersion())) { - return getSiteFeatureURL(entries[i]); + return getSiteFeatureURI(entries[i]); } } - URL base = getBaseURL(); - URL url = getArchiveURL(base, FEATURE_DIR + id + VERSION_SEPARATOR + version + JAR_EXTENSION); + URI base = getBaseURI(); + URI url = getArchiveURI(base, FEATURE_DIR + id + VERSION_SEPARATOR + version + JAR_EXTENSION); if (url != null) return url; - - // fall through to default URL - try { - return getFileURL(base, FEATURE_DIR + id + VERSION_SEPARATOR + version + JAR_EXTENSION); - } catch (MalformedURLException e) { - // shouldn't happen - } - return null; + return getFileURI(base, FEATURE_DIR + id + VERSION_SEPARATOR + version + JAR_EXTENSION); } /* * Return the location of this site. */ - public URL getLocation() { + public URI getLocation() { return location; } - public String getMirrorsURL() { + public String getMirrorsURI() { //copy mirror information from update site to p2 repositories - String mirrors = site.getMirrorsURL(); + String mirrors = site.getMirrorsURI(); if (mirrors == null) return null; //remove site.xml file reference @@ -318,29 +297,24 @@ public class UpdateSite { } /* - * Return a URL which represents the location of the given plug-in. + * Return a URI which represents the location of the given plug-in. */ - public URL getPluginURL(FeatureEntry plugin) { - URL base = getBaseURL(); + public URI getPluginURI(FeatureEntry plugin) { + URI base = getBaseURI(); String path = PLUGIN_DIR + plugin.getId() + VERSION_SEPARATOR + plugin.getVersion() + JAR_EXTENSION; - URL url = getArchiveURL(base, path); + URI url = getArchiveURI(base, path); if (url != null) return url; - try { - return getFileURL(base, path); - } catch (MalformedURLException e) { - // shouldn't happen - } - return null; + return getFileURI(base, path); } - private URL getBaseURL() { - URL base = null; - String siteURLString = site.getLocationURLString(); - if (siteURLString != null) { - if (!siteURLString.endsWith("/")) //$NON-NLS-1$ - siteURLString += "/"; //$NON-NLS-1$ - base = internalGetURL(location, siteURLString); + private URI getBaseURI() { + URI base = null; + String siteURIString = site.getLocationURIString(); + if (siteURIString != null) { + if (!siteURIString.endsWith("/")) //$NON-NLS-1$ + siteURIString += "/"; //$NON-NLS-1$ + base = internalGetURI(location, siteURIString); } if (base == null) base = location; @@ -359,19 +333,10 @@ public class UpdateSite { * then return null. If it is absolute, then create a new url and return it. If it is * relative, then make it relative to the given base url. */ - private URL internalGetURL(URL base, String trailing) { + private URI internalGetURI(URI base, String trailing) { if (trailing == null) return null; - try { - return new URL(trailing); - } catch (MalformedURLException e) { - try { - return new URL(base, trailing); - } catch (MalformedURLException e2) { - // shouldn't happen - } - } - return null; + return base.resolve(trailing); } /* @@ -392,16 +357,16 @@ public class UpdateSite { File digestFile = null; boolean local = false; try { - URL digestURL = getDigestURL(); - if (PROTOCOL_FILE.equals(digestURL.getProtocol())) { - digestFile = URLUtil.toFile(digestURL); + URI digestURI = getDigestURI(); + if (PROTOCOL_FILE.equals(digestURI.getScheme())) { + digestFile = URIUtil.toFile(digestURI); if (!digestFile.exists()) return null; local = true; } else { digestFile = File.createTempFile("digest", ".zip"); //$NON-NLS-1$ //$NON-NLS-2$ BufferedOutputStream destination = new BufferedOutputStream(new FileOutputStream(digestFile)); - IStatus result = getTransport().download(digestURL.toExternalForm(), destination, monitor); + IStatus result = getTransport().download(digestURI.toString(), destination, monitor); if (result.getSeverity() == IStatus.CANCEL || monitor.isCanceled()) throw new OperationCanceledException(); if (!result.isOK()) @@ -420,7 +385,7 @@ public class UpdateSite { } catch (FileNotFoundException fnfe) { // we do not track FNF exceptions as we will fall back to the // standard feature parsing from the site itself, see bug 225587. - } catch (MalformedURLException e) { + } catch (URISyntaxException e) { String msg = NLS.bind(Messages.InvalidRepositoryLocation, location); LogHelper.log(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_INVALID_LOCATION, msg, e)); } catch (IOException e) { @@ -432,16 +397,16 @@ public class UpdateSite { return null; } - private URL getDigestURL() throws MalformedURLException { - URL digestBase = location; - String digestURLString = site.getDigestURLString(); - if (digestURLString != null) { - if (!digestURLString.endsWith("/")) //$NON-NLS-1$ - digestURLString += "/"; //$NON-NLS-1$ - digestBase = internalGetURL(location, digestURLString); + private URI getDigestURI() throws URISyntaxException { + URI digestBase = location; + String digestURIString = site.getDigestURIString(); + if (digestURIString != null) { + if (!digestURIString.endsWith("/")) //$NON-NLS-1$ + digestURIString += "/"; //$NON-NLS-1$ + digestBase = internalGetURI(location, digestURIString); } - return getFileURL(digestBase, "digest.zip"); //$NON-NLS-1$ + return getFileURI(digestBase, "digest.zip"); //$NON-NLS-1$ } /* @@ -464,10 +429,10 @@ public class UpdateSite { if (tmpFeatureCache.containsKey(key)) continue; } - URL featureURL = getSiteFeatureURL(siteFeature); - Feature feature = parseFeature(featureParser, featureURL, monitor); + URI featureURI = getSiteFeatureURI(siteFeature); + Feature feature = parseFeature(featureParser, featureURI, null); if (feature == null) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURL))); + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURI))); } else { if (key == null) { siteFeature.setFeatureIdentifier(feature.getId()); @@ -497,10 +462,10 @@ public class UpdateSite { if (features.containsKey(key)) continue; - URL includedFeatureURL = getFeatureURL(entry.getId(), entry.getVersion()); - Feature includedFeature = parseFeature(featureParser, includedFeatureURL, monitor); + URI includedFeatureURI = getFeatureURI(entry.getId(), entry.getVersion()); + Feature includedFeature = parseFeature(featureParser, includedFeatureURI, monitor); if (includedFeature == null) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, includedFeatureURL))); + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, includedFeatureURI))); } else { features.put(key, includedFeature); loadIncludedFeatures(includedFeature, featureParser, features, monitor); diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java index 0f6dab954..98cea3663 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java @@ -11,7 +11,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.updatesite.artifact; -import java.net.URL; +import java.net.URI; import java.util.*; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.internal.p2.updatesite.UpdateSite; @@ -30,7 +30,7 @@ public class UpdateSiteArtifactRepositoryFactory implements IArtifactRepositoryF /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.IArtifactRepositoryFactory#create(java.net.URL, java.lang.String, java.lang.String, java.util.Map) */ - public IArtifactRepository create(URL location, String name, String type, Map properties) { + public IArtifactRepository create(URI location, String name, String type, Map properties) { return null; } @@ -42,14 +42,14 @@ public class UpdateSiteArtifactRepositoryFactory implements IArtifactRepositoryF /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.IArtifactRepositoryFactory#load(java.net.URL, org.eclipse.core.runtime.IProgressMonitor) */ - public IArtifactRepository load(URL location, IProgressMonitor monitor) throws ProvisionException { + public IArtifactRepository load(URI location, IProgressMonitor monitor) throws ProvisionException { IArtifactRepository repository = loadRepository(location, monitor); initializeRepository(repository, location, monitor); return repository; } - public IArtifactRepository loadRepository(URL location, IProgressMonitor monitor) throws ProvisionException { - URL localRepositoryURL = UpdateSiteMetadataRepositoryFactory.getLocalRepositoryLocation(location); + public IArtifactRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException { + URI localRepositoryURL = UpdateSiteMetadataRepositoryFactory.getLocalRepositoryLocation(location); SimpleArtifactRepositoryFactory factory = new SimpleArtifactRepositoryFactory(); try { IArtifactRepository repository = factory.load(localRepositoryURL, monitor); @@ -59,19 +59,19 @@ public class UpdateSiteArtifactRepositoryFactory implements IArtifactRepositoryF } catch (ProvisionException e) { //fall through and create a new repository } - String repositoryName = "update site: " + location.toExternalForm(); //$NON-NLS-1$ + String repositoryName = "update site: " + location; //$NON-NLS-1$ Properties props = new Properties(); props.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); return factory.create(localRepositoryURL, repositoryName, null, props); } - public void initializeRepository(IArtifactRepository repository, URL location, IProgressMonitor monitor) throws ProvisionException { + public void initializeRepository(IArtifactRepository repository, URI location, IProgressMonitor monitor) throws ProvisionException { UpdateSite updateSite = UpdateSite.load(location, monitor); String savedChecksum = (String) repository.getProperties().get(PROP_SITE_CHECKSUM); if (savedChecksum != null && savedChecksum.equals(updateSite.getChecksum())) return; - if (!location.getProtocol().equals(PROTOCOL_FILE)) + if (!location.getScheme().equals(PROTOCOL_FILE)) repository.setProperty(PROP_FORCE_THREADING, "true"); //$NON-NLS-1$ repository.setProperty(PROP_SITE_CHECKSUM, updateSite.getChecksum()); repository.removeAll(); @@ -85,8 +85,8 @@ public class UpdateSiteArtifactRepositoryFactory implements IArtifactRepositoryF Feature feature = features[i]; IArtifactKey featureKey = FeaturesAction.createFeatureArtifactKey(feature.getId(), feature.getVersion()); ArtifactDescriptor featureArtifactDescriptor = new ArtifactDescriptor(featureKey); - URL featureURL = updateSite.getFeatureURL(feature.getId(), feature.getVersion()); - featureArtifactDescriptor.setRepositoryProperty(PROP_ARTIFACT_REFERENCE, featureURL.toExternalForm()); + URI featureURL = updateSite.getFeatureURI(feature.getId(), feature.getVersion()); + featureArtifactDescriptor.setRepositoryProperty(PROP_ARTIFACT_REFERENCE, featureURL.toString()); allSiteArtifacts.add(featureArtifactDescriptor); FeatureEntry[] featureEntries = feature.getEntries(); @@ -95,8 +95,8 @@ public class UpdateSiteArtifactRepositoryFactory implements IArtifactRepositoryF if (entry.isPlugin() && !entry.isRequires()) { IArtifactKey key = PublisherHelper.createBundleArtifactKey(entry.getId(), entry.getVersion()); ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(key); - URL pluginURL = updateSite.getPluginURL(entry); - artifactDescriptor.setRepositoryProperty(PROP_ARTIFACT_REFERENCE, pluginURL.toExternalForm()); + URI pluginURL = updateSite.getPluginURI(entry); + artifactDescriptor.setRepositoryProperty(PROP_ARTIFACT_REFERENCE, pluginURL.toString()); allSiteArtifacts.add(artifactDescriptor); } } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java index fa26a439c..1f15faf77 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java @@ -13,8 +13,7 @@ package org.eclipse.equinox.internal.p2.updatesite.metadata; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.Map; import java.util.Properties; import org.eclipse.core.runtime.*; @@ -29,27 +28,21 @@ import org.eclipse.equinox.p2.publisher.*; public class UpdateSiteMetadataRepositoryFactory implements IMetadataRepositoryFactory { private static final String PROP_SITE_CHECKSUM = "site.checksum"; //$NON-NLS-1$ - public static URL getLocalRepositoryLocation(URL location) throws ProvisionException { - URL localRepositoryURL = null; - try { - String stateDirName = Integer.toString(location.toExternalForm().hashCode()); - File bundleData = Activator.getBundleContext().getDataFile(null); - File stateDir = new File(bundleData, stateDirName); - localRepositoryURL = stateDir.toURL(); - } catch (MalformedURLException e) { - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, Messages.ErrorCreatingRepository, e)); - } - return localRepositoryURL; + public static URI getLocalRepositoryLocation(URI location) throws ProvisionException { + String stateDirName = Integer.toString(location.hashCode()); + File bundleData = Activator.getBundleContext().getDataFile(null); + File stateDir = new File(bundleData, stateDirName); + return stateDir.toURI(); } /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory#create(java.net.URL, java.lang.String, java.lang.String, java.util.Map) */ - public IMetadataRepository create(URL location, String name, String type, Map properties) { + public IMetadataRepository create(URI location, String name, String type, Map properties) { return null; } - public IStatus validate(URL location, IProgressMonitor monitor) { + public IStatus validate(URI location, IProgressMonitor monitor) { try { UpdateSite.validate(location, monitor); } catch (ProvisionException e) { @@ -58,14 +51,14 @@ public class UpdateSiteMetadataRepositoryFactory implements IMetadataRepositoryF return Status.OK_STATUS; } - public IMetadataRepository load(URL location, IProgressMonitor monitor) throws ProvisionException { + public IMetadataRepository load(URI location, IProgressMonitor monitor) throws ProvisionException { IMetadataRepository repository = loadRepository(location, monitor); initializeRepository(repository, location, monitor); return repository; } - public IMetadataRepository loadRepository(URL location, IProgressMonitor monitor) throws ProvisionException { - URL localRepositoryURL = getLocalRepositoryLocation(location); + public IMetadataRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException { + URI localRepositoryURL = getLocalRepositoryLocation(location); SimpleMetadataRepositoryFactory factory = new SimpleMetadataRepositoryFactory(); try { IMetadataRepository repository = factory.load(localRepositoryURL, monitor); @@ -75,13 +68,13 @@ public class UpdateSiteMetadataRepositoryFactory implements IMetadataRepositoryF } catch (ProvisionException e) { //fall through and create a new repository } - String repositoryName = "update site: " + location.toExternalForm(); //$NON-NLS-1$ + String repositoryName = "update site: " + location; //$NON-NLS-1$ Properties props = new Properties(); props.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); return factory.create(localRepositoryURL, repositoryName, null, props); } - public void initializeRepository(IMetadataRepository repository, URL location, IProgressMonitor monitor) throws ProvisionException { + public void initializeRepository(IMetadataRepository repository, URI location, IProgressMonitor monitor) throws ProvisionException { UpdateSite updateSite = UpdateSite.load(location, monitor); String savedChecksum = (String) repository.getProperties().get(PROP_SITE_CHECKSUM); if (savedChecksum != null && savedChecksum.equals(updateSite.getChecksum())) |