[jboss-osgi-commits] JBoss-OSGI SVN: r93308 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade: classloading and 1 other directory.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Wed Sep 9 06:32:15 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-09-09 06:32:15 -0400 (Wed, 09 Sep 2009)
New Revision: 93308

Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleCapability.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleRequirement.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageRequirement.java
Log:
[JBCL-24] Circular and self dependencies
Extended the Capability interface such that it allows capability/requirement matching in the context of both modules

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-09-09 10:29:32 UTC (rev 93307)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-09-09 10:32:15 UTC (rev 93308)
@@ -61,6 +61,7 @@
 import org.jboss.osgi.plugins.facade.api.PackageAdminServicePlugin;
 import org.jboss.osgi.plugins.facade.api.Plugin;
 import org.jboss.osgi.plugins.facade.api.ServicePlugin;
+import org.jboss.osgi.plugins.facade.classloading.OSGiPackageCapabilityCache;
 import org.jboss.osgi.plugins.filter.NoFilter;
 import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
 import org.jboss.osgi.spi.metadata.OSGiMetaData;
@@ -83,6 +84,7 @@
  * OSGiBundleManager.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
  * @version $Revision: 1.1 $
  */
 public class OSGiBundleManager
@@ -638,10 +640,12 @@
       ControllerState requiredState = context.getRequiredState();
       DeploymentStage requiredStage = unit.getRequiredStage();
       
+      OSGiPackageCapabilityCache capabilityCache = OSGiPackageCapabilityCache.getInstance(bundleState);
       try
       {
          deployerClient.change(unit.getName(), DeploymentStages.CLASSLOADER);
          deployerClient.checkComplete(unit.getName());
+         capabilityCache.commitPreliminaryMatches();
          bundleState.changeState(Bundle.RESOLVED);
          return true;
       }
@@ -650,6 +654,8 @@
          unit.setRequiredStage(requiredStage);
          context.setRequiredState(requiredState);
          
+         capabilityCache.rollbackPreliminaryMatches();
+         
          if (errorOnFail)
             throw new IllegalStateException("Error resolving bundle: " + bundleState, ex);
          

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleCapability.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleCapability.java	2009-09-09 10:29:32 UTC (rev 93307)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleCapability.java	2009-09-09 10:32:15 UTC (rev 93308)
@@ -37,6 +37,7 @@
  * 
  * todo BundlePermission/PROVIDE
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
  * @version $Revision: 1.1 $
  */
 public class OSGiBundleCapability extends ModuleCapability
@@ -92,9 +93,9 @@
    }
 
    @Override
-   public boolean resolves(Module module, Requirement requirement)
+   public boolean resolves(Module capModule, Module reqModule, Requirement requirement)
    {
-      if (super.resolves(module, requirement) == false)
+      if (super.resolves(capModule, reqModule, requirement) == false)
          return false;
       if (requirement instanceof OSGiBundleRequirement == false)
          return true;

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java	2009-09-09 10:29:32 UTC (rev 93307)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoadingDeployer.java	2009-09-09 10:32:15 UTC (rev 93308)
@@ -108,7 +108,7 @@
       {
          for (PackageAttribute packageAttribute : exported)
          {
-            OSGiPackageCapability packageCapability = OSGiPackageCapability.create(osgiMetaData, packageAttribute); 
+            OSGiPackageCapability packageCapability = OSGiPackageCapability.create(bundleState, packageAttribute); 
             capabilities.addCapability(packageCapability);
          }
       }

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleRequirement.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleRequirement.java	2009-09-09 10:29:32 UTC (rev 93307)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleRequirement.java	2009-09-09 10:32:15 UTC (rev 93308)
@@ -35,6 +35,7 @@
  * 
  * todo BundlePermission/REQUIRE
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
  * @version $Revision: 1.1 $
  */
 public class OSGiBundleRequirement extends ModuleRequirement
@@ -110,8 +111,8 @@
          return false;
       if (super.equals(obj) ==false)
          return false;
-      OSGiBundleRequirement other = (OSGiBundleRequirement) obj;
-      return getRequireBundle().equals(other.getRequireBundle());
+      
+      return true;
    }
 
    @Override

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java	2009-09-09 10:29:32 UTC (rev 93307)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java	2009-09-09 10:32:15 UTC (rev 93308)
@@ -28,6 +28,8 @@
 import org.jboss.classloading.spi.dependency.Module;
 import org.jboss.classloading.spi.metadata.Requirement;
 import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
 import org.jboss.osgi.plugins.metadata.AbstractVersionRange;
 import org.jboss.osgi.spi.metadata.OSGiMetaData;
 import org.jboss.osgi.spi.metadata.PackageAttribute;
