Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.osgi.tests')
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java18
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java31
2 files changed, 49 insertions, 0 deletions
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java b/bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java
index 61e86e9a0..0daec7d29 100644
--- a/bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/classloader.hooks.a/org/eclipse/osgi/tests/classloader/hooks/a/TestHookConfigurator.java
@@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.osgi.tests.classloader.hooks.a;
+import java.net.URL;
+import java.util.NoSuchElementException;
import org.eclipse.osgi.container.Module;
import org.eclipse.osgi.internal.hookregistry.ClassLoaderHook;
import org.eclipse.osgi.internal.hookregistry.HookConfigurator;
@@ -27,6 +29,8 @@ public class TestHookConfigurator implements HookConfigurator {
private static final String RECURSION_LOAD = "classloader.hooks.a.recursion.load";
private static final String RECURSION_LOAD_SUPPORTED = "classloader.hooks.a.recursion.load.supported";
private static final String FILTER_CLASS_PATHS = "classloader.hooks.a.filter.class.paths";
+ private static final String PREVENT_RESOURCE_LOAD_PRE = "classloader.hooks.a.fail.resource.load.pre";
+ private static final String PREVENT_RESOURCE_LOAD_POST = "classloader.hooks.a.fail.resource.load.post";
final ThreadLocal<Boolean> doingRecursionLoad = new ThreadLocal<Boolean>() {
protected Boolean initialValue() {
return false;
@@ -81,6 +85,20 @@ public class TestHookConfigurator implements HookConfigurator {
}
return super.getClassPathEntries(name, manager);
}
+
+ @Override
+ public void preFindLocalResource(String name, ClasspathManager manager) {
+ if (Boolean.getBoolean(PREVENT_RESOURCE_LOAD_PRE)) {
+ throw new NoSuchElementException();
+ }
+ }
+
+ @Override
+ public void postFindLocalResource(String name, URL resource, ClasspathManager manager) {
+ if (Boolean.getBoolean(PREVENT_RESOURCE_LOAD_POST)) {
+ throw new NoSuchElementException();
+ }
+ }
});
}
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java
index 131d77a03..3185a16c9 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java
@@ -37,6 +37,7 @@ import org.osgi.framework.wiring.FrameworkWiring;
public class ClassLoaderHookTests extends AbstractFrameworkHookTests {
private static final String TEST_BUNDLE = "substitutes.a";
private static final String TEST_CLASSNAME = "substitutes.x.Ax";
+ private static final String TEST_CLASSNAME_RESOURCE = "substitutes/x/Ax.class";
private static final String HOOK_CONFIGURATOR_BUNDLE = "classloader.hooks.a";
private static final String HOOK_CONFIGURATOR_CLASS = "org.eclipse.osgi.tests.classloader.hooks.a.TestHookConfigurator";
private static final String REJECT_PROP = "classloader.hooks.a.reject";
@@ -44,6 +45,8 @@ public class ClassLoaderHookTests extends AbstractFrameworkHookTests {
private static final String RECURSION_LOAD = "classloader.hooks.a.recursion.load";
private static final String RECURSION_LOAD_SUPPORTED = "classloader.hooks.a.recursion.load.supported";
private static final String FILTER_CLASS_PATHS = "classloader.hooks.a.filter.class.paths";
+ private static final String PREVENT_RESOURCE_LOAD_PRE = "classloader.hooks.a.fail.resource.load.pre";
+ private static final String PREVENT_RESOURCE_LOAD_POST = "classloader.hooks.a.fail.resource.load.post";
private Map<String, String> configuration;
private Framework framework;
@@ -56,6 +59,8 @@ public class ClassLoaderHookTests extends AbstractFrameworkHookTests {
setRecursionLoad(false);
setRecursionLoadSupported(false);
setFilterClassPaths(false);
+ setPreventResourceLoadPre(false);
+ setPreventResourceLoadPost(false);
String loc = bundleInstaller.getBundleLocation(HOOK_CONFIGURATOR_BUNDLE);
loc = loc.substring(loc.indexOf("file:"));
classLoader.addURL(new URL(loc));
@@ -100,6 +105,14 @@ public class ClassLoaderHookTests extends AbstractFrameworkHookTests {
System.setProperty(FILTER_CLASS_PATHS, Boolean.toString(value));
}
+ private void setPreventResourceLoadPre(boolean value) {
+ System.setProperty(PREVENT_RESOURCE_LOAD_PRE, Boolean.toString(value));
+ }
+
+ private void setPreventResourceLoadPost(boolean value) {
+ System.setProperty(PREVENT_RESOURCE_LOAD_POST, Boolean.toString(value));
+ }
+
public void testRejectTransformationFromWeavingHook() throws Exception {
setRejectTransformation(true);
initAndStartFramework();
@@ -193,4 +206,22 @@ public class ClassLoaderHookTests extends AbstractFrameworkHookTests {
// expected
}
}
+
+ public void testPreventResourceLoadFromClassLoadingHook() throws Exception {
+ setPreventResourceLoadPre(false);
+ setPreventResourceLoadPost(false);
+ initAndStartFramework();
+ Bundle b = installBundle();
+ URL resource = b.getResource(TEST_CLASSNAME_RESOURCE);
+ assertNotNull("Could not find resource.", resource);
+
+ setPreventResourceLoadPre(true);
+ resource = b.getResource(TEST_CLASSNAME_RESOURCE);
+ assertNull("Could find resource.", resource);
+
+ setPreventResourceLoadPre(false);
+ setPreventResourceLoadPost(true);
+ resource = b.getResource(TEST_CLASSNAME_RESOURCE);
+ assertNull("Could find resource.", resource);
+ }
}

Back to the top