You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by xa...@apache.org on 2008/02/06 08:05:59 UTC
svn commit: r618913 - in /ant/ivy/core/trunk:
src/java/org/apache/ivy/core/resolve/IvyNode.java
src/java/org/apache/ivy/plugins/resolver/ChainResolver.java
src/java/org/apache/ivy/util/StringUtils.java
test/java/org/apache/ivy/util/StringUtilsTest.java
Author: xavier
Date: Tue Feb 5 23:05:58 2008
New Revision: 618913
URL: http://svn.apache.org/viewvc?rev=618913&view=rev
Log:
improve ChainResolver error reporting
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/IvyNode.java
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java
ant/ivy/core/trunk/src/java/org/apache/ivy/util/StringUtils.java
ant/ivy/core/trunk/test/java/org/apache/ivy/util/StringUtilsTest.java
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/IvyNode.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/IvyNode.java?rev=618913&r1=618912&r2=618913&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/IvyNode.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/IvyNode.java Tue Feb 5 23:05:58 2008
@@ -53,6 +53,7 @@
import org.apache.ivy.plugins.matcher.MatcherHelper;
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.util.Message;
+import org.apache.ivy.util.StringUtils;
import org.apache.ivy.util.filter.Filter;
import org.apache.ivy.util.filter.FilterHelper;
@@ -903,15 +904,7 @@
}
public String getProblemMessage() {
- Exception e = problem;
- if (e == null) {
- return "";
- }
- String errMsg = e instanceof RuntimeException ? e.getMessage() : e.toString();
- if (errMsg == null || errMsg.length() == 0 || "null".equals(errMsg)) {
- errMsg = e.getClass().getName() + " at " + e.getStackTrace()[0].toString();
- }
- return errMsg;
+ return StringUtils.getErrorMessage(problem);
}
public boolean isDownloaded() {
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java?rev=618913&r1=618912&r2=618913&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java Tue Feb 5 23:05:58 2008
@@ -40,6 +40,7 @@
import org.apache.ivy.plugins.resolver.util.HasLatestStrategy;
import org.apache.ivy.plugins.resolver.util.ResolvedResource;
import org.apache.ivy.util.Message;
+import org.apache.ivy.util.StringUtils;
/**
*
@@ -123,7 +124,7 @@
mr = resolver.getDependency(dd, data);
} catch (Exception ex) {
Message.verbose("problem occured while resolving " + dd + " with " + resolver
- + ": " + ex);
+ + ": " + StringUtils.getStackTrace(ex));
errors.add(ex);
} finally {
if (oldLatest != null) {
@@ -178,7 +179,7 @@
StringBuffer err = new StringBuffer();
for (Iterator iter = errors.iterator(); iter.hasNext();) {
Exception ex = (Exception) iter.next();
- err.append(ex).append("\n");
+ err.append("\t").append(StringUtils.getErrorMessage(ex)).append("\n");
}
err.setLength(err.length() - 1);
throw new RuntimeException("several problems occured while resolving " + dd + ":\n"
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/StringUtils.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/StringUtils.java?rev=618913&r1=618912&r2=618913&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/StringUtils.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/StringUtils.java Tue Feb 5 23:05:58 2008
@@ -17,6 +17,8 @@
*/
package org.apache.ivy.util;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
import java.util.Locale;
/**
@@ -37,6 +39,46 @@
return string.toLowerCase(Locale.US);
}
return string.substring(0, 1).toLowerCase(Locale.US) + string.substring(1);
+ }
+
+ /**
+ * Returns the error message associated with the given exception. Th error message returned will
+ * try to be as precise as possible, handling cases where e.getMessage() is not meaningful, like
+ * {@link NullPointerException} for instance.
+ *
+ * @param e
+ * the exception to get the error message from
+ * @return the error message of the given exception
+ */
+ public static String getErrorMessage(Exception e) {
+ if (e == null) {
+ return "";
+ }
+ String errMsg = e instanceof RuntimeException ? e.getMessage() : e.toString();
+ if (errMsg == null || errMsg.length() == 0 || "null".equals(errMsg)) {
+ errMsg = e.getClass().getName() + " at " + e.getStackTrace()[0].toString();
+ }
+ return errMsg;
+ }
+
+ /**
+ * Returns the exception stack trace as a String.
+ *
+ * @param e
+ * the exception to get the stack trace from.
+ * @return the exception stack trace
+ */
+ public static String getStackTrace(Exception e) {
+ if (e == null) {
+ return "";
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintWriter printWriter = new PrintWriter(baos);
+ e.printStackTrace(printWriter);
+ printWriter.flush();
+ String stackTrace = new String(baos.toByteArray());
+ printWriter.close();
+ return stackTrace;
}
/**
Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/util/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/util/StringUtilsTest.java?rev=618913&r1=618912&r2=618913&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/util/StringUtilsTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/util/StringUtilsTest.java Tue Feb 5 23:05:58 2008
@@ -20,6 +20,15 @@
import junit.framework.TestCase;
public class StringUtilsTest extends TestCase {
+
+ public void testGetStackTrace() throws Exception {
+ String trace = StringUtils.getStackTrace(new Exception());
+ assertTrue(trace.indexOf(
+ "java.lang.Exception") != -1);
+ assertTrue(trace.indexOf(
+ "at org.apache.ivy.util.StringUtilsTest.testGetStackTrace(StringUtilsTest.java") != -1);
+ }
+
public void testEncryption() {
assertEquals("apache", StringUtils.decrypt(StringUtils.encrypt("apache")));
assertEquals("yet another string with 126 digits and others :;%_-$& characters",