KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > ant > AntTestA


1 /*
2  * @(#)AntTestA.java
3  *
4  * Copyright (C) 2004 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.codecoverage.v2.ant;
28
29
30 import java.io.File JavaDoc;
31 import java.io.FileOutputStream JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.InputStream JavaDoc;
34 import java.util.Enumeration JavaDoc;
35 import java.util.Vector JavaDoc;
36
37 import org.apache.tools.ant.BuildFileTestA;
38
39
40 /**
41  * Framework extention to the Ant build file test class.
42  *
43  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
44  * @version $Date: 2004/04/15 05:48:27 $
45  * @since February 25, 2004
46  */

47 public abstract class AntTestA extends BuildFileTestA
48 {
49     private Vector JavaDoc tempFiles = new Vector JavaDoc();
50     
51     public AntTestA( String JavaDoc name )
52     {
53         super( name );
54     }
55     
56     
57     protected void addTempFile( File JavaDoc f )
58     {
59         if (f != null)
60         {
61             this.tempFiles.addElement( f );
62         }
63     }
64     
65     
66     /**
67      *
68      * @exception Exception thrown under any exceptional condition.
69      */

70     protected void tearDown() throws Exception JavaDoc
71     {
72         // tear ourself down
73
Enumeration JavaDoc e = this.tempFiles.elements();
74         while (e.hasMoreElements())
75         {
76             File JavaDoc f = (File JavaDoc)e.nextElement();
77             if (f.exists())
78             {
79                 f.delete();
80             }
81         }
82         
83         super.tearDown();
84     }
85
86
87     /**
88      * Overload the parent. We'll use the resource stream to load the
89      * XML file.
90      */

91     protected void configureProject(String JavaDoc filename, int logLevel)
92     {
93         try
94         {
95             InputStream JavaDoc is = this.getClass().getResourceAsStream( filename );
96             try
97             {
98                 File JavaDoc dir = new File JavaDoc(
99                     Long.toString( System.currentTimeMillis() ) );
100                 dir.mkdirs();
101                 File JavaDoc tmp = new File JavaDoc( dir, filename );
102                 FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc( 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 JavaDoc ioe)
121             {
122                 ioe.printStackTrace();
123                 fail( ioe.getMessage() );
124             }
125             finally
126             {
127                 try
128                 {
129                     is.close();
130                 }
131                 catch (IOException JavaDoc ioe)
132                 {
133                     ioe.printStackTrace();
134                     fail( ioe.getMessage() );
135                 }
136             }
137         }
138         catch (RuntimeException JavaDoc ex)
139         {
140             ex.printStackTrace();
141             throw ex;
142         }
143     }
144 }
145
146
Popular Tags