View Javadoc
1 2 package org.apache.commons.jelly.tags.werkz; 3 4 import org.apache.commons.jelly.XMLOutput; 5 6 import org.apache.tools.ant.Project; 7 import org.apache.tools.ant.BuildListener; 8 import org.apache.tools.ant.BuildEvent; 9 import org.apache.tools.ant.taskdefs.optional.junit.JUnitTask; 10 11 import org.xml.sax.SAXException; 12 13 import java.io.IOException; 14 import java.util.Stack; 15 16 public class JellyBuildListener implements BuildListener 17 { 18 private XMLOutput out; 19 20 private Stack taskStack; 21 22 private boolean debug; 23 24 /*** Whether or not to use emacs-style output */ 25 protected boolean emacsMode = false; 26 27 public JellyBuildListener(XMLOutput out) { 28 this.taskStack = new Stack(); 29 this.out = out; 30 this.debug = false; 31 } 32 33 /*** 34 * Sets this logger to produce emacs (and other editor) friendly output. 35 * 36 * @param emacsMode <code>true</code> if output is to be unadorned so that 37 * emacs and other editors can parse files names, etc. 38 */ 39 public void setEmacsMode(boolean emacsMode) { 40 this.emacsMode = emacsMode; 41 } 42 43 public boolean isDebug() { 44 return this.debug; 45 } 46 47 public void isDebug(boolean debug) { 48 this.debug = debug; 49 } 50 51 public void buildFinished(BuildEvent event) { 52 } 53 54 public void buildStarted(BuildEvent event) { 55 } 56 57 public void messageLogged(BuildEvent event) { 58 59 // System.err.println( "messageLogged(" + event + ")" ); 60 61 if ( event.getPriority() > Project.MSG_INFO 62 && 63 ! isDebug() ) { 64 return; 65 } 66 67 try { 68 if ( emacsMode ) { 69 out.write( event.getMessage() + "\n" ); 70 out.flush(); 71 return; 72 } 73 74 if ( ! this.taskStack.isEmpty() ) { 75 out.write( " [" + this.taskStack.peek() + "] " ); 76 } 77 78 switch ( event.getPriority() ) { 79 case ( Project.MSG_ERR ): { 80 out.write( "[ERROR] "); 81 break; 82 } 83 case ( Project.MSG_WARN ): { 84 // out.write( "[WARN] "); 85 break; 86 } 87 case ( Project.MSG_INFO ): { 88 // normal, do nothing. 89 break; 90 } 91 case ( Project.MSG_VERBOSE ): { 92 out.write( "[VERBOSE] "); 93 break; 94 } 95 case ( Project.MSG_DEBUG ): { 96 out.write( "[DEBUG] "); 97 break; 98 } 99 } 100 101 out.write( event.getMessage() + "\n" ); 102 out.flush(); 103 } catch (SAXException e) { 104 // fall-back to stderr. 105 System.err.println( event.getMessage() ); 106 System.err.flush(); 107 } catch (IOException e) { 108 // ignore 109 } 110 111 } 112 113 public void targetFinished(BuildEvent event) { 114 } 115 116 public void targetStarted(BuildEvent event) { 117 } 118 119 public void taskFinished(BuildEvent event) { 120 this.taskStack.pop(); 121 } 122 123 public void taskStarted(BuildEvent event) { 124 this.taskStack.push( event.getTask().getTaskName() ); 125 } 126 } 127 128

This page was automatically generated by Maven