diff options
author | Daniel Raap | 2020-02-04 12:21:41 +0000 |
---|---|---|
committer | Ed Merks | 2020-03-19 15:46:26 +0000 |
commit | 4153c80f717f7de5ae9f728552ab254f15c43d0c (patch) | |
tree | efb6397b472bafac1ed1a0483cabf15c9dfe4e56 | |
parent | 48018a294d30f89b5496085c2c6e493ba4c89700 (diff) | |
download | rt.equinox.p2-I20200322-1800.tar.gz rt.equinox.p2-I20200322-1800.tar.xz rt.equinox.p2-I20200322-1800.zip |
Bug 508348 - keeping UNC paths when converting URL to FileI20200322-1800I20200322-1150I20200322-0300I20200321-1800I20200321-0440I20200320-1800I20200319-1800
uses URIUtil as described in http://wiki.eclipse.org/Eclipse/UNC_Paths
Change-Id: Id20e96be707c4bfadaef3fe8058e1045ad5c52e7
Signed-off-by: Daniel Raap <raap@subshell.com>
11 files changed, 94 insertions, 15 deletions
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF index 548cb55b6..fbd1d84fd 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.frameworkadmin.equinox;singleton:=true -Bundle-Version: 1.1.300.qualifier +Bundle-Version: 1.1.400.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Import-Package: org.eclipse.equinox.frameworkadmin;version="[2.0.0,3.0.0)", diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/pom.xml b/bundles/org.eclipse.equinox.frameworkadmin.equinox/pom.xml index 890dcd1cc..70410637f 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/pom.xml +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/pom.xml @@ -9,6 +9,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.frameworkadmin.equinox</artifactId> - <version>1.1.300-SNAPSHOT</version> + <version>1.1.400-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java index 3cead4796..48e5e5d3d 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java @@ -364,7 +364,7 @@ public class EquinoxFwConfigFileParser { return null; } } - File sharedConfigurationFolder = new File(sharedConfigurationURL.getPath()); + File sharedConfigurationFolder = EquinoxManipulatorImpl.toFile(sharedConfigurationURL); if (!sharedConfigurationFolder.isDirectory()) { Log.log(LogService.LOG_WARNING, NLS.bind(Messages.log_shared_config_file_missing, sharedConfigurationFolder)); return null; diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java index 5f618055c..5b73611ae 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java @@ -212,7 +212,22 @@ public class EquinoxManipulatorImpl implements Manipulator { URL url = location.getURL(); if (!url.getProtocol().equals("file")) //$NON-NLS-1$ return null; - return new File(url.getFile()); + return toFile(url); + } + + static File toFile(URL url) { + try { + URI uri = URIUtil.toURI(url); + File file = URIUtil.toFile(uri); + if (file == null) { + // fall back to path of URL in catch block + throw new URISyntaxException(uri.toString(), "file URL does not represent a local file"); + } + return file; + } catch (URISyntaxException e) { + Log.log(LogService.LOG_WARNING, "URL is not a valid URI, using only path for file", e); //$NON-NLS-1$ + return new File(url.getFile()); + } } private File getRunningLauncherFile() { @@ -614,7 +629,7 @@ public class EquinoxManipulatorImpl implements Manipulator { done = true; } } - if (url == null || !new File(url.getFile()).isAbsolute()) + if (url == null || !toFile(url).isAbsolute()) return urlString; String rootString = rootURL.toExternalForm(); @@ -689,7 +704,7 @@ public class EquinoxManipulatorImpl implements Manipulator { done = true; } } - if (url == null || new File(url.getFile()).isAbsolute()) + if (url == null || toFile(url).isAbsolute()) return urlString; return urlString.substring(0, index - 5) + makeAbsolute(urlString.substring(index), rootURL.toExternalForm()); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.frameworkadmin.test/META-INF/MANIFEST.MF index f9fd89084..f9edb43dd 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.equinox.frameworkadmin.test -Bundle-Version: 1.2.400.qualifier +Bundle-Version: 1.2.500.qualifier Bundle-Vendor: %Bundle-Vendor Require-Bundle: org.eclipse.core.runtime, org.eclipse.equinox.frameworkadmin, diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/pom.xml b/bundles/org.eclipse.equinox.frameworkadmin.test/pom.xml index fbc1b295c..ab5c86199 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/pom.xml +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/pom.xml @@ -9,6 +9,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.frameworkadmin.test</artifactId> - <version>1.2.400-SNAPSHOT</version> + <version>1.2.500-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImplTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImplTest.java new file mode 100644 index 000000000..a2ab4c3d6 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImplTest.java @@ -0,0 +1,53 @@ +/******************************************************************************** + * Copyright (c) 2020, 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + ********************************************************************************/ +package org.eclipse.equinox.internal.frameworkadmin.equinox; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import org.junit.Test; + +public class EquinoxManipulatorImplTest { + + @Test + public void testToFile() throws MalformedURLException { + String filename = "test.txt"; + + String unixUrl = "file:/program files/eclipse/"; + String expectedUnixFolder = "/program files/eclipse"; + String expectedUnixFile = expectedUnixFolder + "/" + filename; + assertEquals(new File(expectedUnixFolder), EquinoxManipulatorImpl.toFile(new URL(unixUrl))); + assertEquals(new File(expectedUnixFile), EquinoxManipulatorImpl.toFile(new URL(unixUrl + filename))); + + String windowsUrl = "file:/C:/Program Files/eclipse/"; + String expectedWindowsFolder = "C:\\Program Files\\eclipse"; + String expectedWindowsFile = expectedWindowsFolder + "\\" + filename; + assertEquals(new File(expectedWindowsFolder), EquinoxManipulatorImpl.toFile(new URL(windowsUrl))); + assertEquals(new File(expectedWindowsFile), EquinoxManipulatorImpl.toFile(new URL(windowsUrl + filename))); + + String uncUrl = "file://server/share/folder/"; + String expectedUncFolder = "//server/share/folder"; + String expectedUncFile = expectedUncFolder + "/" + filename; + assertEquals(new File(expectedUncFolder), EquinoxManipulatorImpl.toFile(new URL(uncUrl))); + assertEquals(new File(expectedUncFile), EquinoxManipulatorImpl.toFile(new URL(uncUrl + filename))); + + String notFileUrl = "http://example.com/path/to/folder/"; + String expectedOtherFolder = "/path/to/folder"; + String expectedOtherFile = expectedOtherFolder + "/" + filename; + assertEquals(new File(expectedOtherFolder), EquinoxManipulatorImpl.toFile(new URL(notFileUrl))); + assertEquals(new File(expectedOtherFile), EquinoxManipulatorImpl.toFile(new URL(notFileUrl + filename))); + } + +} diff --git a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF index 04d037e2c..5bd54376a 100644 --- a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.p2.engine;singleton:=true -Bundle-Version: 2.6.600.qualifier +Bundle-Version: 2.6.700.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.engine.EngineActivator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.engine/pom.xml b/bundles/org.eclipse.equinox.p2.engine/pom.xml index de10bd23f..258a3a0eb 100644 --- a/bundles/org.eclipse.equinox.p2.engine/pom.xml +++ b/bundles/org.eclipse.equinox.p2.engine/pom.xml @@ -9,6 +9,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.p2.engine</artifactId> - <version>2.6.600-SNAPSHOT</version> + <version>2.6.700-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java index 19070cd35..ef16bf4f9 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java @@ -160,7 +160,11 @@ public class SimpleProfileRegistry implements IProfileRegistry, IAgentService { if (DebugHelper.DEBUG_PROFILE_REGISTRY) DebugHelper.debug(PROFILE_REGISTRY, "SimpleProfileRegistry.updateRoamingProfile"); //$NON-NLS-1$ Location installLocation = ServiceHelper.getService(EngineActivator.getContext(), Location.class, Location.INSTALL_FILTER); - File location = new File(installLocation.getURL().getPath()); + File location = URLUtil.toFile(installLocation.getURL()); + if (location == null) { + // fallback: use only path of the URL if the protocol is not 'file' + location = new File(installLocation.getURL().getPath()); + } boolean changed = false; if (!location.equals(new File(selfProfile.getProperty(IProfile.PROP_INSTALL_FOLDER)))) { selfProfile.setProperty(IProfile.PROP_INSTALL_FOLDER, location.getAbsolutePath()); 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 0ff870c37..cfe06fefe 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 @@ -20,8 +20,7 @@ import java.lang.ref.SoftReference; import java.net.*; 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.ServiceHelper; +import org.eclipse.equinox.internal.p2.core.helpers.*; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.engine.IProfile; @@ -98,7 +97,11 @@ public class SurrogateProfileHandler implements ISurrogateProfileHandler { private static void updateProperties(final IProfile sharedProfile, Profile userProfile) { Location installLocation = ServiceHelper.getService(EngineActivator.getContext(), Location.class, Location.INSTALL_FILTER); - File installFolder = new File(installLocation.getURL().getPath()); + File installFolder = URLUtil.toFile(installLocation.getURL()); + if (installFolder == null) { + // fallback: use only path of the URL if the protocol is not 'file' + installFolder = new File(installLocation.getURL().getPath()); + } if (Boolean.parseBoolean(sharedProfile.getProperty(IProfile.PROP_ROAMING))) { userProfile.setProperty(IProfile.PROP_INSTALL_FOLDER, installFolder.getAbsolutePath()); @@ -111,7 +114,11 @@ public class SurrogateProfileHandler implements ISurrogateProfileHandler { } Location configurationLocation = ServiceHelper.getService(EngineActivator.getContext(), Location.class, Location.CONFIGURATION_FILTER); - File configurationFolder = new File(configurationLocation.getURL().getPath()); + File configurationFolder = URLUtil.toFile(configurationLocation.getURL()); + if (configurationFolder == null) { + // fallback: use only path of the URL if the protocol is not 'file' + configurationFolder = new File(configurationLocation.getURL().getPath()); + } userProfile.setProperty(IProfile.PROP_CONFIGURATION_FOLDER, configurationFolder.getAbsolutePath()); // We need to check that the configuration folder is not a file system root. |