ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gle...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Echo.java
Date Fri, 17 Nov 2000 15:03:50 GMT
glennm      00/11/17 07:03:50

  Modified:    src/main/org/apache/tools/ant/taskdefs Echo.java
  Log:
  Now writes message to the logger, rather than to System.out.
  Also introduced logging levels to provide finer control over
  when messages are writen out.  The levels simply reflect the
  current Project.MSG_* values.
  
  Suggested by:           Wolf Siberski
  
  Revision  Changes    Path
  1.5       +43 -5     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Echo.java	2000/09/27 15:58:49	1.4
  +++ Echo.java	2000/11/17 15:03:50	1.5
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant.taskdefs;
   
   import org.apache.tools.ant.*;
  +import org.apache.tools.ant.types.EnumeratedAttribute;
   import java.io.*;
   /**
    * Echo
  @@ -62,10 +63,13 @@
    * @author costin@dnt.ro
    */
   public class Echo extends Task {
  -    private String message = ""; // required
  -    private File file = null;
  -    private boolean append = false;
  +    protected String message = ""; // required
  +    protected File file = null;
  +    protected boolean append = false;
       
  +    // by default, messages are always displayed
  +    protected int logLevel = Project.MSG_WARN;   
  +    
       /**
        * Does the work.
        *
  @@ -73,7 +77,7 @@
        */
       public void execute() throws BuildException {
           if (file == null) {
  -            System.out.println(message);
  +            log(message, logLevel);
           } else {
               FileWriter out = null;
               try {
  @@ -97,7 +101,7 @@
        * @param msg Sets the value for the message variable.
        */
       public void setMessage(String msg) {
  -	this.message = msg;
  +        this.message = msg;
       }
   
       /**
  @@ -120,5 +124,39 @@
       public void addText(String msg) {
           message += 
               ProjectHelper.replaceProperties(msg, project.getProperties());
  +    }
  +
  +    /**
  +     * Set the logging level to one of
  +     * <ul>
  +     *  <li>error</li>
  +     *  <li>warning</li>
  +     *  <li>info</li>
  +     *  <li>verbose</li>
  +     *  <li>debug</li>
  +     * <ul>
  +     * <p>The default is &quot;warning&quot; to ensure that messages are
  +     * displayed by default when using the -quiet command line option.</p>
  +     */
  +    public void setLevel(EchoLevel echoLevel) {
  +        String option = echoLevel.getValue();
  +        if (option.equals("error")) {
  +            logLevel = Project.MSG_ERR;
  +        } else if (option.equals("warning")) {
  +            logLevel = Project.MSG_WARN;
  +        } else if (option.equals("info")) {
  +            logLevel = Project.MSG_INFO;
  +        } else if (option.equals("verbose")) {
  +            logLevel = Project.MSG_VERBOSE;
  +        } else {
  +            // must be "debug"
  +            logLevel = Project.MSG_DEBUG;
  +        }
  +    }
  +
  +    public static class EchoLevel extends EnumeratedAttribute {
  +        public String[] getValues() {
  +            return new String[] {"error", "warning", "info", "verbose", "debug"};
  +        }
       }
   }
  
  
  

Mime
View raw message