001: package net.firstpartners.nounit.ui.common;
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.File;
028: import java.io.FileOutputStream;
029:
030: import net.firstpartners.nounit.reader.bytecode.ByteCodeProjectSnippetFactory;
031: import net.firstpartners.nounit.report.IReport;
032: import net.firstpartners.nounit.report.ReportPicker;
033: import net.firstpartners.nounit.snippet.Snippets;
034: import net.firstpartners.nounit.utility.NoUnitException;
035:
036: import org.jdom.output.XMLOutputter;
037:
038: /**
039: * Do the main processing Java->Xml->XSLT report
040: */
041: public class Processor implements IProcessor {
042:
043: /**
044: * Do the hard work Java->Xml->XSLT report using subclasses
045: * @param inCommandPackage of parameters
046: * @return inCommandPackage with output message
047: */
048: public CommandPackage transform(CommandPackage inCommandPackage)
049: throws NoUnitException {
050:
051: try {
052:
053: //Check for any missing values
054: CommandValueChecker checkArgs = new CommandValueChecker();
055: checkArgs.checkValues(inCommandPackage);
056:
057: //Walk the Package(s) to get the XML
058: ByteCodeProjectSnippetFactory myFactory = new ByteCodeProjectSnippetFactory(
059: inCommandPackage
060: .getString(CommandPackage.START_DIR));
061:
062: Snippets projectInfo = myFactory.getSnippets();
063:
064: //Combine File and Directory
065: String outDir = inCommandPackage
066: .getString(CommandPackage.OUTPUT_DIR);
067: File destination = new File(outDir,
068: SystemValues.XML_OUTPUT_NAME);
069:
070: //Delete file if it's already there
071: if (destination.exists()) {
072: destination.delete();
073: }
074:
075: //Get Handle to file
076: FileOutputStream output = new FileOutputStream(destination);
077:
078: //Output Xml to this stream
079: XMLOutputter fmt = new XMLOutputter(" ", true);
080: fmt.output(projectInfo.getFirstItem().getNodes(), output);
081:
082: //Do the transformation(s)
083: IReport this Report = ReportPicker
084: .getReportMaker(inCommandPackage);
085: this Report.makeReport(inCommandPackage);
086:
087: //Set the output message
088: inCommandPackage.addValue(CommandPackage.USER_MESSAGE,
089: "Transformation Successful");
090:
091: } catch (java.io.IOException ioe) {
092:
093: throw new NoUnitException(ioe, "IO Error");
094:
095: } catch (javax.xml.transform.TransformerException te) {
096:
097: throw new NoUnitException(te, "Transformation Error");
098: }
099:
100: return inCommandPackage;
101: }
102:
103: }
|