@@ -43,19 +45,23 @@
  * todo uses
  * todo include/exclude
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
  * @version $Revision: 1.1 $
  */
 public class OSGiPackageCapability extends PackageCapability
 {
    /** The serialVersionUID */
-   private static final long serialVersionUID = 6047222760667029014L;
+   private static final long serialVersionUID = 3940667616588052822L;
+   
+   /** The log */
+   private static final Logger log = Logger.getLogger(OSGiPackageCapability.class);
+   
+   /** The bundle state */
+   private OSGiBundleState bundleState;
 
-   /** The metadata */
-   private OSGiMetaData metadata;
-
    /** The export package */
    private PackageAttribute exportPackage;
-   
+
    /** The mandatory attributes */
    private String[] mandatoryAttributes;
 
@@ -68,54 +74,44 @@
     * @throws IllegalArgumentException for null metadata
     */
    @SuppressWarnings("deprecation")
-   public static OSGiPackageCapability create(OSGiMetaData metadata, PackageAttribute exportPackage)
+   public static OSGiPackageCapability create(OSGiBundleState bundleState, PackageAttribute exportPackage)
    {
-      if (metadata == null)
-         throw new IllegalArgumentException("Null metadata");
+      if (bundleState == null)
+         throw new IllegalArgumentException("Null bundle");
 
       String name = exportPackage.getAttribute();
       String versionString = exportPackage.getParameterValue(Constants.VERSION_ATTRIBUTE, String.class);
-         
+
       String oldVersionString = exportPackage.getParameterValue(Constants.PACKAGE_SPECIFICATION_VERSION, String.class);
       if (oldVersionString != null)
       {
          if (versionString != null && versionString.equals(oldVersionString) == false)
-            throw new IllegalStateException(Constants.VERSION_ATTRIBUTE + " of " + versionString + " does not match " + Constants.PACKAGE_SPECIFICATION_VERSION + " of " + oldVersionString);
+            throw new IllegalStateException(Constants.VERSION_ATTRIBUTE + " of " + versionString + " does not match " + Constants.PACKAGE_SPECIFICATION_VERSION
+                  + " of " + oldVersionString);
          if (versionString == null)
             versionString = oldVersionString;
       }
-      
+
       Version version = null;
       if (versionString != null)
       {
          // Handle version strings with quotes 
          if (versionString.startsWith("\"") && versionString.endsWith("\""))
             versionString = versionString.substring(1, versionString.length() - 1);
-         
+
          version = Version.parseVersion(versionString);
       }
-      
-      OSGiPackageCapability capability = new OSGiPackageCapability(name, version, metadata, exportPackage);
+
+      OSGiPackageCapability capability = new OSGiPackageCapability(bundleState, name, version, exportPackage);
       capability.setSplitPackagePolicy(SplitPackagePolicy.First);
-      
+
       return capability;
    }
-   
-   /**
-    * Create a new OSGiPackageCapability.
-    * 
-    * @param name the name
-    * @param version the version pass null of the default version
-    * @param metadata the metadata
-    * @param exportPackage the export information
-    * @throws IllegalArgumentException for a null name metadata or exportPackage
-    */
-   public OSGiPackageCapability(String name, Version version, OSGiMetaData metadata, PackageAttribute exportPackage)
+
+   private OSGiPackageCapability(OSGiBundleState bundleState, String name, Version version, PackageAttribute exportPackage)
    {
       super(name, version);
-      if (metadata == null)
-         throw new IllegalArgumentException("Null metadata");
-      this.metadata = metadata;
+      this.bundleState = bundleState;
       this.exportPackage = exportPackage;
 
       String mandatory = exportPackage.getParameterValue(Constants.MANDATORY_DIRECTIVE, String.class);
@@ -133,77 +129,93 @@
       if (exportPackage.getParameter(Constants.BUNDLE_VERSION_ATTRIBUTE) != null)
          throw new IllegalStateException("You cannot specify " + Constants.BUNDLE_VERSION_ATTRIBUTE + " on an Export-Package");
    }
-   
-   /**
-    * Get the metadata.
-    * 
-    * @return the metadata.
-    */
-   public OSGiMetaData getMetaData()
-   {
-      return metadata;
-   }
 
+   @Override
    @SuppressWarnings("deprecation")
-   @Override
-   public boolean resolves(Module module, Requirement requirement)
+   public boolean resolves(Module capModule, Module reqModule, Requirement requirement)
    {
-      if (super.resolves(module, requirement) == false)
+      if (super.resolves(capModule, reqModule, requirement) == false)
          return false;
       if (requirement instanceof OSGiPackageRequirement == false)
          return true;
-      
-      OSGiPackageRequirement packageRequirement = (OSGiPackageRequirement) requirement;
-      OSGiMetaData metaData = getMetaData();
+
+      OSGiPackageRequirement packageRequirement = (OSGiPackageRequirement)requirement;
+      OSGiMetaData metaData = bundleState.getOSGiMetaData();
       PackageAttribute ourParameters = exportPackage;
       PackageAttribute otherParameters = packageRequirement.getRequirePackage();
+
+      OSGiPackageCapabilityCache capabilityCache = OSGiPackageCapabilityCache.getInstance(bundleState);
+      if (capabilityCache.isBlacklistedMatch(requirement, capModule))
+      {
+         log.debug("Blacklisted: " + requirement + " " + capModule);
+         return false;
+      }
+      
+      Module cachedModule = capabilityCache.getCachedMatch(requirement);
+      if (cachedModule == capModule)
+      {
+         log.debug("Cached: " + requirement + " " + capModule);
+         return true;
+      }
+      
+      boolean validMatch = true;
+
       // Check all the manadatory attributes are present
-      if (mandatoryAttributes != null)
+      if (validMatch == true && mandatoryAttributes != null)
       {
-         if (otherParameters == null)
-            return false;
-         
-         for (String mand : mandatoryAttributes)
+         if (otherParameters != null)
          {
-            if (otherParameters.getParameter(mand) == null)
-               return false;
+            for (String mand : mandatoryAttributes)
+            {
+               if (otherParameters.getParameter(mand) == null)
+               {
+                  validMatch = false;
+                  break;
+               }
+            }
          }
       }
-      if (otherParameters != null)
+
+      if (validMatch == true && otherParameters != null)
       {
          Map<String, Parameter> params = otherParameters.getParameters();
          if (params != null && params.isEmpty() == false)
          {
             for (String name : params.keySet())
             {
+               String otherValue = otherParameters.getParameterValue(name, String.class);
+               String ourValue = ourParameters.getParameterValue(name, String.class);
+
                // todo we shouldn't mix attributes and directives in the metadata
                if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(name))
                {
-                  String otherValue = otherParameters.getParameterValue(name, String.class);
-                  return otherValue.equals(metaData.getBundleSymbolicName());
+                  if (otherValue.equals(metaData.getBundleSymbolicName()) == false)
+                     validMatch = false;
                }
                else if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name))
                {
-                  String otherValue = otherParameters.getParameterValue(name, String.class);
-                  VersionRange range = (VersionRange) AbstractVersionRange.valueOf(otherValue);
-                  return range.isInRange(metaData.getBundleVersion());
+                  VersionRange range = (VersionRange)AbstractVersionRange.valueOf(otherValue);
+                  if (range.isInRange(metaData.getBundleVersion()) == false)
+                     validMatch = false;
                }
-               if (Constants.RESOLUTION_DIRECTIVE.equals(name) == false
-                && Constants.PACKAGE_SPECIFICATION_VERSION.equals(name) == false
-                && Constants.VERSION_ATTRIBUTE.equals(name) == false)
+               else if (Constants.RESOLUTION_DIRECTIVE.equals(name) == false 
+                     && Constants.PACKAGE_SPECIFICATION_VERSION.equals(name) == false
+                     && Constants.VERSION_ATTRIBUTE.equals(name) == false)
                {
-                  if (ourParameters == null)
-                     return false;
-                  String ourValue = ourParameters.getParameterValue(name, String.class);
-                  if (ourValue == null)
-                     return false;
-                  if (ourValue.equals(otherParameters.getParameterValue(name, String.class)) == false)
-                     return false;
+                  if (ourValue == null || ourValue.equals(otherValue) == false)
+                     validMatch = false;
                }
+               
+               if (validMatch == false)
+                  break;
             }
          }
       }
