1 11 package org.eclipse.ant.internal.ui.antsupport.logger; 12 13 14 import java.io.PrintStream ; 15 16 import org.apache.tools.ant.BuildEvent; 17 import org.apache.tools.ant.BuildException; 18 import org.apache.tools.ant.BuildLogger; 19 import org.apache.tools.ant.Project; 20 import org.apache.tools.ant.util.StringUtils; 21 import org.eclipse.ant.core.AntSecurityException; 22 import org.eclipse.ant.internal.core.AbstractEclipseBuildLogger; 23 import org.eclipse.ant.internal.ui.antsupport.AntSupportMessages; 24 import org.eclipse.core.runtime.OperationCanceledException; 25 26 public class NullBuildLogger extends AbstractEclipseBuildLogger implements BuildLogger{ 27 28 protected int fMessageOutputLevel = Project.MSG_INFO; 29 private PrintStream fErr= null; 30 private PrintStream fOut= null; 31 protected boolean fEmacsMode= false; 32 33 36 protected Throwable fHandledException= null; 37 38 41 public void setMessageOutputLevel(int level) { 42 fMessageOutputLevel= level; 43 } 44 45 protected int getMessageOutputLevel() { 46 return fMessageOutputLevel; 47 } 48 49 52 public void setEmacsMode(boolean emacsMode) { 53 fEmacsMode= emacsMode; 54 } 55 56 59 public void buildStarted(BuildEvent event) { 60 } 61 62 65 public void buildFinished(BuildEvent event) { 66 String message= handleException(event); 67 if (message != null) { 68 logMessage(message, getMessageOutputLevel()); 69 } 70 fHandledException= null; 71 } 72 73 76 public void targetStarted(BuildEvent event) { 77 } 78 79 82 public void targetFinished(BuildEvent event) { 83 } 84 85 88 public void taskStarted(BuildEvent event) { 89 } 90 91 94 public void taskFinished(BuildEvent event) { 95 } 96 97 100 public void messageLogged(BuildEvent event) { 101 logMessage(event.getMessage(), event.getPriority()); 102 } 103 104 protected PrintStream getErrorPrintStream() { 105 return fErr; 106 } 107 108 protected PrintStream getOutputPrintStream() { 109 return fOut; 110 } 111 112 115 public void setErrorPrintStream(PrintStream err) { 116 if (err == System.err) { 119 fErr= null; 120 } else { 121 fErr= err; 122 } 123 } 124 125 128 public void setOutputPrintStream(PrintStream output) { 129 if (output == System.out) { 132 fOut= null; 133 } else { 134 fOut= output; 135 } 136 } 137 138 protected void logMessage(String message, int priority) { 139 if (priority > getMessageOutputLevel()) { 140 return; 141 } 142 143 if (priority == Project.MSG_ERR) { 144 if (getErrorPrintStream() != null && getErrorPrintStream() != System.err) { 145 getErrorPrintStream().println(message); 147 } 148 } else { 149 if (getOutputPrintStream() != null && getOutputPrintStream() != System.out) { 150 getOutputPrintStream().println(message); 152 } 153 } 154 } 155 156 protected String handleException(BuildEvent event) { 157 Throwable exception = event.getException(); 158 if (exception == null || exception == fHandledException 159 || exception instanceof OperationCanceledException 160 || exception instanceof AntSecurityException) { 161 return null; 162 } 163 fHandledException= exception; 164 StringBuffer message= new StringBuffer (); 165 message.append(StringUtils.LINE_SEP); 166 message.append(AntSupportMessages.NullBuildLogger_1); 167 message.append(StringUtils.LINE_SEP); 168 if (Project.MSG_VERBOSE <= fMessageOutputLevel || !(exception instanceof BuildException)) { 169 message.append(StringUtils.getStackTrace(exception)); 170 } else { 171 if (exception instanceof BuildException) { 172 message.append(exception.toString()).append(StringUtils.LINE_SEP); 173 } else { 174 message.append(exception.getMessage()).append(StringUtils.LINE_SEP); 175 } 176 } 177 178 return message.toString(); 179 } 180 } 181 | Popular Tags |