Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 56861 invoked from network); 29 Mar 2010 17:24:34 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 29 Mar 2010 17:24:34 -0000 Received: (qmail 70809 invoked by uid 500); 29 Mar 2010 17:24:34 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 70677 invoked by uid 500); 29 Mar 2010 17:24:33 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 70670 invoked by uid 99); 29 Mar 2010 17:24:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Mar 2010 17:24:33 +0000 X-ASF-Spam-Status: No, hits=-1173.3 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Mar 2010 17:24:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5E3CA23888CC; Mon, 29 Mar 2010 17:24:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r928839 - in /geronimo/server/trunk: framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/ plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/ plugins/myfaces/geronimo-myfaces/src/main/java/or... Date: Mon, 29 Mar 2010 17:24:12 -0000 To: scm@geronimo.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100329172412.5E3CA23888CC@eris.apache.org> Author: gawor Date: Mon Mar 29 17:24:11 2010 New Revision: 928839 URL: http://svn.apache.org/viewvc?rev=928839&view=rev Log: make sure BundleClassLoader.getBundle() does not return DelegatingBundle Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java?rev=928839&r1=928838&r2=928839&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java (original) +++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java Mon Mar 29 17:24:11 2010 @@ -132,13 +132,41 @@ public class BundleClassLoader extends C } } } + + /** + * Return the bundle associated with this classloader. + * + * In most cases the bundle associated with the classloader is a regular framework bundle. + * However, in some cases the bundle associated with the classloader is a {@link DelegatingBundle}. + * In such cases, the unwrap parameter controls whether this function returns the + * {@link DelegatingBundle} instance or the main application bundle backing with the {@link DelegatingBundle}. + * + * @param unwrap If true and if the bundle associated with this classloader is a {@link DelegatingBundle}, + * this function will return the main application bundle backing with the {@link DelegatingBundle}. + * Otherwise, the bundle associated with this classloader is returned as is. + * @return The bundle associated with this classloader. + */ + public Bundle getBundle(boolean unwrap) { + if (unwrap && bundle instanceof DelegatingBundle) { + return ((DelegatingBundle) bundle).getMainBundle(); + } + return bundle; + } /** - * Return the bundle instance backing this classloader. + * Return the bundle associated with this classloader. + * + * This method calls {@link #getBundle(boolean) getBundle(true)} and therefore always returns a regular + * framework bundle. + *

+ * Note: Some libraries use {@link BundleReference#getBundle()} to obtain a bundle for the given + * classloader and expect the returned bundle instance to be work with any OSGi API. Some of these API might + * not work if {@link DelegatingBundle} is returned. That is why this function will always return + * a regular framework bundle. See {@link #getBundle(boolean)} for more information. * - * @return The bundle used to source the classloader. + * @return The bundle associated with this classloader. */ public Bundle getBundle() { - return bundle; + return getBundle(true); } } Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java?rev=928839&r1=928838&r2=928839&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java (original) +++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java Mon Mar 29 17:24:11 2010 @@ -48,11 +48,20 @@ public class BundleUtils { } /** - * Returns Bundle (if any) associated with current thread's context ClassLoader. + * Returns bundle (if any) associated with current thread's context classloader. + * + * @param unwrap if true and if the bundle associated with the context classloader is a + * {@link DelegatingBundle}, this function will return the main application bundle + * backing with the {@link DelegatingBundle}. Otherwise, the bundle associated with + * the context classloader is returned as is. See {@link BundleClassLoader#getBundle(boolean)} + * for more information. + * @return The bundle associated with the current thread's context classloader. Might be null. */ - public static Bundle getContextBundle() { + public static Bundle getContextBundle(boolean unwrap) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader instanceof BundleReference) { + if (classLoader instanceof BundleClassLoader) { + return ((BundleClassLoader) classLoader).getBundle(unwrap); + } else if (classLoader instanceof BundleReference) { return ((BundleReference) classLoader).getBundle(); } else { return null; Modified: geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java?rev=928839&r1=928838&r2=928839&view=diff ============================================================================== --- geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java (original) +++ geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java Mon Mar 29 17:24:11 2010 @@ -29,7 +29,7 @@ import java.util.zip.ZipEntry; import javax.servlet.ServletContext; import org.apache.geronimo.kernel.osgi.BundleResourceFinder; -import org.apache.geronimo.kernel.osgi.DelegatingBundle; +import org.apache.geronimo.kernel.osgi.BundleUtils; import org.apache.geronimo.kernel.osgi.BundleResourceFinder.ResourceFinderCallback; import org.apache.geronimo.kernel.osgi.jar.BundleJarFile; import org.apache.jasper.JasperException; @@ -41,7 +41,6 @@ import org.apache.jasper.xmlparser.Parse import org.apache.jasper.xmlparser.TreeNode; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleReference; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; import org.osgi.service.packageadmin.PackageAdmin; @@ -157,7 +156,7 @@ public class GeronimoTldLocationsCache e tldScanWebXml(); tldScanResourcePaths(WEB_INF); - Bundle bundle = getBundle(); + Bundle bundle = BundleUtils.getContextBundle(true); if (bundle != null) { tldScanClassPath(bundle); tldScanGlobal(bundle); @@ -167,19 +166,6 @@ public class GeronimoTldLocationsCache e throw new JasperException(ex); } } - - private Bundle getBundle() { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader instanceof BundleReference) { - Bundle bundle = ((BundleReference) classLoader).getBundle(); - if (bundle instanceof DelegatingBundle) { - return ((DelegatingBundle) bundle).getMainBundle(); - } else { - return bundle; - } - } - return null; - } /* * Populates taglib map described in web.xml. Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java?rev=928839&r1=928838&r2=928839&view=diff ============================================================================== --- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java (original) +++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java Mon Mar 29 17:24:11 2010 @@ -46,7 +46,7 @@ public class ApplicationIndexedLifecycle } private Bundle getBundle() { - Bundle bundle = BundleUtils.getContextBundle(); + Bundle bundle = BundleUtils.getContextBundle(false); if (bundle == null) { throw new IllegalStateException("Unable to get Bundle object associated with the context classloader"); }