geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1138728 - in /geronimo/server/trunk/framework/modules: geronimo-hook/ geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/ geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/ geronimo-kernel/src/main/java/org/apache/g...
Date Thu, 23 Jun 2011 03:43:29 GMT
Author: gawor
Date: Thu Jun 23 03:43:29 2011
New Revision: 1138728

URL: http://svn.apache.org/viewvc?rev=1138728&view=rev
Log:
GERONIMO-5744: Support for Equinox-specific classloader that can convert bundle:// urls into
regular file:// or jar:// urls and make things easier for 3rd party libraries. The Equinox-specific
classloader is disabled by default for now

Added:
    geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
  (with props)
    geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoClassLoader.java
  (with props)
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/FrameworkUtils.java
  (with props)
Modified:
    geronimo/server/trunk/framework/modules/geronimo-hook/pom.xml
    geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/ClassLoaderHook.java
    geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoHookConfigurator.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java

Modified: geronimo/server/trunk/framework/modules/geronimo-hook/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-hook/pom.xml?rev=1138728&r1=1138727&r2=1138728&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-hook/pom.xml (original)
+++ geronimo/server/trunk/framework/modules/geronimo-hook/pom.xml Thu Jun 23 03:43:29 2011
@@ -36,8 +36,26 @@
         <dependency>
             <groupId>org.eclipse</groupId>
             <artifactId>osgi</artifactId>
+            <scope>provided</scope>
         </dependency>
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Import-Package>
+                            org.eclipse.*;resolution:=optional,
+                            *
+                        </Import-Package>
+                    </instructions>
+              </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
 </project>
 

