felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r1589774 - in /felix/trunk/resolver/src/main/java/org/apache/felix/resolver: Logger.java ResolverImpl.java
Date Thu, 24 Apr 2014 15:49:47 GMT
Author: rickhall
Date: Thu Apr 24 15:49:46 2014
New Revision: 1589774

URL: http://svn.apache.org/r1589774
Log:
Apply patch FELIX-4492 to improve logging and diagnostics.

Modified:
    felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Logger.java
    felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java

Modified: felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Logger.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Logger.java?rev=1589774&r1=1589773&r2=1589774&view=diff
==============================================================================
--- felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Logger.java (original)
+++ felix/trunk/resolver/src/main/java/org/apache/felix/resolver/Logger.java Thu Apr 24 15:49:46
2014
@@ -18,6 +18,10 @@
  */
 package org.apache.felix.resolver;
 
+import org.osgi.resource.Resource;
+
+import org.osgi.service.resolver.ResolutionException;
+
 /**
  * <p>
  * This class mimics the standard OSGi <tt>LogService</tt> interface. An
@@ -46,10 +50,6 @@ public class Logger
 
     private int m_logLevel = 1;
 
-    private final static int LOGGER_OBJECT_IDX = 0;
-    private final static int LOGGER_METHOD_IDX = 1;
-    private Object[] m_logger = null;
-
     public Logger(int i)
     {
         m_logLevel = i;
@@ -77,6 +77,10 @@ public class Logger
 
     protected void doLog(int level, String msg, Throwable throwable)
     {
+    	if (level > m_logLevel)
+    	{
+    		return;
+    	}
         String s = "";
         s = s + msg;
         if (throwable != null)
@@ -110,13 +114,13 @@ public class Logger
         int level,
         String msg, Throwable throwable)
     {
-        // Save our own copy just in case it changes. We could try to do
-        // more conservative locking here, but let's be optimistic.
-        Object[] logger = m_logger;
-
         if (m_logLevel >= level)
         {
             doLog(level, msg, throwable);
         }
     }
+
+    public void logUsesConstraintViolation(Resource resource, ResolutionException error)
{
+        // do nothing by default
+    }
 }

Modified: felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java?rev=1589774&r1=1589773&r2=1589774&view=diff
==============================================================================
--- felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java (original)
+++ felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java Thu Apr
24 15:49:46 2014
@@ -214,7 +214,7 @@ public class ResolverImpl implements Res
                     }
                 }
 
-                Collection<Resource> faultyResources = null;
+                Map<Resource, ResolutionException> faultyResources = null;
                 do
                 {
                     rethrow = null;
@@ -230,7 +230,7 @@ public class ResolverImpl implements Res
                         ? usesPermutations.remove(0)
                         : importPermutations.remove(0);
 //allCandidates.dump();
-                    Collection<Resource> currentFaultyResources = null;
+                    Map<Resource, ResolutionException> currentFaultyResources = null;
                     // Reuse a resultCache map for checking package consistency
                     // for all resources.
                     Map<Resource, Object> resultCache =
@@ -266,9 +266,20 @@ public class ResolverImpl implements Res
                         {
                             rethrow = ex;
                             if (currentFaultyResources == null) {
-                            	currentFaultyResources = new ArrayList();
+                            	currentFaultyResources = new HashMap<Resource, ResolutionException>();
                             }
-                           	currentFaultyResources.add(resource);
+                            Resource faultyResource = resource;
+                            // check that the faulty requirement is not from a fragment
+                            for (Requirement faultyReq : ex.getUnresolvedRequirements())
{
+                            	if (faultyReq instanceof WrappedRequirement)
+                                {
+                                    faultyResource =
+                                        ((WrappedRequirement) faultyReq)
+                                        .getDeclaredRequirement().getResource();
+                                    break;
+                            	}
+                            }
+                            currentFaultyResources.put(faultyResource, ex);
                         }
                     }
                     if (currentFaultyResources != null) {
@@ -290,7 +301,12 @@ public class ResolverImpl implements Res
                 if (rethrow != null)
                 {
                     if (faultyResources != null) {
-                        retry = (optionalResources.removeAll(faultyResources) || ondemandFragments.removeAll(faultyResources));
+                    	Set<Resource> resourceKeys = faultyResources.keySet();
+                        retry = (optionalResources.removeAll(resourceKeys) || ondemandFragments.removeAll(resourceKeys));
+                        // log all the resolution exceptions for the uses constraint violations
+                        for (Map.Entry<Resource, ResolutionException> usesError : faultyResources.entrySet())
{
+    						m_logger.logUsesConstraintViolation(usesError.getKey(), usesError.getValue());
+    					}
                     }
                     if (!retry) {
                         throw rethrow;



Mime
View raw message