MANIFEST.MF : added apache commons exception package for use in messaging utils
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 29 May 2015 16:33:14 +0000 (18:33 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 29 May 2015 16:33:14 +0000 (18:33 +0200)
MessagingUtils : updated to add all causes in the child statuses

eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java

index a1f584654a8e6045c67fb8596890414f5d357434..b7db5899afaa8ccb51971ef692b17aff93e536e2 100644 (file)
@@ -195,6 +195,7 @@ Export-Package: com.google.api,
  org.apache.commons.collections;uses:="org.apache.commons.collections.keyvalue,new org.apache.commons.collections",
  org.apache.commons.io;uses:="org.apache.commons.io.filefilter",
  org.apache.commons.lang;uses:="org.apache.commons.lang.exception",
+ org.apache.commons.lang.exception,
  org.apache.fop.apps,
  org.apache.http,
  org.apache.http.client,
index e44ad8f82ec17ebc7152a31cf7070174096f8df1..54c8d498fcf6fc7592ed088d6e8f3cdd9e6b071f 100644 (file)
@@ -5,6 +5,7 @@ import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
@@ -293,21 +294,36 @@ public class MessagingUtils {
             throwable = getDefaultThrowable();
         }
 
-        // add main execption
-        for (StackTraceElement ste : throwable.getStackTrace()) {
-            childStatuses.add(new Status(IStatus.ERROR, pluginId, "at " + ste.toString()));
-        }
+        int thCount = 0;
+        int maxTraces = 4;
 
-        // add cause
-        if(throwable.getCause() != null) {
-            childStatuses.add(new Status(IStatus.ERROR, pluginId, ""));
-            childStatuses.add(new Status(IStatus.ERROR, pluginId, "Caused by : " + throwable.getCause().toString()));
-            for (StackTraceElement ste : throwable.getCause().getStackTrace()) {
-                // build & add status
-                childStatuses.add(new Status(IStatus.ERROR, pluginId, "at " + ste.toString()));
+        for(Throwable th : ExceptionUtils.getThrowables(throwable)) {
+            // add main exception
+            if(thCount == 0) {
+                for (StackTraceElement ste : th.getStackTrace()) {
+                    childStatuses.add(new Status(IStatus.ERROR, pluginId, "  at " + ste.toString()));
+                }
+            } else {
+                // add recursive causes
+                if(th != null) {
+                    childStatuses.add(new Status(IStatus.ERROR, pluginId, ""));
+                    String msg = th.toString();
+                    childStatuses.add(new Status(IStatus.ERROR, pluginId, "Caused by : " + msg));
+                    int traceCount = 0;
+                    for (StackTraceElement ste : th.getStackTrace()) {
+                        // add only pre-defined number of trace elements
+                        if(traceCount > maxTraces) {
+                            childStatuses.add(new Status(IStatus.ERROR, pluginId, "  ...."));
+                            break;
+                        }
+                        // build & add status
+                        childStatuses.add(new Status(IStatus.ERROR, pluginId, "  at " + ste.toString()));
+                        traceCount++;
+                    }
+                }
             }
+            thCount++;
         }
-
         String finalMessage = message;
 
         if(finalMessage == null || finalMessage.isEmpty()) {