Added: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java?rev=1138728&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
Thu Jun 23 03:43:29 2011
@@ -0,0 +1,111 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.hook.equinox;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import org.eclipse.osgi.framework.internal.core.Constants;
+import org.eclipse.osgi.util.ManifestElement;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+public class BundleUtils {
+
+    public static LinkedHashSet<Bundle> getWiredBundles(Bundle bundle) {
+        BundleContext bundleContext = bundle.getBundleContext();
+        if (bundleContext == null) {
+            return new LinkedHashSet<Bundle>(0);
+        } else {
+            ServiceReference reference = bundleContext.getServiceReference(PackageAdmin.class.getName());
+            PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference);
+            try {
+                return getWiredBundles(packageAdmin, bundle);
+            } finally {
+                bundle.getBundleContext().ungetService(reference);
+            }
+        }
+    }
+    
+    public static LinkedHashSet<Bundle> getWiredBundles(PackageAdmin packageAdmin,
Bundle bundle) {
+        // handle static wire via Import-Package
+        List<String> imports = getExternalImports(bundle);
+        LinkedHashSet<Bundle> wiredBundles = new LinkedHashSet<Bundle>();
+        for (String packageImport : imports) {
+            ExportedPackage[] exports = packageAdmin.getExportedPackages(packageImport);
+            Bundle wiredBundle = getWiredBundle(bundle, exports);
+            if (wiredBundle != null) {
+                wiredBundles.add(wiredBundle);
+            }
+        }
+        return wiredBundles;
+    }
+
+    private static Bundle getWiredBundle(Bundle bundle, ExportedPackage[] exports) {
+        if (exports != null) {
+            for (ExportedPackage exportedPackage : exports) {
+                Bundle[] importingBundles = exportedPackage.getImportingBundles();
+                if (importingBundles != null) {
+                    for (Bundle importingBundle : importingBundles) {
+                        if (importingBundle == bundle) {
+                            return exportedPackage.getExportingBundle();
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+    
+    public static List<String> getExternalImports(Bundle bundle) {
+        List<String> imports = new ArrayList<String>();
+        
+        String importPackages = (String) bundle.getHeaders().get(Constants.IMPORT_PACKAGE);
+        String exportPackages = (String) bundle.getHeaders().get(Constants.EXPORT_PACKAGE);
+        try {
+            ManifestElement[] importElements = ManifestElement.parseHeader(Constants.IMPORT_PACKAGE,
importPackages);
+            ManifestElement[] exportElements = ManifestElement.parseHeader(Constants.EXPORT_PACKAGE,
exportPackages);
+            
+            if (importElements != null) {
+                for (ManifestElement importElement : importElements) {
+                    if (exportElements == null || !isExported(exportElements, importElement))
{
+                        imports.add(importElement.getValue());
+                    }
+                }
+            }
+        } catch (BundleException e) {
+            // ignore
+        }
+        
+        return imports;
+    }
+    
+    private static boolean isExported(ManifestElement[] exportElements, ManifestElement importElement)
{
+        for (ManifestElement exportElement : exportElements) {
+            if (exportElement.getValue().equals(importElement.getValue())) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/ClassLoaderHook.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/ClassLoaderHook.java?rev=1138728&r1=1138727&r2=1138728&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/ClassLoaderHook.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/ClassLoaderHook.java
Thu Jun 23 03:43:29 2011
@@ -33,6 +33,7 @@ import org.eclipse.osgi.baseadaptor.load
 import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
 import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;
 import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
+import org.eclipse.osgi.framework.internal.core.AbstractBundle;
 import org.eclipse.osgi.framework.internal.core.Constants;
 import org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader;
 import org.eclipse.osgi.internal.loader.BundleLoader;
@@ -41,6 +42,15 @@ import org.osgi.framework.BundleExceptio
 
 public class ClassLoaderHook implements ClassLoadingHook, BundleExtender {
 
+    private static final String USE_URL_CLASSLOADER = "org.apache.geronimo.equinox.useURLClassLoader";
+    
+    private static final boolean useURLClassLoader = initUseURLClassLoader();
+    
+    private static boolean initUseURLClassLoader() {
+        String property = System.getProperty(USE_URL_CLASSLOADER, "false");
+        return Boolean.parseBoolean(property);        
+    }
+    
     private final Map<Long, String> dynamicPackages = 
         Collections.synchronizedMap(new HashMap<Long, String>());
     
@@ -68,7 +78,8 @@ public class ClassLoaderHook implements 
                                              BaseData data,
                                              String[] classpath) {
         BundleLoader loader = (BundleLoader) delegate;
-        String packages = dynamicPackages.get(loader.getBundle().getBundleId());
+        AbstractBundle bundle = loader.getBundle();
+        String packages = dynamicPackages.get(bundle.getBundleId());
         if (packages != null) {
             try {
                 loader.addDynamicImportPackage(ManifestElement.parseHeader(Constants.DYNAMICIMPORT_PACKAGE,
packages));
@@ -77,18 +88,24 @@ public class ClassLoaderHook implements 
             }
         }
         
-        if (domain == null) {
+        ProtectionDomain protectionDomain = domain;
+        if (protectionDomain == null) {
             /**
              * By default Equinox creates a ProtectionDomain for each bundle with AllPermission
permission.
              * That breaks Geronimo security checks. See GERONIMO-5480 for details.
              * This work-around prevents Equinox from adding AllPermission permission to
each bundle.
              */
             PermissionCollection emptyPermissionCollection = (new AllPermission()).newPermissionCollection();
-            ProtectionDomain emptyProtectionDomain = new ProtectionDomain(null, emptyPermissionCollection);
-            return new DefaultClassLoader(parent, delegate, emptyProtectionDomain, data,
classpath);
+            protectionDomain = new ProtectionDomain(null, emptyPermissionCollection);
         }
 
-        return null;
+        BaseClassLoader classLoader;
+        if (useURLClassLoader) {
+            classLoader = new GeronimoClassLoader(this, parent, delegate, protectionDomain,
data, classpath, bundle);
+        } else {
+            classLoader = new DefaultClassLoader(parent, delegate, protectionDomain, data,
classpath);
+        }
+        return classLoader;
     }
 
     public String findLibrary(BaseData arg0, String arg1) {

Added: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoClassLoader.java?rev=1138728&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoClassLoader.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoClassLoader.java
Thu Jun 23 03:43:29 2011
@@ -0,0 +1,277 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.hook.equinox;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.ProtectionDomain;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import org.eclipse.osgi.baseadaptor.BaseData;
+import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
+import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
+import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
+import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;
+import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
+import org.eclipse.osgi.framework.adaptor.BundleData;
+import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
+import org.eclipse.osgi.framework.internal.core.AbstractBundle;
+import org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader;
+import org.eclipse.osgi.service.urlconversion.URLConverter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class GeronimoClassLoader extends URLClassLoader implements BaseClassLoader {
+
+    private static final String PREFIX = "org.apache.xbean.osgi.bundle.util.BundleResourceHelper";
   
+    private static final String SEARCH_WIRED_BUNDLES = PREFIX + ".searchWiredBundles";
+    private static final String CONVERT_RESOURCE_URLS = PREFIX + ".convertResourceUrls";
+    
+    private final static String META_INF_1 = "META-INF/";
+    private final static String META_INF_2 = "/META-INF/";
+    
+    private final ClassLoaderHook hook;
+    private final ClassLoaderDelegate delegate;
+    private final ProtectionDomain domain;
+    private final AbstractBundle bundle;
+    private final ClasspathManager manager;
+    
+    private LinkedHashSet<Bundle> wiredBundles = null;
+    private boolean searchWiredBundles = getSearchWiredBundles(true);
+    private boolean convertResourceUrls = getConvertResourceUrls(true);
+    
+    private URLConverter converter;
+    
+    public GeronimoClassLoader(ClassLoaderHook hook,
+                               ClassLoader parent,
+                               ClassLoaderDelegate delegate,
+                               ProtectionDomain domain,
+                               BaseData bundledata,
+                               String[] classpath,
+                               AbstractBundle bundle) {
+        super(new URL[] {}, parent);     
+        this.hook = hook;
+        this.delegate = delegate;
+        this.domain = domain;
+        this.bundle = bundle;
+        
+        this.manager = new ClasspathManager(bundledata, classpath, this);
+    }
+            
+    @Override
+    protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException
{
+        Class clazz = delegate.findClass(name);
+        if (resolve) {
+            resolveClass(clazz);
+        }
+        return clazz;
+    }
+    
+    @Override
+    public URL getResource(String name) {
+        URL resource = delegate.findResource(name);
+        if (resource == null && isMetaInfResource(name)) {
+            LinkedHashSet<Bundle> wiredBundles = getWiredBundles();
+            Iterator<Bundle> iterator = wiredBundles.iterator();
+            while (iterator.hasNext() && resource == null) {                
+                resource = iterator.next().getResource(name);
+            }
+        }
+        if (resource != null && converter != null) {
+            return convert(resource);
+        } else {
+            return resource;
+        }
+    }
+    
+    @Override
+    public Enumeration<URL> findResources(String name) throws IOException {
+        Enumeration<URL> e = (Enumeration<URL>) delegate.findResources(name);
+        if (isMetaInfResource(name)) {
+            List<URL> allResources = getList();
+            addToList(allResources, e);
+            LinkedHashSet<Bundle> wiredBundles = getWiredBundles();
+            for (Bundle wiredBundle : wiredBundles) {
+                Enumeration<URL> resources = wiredBundle.getResources(name);
+                addToList(allResources, resources);
+            }
+            return Collections.enumeration(allResources);            
+        } else if (e == null) {
+            return Collections.enumeration(Collections.<URL>emptyList());
+        } else {
+            List<URL> allResources = getList();
+            addToList(allResources, e);
+            return Collections.enumeration(allResources);
+        }        
+    }
+    
+    public void setSearchWiredBundles(boolean search) {
+        searchWiredBundles = search;
+    }
+    
+    public boolean getSearchWiredBundles() {
+        return searchWiredBundles;
+    }
+    
+    private synchronized LinkedHashSet<Bundle> getWiredBundles() {
+        if (wiredBundles == null) {
+            wiredBundles = BundleUtils.getWiredBundles(bundle);
+        }
+        return wiredBundles;
+    }
+    
+    private boolean isMetaInfResource(String name) {
+        return searchWiredBundles && name != null && (name.startsWith(META_INF_1)
|| name.startsWith(META_INF_2));
+    }
+          
+    private List<URL> getList() {
+        if (converter == null) {
+            return new ArrayList<URL>();
+        } else {
+            return new ArrayList<URL>() {
+                public boolean add(URL u) {
+                    return super.add(convert(u));
+                }
+            };
+        }
+    }
+    
+    private void addToList(List<URL> list, Enumeration<URL> enumeration) {
+        if (enumeration != null) {
+            while (enumeration.hasMoreElements()) {
+                list.add(enumeration.nextElement());
+            }
+        }
+    }
+           
+    private URL convert(URL url) {
+        try {
+            URL convertedURL = converter.resolve(url);
+            return convertedURL;
+        } catch (IOException e) {
+            e.printStackTrace();
+            return url;
+        }
+    }
+
+    public void initialize() {
+        manager.initialize();
+        if (convertResourceUrls) {
+            BundleContext context = bundle.getBundleContext();
+            if (context != null) {
+                ServiceReference urlReference = context.getServiceReference(URLConverter.class.getName());
+                if (urlReference != null) { 
+                    converter = (URLConverter) context.getService(urlReference);
+                }
+            }
+        }
+    }
+    
+    public void close() {
+        manager.close();      
+    }
+    
+    // other BaseClassLoader methods
+    
+    public ProtectionDomain getDomain() {
+        return domain;
+    }
+        
+    @Override
+    protected String findLibrary(String libname) {
+        // let the manager find the library for us
+        return manager.findLibrary(libname);
+    }
+    
+    public ClasspathEntry createClassPathEntry(BundleFile bundlefile, ProtectionDomain cpDomain)
{
+        return new ClasspathEntry(bundlefile, DefaultClassLoader.createProtectionDomain(bundlefile,
cpDomain));
+    }
+
+    public Class defineClass(String name, byte[] classbytes, ClasspathEntry classpathEntry,
BundleEntry entry) {
+        return defineClass(name, classbytes, 0, classbytes.length, classpathEntry.getDomain());
+    }
+
+    public Class publicFindLoaded(String classname) {
+        return findLoadedClass(classname);
+    }
+
+    public Object publicGetPackage(String pkgname) {
+        return getPackage(pkgname);
+    }
+
+    public Object publicDefinePackage(String name, String specTitle, String specVersion,
String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)
{
+        return definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion,
implVendor, sealBase);
+    }
+
+    public URL findLocalResource(String resource) {
+        return manager.findLocalResource(resource);
+    }
+
+    public Enumeration findLocalResources(String resource) {
+        return manager.findLocalResources(resource);
+    }
+
+    public Class findLocalClass(String classname) throws ClassNotFoundException {
+        return manager.findLocalClass(classname);
+    }
+
+    public void attachFragment(BundleData sourcedata, ProtectionDomain sourcedomain, String[]
sourceclasspath) {
+        manager.attachFragment(sourcedata, sourcedomain, sourceclasspath);
+    }
+
+    public ClassLoaderDelegate getDelegate() {
+        return delegate;
+    }
+
+    public List<URL> findEntries(String path, String filePattern, int options) {
+        return manager.findEntries(path, filePattern, options);
+    }
+
+    public Collection<String> listResources(String path, String filePattern, int options)
{
+        return delegate.listResources(path, filePattern, options);
+    }
+
+    public Collection<String> listLocalResources(String path, String filePattern, int
options) { 
+        return manager.listLocalResources(path, filePattern, options);
+    }
+
+    public ClasspathManager getClasspathManager() {
+        return manager;
+    }
+
+    public Bundle getBundle() {
+        return manager.getBaseData().getBundle();
+    }
+    
+    private static boolean getSearchWiredBundles(boolean defaultValue) {
+        String value = System.getProperty(SEARCH_WIRED_BUNDLES);
+        return (value == null) ? defaultValue : Boolean.parseBoolean(value);        
+    }
+    
+    private static boolean getConvertResourceUrls(boolean defaultValue) {
+        String value = System.getProperty(CONVERT_RESOURCE_URLS);
+        return (value == null) ? defaultValue : Boolean.parseBoolean(value);        
+    }    
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoClassLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoClassLoader.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoClassLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoHookConfigurator.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoHookConfigurator.java?rev=1138728&r1=1138727&r2=1138728&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoHookConfigurator.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/GeronimoHookConfigurator.java
Thu Jun 23 03:43:29 2011
@@ -22,6 +22,9 @@ import org.eclipse.osgi.baseadaptor.Hook
 
 public class GeronimoHookConfigurator implements HookConfigurator {
 
+    /**
+     * Called by Equinox framework.
+     */
     public void addHooks(HookRegistry registry) {
         ClassLoaderHook classLoaderHook = new ClassLoaderHook();
         registry.addClassLoadingHook(classLoaderHook);

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java?rev=1138728&r1=1138727&r2=1138728&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
Thu Jun 23 03:43:29 2011
@@ -56,9 +56,11 @@ import org.apache.geronimo.kernel.Kernel
 import org.apache.geronimo.kernel.NoSuchAttributeException;
 import org.apache.geronimo.kernel.NoSuchOperationException;
 import org.apache.xbean.osgi.bundle.util.BundleClassLoader;
+import org.apache.xbean.osgi.bundle.util.equinox.EquinoxBundleClassLoader;
 import org.apache.geronimo.kernel.config.ManageableAttributeStore;
 import org.apache.geronimo.kernel.management.State;
 import org.apache.geronimo.kernel.management.StateManageable;
+import org.apache.geronimo.kernel.osgi.FrameworkUtils;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.xbean.recipe.ConstructionException;
 import org.apache.xbean.recipe.ObjectRecipe;
@@ -238,7 +240,6 @@ public final class GBeanInstance impleme
         this.lifecycleBroadcaster = lifecycleBroadcaster;
         this.gbeanInstanceState = new GBeanInstanceState(abstractName, kernel, dependencyManager,
this, lifecycleBroadcaster);
         this.bundleContext = bundleContext;
-        this.classLoader = new BundleClassLoader(bundleContext.getBundle());
 
         GBeanInfo gbeanInfo = gbeanData.getGBeanInfo();
         try {
@@ -248,6 +249,12 @@ public final class GBeanInstance impleme
                     " className=" + gbeanInfo.getClassName(), e);
         }
 
+        if (FrameworkUtils.useURLClassLoader() && FrameworkUtils.isEquinox()) {
+            this.classLoader = new EquinoxBundleClassLoader(bundleContext.getBundle());
+        } else {
+            this.classLoader = new BundleClassLoader(bundleContext.getBundle());
+        }
+        
         name = gbeanInfo.getName();
 
         // interfaces

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/FrameworkUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/FrameworkUtils.java?rev=1138728&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/FrameworkUtils.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/FrameworkUtils.java
Thu Jun 23 03:43:29 2011
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.kernel.osgi;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class FrameworkUtils {
+
+    private static final String USE_URL_CLASSLOADER = "org.apache.geronimo.equinox.useURLClassLoader";
+    
+    private static final boolean useURLClassLoader = initUseURLClassLoader();
+    private static final boolean isEquinox = initIsEquinox();
+    
+    private static boolean initUseURLClassLoader() {
+        String property = System.getProperty(USE_URL_CLASSLOADER, "false");
+        return Boolean.parseBoolean(property);        
+    }
+        
+    private static boolean initIsEquinox() {
+        Bundle bundle = FrameworkUtil.getBundle(FrameworkUtils.class);
+        if (bundle != null) {
+            bundle = bundle.getBundleContext().getBundle(0);
+            if (bundle.getSymbolicName().startsWith("org.eclipse.osgi")) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    public static boolean isEquinox() {
+        return isEquinox;
+    }
+    
+    public static boolean useURLClassLoader() {
+        return useURLClassLoader;
+    }
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/FrameworkUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/FrameworkUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/FrameworkUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message