ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Ant.java
Date Tue, 25 Jul 2000 13:15:34 GMT
conor       00/07/25 06:15:33

  Modified:    src/main/org/apache/tools/ant DefaultLogger.java Main.java
               src/main/org/apache/tools/ant/taskdefs Ant.java
  Added:       src/main/org/apache/tools/ant BuildLogger.java
  Log:
  Add the concept of a BuildLogger - A BuildListener with the following
  - An output level used to filter build events
  - Access to the ant output print stream
  - An emacs mode.
  
  Update DefaultLogger to the new interface. In its emacs mode, output
  is unadorned by the [taskname] tags
  
  Add -logger option to allow the logger class to be changed
  Add -emacs option to control the logger's emacsMode setting
  
  Revision  Changes    Path
  1.5       +37 -11    jakarta-ant/src/main/org/apache/tools/ant/DefaultLogger.java
  
  Index: DefaultLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/DefaultLogger.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultLogger.java	2000/07/16 10:39:58	1.4
  +++ DefaultLogger.java	2000/07/25 13:15:29	1.5
  @@ -61,24 +61,48 @@
    *  only writes which targets are being executed, and
    *  any messages that get logged.
    */
  -public class DefaultLogger implements BuildListener {
  +public class DefaultLogger implements BuildLogger {
       private static int LEFT_COLUMN_SIZE = 12;
   
       private PrintStream out;
       private int msgOutputLevel;
       private long startTime = System.currentTimeMillis();
   
  +    private boolean emacsMode = false;
   
       /**
  -     *  Constructs a new logger which will write to the specified
  -     *  PrintStream. Messages with a priority lower (higher?) than
  -     *  msgOutputLevel will be ignored.
  +     * Set the msgOutputLevel this logger is to respond to.
  +     *
  +     * Only messages with a message level lower than or equal to the given level are 
  +     * output to the log.
  +     *
  +     * @param level the logging level for the logger.
        */
  -    public DefaultLogger(PrintStream out, int msgOutputLevel) {
  -        this.out = out;
  -        this.msgOutputLevel = msgOutputLevel;
  +    public void setMessageOutputLevel(int level) {
  +        this.msgOutputLevel = level;
       }
   
  +    
  +    /**
  +     * Set the output stream to which this logger is to send its output.
  +     *
  +     * @param output the output stream for the logger.
  +     */
  +    public void setOutputPrintStream(PrintStream output) {
  +        this.out = output;
  +    }
  +
  +    /**
  +     * Set this logger to produce emacs (and other editor) friendly output.
  +     *
  +     * @param emacsMode true if output is to be unadorned so that emacs and other
  +     * editors can parse files names, etc.
  +     */
  +    public void setEmacsMode(boolean emacsMode) {
  +        this.emacsMode = emacsMode;
  +    }
  +
  +
       public void buildStarted(BuildEvent event) {
           startTime = System.currentTimeMillis();
       }
  @@ -133,11 +157,13 @@
               if (event.getTask() != null) {
                   String name = event.getTask().getTaskName();
   
  -                String msg = "[" + name + "] ";
  -                for (int i = 0; i < (LEFT_COLUMN_SIZE - msg.length()); i++) {
  -                    out.print(" ");
  +                if (!emacsMode) {
  +                    String msg = "[" + name + "] ";
  +                    for (int i = 0; i < (LEFT_COLUMN_SIZE - msg.length()); i++) {
  +                        out.print(" ");
  +                    }
  +                    out.print(msg);
                   }
  -                out.print(msg);
               }
   
               // Print the message
  
  
  
  1.14      +50 -5     jakarta-ant/src/main/org/apache/tools/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Main.java	2000/07/25 12:08:03	1.13
  +++ Main.java	2000/07/25 13:15:29	1.14
  @@ -91,6 +91,18 @@
       private Vector listeners = new Vector(5);
   
       /**
  +     * The Ant logger class. There may be only one logger. It will have the
  +     * right to use the 'out' PrintStream. The class must implements the BuildLogger 
  +     * interface
  +     */
  +    private String loggerClassname = null;
  +
  +    /**
  +     * Indicates whether output to the log is to be unadorned.
  +     */
  +    private boolean emacsMode = false;
  +
  +    /**
        * Indicates if this ant should be run.
        */
       private boolean readyToRun = false;
  @@ -190,6 +202,14 @@
                       value = args[++i];
   
                   definedProps.put(name, value);
  +            } else if (arg.equals("-logger")) {
  +                if (loggerClassname != null) {
  +                    System.out.println("Only one logger class may be specified.");
  +                    return;
  +                }
  +                loggerClassname = args[++i];
  +            } else if (arg.equals("-emacs")) {
  +                emacsMode = true;
               } else if (arg.startsWith("-")) {
                   // we don't have any more args to recognize!
                   String msg = "Unknown arg: " + arg;
  @@ -224,7 +244,6 @@
       /**
        * Executes the build.
        */
  -
       private void runBuild() throws BuildException {
   
           if (!readyToRun) {
  @@ -294,7 +313,7 @@
       protected void addBuildListeners(Project project) {
   
           // Add the default listener
  -        project.addBuildListener(createDefaultBuildListener());
  +        project.addBuildListener(createLogger());
   
           for (int i = 0; i < listeners.size(); i++) {
               String className = (String) listeners.elementAt(i);
  @@ -310,10 +329,34 @@
       }
   
       /**
  -     *  Creates the default build listener for displaying output to the screen.
  +     *  Creates the default build logger for sending build events to the ant log.
        */
  -    private BuildListener createDefaultBuildListener() {
  -        return new DefaultLogger(out, msgOutputLevel);
  +    private BuildLogger createLogger() {
  +        BuildLogger logger = null;
  +        if (loggerClassname != null) {
  +            try {
  +                logger = (BuildLogger)(Class.forName(loggerClassname).newInstance());
  +            }
  +            catch (ClassCastException e) {
  +                System.err.println("The specified logger class " + loggerClassname + 
  +                                         " does not implement the BuildLogger interface");
  +                throw new RuntimeException();
  +            }
  +            catch (Exception e) {
  +                System.err.println("Unable to instantiate specified logger class " + 
  +                                           loggerClassname + " : " + e.getClass().getName());
  +                throw new RuntimeException();
  +            }
  +        }
  +        else {
  +            logger = new DefaultLogger();
  +        }
  +        
  +        logger.setMessageOutputLevel(msgOutputLevel);
  +        logger.setOutputPrintStream(out);
  +        logger.setEmacsMode(emacsMode);
  +        
  +        return logger;
       }
   
       /**
  @@ -328,7 +371,9 @@
           msg.append("  -version               print the version information and exit" +
lSep);
           msg.append("  -quiet                 be extra quiet" + lSep);
           msg.append("  -verbose               be extra verbose" + lSep);
  +        msg.append("  -emacs                 produce logging information without adornments"
+ lSep);
           msg.append("  -logfile <file>        use given file for log" + lSep);
  +        msg.append("  -logger <classname>    the class which is to perform logging"
+ lSep);
           msg.append("  -listener <classname>  add an instance of class as a project
listener" + lSep);
           msg.append("  -buildfile <file>      use given buildfile" + lSep);
           msg.append("  -D<property>=<value>   use value for given property"
+ lSep);
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/BuildLogger.java
  
  Index: BuildLogger.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant;
  
  import java.io.*;
  
  /**
   * Interface used by Ant to log the build output. 
   *
   * A build logger is a build listener which has the 'right' to send output to the
   * ant log, which is usually System.out unles redirected by the -logfile option.
   *
   * @author Conor MacNeill
   */
  public interface BuildLogger extends BuildListener {
      /**
       * Set the msgOutputLevel this logger is to respond to.
       *
       * Only messages with a message level lower than or equal to the given level are 
       * output to the log.
       *
       * @param level the logging level for the logger.
       */
      public void setMessageOutputLevel(int level);
      
      /**
       * Set the output stream to which this logger is to send its output.
       *
       * @param output the output stream for the logger.
       */
      public void setOutputPrintStream(PrintStream output);
      
      /**
       * Set this logger to produce emacs (and other editor) friendly output.
       *
       * @param emacsMode true if output is to be unadorned so that emacs and other
       * editors can parse files names, etc.
       */
      public void setEmacsMode(boolean emacsMode);
  }
  
  
  1.13      +4 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Ant.java	2000/07/24 14:54:49	1.12
  +++ Ant.java	2000/07/25 13:15:32	1.13
  @@ -120,7 +120,10 @@
           if (output != null) {
               try {
                   PrintStream out = new PrintStream(new FileOutputStream(output));
  -                p1.addBuildListener(new DefaultLogger(out, Project.MSG_INFO));
  +                DefaultLogger logger = new DefaultLogger();
  +                logger.setMessageOutputLevel(Project.MSG_INFO);
  +                logger.setOutputPrintStream(out);
  +                p1.addBuildListener(logger);
               }
               catch( IOException ex ) {
                   log( "Ant: Can't set output to " + output );
  
  
  

Mime
View raw message