Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2008-11-11 22:42:43 +0000
committerThomas Watson2008-11-11 22:42:43 +0000
commite190c827aea71e988d23cdc5f34591c845364afc (patch)
tree5fa404ade72967208f02a5bb1ed9e6a01c951663
parent2065be39704867e27ac4f5e628efb96add796505 (diff)
downloadrt.equinox.framework-e190c827aea71e988d23cdc5f34591c845364afc.tar.gz
rt.equinox.framework-e190c827aea71e988d23cdc5f34591c845364afc.tar.xz
rt.equinox.framework-e190c827aea71e988d23cdc5f34591c845364afc.zip
Bug 254598 Exception: String incompatible with IBuddyPolicy
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test1/buddy/dependent/a/test1/ATest.java15
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test1/resources/test1.txt1
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/buddy/dependent/a/test2/ATest.java15
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/resources/test2.txt1
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test1/buddy/registered/a/test1/ATest.java15
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test1/resources/test1.txt1
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test2/buddy/registered/a/test2/ATest.java15
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test2/resources/test2.txt1
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java237
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java6
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PolicyHandler.java198
12 files changed, 342 insertions, 165 deletions
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test1/buddy/dependent/a/test1/ATest.java b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test1/buddy/dependent/a/test1/ATest.java
new file mode 100644
index 000000000..6709bc4f8
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test1/buddy/dependent/a/test1/ATest.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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 buddy.dependent.a.test1;
+
+public class ATest {
+
+}
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test1/resources/test1.txt b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test1/resources/test1.txt
new file mode 100644
index 000000000..6bddbfe0e
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test1/resources/test1.txt
@@ -0,0 +1 @@
+buddy.dependent.a.test1 \ No newline at end of file
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/META-INF/MANIFEST.MF
index e7fb08682..c6dc34a31 100644
--- a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/META-INF/MANIFEST.MF
@@ -7,4 +7,4 @@ Bundle-Localization: plugin
Import-Package:
org.eclipse.osgi.tests.bundles,
org.osgi.framework;version="1.3.0"
-Require-Bundle: buddy.dependent.a
+Require-Bundle: buddy.dependent.a.test1
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/buddy/dependent/a/test2/ATest.java b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/buddy/dependent/a/test2/ATest.java
new file mode 100644
index 000000000..6eac55867
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/buddy/dependent/a/test2/ATest.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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 buddy.dependent.a.test2;
+
+public class ATest {
+
+}
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/resources/test2.txt b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/resources/test2.txt
new file mode 100644
index 000000000..d629a675a
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.dependent.a.test2/resources/test2.txt
@@ -0,0 +1 @@
+buddy.dependent.a.test2 \ No newline at end of file
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test1/buddy/registered/a/test1/ATest.java b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test1/buddy/registered/a/test1/ATest.java
new file mode 100644
index 000000000..195d5533f
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test1/buddy/registered/a/test1/ATest.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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 buddy.registered.a.test1;
+
+public class ATest {
+
+}
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test1/resources/test1.txt b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test1/resources/test1.txt
new file mode 100644
index 000000000..ac6c0131e
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test1/resources/test1.txt
@@ -0,0 +1 @@
+buddy.registered.a.test1 \ No newline at end of file
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test2/buddy/registered/a/test2/ATest.java b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test2/buddy/registered/a/test2/ATest.java
new file mode 100644
index 000000000..14e3e3c99
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test2/buddy/registered/a/test2/ATest.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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 buddy.registered.a.test2;
+
+public class ATest {
+
+}
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test2/resources/test2.txt b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test2/resources/test2.txt
new file mode 100644
index 000000000..b23305444
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/buddy.registered.a.test2/resources/test2.txt
@@ -0,0 +1 @@
+buddy.registered.a.test2 \ 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 d327d4372..01c846758 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2008 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
@@ -809,76 +809,171 @@ public class ClassLoadingBundleTests extends AbstractBundleTests {
}
}
- // TODO temporarily disable til we can debug the build test machine on Win XP
- // public void testBuddyClassLoadingRegistered1() throws Exception{
- // Bundle registeredA = installer.installBundle("buddy.registered.a");
- // installer.resolveBundles(new Bundle[] {registeredA});
- // Enumeration testFiles = registeredA.getResources("resources/test.txt");
- // assertNotNull("testFiles", testFiles);
- // ArrayList testURLs = new ArrayList();
- // while(testFiles.hasMoreElements())
- // testURLs.add(testFiles.nextElement());
- // assertEquals("test.txt number", 1, testURLs.size());
- // assertEquals("buddy.registered.a", "buddy.registered.a", readURL((URL) testURLs.get(0)));
- //
- // Bundle registeredATest1 = installer.installBundle("buddy.registered.a.test1");
- // Bundle registeredATest2 = installer.installBundle("buddy.registered.a.test2");
- // installer.resolveBundles(new Bundle[] {registeredATest1, registeredATest2});
- // testFiles = registeredA.getResources("resources/test.txt");
- // assertNotNull("testFiles", testFiles);
- // testURLs = new ArrayList();
- // while(testFiles.hasMoreElements())
- // testURLs.add(testFiles.nextElement());
- //
- // // TODO some debug code to figure out why this is failing on the test machine
- // if (registeredATest1.getState() != Bundle.RESOLVED) {
- // System.out.println("Bundle is not resolved!! " + registeredATest1.getSymbolicName());
- // State state = Platform.getPlatformAdmin().getState(false);
- // BundleDescription aDesc = state.getBundle(registeredATest1.getBundleId());
- // ResolverError[] errors = state.getResolverErrors(aDesc);
- // for (int i = 0; i < errors.length; i++)
- // System.out.println(errors[i]);
- // }
- // if (registeredATest2.getState() != Bundle.RESOLVED) {
- // System.out.println("Bundle is not resolved!! " + registeredATest2.getSymbolicName());
- // State state = Platform.getPlatformAdmin().getState(false);
- // BundleDescription bDesc = state.getBundle(registeredATest2.getBundleId());
- // ResolverError[] errors = state.getResolverErrors(bDesc);
- // for (int i = 0; i < errors.length; i++)
- // System.out.println(errors[i]);
- // }
- //
- // // The real test
- // assertEquals("test.txt number", 3, testURLs.size());
- // assertEquals("buddy.registered.a", "buddy.registered.a", readURL((URL) testURLs.get(0)));
- // assertEquals("buddy.registered.a.test1", "buddy.registered.a.test1", readURL((URL) testURLs.get(1)));
- // assertEquals("buddy.registered.a.test2", "buddy.registered.a.test2", readURL((URL) testURLs.get(2)));
- // }
- //
- // public void testBuddyClassLoadingDependent1() throws Exception{
- // Bundle dependentA = installer.installBundle("buddy.dependent.a");
- // installer.resolveBundles(new Bundle[] {dependentA});
- // Enumeration testFiles = dependentA.getResources("resources/test.txt");
- // assertNotNull("testFiles", testFiles);
- // ArrayList testURLs = new ArrayList();
- // while(testFiles.hasMoreElements())
- // testURLs.add(testFiles.nextElement());
- // assertEquals("test.txt number", 1, testURLs.size());
- // assertEquals("buddy.dependent.a", "buddy.dependent.a", readURL((URL) testURLs.get(0)));
- //
- // Bundle dependentATest1 = installer.installBundle("buddy.dependent.a.test1");
- // Bundle dependentATest2 = installer.installBundle("buddy.dependent.a.test2");
- // installer.resolveBundles(new Bundle[] {dependentATest1, dependentATest2});
- // testFiles = dependentA.getResources("resources/test.txt");
- // assertNotNull("testFiles", testFiles);
- // testURLs = new ArrayList();
- // while(testFiles.hasMoreElements())
- // testURLs.add(testFiles.nextElement());
- // assertEquals("test.txt number", 3, testURLs.size());
- // assertEquals("buddy.dependent.a", "buddy.dependent.a", readURL((URL) testURLs.get(0)));
- // assertEquals("buddy.dependent.a.test1", "buddy.dependent.a.test1", readURL((URL) testURLs.get(1)));
- // assertEquals("buddy.dependent.a.test2", "buddy.dependent.a.test2", readURL((URL) testURLs.get(2)));
- // }
+ public void testBuddyClassLoadingRegistered1() throws Exception {
+ Bundle registeredA = installer.installBundle("buddy.registered.a"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {registeredA});
+ Enumeration testFiles = registeredA.getResources("resources/test.txt"); //$NON-NLS-1$
+ assertNotNull("testFiles", testFiles); //$NON-NLS-1$
+ ArrayList texts = new ArrayList();
+ while (testFiles.hasMoreElements())
+ texts.add(readURL((URL) testFiles.nextElement()));
+ assertEquals("test.txt number", 1, texts.size()); //$NON-NLS-1$
+ assertTrue("buddy.registered.a", texts.contains("buddy.registered.a")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Bundle registeredATest1 = installer.installBundle("buddy.registered.a.test1"); //$NON-NLS-1$
+ Bundle registeredATest2 = installer.installBundle("buddy.registered.a.test2"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {registeredATest1, registeredATest2});
+ testFiles = registeredA.getResources("resources/test.txt"); //$NON-NLS-1$
+ assertNotNull("testFiles", testFiles); //$NON-NLS-1$
+ texts = new ArrayList();
+ while (testFiles.hasMoreElements())
+ texts.add(readURL((URL) testFiles.nextElement()));
+
+ // The real test
+ assertEquals("test.txt number", 3, texts.size()); //$NON-NLS-1$
+ assertTrue("buddy.registered.a", texts.contains("buddy.registered.a")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("buddy.registered.a.test1", texts.contains("buddy.registered.a.test1")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("buddy.registered.a.test2", texts.contains("buddy.registered.a.test2")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBuddyClassLoadingRegistered2() throws Exception {
+ Bundle registeredA = installer.installBundle("buddy.registered.a"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {registeredA});
+ URL testFile = registeredA.getResource("resources/test1.txt"); //$NON-NLS-1$
+ assertNull("test1.txt", testFile); //$NON-NLS-1$
+
+ testFile = registeredA.getResource("resources/test2.txt"); //$NON-NLS-1$
+ assertNull("test2.txt", testFile); //$NON-NLS-1$
+
+ Bundle registeredATest1 = installer.installBundle("buddy.registered.a.test1"); //$NON-NLS-1$
+ Bundle registeredATest2 = installer.installBundle("buddy.registered.a.test2"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {registeredATest1, registeredATest2});
+
+ testFile = registeredA.getResource("resources/test1.txt"); //$NON-NLS-1$
+ assertNotNull("test1.txt", testFile); //$NON-NLS-1$
+ assertEquals("buddy.registered.a.test1", "buddy.registered.a.test1", readURL(testFile)); //$NON-NLS-1$ //$NON-NLS-2$
+
+ testFile = registeredA.getResource("resources/test2.txt"); //$NON-NLS-1$
+ assertNotNull("test2.txt", testFile); //$NON-NLS-1$
+ assertEquals("buddy.registered.a.test2", "buddy.registered.a.test2", readURL(testFile)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBuddyClassLoadingRegistered3() throws Exception {
+ Bundle registeredA = installer.installBundle("buddy.registered.a"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {registeredA});
+ try {
+ registeredA.loadClass("buddy.registered.a.test1.ATest"); //$NON-NLS-1$
+ fail("expected ClassNotFoundException"); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ // expected
+ }
+ try {
+ registeredA.loadClass("buddy.registered.a.test2.ATest"); //$NON-NLS-1$
+ fail("expected ClassNotFoundException"); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ // expected
+ }
+ Bundle registeredATest1 = installer.installBundle("buddy.registered.a.test1"); //$NON-NLS-1$
+ Bundle registeredATest2 = installer.installBundle("buddy.registered.a.test2"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {registeredATest1, registeredATest2});
+
+ try {
+ Class testClass = registeredA.loadClass("buddy.registered.a.test1.ATest"); //$NON-NLS-1$
+ assertNotNull("testClass", testClass); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ fail("Unexpected ClassNotFoundException", e); //$NON-NLS-1$
+ }
+
+ try {
+ Class testClass = registeredA.loadClass("buddy.registered.a.test2.ATest"); //$NON-NLS-1$
+ assertNotNull("testClass", testClass); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ fail("Unexpected ClassNotFoundException", e); //$NON-NLS-1$
+ }
+ }
+
+ public void testBuddyClassLoadingDependent1() throws Exception {
+ Bundle dependentA = installer.installBundle("buddy.dependent.a"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {dependentA});
+ Enumeration testFiles = dependentA.getResources("resources/test.txt"); //$NON-NLS-1$
+ assertNotNull("testFiles", testFiles); //$NON-NLS-1$
+ ArrayList texts = new ArrayList();
+ while (testFiles.hasMoreElements())
+ texts.add(readURL((URL) testFiles.nextElement()));
+ assertEquals("test.txt number", 1, texts.size()); //$NON-NLS-1$
+ assertTrue("buddy.dependent.a", texts.contains("buddy.dependent.a")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Bundle dependentATest1 = installer.installBundle("buddy.dependent.a.test1"); //$NON-NLS-1$
+ Bundle dependentATest2 = installer.installBundle("buddy.dependent.a.test2"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {dependentATest1, dependentATest2});
+ testFiles = dependentA.getResources("resources/test.txt"); //$NON-NLS-1$
+ assertNotNull("testFiles", testFiles); //$NON-NLS-1$
+ texts = new ArrayList();
+ while (testFiles.hasMoreElements())
+ texts.add(readURL((URL) testFiles.nextElement()));
+ assertEquals("test.txt number", 3, texts.size()); //$NON-NLS-1$
+ assertTrue("buddy.dependent.a", texts.contains("buddy.dependent.a")); //$NON-NLS-1$//$NON-NLS-2$
+ assertTrue("buddy.dependent.a.test1", texts.contains("buddy.dependent.a.test1")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("buddy.dependent.a.test2", texts.contains("buddy.dependent.a.test2")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBuddyClassLoadingDependent2() throws Exception {
+ Bundle dependentA = installer.installBundle("buddy.dependent.a"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {dependentA});
+ URL testFile = dependentA.getResource("resources/test1.txt"); //$NON-NLS-1$
+ assertNull("test1.txt", testFile); //$NON-NLS-1$
+
+ testFile = dependentA.getResource("resources/test2.txt"); //$NON-NLS-1$
+ assertNull("test2.txt", testFile); //$NON-NLS-1$
+
+ Bundle dependentATest1 = installer.installBundle("buddy.dependent.a.test1"); //$NON-NLS-1$
+ Bundle dependentATest2 = installer.installBundle("buddy.dependent.a.test2"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {dependentATest1, dependentATest2});
+
+ testFile = dependentA.getResource("resources/test1.txt"); //$NON-NLS-1$
+ assertNotNull("test1.txt", testFile); //$NON-NLS-1$
+ assertEquals("buddy.dependent.a.test1", "buddy.dependent.a.test1", readURL(testFile)); //$NON-NLS-1$ //$NON-NLS-2$
+
+ testFile = dependentA.getResource("resources/test2.txt"); //$NON-NLS-1$
+ assertNotNull("test2.txt", testFile); //$NON-NLS-1$
+ assertEquals("buddy.dependent.a.test2", "buddy.dependent.a.test2", readURL(testFile)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testBuddyClassLoadingDependent3() throws Exception {
+ Bundle dependentA = installer.installBundle("buddy.dependent.a"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {dependentA});
+
+ try {
+ dependentA.loadClass("buddy.dependent.a.test1.ATest"); //$NON-NLS-1$
+ fail("expected ClassNotFoundException"); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ // expected
+ }
+
+ try {
+ dependentA.loadClass("buddy.dependent.a.test2.ATest"); //$NON-NLS-1$
+ fail("expected ClassNotFoundException"); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ // expected
+ }
+
+ Bundle dependentATest1 = installer.installBundle("buddy.dependent.a.test1"); //$NON-NLS-1$
+ Bundle dependentATest2 = installer.installBundle("buddy.dependent.a.test2"); //$NON-NLS-1$
+ installer.resolveBundles(new Bundle[] {dependentATest1, dependentATest2});
+
+ try {
+ Class testClass = dependentA.loadClass("buddy.dependent.a.test1.ATest"); //$NON-NLS-1$
+ assertNotNull("testClass", testClass); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ fail("Unexpected ClassNotFoundException", e); //$NON-NLS-1$
+ }
+ try {
+ Class testClass = dependentA.loadClass("buddy.dependent.a.test2.ATest"); //$NON-NLS-1$
+ assertNotNull("testClass", testClass); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ fail("Unexpected ClassNotFoundException", e); //$NON-NLS-1$
+ }
+ }
private String readURL(URL url) throws IOException {
StringBuffer sb = new StringBuffer();
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java
index 214368d0c..0124cebd7 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java
@@ -222,7 +222,9 @@ public class BundleLoader implements ClassLoaderDelegate {
} catch (BundleException e) {
// do nothing; buddyList == null
}
- policy = buddyList != null ? new PolicyHandler(this, buddyList) : null;
+ policy = buddyList != null ? new PolicyHandler(this, buddyList, bundle.framework.packageAdmin) : null;
+ if (policy != null)
+ policy.open(bundle.framework.systemBundle.context);
}
private synchronized KeyedHashSet getImportedSources(KeyedHashSet visited) {
@@ -296,7 +298,7 @@ public class BundleLoader implements ClassLoaderDelegate {
if (classloader != null)
classloader.close();
if (policy != null)
- policy.close();
+ policy.close(bundle.framework.systemBundle.context);
loaderFlags |= FLAG_CLOSED; /* This indicates the BundleLoader is destroyed */
}
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PolicyHandler.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PolicyHandler.java
index 4786882c6..6127f15a1 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PolicyHandler.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PolicyHandler.java
@@ -13,8 +13,9 @@ package org.eclipse.osgi.framework.internal.core;
import java.net.URL;
import java.util.*;
import org.osgi.framework.*;
+import org.osgi.service.packageadmin.PackageAdmin;
-public class PolicyHandler {
+public class PolicyHandler implements SynchronousBundleListener {
//Key for the framework buddies
private final static String DEPENDENT_POLICY = "dependent"; //$NON-NLS-1$
private final static String GLOBAL_POLICY = "global"; //$NON-NLS-1$
@@ -25,33 +26,19 @@ public class PolicyHandler {
private final static String PARENT_POLICY = "parent"; //$NON-NLS-1$
//The loader to which this policy is attached.
- BundleLoader policedLoader;
+ private final BundleLoader policedLoader;
//List of the policies as well as cache for the one that have been created. The size of this array never changes over time. This is why the synchronization is not done when iterating over it.
- Object[] policies = null;
+ private volatile Object[] policies = null;
//Support to cut class / resource loading cycles in the context of one thread. The contained object is a set of classname
- private ThreadLocal beingLoaded;
-
- private BundleListener listener = new BundleListener() {
- public void bundleChanged(BundleEvent event) {
- if (event.getType() == BundleEvent.STARTED || event.getType() == BundleEvent.STOPPED)
- return;
- try {
- String list = (String) policedLoader.getBundle().getBundleData().getManifest().get(Constants.BUDDY_LOADER);
- synchronized (this) {
- policies = getArrayFromList(list);
- }
- } catch (BundleException e) {
- //Ignore
- }
- }
- };
+ private final ThreadLocal beingLoaded;
+ private final PackageAdmin packageAdmin;
- public PolicyHandler(BundleLoader loader, String buddyList) {
+ public PolicyHandler(BundleLoader loader, String buddyList, PackageAdmin packageAdmin) {
policedLoader = loader;
policies = getArrayFromList(buddyList);
beingLoaded = new ThreadLocal();
- policedLoader.bundle.framework.systemBundle.context.addBundleListener(listener);
+ this.packageAdmin = packageAdmin;
}
static Object[] getArrayFromList(String stringList) {
@@ -67,66 +54,70 @@ public class PolicyHandler {
return list.isEmpty() ? new Object[0] : (Object[]) list.toArray(new Object[list.size()]);
}
- private synchronized IBuddyPolicy getPolicyImplementation(int policyOrder) {
- if (policies[policyOrder] instanceof String) {
- String buddyName = (String) policies[policyOrder];
+ private IBuddyPolicy getPolicyImplementation(Object[] policiesSnapshot, int policyOrder) {
+ synchronized (policiesSnapshot) {
+ if (policyOrder >= policiesSnapshot.length)
+ return null;
+ if (policiesSnapshot[policyOrder] instanceof String) {
+ String buddyName = (String) policiesSnapshot[policyOrder];
- if (REGISTERED_POLICY.equals(buddyName)) {
- policies[policyOrder] = new RegisteredPolicy(policedLoader);
- return (IBuddyPolicy) policies[policyOrder];
- }
- if (BOOT_POLICY.equals(buddyName)) {
- policies[policyOrder] = SystemPolicy.getInstance(SystemPolicy.BOOT);
- return (IBuddyPolicy) policies[policyOrder];
- }
- if (APP_POLICY.equals(buddyName)) {
- policies[policyOrder] = SystemPolicy.getInstance(SystemPolicy.APP);
- return (IBuddyPolicy) policies[policyOrder];
- }
- if (EXT_POLICY.equals(buddyName)) {
- policies[policyOrder] = SystemPolicy.getInstance(SystemPolicy.EXT);
- return (IBuddyPolicy) policies[policyOrder];
- }
- if (DEPENDENT_POLICY.equals(buddyName)) {
- policies[policyOrder] = new DependentPolicy(policedLoader);
- return (IBuddyPolicy) policies[policyOrder];
- }
- if (GLOBAL_POLICY.equals(buddyName)) {
- policies[policyOrder] = new GlobalPolicy(policedLoader.bundle.framework.packageAdmin);
- return (IBuddyPolicy) policies[policyOrder];
- }
- if (PARENT_POLICY.equals(buddyName)) {
- policies[policyOrder] = new SystemPolicy(policedLoader.getParentClassLoader());
- return (IBuddyPolicy) policies[policyOrder];
- }
+ if (REGISTERED_POLICY.equals(buddyName)) {
+ policiesSnapshot[policyOrder] = new RegisteredPolicy(policedLoader);
+ return (IBuddyPolicy) policiesSnapshot[policyOrder];
+ }
+ if (BOOT_POLICY.equals(buddyName)) {
+ policiesSnapshot[policyOrder] = SystemPolicy.getInstance(SystemPolicy.BOOT);
+ return (IBuddyPolicy) policiesSnapshot[policyOrder];
+ }
+ if (APP_POLICY.equals(buddyName)) {
+ policiesSnapshot[policyOrder] = SystemPolicy.getInstance(SystemPolicy.APP);
+ return (IBuddyPolicy) policiesSnapshot[policyOrder];
+ }
+ if (EXT_POLICY.equals(buddyName)) {
+ policiesSnapshot[policyOrder] = SystemPolicy.getInstance(SystemPolicy.EXT);
+ return (IBuddyPolicy) policiesSnapshot[policyOrder];
+ }
+ if (DEPENDENT_POLICY.equals(buddyName)) {
+ policiesSnapshot[policyOrder] = new DependentPolicy(policedLoader);
+ return (IBuddyPolicy) policiesSnapshot[policyOrder];
+ }
+ if (GLOBAL_POLICY.equals(buddyName)) {
+ policiesSnapshot[policyOrder] = new GlobalPolicy(packageAdmin);
+ return (IBuddyPolicy) policiesSnapshot[policyOrder];
+ }
+ if (PARENT_POLICY.equals(buddyName)) {
+ policiesSnapshot[policyOrder] = new SystemPolicy(policedLoader.getParentClassLoader());
+ return (IBuddyPolicy) policiesSnapshot[policyOrder];
+ }
- // //Buddy policy can be provided by service implementations
- // BundleContext fwkCtx = policedLoader.bundle.framework.systemBundle.context;
- // ServiceReference[] matchingBuddies = null;
- // try {
- // matchingBuddies = fwkCtx.getAllServiceReferences(IBuddyPolicy.class.getName(), "buddyName=" + buddyName);
- // } catch (InvalidSyntaxException e) {
- // //The filter is valid
- // }
- // if (matchingBuddies == null)
- // return new IBuddyPolicy() {
- // public Class loadClass(String name) {
- // return null;
- // }
- //
- // public URL loadResource(String name) {
- // return null;
- // }
- //
- // public Enumeration loadResources(String name) {
- // return null;
- // }
- // };
- //
- // //The policies loaded through service are not cached
- // return ((IBuddyPolicy) fwkCtx.getService(matchingBuddies[0]));
+ // //Buddy policy can be provided by service implementations
+ // BundleContext fwkCtx = policedLoader.bundle.framework.systemBundle.context;
+ // ServiceReference[] matchingBuddies = null;
+ // try {
+ // matchingBuddies = fwkCtx.getAllServiceReferences(IBuddyPolicy.class.getName(), "buddyName=" + buddyName);
+ // } catch (InvalidSyntaxException e) {
+ // //The filter is valid
+ // }
+ // if (matchingBuddies == null)
+ // return new IBuddyPolicy() {
+ // public Class loadClass(String name) {
+ // return null;
+ // }
+ //
+ // public URL loadResource(String name) {
+ // return null;
+ // }
+ //
+ // public Enumeration loadResources(String name) {
+ // return null;
+ // }
+ // };
+ //
+ // //The policies loaded through service are not cached
+ // return ((IBuddyPolicy) fwkCtx.getService(matchingBuddies[0]));
+ }
+ return (IBuddyPolicy) policiesSnapshot[policyOrder];
}
- return (IBuddyPolicy) policies[policyOrder];
}
public Class doBuddyClassLoading(String name) {
@@ -134,8 +125,12 @@ public class PolicyHandler {
return null;
Class result = null;
- for (int i = 0; i < policies.length && result == null; i++) {
- result = getPolicyImplementation(i).loadClass(name);
+ Object[] policiesSnapshot = policies;
+ int policyCount = (policiesSnapshot == null) ? 0 : policiesSnapshot.length;
+ for (int i = 0; i < policyCount && result == null; i++) {
+ IBuddyPolicy policy = getPolicyImplementation(policiesSnapshot, i);
+ if (policy != null)
+ result = policy.loadClass(name);
}
stopLoading(name);
return result;
@@ -145,11 +140,13 @@ public class PolicyHandler {
if (startLoading(name) == false)
return null;
- if (policies == null)
- return null;
URL result = null;
- for (int i = 0; i < policies.length && result == null; i++) {
- result = getPolicyImplementation(i).loadResource(name);
+ Object[] policiesSnapshot = policies;
+ int policyCount = (policiesSnapshot == null) ? 0 : policiesSnapshot.length;
+ for (int i = 0; i < policyCount && result == null; i++) {
+ IBuddyPolicy policy = getPolicyImplementation(policiesSnapshot, i);
+ if (policy != null)
+ result = policy.loadResource(name);
}
stopLoading(name);
return result;
@@ -159,14 +156,17 @@ public class PolicyHandler {
if (startLoading(name) == false)
return null;
- if (policies == null)
- return null;
Vector results = null;
- for (int i = 0; i < policies.length; i++) {
- Enumeration result = getPolicyImplementation(i).loadResources(name);
+ Object[] policiesSnapshot = policies;
+ int policyCount = (policiesSnapshot == null) ? 0 : policiesSnapshot.length;
+ for (int i = 0; i < policyCount; i++) {
+ IBuddyPolicy policy = getPolicyImplementation(policiesSnapshot, i);
+ if (policy == null)
+ continue;
+ Enumeration result = policy.loadResources(name);
if (result != null) {
if (results == null)
- results = new Vector(policies.length);
+ results = new Vector(policyCount);
while (result.hasMoreElements()) {
Object url = result.nextElement();
if (!results.contains(url)) //only add if not already added
@@ -195,7 +195,23 @@ public class PolicyHandler {
((Set) beingLoaded.get()).remove(name);
}
- public void close() {
- policedLoader.bundle.framework.systemBundle.context.removeBundleListener(listener);
+ public void open(BundleContext context) {
+ context.addBundleListener(this);
+ }
+
+ public void close(BundleContext context) {
+ context.removeBundleListener(this);
+ }
+
+ public void bundleChanged(BundleEvent event) {
+ if ((event.getType() & (BundleEvent.RESOLVED | BundleEvent.UNRESOLVED)) == 0)
+ return;
+ // reinitialize the policies
+ try {
+ String list = (String) policedLoader.getBundle().getBundleData().getManifest().get(Constants.BUDDY_LOADER);
+ policies = getArrayFromList(list);
+ } catch (BundleException e) {
+ //Ignore
+ }
}
}

Back to the top