KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > util > SingleLogFilter


1 /*
2  * @(#)SingleLogFilter.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.util;
28
29 import net.sourceforge.groboutils.codecoverage.v2.IChannelLogger;
30 import net.sourceforge.groboutils.codecoverage.v2.logger.DirectoryChannelLogger;
31
32 import java.io.File JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.FileReader JavaDoc;
35
36
37 /**
38  * Transforms the single logging format to the standard logging format.
39  *
40  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
41  * @version $Date: 2004/07/07 09:39:11 $
42  * @since April 16, 2004
43  */

44 public class SingleLogFilter implements ILogFilter
45 {
46     public void process( int channelCount, File JavaDoc dir )
47             throws IOException JavaDoc
48     {
49 //System.out.println("++ Processing single log filter for dir "+dir.getAbsolutePath()+" with "+channelCount+" channels");
50
IChannelLogger[] loggers = createChannels( dir, channelCount );
51         
52         try
53         {
54             ConvertSingleLog csl = new ConvertSingleLog( loggers );
55             File JavaDoc[] contents = dir.listFiles();
56             if (contents != null)
57             {
58                 for (int i = 0; i < contents.length; ++i)
59                 {
60                     String JavaDoc name = contents[i].getName();
61 //System.out.println("++ dir contains "+name);
62
if (contents[i].isFile() && name.startsWith( "single." ) &&
63                         name.endsWith( ".log" ))
64                     {
65 //System.out.println("++ it's a log - process it.");
66
FileReader JavaDoc fr = new FileReader JavaDoc( contents[i] );
67                         csl.read( fr, true );
68                     }
69                 }
70             }
71         }
72         finally
73         {
74             cleanupChannels( loggers );
75         }
76     }
77     
78     
79     protected IChannelLogger[] createChannels( File JavaDoc dir, int count )
80     {
81         DirectoryChannelLogger[] loggers = new DirectoryChannelLogger[ count ];
82         for (int i = 0; i < count; ++i)
83         {
84             File JavaDoc outdir = new File JavaDoc( dir, Integer.toString( i ) );
85             outdir.mkdirs();
86 //System.out.println("++ channel "+i+" outputting to dir "+outdir.getAbsolutePath());
87
loggers[i] = new DirectoryChannelLogger( outdir );
88         }
89         return loggers;
90     }
91
92     protected void cleanupChannels( IChannelLogger[] loggers )
93     {
94         DirectoryChannelLogger[] dcl = (DirectoryChannelLogger[])loggers;
95         
96         // Need to somehow clean up these loggers.
97
}
98 }
99
100
Popular Tags