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.SnippetPackage;
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 Packages of Files (Byte Code) and returns them as snippets
040: * Package (one Directory) NOT project
041: */
042: public class ByteCodePackageSnippetFactory 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 ByteCodePackageSnippetFactory(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 PackageSnippet;
066: String this File;
067: Iterator loopList;
068: HashSet availableClasses;
069: Snippets tmpSnippets;
070: Snippets packageInfo;
071: Snippets classInfo = new Snippets();
072: ByteCodeClassSnippetFactory myClassFactory;
073:
074: try {
075: //Check that the directory is actually
076: availableClasses = DirectoryWalker.getFiles(
077: innerStartDirectory, ".class");
078:
079: } catch (IOException ie) {
080: throw new NoUnitException(ie,
081: "Could not read files from Package");
082: }
083:
084: //Now loop through available Classes
085: loopList = availableClasses.iterator();
086:
087: while (loopList.hasNext()) {
088:
089: this File = (String) loopList.next();
090: myClassFactory = new ByteCodeClassSnippetFactory(this File);
091: tmpSnippets = myClassFactory.getSnippets();
092: classInfo.add(tmpSnippets.getCollection());
093:
094: }
095:
096: //Put all this info into one snippet Package
097: this PackageSnippet = new SnippetPackage(innerStartDirectory,
098: classInfo);
099:
100: //Put into (generic) snippets collections
101: packageInfo = new Snippets();
102: packageInfo.add(thisPackageSnippet);
103:
104: return packageInfo;
105:
106: }
107:
108: }
|