Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDJ Houghton2011-06-28 11:00:03 -0400
committerDJ Houghton2011-06-28 11:00:03 -0400
commit4f0afd3b3dc8ce9e8fc70411aca546e4465b5448 (patch)
treea47e4af13a8af8ca5f714afc10f553188d0221d8
parente5016c27d78dd980cb648d47c9dde7c05617e2a2 (diff)
downloadrt.equinox.p2-R3_4_maintenance.tar.gz
rt.equinox.p2-R3_4_maintenance.tar.xz
rt.equinox.p2-R3_4_maintenance.zip
Bug 342542 - [shared] Help->Software Updates does not work when eclipse is started from a Windows UNC shortcutR34x_v20110628R3_4_maintenance
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java7
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/URIUtil.java111
2 files changed, 115 insertions, 3 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java
index 4fe495fdf..c3674bddf 100644
--- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java
@@ -9,8 +9,7 @@
package org.eclipse.equinox.internal.p2.engine;
import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.*;
import java.util.Iterator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
@@ -129,10 +128,12 @@ public class SurrogateProfileHandler implements ISurrogateProfileHandler {
String installArea = EngineActivator.getContext().getProperty(OSGI_INSTALL_AREA);
try {
URL registryURL = new URL(installArea + P2_ENGINE_DIR + SimpleProfileRegistry.DEFAULT_STORAGE_DIR);
- File sharedRegistryDirectory = new File(registryURL.getPath());
+ File sharedRegistryDirectory = URIUtil.toFile(URIUtil.toURI(registryURL));
profileRegistry = new SimpleProfileRegistry(sharedRegistryDirectory, null, false);
} catch (MalformedURLException e) {
//this is not possible because we know the above URL is valid
+ } catch (URISyntaxException e) {
+ //this is not possible because we know the above URL is valid
}
}
return profileRegistry;
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/URIUtil.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/URIUtil.java
new file mode 100644
index 000000000..06f3ddfbd
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/URIUtil.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.engine;
+
+import java.io.File;
+import java.net.*;
+
+/**
+ * A utility class for manipulating URIs. This class works around some of the
+ * undesirable behavior of the {@link java.net.URI} class, and provides
+ * additional path manipulation methods that are not available on the URI class.
+ * <p>
+ * Note: Class copied (and trimmed) from org.eclipse.equinox.common (URIUtil 1.18)
+ * in order to fix https://bugs.eclipse.org/342542.
+ *
+ * @noinstantiate This class is not intended to be instantiated by clients.
+ */
+public final class URIUtil {
+
+ private static final String UNC_PREFIX = "//"; //$NON-NLS-1$
+ private static final String SCHEME_FILE = "file"; //$NON-NLS-1$
+
+ private URIUtil() {
+ // prevent instantiation
+ }
+
+ /**
+ * Ensures the given path string starts with exactly four leading slashes.
+ */
+ private static String ensureUNCPath(String path) {
+ int len = path.length();
+ StringBuffer result = new StringBuffer(len);
+ for (int i = 0; i < 4; i++) {
+ // if we have hit the first non-slash character, add another leading
+ // slash
+ if (i >= len || result.length() > 0 || path.charAt(i) != '/')
+ result.append('/');
+ }
+ result.append(path);
+ return result.toString();
+ }
+
+ /**
+ * Returns whether the given URI refers to a local file system URI.
+ *
+ * @param uri
+ * The URI to check
+ * @return <code>true</code> if the URI is a local file system location, and
+ * <code>false</code> otherwise
+ */
+ private static boolean isFileURI(URI uri) {
+ return SCHEME_FILE.equalsIgnoreCase(uri.getScheme());
+ }
+
+ /**
+ * 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) {
+ if (!isFileURI(uri))
+ return null;
+ // assume all illegal characters have been properly encoded, so use URI
+ // class to unencode
+ return new File(uri.getSchemeSpecificPart());
+ }
+
+ /**
+ * Returns the URL as a URI. This method will handle URLs that are not
+ * properly encoded (for example they contain unencoded space characters).
+ *
+ * @param url
+ * The URL to convert into a URI
+ * @return A URI representing the given URL
+ */
+ public static URI toURI(URL url) throws URISyntaxException {
+ // URL behaves differently across platforms so for file: URLs we parse
+ // from string form
+ if (SCHEME_FILE.equals(url.getProtocol())) {
+ String pathString = url.toExternalForm().substring(5);
+ // ensure there is a leading slash to handle common malformed URLs
+ // such as file:c:/tmp
+ if (pathString.indexOf('/') != 0)
+ pathString = '/' + pathString;
+ else if (pathString.startsWith(UNC_PREFIX) && !pathString.startsWith(UNC_PREFIX, 2)) {
+ // URL encodes UNC path with two slashes, but URI uses four (see
+ // bug 207103)
+ pathString = ensureUNCPath(pathString);
+ }
+ return new URI(SCHEME_FILE, null, pathString, null);
+ }
+ 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());
+ }
+ }
+} \ No newline at end of file

Back to the top