Browse Source

Add a file attribute to echo to have a simple task that can create

files on the fly.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268043 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
0b508c3284
3 changed files with 55 additions and 7 deletions
  1. +7
    -1
      WHATSNEW
  2. +13
    -3
      docs/index.html
  3. +35
    -3
      src/main/org/apache/tools/ant/taskdefs/Echo.java

+ 7
- 1
WHATSNEW View File

@@ -40,7 +40,9 @@ behavior has been dropped.

* <ejbjar> task syntax has been changed significantly

* build.compiler supports now jvc as well.
* <exec> is no longer implemented by org.apache.tool.ant.taskdefs.Exec.
Custom tasks that rely on Project.createTask("exec") to return an
instance of this class are going to fail.

Other changes:
--------------
@@ -77,6 +79,8 @@ on log output.

* <ejbc> optional task no longer uses a separate VM to invoke the ejbc tool.

* build.compiler supports now jvc as well.

* project specific help can now be obtained with the -projecthelp option.

* Added a -debug option to make -verbose less verbose (and more useful)
@@ -85,6 +89,8 @@ on log output.
and above (towards the root of the filesystem) if you didn't specify
-buildfile and there is no build.xml in the current directory.

* <echo> can now write to a file and accepts nested text.

Fixed bugs:
-----------



+ 13
- 3
docs/index.html View File

@@ -12,7 +12,7 @@
<!-- Names are in alphabetical order, on last name -->
<ul>
<li>Jacques Bergeron (<a href="mailto:jacques.bergeron@dogico.com">jacques.bergeron@dogico.com</a>)</li>
<li>Stefan Bodewig (<a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a>)</li>
<li>Stefan Bodewig (<a href="mailto:stefan.bodewig@epost.de">stefan.bodewig@epost.de</a>)</li>
<li>Patrick Chanezon (<a href="mailto:chanezon@netscape.com">chanezon@netscape.com</a>)</li>
<li>James Duncan Davison (<a href="mailto:duncan@x180.com">duncan@x180.com</a>)</li>
<li>Tom Dimock (<a href="mailto:tad1@cornell.edu">tad1@cornell.edu</a>)</li>
@@ -26,7 +26,7 @@
<li>Dave Walend (<a href="mailto:dwalend@cs.tufts.edu">dwalend@cs.tufts.edu</a>)</li>
</ul>

<p>Version 1.2 - 2000/09/20</p>
<p>Version 1.2 - 2000/09/27</p>

<hr>
<h2>Table of Contents</h2>
@@ -1493,7 +1493,7 @@ subdirectories.</p>
<hr>
<h2><a name="echo">Echo</a></h2>
<h3>Description</h3>
<p>Echoes a message to System.out.</p>
<p>Echoes a message to System.out or a file.</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
@@ -1507,6 +1507,16 @@ subdirectories.</p>
<td valign="top" align="center">Yes, unless data is included in a
character section within this element.</td>
</tr>
<tr>
<td valign="top">file</td>
<td valign="top">the file to write the message to.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">append</td>
<td valign="top">Append to an existing file?</td>
<td valign="top" align="center">No - default is false.</td>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;echo message=&quot;Hello world&quot; /&gt;</pre>


+ 35
- 3
src/main/org/apache/tools/ant/taskdefs/Echo.java View File

@@ -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());
}
}

Loading…
Cancel
Save