Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2008-09-04 17:58:10 +0000
committerThomas Watson2008-09-04 17:58:10 +0000
commit0e56f61d9f96cb814747dac738de7acf7b6e35a1 (patch)
treecbbf6de4fd2e3fbd9b00806c46f79b519e360e16 /bundles
parent01f290b14db9d6b49620067fee54efad1ce9f210 (diff)
downloadrt.equinox.framework-0e56f61d9f96cb814747dac738de7acf7b6e35a1.tar.gz
rt.equinox.framework-0e56f61d9f96cb814747dac738de7acf7b6e35a1.tar.xz
rt.equinox.framework-0e56f61d9f96cb814747dac738de7acf7b6e35a1.zip
Bug 246132 Refactor loader layer
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java6
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java121
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/AbstractBundle.java2
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java15
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoaderProxy.java2
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/DependentPolicy.java (renamed from bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/DependentPolicy.java)10
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java (renamed from bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/GlobalPolicy.java)6
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/IBuddyPolicy.java (renamed from bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/IBuddyPolicy.java)4
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/ParentPolicy.java (renamed from bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/ParentPolicy.java)4
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/PolicyHandler.java (renamed from bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PolicyHandler.java)55
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/RegisteredPolicy.java (renamed from bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/RegisteredPolicy.java)15
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/SystemPolicy.java (renamed from bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/SystemPolicy.java)2
12 files changed, 120 insertions, 122 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java
index 2b63d611f..425ccbd72 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java
@@ -158,11 +158,12 @@ public class BundleInstaller {
};
context.addFrameworkListener(listener);
final HashSet refreshed = new HashSet();
- context.addBundleListener(new SynchronousBundleListener() {
+ BundleListener refreshBundleListener = new SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
refreshed.add(event.getBundle());
}
- });
+ };
+ context.addBundleListener(refreshBundleListener);
try {
pa.refreshPackages(refresh);
synchronized (flag) {
@@ -176,6 +177,7 @@ public class BundleInstaller {
}
} finally {
context.removeFrameworkListener(listener);
+ context.removeBundleListener(refreshBundleListener);
}
return (Bundle[]) refreshed.toArray(new Bundle[refreshed.size()]);
}
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 6e8f0a9df..f7784409e 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
@@ -809,76 +809,57 @@ 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 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$
+ }
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/AbstractBundle.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/AbstractBundle.java
index 243c08ed6..9eadfb6cd 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/AbstractBundle.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/AbstractBundle.java
@@ -1322,7 +1322,7 @@ public abstract class AbstractBundle implements Bundle, Comparable, KeyedElement
return bundledata.getVersion();
}
- protected BundleDescription getBundleDescription() {
+ public BundleDescription getBundleDescription() {
return framework.adaptor.getState().getBundle(getBundleId());
}
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 5ad88bb34..8e102434d 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
@@ -20,6 +20,7 @@ import java.util.*;
import org.eclipse.osgi.framework.adaptor.*;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.util.KeyedHashSet;
+import org.eclipse.osgi.internal.loader.buddy.PolicyHandler;
import org.eclipse.osgi.service.resolver.*;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleException;
@@ -222,7 +223,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) {
@@ -273,7 +276,7 @@ public class BundleLoader implements ClassLoaderDelegate {
/*
* get the loader proxy for a bundle description
*/
- final BundleLoaderProxy getLoaderProxy(BundleDescription source) {
+ public final BundleLoaderProxy getLoaderProxy(BundleDescription source) {
BundleLoaderProxy sourceProxy = (BundleLoaderProxy) source.getUserObject();
if (sourceProxy == null) {
// may need to force the proxy to be created
@@ -296,7 +299,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 */
}
@@ -326,7 +329,7 @@ public class BundleLoader implements ClassLoaderDelegate {
return createClassLoader().getResource(name);
}
- final synchronized ClassLoader getParentClassLoader() {
+ public final synchronized ClassLoader getParentClassLoader() {
if (parent != null)
return parent;
createClassLoader();
@@ -722,7 +725,7 @@ public class BundleLoader implements ClassLoaderDelegate {
return compoundEnumerations(result, findResources(name));
}
- static Enumeration compoundEnumerations(Enumeration list1, Enumeration list2) {
+ public static Enumeration compoundEnumerations(Enumeration list1, Enumeration list2) {
if (list2 == null || !list2.hasMoreElements())
return list1;
if (list1 == null || !list1.hasMoreElements())
@@ -810,7 +813,7 @@ public class BundleLoader implements ClassLoaderDelegate {
/*
* Return the bundle we are associated with.
*/
- final AbstractBundle getBundle() {
+ public final AbstractBundle getBundle() {
return bundle;
}
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoaderProxy.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoaderProxy.java
index 0ef397985..de536ab2b 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoaderProxy.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoaderProxy.java
@@ -43,7 +43,7 @@ public class BundleLoaderProxy implements RequiredBundle {
this.pkgSources = new KeyedHashSet(false);
}
- synchronized BundleLoader getBundleLoader() {
+ public synchronized BundleLoader getBundleLoader() {
if (loader != null)
return loader;
if (bundle.isResolved()) {
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/DependentPolicy.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/DependentPolicy.java
index e7d27215f..f1897f180 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/DependentPolicy.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/DependentPolicy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -9,11 +9,13 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.osgi.framework.internal.core;
+package org.eclipse.osgi.internal.loader.buddy;
import java.io.IOException;
import java.net.URL;
import java.util.*;
+import org.eclipse.osgi.framework.internal.core.BundleLoader;
+import org.eclipse.osgi.framework.internal.core.BundleLoaderProxy;
import org.eclipse.osgi.service.resolver.BundleDescription;
/**
@@ -49,7 +51,7 @@ public class DependentPolicy implements IBuddyPolicy {
BundleLoaderProxy proxy = buddyRequester.getLoaderProxy(searchedBundle);
if (proxy == null)
continue;
- result = proxy.getBundleLoader().findClass(name, true);
+ result = proxy.getBundleLoader().findClass(name);
} catch (ClassNotFoundException e) {
if (result == null)
addDependent(i, searchedBundle);
@@ -76,7 +78,7 @@ public class DependentPolicy implements IBuddyPolicy {
BundleLoaderProxy proxy = buddyRequester.getLoaderProxy(searchedBundle);
if (proxy == null)
continue;
- result = proxy.getBundleLoader().findResource(name, true);
+ result = proxy.getBundleLoader().findResource(name);
if (result == null) {
addDependent(i, searchedBundle);
}
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/GlobalPolicy.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java
index 91ea2325f..ca4cbf9f1 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/GlobalPolicy.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -8,7 +8,9 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.osgi.framework.internal.core;
+package org.eclipse.osgi.internal.loader.buddy;
+
+import org.eclipse.osgi.framework.internal.core.BundleLoader;
import java.io.IOException;
import java.net.URL;
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/IBuddyPolicy.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/IBuddyPolicy.java
index 24abbf295..3e513f67d 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/IBuddyPolicy.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/IBuddyPolicy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.osgi.framework.internal.core;
+package org.eclipse.osgi.internal.loader.buddy;
import java.net.URL;
import java.util.Enumeration;
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/ParentPolicy.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/ParentPolicy.java
index 7d6e55bc7..0c730a126 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/ParentPolicy.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/ParentPolicy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.osgi.framework.internal.core;
+package org.eclipse.osgi.internal.loader.buddy;
import java.net.URL;
import java.util.Enumeration;
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/internal/loader/buddy/PolicyHandler.java
index 4786882c6..2bc93c638 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/internal/loader/buddy/PolicyHandler.java
@@ -8,13 +8,16 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.osgi.framework.internal.core;
+package org.eclipse.osgi.internal.loader.buddy;
import java.net.URL;
import java.util.*;
+import org.eclipse.osgi.framework.internal.core.BundleLoader;
+import org.eclipse.osgi.framework.internal.core.Constants;
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 +28,20 @@ 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.
+ // @GuardedBy this
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) {
@@ -92,7 +82,7 @@ public class PolicyHandler {
return (IBuddyPolicy) policies[policyOrder];
}
if (GLOBAL_POLICY.equals(buddyName)) {
- policies[policyOrder] = new GlobalPolicy(policedLoader.bundle.framework.packageAdmin);
+ policies[policyOrder] = new GlobalPolicy(packageAdmin);
return (IBuddyPolicy) policies[policyOrder];
}
if (PARENT_POLICY.equals(buddyName)) {
@@ -195,7 +185,24 @@ 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;
+ try {
+ String list = (String) policedLoader.getBundle().getBundleData().getManifest().get(Constants.BUDDY_LOADER);
+ synchronized (this) {
+ policies = getArrayFromList(list);
+ }
+ } catch (BundleException e) {
+ //Ignore
+ }
}
}
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/RegisteredPolicy.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/RegisteredPolicy.java
index 5bc9ef082..b02add967 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/RegisteredPolicy.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/RegisteredPolicy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -8,12 +8,13 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.osgi.framework.internal.core;
+package org.eclipse.osgi.internal.loader.buddy;
import java.io.IOException;
import java.net.URL;
-import java.util.*;
-
+import java.util.Enumeration;
+import java.util.Iterator;
+import org.eclipse.osgi.framework.internal.core.*;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleException;
@@ -45,7 +46,7 @@ public class RegisteredPolicy extends DependentPolicy {
}
boolean contributes = false;
for (int j = 0; j < allContributions.length && contributes == false; j++) {
- if (allContributions[j].equals(buddyRequester.bundle.getSymbolicName()))
+ if (allContributions[j].equals(buddyRequester.getBundle().getSymbolicName()))
contributes = true;
}
if (!contributes)
@@ -72,7 +73,7 @@ public class RegisteredPolicy extends DependentPolicy {
BundleLoaderProxy proxy = buddyRequester.getLoaderProxy((BundleDescription) allDependents.get(i));
if (proxy == null)
continue;
- result = proxy.getBundleLoader().findClass(name, true);
+ result = proxy.getBundleLoader().findClass(name);
} catch (ClassNotFoundException e) {
//Nothing to do, just keep looking
continue;
@@ -91,7 +92,7 @@ public class RegisteredPolicy extends DependentPolicy {
BundleLoaderProxy proxy = buddyRequester.getLoaderProxy((BundleDescription) allDependents.get(i));
if (proxy == null)
continue;
- result = proxy.getBundleLoader().findResource(name, true);
+ result = proxy.getBundleLoader().findResource(name);
}
return result;
}
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/SystemPolicy.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/SystemPolicy.java
index 29555008c..7b9a6cea1 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/SystemPolicy.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/loader/buddy/SystemPolicy.java
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.osgi.framework.internal.core;
+package org.eclipse.osgi.internal.loader.buddy;
import java.io.IOException;
import java.net.URL;

Back to the top