KickJava   Java API By Example, From Geeks To Geeks.

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


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.SnippetPackage;
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 Packages of Files (Byte Code) and returns them as snippets
41  * Package (one Directory) NOT project
42  */

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

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

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

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