Skip to content

Commit

Permalink
[JBOSGI-389] Bundle classloader does not implement BundleReference
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Diesler committed Dec 16, 2010
1 parent 9709148 commit b2ed272
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 24 deletions.
1 change: 1 addition & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<!--
Set these VM properties in your IDE debugger
-Djava.util.logging.manager=org.jboss.logmanager.LogManager
-Dtest.archive.directory=${workspace_loc:jbosgi-framework-core/target}/test-libs
-Dmodule.path=${workspace_loc:jbosgi-framework-core/target}/test-modules
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,31 @@
import org.jboss.osgi.resolver.XPackageRequirement;
import org.jboss.osgi.vfs.VFSUtils;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleReference;

/**
* An OSGi extention to the {@link ModuleClassLoader}.
* A fallback loader that takes care of dynamic class loads.
*
* @author thomas.diesler@jboss.com
* @since 29-Jun-2010
*/
public class ModuleClassLoaderExt implements LocalLoader, BundleReference
public class BundleFallbackLoader implements LocalLoader
{
// Provide logging
private static final Logger log = Logger.getLogger(ModuleClassLoaderExt.class);
private static final Logger log = Logger.getLogger(BundleFallbackLoader.class);

private static ThreadLocal<Map<String, AtomicInteger>> dynamicLoadAttempts;
private final ModuleManagerPlugin moduleManager;
private final BundleManager bundleManager;
private final ModuleIdentifier id;

public ModuleClassLoaderExt(BundleManager bundleManager, ModuleIdentifier id)
public BundleFallbackLoader(BundleManager bundleManager, ModuleIdentifier id)
{
this.bundleManager = bundleManager;
this.id = id;

moduleManager = bundleManager.getPlugin(ModuleManagerPlugin.class);
}

@Override
public Bundle getBundle()
{
AbstractBundle bundleState = moduleManager.getBundleState(id);
return bundleState.getBundleWrapper();
}

@Override
public Class<?> loadClassLocal(String className, boolean resolve)
{
Expand Down Expand Up @@ -252,14 +244,12 @@ private Class<?> findInUnresolvedModules(String className)
@Override
public List<Resource> loadResourceLocal(String name)
{
// TODO Auto-generated method stub
return Collections.emptyList();
}

@Override
public Resource loadResourceLocal(String root, String name)
{
// TODO Auto-generated method stub
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.osgi.framework.loading;

import org.jboss.modules.ModuleClassLoader;
import org.jboss.modules.ModuleClassLoaderFactory;
import org.jboss.osgi.framework.bundle.AbstractBundle;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleReference;

/**
* The {@link ModuleClassLoader} for a bundle.
*
* @author thomas.diesler@jboss.com
* @since 16-Dec-2010
*/
public class BundleModuleClassLoader extends ModuleClassLoader implements BundleReference
{
private AbstractBundle bundleState;

private BundleModuleClassLoader(AbstractBundle bundleState, Configuration configuration)
{
super(configuration);
this.bundleState = bundleState;
}

@Override
public Bundle getBundle()
{
return bundleState.getBundleWrapper();
}

public static class Factory implements ModuleClassLoaderFactory
{
private AbstractBundle bundleState;
public Factory(AbstractBundle bundleState)
{
this.bundleState = bundleState;
}

@Override
public ModuleClassLoader create(Configuration configuration)
{
return new BundleModuleClassLoader(bundleState, configuration);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
import org.jboss.osgi.framework.bundle.HostBundle;
import org.jboss.osgi.framework.bundle.OSGiModuleLoader;
import org.jboss.osgi.framework.loading.FragmentLocalLoader;
import org.jboss.osgi.framework.loading.BundleModuleClassLoader;
import org.jboss.osgi.framework.loading.FrameworkLocalLoader;
import org.jboss.osgi.framework.loading.ModuleClassLoaderExt;
import org.jboss.osgi.framework.loading.BundleFallbackLoader;
import org.jboss.osgi.framework.loading.NativeLibraryProvider;
import org.jboss.osgi.framework.loading.NativeResourceLoader;
import org.jboss.osgi.framework.loading.VirtualFileResourceLoader;
Expand Down Expand Up @@ -236,6 +237,7 @@ private ModuleIdentifier createFrameworkModule(final XModule resModule)

FrameworkLocalLoader frameworkLoader = new FrameworkLocalLoader(getBundleManager());
specBuilder.addDependency(DependencySpec.createLocalDependencySpec(frameworkLoader, frameworkLoader.getExportedPaths(), true));
specBuilder.setModuleClassLoaderFactory(new BundleModuleClassLoader.Factory(getBundleManager().getSystemBundle()));

ModuleSpec frameworkSpec = specBuilder.create();
moduleLoader.addModule(bundleRev, frameworkSpec);
Expand Down Expand Up @@ -326,7 +328,8 @@ private ModuleIdentifier createModule(final XModule resModule, List<VirtualFile>
specBuilder.addResourceRoot(nativeLoader);
}

specBuilder.setFallbackLoader(new ModuleClassLoaderExt(getBundleManager(), identifier));
specBuilder.setModuleClassLoaderFactory(new BundleModuleClassLoader.Factory(bundleState));
specBuilder.setFallbackLoader(new BundleFallbackLoader(getBundleManager(), identifier));

// Build the ModuleSpec
moduleSpec = specBuilder.create();
Expand Down
2 changes: 1 addition & 1 deletion itest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<!--
Set these VM properties in your IDE debugger
-Djava.util.logging.manager=org.jboss.logmanager.LogManager
-Dtest.archive.directory=${workspace_loc:jbosgi-framework-itest/target}/test-libs
-Dlog4j.configuration=log4j-console.xml
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.jboss.test.osgi.framework.bundle.update.b.ClassB;
import org.jboss.test.osgi.framework.bundle.update.startexc.BundleStartExActivator;
import org.jboss.test.osgi.framework.bundle.update.stopexc.BundleStopExActivator;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.osgi.framework.Bundle;
Expand Down Expand Up @@ -537,7 +536,6 @@ public void testGetHeaders() throws Exception
}

@Test
@Ignore("[JBOSGI-389] Bundle classloader does not implement BundleReference")
public void testBundleReference() throws Exception
{
Archive<?> assembly = assembleArchive("bundle1", "/bundles/update/update-bundle1", ObjectA.class);
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<version.apache.felix.log>1.0.0</version.apache.felix.log>
<version.javax.inject>1</version.javax.inject>
<version.jboss.arquillian>1.0.0.Alpha4.SP5-SNAPSHOT</version.jboss.arquillian>
<version.jboss.logmanager>1.2.0.CR7</version.jboss.logmanager>
<version.jboss.logmanager.log4j>1.0.0.CR3</version.jboss.logmanager.log4j>
<version.jboss.logmanager>1.2.0.CR8</version.jboss.logmanager>
<version.jboss.logging>3.0.0.Beta4</version.jboss.logging>
<version.jboss.msc>1.0.0.Beta5-SNAPSHOT</version.jboss.msc>
<version.jboss.modules>1.0.0.Beta12-SNAPSHOT</version.jboss.modules>
<version.jboss.osgi.deployment>1.0.9</version.jboss.osgi.deployment>
Expand All @@ -67,9 +67,9 @@
<version>${version.jboss.logmanager}</version>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager-log4j</artifactId>
<version>${version.jboss.logmanager.log4j}</version>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${version.jboss.logging}</version>
</dependency>
<dependency>
<groupId>org.jboss.modules</groupId>
Expand Down

0 comments on commit b2ed272

Please sign in to comment.