ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [4/6] ant git commit: embrace StringUtils#getStackTrace
Date Wed, 21 Dec 2016 19:12:01 GMT
embrace StringUtils#getStackTrace


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/008f1c8b
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/008f1c8b
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/008f1c8b

Branch: refs/heads/1.9.x
Commit: 008f1c8be554f9ed8928fdf6596a6c6c3fa5b063
Parents: 4cecc03
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Wed Dec 21 19:57:36 2016 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Wed Dec 21 20:02:49 2016 +0100

----------------------------------------------------------------------
 src/main/org/apache/tools/ant/AntClassLoader.java             | 7 ++++---
 src/main/org/apache/tools/ant/taskdefs/Classloader.java       | 3 ++-
 src/main/org/apache/tools/ant/taskdefs/Java.java              | 7 ++-----
 src/main/org/apache/tools/ant/taskdefs/KeySubst.java          | 4 +++-
 src/main/org/apache/tools/ant/taskdefs/SubAnt.java            | 4 ++--
 src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java       | 3 ++-
 .../apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java | 4 ++--
 .../apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java   | 3 ++-
 .../org/apache/tools/ant/taskdefs/optional/image/Image.java   | 3 ++-
 .../tools/ant/taskdefs/optional/junit/FailureRecorder.java    | 3 ++-
 .../apache/tools/ant/taskdefs/optional/junit/JUnitTask.java   | 3 ++-
 src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java  | 4 ----
 12 files changed, 25 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/AntClassLoader.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java
index 96b92fc..9fa9eae 100644
--- a/src/main/org/apache/tools/ant/AntClassLoader.java
+++ b/src/main/org/apache/tools/ant/AntClassLoader.java
@@ -49,6 +49,7 @@ import org.apache.tools.ant.util.CollectionUtils;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.JavaEnvUtils;
 import org.apache.tools.ant.util.LoaderUtils;
+import org.apache.tools.ant.util.StringUtils;
 import org.apache.tools.ant.util.VectorSet;
 import org.apache.tools.zip.ZipLong;
 
@@ -401,6 +402,8 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener,
Clo
     protected void log(final String message, final int priority) {
         if (project != null) {
             project.log(message, priority);
+        } else if (priority < Project.MSG_INFO) {
+            System.err.println(message);
         }
     }
 
@@ -1020,7 +1023,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener,
Clo
                             final String msg = "CLASSPATH element " + file
                                 + " is not a JAR.";
                             log(msg, Project.MSG_WARN);
-                            System.err.println(msg);
                             return null;
                         }
                         jarFile = new JarFile(file);
