Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2016-03-21 17:55:21 +0000
committerThomas Watson2016-03-21 17:55:53 +0000
commit7a81308ee3a0d5786d1b6b173310fe12c8c4cc24 (patch)
treeabcb759d5322c87ccfbfb71cd63886d564384068 /bundles
parent91137155f1734258aaeb27aea7c557dd95fd65de (diff)
downloadrt.equinox.framework-7a81308ee3a0d5786d1b6b173310fe12c8c4cc24.tar.gz
rt.equinox.framework-7a81308ee3a0d5786d1b6b173310fe12c8c4cc24.tar.xz
rt.equinox.framework-7a81308ee3a0d5786d1b6b173310fe12c8c4cc24.zip
Bug 489675 - ContextFinder.getResources() searches resources in
different order with getResource Change-Id: I39d2d32b03ce92bc2879ec88ad60d59591291867 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles')
-rwxr-xr-xbundles/org.eclipse.osgi.tests/META-INF/services/javax.print.PrintServiceLookup1
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java17
-rwxr-xr-x[-rw-r--r--]bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java0
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ContextFinder.java22
4 files changed, 30 insertions, 10 deletions
diff --git a/bundles/org.eclipse.osgi.tests/META-INF/services/javax.print.PrintServiceLookup b/bundles/org.eclipse.osgi.tests/META-INF/services/javax.print.PrintServiceLookup
new file mode 100755
index 000000000..425251c2f
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/META-INF/services/javax.print.PrintServiceLookup
@@ -0,0 +1 @@
+# just a test \ No newline at end of file
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java
index 1f623a1fe..b984c2c8b 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java
@@ -1666,6 +1666,23 @@ public class ClassLoadingBundleTests extends AbstractBundleTests {
global.loadClass("test.bug438904.frag.Test2");
}
+ public void testContextFinderGetResource() throws IOException, InvalidSyntaxException {
+ // get the context finder explicitly to test incase the thread context class loader has changed
+ ClassLoader contextFinder = getContext().getService(getContext().getServiceReferences(ClassLoader.class, "(equinox.classloader.type=contextClassLoader)").iterator().next());
+ // Using a resource we know is in java 8.
+ String resource = "META-INF/services/javax.print.PrintServiceLookup";
+ URL systemURL = ClassLoader.getSystemClassLoader().getResource("META-INF/services/javax.print.PrintServiceLookup");
+ assertNotNull("Did not find a parent resource: " + resource, systemURL);
+ //should return the file defined in test bundle.
+ URL url = contextFinder.getResource(resource);
+ //the first element should be the file define in this bundle.
+ List<URL> urls = Collections.list(contextFinder.getResources(resource));
+ // make sure we have a resource located in the parent
+ assertTrue("Did not find a parent resource: " + urls, urls.size() > 1);
+ //assert failed as it return the one defined in parent class.
+ assertEquals(url.toExternalForm(), urls.get(0).toExternalForm());
+ }
+
public void testBundleReference01() throws Exception {
Bundle test = installer.installBundle("test"); //$NON-NLS-1$
Class clazz = test.loadClass("test1.Activator"); //$NON-NLS-1$
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
index 5c64f8fbe..5c64f8fbe 100644..100755
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ContextFinder.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ContextFinder.java
index 603e3bdcc..07dbd791f 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ContextFinder.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ContextFinder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 IBM Corporation and others.
+ * Copyright (c) 2005, 2016 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
@@ -15,6 +15,7 @@ import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
+import org.eclipse.osgi.internal.loader.BundleLoader;
import org.eclipse.osgi.internal.loader.ModuleClassLoader;
public class ContextFinder extends ClassLoader implements PrivilegedAction<List<ClassLoader>> {
@@ -152,22 +153,23 @@ public class ContextFinder extends ClassLoader implements PrivilegedAction<List<
}
}
- protected Enumeration<URL> findResources(String arg0) throws IOException {
+ public Enumeration<URL> getResources(String arg0) throws IOException {
//Shortcut cycle
if (startLoading(arg0) == false) {
- @SuppressWarnings("unchecked")
- Enumeration<URL> result = Collections.enumeration(Collections.EMPTY_LIST);
- return result;
+ return Collections.enumeration(Collections.<URL> emptyList());
}
try {
List<ClassLoader> toConsult = findClassLoaders();
+ Enumeration<URL> result = null;
for (Iterator<ClassLoader> loaders = toConsult.iterator(); loaders.hasNext();) {
- Enumeration<URL> result = loaders.next().getResources(arg0);
- if (result != null && result.hasMoreElements())
- return result;
- // go to the next class loader
+ result = loaders.next().getResources(arg0);
+ if (result != null && result.hasMoreElements()) {
+ // For context finder we do not compound results after this first loader that has resources
+ break;
+ }
+ // no results yet, go to the next class loader
}
- return super.findResources(arg0);
+ return BundleLoader.compoundEnumerations(result, super.getResources(arg0));
} finally {
stopLoading(arg0);
}

Back to the top