diff options
author | Thomas Watson | 2018-06-12 16:13:07 +0000 |
---|---|---|
committer | Thomas Watson | 2018-06-13 19:21:39 +0000 |
commit | c4c90b1c75780b2262b80534035c593ba8dd8f0e (patch) | |
tree | 45ca08c459a1e25d2749ad1f1c0f194a9c6965b8 | |
parent | 2c660df89f34884d8fb27eebbaa12df68cc3f2e8 (diff) | |
download | rt.equinox.framework-I20180615-0300.tar.gz rt.equinox.framework-I20180615-0300.tar.xz rt.equinox.framework-I20180615-0300.zip |
Bug 533867 - Fix when installing locations with # or ?I20180615-0655I20180615-0300I20180614-2045I20180614-2000
Change-Id: I54e44d710c232ddbc96faac06a8b6123c670efce
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
4 files changed, 87 insertions, 38 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java index 3faadc65d..a424ececc 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java @@ -305,46 +305,90 @@ public class BundleInstallUpdateTests extends AbstractBundleTests { } } - public void testPercentLocation() throws BundleException, IOException { + public void testPercentLocation() { doTestSpecialChars('%', false); doTestSpecialChars('%', true); } - public void testSpaceLocation() throws BundleException, IOException { + public void testSpaceLocation() { doTestSpecialChars(' ', false); doTestSpecialChars(' ', true); } - private void doTestSpecialChars(char c, boolean encode) throws BundleException, IOException { + public void testPlusLocation() { + doTestSpecialChars('+', true); + doTestSpecialChars('+', false); + } + + public void testOctothorpLocation() { + doTestSpecialChars('#', true); + // # must be encoded for anything to pass + doTestSpecialChars('#', false, false, false); + } + + public void testQuestionMarkLocation() { + doTestSpecialChars('?', true); + // ? must only be encoded for non-reference installs + doTestSpecialChars('?', false, true, false); + + } + + private void doTestSpecialChars(char c, boolean encode) { + doTestSpecialChars(c, encode, true, true); + } + + private void doTestSpecialChars(char c, boolean encode, boolean refPass, boolean filePass) { File bundlesDirectory = OSGiTestsActivator.getContext().getDataFile("file_with_" + c + "_char"); bundlesDirectory.mkdirs(); - File testBundleJarFile = SystemBundleTests.createBundle(bundlesDirectory, getName() + 1, false, false); - @SuppressWarnings("deprecation") - String testBundleJarFileURL = encode ? testBundleJarFile.toURI().toString() : testBundleJarFile.toURL().toString(); - File testBundleDirFile = SystemBundleTests.createBundle(bundlesDirectory, getName() + 2, false, true); - @SuppressWarnings("deprecation") - String testBundleDirFileURL = encode ? testBundleDirFile.toURI().toString() : testBundleDirFile.toURL().toString(); + File testBundleJarFile = null; + String testBundleJarFileURL = null; + File testBundleDirFile = null; + String testBundleDirFileURL = null; + try { + testBundleJarFile = SystemBundleTests.createBundle(bundlesDirectory, getName() + 1, false, false); + testBundleJarFileURL = encode ? testBundleJarFile.toURI().toString() : testBundleJarFile.toURL().toString(); + testBundleDirFile = SystemBundleTests.createBundle(bundlesDirectory, getName() + 2, false, true); + testBundleDirFileURL = encode ? testBundleDirFile.toURI().toString() : testBundleDirFile.toURL().toString(); + } catch (IOException e) { + fail(e.getMessage()); + } + + String refToJarURL = "reference:" + testBundleJarFileURL; + // Test with reference stream to jar bundle + testInstallSpecialCharBundle(refToJarURL, true, refPass); // Test with reference URL to jar bundle - Bundle testBundleJarRef = getContext().installBundle("reference:" + testBundleJarFileURL); - testBundleJarRef.start(); - testBundleJarRef.uninstall(); + testInstallSpecialCharBundle(refToJarURL, false, refPass); // Test with reference URL to dir bundle - Bundle testBundleDirRef = getContext().installBundle("reference:" + testBundleDirFileURL); - testBundleDirRef.start(); - testBundleDirRef.uninstall(); + testInstallSpecialCharBundle("reference:" + testBundleDirFileURL, false, refPass); // Test with jar bundle - Bundle testBundleJar = getContext().installBundle(testBundleJarFileURL); - testBundleJar.start(); - testBundleJar.uninstall(); + testInstallSpecialCharBundle(testBundleJarFileURL, false, filePass); // Test with dir bundle - Bundle testBundleDir = getContext().installBundle(testBundleDirFileURL); - testBundleDir.start(); - testBundleDir.uninstall(); + testInstallSpecialCharBundle(testBundleDirFileURL, false, filePass); + } + + void testInstallSpecialCharBundle(String location, boolean openStream, boolean expectSuccess) { + try { + Bundle b; + if (openStream) { + b = getContext().installBundle(location, new URL(location).openStream()); + } else { + b = getContext().installBundle(location); + } + b.start(); + b.uninstall(); + if (!expectSuccess) { + fail("Should have failed for location: " + location); + } + } catch (Exception e) { + if (expectSuccess) { + fail("Should not have failed for location: " + location + " " + e.getMessage()); + } + } } public void testPercentCharBundleEntry() throws IOException, BundleException { diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java index 578581f19..6e097c601 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java @@ -1013,10 +1013,7 @@ public class Storage { File outFile = null; try { if (in instanceof ReferenceInputStream) { - URL reference = ((ReferenceInputStream) in).getReference(); - if (!"file".equals(reference.getProtocol())) //$NON-NLS-1$ - throw new BundleException(NLS.bind(Msg.ADAPTOR_URL_CREATE_EXCEPTION, reference)); - return new File(reference.getPath()); + return ((ReferenceInputStream) in).getReference(); } outFile = File.createTempFile(BUNDLE_FILE_NAME, ".tmp", childRoot); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceInputStream.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceInputStream.java index fdd95770b..ef2026e47 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceInputStream.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceInputStream.java @@ -11,18 +11,18 @@ package org.eclipse.osgi.storage.url.reference; +import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.URL; /** - * InputStream subclass which provides a reference (via URL) to the data + * InputStream subclass which provides a reference (via File) to the data * rather than allowing the input stream to be directly read. */ public class ReferenceInputStream extends InputStream { - protected URL reference; + private final File reference; - public ReferenceInputStream(URL reference) { + public ReferenceInputStream(File reference) { this.reference = reference; } @@ -32,7 +32,7 @@ public class ReferenceInputStream extends InputStream { throw new IOException(); } - public URL getReference() { + public File getReference() { return reference; } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java index c776c8b0b..b1819841d 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java @@ -11,11 +11,17 @@ package org.eclipse.osgi.storage.url.reference; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import org.eclipse.osgi.framework.util.FilePath; import org.eclipse.osgi.internal.location.LocationHelper; +import org.eclipse.osgi.internal.messages.Msg; +import org.eclipse.osgi.util.NLS; /** * URLConnection for the reference protocol. @@ -23,23 +29,25 @@ import org.eclipse.osgi.internal.location.LocationHelper; public class ReferenceURLConnection extends URLConnection { private final String installPath; - private URL reference; + private volatile File reference; protected ReferenceURLConnection(URL url, String installPath) { super(url); this.installPath = installPath; } - @SuppressWarnings("deprecation") public synchronized void connect() throws IOException { if (!connected) { // TODO assumes that reference URLs are always based on file: URLs. // There are not solid usecases to the contrary. Yet. - // Construct the ref URL carefully so as to preserve UNC paths etc. - String path = url.getPath().substring(5); + // Construct the ref File carefully so as to preserve UNC paths etc. + String path = url.getPath(); + if (!path.startsWith("file:")) { //$NON-NLS-1$ + throw new IOException(NLS.bind(Msg.ADAPTOR_URL_CREATE_EXCEPTION, path)); + } + path = url.getPath().substring(5); File file = new File(path); - URL ref; if (!file.isAbsolute()) { if (installPath != null) file = makeAbsolute(installPath, file); @@ -47,10 +55,10 @@ public class ReferenceURLConnection extends URLConnection { file = LocationHelper.decodePath(file); - ref = file.toURL(); checkRead(file); - reference = ref; + reference = file; + connected = true; } } |