JBoss-OSGI SVN: r96190 - in projects/jboss-osgi/trunk/reactor/framework/src: test/java/org/jboss/test/osgi and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-09 14:22:02 -0500 (Mon, 09 Nov 2009)
New Revision: 96190
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
Log:
Consistently use framework launch API
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2009-11-09 19:20:18 UTC (rev 96189)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2009-11-09 19:22:02 UTC (rev 96190)
@@ -68,7 +68,7 @@
{
super(bundleManager);
}
-
+
public List<Resolvable> getBundles()
{
List<Resolvable> values = new ArrayList<Resolvable>(resolverBundleMap.values());
@@ -93,7 +93,7 @@
}
return Collections.unmodifiableList(resolvedBundles);
}
-
+
/**
* Resolve the given list of bundles.
*
@@ -109,9 +109,10 @@
// Normalize to OSGiBundleState instances
List<OSGiBundleState> unresolvedBundles = new ArrayList<OSGiBundleState>();
- for (Bundle bundle : bundles)
+ for (Bundle aux : bundles)
{
- unresolvedBundles.add(OSGiBundleState.assertBundleState(bundle));
+ if (aux.getBundleId() != 0)
+ unresolvedBundles.add(OSGiBundleState.assertBundleState(aux));
}
int resolved = 1;
@@ -123,7 +124,7 @@
{
allCapabilities.addAll(list);
}
-
+
List<OSGiBundleState> resolvedBundles = new ArrayList<OSGiBundleState>();
while (resolved > 0 && unresolvedBundles.isEmpty() == false)
{
@@ -173,9 +174,9 @@
public Resolvable removeBundle(Bundle bundle)
{
OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
-
+
bundleCapabilitiesMap.remove(bundleState);
-
+
List<BundleRequirement> bundleRequirements = bundleRequirementsMap.remove(bundleState);
if (bundleRequirements != null)
{
@@ -184,7 +185,7 @@
requirement.unwireCapability();
}
}
-
+
return null;
}
@@ -194,7 +195,7 @@
BundleCapability match = getMatchingCapability(bundleState, importPackage);
if (match == null)
return null;
-
+
OSGiBundleState exportingBundle = match.getExportingBundle();
Resolvable resolverBundle = resolverBundleMap.get(exportingBundle);
return resolverBundle.getExportPackage(importPackage);
@@ -266,7 +267,7 @@
{
// Log the package wiring information
StringBuffer message = new StringBuffer("Resolved: " + bundle);
-
+
// Log the exports
int nameLengthMax = 0;
for (BundleCapability capability : bundleCapabilities)
@@ -289,7 +290,7 @@
for (String line : lines)
message.append(line);
}
-
+
// Log the imports
nameLengthMax = 0;
for (BundleRequirement requirement : bundleRequirements)
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestCase.java 2009-11-09 19:20:18 UTC (rev 96189)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestCase.java 2009-11-09 19:22:02 UTC (rev 96190)
@@ -31,9 +31,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.deployers.client.spi.DeployerClient;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
import org.jboss.osgi.framework.bundle.AbstractBundleState;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.spi.util.ConstantsHelper;
@@ -98,16 +96,6 @@
}
/**
- * Get DeployerClient from Delegate
- *
- * @return The DeployerClient
- */
- protected DeployerClient getDeployerClient()
- {
- return getDelegate().getMainDeployer();
- }
-
- /**
* Get BundleManager from Delegate
*
* @return The BundleManager
@@ -178,16 +166,6 @@
return getDelegate().getDeploymentUnit(bundle);
}
- /**
- * Get MainDeployerStructure from Delegate
- *
- * @return MainDeployerStructure
- */
- protected MainDeployerStructure getMainDeployerStructure()
- {
- return getDelegate().getMainDeployer();
- }
-
protected Bundle assembleBundle(String name, String resources, Class<?>... packages) throws Exception
{
return getDelegate().assembleBundle(name, new String[] { resources }, packages);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java 2009-11-09 19:20:18 UTC (rev 96189)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java 2009-11-09 19:22:02 UTC (rev 96190)
@@ -21,19 +21,19 @@
*/
package org.jboss.test.osgi;
-import java.lang.reflect.Method;
+// $Id: $
+
import java.net.URL;
-import java.util.Collection;
import java.util.Enumeration;
import junit.framework.AssertionFailedError;
import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.deployers.plugins.main.MainDeployerImpl;
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.launch.OSGiFramework;
+import org.jboss.osgi.spi.util.ServiceLoader;
import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
import org.jboss.virtual.AssembledDirectory;
import org.jboss.virtual.VFS;
@@ -42,134 +42,41 @@
import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.FrameworkFactory;
/**
* A OSGiTestDelegate
*
* @author <a href="baileyje(a)gmail.com">John Bailey</a>
- * @version $Revision: 87848 $
+ * @author Thomas.Diesler(a)jboss.com
*/
public class OSGiTestDelegate extends MicrocontainerTestDelegate
{
- private MainDeployerImpl mainDeployer;
private OSGiBundleManager bundleManager;
- static
- {
- //FIXME the vfs is not initialising itself properly
- VFS.init();
- try
- {
- VFS.getRoot(new URL("file:/"));
- }
- catch (Exception ignored) {}
- }
-
/**
* Create a new OSGiTestDelegate.
- *
- * @param clazz
- * @throws Exception
*/
public OSGiTestDelegate(Class<?> clazz) throws Exception
{
super(clazz);
}
- /**
- * Deploys the jboss-osgi-bootstrap.xml bean descriptor to setup OSGi deployers
- */
- protected void deploy() throws Exception
- {
- URL url = getClass().getResource("/META-INF/jboss-osgi-bootstrap.xml");
- if (url == null)
- throw new IllegalStateException("Cannot find: jboss-osgi-bootstrap.xml");
- deploy(url);
- try
- {
- super.deploy();
- deployBundles();
- }
- catch (Throwable t)
- {
- undeploy();
- if (t instanceof Exception)
- throw (Exception) t;
- if (t instanceof Error)
- throw (Error) t;
- throw new RuntimeException("Error during deploy", t);
- }
- }
-
- protected void undeploy()
- {
- undeployBundles();
- super.undeploy();
- }
-
- protected void deployBundles() throws Exception
- {
- try
- {
- Method method = clazz.getMethod("deployBundles", new Class[] { OSGiTestDelegate.class });
- log.debug("Deploying Bundles...");
- method.invoke(null, this);
- }
- catch (NoSuchMethodException e)
- {
- log.debug("No deployBundles() in " + clazz.getName());
- }
- }
-
- protected void undeployBundles()
- {
- OSGiBundleManager bundleManager = getBundleManager();
- Collection<AbstractBundleState> bundles = bundleManager.getBundles();
- for (AbstractBundleState bundleState : bundles)
- {
- try
- {
- if (bundleState.getBundleId() != 0)
- bundleManager.uninstall(bundleState);
- }
- catch (Throwable t)
- {
- getLog().warn("Error undeploying bundle: " + bundleState, t);
- }
- }
- }
-
- /**
- * Get the MainDeployer bean from the MC
- *
- * @return MainDeployerImpl
- */
- protected MainDeployerImpl getMainDeployer()
- {
- if (mainDeployer == null)
- mainDeployer = getBean("MainDeployer", ControllerState.INSTALLED, MainDeployerImpl.class);
- return mainDeployer;
- }
-
- /**
- * Get the BundleManager bean from the MC
- *
- * @return the BundleManager
- */
protected OSGiBundleManager getBundleManager()
{
if (bundleManager == null)
{
- bundleManager = getBean("OSGiBundleManager", ControllerState.INSTALLED, OSGiBundleManager.class);
+ FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
+ OSGiFramework framework = (OSGiFramework)factory.newFramework(null);
try
{
- if (bundleManager.isActive() == false)
- bundleManager.startFramework();
+ framework.start();
}
catch (BundleException ex)
{
- throw new IllegalStateException("Cannot start bundle manager", ex);
+ throw new IllegalStateException("Cannot start framework", ex);
}
+ bundleManager = framework.getBundleManager();
}
return bundleManager;
}
@@ -177,7 +84,7 @@
/**
* Create a bundle
*
- * @param root the location of the location to deploy
+ * @param root the location to deploy
* @param child the child to deploy
* @return Bundle for the deployment
* @throws Exception for any error
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2009-11-09 19:20:18 UTC (rev 96189)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2009-11-09 19:22:02 UTC (rev 96190)
@@ -25,9 +25,7 @@
import java.util.Hashtable;
import org.jboss.test.osgi.OSGiTestCase;
-import org.jboss.test.osgi.OSGiTestDelegate;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
@@ -40,37 +38,24 @@
*/
public class SystemBundleUnitTestCase extends OSGiTestCase
{
- /** The system bundle */
- private static Bundle systemBundle = null;
-
public SystemBundleUnitTestCase(String name)
{
super(name);
}
- public static void deployBundles(OSGiTestDelegate delegate) throws Exception
- {
- Bundle bundle = delegate.addBundle("/bundles/simple/", "simple-bundle1");
- bundle.start();
- BundleContext context = bundle.getBundleContext();
- assertNotNull(context);
- systemBundle = context.getBundle(0);
- assertNotNull(systemBundle);
- }
-
public void testBundleId() throws Exception
{
- assertEquals(0, systemBundle.getBundleId());
+ assertEquals(0, getSystemBundle().getBundleId());
}
public void testSymbolicName() throws Exception
{
- assertEquals(Constants.SYSTEM_BUNDLE_SYMBOLICNAME, systemBundle.getSymbolicName());
+ assertEquals(Constants.SYSTEM_BUNDLE_SYMBOLICNAME, getSystemBundle().getSymbolicName());
}
public void testState() throws Exception
{
- assertEquals(Bundle.ACTIVE, systemBundle.getState());
+ assertEquals(Bundle.ACTIVE, getSystemBundle().getState());
}
public void testStartStop() throws Exception
@@ -87,7 +72,7 @@
{
try
{
- systemBundle.uninstall();
+ getSystemBundle().uninstall();
fail("Should not be here!");
}
catch (Throwable t)
@@ -106,13 +91,13 @@
// todo expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
// todo expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "r4v41");
- Dictionary dictionary = systemBundle.getHeaders();
+ Dictionary dictionary = getSystemBundle().getHeaders();
assertEquals(expected, dictionary);
}
public void testLocation() throws Exception
{
- assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, systemBundle.getLocation());
+ assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, getSystemBundle().getLocation());
}
public void testGetEntry()
14 years, 6 months
JBoss-OSGI SVN: r96183 - in projects/jboss-osgi/trunk/reactor/framework/src: main/java/org/jboss/osgi/framework/classloading and 9 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: adrian(a)jboss.org
Date: 2009-11-09 12:30:32 -0500 (Mon, 09 Nov 2009)
New Revision: 96183
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleRequirement.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/ParameterizedAttribute.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractOSGiMetaData.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractPackageAttribute.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractParameterizedAttribute.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/ManifestParser.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ImportDirectiveResolutionTest.java
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/singleton/singleton1/META-INF/MANIFEST.MF
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/singleton/singleton2/META-INF/MANIFEST.MF
Log:
[JBOSGI-200] - Split parameters into attributes and directives - also completed validation of bundles at install
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -36,6 +36,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Dictionary;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@@ -64,6 +65,7 @@
import org.jboss.kernel.Kernel;
import org.jboss.logging.Logger;
import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.PackageAttribute;
import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
import org.jboss.osgi.framework.plugins.AutoInstallPlugin;
import org.jboss.osgi.framework.plugins.ResolverPlugin;
@@ -612,18 +614,7 @@
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
- // todo more validation
- OSGiMetaData metaData = bundleState.getOSGiMetaData();
- if (metaData.isSingleton())
- {
- String symbolicName = metaData.getBundleSymbolicName();
- for (AbstractBundleState bundle : getBundles())
- {
- OSGiMetaData other = bundle.getOSGiMetaData();
- if (other.isSingleton() && symbolicName.equals(other.getBundleSymbolicName()))
- throw new IllegalStateException("Cannot install singleton " + bundleState + " another singleton is already installed: " + bundle);
- }
- }
+ validateBundle(bundleState);
bundleState.setBundleManager(this);
bundles.add(bundleState);
@@ -642,6 +633,69 @@
}
/**
+ * Validate the bundle
+ *
+ * @param bundleState the bundle state
+ */
+ private void validateBundle(AbstractBundleState bundleState)
+ {
+
+ OSGiMetaData metaData = bundleState.getOSGiMetaData();
+
+ String symbolicName = metaData.getBundleSymbolicName();
+ if (symbolicName == null)
+ throw new IllegalStateException("No bundle symbolic name " + bundleState);
+
+ int manifestVersion = metaData.getBundleManifestVersion();
+ if (manifestVersion > 2)
+ throw new IllegalStateException("Unsupported manifest version " + manifestVersion + " for " + bundleState);
+
+ for (AbstractBundleState bundle : getBundles())
+ {
+ OSGiMetaData other = bundle.getOSGiMetaData();
+ if (symbolicName.equals(other.getBundleSymbolicName()))
+ {
+ if (other.isSingleton() && metaData.isSingleton())
+ throw new IllegalStateException("Cannot install singleton " + bundleState + " another singleton is already installed: " + bundle.getLocation());
+ if (other.getBundleVersion().equals(metaData.getBundleVersion()))
+ throw new IllegalStateException("Cannot install " + bundleState + " a bundle with that name and version is already installed: " + bundle.getLocation());
+ }
+ }
+
+ List<PackageAttribute> importPackages = metaData.getImportPackages();
+ if (importPackages != null && importPackages.isEmpty() == false)
+ {
+ Set<String> packages = new HashSet<String>();
+ for (PackageAttribute packageAttribute : importPackages)
+ {
+ String packageName = packageAttribute.getAttribute();
+ if (packages.contains(packageName))
+ throw new IllegalStateException("Duplicate import of package " + packageName + " for " + bundleState);
+ packages.add(packageName);
+
+ if (packageName.startsWith("java."))
+ throw new IllegalStateException("Not allowed to import java.* for " + bundleState);
+
+ String version = packageAttribute.getAttributeValue(Constants.VERSION_ATTRIBUTE, String.class);
+ String specificationVersion = packageAttribute.getAttributeValue(Constants.PACKAGE_SPECIFICATION_VERSION, String.class);
+ if (version != null && specificationVersion != null && version.equals(specificationVersion) == false)
+ throw new IllegalStateException(packageName + " version and specification version should be the same for " + bundleState);
+ }
+ }
+
+ List<PackageAttribute> exportPackages = metaData.getExportPackages();
+ if (exportPackages != null && exportPackages.isEmpty() == false)
+ {
+ for (PackageAttribute packageAttribute : exportPackages)
+ {
+ String packageName = packageAttribute.getAttribute();
+ if (packageName.startsWith("java."))
+ throw new IllegalStateException("Not allowed to export java.* for " + bundleState);
+ }
+ }
+ }
+
+ /**
* Remove a bundle
*
* @param bundleState the bundle state
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -108,22 +108,19 @@
ParameterizedAttribute otherParameters = bundleRequirement.getRequireBundle();
if (otherParameters != null)
{
- Map<String, Parameter> params = otherParameters.getParameters();
+ Map<String, Parameter> params = otherParameters.getAttributes();
if (params != null && params.isEmpty() == false)
{
for (String name : params.keySet())
{
- // todo we shouldn't mix attributes and directives in the metadata
- if (Constants.VISIBILITY_DIRECTIVE.equals(name) == false
- && Constants.RESOLUTION_DIRECTIVE.equals(name) == false
- && Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name) == false)
+ if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name) == false)
{
if (ourParameters == null)
return false;
- String ourValue = ourParameters.getParameterValue(name, String.class);
+ String ourValue = ourParameters.getAttributeValue(name, String.class);
if (ourValue == null)
return false;
- if (ourValue.equals(otherParameters.getParameterValue(name, String.class)) == false)
+ if (ourValue.equals(otherParameters.getAttributeValue(name, String.class)) == false)
return false;
}
}
@@ -152,9 +149,9 @@
ParameterizedAttribute parameters = metadata.getBundleParameters();
if (parameters != null)
{
- Map<String, Parameter> params = parameters.getParameters();
+ Map<String, Parameter> params = parameters.getAttributes();
if (params != null && params.isEmpty() == false)
- buffer.append(" parameters=").append(params);
+ buffer.append(" attributes=").append(params);
}
}
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleRequirement.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleRequirement.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleRequirement.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -61,7 +61,7 @@
String name = requireBundle.getAttribute();
AbstractVersionRange range = null;
- String version = requireBundle.getParameterValue(Constants.BUNDLE_VERSION_ATTRIBUTE, String.class);
+ String version = requireBundle.getAttributeValue(Constants.BUNDLE_VERSION_ATTRIBUTE, String.class);
if (version != null)
range = (AbstractVersionRange) AbstractVersionRange.valueOf(version);
@@ -83,11 +83,11 @@
throw new IllegalArgumentException("Null requireBundle");
this.requireBundle = requireBundle;
- String visibility = requireBundle.getParameterValue(Constants.VISIBILITY_DIRECTIVE, String.class);
+ String visibility = requireBundle.getDirectiveValue(Constants.VISIBILITY_DIRECTIVE, String.class);
if (Constants.VISIBILITY_REEXPORT.equals(visibility))
setReExport(true);
- String resolution = requireBundle.getParameterValue(Constants.RESOLUTION_DIRECTIVE, String.class);
+ String resolution = requireBundle.getDirectiveValue(Constants.RESOLUTION_DIRECTIVE, String.class);
if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
setOptional(true);
}
@@ -119,8 +119,8 @@
protected void toString(StringBuffer buffer)
{
super.toString(buffer);
- Map<String, Parameter> parameters = requireBundle.getParameters();
+ Map<String, Parameter> parameters = requireBundle.getAttributes();
if (parameters != null && parameters.isEmpty() == false)
- buffer.append(" parameters=").append(parameters);
+ buffer.append(" attributes=").append(parameters);
}
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -82,9 +82,9 @@
throw new IllegalArgumentException("Null bundle");
String name = exportPackage.getAttribute();
- String versionString = exportPackage.getParameterValue(Constants.VERSION_ATTRIBUTE, String.class);
+ String versionString = exportPackage.getAttributeValue(Constants.VERSION_ATTRIBUTE, String.class);
- String oldVersionString = exportPackage.getParameterValue(Constants.PACKAGE_SPECIFICATION_VERSION, String.class);
+ String oldVersionString = exportPackage.getAttributeValue(Constants.PACKAGE_SPECIFICATION_VERSION, String.class);
if (oldVersionString != null)
{
if (versionString != null && versionString.equals(oldVersionString) == false)
@@ -116,7 +116,7 @@
this.bundleState = bundleState;
this.exportPackage = exportPackage;
- String mandatory = exportPackage.getParameterValue(Constants.MANDATORY_DIRECTIVE, String.class);
+ String mandatory = exportPackage.getAttributeValue(Constants.MANDATORY_DIRECTIVE, String.class);
if (mandatory != null)
{
StringTokenizer tokens = new StringTokenizer(mandatory, ",");
@@ -126,9 +126,9 @@
mandatoryAttributes[i++] = tokens.nextToken();
}
- if (exportPackage.getParameter(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE) != null)
+ if (exportPackage.getAttribute(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE) != null)
throw new IllegalStateException("You cannot specify " + Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE + " on an Export-Package");
- if (exportPackage.getParameter(Constants.BUNDLE_VERSION_ATTRIBUTE) != null)
+ if (exportPackage.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE) != null)
throw new IllegalStateException("You cannot specify " + Constants.BUNDLE_VERSION_ATTRIBUTE + " on an Export-Package");
}
@@ -209,7 +209,7 @@
{
for (String mand : mandatoryAttributes)
{
- if (reqParameters.getParameter(mand) == null)
+ if (reqParameters.getAttribute(mand) == null)
{
validMatch = false;
break;
@@ -220,15 +220,14 @@
if (validMatch == true && reqParameters != null)
{
- Map<String, Parameter> params = reqParameters.getParameters();
+ Map<String, Parameter> params = reqParameters.getAttributes();
if (params != null && params.isEmpty() == false)
{
for (String name : params.keySet())
{
- String otherValue = reqParameters.getParameterValue(name, String.class);
- String ourValue = capParameters.getParameterValue(name, String.class);
+ String otherValue = reqParameters.getAttributeValue(name, String.class);
+ String ourValue = capParameters.getAttributeValue(name, String.class);
- // todo we shouldn't mix attributes and directives in the metadata
if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(name))
{
if (otherValue.equals(metaData.getBundleSymbolicName()) == false)
@@ -240,7 +239,7 @@
if (range.isInRange(metaData.getBundleVersion()) == false)
validMatch = false;
}
- else if (Constants.RESOLUTION_DIRECTIVE.equals(name) == false && Constants.PACKAGE_SPECIFICATION_VERSION.equals(name) == false
+ else if (Constants.PACKAGE_SPECIFICATION_VERSION.equals(name) == false
&& Constants.VERSION_ATTRIBUTE.equals(name) == false)
{
if (ourValue == null || ourValue.equals(otherValue) == false)
@@ -277,9 +276,9 @@
ParameterizedAttribute parameters = metadata.getBundleParameters();
if (parameters != null)
{
- Map<String, Parameter> params = parameters.getParameters();
+ Map<String, Parameter> params = parameters.getAttributes();
if (params != null && params.isEmpty() == false)
- buffer.append(" parameters=").append(params);
+ buffer.append(" attributes=").append(params);
}
}
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -72,18 +72,18 @@
String name = requirePackage.getAttribute();
AbstractVersionRange range = null;
- String versionString = requirePackage.getParameterValue(Constants.VERSION_ATTRIBUTE, String.class);
+ String versionString = requirePackage.getAttributeValue(Constants.VERSION_ATTRIBUTE, String.class);
if (versionString != null)
{
range = (AbstractVersionRange)AbstractVersionRange.valueOf(versionString);
- String oldVersionString = requirePackage.getParameterValue(Constants.PACKAGE_SPECIFICATION_VERSION, String.class);
+ String oldVersionString = requirePackage.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.getParameterValue(Constants.PACKAGE_SPECIFICATION_VERSION, String.class);
+ versionString = requirePackage.getAttributeValue(Constants.PACKAGE_SPECIFICATION_VERSION, String.class);
if (versionString != null)
range = (AbstractVersionRange)AbstractVersionRange.valueOf(versionString);
}
@@ -108,7 +108,7 @@
if (requirePackage != null)
{
this.requirePackage = requirePackage;
- String resolution = requirePackage.getParameterValue(Constants.RESOLUTION_DIRECTIVE, String.class);
+ String resolution = requirePackage.getDirectiveValue(Constants.RESOLUTION_DIRECTIVE, String.class);
if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
setOptional(true);
}
@@ -157,7 +157,7 @@
super.toString(buffer);
if (requirePackage != null)
{
- Map<String, Parameter> parameters = requirePackage.getParameters();
+ Map<String, Parameter> parameters = requirePackage.getAttributes();
if (parameters != null)
{
Map<String, Object> keyValueMap = new LinkedHashMap<String, Object>();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/ParameterizedAttribute.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/ParameterizedAttribute.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/ParameterizedAttribute.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -32,28 +32,74 @@
public interface ParameterizedAttribute extends AttributeAware
{
/**
- * Get the parameters.
+ * Get the attributes.
*
- * @return properties for this attribute
+ * @return the attributes
*/
- Map<String, Parameter> getParameters();
+ Map<String, Parameter> getAttributes();
/**
- * Get the parameter by name.
- * Helper method to getParameters method.
+ * Get an attribute by name.
*
- * @param name parameter's name
- * @return parameter value
+ * @param name attributes's name
+ * @return the attribute
*/
- Parameter getParameter(String name);
+ Parameter getAttribute(String name);
/**
- * Get a parameter value
+ * Get an attribute value
*
* @param <T> the expected type
- * @param name the name of the parameter
+ * @param name the name of the attribute
* @param type the expected type
- * @return the parmaeter value
+ * @return the attribute value
*/
- <T> T getParameterValue(String name, Class<T> type);
+ <T> T getAttributeValue(String name, Class<T> type);
+
+ /**
+ * Get a directive value
+ *
+ * @param <T> the expected type
+ * @param name the name of the directive
+ * @param defaultValue the default value when no attribute is specified
+ * @param type the expected type
+ * @return the attribute value
+ */
+ <T> T getAttributeValue(String name, T defaultValue, Class<T> type);
+
+ /**
+ * Get the declerations
+ *
+ * @return the directives
+ */
+ Map<String, Parameter> getDirectives();
+
+ /**
+ * Get a directive by name.
+ *
+ * @param name directive's name
+ * @return the directive
+ */
+ Parameter getDirective(String name);
+
+ /**
+ * Get a directive value
+ *
+ * @param <T> the expected type
+ * @param name the name of the directive
+ * @param type the expected type
+ * @return the directive value
+ */
+ <T> T getDirectiveValue(String name, Class<T> type);
+
+ /**
+ * Get a directive value
+ *
+ * @param <T> the expected type
+ * @param name the name of the directive
+ * @param defaultValue the default value when no directive is specified
+ * @param type the expected type
+ * @return the directive value
+ */
+ <T> T getDirectiveValue(String name, T defaultValue, Class<T> type);
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractOSGiMetaData.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractOSGiMetaData.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractOSGiMetaData.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -151,7 +151,7 @@
public int getBundleManifestVersion()
{
- return get(BUNDLE_MANIFESTVERSION, INTEGER_VC, 1);
+ return get(BUNDLE_MANIFESTVERSION, INTEGER_VC, 2);
}
public String getBundleName()
@@ -225,7 +225,7 @@
parseSymbolicName();
if (parameters == null)
return false;
- return "true".equals(parameters.getParameterValue(Constants.SINGLETON_DIRECTIVE, String.class));
+ return "true".equals(parameters.getDirectiveValue(Constants.SINGLETON_DIRECTIVE, String.class));
}
public String getFragmentAttachment()
@@ -233,7 +233,7 @@
parseSymbolicName();
if (parameters == null)
return null;
- return parameters.getParameterValue(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE, String.class);
+ return parameters.getDirectiveValue(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE, String.class);
}
protected ParameterizedAttribute parseSymbolicName()
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractPackageAttribute.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractPackageAttribute.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractPackageAttribute.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -43,9 +43,9 @@
protected PackageInfo packageInfo;
protected VersionRange versionRange;
- public AbstractPackageAttribute(String attribute, Map<String, Parameter> parameters)
+ public AbstractPackageAttribute(String attribute, Map<String, Parameter> attributes, Map<String, Parameter> directives)
{
- super(attribute, parameters);
+ super(attribute, attributes, directives);
packageInfo = new PackageInfoImpl(attribute);
}
@@ -58,7 +58,7 @@
{
if (versionRange == null)
{
- Parameter parameter = getParameter(Constants.VERSION_ATTRIBUTE);
+ Parameter parameter = getDirective(Constants.VERSION_ATTRIBUTE);
if (parameter != null)
{
if (parameter.isCollection())
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractParameterizedAttribute.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractParameterizedAttribute.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractParameterizedAttribute.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -21,6 +21,7 @@
*/
package org.jboss.osgi.framework.metadata.internal;
+import java.util.Collections;
import java.util.Map;
import org.jboss.osgi.framework.metadata.Parameter;
@@ -36,48 +37,83 @@
{
private static final long serialVersionUID = 1l;
- protected Map<String, Parameter> parameters;
+ protected Map<String, Parameter> attributes;
+
+ protected Map<String, Parameter> directives;
- public AbstractParameterizedAttribute(String attribute, Map<String, Parameter> parameters)
+ public AbstractParameterizedAttribute(String attribute, Map<String, Parameter> attributes, Map<String, Parameter> directives)
{
super(attribute);
- this.parameters = parameters;
+ if (attributes == null)
+ attributes = Collections.emptyMap();
+ this.attributes = attributes;
+ if (directives == null)
+ directives = Collections.emptyMap();
+ this.directives = directives;
}
- public Map<String, Parameter> getParameters()
+ public Map<String, Parameter> getAttributes()
{
- return parameters;
+ return attributes;
}
- public Parameter getParameter(String name)
+ public Parameter getAttribute(String name)
{
- return parameters.get(name);
+ return attributes.get(name);
}
- /**
- * Get a parameter
- *
- * @param <T> the expected type
- * @param name the name of the parameter
- * @param type the expected type
- * @return the parmaeter value
- */
- public <T> T getParameterValue(String name, Class<T> type)
+ public <T> T getAttributeValue(String name, Class<T> type)
{
- Parameter parameter = getParameter(name);
+ return getAttributeValue(name, null, type);
+ }
+
+ public <T> T getAttributeValue(String name, T defaultValue, Class<T> type)
+ {
+ Parameter parameter = getAttribute(name);
if (parameter == null)
- return null;
+ return defaultValue;
if (parameter.isCollection())
- throw new IllegalArgumentException("Duplicate " + name + " parameter.");
+ throw new IllegalArgumentException("Duplicate " + name + " attribute.");
Object value = parameter.getValue();
if (value == null)
- return null;
+ return defaultValue;
return type.cast(value);
}
+ public Map<String, Parameter> getDirectives()
+ {
+ return directives;
+ }
+
+ public Parameter getDirective(String name)
+ {
+ return directives.get(name);
+ }
+
+ public <T> T getDirectiveValue(String name, Class<T> type)
+ {
+ return getDirectiveValue(name, null, type);
+ }
+
+ public <T> T getDirectiveValue(String name, T defaultValue, Class<T> type)
+ {
+ Parameter parameter = getDirective(name);
+ if (parameter == null)
+ return defaultValue;
+ if (parameter.isCollection())
+ throw new IllegalArgumentException("Duplicate " + name + " directive.");
+ Object value = parameter.getValue();
+ if (value == null)
+ return defaultValue;
+ return type.cast(value);
+ }
+
protected void toString(JBossStringBuilder buffer)
{
super.toString(buffer);
- buffer.append(" parameters=" + parameters);
+ if (attributes.isEmpty() == false)
+ buffer.append(" attributes=" + attributes);
+ if (directives.isEmpty() == false)
+ buffer.append(" directives=" + directives);
}
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/ManifestParser.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/ManifestParser.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/metadata/internal/ManifestParser.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -144,7 +144,10 @@
String value = piece.substring(seperator + 2);
if (directives == null)
directives = new HashMap<String, Parameter>();
- directives.put(unquote(name), new AbstractParameter(unquote(value)));
+ String unquoted = unquote(name);
+ if (directives.containsKey(unquoted))
+ throw new IllegalStateException("Dupicate directive: " + unquoted);
+ directives.put(unquoted, new AbstractParameter(unquote(value)));
}
else
{
@@ -155,7 +158,10 @@
String value = piece.substring(seperator + 1);
if (attributes == null)
attributes = new HashMap<String, Parameter>();
- attributes.put(unquote(name), new AbstractParameter(unquote(value)));
+ String unquoted = unquote(name);
+ if (attributes.containsKey(unquoted))
+ throw new IllegalStateException("Dupicate attribute: " + unquoted);
+ attributes.put(unquoted, new AbstractParameter(unquote(value)));
}
else
{
@@ -164,20 +170,13 @@
}
}
- // TODO JBOSGI-200 replace with seperate attribute and directives in the metadata
- if (attributes == null)
- attributes = new HashMap<String, Parameter>();
- if (directives != null)
- attributes.putAll(directives);
- // END JBOSGI-200
-
for (String path : paths)
{
ParameterizedAttribute metadata = null;
if (packages)
- metadata = new AbstractPackageAttribute(path, attributes);
+ metadata = new AbstractPackageAttribute(path, attributes, directives);
else
- metadata = new AbstractParameterizedAttribute(path, attributes);
+ metadata = new AbstractParameterizedAttribute(path, attributes, directives);
list.add(metadata);
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -36,11 +36,15 @@
{
/**
* Get the version of this export.
+ *
+ * @return the version
*/
Version getVersion();
/**
* Get the list of packages that is used by this export.
+ *
+ * @return the list of uses
*/
List<String> getUses();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -39,11 +39,15 @@
/**
* Get the version range for this import package.
+ *
+ * @return the version range
*/
VersionRange getVersion();
/**
* Get the resolution directive for this import package.
+ *
+ * @return the resolution directive
*/
Resolution getResolution();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -34,11 +34,15 @@
{
/**
* Get the bundle that owns this package decalaration
+ *
+ * @return the owner
*/
Resolvable getOwner();
/**
* Get the package name
+ *
+ * @return the name
*/
String getName();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -36,16 +36,22 @@
{
/**
* Get the underlying bundle that this resolvable is associated with.
+ *
+ * @return the bundle
*/
Bundle getBundle();
/**
* Get the bundle's symbolic name.
+ *
+ * @return the symbolic name
*/
String getSymbolicName();
/**
* Get the bundle's version.
+ *
+ * @return the version
*/
Version getVersion();
@@ -57,6 +63,8 @@
/**
* Get an exported package by name.
+ *
+ * @param packageName the package name
* @return The exported package or null if the bundle does not export that package.
*/
ExportPackage getExportPackage(String packageName);
@@ -69,17 +77,19 @@
/**
* Get an imported package by name.
+ *
+ * @param packageName the package name
* @return The imported package or null if the bundle does not import that package.
*/
ImportPackage getImportPackage(String packageName);
/**
- * True if this resovable is a singleton bundle.
+ * @return True if this resovable is a singleton bundle.
*/
boolean isSingleton();
/**
- * True if this resovable has been resolved.
+ * @return True if this resovable has been resolved.
*/
boolean isResolved();
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -41,12 +41,16 @@
/**
* Add a bundle to the resolver.
+ *
+ * @param bundle the bundle
* @return The resolvable associated with the added bundle.
*/
Resolvable addBundle(Bundle bundle);
/**
* Remove a bundle from the resolver.
+
+ * @param bundle the bundle
* @return The resolvable associated with the removed bundle.
*/
Resolvable removeBundle(Bundle bundle);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -26,7 +26,6 @@
import org.jboss.osgi.framework.resolver.ExportPackage;
import org.jboss.osgi.framework.resolver.ImportPackage;
-import org.jboss.osgi.framework.resolver.NamedPackage;
import org.jboss.osgi.framework.resolver.Resolvable;
import org.jboss.osgi.spi.NotImplementedException;
import org.osgi.framework.Version;
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -40,7 +40,6 @@
import org.jboss.osgi.framework.bundle.OSGiBundleState;
import org.jboss.osgi.framework.classloading.OSGiPackageRequirement;
import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.framework.metadata.Parameter;
import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
import org.jboss.osgi.framework.plugins.ResolverPlugin;
import org.jboss.osgi.framework.plugins.internal.AbstractPlugin;
@@ -420,21 +419,12 @@
if (requiredBundleName == null)
throw new IllegalStateException("Cannot obtain value for: " + Constants.REQUIRE_BUNDLE);
- String visibility = Constants.VISIBILITY_PRIVATE;
- Parameter param = attr.getParameter(Constants.VISIBILITY_DIRECTIVE);
- if (param != null)
- visibility = (String)param.getValue();
+ String visibility = attr.getDirectiveValue(Constants.VISIBILITY_DIRECTIVE, Constants.VISIBILITY_PRIVATE, String.class);
- String resolution = Constants.RESOLUTION_MANDATORY;
- param = attr.getParameter(Constants.RESOLUTION_DIRECTIVE);
- if (param != null)
- resolution = (String)param.getValue();
+ String resolution = attr.getDirectiveValue(Constants.RESOLUTION_DIRECTIVE, Constants.RESOLUTION_MANDATORY, String.class);
// [TODO] bundle-version
- //String bundleVersion = null;
- //param = attr.getParameter(Constants.BUNDLE_VERSION_ATTRIBUTE);
- //if (param != null)
- // bundleVersion = (String)param.getValue();
+ //String bundleVersion = attr.getAttributeValue(Constants.BUNDLE_VERSION_ATTRIBUTE, String.class);
if (Constants.RESOLUTION_MANDATORY.equals(resolution))
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -104,12 +104,12 @@
Map<String, Parameter> bnc1 = new HashMap<String, Parameter>();
bnc1.put("osname", new AbstractParameter("QNX"));
bnc1.put("osversion", new AbstractParameter("3.1"));
- bundleNativeCode.add(new AbstractPackageAttribute("/lib/http.DLL", bnc1));
+ bundleNativeCode.add(new AbstractPackageAttribute("/lib/http.DLL", bnc1, null));
Map<String, Parameter> bnc2 = new HashMap<String, Parameter>();
bnc2.put("osname", new AbstractParameter("QWE"));
bnc2.put("osversion", new AbstractParameter("4.0"));
- bundleNativeCode.add(new AbstractPackageAttribute("/lib/tcp.DLL", bnc2));
- bundleNativeCode.add(new AbstractPackageAttribute("/lib/iiop.DLL", bnc2));
+ bundleNativeCode.add(new AbstractPackageAttribute("/lib/tcp.DLL", bnc2, null));
+ bundleNativeCode.add(new AbstractPackageAttribute("/lib/iiop.DLL", bnc2, null));
List<ParameterizedAttribute> metadataBNC = metaData.getBundleNativeCode();
assertNotNull(metadataBNC);
assertEquals(bundleNativeCode.size(), metadataBNC.size());
@@ -118,19 +118,19 @@
ParameterizedAttribute paMD = metadataBNC.get(i);
ParameterizedAttribute myPA = bundleNativeCode.get(i);
assertEquals(paMD.getAttribute(), myPA.getAttribute());
- assertEquals(paMD.getParameters(), myPA.getParameters());
+ assertEquals(paMD.getAttributes(), myPA.getAttributes());
}
List<PackageAttribute> dynamicImports = new ArrayList<PackageAttribute>();
Map<String, Parameter> dyna1 = new HashMap<String, Parameter>();
dyna1.put("user", new AbstractParameter("alesj"));
- dynamicImports.add(new AbstractPackageAttribute("org.jboss.test", dyna1));
+ dynamicImports.add(new AbstractPackageAttribute("org.jboss.test", dyna1, null));
Map<String, Parameter> dyna2 = new HashMap<String, Parameter>();
dyna2.put("version", new AbstractParameter("1.2.3.GA"));
- dynamicImports.add(new AbstractPackageAttribute("com.acme.plugin.*", dyna2));
+ dynamicImports.add(new AbstractPackageAttribute("com.acme.plugin.*", dyna2, null));
Map<String, Parameter> dyna3 = new HashMap<String, Parameter>();
dyna3.put("test", new AbstractParameter("test"));
- dynamicImports.add(new AbstractPackageAttribute("*", dyna3));
+ dynamicImports.add(new AbstractPackageAttribute("*", dyna3, null));
List<PackageAttribute> metadataDyna = metaData.getDynamicImports();
assertNotNull(metadataDyna);
assertEquals(dynamicImports.size(), metadataDyna.size());
@@ -140,17 +140,17 @@
PackageAttribute myPA = dynamicImports.get(i);
assertEquals(paMD.getAttribute(), myPA.getAttribute());
assertEquals(paMD.getPackageInfo(), myPA.getPackageInfo());
- assertEquals(paMD.getParameters(), myPA.getParameters());
+ assertEquals(paMD.getAttributes(), myPA.getAttributes());
}
List<PackageAttribute> exportPackages = new ArrayList<PackageAttribute>();
Map<String, Parameter> ep1 = new HashMap<String, Parameter>();
ep1.put("version", new AbstractParameter("1.3"));
- exportPackages.add(new AbstractPackageAttribute("org.osgi.util.tracker", ep1));
- exportPackages.add(new AbstractPackageAttribute("net.osgi.foo", ep1));
+ exportPackages.add(new AbstractPackageAttribute("org.osgi.util.tracker", ep1, null));
+ exportPackages.add(new AbstractPackageAttribute("net.osgi.foo", ep1, null));
Map<String, Parameter> ep2 = new HashMap<String, Parameter>();
ep2.put("version", new AbstractParameter("[1.0,2.0)"));
- exportPackages.add(new AbstractPackageAttribute("org.jboss.test", ep2));
+ exportPackages.add(new AbstractPackageAttribute("org.jboss.test", ep2, null));
List<PackageAttribute> metadataExport = metaData.getExportPackages();
assertNotNull(metadataExport);
assertEquals(exportPackages.size(), metadataExport.size());
@@ -160,9 +160,9 @@
PackageAttribute myPA = exportPackages.get(i);
assertEquals(paMD.getAttribute(), myPA.getAttribute());
assertEquals(paMD.getPackageInfo(), myPA.getPackageInfo());
- assertEquals(paMD.getParameters(), myPA.getParameters());
- OSGiParameters o1 = new OSGiParameters(paMD.getParameters());
- OSGiParameters o2 = new OSGiParameters(myPA.getParameters());
+ assertEquals(paMD.getAttributes(), myPA.getAttributes());
+ OSGiParameters o1 = new OSGiParameters(paMD.getAttributes());
+ OSGiParameters o2 = new OSGiParameters(myPA.getAttributes());
VersionRange v1 = o1.getVersion();
VersionRange v2 = o2.getVersion();
assertEquals(v1, v2);
@@ -170,12 +170,12 @@
Map<String, Parameter> parameters = new HashMap<String, Parameter>();
parameters.put("bundle-version", new AbstractParameter("\"[3.0.0,4.0.0)\""));
- ParameterizedAttribute fragmentHost = new AbstractParameterizedAttribute("org.eclipse.swt", parameters);
+ ParameterizedAttribute fragmentHost = new AbstractParameterizedAttribute("org.eclipse.swt", parameters, null);
ParameterizedAttribute metadataFragment = metaData.getFragmentHost();
assertNotNull(metadataFragment);
assertEquals(fragmentHost.getAttribute(), metadataFragment.getAttribute());
- OSGiParameters o1 = new OSGiParameters(fragmentHost.getParameters());
- OSGiParameters o2 = new OSGiParameters(metadataFragment.getParameters());
+ OSGiParameters o1 = new OSGiParameters(fragmentHost.getAttributes());
+ OSGiParameters o2 = new OSGiParameters(metadataFragment.getAttributes());
VersionRange v1 = o1.getBundleVersion();
VersionRange v2 = o2.getBundleVersion();
assertNotNull(v1);
@@ -186,12 +186,13 @@
Map<String, Parameter> ip1 = new HashMap<String, Parameter>();
ip1.put("version", new AbstractParameter("1.4"));
ip1.put("name", new AbstractParameter("osgi"));
- importPackages.add(new AbstractPackageAttribute("org.osgi.util.tracker", ip1));
- importPackages.add(new AbstractPackageAttribute("org.osgi.service.io", ip1));
+ importPackages.add(new AbstractPackageAttribute("org.osgi.util.tracker", ip1, null));
+ importPackages.add(new AbstractPackageAttribute("org.osgi.service.io", ip1, null));
Map<String, Parameter> ip2 = new HashMap<String, Parameter>();
ip2.put("version", new AbstractParameter("[2.0,3.0)"));
- ip2.put("resolution", new AbstractParameter("osgi-int"));
- importPackages.add(new AbstractPackageAttribute("org.jboss.test", ip2));
+ Map<String, Parameter> ip2d = new HashMap<String, Parameter>();
+ ip2d.put("resolution", new AbstractParameter("osgi-int"));
+ importPackages.add(new AbstractPackageAttribute("org.jboss.test", ip2, ip2d));
List<PackageAttribute> metadataImport = metaData.getImportPackages();
assertNotNull(metadataImport);
assertEquals(importPackages.size(), metadataImport.size());
@@ -201,9 +202,10 @@
PackageAttribute myPA = importPackages.get(i);
assertEquals(paMD.getAttribute(), myPA.getAttribute());
assertEquals(paMD.getPackageInfo(), myPA.getPackageInfo());
- assertEquals(paMD.getParameters(), myPA.getParameters());
- OSGiParameters oi1 = new OSGiParameters(paMD.getParameters());
- OSGiParameters oi2 = new OSGiParameters(myPA.getParameters());
+ assertEquals(paMD.getAttributes(), myPA.getAttributes());
+ assertEquals(paMD.getDirectives(), myPA.getDirectives());
+ OSGiParameters oi1 = new OSGiParameters(paMD.getAttributes());
+ OSGiParameters oi2 = new OSGiParameters(myPA.getAttributes());
VersionRange vi1 = oi1.getVersion();
VersionRange vi2 = oi2.getVersion();
assertEquals(vi1, vi2);
@@ -212,10 +214,10 @@
List<ParameterizedAttribute> requireBundles = new ArrayList<ParameterizedAttribute>();
Map<String, Parameter> rb1 = new HashMap<String, Parameter>();
rb1.put("visibility", new AbstractParameter("true"));
- requireBundles.add(new AbstractParameterizedAttribute("com.acme.chess", rb1));
+ requireBundles.add(new AbstractParameterizedAttribute("com.acme.chess", null, rb1));
Map<String, Parameter> rb2 = new HashMap<String, Parameter>();
rb2.put("bundle-version", new AbstractParameter("1.2"));
- requireBundles.add(new AbstractParameterizedAttribute("com.alesj.test", rb2));
+ requireBundles.add(new AbstractParameterizedAttribute("com.alesj.test", rb2, null));
List<ParameterizedAttribute> metadataRB = metaData.getRequireBundles();
assertNotNull(metadataRB);
assertEquals(requireBundles.size(), metadataRB.size());
@@ -224,9 +226,10 @@
ParameterizedAttribute paMD = metadataRB.get(i);
ParameterizedAttribute myPA = requireBundles.get(i);
assertEquals(paMD.getAttribute(), myPA.getAttribute());
- assertEquals(paMD.getParameters(), myPA.getParameters());
- OSGiParameters oi1 = new OSGiParameters(paMD.getParameters());
- OSGiParameters oi2 = new OSGiParameters(myPA.getParameters());
+ assertEquals(paMD.getAttributes(), myPA.getAttributes());
+ assertEquals(paMD.getDirectives(), myPA.getDirectives());
+ OSGiParameters oi1 = new OSGiParameters(paMD.getAttributes());
+ OSGiParameters oi2 = new OSGiParameters(myPA.getAttributes());
String vis1 = oi1.getVisibility();
String vis2 = oi2.getVisibility();
assertEquals(vis1, vis2);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ImportDirectiveResolutionTest.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ImportDirectiveResolutionTest.java 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ImportDirectiveResolutionTest.java 2009-11-09 17:30:32 UTC (rev 96183)
@@ -63,6 +63,8 @@
}
/**
* [TODO] testImportAvailable
+ *
+ * @throws BundleException
*/
public void testImportAvailable() throws BundleException
{
@@ -70,6 +72,8 @@
/**
* [TODO] testImportNotAvailable
+
+ * @throws BundleException
*/
public void testImportNotAvailable() throws BundleException
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/singleton/singleton1/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/singleton/singleton1/META-INF/MANIFEST.MF 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/singleton/singleton1/META-INF/MANIFEST.MF 2009-11-09 17:30:32 UTC (rev 96183)
@@ -3,4 +3,4 @@
Implementation-Version: test
Implementation-Vendor: jboss.org
Bundle-Name: Singleton1
-Bundle-SymbolicName: org.jboss.test.osgi.singleton;singleton=true
+Bundle-SymbolicName: org.jboss.test.osgi.singleton;singleton:=true
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/singleton/singleton2/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/singleton/singleton2/META-INF/MANIFEST.MF 2009-11-09 17:28:33 UTC (rev 96182)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/singleton/singleton2/META-INF/MANIFEST.MF 2009-11-09 17:30:32 UTC (rev 96183)
@@ -3,4 +3,4 @@
Implementation-Version: test
Implementation-Vendor: jboss.org
Bundle-Name: Singleton2
-Bundle-SymbolicName: org.jboss.test.osgi.singleton;singleton=true
+Bundle-SymbolicName: org.jboss.test.osgi.singleton;singleton:=true
14 years, 6 months
JBoss-OSGI SVN: r96182 - projects/jboss-osgi/projects/parent/trunk.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-09 12:28:33 -0500 (Mon, 09 Nov 2009)
New Revision: 96182
Modified:
projects/jboss-osgi/projects/parent/trunk/pom.xml
Log:
Add ditro management xml doc
Modified: projects/jboss-osgi/projects/parent/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/parent/trunk/pom.xml 2009-11-09 16:45:35 UTC (rev 96181)
+++ projects/jboss-osgi/projects/parent/trunk/pom.xml 2009-11-09 17:28:33 UTC (rev 96182)
@@ -191,8 +191,16 @@
<!-- DistributionManagement -->
<distributionManagement>
<!--
- Add this to your ~/.m2/settings.xml <servers> <server> <id>jbmuc.dyndns.org</id> <username>yourname</username> <privateKey>/home/yourname/.ssh/id_rsa</privateKey>
- <passphrase>yourpass</passphrase> </server> </servers>
+ Add this to your ~/.m2/settings.xml
+
+ <servers>
+ <server>
+ <id>jbmuc.dyndns.org</id>
+ <username>yourname</username>
+ <privateKey>/home/yourname/.ssh/id_rsa</privateKey>
+ <passphrase>yourpass</passphrase>
+ </server>
+ </servers>
-->
<repository>
<id>repository.jboss.org</id>
14 years, 6 months
JBoss-OSGI SVN: r96181 - in projects/jboss-osgi/trunk: distribution/installer/src/main/resources/runtime/server/conf and 15 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-09 11:45:35 -0500 (Mon, 09 Nov 2009)
New Revision: 96181
Added:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/ResolverPlugin.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPlugin.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePlugin.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java
Removed:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPluginImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePluginImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/
Modified:
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/reactor/blueprint/testsuite/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AutoInstallPluginImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/BundleStoragePluginImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/SystemPackagesPluginImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/NamedPackageImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleCapability.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleRequirement.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/DeployerServiceImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/MicrocontainerServiceImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/StartLevelImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTest.java
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
Log:
Add pluaggability to resolver implementation
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml 2009-11-09 16:45:35 UTC (rev 96181)
@@ -97,6 +97,9 @@
</bean>
-->
+ <bean name="OSGiBundleResolver" class="org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml 2009-11-09 16:45:35 UTC (rev 96181)
@@ -90,6 +90,9 @@
</list>
</property>
</bean>
+ <bean name="OSGiBundleResolver" class="org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
Modified: projects/jboss-osgi/trunk/reactor/blueprint/testsuite/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/blueprint/testsuite/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/blueprint/testsuite/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-09 16:45:35 UTC (rev 96181)
@@ -71,6 +71,9 @@
</list>
</property>
</bean>
+ <bean name="OSGiBundleResolver" class="org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
<property name="synchronous">true</property>
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -66,13 +66,12 @@
import org.jboss.osgi.framework.metadata.OSGiMetaData;
import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
import org.jboss.osgi.framework.plugins.AutoInstallPlugin;
+import org.jboss.osgi.framework.plugins.ResolverPlugin;
import org.jboss.osgi.framework.plugins.BundleStoragePlugin;
import org.jboss.osgi.framework.plugins.FrameworkEventsPlugin;
import org.jboss.osgi.framework.plugins.PackageAdminServicePlugin;
import org.jboss.osgi.framework.plugins.Plugin;
import org.jboss.osgi.framework.plugins.ServicePlugin;
-import org.jboss.osgi.framework.resolver.Resolver;
-import org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl;
import org.jboss.osgi.framework.util.NoFilter;
import org.jboss.util.collection.ConcurrentSet;
import org.jboss.virtual.VFS;
@@ -127,9 +126,6 @@
/** The os version */
private static String OSGi_FRAMEWORK_PROCESSOR;
- /** The bundle resolver */
- private Resolver bundleResolver;
-
/** The bundles by id */
private List<AbstractBundleState> bundles = new CopyOnWriteArrayList<AbstractBundleState>();
@@ -205,7 +201,6 @@
this.kernel = kernel;
this.deployerClient = deployerClient;
this.deployerStructure = (MainDeployerStructure)deployerClient;
- this.bundleResolver = new BasicResolverImpl();
// TODO thread factory
if (executor == null)
@@ -357,16 +352,6 @@
}
/**
- * Get the bundle resolver
- *
- * @return the resolver
- */
- public Resolver getBundleResolver()
- {
- return bundleResolver;
- }
-
- /**
* Are we active
*
* @return true when the system is active
@@ -641,9 +626,16 @@
}
bundleState.setBundleManager(this);
- bundleResolver.addBundle(bundleState);
bundles.add(bundleState);
+ // Add the bundle to the resolver
+ // [TODO] remove this restriction
+ if (bundleState.getBundleId() != 0)
+ {
+ ResolverPlugin bundleResolver = getPlugin(ResolverPlugin.class);
+ bundleResolver.addBundle(bundleState);
+ }
+
bundleState.changeState(Bundle.INSTALLED);
log.debug("Added: " + bundleState);
@@ -662,7 +654,11 @@
bundleState.uninstallInternal();
bundleState.setBundleManager(null);
+
+ // Remove the bundle from the resolver
+ ResolverPlugin bundleResolver = getPlugin(ResolverPlugin.class);
bundleResolver.removeBundle(bundleState);
+
bundles.remove(bundleState);
log.debug("Removed " + bundleState.getCanonicalName());
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -38,11 +38,9 @@
import org.jboss.osgi.framework.metadata.Parameter;
import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
import org.jboss.osgi.framework.metadata.internal.AbstractVersionRange;
+import org.jboss.osgi.framework.plugins.ResolverPlugin;
import org.jboss.osgi.framework.resolver.ExportPackage;
import org.jboss.osgi.framework.resolver.Resolver;
-import org.jboss.osgi.framework.resolver.Resolvable;
-import org.jboss.osgi.framework.resolver.internal.basic.BundleCapability;
-import org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
@@ -146,7 +144,7 @@
// Get the bundle resolver from the bundle manager
OSGiBundleManager bundleManager = bundleState.getBundleManager();
- Resolver bundleResolver = bundleManager.getBundleResolver();
+ Resolver bundleResolver = bundleManager.getPlugin(ResolverPlugin.class);
String location = reqModule.getContextName();
AbstractBundleState bundle = bundleManager.getBundleByLocation(location);
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/ResolverPlugin.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/ResolverPlugin.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/ResolverPlugin.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.plugins;
+
+import org.jboss.osgi.framework.resolver.Resolver;
+
+
+//$Id$
+
+/**
+ * A plugin that handles the resolve phase of bundles.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Nov-2009
+ */
+public interface ResolverPlugin extends Resolver, Plugin
+{
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/ResolverPlugin.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPlugin.java (from rev 96173, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPluginImpl.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPlugin.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPlugin.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.plugins.internal;
+
+//$Id$
+
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.plugins.Plugin;
+
+/**
+ * The base class of all framework plugins.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 18-Aug-2009
+ */
+public abstract class AbstractPlugin implements Plugin
+{
+ protected OSGiBundleManager bundleManager;
+
+ public AbstractPlugin(OSGiBundleManager bundleManager)
+ {
+ if (bundleManager == null)
+ throw new IllegalArgumentException("Null bundleManager");
+
+ this.bundleManager = bundleManager;
+ }
+
+ public OSGiBundleManager getBundleManager()
+ {
+ return bundleManager;
+ }
+
+ public <T extends Plugin> T getPlugin(Class<T> clazz)
+ {
+ return bundleManager.getPlugin(clazz);
+ }
+
+ public <T extends Plugin> T getOptionalPlugin(Class<T> clazz)
+ {
+ return bundleManager.getOptionalPlugin(clazz);
+ }
+}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPluginImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractPluginImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -1,61 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.plugins.internal;
-
-//$Id$
-
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.plugins.Plugin;
-
-/**
- * The base class of all framework plugins.
- *
- * @author thomas.diesler(a)jboss.com
- * @since 18-Aug-2009
- */
-public abstract class AbstractPluginImpl implements Plugin
-{
- protected OSGiBundleManager bundleManager;
-
- public AbstractPluginImpl(OSGiBundleManager bundleManager)
- {
- if (bundleManager == null)
- throw new IllegalArgumentException("Null bundleManager");
-
- this.bundleManager = bundleManager;
- }
-
- public OSGiBundleManager getBundleManager()
- {
- return bundleManager;
- }
-
- public <T extends Plugin> T getPlugin(Class<T> clazz)
- {
- return bundleManager.getPlugin(clazz);
- }
-
- public <T extends Plugin> T getOptionalPlugin(Class<T> clazz)
- {
- return bundleManager.getOptionalPlugin(clazz);
- }
-}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePlugin.java (from rev 96173, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePluginImpl.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePlugin.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePlugin.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.plugins.internal;
+
+//$Id: AbstractPluginImpl.java 92725 2009-08-24 06:19:18Z thomas.diesler(a)jboss.com $
+
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.plugins.ServicePlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The base class of all service plugins.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 18-Aug-2009
+ */
+public abstract class AbstractServicePlugin extends AbstractPlugin implements ServicePlugin
+{
+ public AbstractServicePlugin(OSGiBundleManager bundleManager)
+ {
+ super(bundleManager);
+ }
+
+ public BundleContext getSystemContext()
+ {
+ return bundleManager.getSystemContext();
+ }
+}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePluginImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePluginImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.plugins.internal;
-
-//$Id: AbstractPluginImpl.java 92725 2009-08-24 06:19:18Z thomas.diesler(a)jboss.com $
-
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.plugins.ServicePlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The base class of all service plugins.
- *
- * @author thomas.diesler(a)jboss.com
- * @since 18-Aug-2009
- */
-public abstract class AbstractServicePluginImpl extends AbstractPluginImpl implements ServicePlugin
-{
- public AbstractServicePluginImpl(OSGiBundleManager bundleManager)
- {
- super(bundleManager);
- }
-
- public BundleContext getSystemContext()
- {
- return bundleManager.getSystemContext();
- }
-}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AutoInstallPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AutoInstallPluginImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AutoInstallPluginImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -40,7 +40,7 @@
* @author thomas.diesler(a)jboss.com
* @since 18-Aug-2009
*/
-public class AutoInstallPluginImpl extends AbstractPluginImpl implements AutoInstallPlugin
+public class AutoInstallPluginImpl extends AbstractPlugin implements AutoInstallPlugin
{
// Provide logging
final Logger log = Logger.getLogger(AutoInstallPluginImpl.class);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/BundleStoragePluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/BundleStoragePluginImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/BundleStoragePluginImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -38,7 +38,7 @@
* @author thomas.diesler(a)jboss.com
* @since 18-Aug-2009
*/
-public class BundleStoragePluginImpl extends AbstractPluginImpl implements BundleStoragePlugin
+public class BundleStoragePluginImpl extends AbstractPlugin implements BundleStoragePlugin
{
// Provide logging
final Logger log = Logger.getLogger(BundleStoragePluginImpl.class);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -60,7 +60,7 @@
* @author thomas.diesler(a)jboss.com
* @since 18-Aug-2009
*/
-public class FrameworkEventsPluginImpl extends AbstractPluginImpl implements FrameworkEventsPlugin
+public class FrameworkEventsPluginImpl extends AbstractPlugin implements FrameworkEventsPlugin
{
// Provide logging
final Logger log = Logger.getLogger(FrameworkEventsPluginImpl.class);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/SystemPackagesPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/SystemPackagesPluginImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/SystemPackagesPluginImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -38,7 +38,7 @@
* @author thomas.diesler(a)jboss.com
* @since 18-Aug-2009
*/
-public class SystemPackagesPluginImpl extends AbstractPluginImpl implements SystemPackagesPlugin
+public class SystemPackagesPluginImpl extends AbstractPlugin implements SystemPackagesPlugin
{
// Provide logging
final Logger log = Logger.getLogger(SystemPackagesPluginImpl.class);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -27,21 +27,44 @@
import org.osgi.framework.Version;
/**
+ * An abstraction of a package export.
*
* @author thomas.diesler(a)jboss.com
- * @since 09-Noc-2009
+ * @since 09-Nov-2009
*/
public interface ExportPackage extends NamedPackage
{
+ /**
+ * Get the version of this export.
+ */
Version getVersion();
- List<NamedPackage> getUses();
+ /**
+ * Get the list of packages that is used by this export.
+ */
+ List<String> getUses();
- Set<ImportPackage> getImporters();
-
+ /**
+ * Get the list of mandadtory attributes declared by this export.
+ * @return An empty list if there are no mandatory exports declared.
+ */
List<String> getMandatoryAttributes();
+ /**
+ * Get the list of included classes in this package export.
+ * @return Null if there are no includes defined.
+ */
List<String> getIncludes();
+ /**
+ * Get the list of excluded classes in this package export.
+ * @return Null if there are no excludes defined.
+ */
List<String> getExcludes();
+
+ /**
+ * Get the current set of importers of this export package.
+ * @return An empty set if there is no importer
+ */
+ Set<ImportPackage> getImporters();
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -25,19 +25,43 @@
import org.osgi.framework.Version;
/**
+ * An abstraction of a package import.
*
* @author thomas.diesler(a)jboss.com
- * @since 09-Noc-2009
+ * @since 09-Nov-2009
*/
public interface ImportPackage extends NamedPackage
{
- ExportPackage getExporter();
-
+ enum Resolution
+ {
+ OPTIONAL, MANDATORY
+ };
+
+ /**
+ * Get the version range for this import package.
+ */
VersionRange getVersion();
-
- String getResolution();
-
+
+ /**
+ * Get the resolution directive for this import package.
+ */
+ Resolution getResolution();
+
+ /**
+ * The bundle symbolic name of the exporting bundle.
+ * @return null if this attribute is not set
+ */
String getBundleSymbolicName();
-
+
+ /**
+ * The bundle version of the exporting bundle.
+ * @return null if this attribute is not set
+ */
Version getBundleVersion();
+
+ /**
+ * Get the exporter that this import package is wired to.
+ * @return Null if the import is not yet resolved.
+ */
+ ExportPackage getExporter();
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -25,15 +25,26 @@
/**
+ * An abstraction of an osgi package declaration.
*
* @author thomas.diesler(a)jboss.com
- * @since 09-Noc-2009
+ * @since 09-Nov-2009
*/
public interface NamedPackage
{
+ /**
+ * Get the bundle that owns this package decalaration
+ */
Resolvable getOwner();
-
+
+ /**
+ * Get the package name
+ */
String getName();
-
+
+ /**
+ * Get the associated map of arbitrary attributes.
+ * @return Associated map of arbitrary attributes or an empty map.
+ */
Map<String, String> getAttributes();
}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -1,53 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.resolver;
-
-import java.util.List;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Version;
-
-/**
- *
- * @author thomas.diesler(a)jboss.com
- * @since 09-Noc-2009
- */
-public interface Resolvable
-{
- Bundle getBundle();
-
- String getSymbolicName();
-
- Version getVersion();
-
- List<ExportPackage> getExportPackages();
-
- ExportPackage getExportPackage(String packageName);
-
- List<ImportPackage> getImportPackages();
-
- ImportPackage getImportPackage(String packageName);
-
- boolean isSingleton();
-
- boolean isResolved();
-}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java (from rev 96173, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver;
+
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+/**
+ * An abstraction of a resolvable bundle.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Nov-2009
+ */
+public interface Resolvable
+{
+ /**
+ * Get the underlying bundle that this resolvable is associated with.
+ */
+ Bundle getBundle();
+
+ /**
+ * Get the bundle's symbolic name.
+ */
+ String getSymbolicName();
+
+ /**
+ * Get the bundle's version.
+ */
+ Version getVersion();
+
+ /**
+ * Get the list of exported packages in the declared order.
+ * @return The list of exported packages or an empty list if the bundle does not export any packages.
+ */
+ List<ExportPackage> getExportPackages();
+
+ /**
+ * Get an exported package by name.
+ * @return The exported package or null if the bundle does not export that package.
+ */
+ ExportPackage getExportPackage(String packageName);
+
+ /**
+ * Get the list of imported packages in the declared order.
+ * @return The list of imported packages or an empty list if the bundle does not import any packages.
+ */
+ List<ImportPackage> getImportPackages();
+
+ /**
+ * Get an imported package by name.
+ * @return The imported package or null if the bundle does not import that package.
+ */
+ ImportPackage getImportPackage(String packageName);
+
+ /**
+ * True if this resovable is a singleton bundle.
+ */
+ boolean isSingleton();
+
+ /**
+ * True if this resovable has been resolved.
+ */
+ boolean isResolved();
+}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.resolver;
-
-import java.util.List;
-
-import org.osgi.framework.Bundle;
-
-/**
- *
- * @author thomas.diesler(a)jboss.com
- * @since 09-Noc-2009
- */
-public interface Resolver
-{
- List<Resolvable> getBundles();
-
- Resolvable addBundle(Bundle bundle);
-
- Resolvable removeBundle(Bundle bundle);
-
- List<Resolvable> resolve(List<Bundle> bundles);
-
- ExportPackage getExporter(Bundle bundle, String importPackage);
-}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java (from rev 96173, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver;
+
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * The Resolver handles the resolve phase of bundles.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Nov-2009
+ */
+public interface Resolver
+{
+ /**
+ * Get the registered resolvable bundles.
+ * @return The list of registered resolvable bundles.
+ */
+ List<Resolvable> getBundles();
+
+ /**
+ * Add a bundle to the resolver.
+ * @return The resolvable associated with the added bundle.
+ */
+ Resolvable addBundle(Bundle bundle);
+
+ /**
+ * Remove a bundle from the resolver.
+ * @return The resolvable associated with the removed bundle.
+ */
+ Resolvable removeBundle(Bundle bundle);
+
+ /**
+ * Resolve the given list of bundles.
+ *
+ * @param bundles the bundles to resolve
+ * @return The list of resolved bundles in the resolve order or an empty list
+ */
+ List<Resolvable> resolve(List<Bundle> bundles);
+
+ /**
+ * Get the exporter for the given import package.
+ * @param bundle The bundle that imports the package.
+ * @param importPackage The import package name
+ * @return The export package that the import is wired to or null if the import is not yet resolved.
+ */
+ ExportPackage getExporter(Bundle bundle, String importPackage);
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -34,7 +34,7 @@
/**
*
* @author thomas.diesler(a)jboss.com
- * @since 09-Noc-2009
+ * @since 09-Nov-2009
*/
public class ExportPackageImpl extends NamedPackageImpl implements ExportPackage
{
@@ -63,7 +63,7 @@
throw new NotImplementedException();
}
- public List<NamedPackage> getUses()
+ public List<String> getUses()
{
throw new NotImplementedException();
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/NamedPackageImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/NamedPackageImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/NamedPackageImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -30,7 +30,7 @@
/**
*
* @author thomas.diesler(a)jboss.com
- * @since 09-Noc-2009
+ * @since 09-Nov-2009
*/
public class NamedPackageImpl implements NamedPackage
{
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -1,120 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.resolver.internal;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.framework.metadata.PackageAttribute;
-import org.jboss.osgi.framework.resolver.ExportPackage;
-import org.jboss.osgi.framework.resolver.ImportPackage;
-import org.jboss.osgi.framework.resolver.Resolvable;
-import org.jboss.osgi.spi.NotImplementedException;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Version;
-
-/**
- *
- * @author thomas.diesler(a)jboss.com
- * @since 09-Noc-2009
- */
-public class ResolvableImpl implements Resolvable
-{
- private OSGiBundleState bundle;
- private OSGiMetaData metaData;
- private boolean resolved;
-
- private Map<String, ExportPackage> exportedPackages = new LinkedHashMap<String, ExportPackage>();
-
- public ResolvableImpl(Bundle bundle)
- {
- this.bundle = OSGiBundleState.assertBundleState(bundle);
- this.metaData = ((OSGiBundleState)bundle).getOSGiMetaData();
-
- // Initialize exported packages
- List<PackageAttribute> exportPackages = metaData.getExportPackages();
- if (exportPackages != null)
- {
- for (PackageAttribute attr: exportPackages)
- {
- String packageName = attr.getPackageInfo().getName();
- exportedPackages.put(packageName, new ExportPackageImpl(this, packageName));
- }
- }
- }
-
- public Bundle getBundle()
- {
- return bundle;
- }
-
- public String getSymbolicName()
- {
- return bundle.getSymbolicName();
- }
-
- public Version getVersion()
- {
- return bundle.getVersion();
- }
-
- public ExportPackage getExportPackage(String packageName)
- {
- return exportedPackages.get(packageName);
- }
-
- public List<ExportPackage> getExportPackages()
- {
- List<ExportPackage> values = new ArrayList<ExportPackage>(exportedPackages.values());
- return Collections.unmodifiableList(values);
- }
-
- public ImportPackage getImportPackage(String name)
- {
- throw new NotImplementedException();
- }
-
- public List<ImportPackage> getImportPackages()
- {
- throw new NotImplementedException();
- }
-
- public boolean isResolved()
- {
- return resolved;
- }
-
- public void setResolved(boolean resolved)
- {
- this.resolved = resolved;
- }
-
- public boolean isSingleton()
- {
- return bundle.getOSGiMetaData().isSingleton();
- }
-}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java (from rev 96173, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver.internal;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.PackageAttribute;
+import org.jboss.osgi.framework.resolver.ExportPackage;
+import org.jboss.osgi.framework.resolver.ImportPackage;
+import org.jboss.osgi.framework.resolver.Resolvable;
+import org.jboss.osgi.spi.NotImplementedException;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+/**
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Nov-2009
+ */
+public class ResolvableImpl implements Resolvable
+{
+ private OSGiBundleState bundle;
+ private OSGiMetaData metaData;
+ private boolean resolved;
+
+ private Map<String, ExportPackage> exportedPackages = new LinkedHashMap<String, ExportPackage>();
+
+ public ResolvableImpl(Bundle bundle)
+ {
+ this.bundle = OSGiBundleState.assertBundleState(bundle);
+ this.metaData = ((OSGiBundleState)bundle).getOSGiMetaData();
+
+ // Initialize exported packages
+ List<PackageAttribute> exportPackages = metaData.getExportPackages();
+ if (exportPackages != null)
+ {
+ for (PackageAttribute attr: exportPackages)
+ {
+ String packageName = attr.getPackageInfo().getName();
+ exportedPackages.put(packageName, new ExportPackageImpl(this, packageName));
+ }
+ }
+ }
+
+ public Bundle getBundle()
+ {
+ return bundle;
+ }
+
+ public String getSymbolicName()
+ {
+ return bundle.getSymbolicName();
+ }
+
+ public Version getVersion()
+ {
+ return bundle.getVersion();
+ }
+
+ public ExportPackage getExportPackage(String packageName)
+ {
+ return exportedPackages.get(packageName);
+ }
+
+ public List<ExportPackage> getExportPackages()
+ {
+ List<ExportPackage> values = new ArrayList<ExportPackage>(exportedPackages.values());
+ return Collections.unmodifiableList(values);
+ }
+
+ public ImportPackage getImportPackage(String name)
+ {
+ throw new NotImplementedException();
+ }
+
+ public List<ImportPackage> getImportPackages()
+ {
+ throw new NotImplementedException();
+ }
+
+ public boolean isResolved()
+ {
+ return resolved;
+ }
+
+ public void setResolved(boolean resolved)
+ {
+ this.resolved = resolved;
+ }
+
+ public boolean isSingleton()
+ {
+ return bundle.getOSGiMetaData().isSingleton();
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -36,14 +36,16 @@
import org.jboss.classloading.spi.version.VersionRange;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.logging.Logger;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.bundle.OSGiBundleState;
import org.jboss.osgi.framework.classloading.OSGiPackageRequirement;
import org.jboss.osgi.framework.metadata.OSGiMetaData;
import org.jboss.osgi.framework.metadata.Parameter;
import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
+import org.jboss.osgi.framework.plugins.ResolverPlugin;
+import org.jboss.osgi.framework.plugins.internal.AbstractPlugin;
import org.jboss.osgi.framework.resolver.ExportPackage;
import org.jboss.osgi.framework.resolver.Resolvable;
-import org.jboss.osgi.framework.resolver.Resolver;
import org.jboss.osgi.framework.resolver.internal.ResolvableImpl;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
@@ -54,7 +56,7 @@
* @author thomas.diesler(a)jboss.com
* @since 10-Sep-2009
*/
-public class BasicResolverImpl implements Resolver
+public class BasicResolverImpl extends AbstractPlugin implements ResolverPlugin
{
/** The log */
private static final Logger log = Logger.getLogger(BasicResolverImpl.class);
@@ -63,6 +65,11 @@
private Map<OSGiBundleState, List<BundleCapability>> bundleCapabilitiesMap = new ConcurrentHashMap<OSGiBundleState, List<BundleCapability>>();
private Map<OSGiBundleState, List<BundleRequirement>> bundleRequirementsMap = new ConcurrentHashMap<OSGiBundleState, List<BundleRequirement>>();
+ public BasicResolverImpl(OSGiBundleManager bundleManager)
+ {
+ super(bundleManager);
+ }
+
public List<Resolvable> getBundles()
{
List<Resolvable> values = new ArrayList<Resolvable>(resolverBundleMap.values());
@@ -71,10 +78,6 @@
public Resolvable addBundle(Bundle bundle)
{
- // [TODO] remove this restriction
- if (bundle.getBundleId() == 0)
- return null;
-
OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
return resolverBundleMap.put(bundleState, new ResolvableImpl(bundle));
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleCapability.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleCapability.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleCapability.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -38,7 +38,7 @@
* @author thomas.diesler(a)jboss.com
* @since 10-Sep-2009
*/
-public class BundleCapability
+class BundleCapability
{
private OSGiBundleState bundle;
private PackageCapability packageCapability;
@@ -55,24 +55,24 @@
this.packageCapability = packageCapability;
}
- public OSGiBundleState getExportingBundle()
+ OSGiBundleState getExportingBundle()
{
return bundle;
}
- public Module getExportingModule()
+ Module getExportingModule()
{
OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
DeploymentUnit unit = bundleState.getDeploymentUnit();
return unit.getAttachment(Module.class);
}
- public PackageCapability getPackageCapability()
+ PackageCapability getPackageCapability()
{
return packageCapability;
}
- public List<BundleRequirement> getWiredRequirements()
+ List<BundleRequirement> getWiredRequirements()
{
if (wires == null)
return Collections.emptyList();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleRequirement.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleRequirement.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleRequirement.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -30,7 +30,7 @@
* @author thomas.diesler(a)jboss.com
* @since 10-Sep-2009
*/
-public class BundleRequirement
+class BundleRequirement
{
private OSGiBundleState bundle;
private PackageRequirement packageRequirement;
@@ -47,17 +47,17 @@
this.packageRequirement = packageRequirement;
}
- public BundleCapability getWiredCapability()
+ BundleCapability getWiredCapability()
{
return wire;
}
- public OSGiBundleState getImportingBundle()
+ OSGiBundleState getImportingBundle()
{
return bundle;
}
- public PackageRequirement getPackageRequirement()
+ PackageRequirement getPackageRequirement()
{
return packageRequirement;
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/DeployerServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/DeployerServiceImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/DeployerServiceImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -34,7 +34,7 @@
import org.jboss.osgi.deployment.internal.SystemDeployerService;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.plugins.DeployerServicePlugin;
-import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
+import org.jboss.osgi.framework.plugins.internal.AbstractServicePlugin;
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -45,7 +45,7 @@
* @author thomas.diesler(a)jboss.com
* @since 19-Oct-2009
*/
-public class DeployerServiceImpl extends AbstractServicePluginImpl implements DeployerServicePlugin
+public class DeployerServiceImpl extends AbstractServicePlugin implements DeployerServicePlugin
{
// Provide logging
final Logger log = Logger.getLogger(DeployerServiceImpl.class);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -36,7 +36,7 @@
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.bundle.OSGiBundleState;
import org.jboss.osgi.framework.plugins.LifecycleInterceptorServicePlugin;
-import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
+import org.jboss.osgi.framework.plugins.internal.AbstractServicePlugin;
import org.jboss.osgi.framework.util.DeploymentUnitAttachments;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -48,7 +48,7 @@
* @author thomas.diesler(a)jboss.com
* @since 19-Oct-2009
*/
-public class LifecycleInterceptorServiceImpl extends AbstractServicePluginImpl implements LifecycleInterceptorServicePlugin
+public class LifecycleInterceptorServiceImpl extends AbstractServicePlugin implements LifecycleInterceptorServicePlugin
{
// Provide logging
final Logger log = Logger.getLogger(LifecycleInterceptorServiceImpl.class);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/MicrocontainerServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/MicrocontainerServiceImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/MicrocontainerServiceImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -43,7 +43,7 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.plugins.MicrocontainerServicePlugin;
-import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
+import org.jboss.osgi.framework.plugins.internal.AbstractServicePlugin;
import org.jboss.osgi.spi.management.MicrocontainerServiceMBean;
import org.jboss.osgi.spi.service.MicrocontainerService;
import org.osgi.framework.Constants;
@@ -59,7 +59,7 @@
* @author thomas.diesler(a)jboss.com
* @since 31-Aug-2009
*/
-public class MicrocontainerServiceImpl extends AbstractServicePluginImpl implements MicrocontainerServicePlugin, MicrocontainerServiceMBean
+public class MicrocontainerServiceImpl extends AbstractServicePlugin implements MicrocontainerServicePlugin, MicrocontainerServiceMBean
{
/** The log */
private static final Logger log = Logger.getLogger(MicrocontainerServiceImpl.class);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -37,8 +37,9 @@
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.bundle.OSGiBundleState;
import org.jboss.osgi.framework.bundle.OSGiBundleWrapper;
+import org.jboss.osgi.framework.plugins.ResolverPlugin;
import org.jboss.osgi.framework.plugins.PackageAdminServicePlugin;
-import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
+import org.jboss.osgi.framework.plugins.internal.AbstractServicePlugin;
import org.jboss.osgi.framework.resolver.Resolver;
import org.jboss.osgi.framework.resolver.Resolvable;
import org.jboss.osgi.spi.NotImplementedException;
@@ -58,7 +59,7 @@
* @author thomas.diesler(a)jboss.com
* @since 03-Sep-2009
*/
-public class PackageAdminImpl extends AbstractServicePluginImpl implements PackageAdminServicePlugin
+public class PackageAdminImpl extends AbstractServicePlugin implements PackageAdminServicePlugin
{
/** The log */
private static final Logger log = Logger.getLogger(PackageAdminImpl.class);
@@ -179,7 +180,7 @@
return true;
// Resolve the bundles through the resolver
- Resolver bundleResolver = bundleManager.getBundleResolver();
+ Resolver bundleResolver = bundleManager.getPlugin(ResolverPlugin.class);
List<OSGiBundleState> resolvableBundles = new ArrayList<OSGiBundleState>();
for (Resolvable aux : bundleResolver.resolve(unresolvedBundles))
resolvableBundles.add(OSGiBundleState.assertBundleState(aux.getBundle()));
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/StartLevelImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/StartLevelImpl.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/StartLevelImpl.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -26,7 +26,7 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.plugins.StartLevelPlugin;
-import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
+import org.jboss.osgi.framework.plugins.internal.AbstractServicePlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.startlevel.StartLevel;
@@ -39,7 +39,7 @@
* @author thomas.diesler(a)jboss.com
* @since 31-Aug-2009
*/
-public class StartLevelImpl extends AbstractServicePluginImpl implements StartLevelPlugin
+public class StartLevelImpl extends AbstractServicePlugin implements StartLevelPlugin
{
/** The log */
private static final Logger log = Logger.getLogger(StartLevelImpl.class);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTest.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTest.java 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTest.java 2009-11-09 16:45:35 UTC (rev 96181)
@@ -31,6 +31,7 @@
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.launch.OSGiFramework;
+import org.jboss.osgi.framework.plugins.ResolverPlugin;
import org.jboss.osgi.framework.resolver.Resolvable;
import org.jboss.osgi.framework.resolver.Resolver;
import org.jboss.osgi.spi.util.ServiceLoader;
@@ -83,7 +84,7 @@
}
OSGiBundleManager bundleManager = ((OSGiFramework)framework).getBundleManager();
- Resolver bundleResolver = bundleManager.getBundleResolver();
+ Resolver bundleResolver = bundleManager.getPlugin(ResolverPlugin.class);
assertEquals("All bundles installed", bundlePaths.size(), bundleResolver.getBundles().size());
List<Resolvable> resolved = bundleResolver.resolve(unresolved);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-09 16:45:35 UTC (rev 96181)
@@ -55,6 +55,9 @@
<bean name="OSGiSystemPackages" class="org.jboss.osgi.framework.plugins.internal.SystemPackagesPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
+ <bean name="OSGiBundleResolver" class="org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<!--
********************************
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-09 16:45:35 UTC (rev 96181)
@@ -71,6 +71,9 @@
</list>
</property>
</bean>
+ <bean name="OSGiBundleResolver" class="org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
<property name="synchronous">true</property>
Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-09 16:25:30 UTC (rev 96180)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-09 16:45:35 UTC (rev 96181)
@@ -72,6 +72,9 @@
</list>
</property>
</bean>
+ <bean name="OSGiBundleResolver" class="org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
14 years, 6 months
JBoss-OSGI SVN: r96174 - in projects/jboss-osgi/trunk/reactor/framework/src/test: java/org/jboss/test/osgi and 9 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-09 09:12:05 -0500 (Mon, 09 Nov 2009)
New Revision: 96174
Added:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ClassLoaderDomainUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/
Removed:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/test/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/filter/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/test/
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/bundle/
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/deployers/
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/AbstractManifestTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/VersionRangeTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/metadata/SimpleManifest.mf
Log:
Allign location of metadata tests with others
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,508 @@
+/*
+* 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.bundle;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Set;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * BundleContextUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler(a)jboss.com
+ * @version $Revision: 1.1 $
+ */
+public class BundleContextUnitTestCase extends OSGiTestCase
+{
+ public BundleContextUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetBundle() throws Exception
+ {
+ Bundle bundle1 = addBundle("/bundles/simple/", "simple-bundle1");
+ BundleContext context1 = null;
+ try
+ {
+ bundle1.start();
+ context1 = bundle1.getBundleContext();
+ assertEquals(bundle1, context1.getBundle());
+ assertEquals(bundle1, context1.getBundle(bundle1.getBundleId()));
+
+ Bundle[] bundles = context1.getBundles();
+ Set<Bundle> actual = new HashSet<Bundle>(Arrays.asList(bundles));
+ Set<Bundle> expected = new HashSet<Bundle>(Arrays.asList(bundle1));
+ addBaseBundles(expected);
+ assertEquals(expected, actual);
+
+ Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ BundleContext context2 = null;
+ try
+ {
+ bundle2.start();
+ context2 = bundle2.getBundleContext();
+ assertEquals(bundle2, context2.getBundle());
+
+ bundles = context1.getBundles();
+ actual = new HashSet<Bundle>(Arrays.asList(bundles));
+ expected = new HashSet<Bundle>(Arrays.asList(bundle1, bundle2));
+ addBaseBundles(expected);
+ assertEquals(expected, actual);
+
+ assertEquals(bundle1, context2.getBundle(bundle1.getBundleId()));
+ assertEquals(bundle2, context1.getBundle(bundle2.getBundleId()));
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+
+ assertEquals(bundle1, context1.getBundle(bundle1.getBundleId()));
+ assertNull(context1.getBundle(bundle2.getBundleId()));
+
+ bundles = context1.getBundles();
+ actual = new HashSet<Bundle>(Arrays.asList(bundles));
+ expected = new HashSet<Bundle>(Arrays.asList(bundle1));
+ addBaseBundles(expected);
+ assertEquals(expected, actual);
+
+ try
+ {
+ context2.getBundle();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ context2.getBundle(bundle1.getBundleId());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ context2.getBundles();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+
+ try
+ {
+ context1.getBundle();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ context1.getBundle(bundle1.getBundleId());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ context1.getBundles();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testProperties() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+ assertEquals("r4v42", bundleContext.getProperty(Constants.FRAMEWORK_VERSION));
+ assertEquals("jboss.org", bundleContext.getProperty(Constants.FRAMEWORK_VENDOR));
+ assertEquals(Locale.getDefault().getISO3Language(), bundleContext.getProperty(Constants.FRAMEWORK_LANGUAGE));
+ assertSystemProperty(bundleContext, "os.name", Constants.FRAMEWORK_OS_NAME);
+ assertSystemProperty(bundleContext, "os.version", Constants.FRAMEWORK_OS_VERSION);
+ assertSystemProperty(bundleContext, "os.arch", Constants.FRAMEWORK_PROCESSOR);
+
+ assertNull(bundleContext.getProperty(getClass().getName()));
+ System.setProperty(getClass().getName(), "test");
+ assertEquals("test", bundleContext.getProperty(getClass().getName()));
+
+ bundle.stop();
+ try
+ {
+ bundleContext.getProperty(getClass().getName());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testInstallBundle() throws Exception
+ {
+ // TODO testInstallBundle
+ }
+
+ public void testServiceListener() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ try
+ {
+ bundleContext.addServiceListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.addServiceListener(null, "(a=b)");
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.removeServiceListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ bundleContext.addServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this);
+ bundleContext.removeServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, false);
+
+ bundleContext.addServiceListener(this);
+ bundleContext.addServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this, null);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this, null);
+ bundleContext.removeServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, false);
+
+ bundleContext.addServiceListener(this, null);
+ bundleContext.addServiceListener(this, null);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext.removeServiceListener(this);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("a", "b");
+
+ bundleContext.addServiceListener(this, ("(a=b)"));
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, true);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this, ("(c=d)"));
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, false);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this, "(a=b)");
+ bundleContext.removeServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, false);
+
+ bundleContext.addServiceListener(this, "(c=d)");
+ bundleContext.addServiceListener(this, "(a=b)");
+ assertServiceLifecycle(bundle, bundleContext, properties, true);
+ bundleContext.removeServiceListener(this);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ protected BundleContext assertServiceLifecycle(Bundle bundle, BundleContext bundleContext, boolean events) throws Exception
+ {
+ return assertServiceLifecycle(bundle, bundleContext, null, events);
+ }
+
+ protected BundleContext assertServiceLifecycle(Bundle bundle, BundleContext bundleContext, Dictionary<String, Object> properties, boolean events) throws Exception
+ {
+ assertNoServiceEvent();
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ ServiceReference reference = registration.getReference();
+
+ if (events)
+ assertServiceEvent(ServiceEvent.REGISTERED, reference);
+ else
+ assertNoServiceEvent();
+
+ registration.setProperties(properties);
+ if (events)
+ assertServiceEvent(ServiceEvent.MODIFIED, reference);
+ else
+ assertNoServiceEvent();
+
+ registration.unregister();
+ if (events)
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+ else
+ assertNoServiceEvent();
+
+ registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ reference = registration.getReference();
+ if (events)
+ assertServiceEvent(ServiceEvent.REGISTERED, reference);
+ else
+ assertNoServiceEvent();
+
+ bundle.stop();
+ if (events)
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+ else
+ assertNoServiceEvent();
+
+ try
+ {
+ bundleContext.addServiceListener(this);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ bundle.start();
+ bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+ return bundleContext;
+ }
+
+ public void testBundleListener() throws Exception
+ {
+ // todo how to test INSTALLED/RESOLVED?
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ try
+ {
+ bundleContext.addBundleListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.removeBundleListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ bundleContext.addBundleListener(this);
+ bundleContext = assertBundleLifecycle(bundle, bundleContext, true);
+ bundleContext.removeBundleListener(this);
+
+ bundleContext.addBundleListener(this);
+ bundleContext.removeBundleListener(this);
+ bundleContext = assertBundleLifecycle(bundle, bundleContext, false);
+
+ bundleContext.addBundleListener(this);
+ bundleContext.addBundleListener(this);
+ bundleContext = assertBundleLifecycle(bundle, bundleContext, true);
+ bundleContext.removeBundleListener(this);
+
+ bundleContext.addBundleListener(this);
+
+ // todo test asynch BundleListener
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertBundleEvent(BundleEvent.STOPPING, bundle);
+ assertBundleEvent(BundleEvent.STOPPED, bundle);
+ // todo assertBundleEvent(BundleEvent.UNRESOLVED, bundle);
+ assertBundleEvent(BundleEvent.UNINSTALLED, bundle);
+ }
+
+ protected BundleContext assertBundleLifecycle(Bundle bundle, BundleContext bundleContext, boolean events) throws Exception
+ {
+ assertNoBundleEvent();
+
+ bundle.stop();
+ if (events)
+ {
+ assertBundleEvent(BundleEvent.STOPPING, bundle);
+ assertBundleEvent(BundleEvent.STOPPED, bundle);
+ }
+ else
+ {
+ assertNoBundleEvent();
+ }
+
+ bundle.start();
+ if (events)
+ {
+ assertBundleEvent(BundleEvent.STARTING, bundle);
+ assertBundleEvent(BundleEvent.STARTED, bundle);
+ }
+ else
+ {
+ assertNoBundleEvent();
+ }
+
+ return bundleContext;
+ }
+
+ public void testFrameworkListener() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ try
+ {
+ bundleContext.addFrameworkListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.removeFrameworkListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ // todo test events
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetDataFile() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ File dataFile = bundleContext.getDataFile("blah");
+ assertNotNull(dataFile);
+ assertTrue(dataFile.toString().endsWith(File.separator + "blah"));
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ protected void assertSystemProperty(BundleContext bundleContext, String property, String osgiProperty)
+ {
+ String expected = System.getProperty(property);
+ assertNotNull(expected);
+ assertEquals(expected, bundleContext.getProperty(osgiProperty));
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/BundleEntriesUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,462 @@
+/*
+* 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.bundle;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+
+/**
+ * BundleEntriesUnitTestCase.
+ *
+ * TODO test security
+ * TODO test fragments
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleEntriesUnitTestCase extends OSGiTestCase
+{
+ public BundleEntriesUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testEntriesNotInstalled() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ uninstall(bundle);
+ try
+ {
+ bundle.getEntry("root.xml");
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ try
+ {
+ bundle.findEntries("", "root.xml", false);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testFindEntriesNoPath() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ try
+ {
+ bundle.findEntries(null, "root.xml", false);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testEntries() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ try
+ {
+ assertEntry(bundle, "");
+ assertNoEntries(bundle, "", "", false);
+ assertNoEntries(bundle, "", "", true);
+ assertEntryPaths("", bundle,
+ "/",
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml",
+ "META-INF/",
+ "META-INF/MANIFEST.MF",
+ "org/",
+ "org/jboss/",
+ "org/jboss/test/",
+ "org/jboss/test/osgi/",
+ "org/jboss/test/osgi/bundle/",
+ "org/jboss/test/osgi/bundle/entries/",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertNoEntry(bundle, "DoesNotExist");
+ assertNoEntries(bundle, "", "DoesNotExist", false);
+ assertNoEntries(bundle, "", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "DoesNotExist");
+
+ assertEntry(bundle, "root-no-suffix");
+ assertEntries(bundle, "", "root-no-suffix", false, "root-no-suffix");
+ assertEntries(bundle, "", "root-no-suffix", true, "root-no-suffix");
+ assertEntryPaths(bundle, "root-no-suffix");
+
+ assertEntry(bundle, "root.xml");
+ assertEntries(bundle, "", "root.xml", false, "root.xml");
+ assertEntries(bundle, "", "root.xml", true, "root.xml");
+ assertEntryPaths(bundle, "root.xml");
+
+ assertEntry(bundle, "entry1.xml");
+ assertEntries(bundle, "", "entry1.xml", false, "entry1.xml");
+ assertEntries(bundle, "", "entry1.xml", true,
+ "entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml"
+ );
+ assertEntryPaths(bundle, "entry1.xml");
+
+ assertEntry(bundle, "META-INF");
+ assertNoEntries(bundle, "", "META-INF", false);
+ assertNoEntries(bundle, "", "META-INF", true);
+ assertEntryPaths("META-INF", bundle,
+ "META-INF/",
+ "META-INF/MANIFEST.MF"
+ );
+
+ assertNoEntry(bundle, "META-INF/DoesNotExist");
+ assertNoEntries(bundle, "META-INF", "DoesNotExist", false);
+ assertNoEntries(bundle, "META-INF", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "META-INF/DoesNotExist");
+
+ assertEntry(bundle, "META-INF/MANIFEST.MF");
+ assertEntries(bundle, "META-INF", "MANIFEST.MF", false, "META-INF/MANIFEST.MF");
+ assertEntries(bundle, "META-INF", "MANIFEST.MF", true, "META-INF/MANIFEST.MF");
+ assertEntryPaths(bundle, "META-INF/MANIFEST.MF");
+
+ assertEntry(bundle, "org");
+ assertNoEntries(bundle, "", "org", false);
+ assertNoEntries(bundle, "", "org", true);
+ assertEntryPaths("org", bundle,
+ "org/",
+ "org/jboss/",
+ "org/jboss/test/",
+ "org/jboss/test/osgi/",
+ "org/jboss/test/osgi/bundle/",
+ "org/jboss/test/osgi/bundle/entries/",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertNoEntry(bundle, "org/DoesNotExist");
+ assertNoEntries(bundle, "org", "DoesNotExist", false);
+ assertNoEntries(bundle, "org", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "org/DoesNotExist");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries");
+ assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries", false);
+ assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries", true);
+ assertEntryPaths("org/jboss/test/osgi/bundle/entries", bundle,
+ "org/jboss/test/osgi/bundle/entries/",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertNoEntry(bundle, "org/jboss/test/osgi/bundle/DoesNotExist");
+ assertNoEntries(bundle, "org/jboss/test/osgi/bundle", "DoesNotExist", false);
+ assertNoEntries(bundle, "org/jboss/test/osgi/bundle", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "org/jboss/test/osgi/bundle/DoesNotExist");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/notxml.suffix");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "notxml.suffix", false,
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "notxml.suffix", true,
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix"
+ );
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/notxml.suffix");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/entry1.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry1.xml", false,
+ "org/jboss/test/osgi/bundle/entries/entry1.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry1.xml", true,
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml"
+ );
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/entry1.xml");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/entry2.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry2.xml", false,
+ "org/jboss/test/osgi/bundle/entries/entry2.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry2.xml", true,
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/entry2.xml");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/sub");
+ assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries/sub", false);
+ assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries/sub", true);
+ assertEntryPaths("org/jboss/test/osgi/bundle/entries/sub", bundle,
+ "org/jboss/test/osgi/bundle/entries/sub/",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertNoEntry(bundle, "org/jboss/test/osgi/bundle/DoesNotExist/sub");
+ assertNoEntries(bundle, "org/jboss/test/osgi/bundle/sub", "DoesNotExist", false);
+ assertNoEntries(bundle, "org/jboss/test/osgi/bundle/sub", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "org/jboss/test/osgi/bundle/DoesNotExist/sub");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry1.xml", false,
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry1.xml", true,
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry2.xml", false,
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry2.xml", true,
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+
+ assertEntries(bundle, "", "*", false,
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", "*", true,
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml",
+ "META-INF/MANIFEST.MF",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "", null, false,
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", null, true,
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml",
+ "META-INF/MANIFEST.MF",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "", "root*", false,
+ "root-no-suffix",
+ "root.xml"
+ );
+ assertEntries(bundle, "", "root*", true,
+ "root-no-suffix",
+ "root.xml"
+ );
+
+ assertEntries(bundle, "", "entry*", false,
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", "entry*", true,
+ "entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry*", false,
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml"
+ );
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry*", true,
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "", "*.xml", false,
+ "root.xml",
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", "*.xml", true,
+ "root.xml",
+ "entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "", "*xml*", false,
+ "root.xml",
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", "*xml*", true,
+ "root.xml",
+ "entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "*xml*", false,
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml"
+ );
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "*xml*", true,
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ protected void assertEntry(Bundle bundle, String path) throws Exception
+ {
+ URL expected = getBundleResource(bundle, path);
+ if (expected == null)
+ fail("Expected resource not found: " + path);
+
+ assertEntry(bundle, path, expected);
+ assertEntry(bundle, "/" + path, expected);
+ }
+
+ protected void assertEntry(Bundle bundle, String path, URL expected) throws Exception
+ {
+ URL actual = bundle.getEntry(path);
+ assertEquals(expected, actual);
+ }
+
+ protected void assertNoEntry(Bundle bundle, String path) throws Exception
+ {
+ URL actual = bundle.getEntry(path);
+ assertNull("Did not expect entry: " + actual + " for path: " + path, actual);
+ }
+
+ protected void assertEntries(Bundle bundle, String path, String filePattern, boolean recurse, String... entries) throws Exception
+ {
+ Set<URL> expected = new HashSet<URL>();
+ for (String entry : entries)
+ {
+ Enumeration<URL> urls = getBundleResources(bundle, entry);
+ if (urls == null || urls.hasMoreElements() == false)
+ fail("Expected resource not found: " + entry);
+ while (urls.hasMoreElements())
+ expected.add(urls.nextElement());
+ }
+
+ assertEntries(bundle, path, filePattern, recurse, expected);
+ assertEntries(bundle, "/" + path, filePattern, recurse, expected);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void assertEntries(Bundle bundle, String path, String filePattern, boolean recurse, Set<URL> expected) throws Exception
+ {
+ Set<URL> actual = new HashSet<URL>();
+ Enumeration<URL> enumeration = bundle.findEntries(path, filePattern, recurse);
+ while (enumeration != null && enumeration.hasMoreElements())
+ actual.add(enumeration.nextElement());
+
+ assertEquals(expected, actual);
+ }
+
+ protected void assertNoEntries(Bundle bundle, String path, String filePattern, boolean recurse) throws Exception
+ {
+ assertEntries(bundle, path, filePattern, recurse);
+ }
+
+ protected void assertEntryPaths(Bundle bundle, String path) throws Exception
+ {
+ Set<String> expected = Collections.singleton(path);
+
+ assertEntryPaths(bundle, path, expected);
+ assertEntryPaths(bundle, "/" + path, expected);
+ }
+
+ protected void assertEntryPaths(String path, Bundle bundle, String... entries) throws Exception
+ {
+ Set<String> expected = new HashSet<String>();
+ expected.addAll(Arrays.asList(entries));
+
+ assertEntryPaths(bundle, path, expected);
+ assertEntryPaths(bundle, "/" + path, expected);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void assertEntryPaths(Bundle bundle, String path, Set<String> expected) throws Exception
+ {
+ Set<String> actual = new HashSet<String>();
+ Enumeration<String> enumeration = bundle.getEntryPaths(path);
+ while (enumeration != null && enumeration.hasMoreElements())
+ actual.add(enumeration.nextElement());
+
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void assertNoEntryPaths(Bundle bundle, String path) throws Exception
+ {
+ Enumeration<String> enumeration = bundle.getEntryPaths(path);
+ if (enumeration != null)
+ {
+ Set<String> actual = new HashSet<String>();
+ while (enumeration.hasMoreElements())
+ actual.add(enumeration.nextElement());
+ fail("For path " + path + " did not expect entry paths: " + actual);
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/BundleUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,245 @@
+/*
+* 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.bundle;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.jar.Attributes;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * BundleUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleUnitTestCase extends OSGiTestCase
+{
+ public BundleUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testBundleId() throws Exception
+ {
+ long id1 = -1;
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ id1 = bundle.getBundleId();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertEquals(id1, bundle.getBundleId());
+
+ long id2 = -1;
+ bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ id2 = bundle.getBundleId();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertEquals(id2, bundle.getBundleId());
+ assertTrue("Ids should be different" + id1 + "," + id2, id1 != id2);
+ }
+
+ public void testSymbolicName() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicName());
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicName());
+ }
+
+ public void testState() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ assertEquals(Bundle.INSTALLED, bundle.getState());
+
+ bundle.start();
+ assertEquals(Bundle.ACTIVE, bundle.getState());
+
+ bundle.stop();
+ assertEquals(Bundle.RESOLVED, bundle.getState());
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertEquals(Bundle.UNINSTALLED, bundle.getState());
+ }
+
+ public void testGetBundleContext() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNull(bundleContext);
+
+ bundle.start();
+ bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundle.stop();
+ bundleContext = bundle.getBundleContext();
+ assertNull(bundleContext);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testLastModified() throws Exception
+ {
+ // TODO testLastModified
+ }
+
+ public void testStartStop() throws Exception
+ {
+ // TODO testStartStop
+ }
+
+ public void testUpdate() throws Exception
+ {
+ // TODO testUpdate
+ }
+
+ public void testUninstall() throws Exception
+ {
+ // TODO testUninstall
+ }
+
+ public void testSingleton() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundle1", "/bundles/singleton/singleton1");
+ try
+ {
+ Bundle bundle2 = assembleBundle("bundle2", "/bundles/singleton/singleton2");
+ uninstall(bundle2);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(BundleException.class, t);
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testNotSingleton() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundle1", "/bundles/singleton/singleton1");
+ try
+ {
+ Bundle bundle2 = assembleBundle("not-singleton", "/bundles/singleton/not-singleton");
+ try
+ {
+ assertEquals(bundle1.getSymbolicName(), bundle2.getSymbolicName());
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetHeaders() throws Exception
+ {
+ // TODO case insensistive
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ Dictionary expected = new Hashtable();
+ expected.put(Constants.BUNDLE_NAME, "Simple1");
+ expected.put(Constants.BUNDLE_SYMBOLICNAME, "org.jboss.test.osgi.simple1");
+ expected.put(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
+ expected.put(Attributes.Name.IMPLEMENTATION_TITLE.toString(), "JBoss OSGi tests");
+ expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
+ expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "test");
+
+ Dictionary dictionary = bundle.getHeaders();
+ assertEquals(expected, dictionary);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testLocation() throws Exception
+ {
+ // TODO testGetLocation
+ }
+
+ public void testGetRegisteredServices() throws Exception
+ {
+ // TODO testGetRegisteredServices
+ }
+
+ public void testServicesInUse() throws Exception
+ {
+ // TODO testServicesInUse
+ }
+
+ public void testHasPermission() throws Exception
+ {
+ // TODO testHasPermission
+ }
+
+ public void testGetResources() throws Exception
+ {
+ // TODO testGetResource(s)
+ }
+
+ public void testLoadClass() throws Exception
+ {
+ // TODO testLoadClass
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/SystemBundleUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,147 @@
+/*
+* 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.bundle;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.OSGiTestDelegate;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * SystemBundleUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SystemBundleUnitTestCase extends OSGiTestCase
+{
+ /** The system bundle */
+ private static Bundle systemBundle = null;
+
+ public SystemBundleUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static void deployBundles(OSGiTestDelegate delegate) throws Exception
+ {
+ Bundle bundle = delegate.addBundle("/bundles/simple/", "simple-bundle1");
+ bundle.start();
+ BundleContext context = bundle.getBundleContext();
+ assertNotNull(context);
+ systemBundle = context.getBundle(0);
+ assertNotNull(systemBundle);
+ }
+
+ public void testBundleId() throws Exception
+ {
+ assertEquals(0, systemBundle.getBundleId());
+ }
+
+ public void testSymbolicName() throws Exception
+ {
+ assertEquals(Constants.SYSTEM_BUNDLE_SYMBOLICNAME, systemBundle.getSymbolicName());
+ }
+
+ public void testState() throws Exception
+ {
+ assertEquals(Bundle.ACTIVE, systemBundle.getState());
+ }
+
+ public void testStartStop() throws Exception
+ {
+ // TODO testStartStop
+ }
+
+ public void testUpdate() throws Exception
+ {
+ // TODO testUpdate
+ }
+
+ public void testUninstall() throws Exception
+ {
+ try
+ {
+ systemBundle.uninstall();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(BundleException.class, t);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetHeaders() throws Exception
+ {
+ Dictionary expected = new Hashtable();
+ expected.put(Constants.BUNDLE_NAME, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
+ expected.put(Constants.BUNDLE_SYMBOLICNAME, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
+ // todo expected.put(Attributes.Name.IMPLEMENTATION_TITLE.toString(), "JBoss OSGi");
+ // todo expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
+ // todo expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "r4v41");
+
+ Dictionary dictionary = systemBundle.getHeaders();
+ assertEquals(expected, dictionary);
+ }
+
+ public void testLocation() throws Exception
+ {
+ assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, systemBundle.getLocation());
+ }
+
+ public void testGetEntry()
+ {
+ // TODO [JBOSGI-138] Proper system BundleContext implementation
+ }
+
+ public void testGetEntryPath()
+ {
+ // TODO [JBOSGI-138] Proper system BundleContext implementation
+ }
+
+ public void testFindEntries()
+ {
+ // TODO [JBOSGI-138] Proper system BundleContext implementation
+ }
+
+ public void testLoadClass()
+ {
+ // TODO [JBOSGI-138] Proper system BundleContext implementation
+ }
+
+ public void testGetResource()
+ {
+ // TODO [JBOSGI-138] Proper system BundleContext implementation
+ }
+
+ public void testGetResources()
+ {
+ // TODO [JBOSGI-138] Proper system BundleContext implementation
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata)
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/AbstractManifestTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata/AbstractManifestTestCase.java 2009-11-05 18:58:42 UTC (rev 96066)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/AbstractManifestTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -19,7 +19,7 @@
* 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.bundle.metadata;
+package org.jboss.test.osgi.bundle.metadata;
import java.io.IOException;
import java.io.InputStream;
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata/HeaderValuesTestCase.java 2009-11-05 18:58:42 UTC (rev 96066)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -19,7 +19,7 @@
* 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.bundle.metadata;
+package org.jboss.test.osgi.bundle.metadata;
import java.io.Serializable;
import java.net.URL;
@@ -79,7 +79,7 @@
Manifest manifest = getManifest(createName("Simple"));
OSGiMetaData metaData = new AbstractOSGiMetaData(manifest);
- assertEquals(metaData.getBundleActivator(), "org.jboss.test.bundle.metadata.BundleActivator");
+ assertEquals(metaData.getBundleActivator(), "org.jboss.test.osgi.bundle.metadata.BundleActivator");
List<String> classpath = Arrays.asList("test.jar", "mc.jar", "seam.jar");
assertEquals(metaData.getBundleClassPath(), classpath);
assertEquals(metaData.getBundleDescription(), "TestHeadersManifest");
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/VersionRangeTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata/VersionRangeTestCase.java 2009-11-05 18:58:42 UTC (rev 96066)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/VersionRangeTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -1,4 +1,4 @@
-package org.jboss.test.bundle.metadata;
+package org.jboss.test.osgi.bundle.metadata;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ClassLoaderDomainUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/test/ClassLoaderDomainUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ClassLoaderDomainUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ClassLoaderDomainUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,112 @@
+/*
+* 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;
+
+// $Id$
+
+import static org.junit.Assert.fail;
+
+import java.net.URL;
+
+import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
+import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.spi.filter.PackageClassFilter;
+import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.testing.OSGiTestHelper;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * ClassLoaderDomainUnitTestCase.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 03-Sep-2009
+ */
+public class ClassLoaderDomainUnitTestCase
+{
+ private static final String OSGI_CLASSLOADER_DOMAIN = "OSGiDomain";
+ private ClassLoaderSystem classLoaderSystem;
+
+ @Before
+ public void setUp()
+ {
+ classLoaderSystem = new DefaultClassLoaderSystem();
+ AbstractJDKChecker.getExcluded().add(getClass());
+ }
+
+ @Test
+ public void testSystemPolicy() throws Exception
+ {
+ ClassLoaderDomain domain = new ClassLoaderDomain(OSGI_CLASSLOADER_DOMAIN);
+ classLoaderSystem.registerDomain(domain);
+
+ // Setup the class filter
+ String filteredPackages = Logger.class.getPackage().getName();
+ PackageClassFilter classFilter = PackageClassFilter.createPackageClassFilterFromString(filteredPackages);
+ classFilter.setIncludeJava(true);
+
+ domain.setParentPolicy(new ParentPolicy(classFilter, ClassFilter.NOTHING));
+
+ URL coreURL = new OSGiTestHelper().getTestArchiveURL("bundles/org.osgi.core.jar");
+ VirtualFile coreVF = VFS.createNewRoot(coreURL);
+
+ ClassLoaderPolicy systemPolicy = new VFSClassLoaderPolicy("OSGiSystemPolicy", new VirtualFile[] { coreVF });
+ ClassLoader classLoader = classLoaderSystem.registerClassLoaderPolicy(OSGI_CLASSLOADER_DOMAIN, systemPolicy);
+
+ // Load JDK class
+ assertLoadClass(classLoader, String.class.getName(), true);
+
+ // Load from org.osgi.core
+ assertLoadClass(classLoader, Bundle.class.getName(), true);
+
+ // Load from system classpath
+ assertLoadClass(classLoader, Logger.class.getName(), true);
+
+ // No access to implementation
+ assertLoadClass(classLoader, OSGiBundleManager.class.getName(), false);
+ }
+
+ private void assertLoadClass(ClassLoader classLoader, String name, boolean success)
+ {
+ try
+ {
+ classLoader.loadClass(name);
+ if (success == false)
+ fail("Expected ClassNotFoundException for '" + name + "' from " + classLoader);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ if (success)
+ fail("Cannot load '" + name + "' from " + classLoader);
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/test/ExportImportPackageUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,519 @@
+/*
+* 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 org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.classloader.support.a.A;
+import org.jboss.test.osgi.classloader.support.b.B;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * ExportImportUnitTestCase.
+ *
+ * TODO test security
+ * TODO test mandatory attributes
+ * TODO test include/exclude
+ * TODO test uses
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler(a)jboss.com
+ * @version $Revision: 1.1 $
+ */
+public class ExportImportPackageUnitTestCase extends OSGiTestCase
+{
+ public ExportImportPackageUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testSimpleImportPackage() throws Exception
+ {
+ //Bundle-Name: BundleA
+ //Bundle-Version: 1.0.0
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
+ //Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+
+ //Bundle-Name: BundleB
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+ //Export-Package: org.jboss.test.osgi.classloader.support.b
+ //Import-Package: org.jboss.test.osgi.classloader.support.a
+ Bundle bundle2 = assembleBundle("simpleimportpackageA", "/bundles/classloader/simpleimportpackageA", B.class);
+
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+
+ assertLoadClassFail(bundle1, B.class);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testSimpleImportPackageFails() throws Exception
+ {
+ //Bundle-Name: BundleA
+ //Bundle-Version: 1.0.0
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
+ //Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+
+ //Bundle-Name: BundleB
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+ //Import-Package: doesnotexist
+ Bundle bundle2 = assembleBundle("simpleimportpackagefails", "/bundles/classloader/simpleimportpackagefails", B.class);
+
+ try
+ {
+ bundle2.start();
+ fail("Should not be here!");
+ }
+ catch (BundleException ex)
+ {
+ // expected
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testSelfImportPackage() throws Exception
+ {
+ //Bundle-Name: BundleB
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+ //Export-Package: org.jboss.test.osgi.classloader.support.b
+ //Import-Package: org.jboss.test.osgi.classloader.support.a
+ Bundle bundleB = assembleBundle("BundleB", "/bundles/classloader/simpleimportpackageA", B.class);
+
+ try
+ {
+ assertEquals("Bundle INSTALLED", Bundle.INSTALLED, bundleB.getState());
+
+ try
+ {
+ bundleB.start();
+ fail("Expected to fail due to unresolved import");
+ }
+ catch (BundleException ex)
+ {
+ // expected
+ }
+
+ //Bundle-Name: BundleA
+ //Bundle-Version: 1.0.0
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA
+ //Export-Package: org.jboss.test.osgi.classloader.support.a, org.jboss.test.osgi.classloader.support.b
+ //Import-Package: org.jboss.test.osgi.classloader.support.a, org.jboss.test.osgi.classloader.support.b
+ Bundle bundleA = assembleBundle("BundleA", "/bundles/classloader/selfimportpackageAB", A.class, B.class);
+
+ try
+ {
+ bundleB.start();
+ assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundleB.getState());
+
+ // BundleA is expected to resolve when BundleB gets started
+ assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundleA.getState());
+ assertLoadClass(bundleA, A.class, bundleA);
+ assertLoadClass(bundleA, B.class, bundleA);
+
+ // BundleB imports A from BundleA
+ assertLoadClass(bundleB, A.class, bundleA);
+
+ // BundleB does not import B
+ assertLoadClass(bundleB, B.class, bundleB);
+ }
+ finally
+ {
+ uninstall(bundleA);
+ }
+ }
+ finally
+ {
+ uninstall(bundleB);
+ }
+ }
+
+ public void testVersionImportPackage() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("versionimportpackageA", "/bundles/classloader/versionimportpackageA", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testVersionImportPackageFails() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("versionimportpackagefails", "/bundles/classloader/versionimportpackagefails", B.class);
+ try
+ {
+ bundle2.start();
+ fail("Should not be here!");
+ }
+ catch (BundleException ex)
+ {
+ // expected
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testOptionalImportPackage() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("optionalimportpackageA", "/bundles/classloader/optionalimportpackageA", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testOptionalImportPackageFails() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("optionalimportpackagefails", "/bundles/classloader/optionalimportpackagefails", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClassFail(bundle2, A.class);
+ assertLoadClass(bundle2, B.class);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testBundleNameImportPackage() throws Exception
+ {
+ //Bundle-Name: NotBundleA
+ //Bundle-Version: 1.0.0
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.notbundleA
+ //Export-Package: org.jboss.test.osgi.classloader.support.a
+ Bundle bundle0 = assembleBundle("notbundleA", "/bundles/classloader/notbundleA", A.class);
+
+ try
+ {
+ bundle0.start();
+ assertLoadClass(bundle0, A.class);
+ assertLoadClass(bundle0, A.class, bundle0);
+
+ //Bundle-Name: BundleA
+ //Bundle-Version: 1.0.0
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
+ //Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ assertLoadClass(bundle1, A.class, bundle1);
+
+ //Bundle-Name: BundleB
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+ //Import-Package: org.jboss.test.osgi.classloader.support.a;bundle-symbolic-name=org.jboss.test.osgi.classloader.bundleA
+ Bundle bundle2 = assembleBundle("bundlenameimportpackageA", "/bundles/classloader/bundlenameimportpackageA", B.class);
+
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+ finally
+ {
+ uninstall(bundle0);
+ }
+ }
+
+ public void testBundleNameImportPackageFails() throws Exception
+ {
+ Bundle bundle0 = assembleBundle("notbundleA", "/bundles/classloader/notbundleA", A.class);
+ try
+ {
+ bundle0.start();
+ assertLoadClass(bundle0, A.class);
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("bundlenameimportpackagefails", "/bundles/classloader/bundlenameimportpackagefails", B.class);
+ try
+ {
+ bundle2.start();
+ fail("Should not be here!");
+ }
+ catch (BundleException ex)
+ {
+ // expected
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+ finally
+ {
+ uninstall(bundle0);
+ }
+ }
+
+ public void testBundleVersionImportPackage() throws Exception
+ {
+ Bundle bundle0 = assembleBundle("bundleA2", "/bundles/classloader/bundleA2", A.class);
+ try
+ {
+ bundle0.start();
+ assertLoadClass(bundle0, A.class);
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("bundleversionimportpackageA", "/bundles/classloader/bundleversionimportpackageA", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+ finally
+ {
+ uninstall(bundle0);
+ }
+ }
+
+ public void testBundleVersionImportPackageFails() throws Exception
+ {
+ Bundle bundle0 = assembleBundle("bundleA2", "/bundles/classloader/bundleA2", A.class);
+ try
+ {
+ bundle0.start();
+ assertLoadClass(bundle0, A.class);
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("bundleversionimportpackagefails", "/bundles/classloader/bundleversionimportpackagefails", B.class);
+ try
+ {
+ bundle2.start();
+ fail("Should not be here!");
+ }
+ catch (BundleException ex)
+ {
+ // expected
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+ finally
+ {
+ uninstall(bundle0);
+ }
+ }
+
+ public void testAttributeImportPackage() throws Exception
+ {
+ Bundle bundle0 = assembleBundle("bundleA2", "/bundles/classloader/bundleA2", A.class);
+ try
+ {
+ bundle0.start();
+ assertLoadClass(bundle0, A.class);
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("attributeimportpackageA", "/bundles/classloader/attributeimportpackageA", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+ finally
+ {
+ uninstall(bundle0);
+ }
+ }
+
+ public void testAttributeImportPackageFails() throws Exception
+ {
+ Bundle bundle0 = assembleBundle("bundleA2", "/bundles/classloader/bundleA2", A.class);
+ try
+ {
+ bundle0.start();
+ assertLoadClass(bundle0, A.class);
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("attributeimportpackagefails", "/bundles/classloader/attributeimportpackagefails", B.class);
+ try
+ {
+ bundle2.start();
+ fail("Should not be here!");
+ }
+ catch (BundleException ex)
+ {
+ // expected
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+ finally
+ {
+ uninstall(bundle0);
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/test/RequireBundleUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,338 @@
+/*
+* 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 org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.classloader.support.a.A;
+import org.jboss.test.osgi.classloader.support.b.B;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * RequireBundleUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RequireBundleUnitTestCase extends OSGiTestCase
+{
+ public RequireBundleUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testSimpleRequireBundle() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("simplerequirebundleA", "/bundles/classloader/simplerequirebundleA", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testSimpleRequireBundleFails() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("simplerequirebundlefails", "/bundles/classloader/simplerequirebundlefails", B.class);
+ try
+ {
+ bundle2.start();
+ fail("Should not be here!");
+ }
+ catch (BundleException ex)
+ {
+ // expected
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testVersionRequireBundle() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("versionrequirebundleA", "/bundles/classloader/versionrequirebundleA", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testVersionRequireBundleFails() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("versionrequirebundlefails", "/bundles/classloader/versionrequirebundlefails", B.class);
+ try
+ {
+ bundle2.start();
+ fail("Should not be here!");
+ }
+ catch (RuntimeException rte)
+ {
+ // expected
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testOptionalRequireBundle() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("optionalrequirebundleA", "/bundles/classloader/optionalrequirebundleA", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testOptionalRequireBundleFails() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("optionalrequirebundlefails", "/bundles/classloader/optionalrequirebundlefails", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClassFail(bundle2, A.class);
+ assertLoadClass(bundle2, B.class);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testReExportRequireBundle() throws Exception
+ {
+ //Bundle-Name: BundleA
+ //Bundle-Version: 1.0.0
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
+ //Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+
+ //Bundle-Name: BundleB
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+ //Require-Bundle: org.jboss.test.osgi.classloader.bundleA;visibility:=reexport
+ //Export-Package: org.jboss.test.osgi.classloader.support.b
+ Bundle bundle2 = assembleBundle("reexportrequirebundleA", "/bundles/classloader/reexportrequirebundleA", B.class);
+
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+
+ //Bundle-Name: BundleC
+ //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleC
+ //Require-Bundle: org.jboss.test.osgi.classloader.bundleB
+ Bundle bundle3 = assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
+
+ try
+ {
+ assertLoadClass(bundle3, A.class, bundle1);
+ assertLoadClass(bundle3, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle3);
+ }
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testNoReExportRequireBundle() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("noreexportrequirebundleA", "/bundles/classloader/noreexportrequirebundleA", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ Bundle bundle3 = assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
+ try
+ {
+ assertLoadClassFail(bundle3, A.class);
+ assertLoadClass(bundle3, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle3);
+ }
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testAttributeRequireBundle() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("attributerequirebundleA", "/bundles/classloader/attributerequirebundleA", B.class);
+ try
+ {
+ bundle2.start();
+ assertLoadClass(bundle2, A.class, bundle1);
+ assertLoadClass(bundle2, B.class, bundle2);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testAttributeRequireBundleFails() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ try
+ {
+ bundle1.start();
+ assertLoadClass(bundle1, A.class);
+ Bundle bundle2 = assembleBundle("attributerequirebundlefails", "/bundles/classloader/attributerequirebundlefails", B.class);
+ try
+ {
+ bundle2.start();
+ fail("Should not be here!");
+ }
+ catch (RuntimeException rte)
+ {
+ // expected
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/GetServiceReferencesUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,569 @@
+/*
+* 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.service;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.a.A;
+import org.jboss.test.osgi.service.support.b.B;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetServiceReferencesUnitTestCase.
+ *
+ * todo test service permissions
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class GetServiceReferencesUnitTestCase extends OSGiTestCase
+{
+ public GetServiceReferencesUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetServiceReferences() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ assertNoGetReference(bundleContext1, A.class.getName());
+ assertNoReferences(bundleContext1, A.class.getName());
+ assertNoAllReferences(bundleContext1, A.class.getName());
+ assertNoGetReference(bundleContext1, B.class.getName());
+ assertNoReferences(bundleContext1, B.class.getName());
+ assertNoAllReferences(bundleContext1, B.class.getName());
+
+ Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ assertGetReference(bundleContext1, A.class.getName(), reference1);
+ assertReferences(bundleContext1, A.class.getName(), reference1);
+ assertAllReferences(bundleContext1, A.class.getName(), reference1);
+ assertNoGetReference(bundleContext1, B.class.getName());
+ assertNoReferences(bundleContext1, B.class.getName());
+ assertNoAllReferences(bundleContext1, B.class.getName());
+
+ registration1.unregister();
+
+ assertNoGetReference(bundleContext1, A.class.getName());
+ assertNoReferences(bundleContext1, A.class.getName());
+ assertNoAllReferences(bundleContext1, A.class.getName());
+ assertNoGetReference(bundleContext1, B.class.getName());
+ assertNoReferences(bundleContext1, B.class.getName());
+ assertNoAllReferences(bundleContext1, B.class.getName());
+
+ try
+ {
+ bundleContext1.getServiceReference(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext1.getServiceReferences(null, "invalid");
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(InvalidSyntaxException.class, t);
+ }
+
+ try
+ {
+ bundleContext1.getAllServiceReferences(null, "invalid");
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(InvalidSyntaxException.class, t);
+ }
+
+ bundle1.stop();
+
+ try
+ {
+ bundleContext1.getServiceReference(A.class.getName());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ bundleContext1.getServiceReferences(null, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ bundleContext1.getAllServiceReferences(null, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testGetServiceReferencesNoClassNotAssignable() throws Exception
+ {
+ assertGetServiceReferencesNotAssignable(null);
+ }
+
+ public void testGetServiceReferencesNotAssignable() throws Exception
+ {
+ assertGetServiceReferencesNotAssignable(A.class.getName());
+ }
+
+ public void assertGetServiceReferencesNotAssignable(String className) throws Exception
+ {
+ Bundle bundle1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+
+ Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ Bundle bundle2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+
+ clazz = bundle2.loadClass(A.class.getName());
+ Object service2 = clazz.newInstance();
+ ServiceRegistration registration2 = bundleContext2.registerService(A.class.getName(), service2, null);
+ assertNotNull(registration2);
+ ServiceReference reference2 = registration2.getReference();
+ assertNotNull(reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+
+ registration1.unregister();
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+
+ registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+
+ registration2.unregister();
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+
+ registration1.unregister();
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testGetServiceReferencesNoClassAssignable() throws Exception
+ {
+ assertGetServiceReferencesAssignable(null);
+ }
+
+ public void testGetServiceReferencesClassAssignable() throws Exception
+ {
+ assertGetServiceReferencesAssignable(A.class.getName());
+ }
+
+ public void assertGetServiceReferencesAssignable(String className) throws Exception
+ {
+ Bundle bundle1 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+
+ Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ Bundle bundle2 = assembleBundle("service1", "/bundles/service/service-bundle1");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference1);
+
+ clazz = bundle2.loadClass(A.class.getName());
+ Object service2 = clazz.newInstance();
+ ServiceRegistration registration2 = bundleContext2.registerService(A.class.getName(), service2, null);
+ assertNotNull(registration2);
+ ServiceReference reference2 = registration2.getReference();
+ assertNotNull(reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference1);
+
+ registration1.unregister();
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+
+ registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+
+ registration2.unregister();
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference1);
+
+ registration1.unregister();
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testGetServiceReferencesRankings() throws Exception
+ {
+ String className = A.class.getName();
+
+ Bundle bundle1 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ assertNoGetReference(bundleContext1, className);
+ assertNoReferences(bundleContext1, className);
+ assertNoAllReferences(bundleContext1, className);
+
+ Dictionary<String, Object> properties1 = new Hashtable<String, Object>();
+ properties1.put(Constants.SERVICE_RANKING, 1);
+ Class<?> clazz = bundle1.loadClass(className);
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(className, service1, properties1);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ Bundle bundle2 = assembleBundle("service1", "/bundles/service/service-bundle1");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ assertGetReference(bundleContext2, className, reference1);
+ assertReferences(bundleContext2, className, reference1);
+ assertAllReferences(bundleContext2, className, reference1);
+
+ Dictionary<String, Object> properties2 = new Hashtable<String, Object>();
+ properties2.put(Constants.SERVICE_RANKING, 2);
+ clazz = bundle2.loadClass(className);
+ Object service2 = clazz.newInstance();
+ ServiceRegistration registration2 = bundleContext2.registerService(className, service2, properties2);
+ assertNotNull(registration2);
+ ServiceReference reference2 = registration2.getReference();
+ assertNotNull(reference2);
+
+ assertGetReference(bundleContext1, className, reference2);
+ assertReferences(bundleContext1, className, reference2, reference1);
+ assertAllReferences(bundleContext1, className, reference2, reference1);
+
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2, reference1);
+ assertAllReferences(bundleContext2, className, reference2, reference1);
+
+ registration1.unregister();
+
+ assertGetReference(bundleContext1, className, reference2);
+ assertReferences(bundleContext1, className, reference2);
+ assertAllReferences(bundleContext1, className, reference2);
+
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2);
+ assertAllReferences(bundleContext2, className, reference2);
+
+ registration1 = bundleContext1.registerService(className, service1, properties1);
+ assertNotNull(registration1);
+ reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ assertGetReference(bundleContext1, className, reference2);
+ assertReferences(bundleContext1, className, reference2, reference1);
+ assertAllReferences(bundleContext1, className, reference2, reference1);
+
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2, reference1);
+ assertAllReferences(bundleContext2, className, reference2, reference1);
+
+ registration2.unregister();
+
+ assertGetReference(bundleContext1, className, reference1);
+ assertReferences(bundleContext1, className, reference1);
+ assertAllReferences(bundleContext1, className, reference1);
+
+ assertGetReference(bundleContext2, className, reference1);
+ assertReferences(bundleContext2, className, reference1);
+ assertAllReferences(bundleContext2, className, reference1);
+
+ registration1.unregister();
+
+ assertNoGetReference(bundleContext1, className);
+ assertNoReferences(bundleContext1, className);
+ assertNoAllReferences(bundleContext1, className);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+ assertNoReferences(bundleContext2, className);
+ assertNoAllReferences(bundleContext2, className);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testGetServiceReferencesFilterted() throws Exception
+ {
+ String className = A.class.getName();
+ String wrongClassName = B.class.getName();
+
+ Bundle bundle1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ assertNoGetReference(bundleContext1, A.class.getName());
+ assertNoReferences(bundleContext1, null, "(a=b)");
+ assertNoAllReferences(bundleContext1, null, "(a=b)");
+ assertNoReferences(bundleContext1, className, "(a=b)");
+ assertNoAllReferences(bundleContext1, className, "(a=b)");
+ assertNoReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoReferences(bundleContext1, null, "(c=d)");
+ assertNoAllReferences(bundleContext1, null, "(c=d)");
+ assertNoReferences(bundleContext1, className, "(c=d)");
+ assertNoAllReferences(bundleContext1, className, "(c=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoReferences(bundleContext1, null, "(c=x)");
+ assertNoAllReferences(bundleContext1, null, "(c=x)");
+ assertNoReferences(bundleContext1, className, "(c=x)");
+ assertNoAllReferences(bundleContext1, className, "(c=x)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoReferences(bundleContext1, null, "(x=d)");
+ assertNoAllReferences(bundleContext1, null, "(x=d)");
+ assertNoReferences(bundleContext1, className, "(x=d)");
+ assertNoAllReferences(bundleContext1, className, "(x=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(x=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(x=d)");
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("a", "b");
+ properties.put("c", "d");
+
+ Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, properties);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ assertGetReference(bundleContext1, A.class.getName(), reference1);
+ assertReferences(bundleContext1, null, "(a=b)", reference1);
+ assertAllReferences(bundleContext1, null, "(a=b)", reference1);
+ assertReferences(bundleContext1, className, "(a=b)", reference1);
+ assertAllReferences(bundleContext1, className, "(a=b)", reference1);
+ assertNoReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertReferences(bundleContext1, null, "(c=d)", reference1);
+ assertAllReferences(bundleContext1, null, "(c=d)", reference1);
+ assertReferences(bundleContext1, className, "(c=d)", reference1);
+ assertAllReferences(bundleContext1, className, "(c=d)", reference1);
+ assertNoReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoReferences(bundleContext1, null, "(c=x)");
+ assertNoAllReferences(bundleContext1, null, "(c=x)");
+ assertNoReferences(bundleContext1, className, "(c=x)");
+ assertNoAllReferences(bundleContext1, className, "(c=x)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoReferences(bundleContext1, null, "(x=d)");
+ assertNoAllReferences(bundleContext1, null, "(x=d)");
+ assertNoReferences(bundleContext1, className, "(x=d)");
+ assertNoAllReferences(bundleContext1, className, "(x=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(x=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(x=d)");
+
+ registration1.unregister();
+
+ assertNoGetReference(bundleContext1, A.class.getName());
+ assertNoReferences(bundleContext1, null, "(a=b)");
+ assertNoAllReferences(bundleContext1, null, "(a=b)");
+ assertNoReferences(bundleContext1, className, "(a=b)");
+ assertNoAllReferences(bundleContext1, className, "(a=b)");
+ assertNoReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoReferences(bundleContext1, null, "(c=d)");
+ assertNoAllReferences(bundleContext1, null, "(c=d)");
+ assertNoReferences(bundleContext1, className, "(c=d)");
+ assertNoAllReferences(bundleContext1, className, "(c=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoReferences(bundleContext1, null, "(c=x)");
+ assertNoAllReferences(bundleContext1, null, "(c=x)");
+ assertNoReferences(bundleContext1, className, "(c=x)");
+ assertNoAllReferences(bundleContext1, className, "(c=x)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoReferences(bundleContext1, null, "(x=d)");
+ assertNoAllReferences(bundleContext1, null, "(x=d)");
+ assertNoReferences(bundleContext1, className, "(x=d)");
+ assertNoAllReferences(bundleContext1, className, "(x=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(x=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(x=d)");
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,197 @@
+/*
+* 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.service;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.BrokenServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetUnGetServiceUnitTestCase.
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class GetUnGetServiceUnitTestCase extends OSGiTestCase
+{
+ static String OBJCLASS = BundleContext.class.getName();
+
+ public GetUnGetServiceUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetUnServiceErrors() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.registerService(OBJCLASS, bundleContext, null);
+
+ try
+ {
+ bundleContext.getService(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.ungetService(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetService() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ registration.unregister();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetServiceAfterStop() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ bundle.stop();
+ try
+ {
+ bundleContext.getService(reference);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testErrorInGetService() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.addFrameworkListener(this);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), new BrokenServiceFactory(bundleContext, true), null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, RuntimeException.class);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testErrorInUnGetService() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.addFrameworkListener(this);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), new BrokenServiceFactory(bundleContext, false), null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+ assertNoFrameworkEvent();
+
+ registration.unregister();
+
+ assertFrameworkEvent(FrameworkEvent.WARNING, bundle, RuntimeException.class);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,240 @@
+/*
+* 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.service;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * RegisterServiceUnitTestCase.
+ *
+ * todo test secutiry
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RegisterServiceUnitTestCase extends OSGiTestCase
+{
+ static String OBJCLASS = BundleContext.class.getName();
+ static String[] OBJCLASSES = new String[] { OBJCLASS };
+
+ public RegisterServiceUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testRegisterServiceErrors() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+ String[] OBJCLASSES = new String[] { OBJCLASS };
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ try
+ {
+ bundleContext.registerService((String) null, new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService((String[]) null, new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(new String[0], new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASS, null, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASSES, null, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASS, new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASSES, new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("case", "a");
+ properties.put("CASE", "a");
+ try
+ {
+ bundleContext.registerService(OBJCLASS, bundleContext, properties);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASSES, bundleContext, properties);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ bundle.stop();
+
+ try
+ {
+ bundleContext.registerService(OBJCLASS, bundleContext, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASSES, bundleContext, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testRegisterServiceOBJCLASS() throws Exception
+ {
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(Constants.OBJECTCLASS, new String[] { "rubbish" });
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+ ServiceReference reference = registration.getReference();
+ assertObjectClass(OBJCLASS, reference);
+ registration.setProperties(properties);
+ assertObjectClass(OBJCLASS, reference);
+ registration.unregister();
+
+ registration = bundleContext.registerService(OBJCLASSES, bundleContext, null);
+ reference = registration.getReference();
+ assertObjectClass(OBJCLASSES, reference);
+ registration.setProperties(properties);
+ assertObjectClass(OBJCLASSES, reference);
+ registration.unregister();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testRegisterService() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ registration = bundleContext.registerService(OBJCLASSES, bundleContext, null);
+ reference = registration.getReference();
+ actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,198 @@
+/*
+* 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.service;
+
+import org.jboss.osgi.framework.bundle.OSGiBundleWrapper;
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetUnGetServiceUnitTestCase.
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler(a)jboss.com
+ * @version $Revision$
+ */
+public class ServiceFactoryUnitTestCase extends OSGiTestCase
+{
+ static String OBJCLASS = BundleContext.class.getName();
+ static String[] OBJCLASSES = new String[] { OBJCLASS };
+
+ public ServiceFactoryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testRegisterServiceFactory() throws Exception
+ {
+ Bundle bundleA = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundleA.start();
+ BundleContext contextA = bundleA.getBundleContext();
+ assertNotNull(contextA);
+
+ SimpleServiceFactory serviceFactory = new SimpleServiceFactory(contextA);
+ ServiceRegistration sregA = contextA.registerService(OBJCLASS, serviceFactory, null);
+
+ ServiceReference srefA = sregA.getReference();
+ Object actual = contextA.getService(srefA);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+ assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ assertEquals(1, serviceFactory.getCount);
+
+ srefA = contextA.getServiceReference(OBJCLASS);
+ actual = contextA.getService(srefA);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+ assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ assertEquals(1, serviceFactory.getCount);
+
+ Bundle bundleB = addBundle("/bundles/simple/", "simple-bundle2");
+ try
+ {
+ bundleB.start();
+ BundleContext contextB = bundleB.getBundleContext();
+ assertNotNull(contextB);
+
+ ServiceReference srefB = contextB.getServiceReference(OBJCLASS);
+ actual = contextB.getService(srefB);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+
+ assertEquals(bundleB.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ assertEquals(2, serviceFactory.getCount);
+ }
+ finally
+ {
+ uninstall(bundleB);
+ }
+ }
+ finally
+ {
+ uninstall(bundleA);
+ }
+ }
+
+ public void testGetServiceFactory() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ registration.unregister();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetServiceFactoryAfterStop() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ bundle.stop();
+ try
+ {
+ bundleContext.getService(reference);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetWrongInterfacesForServiceFactory() throws Exception
+ {
+ String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.addFrameworkListener(this);
+
+ ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+
+ registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
+ reference = registration.getReference();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/ServiceReferenceUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,605 @@
+/*
+* 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.service;
+
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.a.A;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * ServiceReferenceUnitTestCase.
+ *
+ * todo more isAssignableTests
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceReferenceUnitTestCase extends OSGiTestCase
+{
+ public ServiceReferenceUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetProperty() throws Exception
+ {
+ ServiceReference reference = null;
+ String[] clazzes = new String[] { BundleContext.class.getName() };
+ Object serviceID = null;
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("testA", "a");
+ properties.put("testB", "b");
+ properties.put("MiXeD", "Case");
+ ServiceRegistration registration = bundleContext.registerService(clazzes, bundleContext, properties);
+ assertNotNull(registration);
+
+ reference = registration.getReference();
+ assertNotNull(reference);
+
+ serviceID = reference.getProperty(Constants.SERVICE_ID);
+ assertNotNull(serviceID);
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toLowerCase()));
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toUpperCase()));
+ assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toLowerCase()));
+ assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toUpperCase()));
+ assertEquals("a", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+ assertNull(reference.getProperty("doesNotExist"));
+
+ properties.put("testA", "notA");
+ assertEquals("a", reference.getProperty("testA"));
+ properties.put(Constants.SERVICE_ID, "rubbish");
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ properties.put(Constants.OBJECTCLASS, "rubbish");
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+
+ registration.setProperties(properties);
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals("notA", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+
+ registration.setProperties(null);
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertNull(reference.getProperty("testA"));
+ assertNull(reference.getProperty("testB"));
+ assertNull(reference.getProperty("MiXeD"));
+ assertNull(reference.getProperty("mixed"));
+ assertNull(reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+
+ registration.setProperties(properties);
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals("notA", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+
+ registration.unregister();
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals("notA", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals("notA", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+ }
+
+ public void testGetPropertyKeys() throws Exception
+ {
+ ServiceReference reference = null;
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("testA", "a");
+ properties.put("testB", "b");
+ properties.put("MiXeD", "Case");
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration);
+
+ reference = registration.getReference();
+ assertNotNull(reference);
+
+ assertPropertyKeys(reference, "testA", "testB", "MiXeD");
+
+ properties.put("testC", "c");
+ assertPropertyKeys(reference, "testA", "testB", "MiXeD");
+
+ registration.setProperties(properties);
+ assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+
+ registration.setProperties(null);
+ assertPropertyKeys(reference);
+
+ registration.setProperties(properties);
+ assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+
+ registration.unregister();
+ assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+ }
+
+ protected void assertPropertyKeys(ServiceReference reference, String... expectedKeys)
+ {
+ Set<String> expected = new HashSet<String>();
+ expected.add(Constants.SERVICE_ID);
+ expected.add(Constants.OBJECTCLASS);
+ for (String key : expectedKeys)
+ expected.add(key);
+
+ Set<String> actual = new HashSet<String>();
+ for (String key : reference.getPropertyKeys())
+ actual.add(key);
+
+ assertEquals(expected, actual);
+ }
+
+ public void testGetBundle() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ Bundle other = reference.getBundle();
+ assertEquals(bundle, other);
+
+ registration.unregister();
+
+ other = reference.getBundle();
+ assertNull("" + other, other);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetBundleAfterStop() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ Bundle other = reference.getBundle();
+ assertEquals(bundle, other);
+
+ bundle.stop();
+
+ other = reference.getBundle();
+ assertNull("" + other, other);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testUsingBundles() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ assertUsingBundles(reference);
+
+ Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ bundleContext2.getService(reference);
+ assertUsingBundles(reference, bundle2);
+
+ bundleContext2.ungetService(reference);
+ assertUsingBundles(reference);
+
+ bundleContext2.getService(reference);
+ bundleContext2.getService(reference);
+ assertUsingBundles(reference, bundle2);
+ bundleContext2.ungetService(reference);
+ assertUsingBundles(reference, bundle2);
+ bundleContext2.ungetService(reference);
+ assertUsingBundles(reference);
+
+ bundleContext.getService(reference);
+ bundleContext2.getService(reference);
+ assertUsingBundles(reference, bundle, bundle2);
+
+ registration.unregister();
+ assertUsingBundles(reference);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testUsingBundlesAfterStop() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ assertUsingBundles(reference);
+
+ Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ bundleContext.getService(reference);
+ bundleContext2.getService(reference);
+ assertUsingBundles(reference, bundle, bundle2);
+
+ bundle.stop();
+ assertUsingBundles(reference);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testIsAssignableToErrors() throws Exception
+ {
+ Bundle bundle = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ try
+ {
+ reference.isAssignableTo(null, A.class.getName());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ reference.isAssignableTo(bundle, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testNotAssignableTo() throws Exception
+ {
+ Bundle bundle = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ Bundle bundle2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+ try
+ {
+ assertFalse(reference.isAssignableTo(bundle2, A.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle2, String.class.getName()));
+
+ registration.unregister();
+ assertFalse(reference.isAssignableTo(bundle2, A.class.getName()));
+ assertFalse(reference.isAssignableTo(bundle2, String.class.getName())); // review ???
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testIsAssignableTo() throws Exception
+ {
+ //Bundle-Name: Service2
+ //Bundle-SymbolicName: org.jboss.test.osgi.service2
+ //Export-Package: org.jboss.test.osgi.service.support.a
+ Bundle bundle2 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ //Bundle-Name: Service1
+ //Bundle-SymbolicName: org.jboss.test.osgi.service1
+ //Import-Package: org.jboss.test.osgi.service.support.a
+ Bundle bundle1 = assembleBundle("service1", "/bundles/service/service-bundle1");
+
+ try
+ {
+
+ ServiceRegistration registration = bundleContext2.registerService(BundleContext.class.getName(), bundleContext2, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ assertTrue(reference.isAssignableTo(bundle2, A.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle2, String.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle1, A.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle1, String.class.getName()));
+
+ registration.unregister();
+ assertTrue(reference.isAssignableTo(bundle2, A.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle2, String.class.getName()));
+ assertFalse(reference.isAssignableTo(bundle1, A.class.getName()));
+ assertFalse(reference.isAssignableTo(bundle1, String.class.getName())); // review ???
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+
+ public void testCompareTo() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration1 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration1);
+
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ ServiceRegistration registration2 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration2);
+
+ ServiceReference reference2 = registration2.getReference();
+ assertNotNull(reference2);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(Constants.SERVICE_RANKING, 10);
+ ServiceRegistration registration3 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration3);
+
+ ServiceReference reference3 = registration3.getReference();
+ assertNotNull(reference3);
+
+ properties = new Hashtable<String, Object>();
+ properties.put(Constants.SERVICE_RANKING, -10);
+ ServiceRegistration registration4 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration4);
+
+ ServiceReference reference4 = registration4.getReference();
+ assertNotNull(reference4);
+
+ assertGreaterRanking(reference1, reference2);
+ assertGreaterRanking(reference3, reference1);
+ assertGreaterRanking(reference3, reference2);
+ assertGreaterRanking(reference1, reference4);
+ assertGreaterRanking(reference2, reference4);
+ assertGreaterRanking(reference3, reference4);
+
+ try
+ {
+ reference1.compareTo(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ reference1.compareTo(new Object());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ properties = new Hashtable<String, Object>();
+ properties.put(Constants.SERVICE_RANKING, "NotANumber");
+ ServiceRegistration registration5 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration5);
+
+ ServiceReference reference5 = registration5.getReference();
+ assertNotNull(reference5);
+
+ assertGreaterRanking(reference1, reference5); // review ???
+
+ Set<ServiceReference> ordering = new TreeSet<ServiceReference>();
+ ordering.add(reference1);
+ ordering.add(reference2);
+ ordering.add(reference3);
+ ordering.add(reference4);
+ ordering.add(reference5);
+ Iterator<ServiceReference> iterator = ordering.iterator();
+ assertEquals(reference4, iterator.next());
+ assertEquals(reference5, iterator.next());
+ assertEquals(reference2, iterator.next());
+ assertEquals(reference1, iterator.next());
+ assertEquals(reference3, iterator.next());
+
+ ordering = new TreeSet<ServiceReference>();
+ ordering.add(reference5);
+ ordering.add(reference4);
+ ordering.add(reference3);
+ ordering.add(reference2);
+ ordering.add(reference1);
+ iterator = ordering.iterator();
+ assertEquals(reference4, iterator.next());
+ assertEquals(reference5, iterator.next());
+ assertEquals(reference2, iterator.next());
+ assertEquals(reference1, iterator.next());
+ assertEquals(reference3, iterator.next());
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ protected void assertGreaterRanking(ServiceReference reference1, ServiceReference reference2) throws Exception
+ {
+ assertTrue(reference1 + " > " + reference2, reference1.compareTo(reference2) > 0);
+ assertTrue(reference2 + " < " + reference1, reference2.compareTo(reference1) < 0);
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,355 @@
+/*
+* 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.service;
+
+import java.util.Hashtable;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * ServiceRegistrationUnitTestCase.
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceRegistrationUnitTestCase extends OSGiTestCase
+{
+ public ServiceRegistrationUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetReference() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ ServiceReference reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+ assertEquals(reference, reference2);
+
+ Object object = bundleContext.getService(reference);
+ assertEquals(bundleContext, object);
+
+ reference2 = registration.getReference();
+ assertEquals(reference, reference2);
+
+ registration.unregister();
+ try
+ {
+ registration.getReference();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ ServiceRegistration registration2 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+ assertNotSame(registration, registration2);
+
+ reference2 = registration2.getReference();
+ assertNotNull(reference2);
+ assertNotSame(reference, reference2);
+
+ bundle.stop();
+ try
+ {
+ registration2.getReference();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testSetProperties() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ String propertyA = "org.jboss.osgi.test.PropertyA";
+ String propertyALower = "org.jboss.osgi.test.propertya";
+
+ Hashtable<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(propertyA, "testA");
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration);
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+ assertEquals("testA", reference.getProperty(propertyA));
+ assertEquals("testA", reference.getProperty(propertyALower));
+
+ Object serviceID = reference.getProperty(Constants.SERVICE_ID);
+ Object objectClass = reference.getProperty(Constants.OBJECTCLASS);
+
+ assertAllReferences(bundleContext, null, "(" + propertyA + "=testA)", reference);
+ assertAllReferences(bundleContext, null, "(" + propertyALower + "=testA)", reference);
+ assertAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=" + serviceID + ")", reference);
+
+ bundleContext.addServiceListener(this);
+
+ properties = new Hashtable<String, Object>();
+ properties.put(propertyA, "testAChanged");
+ registration.setProperties(properties);
+ assertServiceEvent(ServiceEvent.MODIFIED, reference);
+ assertEquals("testAChanged", reference.getProperty(propertyA));
+ assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testA)");
+ assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testA)");
+ assertAllReferences(bundleContext, null, "(" + propertyA + "=testAChanged)", reference);
+ assertAllReferences(bundleContext, null, "(" + propertyALower + "=testAChanged)", reference);
+
+ registration.setProperties(null);
+ assertServiceEvent(ServiceEvent.MODIFIED, reference);
+ assertNull(reference.getProperty(propertyA));
+ assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testA)");
+ assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testA)");
+ assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testAChanged)");
+ assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testAChanged)");
+
+ properties = new Hashtable<String, Object>();
+ properties.put(propertyA, "testA2");
+ properties.put(Constants.SERVICE_ID, "rubbish1");
+ properties.put(Constants.OBJECTCLASS, "rubbish2");
+ registration.setProperties(properties);
+ assertServiceEvent(ServiceEvent.MODIFIED, reference);
+ assertEquals("testA2", reference.getProperty(propertyA));
+ assertEquals("testA2", reference.getProperty(propertyALower));
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toLowerCase()));
+ assertEquals(objectClass, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals(objectClass, reference.getProperty(Constants.OBJECTCLASS.toLowerCase()));
+
+ try
+ {
+ assertNoAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=rubbish1)");
+ fail("NumberFormatException expected");
+ }
+ catch (NumberFormatException ex)
+ {
+ // expected
+ }
+
+ assertAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=" + serviceID + ")", reference);
+
+ properties = new Hashtable<String, Object>();
+ properties.put("a", "1");
+ properties.put("A", "2");
+ try
+ {
+ registration.setProperties(properties);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ assertNoServiceEvent();
+
+ registration.unregister();
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+
+ try
+ {
+ registration.setProperties(new Hashtable<String, Object>());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ assertNoServiceEvent();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testSetPropertiesAfterStop() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ bundle.stop();
+
+ try
+ {
+ registration.setProperties(new Hashtable<String, Object>());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ assertNoServiceEvent();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testUnregister() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ SimpleServiceFactory factory = new SimpleServiceFactory(bundleContext);
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), factory, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ ServiceReference reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+ assertEquals(reference, reference2);
+
+ ServiceReference[] inUse = bundle.getServicesInUse();
+ assertNull(inUse);
+
+ bundleContext.getService(reference);
+ inUse = bundle.getServicesInUse();
+ assertEquals(new ServiceReference[] { reference }, inUse);
+
+ Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+ bundleContext2.getService(reference);
+ inUse = bundle2.getServicesInUse();
+ assertEquals(new ServiceReference[] { reference }, inUse);
+
+ assertNull(factory.ungetBundle);
+ assertNull(factory.ungetRegisation);
+ assertNull(factory.ungetService);
+
+ bundleContext.addServiceListener(this);
+ registration.unregister();
+
+ reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+ assertNull("" + reference2, reference2);
+
+ Object actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+
+ inUse = bundle.getServicesInUse();
+ assertNull(inUse);
+ inUse = bundle2.getServicesInUse();
+ assertNull(inUse);
+
+ assertEquals(registration, factory.ungetRegisation);
+ assertEquals(bundleContext, factory.ungetService);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+
+ try
+ {
+ registration.unregister();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testUnregisterAfterStop() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ bundle.stop();
+
+ try
+ {
+ registration.unregister();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/test/OSGiSmokeTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java 2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,112 @@
+/*
+* 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.smoke;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.smoke.support.a.A;
+import org.jboss.test.osgi.smoke.support.a.b.B;
+import org.jboss.test.osgi.smoke.support.c.C;
+import org.osgi.framework.Bundle;
+
+/**
+ * OSGiSmokeTestCase.
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiSmokeTestCase extends OSGiTestCase
+{
+ public OSGiSmokeTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testNoManifest() throws Exception
+ {
+ // [TODO] discuss no manifest
+ //testBundle("smoke-no-manifest", Bundle.ACTIVE);
+ }
+
+ public void testNonOSGiManifest() throws Exception
+ {
+ // [TODO] discuss no osgi manifest
+ //testBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
+ }
+
+ public void testOSGiManifest() throws Exception
+ {
+ testBundle("smoke-osgi-manifest", Bundle.INSTALLED);
+ }
+
+ public void testAssembled() throws Exception
+ {
+ Bundle bundle = assembleBundle("smoke-assembled", "/bundles/smoke/smoke-assembled", A.class);
+ try
+ {
+ testBundle(bundle, "smoke-assembled", Bundle.INSTALLED);
+ bundle.start();
+ assertLoadClass(bundle, A.class);
+ assertLoadClassFail(bundle, B.class);
+ assertLoadClassFail(bundle, C.class);
+ }
+ finally
+ {
+ bundle.uninstall();
+ }
+ }
+
+ protected void testBundle(String name, int expectedState) throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/smoke/", name);
+ try
+ {
+ testBundle(bundle, name, expectedState);
+ }
+ finally
+ {
+ bundle.uninstall();
+ }
+ }
+
+ protected void testBundle(Bundle bundle, String name, int expectedState) throws Exception
+ {
+ assertEquals(expectedState, bundle.getState());
+ checkId(bundle, name);
+ bundle.start();
+ bundle.stop();
+ }
+
+ protected void checkId(Bundle bundle, String name) throws Exception
+ {
+ URL url = bundle.getEntry("id");
+ if (url == null)
+ fail("id entry not found for " + bundle);
+ InputStream is = url.openStream();
+ byte[] bytes = new byte[100];
+ is.read(bytes);
+ String value = new String(bytes);
+ assertTrue("Expected=" + name + " was " + value, value.startsWith(name));
+ }
+}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle (from rev 96123, projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/bundle)
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/metadata/SimpleManifest.mf
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/bundle/metadata/SimpleManifest.mf 2009-11-07 19:16:20 UTC (rev 96123)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/metadata/SimpleManifest.mf 2009-11-09 14:12:05 UTC (rev 96174)
@@ -4,7 +4,7 @@
Implementation-Title: JBoss OSGi tests
Implementation-Version: 2.0.0.beta2
Implementation-Vendor: jboss.org
-Bundle-Activator: org.jboss.test.bundle.metadata.BundleActivator
+Bundle-Activator: org.jboss.test.osgi.bundle.metadata.BundleActivator
Bundle-ClassPath: test.jar,mc.jar,seam.jar
Bundle-Description: TestHeadersManifest
Bundle-Localization: OSGI-INF/l10n/bundle
14 years, 6 months
JBoss-OSGI SVN: r96171 - in projects/jboss-osgi/trunk: reactor/framework and 16 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-09 08:52:41 -0500 (Mon, 09 Nov 2009)
New Revision: 96171
Added:
projects/jboss-osgi/trunk/distribution/docbook/src/main/graphics/jbossosgi-enterprise.odp
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/NamedPackageImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleCapability.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleRequirement.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/NoFilter.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ImportDirectiveResolutionTest.java
Removed:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/FilterImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/NoFilter.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/model/
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/parser/
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/property/
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleCapability.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleRequirement.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleResolver.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/ds/
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/FrameworkUtil.java
projects/jboss-osgi/trunk/reactor/framework/src/main/resources/schema/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloading/bundleclasspath/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/filter/test/
Modified:
projects/jboss-osgi/trunk/reactor/framework/pom.xml
projects/jboss-osgi/trunk/reactor/framework/scripts/assembly-bundles.xml
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/launch/OSGiFramework.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTest.java
Log:
Remove stale Version impl.
Remove stale DS impl.
Expand bundle resolver API
Added: projects/jboss-osgi/trunk/distribution/docbook/src/main/graphics/jbossosgi-enterprise.odp
===================================================================
(Binary files differ)
Property changes on: projects/jboss-osgi/trunk/distribution/docbook/src/main/graphics/jbossosgi-enterprise.odp
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: projects/jboss-osgi/trunk/reactor/framework/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/pom.xml 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/pom.xml 2009-11-09 13:52:41 UTC (rev 96171)
@@ -259,6 +259,11 @@
<artifactId>jboss-osgi-xml-binding</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.web</groupId>
+ <artifactId>pax-web-jetty-bundle</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified: projects/jboss-osgi/trunk/reactor/framework/scripts/assembly-bundles.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/scripts/assembly-bundles.xml 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/scripts/assembly-bundles.xml 2009-11-09 13:52:41 UTC (rev 96171)
@@ -37,6 +37,7 @@
<include>*:org.apache.felix.configadmin:jar</include>
<include>*:org.apache.felix.log:jar</include>
<include>*:org.apache.felix.metatype:jar</include>
+ <include>*:pax-web-jetty-bundle:jar</include>
</includes>
<useStrictFiltering>true</useStrictFiltering>
<scope>test</scope>
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -63,7 +63,6 @@
import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
import org.jboss.kernel.Kernel;
import org.jboss.logging.Logger;
-import org.jboss.osgi.framework.filter.NoFilter;
import org.jboss.osgi.framework.metadata.OSGiMetaData;
import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
import org.jboss.osgi.framework.plugins.AutoInstallPlugin;
@@ -72,7 +71,9 @@
import org.jboss.osgi.framework.plugins.PackageAdminServicePlugin;
import org.jboss.osgi.framework.plugins.Plugin;
import org.jboss.osgi.framework.plugins.ServicePlugin;
-import org.jboss.osgi.framework.resolver.BundleResolver;
+import org.jboss.osgi.framework.resolver.Resolver;
+import org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl;
+import org.jboss.osgi.framework.util.NoFilter;
import org.jboss.util.collection.ConcurrentSet;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VFSUtils;
@@ -126,8 +127,8 @@
/** The os version */
private static String OSGi_FRAMEWORK_PROCESSOR;
- /** The bundles resolver */
- private BundleResolver bundleResolver;
+ /** The bundle resolver */
+ private Resolver bundleResolver;
/** The bundles by id */
private List<AbstractBundleState> bundles = new CopyOnWriteArrayList<AbstractBundleState>();
@@ -204,7 +205,7 @@
this.kernel = kernel;
this.deployerClient = deployerClient;
this.deployerStructure = (MainDeployerStructure)deployerClient;
- this.bundleResolver = new BundleResolver(this);
+ this.bundleResolver = new BasicResolverImpl();
// TODO thread factory
if (executor == null)
@@ -360,7 +361,7 @@
*
* @return the resolver
*/
- public BundleResolver getBundleResolver()
+ public Resolver getBundleResolver()
{
return bundleResolver;
}
@@ -640,6 +641,7 @@
}
bundleState.setBundleManager(this);
+ bundleResolver.addBundle(bundleState);
bundles.add(bundleState);
bundleState.changeState(Bundle.INSTALLED);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -389,4 +389,18 @@
if (rethrow != null)
throw rethrow;
}
+
+ public static OSGiBundleState assertBundleState(Bundle bundle)
+ {
+ if (bundle == null)
+ throw new IllegalArgumentException("Null bundle");
+
+ if (bundle instanceof OSGiBundleWrapper)
+ bundle = ((OSGiBundleWrapper)bundle).getBundleState();
+
+ if (bundle instanceof OSGiBundleState == false)
+ throw new IllegalArgumentException("Not an OSGiBundleState: " + bundle);
+
+ return (OSGiBundleState)bundle;
+ }
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -30,6 +30,7 @@
import org.jboss.classloading.spi.metadata.Requirement;
import org.jboss.classloading.spi.version.VersionRange;
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.bundle.OSGiBundleState;
import org.jboss.osgi.framework.metadata.OSGiMetaData;
@@ -37,8 +38,11 @@
import org.jboss.osgi.framework.metadata.Parameter;
import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
import org.jboss.osgi.framework.metadata.internal.AbstractVersionRange;
-import org.jboss.osgi.framework.resolver.BundleCapability;
-import org.jboss.osgi.framework.resolver.BundleResolver;
+import org.jboss.osgi.framework.resolver.ExportPackage;
+import org.jboss.osgi.framework.resolver.Resolver;
+import org.jboss.osgi.framework.resolver.Resolvable;
+import org.jboss.osgi.framework.resolver.internal.basic.BundleCapability;
+import org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
@@ -138,20 +142,32 @@
if (requirement instanceof OSGiPackageRequirement == false)
return true;
+ PackageRequirement packageRequirement = (PackageRequirement)requirement;
+
// Get the bundle resolver from the bundle manager
OSGiBundleManager bundleManager = bundleState.getBundleManager();
- BundleResolver bundleResolver = bundleManager.getBundleResolver();
+ Resolver bundleResolver = bundleManager.getBundleResolver();
- // True if capModule matches with the resolved module
- PackageRequirement packageRequirement = (PackageRequirement)requirement;
- BundleCapability bundleCapability = bundleResolver.getMatchingCapability(reqModule, packageRequirement);
- if (bundleCapability == null)
+ String location = reqModule.getContextName();
+ AbstractBundleState bundle = bundleManager.getBundleByLocation(location);
+ if (bundle == null)
+ {
+ // Is this an illegal state?
return false;
+ }
- Module capModule = getModule();
- Module otherCapModule = bundleCapability.getExportingModule();
- PackageCapability otherCapability = bundleCapability.getPackageCapability();
- boolean isMatch = (otherCapModule == capModule && otherCapability == this);
+ // Get the exporter for this requirement
+ ExportPackage exporter = bundleResolver.getExporter(bundle, packageRequirement.getName());
+ if (exporter == null)
+ return false;
+
+ // Get the exporters module
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(exporter.getOwner().getBundle());
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ Module otherCapModule = unit.getAttachment(Module.class);
+
+ String otherCapability = exporter.getName();
+ boolean isMatch = (otherCapModule == getModule() && otherCapability.equals(getName()));
return isMatch;
}
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/FilterImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/FilterImpl.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/FilterImpl.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -1,108 +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.filter;
-
-import java.util.Dictionary;
-
-import org.jboss.osgi.framework.filter.model.Operation;
-import org.jboss.osgi.framework.filter.parser.FilterParser;
-import org.jboss.osgi.framework.filter.property.PropertySource;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
-/**
- * FilterImpl.
- *
- * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class FilterImpl implements Filter
-{
- /** The operation */
- private Operation operation;
-
- /** The cached string */
- private String cachedString;
-
- /**
- * Create a new FilterImpl.
- *
- * @param filter the filter
- * @throws InvalidSyntaxException if the filter syntax is invalid
- */
- public FilterImpl(String filter) throws InvalidSyntaxException
- {
- if (filter == null)
- throw new InvalidSyntaxException("Null filter", "?");
-
- FilterParser parser = new FilterParser();
- this.operation = parser.parse(filter);
- }
-
- @SuppressWarnings("unchecked")
- public boolean match(Dictionary dictionary)
- {
- return operation.match(PropertySource.fromDictionary(dictionary, false));
- }
-
- public boolean match(ServiceReference reference)
- {
- return operation.match(PropertySource.fromServiceReference(reference));
- }
-
- @SuppressWarnings("unchecked")
- public boolean matchCase(Dictionary dictionary)
- {
- return operation.match(PropertySource.fromDictionary(dictionary, true));
- }
-
- @Override
- public String toString()
- {
- if (cachedString == null)
- {
- StringBuilder builder = new StringBuilder();
- builder.append('(');
- operation.toString(builder);
- builder.append(')');
- cachedString = builder.toString();
- }
- return cachedString;
- }
-
- @Override
- public int hashCode()
- {
- return toString().hashCode();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- return true;
- if (obj == null || obj instanceof Filter == false)
- return false;
- return toString().equals(obj.toString());
- }
-}
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/NoFilter.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/NoFilter.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/NoFilter.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -1,63 +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.filter;
-
-import java.util.Dictionary;
-
-import org.osgi.framework.Filter;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Dummy filter implementation
- *
- * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class NoFilter implements Filter
-{
- /** Singleton instance */
- public static final Filter INSTANCE = new NoFilter();
-
- /**
- * Singleton
- */
- private NoFilter()
- {
- }
-
- @SuppressWarnings("unchecked")
- public boolean match(Dictionary dictionary)
- {
- return true;
- }
-
- public boolean match(ServiceReference reference)
- {
- return true;
- }
-
- @SuppressWarnings("unchecked")
- public boolean matchCase(Dictionary dictionary)
- {
- return true;
- }
-}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/launch/OSGiFramework.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/launch/OSGiFramework.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/launch/OSGiFramework.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -52,6 +52,11 @@
this.bundleManager = bundleManager;
}
+ public OSGiBundleManager getBundleManager()
+ {
+ return bundleManager;
+ }
+
public void init() throws BundleException
{
bundleManager.initFramework();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -40,8 +40,8 @@
import org.jboss.osgi.framework.bundle.AbstractBundleState;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.bundle.OSGiServiceState;
-import org.jboss.osgi.framework.filter.NoFilter;
import org.jboss.osgi.framework.plugins.FrameworkEventsPlugin;
+import org.jboss.osgi.framework.util.NoFilter;
import org.jboss.osgi.spi.util.ConstantsHelper;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleCapability.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleCapability.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleCapability.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -1,126 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.resolver;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.jboss.classloading.plugins.metadata.PackageCapability;
-import org.jboss.classloading.spi.dependency.Module;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.osgi.framework.classloading.OSGiPackageCapability;
-import org.jboss.osgi.framework.classloading.OSGiPackageRequirement;
-
-/**
- * An association of bundle/capability.
- *
- * @author thomas.diesler(a)jboss.com
- * @since 10-Sep-2009
- */
-public class BundleCapability
-{
- private OSGiBundleState bundle;
- private PackageCapability packageCapability;
- private List<BundleRequirement> wires;
-
- BundleCapability(OSGiBundleState bundle, PackageCapability packageCapability)
- {
- if (bundle == null)
- throw new IllegalArgumentException("Null bundle");
- if (packageCapability == null)
- throw new IllegalArgumentException("Null packageCapability");
-
- this.bundle = bundle;
- this.packageCapability = packageCapability;
- }
-
- public OSGiBundleState getExportingBundle()
- {
- return bundle;
- }
-
- public Module getExportingModule()
- {
- OSGiBundleState bundleState = BundleResolver.assertBundleState(bundle);
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- return unit.getAttachment(Module.class);
- }
-
- public PackageCapability getPackageCapability()
- {
- return packageCapability;
- }
-
- public List<BundleRequirement> getWiredRequirements()
- {
- if (wires == null)
- return Collections.emptyList();
-
- return Collections.unmodifiableList(wires);
- }
-
- boolean matches(BundleRequirement bundleRequirement)
- {
- OSGiPackageCapability osgiPackageCapability = (OSGiPackageCapability)packageCapability;
- OSGiPackageRequirement osgiPackageRequirement = (OSGiPackageRequirement)bundleRequirement.getPackageRequirement();
- return osgiPackageCapability.match(osgiPackageRequirement);
- }
-
- void wireRequirement(BundleRequirement bundleRequirement)
- {
- if (wires == null)
- wires = new CopyOnWriteArrayList<BundleRequirement>();
-
- wires.add(bundleRequirement);
- }
-
- void unwireRequirement(BundleRequirement bundleRequirement)
- {
- if (wires != null)
- wires.remove(bundleRequirement);
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj instanceof BundleCapability == false)
- return false;
- if (obj == this)
- return true;
- return toString().equals(obj.toString());
- }
-
- @Override
- public int hashCode()
- {
- return toString().hashCode();
- }
-
- @Override
- public String toString()
- {
- String name = packageCapability.getName();
- return "BundleCapability[" + name + "," + bundle + "]";
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleRequirement.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleRequirement.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleRequirement.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.resolver;
-
-import org.jboss.classloading.plugins.metadata.PackageRequirement;
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-
-/**
- * An association of bundle/requirement.
- *
- * @author thomas.diesler(a)jboss.com
- * @since 10-Sep-2009
- */
-public class BundleRequirement
-{
- private OSGiBundleState bundle;
- private PackageRequirement packageRequirement;
- private BundleCapability wire;
-
- BundleRequirement(OSGiBundleState bundle, PackageRequirement packageRequirement)
- {
- if (bundle == null)
- throw new IllegalArgumentException("Null bundle");
- if (packageRequirement == null)
- throw new IllegalArgumentException("Null packageRequirement");
-
- this.bundle = bundle;
- this.packageRequirement = packageRequirement;
- }
-
- public BundleCapability getWiredCapability()
- {
- return wire;
- }
-
- public OSGiBundleState getImportingBundle()
- {
- return bundle;
- }
-
- public PackageRequirement getPackageRequirement()
- {
- return packageRequirement;
- }
-
- void wireCapability(BundleCapability bundleCapability)
- {
- wire = bundleCapability;
- if (bundleCapability != null)
- bundleCapability.wireRequirement(this);
- }
-
- void unwireCapability()
- {
- if (wire != null)
- {
- wire.unwireRequirement(this);
- wire = null;
- }
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj instanceof BundleRequirement == false)
- return false;
- if (obj == this)
- return true;
- return toString().equals(obj.toString());
- }
-
- @Override
- public int hashCode()
- {
- return toString().hashCode();
- }
-
- @Override
- public String toString()
- {
- String name = packageRequirement.getName();
- return "BundleRequirement[" + name + "," + bundle + "]";
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleResolver.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleResolver.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleResolver.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -1,461 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.resolver;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.classloading.plugins.metadata.PackageCapability;
-import org.jboss.classloading.plugins.metadata.PackageRequirement;
-import org.jboss.classloading.spi.dependency.Module;
-import org.jboss.classloading.spi.metadata.Capability;
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
-import org.jboss.classloading.spi.metadata.Requirement;
-import org.jboss.classloading.spi.version.VersionRange;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.logging.Logger;
-import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.osgi.framework.bundle.OSGiBundleWrapper;
-import org.jboss.osgi.framework.classloading.OSGiPackageRequirement;
-import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.framework.metadata.Parameter;
-import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-
-/**
- * The BundleResolver wires BundleRequirements to their corresponding BundleCapability.
- *
- * @author thomas.diesler(a)jboss.com
- * @since 10-Sep-2009
- */
-public class BundleResolver
-{
- /** The log */
- private static final Logger log = Logger.getLogger(BundleResolver.class);
-
- private OSGiBundleManager bundleManager;
- private Map<OSGiBundleState, List<BundleCapability>> bundleCapabilitiesMap = new ConcurrentHashMap<OSGiBundleState, List<BundleCapability>>();
- private Map<OSGiBundleState, List<BundleRequirement>> bundleRequirementsMap = new ConcurrentHashMap<OSGiBundleState, List<BundleRequirement>>();
-
- public BundleResolver(OSGiBundleManager bundleManager)
- {
- this.bundleManager = bundleManager;
- }
-
- /**
- * Resolve the given list of bundles.
- *
- * This is an iterative process that tries to wire BundleRequirements to BundleCapabilities.
- *
- * @param bundles the bundles to resolve
- * @return The list of resolved bundles in the resolve order or an empty list
- */
- public List<OSGiBundleState> resolveBundles(List<Bundle> bundles)
- {
- if (bundles == null)
- throw new IllegalArgumentException("Null bundles");
-
- // Normalize to OSGiBundleState instances
- List<OSGiBundleState> unresolvedBundles = new ArrayList<OSGiBundleState>();
- for (Bundle bundle : bundles)
- {
- unresolvedBundles.add(assertBundleState(bundle));
- }
-
- int resolved = 1;
- int resolveRounds = 0;
-
- // Get the list of all capabilities
- List<BundleCapability> allCapabilities = new ArrayList<BundleCapability>();
- for (List<BundleCapability> list : bundleCapabilitiesMap.values())
- {
- allCapabilities.addAll(list);
- }
-
- List<OSGiBundleState> resolvedBundles = new ArrayList<OSGiBundleState>();
- while (resolved > 0 && unresolvedBundles.isEmpty() == false)
- {
- resolveRounds++;
-
- log.debug("#" + resolveRounds + " *****************************************************************");
- log.debug("Unresolved bundles: " + unresolvedBundles);
-
- resolved = 0;
- Iterator<OSGiBundleState> it = unresolvedBundles.iterator();
- while (it.hasNext())
- {
- OSGiBundleState bundleState = it.next();
- log.debug("Resolving: " + bundleState);
- if (resolveBundle(allCapabilities, bundleState))
- {
- resolvedBundles.add(bundleState);
- it.remove();
- resolved++;
- }
- }
- }
-
- log.debug("END *****************************************************************");
-
- // Log the unresolved bundles
- for (OSGiBundleState bundle : unresolvedBundles)
- {
- StringBuffer message = new StringBuffer("Unresolved bundle: " + bundle);
- message.append("\n Cannot find exporter for");
- List<BundleRequirement> bundleRequirements = getBundleRequirements(bundle);
- for (BundleRequirement requirement : bundleRequirements)
- {
- PackageRequirement packreq = requirement.getPackageRequirement();
- BundleCapability bestMatch = findBestMatch(allCapabilities, requirement);
- if (bestMatch == null && packreq.isOptional() == false && packreq.isDynamic() == false)
- {
- message.append("\n " + packreq.getName() + ";version=" + packreq.getVersionRange());
- }
- }
- log.debug(message);
- }
-
- return resolvedBundles;
- }
-
- public void removeBundle(Bundle bundle)
- {
- OSGiBundleState bundleState = assertBundleState(bundle);
-
- bundleCapabilitiesMap.remove(bundleState);
-
- List<BundleRequirement> bundleRequirements = bundleRequirementsMap.remove(bundleState);
- if (bundleRequirements != null)
- {
- for (BundleRequirement requirement : bundleRequirements)
- {
- requirement.unwireCapability();
- }
- }
- }
-
- public BundleCapability getMatchingCapability(Module module, PackageRequirement packageRequirement)
- {
- String location = module.getContextName();
- AbstractBundleState bundle = bundleManager.getBundleByLocation(location);
- if (bundle == null)
- return null;
-
- List<BundleRequirement> requirements = bundleRequirementsMap.get(bundle);
- if (requirements == null)
- return null;
-
- BundleCapability result = null;
- for (BundleRequirement req : requirements)
- {
- if (req.getPackageRequirement() == packageRequirement)
- {
- result = req.getWiredCapability();
- break;
- }
- }
-
- return result;
- }
-
- private boolean resolveBundle(List<BundleCapability> allCapabilities, OSGiBundleState bundle)
- {
- List<BundleCapability> bundleCapabilities = getBundleCapabilities(bundle);
- List<BundleRequirement> bundleRequirements = getBundleRequirements(bundle);
-
- List<BundleCapability> futureCapabilities = new ArrayList<BundleCapability>(allCapabilities);
- futureCapabilities.addAll(bundleCapabilities);
-
- for (BundleRequirement requirement : bundleRequirements)
- {
- PackageRequirement packreq = requirement.getPackageRequirement();
-
- BundleCapability bestMatch = findBestMatch(futureCapabilities, requirement);
- if (bestMatch == null && packreq.isOptional() == false && packreq.isDynamic() == false)
- return false;
-
- requirement.wireCapability(bestMatch);
- }
-
- // Remove optional or dynamic requirements that don't have a wire
- Iterator<BundleRequirement> it = bundleRequirements.iterator();
- while (it.hasNext())
- {
- if (it.next().getWiredCapability() == null)
- it.remove();
- }
-
- if (processRequiredBundle(bundle, bundleCapabilities, bundleRequirements) == false)
- return false;
-
- allCapabilities.addAll(bundleCapabilities);
- bundleCapabilitiesMap.put(bundle, bundleCapabilities);
- bundleRequirementsMap.put(bundle, bundleRequirements);
-
- logResolvedBundleInfo(bundle, bundleCapabilities, bundleRequirements);
-
- return true;
- }
-
- /**
- * Logs information about a resolved bundle
- */
- private void logResolvedBundleInfo(OSGiBundleState bundle, List<BundleCapability> bundleCapabilities, List<BundleRequirement> bundleRequirements)
- {
- // Log the package wiring information
- StringBuffer message = new StringBuffer("Resolved: " + bundle);
-
- // Log the exports
- int nameLengthMax = 0;
- for (BundleCapability capability : bundleCapabilities)
- {
- PackageCapability packcap = capability.getPackageCapability();
- String packNameVersion = packcap.getName() + ";version=" + packcap.getVersion();
- nameLengthMax = Math.max(nameLengthMax, packNameVersion.length());
- }
- if (bundleCapabilities.isEmpty() == false)
- {
- message.append("\n Exports");
- List<String> lines = new ArrayList<String>();
- for (BundleCapability capability : bundleCapabilities)
- {
- PackageCapability packcap = capability.getPackageCapability();
- String packNameVersion = packcap.getName() + ";version=" + packcap.getVersion();
- lines.add("\n " + packNameVersion);
- }
- Collections.sort(lines);
- for (String line : lines)
- message.append(line);
- }
-
- // Log the imports
- nameLengthMax = 0;
- for (BundleRequirement requirement : bundleRequirements)
- {
- PackageRequirement packreq = requirement.getPackageRequirement();
- String packNameVersion = packreq.getName() + ";version=" + packreq.getVersionRange();
- nameLengthMax = Math.max(nameLengthMax, packNameVersion.length());
- }
- if (bundleRequirements.isEmpty() == false)
- {
- message.append("\n Imports");
- List<String> lines = new ArrayList<String>();
- for (BundleRequirement requirement : bundleRequirements)
- {
- PackageRequirement packreq = requirement.getPackageRequirement();
- String packNameVersion = packreq.getName() + ";version=" + packreq.getVersionRange();
- StringBuffer line = new StringBuffer("\n " + packNameVersion);
- for (int i = 0; i < (nameLengthMax - packNameVersion.length()); i++)
- line.append(" ");
-
- BundleCapability wire = requirement.getWiredCapability();
- if (wire == null)
- {
- line.append(" <= null");
- }
- else
- {
- Bundle wireBundle = wire.getExportingBundle();
- PackageCapability wireCap = wire.getPackageCapability();
- packNameVersion = wireCap.getName() + ";version=" + wireCap.getVersion();
- line.append(" <= " + wireBundle + " " + packNameVersion);
- }
- lines.add(line.toString());
- }
- Collections.sort(lines);
- for (String line : lines)
- message.append(line);
- }
- log.debug(message);
- }
-
- private BundleCapability findBestMatch(List<BundleCapability> capabilities, BundleRequirement requirement)
- {
- BundleCapability result = null;
- for (BundleCapability capability : capabilities)
- {
- if (capability.matches(requirement))
- {
- if (result == null)
- {
- result = capability;
- }
- else
- {
- // [TODO] handle multiple matches
- }
- }
- }
- return result;
- }
-
- /**
- * Get the set of bundle capabilities
- */
- private List<BundleCapability> getBundleCapabilities(OSGiBundleState bundle)
- {
- List<BundleCapability> result = new ArrayList<BundleCapability>();
-
- OSGiBundleState bundleState = assertBundleState(bundle);
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- ClassLoadingMetaData metadata = unit.getAttachment(ClassLoadingMetaData.class);
-
- List<Capability> capabilities = metadata.getCapabilities().getCapabilities();
- if (capabilities != null)
- {
- for (Capability capability : capabilities)
- {
- if (capability instanceof PackageCapability)
- {
- PackageCapability packageCapability = (PackageCapability)capability;
- result.add(new BundleCapability(bundle, packageCapability));
- }
- }
- }
- return result;
- }
-
- /**
- * Get the set of bundle requirements
- */
- private List<BundleRequirement> getBundleRequirements(OSGiBundleState bundle)
- {
- List<BundleRequirement> result = new ArrayList<BundleRequirement>();
-
- OSGiBundleState bundleState = assertBundleState(bundle);
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- ClassLoadingMetaData classloadingMetaData = unit.getAttachment(ClassLoadingMetaData.class);
-
- List<Requirement> requirements = classloadingMetaData.getRequirements().getRequirements();
- if (requirements != null)
- {
- for (Requirement requirement : requirements)
- {
- if (requirement instanceof PackageRequirement)
- {
- PackageRequirement packageRequirement = (PackageRequirement)requirement;
- result.add(new BundleRequirement(bundle, packageRequirement));
- }
- }
- }
-
- return result;
- }
-
- private boolean processRequiredBundle(OSGiBundleState bundle, List<BundleCapability> bundleCapabilities, List<BundleRequirement> bundleRequirements)
- {
- // The Require-Bundle header specifies that all exported packages from
- // another bundle must be imported, effectively requiring the public interface
- // of another bundle
- OSGiMetaData osgiMetaData = bundle.getOSGiMetaData();
- List<ParameterizedAttribute> requireBundles = osgiMetaData.getRequireBundles();
- if (requireBundles != null)
- {
- for (ParameterizedAttribute attr : requireBundles)
- {
- String requiredBundleName = attr.getAttribute();
- if (requiredBundleName == null)
- throw new IllegalStateException("Cannot obtain value for: " + Constants.REQUIRE_BUNDLE);
-
- String visibility = Constants.VISIBILITY_PRIVATE;
- Parameter param = attr.getParameter(Constants.VISIBILITY_DIRECTIVE);
- if (param != null)
- visibility = (String)param.getValue();
-
- String resolution = Constants.RESOLUTION_MANDATORY;
- param = attr.getParameter(Constants.RESOLUTION_DIRECTIVE);
- if (param != null)
- resolution = (String)param.getValue();
-
- // [TODO] bundle-version
- //String bundleVersion = null;
- //param = attr.getParameter(Constants.BUNDLE_VERSION_ATTRIBUTE);
- //if (param != null)
- // bundleVersion = (String)param.getValue();
-
- if (Constants.RESOLUTION_MANDATORY.equals(resolution))
- {
- Bundle requiredBundle = getRequiredBundle(requiredBundleName);
- if (requiredBundle == null)
- {
- log.debug("Cannot find " + resolution + " required bundle: " + requiredBundleName);
- return false;
- }
-
- List<BundleCapability> otherCapabilities = bundleCapabilitiesMap.get(requiredBundle);
- for (BundleCapability otherCapability : otherCapabilities)
- {
- PackageCapability otherPackage = otherCapability.getPackageCapability();
- String packageName = otherPackage.getName();
- Object version = otherPackage.getVersion();
- VersionRange versionRange = new VersionRange(version, true, version, true);
-
- OSGiPackageRequirement newPackageRequirement = new OSGiPackageRequirement(bundle, packageName, versionRange, null);
- BundleRequirement newBundleRequirement = new BundleRequirement(bundle, newPackageRequirement);
- newBundleRequirement.wireCapability(otherCapability);
- bundleRequirements.add(newBundleRequirement);
-
- if (Constants.VISIBILITY_REEXPORT.equals(visibility))
- {
- BundleCapability newBundleCapability = new BundleCapability(bundle, otherPackage);
- bundleCapabilities.add(newBundleCapability);
- }
- }
- }
- else if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
- {
- // [TODO] resolution=optional
- }
- }
- }
-
- return true;
- }
-
- private Bundle getRequiredBundle(String requiredBundle)
- {
- for (Bundle bundle : bundleCapabilitiesMap.keySet())
- {
- if (bundle.getSymbolicName().equals(requiredBundle))
- return bundle;
- }
- return null;
- }
-
- static OSGiBundleState assertBundleState(Bundle bundle)
- {
- if (bundle instanceof OSGiBundleWrapper)
- bundle = ((OSGiBundleWrapper)bundle).getBundleState();
-
- if (bundle instanceof OSGiBundleState == false)
- throw new IllegalArgumentException("Cannot obtain bunde state from: " + bundle);
-
- return (OSGiBundleState)bundle;
- }
-}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver;
+
+import java.util.List;
+import java.util.Set;
+
+import org.osgi.framework.Version;
+
+/**
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Noc-2009
+ */
+public interface ExportPackage extends NamedPackage
+{
+ Version getVersion();
+
+ List<NamedPackage> getUses();
+
+ Set<ImportPackage> getImporters();
+
+ List<String> getMandatoryAttributes();
+
+ List<String> getIncludes();
+
+ List<String> getExcludes();
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ExportPackage.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver;
+
+import org.jboss.osgi.framework.metadata.VersionRange;
+import org.osgi.framework.Version;
+
+/**
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Noc-2009
+ */
+public interface ImportPackage extends NamedPackage
+{
+ ExportPackage getExporter();
+
+ VersionRange getVersion();
+
+ String getResolution();
+
+ String getBundleSymbolicName();
+
+ Version getBundleVersion();
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/ImportPackage.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver;
+
+import java.util.Map;
+
+
+/**
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Noc-2009
+ */
+public interface NamedPackage
+{
+ Resolvable getOwner();
+
+ String getName();
+
+ Map<String, String> getAttributes();
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/NamedPackage.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver;
+
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+/**
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Noc-2009
+ */
+public interface Resolvable
+{
+ Bundle getBundle();
+
+ String getSymbolicName();
+
+ Version getVersion();
+
+ List<ExportPackage> getExportPackages();
+
+ ExportPackage getExportPackage(String packageName);
+
+ List<ImportPackage> getImportPackages();
+
+ ImportPackage getImportPackage(String packageName);
+
+ boolean isSingleton();
+
+ boolean isResolved();
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolvable.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver;
+
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+
+/**
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Noc-2009
+ */
+public interface Resolver
+{
+ List<Resolvable> getBundles();
+
+ Resolvable addBundle(Bundle bundle);
+
+ Resolvable removeBundle(Bundle bundle);
+
+ List<Resolvable> resolve(List<Bundle> bundles);
+
+ ExportPackage getExporter(Bundle bundle, String importPackage);
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/Resolver.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver.internal;
+
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.osgi.framework.resolver.ExportPackage;
+import org.jboss.osgi.framework.resolver.ImportPackage;
+import org.jboss.osgi.framework.resolver.NamedPackage;
+import org.jboss.osgi.framework.resolver.Resolvable;
+import org.jboss.osgi.spi.NotImplementedException;
+import org.osgi.framework.Version;
+
+/**
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Noc-2009
+ */
+public class ExportPackageImpl extends NamedPackageImpl implements ExportPackage
+{
+ public ExportPackageImpl(Resolvable owner, String packageName)
+ {
+ super(owner, packageName);
+ }
+
+ public List<String> getExcludes()
+ {
+ throw new NotImplementedException();
+ }
+
+ public Set<ImportPackage> getImporters()
+ {
+ throw new NotImplementedException();
+ }
+
+ public List<String> getIncludes()
+ {
+ throw new NotImplementedException();
+ }
+
+ public List<String> getMandatoryAttributes()
+ {
+ throw new NotImplementedException();
+ }
+
+ public List<NamedPackage> getUses()
+ {
+ throw new NotImplementedException();
+ }
+
+ public Version getVersion()
+ {
+ throw new NotImplementedException();
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ExportPackageImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/NamedPackageImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/NamedPackageImpl.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/NamedPackageImpl.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver.internal;
+
+import java.util.Map;
+
+import org.jboss.osgi.framework.resolver.NamedPackage;
+import org.jboss.osgi.framework.resolver.Resolvable;
+import org.jboss.osgi.spi.NotImplementedException;
+
+/**
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Noc-2009
+ */
+public class NamedPackageImpl implements NamedPackage
+{
+ private Resolvable owner;
+ private String packageName;
+
+ public NamedPackageImpl(Resolvable owner, String packageName)
+ {
+ this.owner = owner;
+ this.packageName = packageName;
+ }
+
+ public Resolvable getOwner()
+ {
+ return owner;
+ }
+
+ public String getName()
+ {
+ return packageName;
+ }
+
+ public Map<String, String> getAttributes()
+ {
+ throw new NotImplementedException();
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/NamedPackageImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver.internal;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.PackageAttribute;
+import org.jboss.osgi.framework.resolver.ExportPackage;
+import org.jboss.osgi.framework.resolver.ImportPackage;
+import org.jboss.osgi.framework.resolver.Resolvable;
+import org.jboss.osgi.spi.NotImplementedException;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+/**
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Noc-2009
+ */
+public class ResolvableImpl implements Resolvable
+{
+ private OSGiBundleState bundle;
+ private OSGiMetaData metaData;
+ private boolean resolved;
+
+ private Map<String, ExportPackage> exportedPackages = new LinkedHashMap<String, ExportPackage>();
+
+ public ResolvableImpl(Bundle bundle)
+ {
+ this.bundle = OSGiBundleState.assertBundleState(bundle);
+ this.metaData = ((OSGiBundleState)bundle).getOSGiMetaData();
+
+ // Initialize exported packages
+ List<PackageAttribute> exportPackages = metaData.getExportPackages();
+ if (exportPackages != null)
+ {
+ for (PackageAttribute attr: exportPackages)
+ {
+ String packageName = attr.getPackageInfo().getName();
+ exportedPackages.put(packageName, new ExportPackageImpl(this, packageName));
+ }
+ }
+ }
+
+ public Bundle getBundle()
+ {
+ return bundle;
+ }
+
+ public String getSymbolicName()
+ {
+ return bundle.getSymbolicName();
+ }
+
+ public Version getVersion()
+ {
+ return bundle.getVersion();
+ }
+
+ public ExportPackage getExportPackage(String packageName)
+ {
+ return exportedPackages.get(packageName);
+ }
+
+ public List<ExportPackage> getExportPackages()
+ {
+ List<ExportPackage> values = new ArrayList<ExportPackage>(exportedPackages.values());
+ return Collections.unmodifiableList(values);
+ }
+
+ public ImportPackage getImportPackage(String name)
+ {
+ throw new NotImplementedException();
+ }
+
+ public List<ImportPackage> getImportPackages()
+ {
+ throw new NotImplementedException();
+ }
+
+ public boolean isResolved()
+ {
+ return resolved;
+ }
+
+ public void setResolved(boolean resolved)
+ {
+ this.resolved = resolved;
+ }
+
+ public boolean isSingleton()
+ {
+ return bundle.getOSGiMetaData().isSingleton();
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolvableImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleResolver.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,484 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver.internal.basic;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.classloading.OSGiPackageRequirement;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.Parameter;
+import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
+import org.jboss.osgi.framework.resolver.ExportPackage;
+import org.jboss.osgi.framework.resolver.Resolvable;
+import org.jboss.osgi.framework.resolver.Resolver;
+import org.jboss.osgi.framework.resolver.internal.ResolvableImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+
+/**
+ * The BundleResolver wires BundleRequirements to their corresponding BundleCapability.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 10-Sep-2009
+ */
+public class BasicResolverImpl implements Resolver
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(BasicResolverImpl.class);
+
+ private Map<OSGiBundleState, Resolvable> resolverBundleMap = new ConcurrentHashMap<OSGiBundleState, Resolvable>();
+ private Map<OSGiBundleState, List<BundleCapability>> bundleCapabilitiesMap = new ConcurrentHashMap<OSGiBundleState, List<BundleCapability>>();
+ private Map<OSGiBundleState, List<BundleRequirement>> bundleRequirementsMap = new ConcurrentHashMap<OSGiBundleState, List<BundleRequirement>>();
+
+ public List<Resolvable> getBundles()
+ {
+ List<Resolvable> values = new ArrayList<Resolvable>(resolverBundleMap.values());
+ return Collections.unmodifiableList(values);
+ }
+
+ public Resolvable addBundle(Bundle bundle)
+ {
+ // [TODO] remove this restriction
+ if (bundle.getBundleId() == 0)
+ return null;
+
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
+ return resolverBundleMap.put(bundleState, new ResolvableImpl(bundle));
+ }
+
+ public List<Resolvable> resolve(List<Bundle> bundles)
+ {
+ List<Resolvable> resolvedBundles = new ArrayList<Resolvable>();
+ for (OSGiBundleState aux : resolveBundles(bundles))
+ {
+ Resolvable resBundle = resolverBundleMap.get(aux);
+ if (resBundle == null)
+ throw new IllegalStateException("Cannot obtain bundle for: " + aux);
+ resolvedBundles.add(resBundle);
+ }
+ return Collections.unmodifiableList(resolvedBundles);
+ }
+
+ /**
+ * Resolve the given list of bundles.
+ *
+ * This is an iterative process that tries to wire BundleRequirements to BundleCapabilities.
+ *
+ * @param bundles the bundles to resolve
+ * @return The list of resolved bundles in the resolve order or an empty list
+ */
+ private List<OSGiBundleState> resolveBundles(List<Bundle> bundles)
+ {
+ if (bundles == null)
+ throw new IllegalArgumentException("Null bundles");
+
+ // Normalize to OSGiBundleState instances
+ List<OSGiBundleState> unresolvedBundles = new ArrayList<OSGiBundleState>();
+ for (Bundle bundle : bundles)
+ {
+ unresolvedBundles.add(OSGiBundleState.assertBundleState(bundle));
+ }
+
+ int resolved = 1;
+ int resolveRounds = 0;
+
+ // Get the list of all capabilities
+ List<BundleCapability> allCapabilities = new ArrayList<BundleCapability>();
+ for (List<BundleCapability> list : bundleCapabilitiesMap.values())
+ {
+ allCapabilities.addAll(list);
+ }
+
+ List<OSGiBundleState> resolvedBundles = new ArrayList<OSGiBundleState>();
+ while (resolved > 0 && unresolvedBundles.isEmpty() == false)
+ {
+ resolveRounds++;
+
+ log.debug("#" + resolveRounds + " *****************************************************************");
+ log.debug("Unresolved bundles: " + unresolvedBundles);
+
+ resolved = 0;
+ Iterator<OSGiBundleState> it = unresolvedBundles.iterator();
+ while (it.hasNext())
+ {
+ OSGiBundleState bundleState = it.next();
+ log.debug("Resolving: " + bundleState);
+ if (resolveBundle(allCapabilities, bundleState))
+ {
+ resolvedBundles.add(bundleState);
+ it.remove();
+ resolved++;
+ }
+ }
+ }
+
+ log.debug("END *****************************************************************");
+
+ // Log the unresolved bundles
+ for (OSGiBundleState bundle : unresolvedBundles)
+ {
+ StringBuffer message = new StringBuffer("Unresolved bundle: " + bundle);
+ message.append("\n Cannot find exporter for");
+ List<BundleRequirement> bundleRequirements = getBundleRequirements(bundle);
+ for (BundleRequirement requirement : bundleRequirements)
+ {
+ PackageRequirement packreq = requirement.getPackageRequirement();
+ BundleCapability bestMatch = findBestMatch(allCapabilities, requirement);
+ if (bestMatch == null && packreq.isOptional() == false && packreq.isDynamic() == false)
+ {
+ message.append("\n " + packreq.getName() + ";version=" + packreq.getVersionRange());
+ }
+ }
+ log.debug(message);
+ }
+
+ return resolvedBundles;
+ }
+
+ public Resolvable removeBundle(Bundle bundle)
+ {
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
+
+ bundleCapabilitiesMap.remove(bundleState);
+
+ List<BundleRequirement> bundleRequirements = bundleRequirementsMap.remove(bundleState);
+ if (bundleRequirements != null)
+ {
+ for (BundleRequirement requirement : bundleRequirements)
+ {
+ requirement.unwireCapability();
+ }
+ }
+
+ return null;
+ }
+
+ public ExportPackage getExporter(Bundle bundle, String importPackage)
+ {
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
+ BundleCapability match = getMatchingCapability(bundleState, importPackage);
+ if (match == null)
+ return null;
+
+ OSGiBundleState exportingBundle = match.getExportingBundle();
+ Resolvable resolverBundle = resolverBundleMap.get(exportingBundle);
+ return resolverBundle.getExportPackage(importPackage);
+ }
+
+ private BundleCapability getMatchingCapability(OSGiBundleState bundle, String importPackage)
+ {
+ List<BundleRequirement> requirements = bundleRequirementsMap.get(bundle);
+ if (requirements == null)
+ return null;
+
+ BundleCapability result = null;
+ for (BundleRequirement aux : requirements)
+ {
+ String auxName = aux.getPackageRequirement().getName();
+ if (auxName.equals(importPackage))
+ {
+ result = aux.getWiredCapability();
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ private boolean resolveBundle(List<BundleCapability> allCapabilities, OSGiBundleState bundle)
+ {
+ List<BundleCapability> bundleCapabilities = getBundleCapabilities(bundle);
+ List<BundleRequirement> bundleRequirements = getBundleRequirements(bundle);
+
+ List<BundleCapability> futureCapabilities = new ArrayList<BundleCapability>(allCapabilities);
+ futureCapabilities.addAll(bundleCapabilities);
+
+ for (BundleRequirement requirement : bundleRequirements)
+ {
+ PackageRequirement packreq = requirement.getPackageRequirement();
+
+ BundleCapability bestMatch = findBestMatch(futureCapabilities, requirement);
+ if (bestMatch == null && packreq.isOptional() == false && packreq.isDynamic() == false)
+ return false;
+
+ requirement.wireCapability(bestMatch);
+ }
+
+ // Remove optional or dynamic requirements that don't have a wire
+ Iterator<BundleRequirement> it = bundleRequirements.iterator();
+ while (it.hasNext())
+ {
+ if (it.next().getWiredCapability() == null)
+ it.remove();
+ }
+
+ if (processRequiredBundle(bundle, bundleCapabilities, bundleRequirements) == false)
+ return false;
+
+ allCapabilities.addAll(bundleCapabilities);
+ bundleCapabilitiesMap.put(bundle, bundleCapabilities);
+ bundleRequirementsMap.put(bundle, bundleRequirements);
+
+ logResolvedBundleInfo(bundle, bundleCapabilities, bundleRequirements);
+
+ return true;
+ }
+
+ /**
+ * Logs information about a resolved bundle
+ */
+ private void logResolvedBundleInfo(OSGiBundleState bundle, List<BundleCapability> bundleCapabilities, List<BundleRequirement> bundleRequirements)
+ {
+ // Log the package wiring information
+ StringBuffer message = new StringBuffer("Resolved: " + bundle);
+
+ // Log the exports
+ int nameLengthMax = 0;
+ for (BundleCapability capability : bundleCapabilities)
+ {
+ PackageCapability packcap = capability.getPackageCapability();
+ String packNameVersion = packcap.getName() + ";version=" + packcap.getVersion();
+ nameLengthMax = Math.max(nameLengthMax, packNameVersion.length());
+ }
+ if (bundleCapabilities.isEmpty() == false)
+ {
+ message.append("\n Exports");
+ List<String> lines = new ArrayList<String>();
+ for (BundleCapability capability : bundleCapabilities)
+ {
+ PackageCapability packcap = capability.getPackageCapability();
+ String packNameVersion = packcap.getName() + ";version=" + packcap.getVersion();
+ lines.add("\n " + packNameVersion);
+ }
+ Collections.sort(lines);
+ for (String line : lines)
+ message.append(line);
+ }
+
+ // Log the imports
+ nameLengthMax = 0;
+ for (BundleRequirement requirement : bundleRequirements)
+ {
+ PackageRequirement packreq = requirement.getPackageRequirement();
+ String packNameVersion = packreq.getName() + ";version=" + packreq.getVersionRange();
+ nameLengthMax = Math.max(nameLengthMax, packNameVersion.length());
+ }
+ if (bundleRequirements.isEmpty() == false)
+ {
+ message.append("\n Imports");
+ List<String> lines = new ArrayList<String>();
+ for (BundleRequirement requirement : bundleRequirements)
+ {
+ PackageRequirement packreq = requirement.getPackageRequirement();
+ String packNameVersion = packreq.getName() + ";version=" + packreq.getVersionRange();
+ StringBuffer line = new StringBuffer("\n " + packNameVersion);
+ for (int i = 0; i < (nameLengthMax - packNameVersion.length()); i++)
+ line.append(" ");
+
+ BundleCapability wire = requirement.getWiredCapability();
+ if (wire == null)
+ {
+ line.append(" <= null");
+ }
+ else
+ {
+ Bundle wireBundle = wire.getExportingBundle();
+ PackageCapability wireCap = wire.getPackageCapability();
+ packNameVersion = wireCap.getName() + ";version=" + wireCap.getVersion();
+ line.append(" <= " + wireBundle + " " + packNameVersion);
+ }
+ lines.add(line.toString());
+ }
+ Collections.sort(lines);
+ for (String line : lines)
+ message.append(line);
+ }
+ log.debug(message);
+ }
+
+ private BundleCapability findBestMatch(List<BundleCapability> capabilities, BundleRequirement requirement)
+ {
+ BundleCapability result = null;
+ for (BundleCapability capability : capabilities)
+ {
+ if (capability.matches(requirement))
+ {
+ if (result == null)
+ {
+ result = capability;
+ }
+ else
+ {
+ // [TODO] handle multiple matches
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get the set of bundle capabilities
+ */
+ private List<BundleCapability> getBundleCapabilities(OSGiBundleState bundle)
+ {
+ List<BundleCapability> result = new ArrayList<BundleCapability>();
+
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ ClassLoadingMetaData metadata = unit.getAttachment(ClassLoadingMetaData.class);
+
+ List<Capability> capabilities = metadata.getCapabilities().getCapabilities();
+ if (capabilities != null)
+ {
+ for (Capability capability : capabilities)
+ {
+ if (capability instanceof PackageCapability)
+ {
+ PackageCapability packageCapability = (PackageCapability)capability;
+ result.add(new BundleCapability(bundle, packageCapability));
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get the set of bundle requirements
+ */
+ private List<BundleRequirement> getBundleRequirements(OSGiBundleState bundle)
+ {
+ List<BundleRequirement> result = new ArrayList<BundleRequirement>();
+
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ ClassLoadingMetaData classloadingMetaData = unit.getAttachment(ClassLoadingMetaData.class);
+
+ List<Requirement> requirements = classloadingMetaData.getRequirements().getRequirements();
+ if (requirements != null)
+ {
+ for (Requirement requirement : requirements)
+ {
+ if (requirement instanceof PackageRequirement)
+ {
+ PackageRequirement packageRequirement = (PackageRequirement)requirement;
+ result.add(new BundleRequirement(bundle, packageRequirement));
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private boolean processRequiredBundle(OSGiBundleState bundle, List<BundleCapability> bundleCapabilities, List<BundleRequirement> bundleRequirements)
+ {
+ // The Require-Bundle header specifies that all exported packages from
+ // another bundle must be imported, effectively requiring the public interface
+ // of another bundle
+ OSGiMetaData osgiMetaData = bundle.getOSGiMetaData();
+ List<ParameterizedAttribute> requireBundles = osgiMetaData.getRequireBundles();
+ if (requireBundles != null)
+ {
+ for (ParameterizedAttribute attr : requireBundles)
+ {
+ String requiredBundleName = attr.getAttribute();
+ if (requiredBundleName == null)
+ throw new IllegalStateException("Cannot obtain value for: " + Constants.REQUIRE_BUNDLE);
+
+ String visibility = Constants.VISIBILITY_PRIVATE;
+ Parameter param = attr.getParameter(Constants.VISIBILITY_DIRECTIVE);
+ if (param != null)
+ visibility = (String)param.getValue();
+
+ String resolution = Constants.RESOLUTION_MANDATORY;
+ param = attr.getParameter(Constants.RESOLUTION_DIRECTIVE);
+ if (param != null)
+ resolution = (String)param.getValue();
+
+ // [TODO] bundle-version
+ //String bundleVersion = null;
+ //param = attr.getParameter(Constants.BUNDLE_VERSION_ATTRIBUTE);
+ //if (param != null)
+ // bundleVersion = (String)param.getValue();
+
+ if (Constants.RESOLUTION_MANDATORY.equals(resolution))
+ {
+ Bundle requiredBundle = getRequiredBundle(requiredBundleName);
+ if (requiredBundle == null)
+ {
+ log.debug("Cannot find " + resolution + " required bundle: " + requiredBundleName);
+ return false;
+ }
+
+ List<BundleCapability> otherCapabilities = bundleCapabilitiesMap.get(requiredBundle);
+ for (BundleCapability otherCapability : otherCapabilities)
+ {
+ PackageCapability otherPackage = otherCapability.getPackageCapability();
+ String packageName = otherPackage.getName();
+ Object version = otherPackage.getVersion();
+ VersionRange versionRange = new VersionRange(version, true, version, true);
+
+ OSGiPackageRequirement newPackageRequirement = new OSGiPackageRequirement(bundle, packageName, versionRange, null);
+ BundleRequirement newBundleRequirement = new BundleRequirement(bundle, newPackageRequirement);
+ newBundleRequirement.wireCapability(otherCapability);
+ bundleRequirements.add(newBundleRequirement);
+
+ if (Constants.VISIBILITY_REEXPORT.equals(visibility))
+ {
+ BundleCapability newBundleCapability = new BundleCapability(bundle, otherPackage);
+ bundleCapabilities.add(newBundleCapability);
+ }
+ }
+ }
+ else if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
+ {
+ // [TODO] resolution=optional
+ }
+ }
+ }
+
+ return true;
+ }
+
+ private Bundle getRequiredBundle(String requiredBundle)
+ {
+ for (Bundle bundle : bundleCapabilitiesMap.keySet())
+ {
+ if (bundle.getSymbolicName().equals(requiredBundle))
+ return bundle;
+ }
+ return null;
+ }
+}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleCapability.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleCapability.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleCapability.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleCapability.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver.internal.basic;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.classloading.OSGiPackageCapability;
+import org.jboss.osgi.framework.classloading.OSGiPackageRequirement;
+
+/**
+ * An association of bundle/capability.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 10-Sep-2009
+ */
+public class BundleCapability
+{
+ private OSGiBundleState bundle;
+ private PackageCapability packageCapability;
+ private List<BundleRequirement> wires;
+
+ BundleCapability(OSGiBundleState bundle, PackageCapability packageCapability)
+ {
+ if (bundle == null)
+ throw new IllegalArgumentException("Null bundle");
+ if (packageCapability == null)
+ throw new IllegalArgumentException("Null packageCapability");
+
+ this.bundle = bundle;
+ this.packageCapability = packageCapability;
+ }
+
+ public OSGiBundleState getExportingBundle()
+ {
+ return bundle;
+ }
+
+ public Module getExportingModule()
+ {
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ return unit.getAttachment(Module.class);
+ }
+
+ public PackageCapability getPackageCapability()
+ {
+ return packageCapability;
+ }
+
+ public List<BundleRequirement> getWiredRequirements()
+ {
+ if (wires == null)
+ return Collections.emptyList();
+
+ return Collections.unmodifiableList(wires);
+ }
+
+ boolean matches(BundleRequirement bundleRequirement)
+ {
+ OSGiPackageCapability osgiPackageCapability = (OSGiPackageCapability)packageCapability;
+ OSGiPackageRequirement osgiPackageRequirement = (OSGiPackageRequirement)bundleRequirement.getPackageRequirement();
+ return osgiPackageCapability.match(osgiPackageRequirement);
+ }
+
+ void wireRequirement(BundleRequirement bundleRequirement)
+ {
+ if (wires == null)
+ wires = new CopyOnWriteArrayList<BundleRequirement>();
+
+ wires.add(bundleRequirement);
+ }
+
+ void unwireRequirement(BundleRequirement bundleRequirement)
+ {
+ if (wires != null)
+ wires.remove(bundleRequirement);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof BundleCapability == false)
+ return false;
+ if (obj == this)
+ return true;
+ return toString().equals(obj.toString());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ String name = packageCapability.getName();
+ return "BundleCapability[" + name + "," + bundle + "]";
+ }
+}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleRequirement.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/BundleRequirement.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleRequirement.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BundleRequirement.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver.internal.basic;
+
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+
+/**
+ * An association of bundle/requirement.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 10-Sep-2009
+ */
+public class BundleRequirement
+{
+ private OSGiBundleState bundle;
+ private PackageRequirement packageRequirement;
+ private BundleCapability wire;
+
+ BundleRequirement(OSGiBundleState bundle, PackageRequirement packageRequirement)
+ {
+ if (bundle == null)
+ throw new IllegalArgumentException("Null bundle");
+ if (packageRequirement == null)
+ throw new IllegalArgumentException("Null packageRequirement");
+
+ this.bundle = bundle;
+ this.packageRequirement = packageRequirement;
+ }
+
+ public BundleCapability getWiredCapability()
+ {
+ return wire;
+ }
+
+ public OSGiBundleState getImportingBundle()
+ {
+ return bundle;
+ }
+
+ public PackageRequirement getPackageRequirement()
+ {
+ return packageRequirement;
+ }
+
+ void wireCapability(BundleCapability bundleCapability)
+ {
+ wire = bundleCapability;
+ if (bundleCapability != null)
+ bundleCapability.wireRequirement(this);
+ }
+
+ void unwireCapability()
+ {
+ if (wire != null)
+ {
+ wire.unwireRequirement(this);
+ wire = null;
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof BundleRequirement == false)
+ return false;
+ if (obj == this)
+ return true;
+ return toString().equals(obj.toString());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ String name = packageRequirement.getName();
+ return "BundleRequirement[" + name + "," + bundle + "]";
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -39,7 +39,8 @@
import org.jboss.osgi.framework.bundle.OSGiBundleWrapper;
import org.jboss.osgi.framework.plugins.PackageAdminServicePlugin;
import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
-import org.jboss.osgi.framework.resolver.BundleResolver;
+import org.jboss.osgi.framework.resolver.Resolver;
+import org.jboss.osgi.framework.resolver.Resolvable;
import org.jboss.osgi.spi.NotImplementedException;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -177,8 +178,12 @@
if (unresolvedBundles.isEmpty())
return true;
- BundleResolver bundleResolver = bundleManager.getBundleResolver();
- List<OSGiBundleState> resolvableBundles = bundleResolver.resolveBundles(unresolvedBundles);
+ // Resolve the bundles through the resolver
+ Resolver bundleResolver = bundleManager.getBundleResolver();
+ List<OSGiBundleState> resolvableBundles = new ArrayList<OSGiBundleState>();
+ for (Resolvable aux : bundleResolver.resolve(unresolvedBundles))
+ resolvableBundles.add(OSGiBundleState.assertBundleState(aux.getBundle()));
+
boolean allResolved = resolvableBundles.containsAll(unresolvedBundles);
int resolved = 1;
@@ -241,7 +246,6 @@
return capability.getName();
}
- @SuppressWarnings("deprecation")
public String getSpecificationVersion()
{
throw new NotImplementedException();
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/FrameworkUtil.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/FrameworkUtil.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/FrameworkUtil.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -1,40 +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.util;
-
-import org.jboss.osgi.framework.filter.FilterImpl;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-
-/**
- * FrameworkUtil.
- *
- * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class FrameworkUtil
-{
- public static Filter createFilter(String filter) throws InvalidSyntaxException
- {
- return new FilterImpl(filter);
- }
-}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/NoFilter.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/filter/NoFilter.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/NoFilter.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/util/NoFilter.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,63 @@
+/*
+* 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.util;
+
+import java.util.Dictionary;
+
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Dummy filter implementation
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NoFilter implements Filter
+{
+ /** Singleton instance */
+ public static final Filter INSTANCE = new NoFilter();
+
+ /**
+ * Singleton
+ */
+ private NoFilter()
+ {
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean match(Dictionary dictionary)
+ {
+ return true;
+ }
+
+ public boolean match(ServiceReference reference)
+ {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matchCase(Dictionary dictionary)
+ {
+ return true;
+ }
+}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -83,8 +83,6 @@
{
URL url = getClass().getResource("/META-INF/jboss-osgi-bootstrap.xml");
if (url == null)
- url = getClass().getResource("/META-INF/jboss-osgi-default-bootstrap.xml");
- if (url == null)
throw new IllegalStateException("Cannot find: jboss-osgi-bootstrap.xml");
deploy(url);
try
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTest.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTest.java 2009-11-09 13:49:05 UTC (rev 96170)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTest.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -29,8 +29,10 @@
import java.util.Collections;
import java.util.List;
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.osgi.framework.resolver.BundleResolver;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.launch.OSGiFramework;
+import org.jboss.osgi.framework.resolver.Resolvable;
+import org.jboss.osgi.framework.resolver.Resolver;
import org.jboss.osgi.spi.util.ServiceLoader;
import org.jboss.osgi.testing.OSGiTest;
import org.junit.Test;
@@ -65,11 +67,11 @@
bundlePaths.add("bundles/jboss-osgi-jndi.jar");
bundlePaths.add("bundles/jboss-osgi-xml-binding.jar");
bundlePaths.add("bundles/org.apache.felix.configadmin.jar");
- //bundlePaths.add("bundles/org.apache.felix.http.jetty.jar");
bundlePaths.add("bundles/org.apache.felix.log.jar");
bundlePaths.add("bundles/org.apache.felix.metatype.jar");
bundlePaths.add("bundles/org.osgi.compendium.jar");
-
+ bundlePaths.add("bundles/pax-web-jetty-bundle.jar");
+
Collections.shuffle(bundlePaths);
List<Bundle> unresolved = new ArrayList<Bundle>();
@@ -80,8 +82,11 @@
unresolved.add(bundle);
}
- BundleResolver bundleResolver = new BundleResolver(null);
- List<OSGiBundleState> resolved = bundleResolver.resolveBundles(unresolved);
+ OSGiBundleManager bundleManager = ((OSGiFramework)framework).getBundleManager();
+ Resolver bundleResolver = bundleManager.getBundleResolver();
+ assertEquals("All bundles installed", bundlePaths.size(), bundleResolver.getBundles().size());
+
+ List<Resolvable> resolved = bundleResolver.resolve(unresolved);
assertEquals("All bundles resolved", unresolved.size(), resolved.size());
framework.stop();
Added: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ImportDirectiveResolutionTest.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ImportDirectiveResolutionTest.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ImportDirectiveResolutionTest.java 2009-11-09 13:52:41 UTC (rev 96171)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.resolver;
+
+// $Id$
+
+import org.jboss.osgi.spi.framework.OSGiBootstrap;
+import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
+import org.jboss.osgi.testing.OSGiTest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.Framework;
+
+/**
+ * Test import directive 'resolution'
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 09-Nov-2009
+ */
+@Ignore
+public class ImportDirectiveResolutionTest extends OSGiTest
+{
+
+ private static Framework framework;
+
+ @BeforeClass
+ public static void beforeClass() throws BundleException
+ {
+ OSGiBootstrapProvider bootProvider = OSGiBootstrap.getBootstrapProvider();
+ framework = bootProvider.getFramework();
+ framework.start();
+ }
+
+ @AfterClass
+ public static void afterClass() throws BundleException
+ {
+ if (framework != null)
+ {
+ framework.stop();
+ framework = null;
+ }
+ }
+ /**
+ * [TODO] testImportAvailable
+ */
+ public void testImportAvailable() throws BundleException
+ {
+ }
+
+ /**
+ * [TODO] testImportNotAvailable
+ */
+ public void testImportNotAvailable() throws BundleException
+ {
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/resolver/ImportDirectiveResolutionTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
14 years, 6 months
JBoss-OSGI SVN: r96126 - projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-07 17:47:43 -0500 (Sat, 07 Nov 2009)
New Revision: 96126
Modified:
projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc/config.xml
Log:
Set jdk1.6 as matrix axis.
Modified: projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc/config.xml
===================================================================
--- projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc/config.xml 2009-11-07 22:44:02 UTC (rev 96125)
+++ projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc/config.xml 2009-11-07 22:47:43 UTC (rev 96126)
@@ -25,7 +25,6 @@
</scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
- <jdk>jdk1.6</jdk>
<triggers class="vector">
<hudson.triggers.TimerTrigger>
<spec>0 6 * * *</spec>
@@ -46,6 +45,12 @@
<string>jboss600</string>
</values>
</axis>
+ <axis>
+ <name>jdk</name>
+ <values>
+ <string>jdk1.6</string>
+ </values>
+ </axis>
</axes>
<builders>
<hudson.tasks.Shell>
14 years, 7 months
JBoss-OSGI SVN: r96125 - projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-07 17:44:02 -0500 (Sat, 07 Nov 2009)
New Revision: 96125
Modified:
projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc/config.xml
Log:
Set jdk1.6 explicitly. For some reason that causes HUDSON_HOME to be visible
Modified: projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc/config.xml
===================================================================
--- projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc/config.xml 2009-11-07 21:30:05 UTC (rev 96124)
+++ projects/jboss-osgi/trunk/hudson/hudson-home/jobs/jbossosgi-matrix-jbossmc/config.xml 2009-11-07 22:44:02 UTC (rev 96125)
@@ -25,6 +25,7 @@
</scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
+ <jdk>jdk1.6</jdk>
<triggers class="vector">
<hudson.triggers.TimerTrigger>
<spec>0 6 * * *</spec>
@@ -46,7 +47,6 @@
</values>
</axis>
</axes>
- <jdk>jdk1.6</jdk>
<builders>
<hudson.tasks.Shell>
<command>
14 years, 7 months
JBoss-OSGI SVN: r96124 - projects/jboss-osgi/trunk/reactor/framework/src/test/resources.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-07 16:30:05 -0500 (Sat, 07 Nov 2009)
New Revision: 96124
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/log4j.xml
Log:
Rollback -r95950 log4j.xml. Scroll blindness in console and hudson
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/log4j.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/log4j.xml 2009-11-07 19:16:20 UTC (rev 96123)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/log4j.xml 2009-11-07 21:30:05 UTC (rev 96124)
@@ -8,7 +8,7 @@
<!-- ================================= -->
<appender name="FILE" class="org.apache.log4j.FileAppender">
- <param name="File" value="${java.io.tmpdir}/test.log"/>
+ <param name="File" value="${log4j.output.dir}/test.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
@@ -22,7 +22,7 @@
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
- <param name="Threshold" value="DEBUG" />
+ <param name="Threshold" value="INFO" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n" />
</layout>
@@ -43,7 +43,7 @@
<!-- ======================= -->
<root>
- <appender-ref ref="CONSOLE"/>
+ <!--appender-ref ref="CONSOLE"/-->
<appender-ref ref="FILE"/>
</root>
14 years, 7 months
JBoss-OSGI SVN: r95996 - in projects/jboss-osgi/trunk: testsuite/example/src/test/java/org/jboss/test/osgi/example/jta and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-04 09:12:18 -0500 (Wed, 04 Nov 2009)
New Revision: 95996
Modified:
projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch070-provided-bundles.xml
projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch080-provided-examples.xml
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jta/TransactionTestCase.java
Log:
Add JTA coverage to userguide
Modified: projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch070-provided-bundles.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch070-provided-bundles.xml 2009-11-04 13:14:13 UTC (rev 95995)
+++ projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch070-provided-bundles.xml 2009-11-04 14:12:18 UTC (rev 95996)
@@ -5,22 +5,37 @@
<title>Provided Bundles and Services</title>
- <sect1 xml:id="SecBundleXerces">
- <title>XML Parser Services</title>
+ <sect1 xml:id="SecBundleBlueprint">
+ <title>Blueprint Container Service</title>
- <para>The JBoss OSGi <emphasis role="bold">jboss-osgi-apache-xerces.jar</emphasis> bundle provides services
- from DOM and SAX parsing.</para>
-
- <para>The services are registered with the Framework under the name</para>
+ <para>The JBoss OSGi <emphasis role="bold">jboss-osgi-blueprint.jar</emphasis> bundle provides
+ an early access of a Blueprint extender service.</para>
+ <para>The <ulink url="http://jbossosgi.blogspot.com/2009/04/osgi-blueprint-service-rfc-124.html">Blueprint Container</ulink>
+ service allows bundles to contain standard blueprint descriptors, which can be used for component wiring
+ and injection of blueprint components. The idea is to use a plain POJO programming model and let
+ Blueprint do the wiring for you. There should be no need for OSGi API to "pollute" your application logic.</para>
+
+ <para>The Blueprint API is divided into the <emphasis role="bold">Blueprint Container</emphasis> and
+ <emphasis role="bold">Blueprint Reflection</emphasis> packages.</para>
+
<itemizedlist>
- <listitem><emphasis role="bold"><ulink url="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory....">javax.xml.parsers.SAXParserFactory</ulink></emphasis></listitem>
- <listitem><emphasis role="bold"><ulink url="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFa...">javax.xml.parsers.DocumentBuilderFactory</ulink></emphasis></listitem>
+ <listitem><emphasis role="bold"><ulink url="http://jbmuc.dyndns.org/jboss-osgi-1.0.0.Beta4/apidocs/org/osgi/service/b...">org.osgi.service.blueprint.container</ulink></emphasis></listitem>
+ <listitem><emphasis role="bold"><ulink url="http://jbmuc.dyndns.org/jboss-osgi-1.0.0.Beta4/apidocs/org/osgi/service/b...">org.osgi.service.blueprint.reflect</ulink></emphasis></listitem>
</itemizedlist>
- <para>Please see <ulink url="http://www.osgi.org/javadoc/r4v41/org/osgi/util/xml/XMLParserActivator.html">XMLParserActivator</ulink>
- for details.</para>
+ </sect1>
+
+ <sect1 xml:id="SecHttpService">
+ <title>HttpService</title>
+ <para>The <emphasis role="bold">pax-web-jetty-bundle.jar</emphasis> bundle from the OPS4J
+ <ulink url="http://wiki.ops4j.org/display/paxweb/Pax+Web">Pax Web</ulink> project provides access to the
+ <ulink url="http://www.osgi.org/javadoc/r4v42/org/osgi/service/http/package-frame.html">HttpService</ulink>.</para>
+
+ <para>An example of how a bundle uses the HttpService to register servlet and resources is given in
+ <link linkend="SecHTTPServiceExample">HttpService Example</link>.</para>
+
</sect1>
<sect1 xml:id="SecBundleJAXB">
@@ -111,6 +126,30 @@
</sect1>
+ <sect1 xml:id="SecBundleJTA">
+ <title>JTA Service</title>
+
+ <para>The JBoss OSGi <emphasis role="bold">jboss-osgi-jta.jar</emphasis> bundle registers two services with framework.</para>
+
+ <itemizedlist>
+ <listitem><emphasis role="bold"><ulink url="http://java.sun.com/javaee/5/docs/api/javax/transaction/TransactionManage...">javax.transaction.TransactionManager</ulink></emphasis></listitem>
+ <listitem><emphasis role="bold"><ulink url="http://java.sun.com/javaee/5/docs/api/javax/transaction/UserTransaction.html">javax.transaction.UserTransaction</ulink></emphasis></listitem>
+ </itemizedlist>
+
+ <para>Among others the JTA Service can be configured with these properties.</para>
+
+ <table>
+ <tr><th>Key</th><th>Value</th><th>Description</th></tr>
+ <tr valign="top">
+ <td>com.arjuna.ats.arjuna.objectstore.objectStoreDir</td>
+ <td>${server.data.dir}/tx-object-store</td>
+ <td>The property that sets the transaction object store directory</td>
+ </tr>
+ </table>
+
+ <para>For details please refer to the <ulink url="http://www.jboss.org/jbosstm/docs/index.html">JBossTM documentation</ulink>.</para>
+ </sect1>
+
<sect1 xml:id="SecBundleMicrocontainer">
<title>Microcontainer Service</title>
@@ -137,39 +176,6 @@
</programlisting>
</sect1>
- <sect1 xml:id="SecBundleBlueprint">
- <title>Blueprint Container Service</title>
-
- <para>The JBoss OSGi <emphasis role="bold">jboss-osgi-blueprint.jar</emphasis> bundle provides
- an early access of a Blueprint extender service.</para>
-
- <para>The <ulink url="http://jbossosgi.blogspot.com/2009/04/osgi-blueprint-service-rfc-124.html">Blueprint Container</ulink>
- service allows bundles to contain standard blueprint descriptors, which can be used for component wiring
- and injection of blueprint components. The idea is to use a plain POJO programming model and let
- Blueprint do the wiring for you. There should be no need for OSGi API to "pollute" your application logic.</para>
-
- <para>The Blueprint API is divided into the <emphasis role="bold">Blueprint Container</emphasis> and
- <emphasis role="bold">Blueprint Reflection</emphasis> packages.</para>
-
- <itemizedlist>
- <listitem><emphasis role="bold"><ulink url="http://jbmuc.dyndns.org/jboss-osgi-1.0.0.Beta4/apidocs/org/osgi/service/b...">org.osgi.service.blueprint.container</ulink></emphasis></listitem>
- <listitem><emphasis role="bold"><ulink url="http://jbmuc.dyndns.org/jboss-osgi-1.0.0.Beta4/apidocs/org/osgi/service/b...">org.osgi.service.blueprint.reflect</ulink></emphasis></listitem>
- </itemizedlist>
-
- </sect1>
-
- <sect1 xml:id="SecHttpService">
- <title>HttpService</title>
-
- <para>The <emphasis role="bold">pax-web-jetty-bundle.jar</emphasis> bundle from the OPS4J
- <ulink url="http://wiki.ops4j.org/display/paxweb/Pax+Web">Pax Web</ulink> project provides access to the
- <ulink url="http://www.osgi.org/javadoc/r4v42/org/osgi/service/http/package-frame.html">HttpService</ulink>.</para>
-
- <para>An example of how a bundle uses the HttpService to register servlet and resources is given in
- <link linkend="SecHTTPServiceExample">HttpService Example</link>.</para>
-
- </sect1>
-
<sect1 xml:id="SecWebAppExtender">
<title>WebApp Extender</title>
@@ -193,4 +199,22 @@
</sect1>
+ <sect1 xml:id="SecBundleXerces">
+ <title>XML Parser Services</title>
+
+ <para>The JBoss OSGi <emphasis role="bold">jboss-osgi-apache-xerces.jar</emphasis> bundle provides services
+ from DOM and SAX parsing.</para>
+
+ <para>The services are registered with the Framework under the name</para>
+
+ <itemizedlist>
+ <listitem><emphasis role="bold"><ulink url="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory....">javax.xml.parsers.SAXParserFactory</ulink></emphasis></listitem>
+ <listitem><emphasis role="bold"><ulink url="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFa...">javax.xml.parsers.DocumentBuilderFactory</ulink></emphasis></listitem>
+ </itemizedlist>
+
+ <para>Please see <ulink url="http://www.osgi.org/javadoc/r4v41/org/osgi/util/xml/XMLParserActivator.html">XMLParserActivator</ulink>
+ for details.</para>
+
+ </sect1>
+
</chapter>
Modified: projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch080-provided-examples.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch080-provided-examples.xml 2009-11-04 13:14:13 UTC (rev 95995)
+++ projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch080-provided-examples.xml 2009-11-04 14:12:18 UTC (rev 95996)
@@ -6,7 +6,7 @@
<title>Provided Examples</title>
<sect1 xml:id="SecBuildAndRunExamples">
- <title>Building the Examples</title>
+ <title>Build and Run the Examples</title>
<para>JBoss OSGi comes with a number of examples that demonstrate supported functionality
and show best practices. All examples are part of the binary distribution and tightly
@@ -95,46 +95,97 @@
<para>The simple example is covered in: <link linkend="SecWritingTests">Writing Test Cases</link></para>
</sect1>
- <sect1 xml:id="SecXMLParserServiceExample">
- <title>SAX/DOM Parser Service Example</title>
+ <sect1 xml:id="SecBlueprintContainerExample">
+ <title>Blueprint Container</title>
+
+ <para>The <emphasis role="bold">example-blueprint.jar</emphasis> bundle contains a number of
+ components that are wired together and registerd as OSGi service through the Blueprint Container
+ Service.</para>
+
+ <para>The example uses this simple blueprint descriptor</para>
- <para>The <emphasis role="bold">example-xml-parser.jar</emphasis> bundle gets a DocumentBuilderFactory/SAXParserFactory
- respectivly and unmarshalls an XML document using that parser.
- </para>
+ <programlisting role="XML"><![CDATA[
+ <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" ...>
+
+ <bean id="beanA" class="org.jboss.test.osgi.example.blueprint.bundle.BeanA">
+ <property name="mbeanServer" ref="mbeanService"/>
+ </bean>
+
+ <service id="serviceA" ref="beanA" interface="org.jboss.test.osgi.example.blueprint.bundle.ServiceA">
+ </service>
+
+ <service id="serviceB" interface="org.jboss.test.osgi.example.blueprint.bundle.ServiceB">
+ <bean class="org.jboss.test.osgi.example.blueprint.bundle.BeanB">
+ <property name="beanA" ref="beanA"/>
+ </bean>
+ </service>
+
+ <reference id="mbeanService" interface="javax.management.MBeanServer"/>
+ </blueprint>
+ ]]></programlisting>
+
+ <para>The Blueprint Container registers two services <emphasis role="bold">ServiceA</emphasis> and
+ <emphasis role="bold">ServiceB</emphasis>. ServiceA is backed up by <emphasis role="bold">BeanA</emphasis>,
+ ServiceB is backed up by the anonymous <emphasis role="bold">BeanB</emphasis>. BeanA is injected into
+ BeanB and the <emphasis role="bold">MBeanServer</emphasis> gets injected into BeanA. Both beans are plain POJOs.
+ There is <emphasis role="bold">no BundleActivator</emphasis> neccessary to register the services.</para>
+
+ <para>The example test verifies the correct wiring like this</para>
+
<programlisting role="JAVA">
- ServiceReference sref = context.getServiceReference(DocumentBuilderFactory.class.getName());
- if (sref == null)
- throw new IllegalStateException("DocumentBuilderFactory not available");
-
- DocumentBuilderFactory factory = (DocumentBuilderFactory)context.getService(sref);
- factory.setValidating(false);
-
- DocumentBuilder domBuilder = factory.newDocumentBuilder();
- URL resURL = context.getBundle().getResource("example-xml-parser.xml");
- Document dom = domBuilder.parse(resURL.openStream());
- assertNotNull("Document not null", dom);
+ @Test
+ public void testServiceA() throws Exception
+ {
+ ServiceReference sref = context.getServiceReference(ServiceA.class.getName());
+ assertNotNull("ServiceA not null", sref);
+
+ ServiceA service = (ServiceA)context.getService(sref);
+ MBeanServer mbeanServer = service.getMbeanServer();
+ assertNotNull("MBeanServer not null", mbeanServer);
+ }
</programlisting>
<programlisting role="JAVA">
- ServiceReference sref = context.getServiceReference(SAXParserFactory.class.getName());
- if (sref == null)
- throw new IllegalStateException("SAXParserFactory not available");
+ @Test
+ public void testServiceB() throws Exception
+ {
+ ServiceReference sref = context.getServiceReference(ServiceB.class.getName());
+ assertNotNull("ServiceB not null", sref);
+
+ ServiceB service = (ServiceB)context.getService(sref);
+ BeanA beanA = service.getBeanA();
+ assertNotNull("BeanA not null", beanA);
+ }
+ </programlisting>
+ </sect1>
+
+ <sect1 xml:id="SecHTTPServiceExample">
+ <title>HttpService</title>
+
+ <para>The <emphasis role="bold">example-http.jar</emphasis> bundle contains a Service
+ that registeres a servlet and a resource with the <ulink url="http://www.osgi.org/javadoc/r4v41/org/osgi/service/http/HttpService.html">HttpService</ulink>.
+ </para>
+
+ <programlisting role="JAVA">
+ ServiceTracker tracker = new ServiceTracker(context, HttpService.class.getName(), null);
+ tracker.open();
- SAXParserFactory factory = (SAXParserFactory)context.getService(sref);
- factory.setValidating(false);
-
- SAXParser saxParser = factory.newSAXParser();
- URL resURL = context.getBundle().getResource("example-xml-parser.xml");
-
- SAXHandler saxHandler = new SAXHandler();
- saxParser.parse(resURL.openStream(), saxHandler);
- assertEquals("content", saxHandler.getContent());
+ HttpService httpService = (HttpService)tracker.getService();
+ if (httpService == null)
+ throw new IllegalStateException("HttpService not registered");
+
+ Properties initParams = new Properties();
+ initParams.setProperty("initProp", "SomeValue");
+ httpService.registerServlet("/servlet", new EndpointServlet(context), initParams, null);
+ httpService.registerResources("/file", "/res", null);
</programlisting>
+
+ <para>The test then verifies that the registered servlet context and the registered resource can be accessed.</para>
</sect1>
<sect1 xml:id="SecJAXBServiceExample">
- <title>JAXB Service Example</title>
+ <title>JAXB Service</title>
<para>The <emphasis role="bold">example-xml-jaxb.jar</emphasis> bundle gets the JAXBContext from the JAXBService
and unmarshalls an XML document using JAXB
@@ -156,7 +207,7 @@
</sect1>
<sect1 xml:id="SecJMXServiceExample">
- <title>JMX Service Example</title>
+ <title>JMX Service</title>
<para>The <emphasis role="bold">example-jmx.jar</emphasis> bundle tracks the MBeanServer service and registers
a pojo with JMX. It then verifies the JMX access.
@@ -216,7 +267,7 @@
</sect1>
<sect1 xml:id="SecJNDIServiceExample">
- <title>JNDI Service Example</title>
+ <title>JNDI Service</title>
<para>The <emphasis role="bold">example-jndi.jar</emphasis> bundle gets the InitialContext service and registers
a string with JNDI. It then verifies the JNDI access.
@@ -261,32 +312,103 @@
</sect1>
- <sect1 xml:id="SecHTTPServiceExample">
- <title>HttpService Example</title>
-
- <para>The <emphasis role="bold">example-http.jar</emphasis> bundle contains a Service
- that registeres a servlet and a resource with the <ulink url="http://www.osgi.org/javadoc/r4v41/org/osgi/service/http/HttpService.html">HttpService</ulink>.
+ <sect1 xml:id="SecJTAServiceExample">
+ <title>JTA Service</title>
+
+ <para>The <emphasis role="bold">example-jta.jar</emphasis> bundle gets the
+ <ulink url="http://java.sun.com/javaee/5/docs/api/javax/transaction/UserTransaction.html">javax.transaction.UserTransaction</ulink> service
+ and registers a transactional user object (i.e. one that implements <ulink url="http://java.sun.com/javaee/5/docs/api/javax/transaction/Synchronization.html">
+ Synchronization</ulink>) with the <ulink url="http://java.sun.com/javaee/5/docs/api/javax/transaction/TransactionManage...">javax.transaction.TransactionManager</ulink>
+ service. It then verifies that modifications on the user object are transactional.
</para>
<programlisting role="JAVA">
- ServiceTracker tracker = new ServiceTracker(context, HttpService.class.getName(), null);
- tracker.open();
+ Transactional txObj = new Transactional();
- HttpService httpService = (HttpService)tracker.getService();
- if (httpService == null)
- throw new IllegalStateException("HttpService not registered");
-
- Properties initParams = new Properties();
- initParams.setProperty("initProp", "SomeValue");
- httpService.registerServlet("/servlet", new EndpointServlet(context), initParams, null);
- httpService.registerResources("/file", "/res", null);
+ ServiceReference userTxRef = context.getServiceReference(UserTransaction.class.getName());
+ assertNotNull("UserTransaction service not null", userTxRef);
+
+ UserTransaction userTx = (UserTransaction)context.getService(userTxRef);
+ assertNotNull("UserTransaction not null", userTx);
+
+ userTx.begin();
+ try
+ {
+ ServiceReference tmRef = context.getServiceReference(TransactionManager.class.getName());
+ assertNotNull("TransactionManager service not null", tmRef);
+
+ TransactionManager tm = (TransactionManager)context.getService(tmRef);
+ assertNotNull("TransactionManager not null", tm);
+
+ Transaction tx = tm.getTransaction();
+ assertNotNull("Transaction not null", tx);
+
+ tx.registerSynchronization(txObj);
+
+ txObj.setMessage("Donate $1.000.000");
+ assertNull("Uncommited message null", txObj.getMessage());
+
+ userTx.commit();
+ }
+ catch (Exception e)
+ {
+ userTx.setRollbackOnly();
+ }
+
+ assertEquals("Donate $1.000.000", txObj.getMessage());
</programlisting>
- <para>The test then verifies that the registered servlet context and the registered resource can be accessed.</para>
+ <programlisting role="JAVA">
+ class Transactional implements Synchronization
+ {
+ private String volatileMessage;
+ private String message;
+
+ public void beforeCompletion()
+ {
+ }
+
+ public void afterCompletion(int status)
+ {
+ if (status == Status.STATUS_COMMITTED)
+ message = volatileMessage;
+ }
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public void setMessage(String message)
+ {
+ this.volatileMessage = message;
+ }
+ }
+ </programlisting>
+
</sect1>
+ <sect1 xml:id="SecMicrocontainerServiceExample">
+ <title>Microcontainer Service</title>
+
+ <para>The <emphasis role="bold">example-microcontainer.jar</emphasis> bundle calls a service
+ from an MC bean and vica versa. The MC bean gets the MBeanServer injected and registeres itself as an MBean.</para>
+
+ <para>The test accesses the registered MBean.</para>
+
+ <programlisting role="JAVA">
+ @Test
+ public void testServiceRoundTrip() throws Exception
+ {
+ SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, MBEAN_NAME, runtime.getMBeanServer());
+ assertEquals("hello", someBean.echo("hello"));
+ assertEquals("hello", someBean.callSomeService("hello"));
+ }
+ </programlisting>
+ </sect1>
+
<sect1 xml:id="SecWebAppExample">
- <title>WebApp Example</title>
+ <title>Web Application</title>
<para>The <emphasis role="bold">example-webapp.war</emphasis> archive is an OSGi Bundle and a Web Application Archive (WAR)
at the same time. Similar to <link linkend="SecHTTPServiceExample">HTTP Service Example</link> it registers a servlet and resources with
@@ -344,88 +466,42 @@
</sect1>
- <sect1 xml:id="SecMicrocontainerServiceExample">
- <title>Microcontainer Service Example</title>
+ <sect1 xml:id="SecXMLParserServiceExample">
+ <title>XML Parser Service</title>
+
+ <para>The <emphasis role="bold">example-xml-parser.jar</emphasis> bundle gets a DocumentBuilderFactory/SAXParserFactory
+ respectivly and unmarshalls an XML document using that parser.
+ </para>
- <para>The <emphasis role="bold">example-microcontainer.jar</emphasis> bundle calls a service
- from an MC bean and vica versa. The MC bean gets the MBeanServer injected and registeres itself as an MBean.</para>
-
- <para>The test accesses the registered MBean.</para>
-
<programlisting role="JAVA">
- @Test
- public void testServiceRoundTrip() throws Exception
- {
- SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, MBEAN_NAME, runtime.getMBeanServer());
- assertEquals("hello", someBean.echo("hello"));
- assertEquals("hello", someBean.callSomeService("hello"));
- }
+ ServiceReference sref = context.getServiceReference(DocumentBuilderFactory.class.getName());
+ if (sref == null)
+ throw new IllegalStateException("DocumentBuilderFactory not available");
+
+ DocumentBuilderFactory factory = (DocumentBuilderFactory)context.getService(sref);
+ factory.setValidating(false);
+
+ DocumentBuilder domBuilder = factory.newDocumentBuilder();
+ URL resURL = context.getBundle().getResource("example-xml-parser.xml");
+ Document dom = domBuilder.parse(resURL.openStream());
+ assertNotNull("Document not null", dom);
</programlisting>
- </sect1>
-
- <sect1 xml:id="SecBlueprintContainerExample">
- <title>Blueprint Container Example</title>
- <para>The <emphasis role="bold">example-blueprint.jar</emphasis> bundle contains a number of
- components that are wired together and registerd as OSGi service through the Blueprint Container
- Service.</para>
-
- <para>The example uses this simple blueprint descriptor</para>
-
- <programlisting role="XML"><![CDATA[
- <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" ...>
+ <programlisting role="JAVA">
+ ServiceReference sref = context.getServiceReference(SAXParserFactory.class.getName());
+ if (sref == null)
+ throw new IllegalStateException("SAXParserFactory not available");
- <bean id="beanA" class="org.jboss.test.osgi.example.blueprint.bundle.BeanA">
- <property name="mbeanServer" ref="mbeanService"/>
- </bean>
+ SAXParserFactory factory = (SAXParserFactory)context.getService(sref);
+ factory.setValidating(false);
- <service id="serviceA" ref="beanA" interface="org.jboss.test.osgi.example.blueprint.bundle.ServiceA">
- </service>
+ SAXParser saxParser = factory.newSAXParser();
+ URL resURL = context.getBundle().getResource("example-xml-parser.xml");
- <service id="serviceB" interface="org.jboss.test.osgi.example.blueprint.bundle.ServiceB">
- <bean class="org.jboss.test.osgi.example.blueprint.bundle.BeanB">
- <property name="beanA" ref="beanA"/>
- </bean>
- </service>
-
- <reference id="mbeanService" interface="javax.management.MBeanServer"/>
-
- </blueprint>
- ]]></programlisting>
-
- <para>The Blueprint Container registers two services <emphasis role="bold">ServiceA</emphasis> and
- <emphasis role="bold">ServiceB</emphasis>. ServiceA is backed up by <emphasis role="bold">BeanA</emphasis>,
- ServiceB is backed up by the anonymous <emphasis role="bold">BeanB</emphasis>. BeanA is injected into
- BeanB and the <emphasis role="bold">MBeanServer</emphasis> gets injected into BeanA. Both beans are plain POJOs.
- There is <emphasis role="bold">no BundleActivator</emphasis> neccessary to register the services.</para>
-
- <para>The example test verifies the correct wiring like this</para>
-
- <programlisting role="JAVA">
- @Test
- public void testServiceA() throws Exception
- {
- ServiceReference sref = context.getServiceReference(ServiceA.class.getName());
- assertNotNull("ServiceA not null", sref);
-
- ServiceA service = (ServiceA)context.getService(sref);
- MBeanServer mbeanServer = service.getMbeanServer();
- assertNotNull("MBeanServer not null", mbeanServer);
- }
+ SAXHandler saxHandler = new SAXHandler();
+ saxParser.parse(resURL.openStream(), saxHandler);
+ assertEquals("content", saxHandler.getContent());
</programlisting>
-
- <programlisting role="JAVA">
- @Test
- public void testServiceB() throws Exception
- {
- ServiceReference sref = context.getServiceReference(ServiceB.class.getName());
- assertNotNull("ServiceB not null", sref);
-
- ServiceB service = (ServiceB)context.getService(sref);
- BeanA beanA = service.getBeanA();
- assertNotNull("BeanA not null", beanA);
- }
- </programlisting>
</sect1>
</chapter>
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jta/TransactionTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jta/TransactionTestCase.java 2009-11-04 13:14:13 UTC (rev 95995)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jta/TransactionTestCase.java 2009-11-04 14:12:18 UTC (rev 95996)
@@ -93,20 +93,29 @@
// Stop here if the context is not injected
assumeNotNull(context);
- ServiceReference sref = context.getServiceReference(UserTransaction.class.getName());
- assertNotNull("UserTransaction service not null", sref);
+ Transactional txObj = new Transactional();
- UserTransaction userTx = (UserTransaction)context.getService(sref);
+ ServiceReference userTxRef = context.getServiceReference(UserTransaction.class.getName());
+ assertNotNull("UserTransaction service not null", userTxRef);
+
+ UserTransaction userTx = (UserTransaction)context.getService(userTxRef);
assertNotNull("UserTransaction not null", userTx);
- Transactional txObj = new Transactional();
-
userTx.begin();
try
{
- txObj.register(context);
+ ServiceReference tmRef = context.getServiceReference(TransactionManager.class.getName());
+ assertNotNull("TransactionManager service not null", tmRef);
- txObj.setMessage("Hello World");
+ TransactionManager tm = (TransactionManager)context.getService(tmRef);
+ assertNotNull("TransactionManager not null", tm);
+
+ Transaction tx = tm.getTransaction();
+ assertNotNull("Transaction not null", tx);
+
+ tx.registerSynchronization(txObj);
+
+ txObj.setMessage("Donate $1.000.000");
assertNull("Uncommited message null", txObj.getMessage());
userTx.commit();
@@ -116,7 +125,7 @@
userTx.setRollbackOnly();
}
- assertEquals("Hello World", txObj.getMessage());
+ assertEquals("Donate $1.000.000", txObj.getMessage());
}
class Transactional implements Synchronization
@@ -143,19 +152,5 @@
{
this.volatileMessage = message;
}
-
- void register(BundleContext context) throws Exception
- {
- ServiceReference sref = context.getServiceReference(TransactionManager.class.getName());
- assertNotNull("TransactionManager service not null", sref);
-
- TransactionManager tm = (TransactionManager)context.getService(sref);
- assertNotNull("TransactionManager not null", tm);
-
- Transaction tx = tm.getTransaction();
- assertNotNull("Transaction not null", tx);
-
- tx.registerSynchronization(this);
- }
}
}
\ No newline at end of file
14 years, 7 months