package net.firstpartners.nounit.reader.bytecode;
/**
* Title: NoUnit - Identify Classes that are not being unit Tested
*
* Copyright (C) 2001 Paul Browne , FirstPartners.net
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author Paul Browne
* @version 0.7
*/
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import net.firstpartners.nounit.reader.ISnippetFactory;
import net.firstpartners.nounit.snippet.ISnippet;
import net.firstpartners.nounit.snippet.SnippetPackage;
import net.firstpartners.nounit.snippet.Snippets;
import net.firstpartners.nounit.utility.DirectoryWalker;
import net.firstpartners.nounit.utility.NoUnitException;
/**
* Reads Entire Packages of Files (Byte Code) and returns them as snippets
* Package (one Directory) NOT project
*/
public class ByteCodePackageSnippetFactory extends AbstractByteCodeSnippetFactory implements ISnippetFactory {
/**
* Inner store for the current class source
*/
private String innerStartDirectory;
/**
* Constructor - Get (and store) source class file
* @param startDirectory to start reading classes from
*/
public ByteCodePackageSnippetFactory(String startDirectory){
innerStartDirectory = startDirectory;
}
/**
* Get a set of (package) snippets from the current source
* @return snippets Collection of ISnippets describing the file
*/
public Snippets getSnippets()
throws NoUnitException {
//Local Variables
ISnippet thisPackageSnippet;
String thisFile;
Iterator loopList;
HashSet availableClasses;
Snippets tmpSnippets;
Snippets packageInfo ;
Snippets classInfo = new Snippets();
ByteCodeClassSnippetFactory myClassFactory;
try {
//Check that the directory is actually
availableClasses = DirectoryWalker.getFiles(innerStartDirectory, ".class");
} catch (IOException ie) {
throw new NoUnitException(ie,"Could not read files from Package");
}
//Now loop through available Classes
loopList = availableClasses.iterator();
while (loopList.hasNext()) {
thisFile = (String)loopList.next();
myClassFactory = new ByteCodeClassSnippetFactory(thisFile);
tmpSnippets = myClassFactory.getSnippets();
classInfo.add(tmpSnippets.getCollection());
}
//Put all this info into one snippet Package
thisPackageSnippet = new SnippetPackage(innerStartDirectory,classInfo);
//Put into (generic) snippets collections
packageInfo = new Snippets();
packageInfo.add(thisPackageSnippet);
return packageInfo ;
}
}
|