-      return true;
+      
+      if (validMatch == true && capModule == reqModule)
+         capabilityCache.addPreliminaryMatch(requirement, capModule);
+      
+      return validMatch;
    }
 
    @Override
@@ -213,16 +225,17 @@
          return true;
       if (obj == null || obj instanceof OSGiPackageCapability == false)
          return false;
-      if (super.equals(obj) ==false)
+      if (super.equals(obj) == false)
          return false;
-      OSGiPackageCapability other = (OSGiPackageCapability) obj;
-      return getMetaData().equals(other.getMetaData());
+      
+      return true;
    }
 
    @Override
    protected void toString(StringBuffer buffer)
    {
       super.toString(buffer);
+      OSGiMetaData metadata = bundleState.getOSGiMetaData();
       ParameterizedAttribute parameters = metadata.getBundleParameters();
       if (parameters != null)
       {

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java	2009-09-09 10:29:32 UTC (rev 93307)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java	2009-09-09 10:32:15 UTC (rev 93308)
@@ -25,38 +25,49 @@
 import java.util.Map;
 
 import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
 import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
 
 
 /**
- * [TODO] 
+ * A package capabilty cache that helps the OSGiPackageCapability to decide 
+ * if a given requirement matches against a capability in the context of both
+ * modules. 
  * 
  * @author Thomas.Diesler at jboss.com
  * @since 08-Sep-2009
  */
 public class OSGiPackageCapabilityCache
 {
-   // [TODO] remove static usage
-   private static OSGiPackageCapabilityCache cacheInstance;
-   
+   private OSGiBundleState bundleState;
    private Map<Requirement, Module> preliminaryMatches = new HashMap<Requirement, Module>();
    private Map<Requirement, Module> blacklistedMatches = new HashMap<Requirement, Module>();
    private Map<Requirement, Module> cachedMatches = new HashMap<Requirement, Module>();
 
-   private OSGiPackageCapabilityCache()
+   public static OSGiPackageCapabilityCache getInstance(OSGiBundleState bundleState)
    {
-      cacheInstance = this;
-   }
-   
-   public static OSGiPackageCapabilityCache getInstance()
-   {
+      DeploymentUnit unit = bundleState.getDeploymentUnit();
+      OSGiPackageCapabilityCache cacheInstance = unit.getAttachment(OSGiPackageCapabilityCache.class);
       if (cacheInstance == null)
       {
-         cacheInstance = new OSGiPackageCapabilityCache();
+         cacheInstance = new OSGiPackageCapabilityCache(bundleState);
+         unit.addAttachment(OSGiPackageCapabilityCache.class, cacheInstance);
       }
-      return cacheInstance; 
+      return cacheInstance;
    }
    
+   private OSGiPackageCapabilityCache(OSGiBundleState bundleState)
+   {
+      if (bundleState == null)
+         throw new IllegalArgumentException("Null bundle");
+      this.bundleState = bundleState;
+   }
+   
    public Module getCachedMatch(Requirement requirement)
    {
       return cachedMatches.get(requirement);
@@ -67,21 +78,32 @@
       preliminaryMatches.put(requirement, module);
    }
    
-   public boolean isValidMatch(Requirement requirement, Module module)
+   public boolean isBlacklistedMatch(Requirement requirement, Module module)
    {
       Module other = blacklistedMatches.get(requirement);
-      return module != other;
+      return module == other;
    }
    
-   public void storePreliminaryMatches()
+   public void commitPreliminaryMatches()
    {
       cachedMatches.putAll(preliminaryMatches);
       preliminaryMatches.clear();
    }
    
-   public void blacklistPreliminaryMatches()
+   public void rollbackPreliminaryMatches()
    {
       blacklistedMatches.putAll(preliminaryMatches);
       preliminaryMatches.clear();
+      
+      // Reset all resolved dependency items
+      // [JBKERNEL-54] DependencyItem inconsistency when multiple possible matches
+      DeploymentUnit unit = bundleState.getDeploymentUnit();
+      ControllerContext context = unit.getAttachment(ControllerContext.class);
+      DependencyInfo di = context.getDependencyInfo();
+      for (DependencyItem iDependOn : di.getIDependOn(RequirementDependencyItem.class))
+      {
+         if (iDependOn.isResolved())
+            iDependOn.unresolved(context.getController());
+      }
    }
 }

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageRequirement.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageRequirement.java	2009-09-09 10:29:32 UTC (rev 93307)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageRequirement.java	2009-09-09 10:32:15 UTC (rev 93308)
@@ -36,6 +36,7 @@
  *
  * todo PackagePermission/IMPORT
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
  * @version $Revision: 1.1 $
  */
 public class OSGiPackageRequirement extends PackageRequirement
@@ -120,8 +121,8 @@
          return false;
       if (super.equals(obj) == false)
          return false;
-      OSGiPackageRequirement other = (OSGiPackageRequirement)obj;
-      return getRequirePackage().equals(other.getRequirePackage());
+      
+      return true;
    }
 
    @Override



More information about the jboss-osgi-commits mailing list