[jboss-osgi-commits] JBoss-OSGI SVN: r93312 - projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Wed Sep 9 09:31:20 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-09-09 09:31:19 -0400 (Wed, 09 Sep 2009)
New Revision: 93312

Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
Log:
Add more debugging

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 12:04:45 UTC (rev 93311)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java	2009-09-09 13:31:19 UTC (rev 93312)
@@ -21,8 +21,11 @@
 */
 package org.jboss.osgi.plugins.facade.classloading;
 
+// $Id: $
+
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import org.jboss.classloading.spi.dependency.Module;
 import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
@@ -31,9 +34,9 @@
 import org.jboss.dependency.spi.DependencyInfo;
 import org.jboss.dependency.spi.DependencyItem;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
 import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
 
-
 /**
  * A package capabilty cache that helps the OSGiPackageCapability to decide 
  * if a given requirement matches against a capability in the context of both
@@ -44,6 +47,9 @@
  */
 public class OSGiPackageCapabilityCache
 {
+   /** The log */
+   private static final Logger log = Logger.getLogger(OSGiPackageCapabilityCache.class);
+   
    private OSGiBundleState bundleState;
    private Map<Requirement, Module> preliminaryMatches = new HashMap<Requirement, Module>();
    private Map<Requirement, Module> blacklistedMatches = new HashMap<Requirement, Module>();
@@ -75,35 +81,75 @@
    
    public void addPreliminaryMatch(Requirement requirement, Module module)
    {
-      preliminaryMatches.put(requirement, module);
+      if (preliminaryMatches.containsKey(requirement) == false)
+      {
+         log.debug("Add " + requirement + " " + getModuleName(module));
+         preliminaryMatches.put(requirement, module);
+      }
    }
    
    public boolean isBlacklistedMatch(Requirement requirement, Module module)
    {
       Module other = blacklistedMatches.get(requirement);
-      return module == other;
+      boolean blacklisted = (module == other);
+      if (blacklisted)
+         log.info("Blacklisted " + requirement + " " + getModuleName(module));
+      
+      return blacklisted;
    }
    
    public void commitPreliminaryMatches()
    {
+      log.info(getLogMessage("Commit preliminary matches", preliminaryMatches));
       cachedMatches.putAll(preliminaryMatches);
       preliminaryMatches.clear();
    }
-   
+
    public void rollbackPreliminaryMatches()
    {
+      log.info(getLogMessage("Rollback preliminary matches", preliminaryMatches));
       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();
+      
+      StringBuffer message = new StringBuffer("Unresolved requirements: ");
       for (DependencyItem iDependOn : di.getIDependOn(RequirementDependencyItem.class))
       {
+         // Reset all resolved dependency items
+         // [JBKERNEL-54] DependencyItem inconsistency when multiple possible matches
          if (iDependOn.isResolved())
+         {
             iDependOn.unresolved(context.getController());
+         }
+         else
+         {
+            RequirementDependencyItem reqdi = (RequirementDependencyItem)iDependOn;
+            Requirement unresolved = reqdi.getRequirement();
+            message.append("\n  " + unresolved);
+         }
       }
+      
+      // Log all unresolved dependency items
+      log.info(message);
    }
+
+   private String getLogMessage(String message, Map<Requirement, Module> matches)
+   {
+      StringBuffer buffer = new StringBuffer(message);
+      for (Entry<Requirement, Module> entry : matches.entrySet())
+      {
+         Requirement requirement = entry.getKey();
+         Module module = entry.getValue();
+         buffer.append("\n  " + requirement + " " + getModuleName(module));
+      }
+      return buffer.toString();
+   }
+
+   private String getModuleName(Module module)
+   {
+      return module.getName() + ":" + module.getVersion();
+   }
 }



More information about the jboss-osgi-commits mailing list