[jboss-osgi-commits] JBoss-OSGI SVN: r99339 - in projects/jboss-osgi/projects/runtime/framework/trunk/src: main/java/org/jboss/osgi/framework/deployers and 2 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Wed Jan 13 08:39:49 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-01-13 08:39:48 -0500 (Wed, 13 Jan 2010)
New Revision: 99339

Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleRequirement.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentClassLoadingDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java
Log:
Simplify Bundle Capability/Requirement

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java	2010-01-13 13:31:40 UTC (rev 99338)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java	2010-01-13 13:39:48 UTC (rev 99339)
@@ -26,6 +26,7 @@
 import org.jboss.classloading.plugins.metadata.ModuleCapability;
 import org.jboss.classloading.spi.dependency.Module;
 import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.version.VersionRange;
 import org.jboss.osgi.framework.bundle.AbstractBundleState;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.framework.metadata.Parameter;
@@ -66,7 +67,7 @@
 
       return new OSGiBundleCapability(symbolicName, version, bundleState);
    }
-   
+
    /**
     * Create a new OSGiBundleCapability.
     * 
@@ -82,7 +83,7 @@
          throw new IllegalArgumentException("Null bundleState");
       this.bundleState = bundleState;
    }
-   
+
    /**
     * Get the metadata.
     * 
@@ -100,33 +101,34 @@
          return false;
       if (requirement instanceof OSGiBundleRequirement == false)
          return true;
-      
+
       // Review its not clear to me from the spec whether attribute matching 
       // beyond the version should work for require-bundle?
-      OSGiBundleRequirement bundleRequirement = (OSGiBundleRequirement) requirement;
-      OSGiMetaData osgiMetaData = getMetaData();
-      ParameterizedAttribute ourParameters = osgiMetaData.getBundleParameters();
-      ParameterizedAttribute otherParameters = bundleRequirement.getRequireBundle();
-      if (otherParameters != null)
+      Version ourVersion = Version.parseVersion(getMetaData().getBundleVersion());
+      OSGiBundleRequirement bundleRequirement = (OSGiBundleRequirement)requirement;
+      VersionRange requiredRange = bundleRequirement.getVersionRange();
+      if (requiredRange.isInRange(ourVersion) == false)
+         return false;
+
+      ParameterizedAttribute ourParameters = getMetaData().getBundleParameters();
+      if (ourParameters == null)
+         return false;
+
+      Map<String, Parameter> params = bundleRequirement.getAttributes();
+      if (params != null && params.isEmpty() == false)
       {
-         Map<String, Parameter> params = otherParameters.getAttributes();
-         if (params != null && params.isEmpty() == false)
+         for (String name : params.keySet())
          {
-            for (String name : params.keySet())
-            {
-               if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name) == false)
-               {
-                  if (ourParameters == null)
-                     return false;
-                  String ourValue = ourParameters.getAttributeValue(name, String.class);
-                  if (ourValue == null)
-                     return false;
-                  if (ourValue.equals(otherParameters.getAttributeValue(name, String.class)) == false)
-                     return false;
-               }
-            }
+            if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name))
+               continue;
+
+            String reqValue = (String)params.get(name).getValue();
+            String ourValue = ourParameters.getAttributeValue(name, String.class);
+            if (reqValue.equals(ourValue) == false)
+               return false;
          }
       }
+
       return true;
    }
 
@@ -137,9 +139,9 @@
          return true;
       if (obj == null || obj instanceof OSGiBundleCapability == false)
          return false;
-      if (super.equals(obj) ==false)
+      if (super.equals(obj) == false)
          return false;
-      OSGiBundleCapability other = (OSGiBundleCapability) obj;
+      OSGiBundleCapability other = (OSGiBundleCapability)obj;
       return getMetaData().equals(other.getMetaData());
    }
 

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleRequirement.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleRequirement.java	2010-01-13 13:31:40 UTC (rev 99338)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleRequirement.java	2010-01-13 13:39:48 UTC (rev 99339)
@@ -21,6 +21,8 @@
 */
 package org.jboss.osgi.framework.classloading;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.jboss.classloading.plugins.metadata.ModuleRequirement;
