aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cummi...@apache.org
Subject svn commit: r1062949 - in /aries/trunk/application: application-api/src/main/java/org/apache/aries/application/management/ application-api/src/main/java/org/apache/aries/application/modelling/ application-deployment-management/src/test/java/org/apache/...
Date Mon, 24 Jan 2011 20:01:50 GMT
Author: cumminsh
Date: Mon Jan 24 20:01:29 2011
New Revision: 1062949

URL: http://svn.apache.org/viewvc?rev=1062949&view=rev
Log:
ARIES-557: Extra methods (forward compatible) for richer information on ResolverException.

Modified:
    aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ResolverException.java
    aries/trunk/application/application-api/src/main/java/org/apache/aries/application/modelling/ModellingConstants.java
    aries/trunk/application/application-deployment-management/src/test/java/org/apache/aries/application/deployment/management/DeploymentGeneratorTest.java
    aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java

Modified: aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ResolverException.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ResolverException.java?rev=1062949&r1=1062948&r2=1062949&view=diff
==============================================================================
--- aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ResolverException.java
(original)
+++ aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/ResolverException.java
Mon Jan 24 20:01:29 2011
@@ -18,8 +18,12 @@
  */
 package org.apache.aries.application.management;
 
-import java.util.List;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.aries.application.modelling.ModellingConstants;
 
 /**
  * Exception thrown by the AriesApplicationResolver interface
@@ -27,7 +31,7 @@ import java.util.ArrayList;
 public class ResolverException extends Exception {
 
   private static final long serialVersionUID = 8176120468577397671L;
-  private List<String> _unsatisfiedRequirementMessages = new ArrayList<String>();
+  private Map<String, String> _unsatisfiedRequirementMessages = new HashMap<String,
String>();
   
   /**
    * Construct from an Exception
@@ -45,9 +49,22 @@ public class ResolverException extends E
   }
   
   public void setUnsatisfiedRequirements (List<String> reqts) { 
-    _unsatisfiedRequirementMessages = reqts;
+    // Assume the type is unknown if we don't get told it
+    for (String reqt : reqts)
+    {
+      _unsatisfiedRequirementMessages.put(reqt, ModellingConstants.OBR_UNKNOWN);
+    }
   }
   public List<String> getUnsatisfiedRequirements() { 
-    return _unsatisfiedRequirementMessages;
+    return new ArrayList<String>(_unsatisfiedRequirementMessages.keySet());
+  }
+
+  public void setUnsatisfiedRequirementsAndReasons(
+      Map<String, String> unsatisfiedRequirements) {
+    _unsatisfiedRequirementMessages = unsatisfiedRequirements;
+  }
+  
+  public Map<String, String> getUnsatisfiedRequirementsAndReasons() {
+      return _unsatisfiedRequirementMessages;
   }
 }

Modified: aries/trunk/application/application-api/src/main/java/org/apache/aries/application/modelling/ModellingConstants.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/modelling/ModellingConstants.java?rev=1062949&r1=1062948&r2=1062949&view=diff
==============================================================================
--- aries/trunk/application/application-api/src/main/java/org/apache/aries/application/modelling/ModellingConstants.java
(original)
+++ aries/trunk/application/application-api/src/main/java/org/apache/aries/application/modelling/ModellingConstants.java
Mon Jan 24 20:01:29 2011
@@ -29,5 +29,6 @@ public class ModellingConstants
   public static final String OBR_PACKAGE = "package";
   public static final String OBR_SERVICE = "service";
   public static final String OBR_COMPOSITE_BUNDLE = "composite-bundle";
+  public static final String OBR_UNKNOWN = "unknown";
   public static final String OPTIONAL_KEY = Constants.RESOLUTION_DIRECTIVE + ":";
 }

Modified: aries/trunk/application/application-deployment-management/src/test/java/org/apache/aries/application/deployment/management/DeploymentGeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-deployment-management/src/test/java/org/apache/aries/application/deployment/management/DeploymentGeneratorTest.java?rev=1062949&r1=1062948&r2=1062949&view=diff
==============================================================================
--- aries/trunk/application/application-deployment-management/src/test/java/org/apache/aries/application/deployment/management/DeploymentGeneratorTest.java
(original)
+++ aries/trunk/application/application-deployment-management/src/test/java/org/apache/aries/application/deployment/management/DeploymentGeneratorTest.java
Mon Jan 24 20:01:29 2011
@@ -362,7 +362,7 @@ public class DeploymentGeneratorTest
       // Get the unsatisfied Requirements
       List<String> unsatisfiedReqs = rx.getUnsatisfiedRequirements();
       // Ensure we've got 4 unsatisfied Requirements
-      assertEquals ("4 unsatisfied requirements expected, not " + unsatisfiedReqs.size(),
unsatisfiedReqs.size(), 4);
+      assertEquals ("4 unsatisfied requirements expected, but got " + Arrays.toString(unsatisfiedReqs.toArray()),
4, unsatisfiedReqs.size());
       List<String> checkMessages = new ArrayList<String>();
       // Now load an array with the expected messages.
       checkMessages.add("Shared bundle test.shared1_1.0.0 has a dependency for package test.isolated1
which " +

Modified: aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java?rev=1062949&r1=1062948&r2=1062949&view=diff
==============================================================================
--- aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java
(original)
+++ aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java
Mon Jan 24 20:01:29 2011
@@ -197,21 +197,16 @@ public class OBRAriesResolver implements
       // let's refine the list by removing the indirect unsatisfied bundles that are caused
by unsatisfied packages or other bundles
       Map<String,Set<String>> refinedReqs = refineUnsatisfiedRequirements(obrResolver,
reasons);
       StringBuffer reqList = new StringBuffer();
-      List<String> unsatisfiedRequirements = new LinkedList<String>();
-
-      for (Map.Entry<String, Set<String>> filterEntry : refinedReqs.entrySet())
{
-        log.debug("unable to satisfy the filter , filter = " + filterEntry.getKey() + "required
by "+filterEntry.getValue());
-       
-        String reason = extractConsumableMessageInfo(filterEntry.getKey(),filterEntry.getValue());
+      Map<String, String> unsatisfiedRequirements = extractConsumableMessageInfo(refinedReqs);
 
+      for (String reason : unsatisfiedRequirements.values()) {
         reqList.append('\n');
         reqList.append(reason);
-        unsatisfiedRequirements.add(reason);
       }
 
       ResolverException re = new ResolverException(MessageUtil.getMessage("RESOLVER_UNABLE_TO_RESOLVE",

           new Object[] { appName, reqList }));
-      re.setUnsatisfiedRequirements(unsatisfiedRequirements);
+      re.setUnsatisfiedRequirementsAndReasons(unsatisfiedRequirements);
       log.debug(LOG_EXIT, "resolve", re);
       
       throw re;
@@ -307,21 +302,16 @@ public class OBRAriesResolver implements
       //refine the list by removing the indirect unsatisfied bundles that are caused by unsatisfied
packages or other bundles
       Map<String,Set<String>> refinedReqs = refineUnsatisfiedRequirements(obrResolver,
reasons);
       StringBuffer reqList = new StringBuffer();
-      List<String> unsatisfiedRequirements = new LinkedList<String>();
-
-      for (Map.Entry<String, Set<String>> filterEntry : refinedReqs.entrySet())
{
-        log.debug("unable to satisfied the filter , filter = " + filterEntry.getKey() + "required
by "+filterEntry.getValue());
-       
-        String reason = extractConsumableMessageInfo(filterEntry.getKey(),filterEntry.getValue());
+      Map<String, String> unsatisfiedRequirements = extractConsumableMessageInfo(refinedReqs);
 
+      for (String reason : unsatisfiedRequirements.values()) {
         reqList.append('\n');
         reqList.append(reason);
-        unsatisfiedRequirements.add(reason);
       }
 
       ResolverException re = new ResolverException(MessageUtil.getMessage("RESOLVER_UNABLE_TO_RESOLVE",

           new Object[] { app.getApplicationMetadata().getApplicationName(), reqList }));
-      re.setUnsatisfiedRequirements(unsatisfiedRequirements);
+      re.setUnsatisfiedRequirementsAndReasons(unsatisfiedRequirements);
       log.debug(LOG_EXIT, "resolve", re);
       
       throw re;
@@ -528,71 +518,92 @@ public class OBRAriesResolver implements
    * @param bundlesFailing For problems with a bundle, the set of bundles that have a problem
    * @return human readable form
    */
