Author: thomas.diesler(a)jboss.com
Date: 2010-03-26 06:07:20 -0400 (Fri, 26 Mar 2010)
New Revision: 103025
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/DynamicImportPackageTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/AbstractClassLoadingDeployer.java
Removed:
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/BundleClassPathTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverSmokeTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleFrameworkTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleLogServiceTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleClassLoadingDeployer.java
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentClassLoadingDeployer.java
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
Log:
[JBCL-131] Add a notion of on demand resolution
Add initial test coverage for DynamicImport-Package
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextTestCase.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextTestCase.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextTestCase.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -212,13 +212,13 @@
public void testInstallBundle() throws Exception
{
URL url = getTestArchiveURL("bundles/jboss-osgi-common.jar");
- Bundle bundle = systemContext.installBundle(url.toExternalForm());
+ Bundle bundle = installBundle(url.toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundle.getState());
assertEquals(url.toExternalForm(), bundle.getLocation());
- Bundle duplicate = systemContext.installBundle(url.toExternalForm());
+ Bundle duplicate = installBundle(url.toExternalForm());
assertSame("Duplicate bundle", bundle, duplicate);
}
finally
@@ -229,7 +229,7 @@
// Test file location
String location = getTestArchivePath("bundles/jboss-osgi-common.jar");
- bundle = systemContext.installBundle(location);
+ bundle = installBundle(location);
try
{
assertBundleState(Bundle.INSTALLED, bundle.getState());
@@ -242,7 +242,7 @@
}
// Test symbolic location
- bundle = systemContext.installBundle("/symbolic/location",
url.openStream());
+ bundle = installBundle("/symbolic/location", url.openStream());
try
{
assertBundleState(Bundle.INSTALLED, bundle.getState());
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/BundleClassPathTestCase.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/BundleClassPathTestCase.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/BundleClassPathTestCase.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -44,7 +44,7 @@
public void testBundleClassPath() throws Exception
{
URL bundleURL = getTestArchiveURL("bundle-classpath.war");
- Bundle bundle = systemContext.installBundle(bundleURL.toExternalForm());
+ Bundle bundle = installBundle(bundleURL.toExternalForm());
bundle.start();
assertEquals("Bundle state", Bundle.ACTIVE, bundle.getState());
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/DynamicImportPackageTestCase.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/DynamicImportPackageTestCase.java
(rev 0)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/DynamicImportPackageTestCase.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -0,0 +1,114 @@
+/*
+* 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.test.osgi.classloader;
+
+import java.io.InputStream;
+
+import org.jboss.osgi.testing.OSGiFrameworkTest;
+import org.jboss.osgi.testing.OSGiManifestBuilder;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.service.log.LogService;
+
+/**
+ * Test the DynamicImport-Package manifest header.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Mar-2010
+ */
+public class DynamicImportPackageTestCase extends OSGiFrameworkTest
+{
+ @Test
+ public void testLogServiceAvailableOnInstall() throws Exception
+ {
+ Bundle cmpd = installBundle("bundles/org.osgi.compendium.jar");
+ try
+ {
+ Bundle bundle = installBundle(getBundleArchive());
+ assertBundleState(Bundle.INSTALLED, bundle.getState());
+ try
+ {
+ bundle.start();
+ assertBundleState(Bundle.ACTIVE, bundle.getState());
+
+ assertLoadClass(bundle, LogService.class.getName());
+ }
+ finally
+ {
+ bundle.uninstall();
+ }
+ }
+ finally
+ {
+ cmpd.uninstall();
+ }
+ }
+
+ @Test
+ public void testLogServiceNotAvailableOnInstall() throws Exception
+ {
+ Bundle bundle = installBundle(getBundleArchive());
+ assertBundleState(Bundle.INSTALLED, bundle.getState());
+ try
+ {
+ bundle.start();
+ assertBundleState(Bundle.ACTIVE, bundle.getState());
+
+ assertLoadClassFail(bundle, LogService.class.getName());
+
+ Bundle cmpd = installBundle("bundles/org.osgi.compendium.jar");
+ try
+ {
+ System.out.println("FIXME [JBCL-131] Add a notion of on demand
resolution");
+ //assertLoadClass(bundle, LogService.class.getName());
+ }
+ finally
+ {
+ cmpd.uninstall();
+ }
+ }
+ finally
+ {
+ bundle.uninstall();
+ }
+ }
+
+ private JavaArchive getBundleArchive()
+ {
+ JavaArchive archive = Archives.create("dynamic-log-service",
JavaArchive.class);
+ archive.setManifest(new Asset()
+ {
+ public InputStream openStream()
+ {
+ OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
+ builder.addBundleManifestVersion(2);
+ builder.addBundleSymbolicName("dynamic-log-service");
+ builder.addDynamicImportPackages("org.osgi.service.log");
+ return builder.openStream();
+ }
+ });
+ return archive;
+ }
+}
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverSmokeTestCase.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverSmokeTestCase.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverSmokeTestCase.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -36,7 +36,6 @@
import org.jboss.test.osgi.AbstractFrameworkTest;
import org.junit.Test;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
/**
* Smoketest for the {@link Resolver}
@@ -47,7 +46,7 @@
public class ResolverSmokeTestCase extends AbstractFrameworkTest
{
@Test
- public void testRandomBundleResolution() throws BundleException
+ public void testRandomBundleResolution() throws Exception
{
List<String> bundlePaths = new ArrayList<String>();
bundlePaths.add("bundles/jboss-osgi-apache-xerces.jar");
@@ -70,7 +69,7 @@
List<Bundle> unresolved = new ArrayList<Bundle>();
for (String path : bundlePaths)
{
- Bundle bundle = systemContext.installBundle(getTestArchivePath(path));
+ Bundle bundle = installBundle(getTestArchivePath(path));
unresolved.add(bundle);
}
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleFrameworkTestCase.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleFrameworkTestCase.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleFrameworkTestCase.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -47,7 +47,7 @@
public void testBundleInstall() throws Exception
{
URL bundleURL = getTestArchiveURL("simple-bundle.jar");
- Bundle bundle = systemContext.installBundle(bundleURL.toExternalForm());
+ Bundle bundle = installBundle(bundleURL.toExternalForm());
assertEquals("simple-bundle", bundle.getSymbolicName());
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleLogServiceTestCase.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleLogServiceTestCase.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleLogServiceTestCase.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -51,7 +51,7 @@
@Test
public void testNoLogService() throws Exception
{
- Bundle bundle =
systemContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
+ Bundle bundle =
installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
try
{
bundle.start();
@@ -70,12 +70,12 @@
@Test
public void testLogServiceFromThirdParty() throws Exception
{
- Bundle logBundle =
systemContext.installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar"));
+ Bundle logBundle =
installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar"));
try
{
logBundle.start();
- Bundle bundle =
systemContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
+ Bundle bundle =
installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
try
{
try
@@ -102,10 +102,10 @@
@Test
public void testLogServiceFromCompendium() throws Exception
{
- Bundle cmpnBundle =
systemContext.installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar"));
+ Bundle cmpnBundle =
installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar"));
try
{
- Bundle bundle =
systemContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
+ Bundle bundle =
installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
try
{
bundle.start();
@@ -132,15 +132,15 @@
@Test
public void testLogServiceFromTwoExporters() throws Exception
{
- Bundle cmpnBundle =
systemContext.installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar"));
+ Bundle cmpnBundle =
installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar"));
try
{
- Bundle logBundle =
systemContext.installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar"));
+ Bundle logBundle =
installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar"));
try
{
logBundle.start();
- Bundle bundle =
systemContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
+ Bundle bundle =
installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
try
{
bundle.start();
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -35,7 +35,7 @@
import org.osgi.framework.Constants;
/**
- * OSGiPackageRequirement.
+ * A classloading requirement that extends a {@link PackageRequirement} by OSGi
metadata.
*
* todo PackagePermission/IMPORT
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
@@ -51,44 +51,44 @@
private AbstractBundleState bundleState;
/** The attributes */
- private PackageAttribute requirePackage;
-
+ private PackageAttribute packageAttribute;
+
/**
* Create a new OSGiPackageRequirement.
*
* @param bundleState the bundle state
- * @param requirePackage the require package metadata
+ * @param packageAttribute the require package metadata
* @return the requirement
* @throws IllegalArgumentException for a null requirePackage
*/
@SuppressWarnings("deprecation")
- public static OSGiPackageRequirement create(AbstractBundleState bundleState,
PackageAttribute requirePackage)
+ public static OSGiPackageRequirement create(AbstractBundleState bundleState,
PackageAttribute packageAttribute, boolean isDynamic)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle");
- if (requirePackage == null)
+ if (packageAttribute == null)
throw new IllegalArgumentException("Null require package");
- String name = requirePackage.getAttribute();
+ String name = packageAttribute.getAttribute();
AbstractVersionRange range = null;
- String versionString =
requirePackage.getAttributeValue(Constants.VERSION_ATTRIBUTE, String.class);
+ String versionString =
packageAttribute.getAttributeValue(Constants.VERSION_ATTRIBUTE, String.class);
if (versionString != null)
{
range = (AbstractVersionRange)AbstractVersionRange.valueOf(versionString);
- String oldVersionString =
requirePackage.getAttributeValue(Constants.PACKAGE_SPECIFICATION_VERSION, String.class);
+ String oldVersionString =
packageAttribute.getAttributeValue(Constants.PACKAGE_SPECIFICATION_VERSION,
String.class);
if (oldVersionString != null && oldVersionString.equals(versionString)
== false)
throw new IllegalStateException(Constants.VERSION_ATTRIBUTE + " of
" + versionString + " does not match " +
Constants.PACKAGE_SPECIFICATION_VERSION
+ " of " + oldVersionString);
}
else
{
- versionString =
requirePackage.getAttributeValue(Constants.PACKAGE_SPECIFICATION_VERSION, String.class);
+ versionString =
packageAttribute.getAttributeValue(Constants.PACKAGE_SPECIFICATION_VERSION,
String.class);
if (versionString != null)
range = (AbstractVersionRange)AbstractVersionRange.valueOf(versionString);
}
- return new OSGiPackageRequirement(bundleState, name, range, requirePackage);
+ return new OSGiPackageRequirement(bundleState, name, range, packageAttribute,
isDynamic);
}
/**
@@ -97,21 +97,28 @@
* @param bundleState the bundleState
* @param name the name
* @param versionRange the version range - pass null for all versions
- * @param requirePackage the require package metadata
+ * @param packageAttribute the require package metadata
* @throws IllegalArgumentException for a null name or requirePackage
*/
- public OSGiPackageRequirement(AbstractBundleState bundleState, String name,
VersionRange versionRange, PackageAttribute requirePackage)
+ public OSGiPackageRequirement(AbstractBundleState bundleState, String name,
VersionRange versionRange, PackageAttribute packageAttribute, boolean isDynamic)
{
super(name, versionRange);
+ if (bundleState == null)
+ throw new IllegalArgumentException("Null bundleState");
+ if (packageAttribute == null)
+ throw new IllegalArgumentException("Null packageAttribute");
+
this.bundleState = bundleState;
+ this.packageAttribute = packageAttribute;
- if (requirePackage != null)
- {
- this.requirePackage = requirePackage;
- String resolution =
requirePackage.getDirectiveValue(Constants.RESOLUTION_DIRECTIVE, String.class);
- if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
- setOptional(true);
- }
+ // resolution:=optional
+ String resolution =
packageAttribute.getDirectiveValue(Constants.RESOLUTION_DIRECTIVE, String.class);
+ if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
+ setOptional(true);
+
+ // DynamicImport-Package
+ if (isDynamic == true)
+ setDynamic(true);
}
/**
@@ -121,7 +128,7 @@
*/
public PackageAttribute getPackageMetaData()
{
- return requirePackage;
+ return packageAttribute;
}
/**
@@ -134,7 +141,7 @@
Module module = null;
if (bundleState instanceof AbstractDeployedBundleState)
{
- AbstractDeployedBundleState depBundle =
(AbstractDeployedBundleState)bundleState;
+ AbstractDeployedBundleState depBundle =
(AbstractDeployedBundleState)bundleState;
DeploymentUnit unit = depBundle.getDeploymentUnit();
module = unit.getAttachment(Module.class);
if (module == null)
@@ -142,7 +149,7 @@
}
return module;
}
-
+
@Override
public boolean equals(Object obj)
{
@@ -152,18 +159,19 @@
return false;
if (super.equals(obj) == false)
return false;
-
+
return true;
}
private String shortString;
+
public String toShortString()
{
if (shortString == null)
{
StringBuffer buffer = new StringBuffer(bundleState.getCanonicalName() +
"[" + getName());
- Map<String, Parameter> attributes = requirePackage.getAttributes();
- Map<String, Parameter> directives = requirePackage.getDirectives();
+ Map<String, Parameter> attributes = packageAttribute.getAttributes();
+ Map<String, Parameter> directives = packageAttribute.getDirectives();
for (Map.Entry<String, Parameter> entry : directives.entrySet())
buffer.append(";" + entry.getKey() + ":=" +
entry.getValue().getValue());
for (Map.Entry<String, Parameter> entry : attributes.entrySet())
@@ -173,7 +181,7 @@
}
return shortString;
}
-
+
@Override
protected void toString(StringBuffer buffer)
{
Copied:
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/AbstractClassLoadingDeployer.java
(from rev 103005,
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java)
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/AbstractClassLoadingDeployer.java
(rev 0)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/AbstractClassLoadingDeployer.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -0,0 +1,169 @@
+/*
+* 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.deployers;
+
+// $Id$
+
+import java.util.List;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.RequirementsMetaData;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.AbstractBundleState;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.classloading.OSGiBundleCapability;
+import org.jboss.osgi.framework.classloading.OSGiBundleRequirement;
+import org.jboss.osgi.framework.classloading.OSGiClassLoadingMetaData;
+import org.jboss.osgi.framework.classloading.OSGiPackageCapability;
+import org.jboss.osgi.framework.classloading.OSGiPackageRequirement;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.PackageAttribute;
+import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
+import org.jboss.osgi.framework.plugins.SystemPackagesPlugin;
+
+/**
+ * An abstract OSGi classloading deployer, that maps {@link OSGiMetaData} into {@link
ClassLoadingMetaData}.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 07-Jan-2010
+ */
+public class AbstractClassLoadingDeployer extends
AbstractSimpleRealDeployer<OSGiMetaData>
+{
+ private ClassLoaderDomain domain;
+ private ClassLoaderFactory factory;
+
+ public AbstractClassLoadingDeployer()
+ {
+ super(OSGiMetaData.class);
+ addInput(AbstractBundleState.class);
+ setOutput(ClassLoadingMetaData.class);
+ setStage(DeploymentStages.POST_PARSE);
+ setTopLevelOnly(true);
+ }
+
+ public void setDomain(ClassLoaderDomain domain)
+ {
+ this.domain = domain;
+ }
+
+ public void setFactory(ClassLoaderFactory factory)
+ {
+ this.factory = factory;
+ }
+
+ @Override
+ public void deploy(DeploymentUnit unit, OSGiMetaData osgiMetaData) throws
DeploymentException
+ {
+ if (unit.isAttachmentPresent(ClassLoadingMetaData.class))
+ return;
+
+ AbstractBundleState bundleState = unit.getAttachment(AbstractBundleState.class);
+ if (bundleState == null)
+ throw new IllegalStateException("No bundle state");
+
+ OSGiBundleManager bundleManager = bundleState.getBundleManager();
+
+ OSGiClassLoadingMetaData classLoadingMetaData = new OSGiClassLoadingMetaData();
+ classLoadingMetaData.setName(bundleState.getSymbolicName());
+ classLoadingMetaData.setVersion(bundleState.getVersion());
+ classLoadingMetaData.setDomain(domain != null ? domain.getName() : null);
+
+ CapabilitiesMetaData capabilities = classLoadingMetaData.getCapabilities();
+ RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
+
+ OSGiBundleCapability bundleCapability = OSGiBundleCapability.create(bundleState);
+ capabilities.addCapability(bundleCapability);
+
+ // Required Bundles
+ List<ParameterizedAttribute> requireBundles =
osgiMetaData.getRequireBundles();
+ if (requireBundles != null && requireBundles.isEmpty() == false)
+ {
+ for (ParameterizedAttribute requireBundle : requireBundles)
+ {
+ OSGiBundleRequirement requirement =
OSGiBundleRequirement.create(requireBundle);
+ requirements.addRequirement(requirement);
+ }
+ }
+
+ // Export-Package
+ List<PackageAttribute> exports = osgiMetaData.getExportPackages();
+ if (exports != null && exports.isEmpty() == false)
+ {
+ for (PackageAttribute packageAttribute : exports)
+ {
+ OSGiPackageCapability packageCapability =
OSGiPackageCapability.create(bundleState, packageAttribute);
+ capabilities.addCapability(packageCapability);
+ }
+ }
+
+ // Import-Package
+ List<PackageAttribute> imports = osgiMetaData.getImportPackages();
+ if (imports != null && imports.isEmpty() == false)
+ {
+ SystemPackagesPlugin syspackPlugin =
bundleManager.getPlugin(SystemPackagesPlugin.class);
+ for (PackageAttribute packageAttribute : imports)
+ {
+ String packageName = packageAttribute.getAttribute();
+
+ // [TODO] Should system packages be added as capabilities?
+ if (syspackPlugin.isSystemPackage(packageName) == true)
+ continue;
+
+ OSGiPackageRequirement requirement =
OSGiPackageRequirement.create(bundleState, packageAttribute, false);
+ requirements.addRequirement(requirement);
+ }
+ }
+
+ // DynamicImport-Package
+ List<PackageAttribute> dynamicImports = osgiMetaData.getDynamicImports();
+ if (dynamicImports != null && dynamicImports.isEmpty() == false)
+ {
+ SystemPackagesPlugin syspackPlugin =
bundleManager.getPlugin(SystemPackagesPlugin.class);
+ for (PackageAttribute packageAttribute : dynamicImports)
+ {
+ String packageName = packageAttribute.getAttribute();
+
+ // [TODO] Should system packages be added as capabilities?
+ if (syspackPlugin.isSystemPackage(packageName) == true)
+ continue;
+
+ OSGiPackageRequirement requirement =
OSGiPackageRequirement.create(bundleState, packageAttribute, true);
+ requirements.addRequirement(requirement);
+ }
+ }
+
+ unit.addAttachment(ClassLoadingMetaData.class, classLoadingMetaData);
+
+ // AnnotationMetaDataDeployer.ANNOTATION_META_DATA_COMPLETE
+ unit.addAttachment("org.jboss.deployment.annotation.metadata.complete",
Boolean.TRUE);
+
+ // Add the OSGi ClassLoaderFactory if configured
+ if (factory != null)
+ unit.addAttachment(ClassLoaderFactory.class, factory);
+ }
+}
Deleted:
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -1,152 +0,0 @@
-/*
-* 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.deployers;
-
-// $Id$
-
-import java.util.List;
-
-import org.jboss.classloader.spi.ClassLoaderDomain;
-import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
-import org.jboss.classloading.spi.metadata.RequirementsMetaData;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.ClassLoaderFactory;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.classloading.OSGiBundleCapability;
-import org.jboss.osgi.framework.classloading.OSGiBundleRequirement;
-import org.jboss.osgi.framework.classloading.OSGiClassLoadingMetaData;
-import org.jboss.osgi.framework.classloading.OSGiPackageCapability;
-import org.jboss.osgi.framework.classloading.OSGiPackageRequirement;
-import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.framework.metadata.PackageAttribute;
-import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
-import org.jboss.osgi.framework.plugins.SystemPackagesPlugin;
-
-/**
- * An abstract OSGi classloading deployer, that maps {@link OSGiMetaData} into {@link
ClassLoadingMetaData}.
- *
- * @author thomas.diesler(a)jboss.com
- * @since 07-Jan-2010
- */
-public class AbstractOSGiClassLoadingDeployer extends
AbstractSimpleRealDeployer<OSGiMetaData>
-{
- private ClassLoaderDomain domain;
- private ClassLoaderFactory factory;
-
- public AbstractOSGiClassLoadingDeployer()
- {
- super(OSGiMetaData.class);
- addInput(AbstractBundleState.class);
- setOutput(ClassLoadingMetaData.class);
- setStage(DeploymentStages.POST_PARSE);
- setTopLevelOnly(true);
- }
-
- public void setDomain(ClassLoaderDomain domain)
- {
- this.domain = domain;
- }
-
- public void setFactory(ClassLoaderFactory factory)
- {
- this.factory = factory;
- }
-
- @Override
- public void deploy(DeploymentUnit unit, OSGiMetaData osgiMetaData) throws
DeploymentException
- {
- if (unit.isAttachmentPresent(ClassLoadingMetaData.class))
- return;
-
- AbstractBundleState bundleState = unit.getAttachment(AbstractBundleState.class);
- if (bundleState == null)
- throw new IllegalStateException("No bundle state");
-
- OSGiBundleManager bundleManager = bundleState.getBundleManager();
-
- OSGiClassLoadingMetaData classLoadingMetaData = new OSGiClassLoadingMetaData();
- classLoadingMetaData.setName(bundleState.getSymbolicName());
- classLoadingMetaData.setVersion(bundleState.getVersion());
- classLoadingMetaData.setDomain(domain != null ? domain.getName() : null);
-
- CapabilitiesMetaData capabilities = classLoadingMetaData.getCapabilities();
- RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
-
- OSGiBundleCapability bundleCapability = OSGiBundleCapability.create(bundleState);
- capabilities.addCapability(bundleCapability);
-
- // Required Bundles
- List<ParameterizedAttribute> requireBundles =
osgiMetaData.getRequireBundles();
- if (requireBundles != null && requireBundles.isEmpty() == false)
- {
- for (ParameterizedAttribute requireBundle : requireBundles)
- {
- OSGiBundleRequirement requirement =
OSGiBundleRequirement.create(requireBundle);
- requirements.addRequirement(requirement);
- }
- }
-
- // Export Packages
- List<PackageAttribute> exported = osgiMetaData.getExportPackages();
- if (exported != null && exported.isEmpty() == false)
- {
- for (PackageAttribute packageAttribute : exported)
- {
- OSGiPackageCapability packageCapability =
OSGiPackageCapability.create(bundleState, packageAttribute);
- capabilities.addCapability(packageCapability);
- }
- }
-
- // Import Packages
- List<PackageAttribute> imported = osgiMetaData.getImportPackages();
- if (imported != null && imported.isEmpty() == false)
- {
- SystemPackagesPlugin syspackPlugin =
bundleManager.getPlugin(SystemPackagesPlugin.class);
- for (PackageAttribute packageAttribute : imported)
- {
- String packageName = packageAttribute.getAttribute();
-
- // [TODO] Should system packages be added as capabilities?
- boolean isSystemPackage = syspackPlugin.isSystemPackage(packageName);
- if (isSystemPackage == false)
- {
- OSGiPackageRequirement requirement =
OSGiPackageRequirement.create(bundleState, packageAttribute);
- requirements.addRequirement(requirement);
- }
- }
- }
-
- unit.addAttachment(ClassLoadingMetaData.class, classLoadingMetaData);
-
- // AnnotationMetaDataDeployer.ANNOTATION_META_DATA_COMPLETE
- unit.addAttachment("org.jboss.deployment.annotation.metadata.complete",
Boolean.TRUE);
-
- // Add the OSGi ClassLoaderFactory if configured
- if (factory != null)
- unit.addAttachment(ClassLoaderFactory.class, factory);
- }
-}
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleClassLoadingDeployer.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleClassLoadingDeployer.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleClassLoadingDeployer.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -36,7 +36,7 @@
* @author thomas.diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class OSGiBundleClassLoadingDeployer extends AbstractOSGiClassLoadingDeployer
+public class OSGiBundleClassLoadingDeployer extends AbstractClassLoadingDeployer
{
@Override
public void deploy(DeploymentUnit unit, OSGiMetaData osgiMetaData) throws
DeploymentException
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentClassLoadingDeployer.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentClassLoadingDeployer.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentClassLoadingDeployer.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -42,7 +42,7 @@
* @author thomas.diesler(a)jboss.com
* @since 07-Jan-2010
*/
-public class OSGiFragmentClassLoadingDeployer extends AbstractOSGiClassLoadingDeployer
+public class OSGiFragmentClassLoadingDeployer extends AbstractClassLoadingDeployer
{
@Override
public void deploy(DeploymentUnit unit, OSGiMetaData osgiMetaData) throws
DeploymentException
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2010-03-26
10:01:44 UTC (rev 103024)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2010-03-26
10:07:20 UTC (rev 103025)
@@ -452,7 +452,7 @@
Object version = otherPackage.getVersion();
VersionRange versionRange = new VersionRange(version, true, version,
true);
- OSGiPackageRequirement newPackageRequirement = new
OSGiPackageRequirement(bundle, packageName, versionRange, null);
+ OSGiPackageRequirement newPackageRequirement = new
OSGiPackageRequirement(bundle, packageName, versionRange, null, false);
BundleRequirement newBundleRequirement = new BundleRequirement(bundle,
newPackageRequirement);
newBundleRequirement.wireCapability(otherCapability);
bundleRequirements.add(newBundleRequirement);
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml 2010-03-26 10:01:44 UTC
(rev 103024)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml 2010-03-26 10:07:20 UTC
(rev 103025)
@@ -55,7 +55,7 @@
<version.apache.felix.configadmin>1.0.10</version.apache.felix.configadmin>
<version.apache.felix.log>1.0.0</version.apache.felix.log>
<version.apache.felix.metatype>1.0.2</version.apache.felix.metatype>
- <version.jboss.classloading>2.2.0.Alpha4</version.jboss.classloading>
+ <version.jboss.classloading>2.2.0-SNAPSHOT</version.jboss.classloading>
<version.jboss.deployers>2.2.0.Alpha4</version.jboss.deployers>
<version.jboss.kernel>2.2.0.Alpha9</version.jboss.kernel>
<version.jboss.logging>2.2.0.CR1</version.jboss.logging>