001: package net.firstpartners.nounit.reader.bytecode;
002:
003: /**
004: * Title: NoUnit - Identify Classes that are not being unit Tested
005: *
006: * Copyright (C) 2001 Paul Browne , FirstPartners.net
007: *
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * @author Paul Browne
024: * @version 0.7
025: */
026:
027: import java.io.IOException;
028: import java.util.HashSet;
029: import java.util.Iterator;
030:
031: import net.firstpartners.nounit.reader.ISnippetFactory;
032: import net.firstpartners.nounit.snippet.ISnippet;
033: import net.firstpartners.nounit.snippet.SnippetProject;
034: import net.firstpartners.nounit.snippet.Snippets;
035: import net.firstpartners.nounit.utility.DirectoryWalker;
036: import net.firstpartners.nounit.utility.NoUnitException;
037:
038: /**
039: * Reads Entire Project of Packages of Files (Byte Code) and returns them as snippets
040: * Package (one Directory) NOT project
041: */
042: public class ByteCodeProjectSnippetFactory extends
043: AbstractByteCodeSnippetFactory implements ISnippetFactory {
044:
045: /**
046: * Inner store for the current class source
047: */
048: private String innerStartDirectory;
049:
050: /**
051: * Constructor - Get (and store) source class file
052: * @param startDirectory to start reading classes from
053: */
054: public ByteCodeProjectSnippetFactory(String startDirectory) {
055: innerStartDirectory = startDirectory;
056: }
057:
058: /**
059: * Get a set of (package) snippets from the current source
060: * @return snippets Collection of ISnippets describing the file
061: */
062: public Snippets getSnippets() throws NoUnitException {
063:
064: //Local Variables
065: ISnippet this ProjectSnippet;
066: String this File;
067: Iterator loopList;
068: HashSet availablePackages;
069: Snippets tmpSnippets;
070: Snippets projectInfo;
071: Snippets packageInfo = new Snippets();
072: ByteCodePackageSnippetFactory myPackageFactory;
073:
074: try {
075:
076: //Check that the directory is actually there
077: availablePackages = DirectoryWalker
078: .getDirs(innerStartDirectory);
079:
080: } catch (IOException ie) {
081: throw new NoUnitException(ie,
082: "Could not read files from Package");
083: }
084:
085: //Now loop through available Classes
086: loopList = availablePackages.iterator();
087:
088: while (loopList.hasNext()) {
089: this File = (String) loopList.next();
090: myPackageFactory = new ByteCodePackageSnippetFactory(
091: this File);
092: tmpSnippets = myPackageFactory.getSnippets();
093: packageInfo.add(tmpSnippets.getCollection());
094: }
095:
096: //Put all this info into one snippet Package
097: this ProjectSnippet = new SnippetProject(packageInfo);
098:
099: //Put into (generic) snippets collections
100: projectInfo = new Snippets();
101: projectInfo.add(thisProjectSnippet);
102:
103: return projectInfo;
104:
105: }
106:
107: }
|