-  private String extractConsumableMessageInfo(String filter, Set<String> bundlesFailing)
-  {
-    log.debug(LOG_ENTRY, "extractConsumableMessageInfo", new Object[] {filter, bundlesFailing});
-    
-    Map<String, String> attrs = ManifestHeaderProcessor.parseFilter(filter);
-    Map<String, String> customAttrs = new HashMap<String, String>();
-    for (Map.Entry<String, String> e : attrs.entrySet()) {
-      if (!SPECIAL_FILTER_ATTRS.contains(e.getKey())) {
-        customAttrs.put(e.getKey(), e.getValue());
+  private Map<String, String> extractConsumableMessageInfo(
+      Map<String, Set<String>> refinedReqs) {
+    log.debug(LOG_ENTRY, "extractConsumableMessageInfo", refinedReqs);
+
+    Map<String, String> unsatisfiedRequirements = new HashMap<String, String>();
+
+    for (Map.Entry<String, Set<String>> filterEntry : refinedReqs.entrySet())
{
+
+      String filter = filterEntry.getKey();
+      Set<String> bundlesFailing = filterEntry.getValue();
+
+      log.debug("unable to satisfy the filter , filter = "
+          + filter + "required by " + Arrays.toString(bundlesFailing.toArray()));
+
+      Map<String, String> attrs = ManifestHeaderProcessor.parseFilter(filter);
+      Map<String, String> customAttrs = new HashMap<String, String>();
+      for (Map.Entry<String, String> e : attrs.entrySet()) {
+        if (!SPECIAL_FILTER_ATTRS.contains(e.getKey())) {
+          customAttrs.put(e.getKey(), e.getValue());
+        }
       }
-    }
 
-    StringBuilder msgKey = new StringBuilder();
-    List<Object> inserts = new ArrayList<Object>();
-
-    boolean unknownType = false;
-    if (attrs.containsKey(ModellingConstants.OBR_PACKAGE)) {
-      msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_PACKAGE");
-      inserts.add(attrs.get(ModellingConstants.OBR_PACKAGE));
-    } else if (attrs.containsKey(ModellingConstants.OBR_SYMBOLIC_NAME)) {
-      msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_BUNDLE");
-      inserts.add(attrs.get(ModellingConstants.OBR_SYMBOLIC_NAME));
-    } else if (attrs.containsKey(ModellingConstants.OBR_SERVICE)) {
-      msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_SERVICE");
-      //No insert for service name as the name must be "*" to match any Service capability
-    } else {
-      unknownType = true;
-      msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_FILTER");
-      inserts.add(filter);
-    }
-
-    if (bundlesFailing != null && bundlesFailing.size() != 0) {
-      msgKey.append("_REQUIRED_BY_BUNDLE");
-      if (bundlesFailing.size() == 1)
-        inserts.add(bundlesFailing.iterator().next()); // Just take the string if there's
only one of them
-      else
-        inserts.add(bundlesFailing.toString()); // Add the whole set if there isn't exactly
one
-    }
-    if (!unknownType && !customAttrs.isEmpty()) {
-      msgKey.append("_WITH_ATTRS");
-      inserts.add(customAttrs);
-    }
-
-    if (!unknownType && attrs.containsKey(Constants.VERSION_ATTRIBUTE)) {
-      msgKey.append("_WITH_VERSION");
-      VersionRange vr = ManifestHeaderProcessor.parseVersionRange(attrs
-          .get(Constants.VERSION_ATTRIBUTE));
-      inserts.add(vr.getMinimumVersion());
-
-      if (!!!vr.isExactVersion()) {
-        msgKey.append(vr.isMinimumExclusive() ? "_LOWEX" : "_LOW");
-        if (vr.getMaximumVersion() != null) {
-          msgKey.append(vr.isMaximumExclusive() ? "_UPEX" : "_UP");
-          inserts.add(vr.getMaximumVersion());
+      StringBuilder msgKey = new StringBuilder();
+      List<Object> inserts = new ArrayList<Object>();
+
+      final String type;
+      boolean unknownType = false;
+      if (attrs.containsKey(ModellingConstants.OBR_PACKAGE)) {
+        type = ModellingConstants.OBR_PACKAGE;
+        msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_PACKAGE");
+        inserts.add(attrs.get(ModellingConstants.OBR_PACKAGE));
+      } else if (attrs.containsKey(ModellingConstants.OBR_SYMBOLIC_NAME)) {
+        type = ModellingConstants.OBR_SYMBOLIC_NAME;
+        msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_BUNDLE");
+        inserts.add(attrs.get(ModellingConstants.OBR_SYMBOLIC_NAME));
+      } else if (attrs.containsKey(ModellingConstants.OBR_SERVICE)) {
+        type = ModellingConstants.OBR_SERVICE;
+        msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_SERVICE");
+        // No insert for service name as the name must be "*" to match any
+        // Service capability
+      } else {
+        type = ModellingConstants.OBR_UNKNOWN;
+        unknownType = true;
+        msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_FILTER");
+        inserts.add(filter);
+      }
+
+      if (bundlesFailing != null && bundlesFailing.size() != 0) {
+        msgKey.append("_REQUIRED_BY_BUNDLE");
+        if (bundlesFailing.size() == 1)
+          inserts.add(bundlesFailing.iterator().next()); // Just take the string
+                                                         // if there's only one
+                                                         // of them
+        else
+          inserts.add(bundlesFailing.toString()); // Add the whole set if there
+                                                  // isn't exactly one
+      }
+      if (!unknownType && !customAttrs.isEmpty()) {
+        msgKey.append("_WITH_ATTRS");
+        inserts.add(customAttrs);
+      }
+
+      if (!unknownType && attrs.containsKey(Constants.VERSION_ATTRIBUTE)) {
+        msgKey.append("_WITH_VERSION");
+        VersionRange vr = ManifestHeaderProcessor.parseVersionRange(attrs
+            .get(Constants.VERSION_ATTRIBUTE));
+        inserts.add(vr.getMinimumVersion());
+
+        if (!!!vr.isExactVersion()) {
+          msgKey.append(vr.isMinimumExclusive() ? "_LOWEX" : "_LOW");
+          if (vr.getMaximumVersion() != null) {
+            msgKey.append(vr.isMaximumExclusive() ? "_UPEX" : "_UP");
+            inserts.add(vr.getMaximumVersion());
+          }
         }
       }
+
+      String msgKeyStr = msgKey.toString();
+
+      String msg = MessageUtil.getMessage(msgKeyStr, inserts.toArray());
+      unsatisfiedRequirements.put(msg, type);
     }
 
-    String msgKeyStr = msgKey.toString();
-    
-    String msg = MessageUtil.getMessage(msgKeyStr, inserts.toArray());
+    log.debug(LOG_EXIT, "extractConsumableMessageInfo", unsatisfiedRequirements);
 
-    log.debug(LOG_EXIT, "extractConsumableMessageInfo", msg);
-    
-    return msg;
+    return unsatisfiedRequirements;
   }
   
   /**



Mime
View raw message