ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sco...@apache.org
Subject svn commit: r470639 - in /ant/core/trunk/src: main/org/apache/tools/ant/DefaultLogger.java tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java
Date Fri, 03 Nov 2006 02:57:33 GMT
Author: scohen
Date: Thu Nov  2 18:57:32 2006
New Revision: 470639

URL: http://svn.apache.org/viewvc?view=rev&rev=470639
Log:
Fix bug 40882.

Note that the new test added to EchoTest.java would fail as indicated in the 
defect without the change to DefaultLogger.java.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java?view=diff&rev=470639&r1=470638&r2=470639
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java Thu Nov  2 18:57:32 2006
@@ -252,14 +252,19 @@
                             new StringReader(event.getMessage()));
                     String line = r.readLine();
                     boolean first = true;
-                    while (line != null) {
-                        if (!first) {
+                    do {
+                        if (first) {
+                            if (line == null) {
+                                message.append(label);
+                                break;
+                            }
+                        } else {
                             message.append(StringUtils.LINE_SEP);
                         }
                         first = false;
                         message.append(label).append(line);
                         line = r.readLine();
-                    }
+                    } while (line != null);
                 } catch (IOException e) {
                     // shouldn't be possible
                     message.append(label).append(event.getMessage());

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java?view=diff&rev=470639&r1=470638&r2=470639
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java Thu Nov  2
18:57:32 2006
@@ -18,7 +18,12 @@
 
 package org.apache.tools.ant.taskdefs;
 
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
 import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.Project;
 
 /**
  */
@@ -39,8 +44,16 @@
     // Output an empty String
     public void test1() {
         expectLog("test1", "");
+        expectOutput("test1","");
     }
-
+    
+    public void testLogBlankEcho() {
+        EchoTestLogger logger = new EchoTestLogger();
+        getProject().addBuildListener(logger);
+        getProject().executeTarget("test1");
+        assertEquals("     [echo] ", logger.lastLoggedMessage );
+    }
+ 
     // Output 'OUTPUT OF ECHO'
     public void test2() {
         expectLog("test2", "OUTPUT OF ECHO");
@@ -73,5 +86,27 @@
     }
     public void testUTF8Encoding() throws Exception {
         executeTarget("testUTF8Encoding");
+    }
+    
+    private class EchoTestLogger extends DefaultLogger {
+        String lastLoggedMessage;
+    
+        
+        /**
+         * 
+         */
+        public EchoTestLogger() {
+            super();
+            this.setMessageOutputLevel(Project.MSG_DEBUG);
+            this.setOutputPrintStream(new PrintStream(new ByteArrayOutputStream(256)));
+            this.setErrorPrintStream(new PrintStream(new ByteArrayOutputStream(256)));
+        }
+        /* 
+         * @param message
+         */
+        protected void log(String message) {
+            this.lastLoggedMessage = message;
+        }
+        
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message