Merge pull request #10 from bosschaert/SLING-9496

SLING-9496 Dead code in the API Regions runtime
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
index af0374f..d6a1881 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
@@ -29,6 +29,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.logging.Level;
+import java.util.stream.Collectors;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Version;
@@ -151,9 +152,15 @@
         // Remove any capabilities that are not covered
         candidates.retainAll(coveredCaps.keySet());
 
+        Level logLevel;
         if (candidates.isEmpty()) {
-            removedCandidates.removeAll(candidates);
+            logLevel = Level.WARNING;
+        } else {
+            logLevel = Level.INFO;
+        }
+        removedCandidates.removeAll(candidates);
 
+        if (!removedCandidates.isEmpty()) {
             StringBuilder sb = new StringBuilder();
             boolean first = true;
             for (BundleCapability bc : removedCandidates) {
@@ -171,7 +178,7 @@
                 sb.append("]");
             }
 
-            Activator.LOG.log(Level.WARNING,
+            Activator.LOG.log(logLevel,
                     "API-Regions removed candidates {0} for requirement {1} as the requirement is in the following regions: {2} and in feature: {3}",
                     new Object[] {sb, requirement, reqRegions, reqFeatures});
         }
@@ -226,8 +233,14 @@
         // There are specific capabilities, therefore we should remove the Global region is any from the capabilities
         // We have collected the capabilities we want to keep in specificCaps
         for (Iterator<BundleCapability> it = capMap.keySet().iterator(); it.hasNext(); ) {
-            if (!specificCaps.contains(it.next())) {
+            BundleCapability cap = it.next();
+            if (!specificCaps.contains(cap)) {
                 it.remove();
+                Activator.LOG.log(Level.INFO, "Removing candidate {0} which is in region {1} as more specific candidates are available in regions {2}",
+                        new Object[] {
+                                cap, capMap.get(cap),
+                                specificCaps.stream().map(c -> "" + c + " region " + capMap.get(c)).collect(Collectors.joining("/"))
+                        });
             }
         }
     }