Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2011-10-20 07:27:46 -0400
committerGlyn Normington2011-10-20 07:27:46 -0400
commit1f4aaf837ba7431b54d958fc89920787494b70c7 (patch)
tree657f3bcc8892ebd25b5d65395dfaea0b9e37ecf2
parent7c7c26987a56cbd812eaa098a513d0be211636a6 (diff)
downloadorg.eclipse.virgo.kernel-1f4aaf837ba7431b54d958fc89920787494b70c7.tar.gz
org.eclipse.virgo.kernel-1f4aaf837ba7431b54d958fc89920787494b70c7.tar.xz
org.eclipse.virgo.kernel-1f4aaf837ba7431b54d958fc89920787494b70c7.zip
bug 360965: avoid Spring DM overriding the TCCL of PARs and scoped plans
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/SyntheticContextTCCLIntegrationTests.java2
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelOsgiApplicationContextCreator.java5
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelOsgiContextClassLoaderProvider.java43
3 files changed, 48 insertions, 2 deletions
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/SyntheticContextTCCLIntegrationTests.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/SyntheticContextTCCLIntegrationTests.java
index e32a4f53..064767be 100644
--- a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/SyntheticContextTCCLIntegrationTests.java
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/SyntheticContextTCCLIntegrationTests.java
@@ -14,7 +14,6 @@ package org.eclipse.virgo.kernel.deployer.test;
import java.io.File;
import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -29,7 +28,6 @@ import org.junit.Test;
* For the source of the PAR and "global" bundle, see test-apps/synthetic-tccl. Instructions for building are in
* README.TXT.
*/
-@Ignore("Bug 360965 - Avoid Spring DM overriding TCCL of scoped applications")
public class SyntheticContextTCCLIntegrationTests extends AbstractDeployerIntegrationTest {
@Test
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelOsgiApplicationContextCreator.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelOsgiApplicationContextCreator.java
index c4724b46..da88d44d 100644
--- a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelOsgiApplicationContextCreator.java
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelOsgiApplicationContextCreator.java
@@ -13,6 +13,7 @@ package org.eclipse.virgo.kernel.dmfragment.internal;
import org.osgi.framework.BundleContext;
import org.springframework.osgi.context.DelegatedExecutionOsgiBundleApplicationContext;
+import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
import org.springframework.osgi.extender.support.DefaultOsgiApplicationContextCreator;
/**
@@ -30,6 +31,10 @@ final class KernelOsgiApplicationContextCreator extends DefaultOsgiApplicationCo
@Override
public DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(BundleContext bundleContext) throws Exception {
DelegatedExecutionOsgiBundleApplicationContext applicationContext = super.createApplicationContext(bundleContext);
+ if (applicationContext instanceof OsgiBundleXmlApplicationContext) {
+ OsgiBundleXmlApplicationContext osgiBundleXmlApplicationContext = (OsgiBundleXmlApplicationContext) applicationContext;
+ osgiBundleXmlApplicationContext.setContextClassLoaderProvider(new KernelOsgiContextClassLoaderProvider(osgiBundleXmlApplicationContext.getBundle()));
+ }
return applicationContext;
}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelOsgiContextClassLoaderProvider.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelOsgiContextClassLoaderProvider.java
new file mode 100644
index 00000000..27904924
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelOsgiContextClassLoaderProvider.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2011 VMware Inc.
+ * 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:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import org.osgi.framework.Bundle;
+import org.springframework.osgi.context.support.ContextClassLoaderProvider;
+import org.springframework.osgi.util.BundleDelegatingClassLoader;
+
+/**
+ * {@link KernelOsgiContextClassLoaderProvider} preserves any existing thread context class loader and uses the bundle
+ * to load classes otherwise.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * Thread safe.
+ */
+final class KernelOsgiContextClassLoaderProvider implements ContextClassLoaderProvider {
+
+ private final BundleDelegatingClassLoader bundleClassLoader;
+
+ KernelOsgiContextClassLoaderProvider(Bundle bundle) {
+ this.bundleClassLoader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ClassLoader getContextClassLoader() {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ return tccl == null ? this.bundleClassLoader : tccl;
+ }
+
+} \ No newline at end of file

Back to the top