@@ -42,10 +44,11 @@
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 4264597072894634275L;
-   
-   /** The attributes */
-   private ParameterizedAttribute requireBundle;
 
+   private String visibility;
+   private String resolution;
+   private Map<String, Parameter> attributes;
+
    /**
     * Create a new OSGiBundleRequirement.
     * 
@@ -59,49 +62,61 @@
          throw new IllegalArgumentException("Null require bundle");
 
       String name = requireBundle.getAttribute();
-      
+
       AbstractVersionRange range = null;
       String version = requireBundle.getAttributeValue(Constants.BUNDLE_VERSION_ATTRIBUTE, String.class);
       if (version != null)
-         range = (AbstractVersionRange) AbstractVersionRange.valueOf(version);
+         range = (AbstractVersionRange)AbstractVersionRange.valueOf(version);
 
-      return new OSGiBundleRequirement(name, range, requireBundle);
+      String visibility = requireBundle.getDirectiveValue(Constants.VISIBILITY_DIRECTIVE, String.class);
+      String resolution = requireBundle.getDirectiveValue(Constants.RESOLUTION_DIRECTIVE, String.class);
+      Map<String, Parameter> attributes = requireBundle.getAttributes();
+
+      return new OSGiBundleRequirement(name, range, visibility, resolution, attributes);
    }
-   
+
    /**
-    * Create a new OSGiBundleRequirement.
+    * Create a new bundle requirement.
     * 
-    * @param name the name
-    * @param versionRange the version range - pass null for all versions
-    * @param requireBundle the require bundle metadata
-    * @throws IllegalArgumentException for a null name or requireBundle
+    * @param name the symbolic name of the required bundle
+    * @param versionRange the version range of the required bundle
     */
-   public OSGiBundleRequirement(String name, VersionRange versionRange, ParameterizedAttribute requireBundle)
+   public static OSGiBundleRequirement create(String name, VersionRange versionRange)
    {
+      return new OSGiBundleRequirement(name, versionRange, Constants.VISIBILITY_PRIVATE, Constants.RESOLUTION_MANDATORY, null);
+   }
+
+   /**
+    * Create a new OSGiBundleRequirement.
+    */
+   private OSGiBundleRequirement(String name, VersionRange versionRange, String visDirective, String resDirective, Map<String, Parameter> attrMap)
+   {
       super(name, versionRange);
-      if (requireBundle == null)
-         throw new IllegalArgumentException("Null requireBundle");
-      this.requireBundle = requireBundle;
 
-      String visibility = requireBundle.getDirectiveValue(Constants.VISIBILITY_DIRECTIVE, String.class);
+      attributes = attrMap;
+      if (attributes == null)
+         attributes = new HashMap<String, Parameter>();
+
+      visibility = visDirective;
+      if (visibility == null)
+         visibility = Constants.VISIBILITY_PRIVATE;
+
+      resolution = resDirective;
+      if (resolution == null)
+         resolution = Constants.RESOLUTION_MANDATORY;
+
       if (Constants.VISIBILITY_REEXPORT.equals(visibility))
          setReExport(true);
 
-      String resolution = requireBundle.getDirectiveValue(Constants.RESOLUTION_DIRECTIVE, String.class);
       if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
          setOptional(true);
    }
-   
-   /**
-    * Get the requireBundle metadata.
-    * 
-    * @return the requireBundle.
-    */
-   public ParameterizedAttribute getRequireBundle()
+
+   public Map<String, Parameter> getAttributes()
    {
-      return requireBundle;
+      return Collections.unmodifiableMap(attributes);
    }
-   
+
    @Override
    public boolean equals(Object obj)
    {
@@ -109,9 +124,9 @@
          return true;
       if (obj == null || obj instanceof OSGiBundleRequirement == false)
          return false;
-      if (super.equals(obj) ==false)
+      if (super.equals(obj) == false)
          return false;
-      
+
       return true;
    }
 
