1 26 27 package net.sourceforge.groboutils.codecoverage.v2.ant; 28 29 30 import java.io.File ; 31 import java.io.FileOutputStream ; 32 import java.io.IOException ; 33 import java.io.InputStream ; 34 import java.util.Enumeration ; 35 import java.util.Vector ; 36 37 import org.apache.tools.ant.BuildFileTestA; 38 39 40 47 public abstract class AntTestA extends BuildFileTestA 48 { 49 private Vector tempFiles = new Vector (); 50 51 public AntTestA( String name ) 52 { 53 super( name ); 54 } 55 56 57 protected void addTempFile( File f ) 58 { 59 if (f != null) 60 { 61 this.tempFiles.addElement( f ); 62 } 63 } 64 65 66 70 protected void tearDown() throws Exception 71 { 72 Enumeration e = this.tempFiles.elements(); 74 while (e.hasMoreElements()) 75 { 76 File f = (File )e.nextElement(); 77 if (f.exists()) 78 { 79 f.delete(); 80 } 81 } 82 83 super.tearDown(); 84 } 85 86 87 91 protected void configureProject(String filename, int logLevel) 92 { 93 try 94 { 95 InputStream is = this.getClass().getResourceAsStream( filename ); 96 try 97 { 98 File dir = new File ( 99 Long.toString( System.currentTimeMillis() ) ); 100 dir.mkdirs(); 101 File tmp = new File ( dir, filename ); 102 FileOutputStream fos = new FileOutputStream ( tmp ); 103 try 104 { 105 byte[] buff = new byte[ 4096 ]; 106 int size = is.read( buff ); 107 while (size > 0) 108 { 109 fos.write( buff, 0, size ); 110 size = is.read( buff ); 111 } 112 } 113 finally 114 { 115 fos.close(); 116 } 117 118 super.configureProject( tmp.getAbsolutePath(), logLevel ); 119 } 120 catch (IOException ioe) 121 { 122 ioe.printStackTrace(); 123 fail( ioe.getMessage() ); 124 } 125 finally 126 { 127 try 128 { 129 is.close(); 130 } 131 catch (IOException ioe) 132 { 133 ioe.printStackTrace(); 134 fail( ioe.getMessage() ); 135 } 136 } 137 } 138 catch (RuntimeException ex) 139 { 140 ex.printStackTrace(); 141 throw ex; 142 } 143 } 144 } 145 146 | Popular Tags |