@@ -1043,8 +1045,7 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener,
Clo
         } catch (final Exception e) {
             final String msg = "Unable to obtain resource from " + file + ": ";
             log(msg + e, Project.MSG_WARN);
-            System.err.println(msg);
-            e.printStackTrace();
+            log(StringUtils.getStackTrace(e), Project.MSG_WARN);
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/Classloader.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Classloader.java b/src/main/org/apache/tools/ant/taskdefs/Classloader.java
index 8a5967c..99d47a1 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Classloader.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Classloader.java
@@ -27,6 +27,7 @@ import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * EXPERIMENTAL
@@ -238,7 +239,7 @@ public class Classloader extends Task {
             // TODO add exceptions
 
         } catch (Exception ex) {
-            ex.printStackTrace();
+            log(StringUtils.getStackTrace(ex), Project.MSG_ERR);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/Java.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Java.java b/src/main/org/apache/tools/ant/taskdefs/Java.java
index ffe92cf..ed9f906 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Java.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Java.java
@@ -40,6 +40,7 @@ import org.apache.tools.ant.types.PropertySet;
 import org.apache.tools.ant.types.RedirectorElement;
 import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.util.KeepAliveInputStream;
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * Launcher for Java applications. Allows use of
@@ -997,11 +998,7 @@ public class Java extends Task {
      * @since 1.6.2
      */
     private void log(Throwable t) {
-        StringWriter sw = new StringWriter();
-        PrintWriter w = new PrintWriter(sw);
-        t.printStackTrace(w);
-        w.close();
-        log(sw.toString(), Project.MSG_ERR);
+        log(StringUtils.getStackTrace(t), Project.MSG_ERR);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/KeySubst.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/KeySubst.java b/src/main/org/apache/tools/ant/taskdefs/KeySubst.java
index 28d46b9..64fbf7c 100644
--- a/src/main/org/apache/tools/ant/taskdefs/KeySubst.java
+++ b/src/main/org/apache/tools/ant/taskdefs/KeySubst.java
@@ -28,8 +28,10 @@ import java.util.Hashtable;
 import java.util.StringTokenizer;
 
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * Keyword substitution. Input file is written to output file.
@@ -80,7 +82,7 @@ public class KeySubst extends Task {
             }
             bw.flush();
         } catch (IOException ioe) {
-            ioe.printStackTrace();
+            log(StringUtils.getStackTrace(ioe), Project.MSG_ERR);
         } finally {
             FileUtils.close(bw);
             FileUtils.close(br);

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java
index 35109fa..c374d83 100644
--- a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java
+++ b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java
@@ -34,7 +34,7 @@ import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.PropertySet;
 import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.types.ResourceCollection;
-
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * Calls a given target for all defined sub-builds. This is an extension
@@ -255,7 +255,7 @@ public class SubAnt extends Task {
                     log("Target '" + file
                         + "' failed with message '"
                         + thrownException.getMessage() + "'.", Project.MSG_ERR);
-                    thrownException.printStackTrace(System.err);
+                    log(StringUtils.getStackTrace(thrownException), Project.MSG_ERR);
                     if (buildException == null) {
                         buildException =
                             new BuildException(thrownException);

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
index 2e2f005..7544592 100644
--- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
+++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
@@ -58,6 +58,7 @@ import org.apache.tools.ant.util.ClasspathUtils;
 import org.apache.tools.ant.util.FileNameMapper;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.ResourceUtils;
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * Processes a set of XML documents via XSLT. This is
@@ -952,7 +953,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
                 try {
                     resolveProcessor(PROCESSOR_TRAX);
                 } catch (final Throwable e1) {
-                    e1.printStackTrace();
+                    log(StringUtils.getStackTrace(e1), Project.MSG_ERR);
                     handleError(e1);
                 }
             }

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java
index cda13a5..350d673 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java
@@ -30,7 +30,7 @@ import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Execute;
 import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
 import org.apache.tools.ant.types.Commandline;
-
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * Creates new Continuus ccm task and sets it as the default.
@@ -322,7 +322,7 @@ public class CCMCreateTask extends Continuus implements ExecuteStreamHandler
{
             } // end of if ()
         } catch (NullPointerException npe) {
             log("error procession stream , null pointer exception", Project.MSG_ERR);
-            npe.printStackTrace();
+            log(StringUtils.getStackTrace(npe), Project.MSG_ERR);
             throw new BuildException(npe.getClass().getName());
         } catch (Exception e) {
             log("error procession stream " + e.getMessage(), Project.MSG_ERR);

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
index f9c2ef1..76b61ae 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
@@ -43,6 +43,7 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * Compiles EJB stubs and skeletons for the iPlanet Application
@@ -443,7 +444,7 @@ public class IPlanetEjbc {
             p.destroy();
         } catch (IOException e) {
             log("An IOException has occurred while trying to execute ejbc.");
-            e.printStackTrace();
+            log(StringUtils.getStackTrace(e));
         } catch (InterruptedException e) {
             // Do nothing
         }

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java b/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
index 162e375..9b3766e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
@@ -40,6 +40,7 @@ import org.apache.tools.ant.types.optional.image.TransformOperation;
 import org.apache.tools.ant.util.FileNameMapper;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.IdentityMapper;
+import org.apache.tools.ant.util.StringUtils;
 
 import com.sun.media.jai.codec.FileSeekableStream;
 
@@ -392,7 +393,7 @@ public class Image extends MatchingTask {
             }
 
         } catch (Exception err) {
-            err.printStackTrace();
+            log(StringUtils.getStackTrace(err), Project.MSG_ERR);
             throw new BuildException(err.getMessage());
         }
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
index 4c90631..bfcbfed 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
@@ -38,6 +38,7 @@ import org.apache.tools.ant.BuildListener;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectComponent;
 import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * <p>Collects all failing test <i>cases</i> and creates a new JUnit test
class containing
@@ -260,7 +261,7 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm
             createClassFooter();
 
         } catch (IOException e) {
-            e.printStackTrace();
+            log(StringUtils.getStackTrace(e));
         } finally {
             FileUtils.close(writer);
         }

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
index a9e1662..e15e11e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
@@ -63,6 +63,7 @@ import org.apache.tools.ant.types.PropertySet;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.LoaderUtils;
 import org.apache.tools.ant.util.SplitClassLoader;
+import org.apache.tools.ant.util.StringUtils;
 
 /**
  * Runs JUnit tests.
@@ -1299,7 +1300,7 @@ public class JUnitTask extends Task {
                             + " testcase not started or mixing ant versions?";
                 }
             } catch (final Exception e) {
-                e.printStackTrace();
+                log(StringUtils.getStackTrace(e), Project.MSG_INFO);
                 // ignored.
             } finally {
                 FileUtils.close(br);

http://git-wip-us.apache.org/repos/asf/ant/blob/008f1c8b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
index e22bd05..568cbc1 100644
--- a/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
+++ b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
@@ -195,10 +195,6 @@ public class AntClassLoaderTest {
             int startMessage = log.indexOf("CLASSPATH element ");
             assertTrue(startMessage >= 0);
             assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0);
-            log = errBuffer.toString();
-            startMessage = log.indexOf("CLASSPATH element ");
-            assertTrue(startMessage >= 0);
-            assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0);
         } finally {
             System.setErr(sysErr);
         }


Mime
View raw message