KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > reader > bytecode > ByteCodeProjectSnippetFactory


1
2 package net.firstpartners.nounit.reader.bytecode;
3
4 /**
5  * Title: NoUnit - Identify Classes that are not being unit Tested
6  *
7  * Copyright (C) 2001 Paul Browne , FirstPartners.net
8  *
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  *
24  * @author Paul Browne
25  * @version 0.7
26  */

27
28 import java.io.IOException JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 import net.firstpartners.nounit.reader.ISnippetFactory;
33 import net.firstpartners.nounit.snippet.ISnippet;
34 import net.firstpartners.nounit.snippet.SnippetProject;
35 import net.firstpartners.nounit.snippet.Snippets;
36 import net.firstpartners.nounit.utility.DirectoryWalker;
37 import net.firstpartners.nounit.utility.NoUnitException;
38
39 /**
40  * Reads Entire Project of Packages of Files (Byte Code) and returns them as snippets
41  * Package (one Directory) NOT project
42  */

43 public class ByteCodeProjectSnippetFactory
44  extends AbstractByteCodeSnippetFactory
45  implements ISnippetFactory
46 {
47     
48     /**
49      * Inner store for the current class source
50      */

51     private String JavaDoc innerStartDirectory;
52     
53    
54     /**
55      * Constructor - Get (and store) source class file
56      * @param startDirectory to start reading classes from
57      */

58     public ByteCodeProjectSnippetFactory(String JavaDoc startDirectory){
59         innerStartDirectory = startDirectory;
60     }
61     
62     /**
63      * Get a set of (package) snippets from the current source
64      * @return snippets Collection of ISnippets describing the file
65      */

66     public Snippets getSnippets()
67     throws NoUnitException {
68         
69         //Local Variables
70
ISnippet thisProjectSnippet;
71         String JavaDoc thisFile;
72         Iterator JavaDoc loopList;
73         HashSet JavaDoc availablePackages;
74         Snippets tmpSnippets;
75         Snippets projectInfo ;
76         Snippets packageInfo = new Snippets();
77         ByteCodePackageSnippetFactory myPackageFactory;
78         
79         try {
80             
81             //Check that the directory is actually there
82
availablePackages = DirectoryWalker.getDirs(innerStartDirectory);
83             
84         } catch (IOException JavaDoc ie) {
85             throw new NoUnitException(ie,"Could not read files from Package");
86         }
87         
88         //Now loop through available Classes
89
loopList = availablePackages.iterator();
90         
91         while (loopList.hasNext()) {
92             thisFile = (String JavaDoc)loopList.next();
93             myPackageFactory = new ByteCodePackageSnippetFactory(thisFile);
94             tmpSnippets = myPackageFactory.getSnippets();
95             packageInfo.add(tmpSnippets.getCollection());
96         }
97         
98         //Put all this info into one snippet Package
99
thisProjectSnippet = new SnippetProject(packageInfo);
100         
101         //Put into (generic) snippets collections
102
projectInfo = new Snippets();
103         projectInfo.add(thisProjectSnippet);
104         
105         return projectInfo ;
106         
107     }
108     
109     
110 }
111
Popular Tags