diff --git a/WHATSNEW b/WHATSNEW
index a29d48b28..a54f66634 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -40,7 +40,9 @@ behavior has been dropped.
* Version 1.2 - 2000/09/20 Version 1.2 - 2000/09/27
-
Table of Contents
@@ -1493,7 +1493,7 @@ subdirectories.
Echoes a message to System.out.
+Echoes a message to System.out or a file.
Yes, unless data is included in a character section within this element. | ||
file | +the file to write the message to. | +No | +
append | +Append to an existing file? | +No - default is false. | +
<echo message="Hello world" />diff --git a/src/main/org/apache/tools/ant/taskdefs/Echo.java b/src/main/org/apache/tools/ant/taskdefs/Echo.java index d6b70f974..8c480fddc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Echo.java +++ b/src/main/org/apache/tools/ant/taskdefs/Echo.java @@ -56,7 +56,6 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.*; import java.io.*; -import java.net.*; /** * Echo * @@ -64,6 +63,8 @@ import java.net.*; */ public class Echo extends Task { private String message = ""; // required + private File file = null; + private boolean append = false; /** * Does the work. @@ -71,7 +72,23 @@ public class Echo extends Task { * @exception BuildException if someting goes wrong with the build */ public void execute() throws BuildException { - System.out.println(message); + if (file == null) { + System.out.println(message); + } else { + FileWriter out = null; + try { + out = new FileWriter(file.getAbsolutePath(), append); + out.write(message, 0, message.length()); + } catch (IOException ioe) { + throw new BuildException(ioe, location); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException ioex) {} + } + } + } } /** @@ -83,10 +100,25 @@ public class Echo extends Task { this.message = msg; } + /** + * Sets the file attribute. + */ + public void setFile(File file) { + this.file = file; + } + + /** + * Shall we append to an existing file? + */ + public void setAppend(boolean append) { + this.append = append; + } + /** * Set a multiline message. */ public void addText(String msg) { - message += msg; + message += + ProjectHelper.replaceProperties(msg, project.getProperties()); } }