1 28 29 package com.idaremedia.antx.capture; 30 31 import java.io.BufferedOutputStream ; 32 import java.io.File ; 33 import java.io.FileOutputStream ; 34 import java.io.IOException ; 35 import java.io.OutputStream ; 36 37 import org.apache.tools.ant.BuildException; 38 import org.apache.tools.ant.Project; 39 40 import com.idaremedia.antx.AntX; 41 import com.idaremedia.antx.parameters.FlexInformationSaver; 42 import com.idaremedia.antx.parameters.TransformHelper; 43 44 78 79 public final class CopyLoggedTask extends LogsUsingTask 80 implements FlexInformationSaver 81 { 82 85 public CopyLoggedTask() 86 { 87 super(AntX.capture+"CopyLoggedTask:"); 88 } 89 90 91 95 public CopyLoggedTask(String iam) 96 { 97 super(iam); 98 } 99 100 104 110 public void setToFile(String fileRef) 111 { 112 require_(fileRef!=null,"setToFil- nonzro fileref"); 113 fileRef = TransformHelper.toPath(fileRef,getProject()); 114 m_toFile= new File (fileRef); 115 116 } 117 118 119 125 public final void setToProjectFile(File outputFile) 126 { 127 require_(outputFile!=null,"setToProjFil- nonzro file"); 128 m_toFile= outputFile; 129 } 130 131 132 137 public final String getToFilePath() 138 { 139 File f = getToFile(); 140 return f!=null ? f.getPath() : null; 141 } 142 143 144 148 public File getToFile() 149 { 150 return m_toFile; 151 } 152 153 154 159 public void setAppend(boolean append) 160 { 161 m_tryAppend= append; 162 } 163 164 165 170 public final boolean willTryAppend() 171 { 172 return m_tryAppend; 173 } 174 175 176 180 public void setToProperty(String property) 181 { 182 require_(property!=null,"setPropty- nonzro nam"); 183 m_updateProperty = property; 184 } 185 186 187 193 public String getToProperty() 194 { 195 return m_updateProperty; 196 } 197 198 199 203 public void setToReference(String name) 204 { 205 require_(name!=null,"setRef- nonzro nam"); 206 m_updateReference = name; 207 } 208 209 210 216 public String getToReference() 217 { 218 return m_updateReference; 219 } 220 221 222 226 232 protected OutputStream getOutputStream() 233 { 234 File f = getToFile(); 235 if (f!=null) { 236 try { 237 return new FileOutputStream (f.getPath(), willTryAppend()); 238 } catch(IOException ioX) { 239 String ermsg = uistrs().get("task.echo.unable.use.file", 240 f.getPath(), ioX.getMessage()); 241 log(ermsg,Project.MSG_ERR); 242 throw new BuildException(ermsg,getLocation()); 243 } 244 } 245 return null; 246 } 247 248 249 250 256 public void execute() 257 { 258 verifyCanExecute_("execute"); 259 260 String info = getVUTLog(); 261 262 if (getToProperty()!=null) { 263 checkIfProperty_(getToProperty(), true); 264 getProject().setNewProperty(getToProperty(),info); 265 } 266 267 if (getToReference()!=null) { 268 checkIfReference_(getToReference(),true); 269 getProject().addReference(getToReference(),info); 270 } 271 272 OutputStream fos = getOutputStream(); 273 if (fos!=null) { 274 try { 275 BufferedOutputStream bos = new BufferedOutputStream (fos, 512); 276 byte[] raw = info.getBytes(); 277 bos.write(raw,0,raw.length); 278 bos.flush(); 279 raw = null; 280 } catch(IOException ioX) { 281 String ermsg = uistrs().get("task.echo.unable.use.file", 282 getToFile().getPath(), 283 ioX.getMessage()); 284 log(ermsg,Project.MSG_ERR); 285 throw new BuildException(ermsg,getLocation()); 286 } finally { 287 try { fos.close(); } catch(IOException igx) {} 288 } 289 } 290 291 if (willReset()) { 292 LogsRecorder r = getRecorder(true); 293 if (r!=null) { 294 r.clearLogs(); 295 } 296 } 297 } 298 299 300 305 protected void verifyCanExecute_(String calr) 306 { 307 super.verifyCanExecute_(calr); 308 309 String pn = getToProperty(); 310 311 if (getToFile()==null && pn==null) { 312 String ermsg = getAntXMsg("task.needs.this.attr",getTaskName(), 313 "tofile|toproperty"); 314 log(ermsg,Project.MSG_ERR); 315 throw new BuildException(ermsg,getLocation()); 316 } 317 if (pn!=null) { 318 checkIfProperty_(pn,true); 319 } 320 } 321 322 private String m_updateProperty, m_updateReference; 323 private File m_toFile; 324 private boolean m_tryAppend;} 326 327 328 | Popular Tags |