Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2015-02-24 14:12:27 +0000
committerThomas Watson2015-02-24 14:59:33 +0000
commitfdb29dbe08e2fda5681967bf5142edf632f595d0 (patch)
tree1fd9eef116aaf082c5ff1742a09d7483b2432143
parent65466443204693677bb7bbe41fdaa019993f0760 (diff)
downloadrt.equinox.framework-fdb29dbe08e2fda5681967bf5142edf632f595d0.tar.gz
rt.equinox.framework-fdb29dbe08e2fda5681967bf5142edf632f595d0.tar.xz
rt.equinox.framework-fdb29dbe08e2fda5681967bf5142edf632f595d0.zip
Bug 460637 - BundleFileWrapper does not wrap the invocation to
getResourceURL
-rw-r--r--bundles/org.eclipse.osgi.tests/.classpath1
-rw-r--r--bundles/org.eclipse.osgi.tests/build.properties5
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/wrapper/hooks/a/TestHookConfigurator.java69
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AllFrameworkHookTests.java4
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/BundleFileWrapperFactoryHookTests.java65
-rwxr-xr-xbundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapper.java9
7 files changed, 153 insertions, 3 deletions
diff --git a/bundles/org.eclipse.osgi.tests/.classpath b/bundles/org.eclipse.osgi.tests/.classpath
index 8769c8c32..8e39802d6 100644
--- a/bundles/org.eclipse.osgi.tests/.classpath
+++ b/bundles/org.eclipse.osgi.tests/.classpath
@@ -129,5 +129,6 @@
<classpathentry kind="src" output="bundle_tests/test.bug438904.global" path="bundles_src/test.bug438904.global"/>
<classpathentry kind="src" output="bundle_tests/test.system.nls" path="bundles_src/test.system.nls"/>
<classpathentry kind="src" output="bundle_tests/test.bug449484" path="bundles_src/test.bug449484"/>
+ <classpathentry kind="src" output="bundle_tests/wrapper.hooks.a" path="bundles_src/wrapper.hooks.a"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/bundles/org.eclipse.osgi.tests/build.properties b/bundles/org.eclipse.osgi.tests/build.properties
index 1aecd094c..d2699ba3d 100644
--- a/bundles/org.eclipse.osgi.tests/build.properties
+++ b/bundles/org.eclipse.osgi.tests/build.properties
@@ -262,6 +262,8 @@ source.bundle_tests/test.system.nls.jar = bundles_src/test.system.nls/
manifest.bundle_tests/test.system.nls.jar = META-INF/MANIFEST.MF
source.bundle_tests/test.bug449484.jar = bundles_src/test.bug449484/
manifest.bundle_tests/test.bug449484.jar = META-INF/MANIFEST.MF
+source.bundle_tests/wrapper.hooks.a.jar = bundles_src/wrapper.hooks.a/
+manifest.bundle_tests/wrapper.hooks.a.jar = META-INF/MANIFEST.MF
jars.compile.order = bundle_tests/ext.framework.b.jar,\
osgitests.jar,\
@@ -388,4 +390,5 @@ jars.compile.order = bundle_tests/ext.framework.b.jar,\
bundle_tests/test.bug438904.frag.jar,\
bundle_tests/test.bug438904.global.jar,\
bundle_tests/test.system.nls.jar,\
- bundle_tests/test.bug449484.jar
+ bundle_tests/test.bug449484.jar,\
+ bundle_tests/wrapper.hooks.a.jar
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..716424843
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: wrapper.hooks.a
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/wrapper/hooks/a/TestHookConfigurator.java b/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/wrapper/hooks/a/TestHookConfigurator.java
new file mode 100644
index 000000000..0ea6d109d
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/wrapper/hooks/a/TestHookConfigurator.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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 wrapper.hooks.a;
+
+import java.net.URL;
+import java.util.Collection;
+import org.eclipse.osgi.container.Module;
+import org.eclipse.osgi.internal.hookregistry.*;
+import org.eclipse.osgi.service.urlconversion.URLConverter;
+import org.eclipse.osgi.storage.BundleInfo.Generation;
+import org.eclipse.osgi.storage.bundlefile.BundleFile;
+import org.eclipse.osgi.storage.bundlefile.BundleFileWrapper;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class TestHookConfigurator implements HookConfigurator {
+ public void addHooks(HookRegistry hookRegistry) {
+ BundleFileWrapperFactoryHook noop = new BundleFileWrapperFactoryHook() {
+ @Override
+ public BundleFileWrapper wrapBundleFile(BundleFile bundleFile, Generation generation, boolean base) {
+ return new BundleFileWrapper(bundleFile) {
+ // Do nothing to test multiple wrappers
+ };
+ }
+ };
+ // add no-op before the getResourceURL override
+ hookRegistry.addBundleFileWrapperFactoryHook(noop);
+
+ hookRegistry.addBundleFileWrapperFactoryHook(new BundleFileWrapperFactoryHook() {
+
+ @Override
+ public BundleFileWrapper wrapBundleFile(BundleFile bundleFile, Generation generation, boolean base) {
+ return new BundleFileWrapper(bundleFile) {
+ @Override
+ public URL getResourceURL(String path, Module hostModule, int index) {
+ URL url = super.getResourceURL(path, hostModule, index);
+ if (url != null) {
+ try {
+ return converter(hostModule, url);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ private URL converter(Module module, URL url) throws Exception {
+ // This is just test code, don't get the URLConverter this way in real code
+ BundleContext systemContext = module.getContainer().getModule(0).getBundle().getBundleContext();
+ Collection<ServiceReference<URLConverter>> converters = systemContext.getServiceReferences(URLConverter.class, "(protocol=" + url.getProtocol() + ")");
+ return systemContext.getService(converters.iterator().next()).resolve(url);
+ }
+
+ };
+ }
+ });
+
+ // And add no-op after
+ hookRegistry.addBundleFileWrapperFactoryHook(noop);
+ }
+}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AllFrameworkHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AllFrameworkHookTests.java
index af7c1c05b..7f46fee67 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AllFrameworkHookTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AllFrameworkHookTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+ * Copyright (c) 2013, 2015 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
@@ -17,6 +17,8 @@ public class AllFrameworkHookTests {
public static Test suite() {
TestSuite suite = new TestSuite(AllFrameworkHookTests.class.getName());
suite.addTest(new TestSuite(StorageHookTests.class));
+ suite.addTest(new TestSuite(ClassLoaderHookTests.class));
+ suite.addTest(new TestSuite(BundleFileWrapperFactoryHookTests.class));
return suite;
}
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/BundleFileWrapperFactoryHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/BundleFileWrapperFactoryHookTests.java
new file mode 100644
index 000000000..4af7ed3d1
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/BundleFileWrapperFactoryHookTests.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.osgi.tests.hooks.framework;
+
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.osgi.internal.hookregistry.HookRegistry;
+import org.eclipse.osgi.tests.OSGiTestsActivator;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.launch.Framework;
+
+public class BundleFileWrapperFactoryHookTests extends AbstractFrameworkHookTests {
+ private static final String TEST_BUNDLE = "substitutes.a";
+ private static final String HOOK_CONFIGURATOR_BUNDLE = "wrapper.hooks.a";
+ private static final String HOOK_CONFIGURATOR_CLASS = "wrapper.hooks.a.TestHookConfigurator";
+
+ private Map<String, String> configuration;
+ private Framework framework;
+ private String location;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ String loc = bundleInstaller.getBundleLocation(HOOK_CONFIGURATOR_BUNDLE);
+ loc = loc.substring(loc.indexOf("file:"));
+ classLoader.addURL(new URL(loc));
+ location = bundleInstaller.getBundleLocation(TEST_BUNDLE);
+ File file = OSGiTestsActivator.getContext().getDataFile(getName());
+ configuration = new HashMap<String, String>();
+ configuration.put(Constants.FRAMEWORK_STORAGE, file.getAbsolutePath());
+ configuration.put(HookRegistry.PROP_HOOK_CONFIGURATORS_INCLUDE, HOOK_CONFIGURATOR_CLASS);
+ framework = createFramework(configuration);
+ }
+
+ protected void tearDown() throws Exception {
+ stopQuietly(framework);
+ super.tearDown();
+ }
+
+ private void initAndStartFramework() throws Exception {
+ initAndStart(framework);
+ }
+
+ private Bundle installBundle() throws Exception {
+ return framework.getBundleContext().installBundle(location);
+ }
+
+ public void testGetResourceURL() throws Exception {
+ initAndStartFramework();
+
+ Bundle b = installBundle();
+ URL url = b.getResource("data/resource1");
+ assertTrue("Wrong protocol used: " + url, "jar".equals(url.getProtocol()) || "file".equals(url.getProtocol()));
+ }
+}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapper.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapper.java
index 33f59380e..bf4a3a020 100755
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapper.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/BundleFileWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+ * Copyright (c) 2013, 2015 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
@@ -12,7 +12,9 @@ package org.eclipse.osgi.storage.bundlefile;
import java.io.File;
import java.io.IOException;
+import java.net.URL;
import java.util.Enumeration;
+import org.eclipse.osgi.container.Module;
import org.eclipse.osgi.internal.hookregistry.BundleFileWrapperFactoryHook;
import org.eclipse.osgi.storage.BundleInfo;
@@ -83,4 +85,9 @@ public class BundleFileWrapper extends BundleFile {
public boolean containsDir(String dir) {
return bundleFile.containsDir(dir);
}
+
+ @Override
+ public URL getResourceURL(String path, Module hostModule, int index) {
+ return bundleFile.getResourceURL(path, hostModule, index);
+ }
}

Back to the top