1 28 29 package com.idaremedia.antx.capture; 30 31 import org.apache.tools.ant.BuildException; 32 import org.apache.tools.ant.Project; 33 34 import com.idaremedia.antx.AssertableTask; 35 import com.idaremedia.antx.ownhelpers.FeedbackSink; 36 37 47 48 public abstract class LogsUsingTask extends AssertableTask 49 { 50 54 protected LogsUsingTask(String iam) 55 { 56 super(iam); 57 } 58 59 60 64 65 70 public void setImportant(boolean is) 71 { 72 m_isImportant = is; 73 } 74 75 76 81 public final boolean shouldBeImportant() 82 { 83 return m_isImportant; 84 } 85 86 87 91 public void setReset(boolean reset) 92 { 93 m_resetAfter = reset; 94 } 95 96 97 102 public final boolean willReset() 103 { 104 return m_resetAfter; 105 } 106 107 108 114 public void setFrom(FeedbackSink source) 115 { 116 require_(source!=null,"setFrom- nonzro src"); 117 verifyLogsSource(source); 118 m_from = source; 119 } 120 121 122 127 public FeedbackSink getFrom() 128 { 129 return m_from; 130 } 131 132 133 139 protected void verifyLogsSource(FeedbackSink source) 140 { 141 if (!FeedbackSink.isGrouping(source)) { 142 String ermsg = getAntXMsg("brul.logs.bad.capture.sink", 143 getTaskName(), source.getValue()); 144 log(ermsg,Project.MSG_ERR); 145 throw new BuildException(ermsg,getLocation()); 146 } 147 } 148 149 153 159 protected boolean isSourceFlexible() 160 { 161 return false; 162 } 163 164 165 166 172 protected final LogsRecorder getRecorder(boolean allowNull) 173 { 174 LogsRecorder r=null; 175 176 switch (getFrom().getIndex()) { 177 case FeedbackSink.ANTLOG_INDEX: { 178 r = CapturedLogs.getRecorder(); 179 break; 180 } 181 case FeedbackSink.STDIO_INDEX: 182 case FeedbackSink.STDOUT_INDEX: 183 case FeedbackSink.STDERR_INDEX: { 184 r = CapturedLogs.getStdIORecorder(); 185 break; 186 } 187 } 188 if (r==null && !allowNull) { 189 r = EmptyLogs.INSTANCE; 190 } 191 return r; 192 } 193 194 195 200 protected final String getVUTLog() 201 { 202 LogsRecorder r = getRecorder(false); 203 if (shouldBeImportant()) { 204 return r.copyOfImportantLogs(); 205 } 206 return r.copyOfAllLogs(); 207 } 208 209 210 214 protected void verifyCanExecute_(String calr) 215 { 216 super.verifyCanExecute_(calr); 217 218 if (getRecorder(true)==null) { 219 String warning = getAntXMsg("brul.logs.no.recorder"); 220 int level = isSourceFlexible() ? Project.MSG_VERBOSE : Project.MSG_WARN; 221 log(warning,level); 222 } 223 } 224 225 226 private boolean m_isImportant=true; private boolean m_resetAfter; private FeedbackSink m_from = FeedbackSink.ANTLOG;} 230 231 232 | Popular Tags |