@@ -119,8 +134,10 @@
    protected void toString(StringBuffer buffer)
    {
       super.toString(buffer);
-      Map<String, Parameter> parameters = requireBundle.getAttributes();
-      if (parameters != null && parameters.isEmpty() == false)
-         buffer.append(" attributes=").append(parameters);
+      if (attributes.containsKey(Constants.VISIBILITY_DIRECTIVE) == false)
+         buffer.append(Constants.VISIBILITY_DIRECTIVE + ":=" + visibility);
+      if (attributes.containsKey(Constants.RESOLUTION_DIRECTIVE) == false)
+         buffer.append(Constants.RESOLUTION_DIRECTIVE + ":=" + resolution);
+      buffer.append(attributes);
    }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java	2010-01-13 13:31:40 UTC (rev 99338)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java	2010-01-13 13:39:48 UTC (rev 99339)
@@ -112,7 +112,7 @@
    {
       if (fragmentLoaders == null)
          fragmentLoaders = new ArrayList<DelegateLoader>();
-      
+
       fragmentLoaders.add(delegateLoader);
    }
 

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java	2010-01-13 13:31:40 UTC (rev 99338)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java	2010-01-13 13:39:48 UTC (rev 99339)
@@ -56,7 +56,7 @@
 {
    private ClassLoaderDomain domain;
    private ClassLoaderFactory factory;
-   
+
    public AbstractOSGiClassLoadingDeployer()
    {
       super(OSGiMetaData.class);
@@ -70,7 +70,7 @@
    {
       this.domain = domain;
    }
-   
+
    public void setFactory(ClassLoaderFactory factory)
    {
       this.factory = factory;
@@ -85,9 +85,9 @@
       AbstractBundleState bundleState = unit.getAttachment(AbstractBundleState.class);
       if (bundleState == null)
          throw new IllegalStateException("No bundle state");
-      
+
       OSGiBundleManager bundleManager = bundleState.getBundleManager();
-      
+
       OSGiClassLoadingMetaData classLoadingMetaData = new OSGiClassLoadingMetaData();
       classLoadingMetaData.setName(bundleState.getSymbolicName());
       classLoadingMetaData.setVersion(bundleState.getVersion());
@@ -95,10 +95,10 @@
 
       CapabilitiesMetaData capabilities = classLoadingMetaData.getCapabilities();
       RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
-      
+
       OSGiBundleCapability bundleCapability = OSGiBundleCapability.create(bundleState);
       capabilities.addCapability(bundleCapability);
-      
+
       List<ParameterizedAttribute> requireBundles = osgiMetaData.getRequireBundles();
       if (requireBundles != null && requireBundles.isEmpty() == false)
       {
@@ -108,17 +108,17 @@
             requirements.addRequirement(requirement);
          }
       }
-      
+
       List<PackageAttribute> exported = osgiMetaData.getExportPackages();
       if (exported != null && exported.isEmpty() == false)
       {
          for (PackageAttribute packageAttribute : exported)
          {
-            OSGiPackageCapability packageCapability = OSGiPackageCapability.create(bundleState, packageAttribute); 
+            OSGiPackageCapability packageCapability = OSGiPackageCapability.create(bundleState, packageAttribute);
             capabilities.addCapability(packageCapability);
          }
       }
-      
+
       List<PackageAttribute> imported = osgiMetaData.getImportPackages();
       if (imported != null && imported.isEmpty() == false)
       {
@@ -126,22 +126,22 @@
          for (PackageAttribute packageAttribute : imported)
          {
             String packageName = packageAttribute.getAttribute();
-            
+
             // [TODO] Should system packages be added as capabilities?
             boolean isSystemPackage = syspackPlugin.isSystemPackage(packageName);
             if (isSystemPackage == false)
             {
-               OSGiPackageRequirement requirement = OSGiPackageRequirement.create(bundleState, packageAttribute); 
+               OSGiPackageRequirement requirement = OSGiPackageRequirement.create(bundleState, packageAttribute);
                requirements.addRequirement(requirement);
             }
          }
       }
-      
+
       unit.addAttachment(ClassLoadingMetaData.class, classLoadingMetaData);
 
       // AnnotationMetaDataDeployer.ANNOTATION_META_DATA_COMPLETE
       unit.addAttachment("org.jboss.deployment.annotation.metadata.complete", Boolean.TRUE);
-      
+
       // Add the OSGi ClassLoaderFactory if configured
       if (factory != null)
          unit.addAttachment(ClassLoaderFactory.class, factory);

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentClassLoadingDeployer.java	2010-01-13 13:31:40 UTC (rev 99338)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentClassLoadingDeployer.java	2010-01-13 13:39:48 UTC (rev 99339)
@@ -48,25 +48,33 @@
    public void deploy(DeploymentUnit unit, OSGiMetaData osgiMetaData) throws DeploymentException
    {
       super.deploy(unit, osgiMetaData);
-      
+
       // Return if this is not a bundle fragment 
       AbstractBundleState bundleState = unit.getAttachment(AbstractBundleState.class);
       if (bundleState.isFragment() == false)
          return;
-      
+
       OSGiClassLoadingMetaData classLoadingMetaData = (OSGiClassLoadingMetaData)unit.getAttachment(ClassLoadingMetaData.class);
-      
+
       // Initialize the Fragment-Host 
       ParameterizedAttribute hostAttr = osgiMetaData.getFragmentHost();
       FragmentHostMetaData fragmentHost = new FragmentHostMetaData(hostAttr.getAttribute());
       classLoadingMetaData.setFragmentHost(fragmentHost);
-      
+
       Parameter bundleVersionAttr = hostAttr.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE);
       if (bundleVersionAttr != null)
          fragmentHost.setBundleVersion((Version)bundleVersionAttr.getValue());
-      
+
       Parameter extensionDirective = hostAttr.getDirective(Constants.EXTENSION_DIRECTIVE);
       if (extensionDirective != null)
          fragmentHost.setExtension((String)extensionDirective.getValue());
+
+      // TODO Modify the CL metadata of the host such that eventually the CL policy
+      // contains a DelegateLoader for the attached fragment
+
+      // Adding the fragment as an OSGiBundleRequirement to the host does not work because 
+      // those requirements end up as DependencyItems already during the INSTALL phase. 
+      // Remember to do equivalent code in OSGiBundleClassLoadingDeployer
+      // in case the fragment gets installed before the host.
    }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java	2010-01-13 13:31:40 UTC (rev 99338)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java	2010-01-13 13:39:48 UTC (rev 99339)
@@ -317,11 +317,17 @@
    
    public void testAttributeRequireBundleFails() throws Exception
    {
+      // 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-Version: 1.0.0
       Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
       try
       {
          bundle1.start();
          assertLoadClass(bundle1, A.class);
+         
+         // Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+         // Require-Bundle: org.jboss.test.osgi.classloader.bundleA;doesnotexist=true;test=y
          Bundle bundle2 = installBundle(assembleBundle("attributerequirebundlefails", "/bundles/classloader/attributerequirebundlefails", B.class));
          try
          {

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java	2010-01-13 13:31:40 UTC (rev 99338)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java	2010-01-13 13:39:48 UTC (rev 99339)
@@ -307,14 +307,14 @@
 
          // Clarify error behaviour when fragments fail to attach
          // https://www.osgi.org/members/bugzilla/show_bug.cgi?id=1524
-         //
-         // Felix: Merges FragC Require-Bundle into HostA and fails to resolve
+         
          // Equinox: Resolves HostA but does not attach FragA
          if (hostA.getState() == Bundle.ACTIVE)
             assertBundleState(Bundle.INSTALLED, fragC.getState());
       }
       catch (BundleException ex)
       {
+         // Felix: Merges FragC's bundle requirement into HostA and fails to resolve
          assertBundleState(Bundle.INSTALLED, hostA.getState());
       }
 



More information about the jboss-osgi-commits mailing list