Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * RHQ Management Platform
   * Copyright (C) 2010 Red Hat, Inc.
   * All rights reserved.
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation version 2 of the License.
   *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 package org.rhq.bundle.ant;
 
 import java.util.Date;
 
Listens for Ant build events and logs them to a print writer.

Author(s):
John Mazzitelli
 
 public class LoggerAntBuildListener implements BuildListener {
     private final String mainTarget;
     private final PrintWriter output;
     private final int priorityThreshold;
 
     public LoggerAntBuildListener(String targetPrintWriter printWriterint priorityThreshold) {
         this. = (target != null) ? target : "(default)";
         this. = printWriter;
         this. = priorityThreshold;
 
         // start with the date this was started
         this..println("======================================");
         this..println("Ant target [" + this. + "]");
         this..println(new Date());
         this..println("======================================");
     }
 
     public void buildFinished(BuildEvent event) {
         logEvent(event"FINISHED! [" + this. + ']');
     }
 
     public void buildStarted(BuildEvent event) {
         logEvent(event"STARTED! [" + this. + ']');
     }
 
     public void messageLogged(BuildEvent event) {
         if (event.getPriority() <= this.) {
             logEvent(eventnull);
         }
     }
 
     public void targetFinished(BuildEvent event) {
         logEvent(eventnull);
     }
 
     public void targetStarted(BuildEvent event) {
         logEvent(eventnull);
     }
 
     public void taskFinished(BuildEvent event) {
         logEvent(eventnull);
     }
 
     public void taskStarted(BuildEvent event) {
         logEvent(eventnull);
     }
 
     private void logEvent(BuildEvent eventString additionalMessage) {
         String message = event.getMessage();
         Throwable exception = event.getException();
         Target target = event.getTarget();
         Task task = event.getTask();
 
         if (additionalMessage != null) {
             this..println(additionalMessage);
         }
 
         if (target != null) {
             String targetName = (target.getName() != null) ? target.getName() : "";
             this..print("[" + targetName + "] ");
         }
 
         if (task != null) {
             this..print("<" + task.getTaskName() + "> ");
         }
 
        if (message != null) {
            this..print(message);
        }
        if (exception != null) {
            this..println();
            exception.printStackTrace();
        }
        this..println();
        this..flush();
        return;
    }
New to GrepCode? Check out our FAQ X