ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Echo.java
Date Wed, 27 Sep 2000 15:59:03 GMT
bodewig     00/09/27 08:58:57

  Modified:    .        WHATSNEW
               docs     index.html
               src/main/org/apache/tools/ant/taskdefs Echo.java
  Log:
  Add a file attribute to echo to have a simple task that can create
  files on the fly.
  
  Revision  Changes    Path
  1.32      +7 -1      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- WHATSNEW	2000/09/20 15:53:20	1.31
  +++ WHATSNEW	2000/09/27 15:58:19	1.32
  @@ -40,7 +40,9 @@
   
   * <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 @@
   
   * <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)
  @@ -84,6 +88,8 @@
   * Ant will now search for a file named build.xml in the parent directory
   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:
   -----------
  
  
  
  1.118     +13 -3     jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.117
  retrieving revision 1.118
  diff -u -r1.117 -r1.118
  --- index.html	2000/09/27 15:08:46	1.117
  +++ index.html	2000/09/27 15:58:34	1.118
  @@ -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 @@
   <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>
  @@ -1506,6 +1506,16 @@
       <td valign="top">the message to echo.</td>
       <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>
  
  
  
  1.4       +35 -3     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Echo.java
  
  Index: Echo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Echo.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Echo.java	2000/09/14 14:13:39	1.3
  +++ Echo.java	2000/09/27 15:58:49	1.4
  @@ -56,7 +56,6 @@
   
   import org.apache.tools.ant.*;
   import java.io.*;
  -import java.net.*;
   /**
    * Echo
    *
  @@ -64,6 +63,8 @@
    */
   public class Echo extends Task {
       private String message = ""; // required
  +    private File file = null;
  +    private boolean append = false;
       
       /**
        * Does the work.
  @@ -71,7 +72,23 @@
        * @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) {}
  +                }
  +            }
  +        }
       }
   
       /**
  @@ -84,9 +101,24 @@
       }
   
       /**
  +     * 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());
       }
   }
  
  
  

Mime
View raw message