001: package net.firstpartners.nounit.ui.command;
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 org.apache.log4j.Logger;
028:
029: import net.firstpartners.nounit.ui.common.*;
030: import net.firstpartners.nounit.utility.*;
031:
032: /**
033: * Find information about java file / class
034: * and convert to whatever format required
035: * Main entry point into System
036: * @deprecated as @see net.firstpartners.nounit.ant.NoUnitTask takes over most
037: * of the functions
038: */
039: public class CommandLineProcessor {
040:
041: //handle to logger
042: static Logger log = Logger.getLogger(CommandLineProcessor.class);
043:
044: /**
045: * Get the informaton about the particular class
046: * @param args - key_name , key_value pairs , as per instructions
047: * @deprecated in favour of @see net.firstpartners.nounit.ant.NoUnitTask
048: */
049: public static void main(String[] args) throws NoUnitException {
050:
051: log.debug(""); // blank line before any results
052:
053: //Local Variables
054: CommandPackage userArgs;
055: CommandPackage results;
056: Processor mainProcessor = new Processor();
057:
058: //Check for no args
059: if (args.length == 0) {
060: log.debug(getInstructions());
061: return;
062: } else {
063:
064: try {
065:
066: //Check for an even number of arguments
067: checkArgsLength(args.length);
068:
069: //Put the Args into a command Package
070: userArgs = new CommandPackage(args);
071:
072: //Pass to common processor
073: results = mainProcessor.transform(userArgs);
074:
075: //show the result if any
076: log.debug(results
077: .getString(CommandPackage.USER_MESSAGE));
078:
079: } catch (NoUnitException nue) {
080:
081: //Print Debugging info
082: nue.printStackTrace();
083: log.debug("----------------");
084: Exception e = nue.getOriginalException();
085: if (e != null) {
086: e.printStackTrace();
087: }
088: }
089: }
090: }
091:
092: /**
093: * Get user friendly Instruction Message
094: * @return instructions - String
095: */
096: private static String getInstructions() {
097:
098: StringBuffer instructions = new StringBuffer();
099:
100: instructions.append("\n\n");
101: instructions.append("NoUnit Test Coverage Measure\n");
102: instructions.append("============================\n");
103: instructions.append("\n");
104: instructions.append("Parameters: (*) marks optional\n");
105: instructions.append("\n");
106: instructions
107: .append("start_dir (directory to start looking for java files)\n");
108: instructions.append("output_dir (directory to output to)\n");
109: instructions
110: .append("report_class (Class to Generate NoUnit Report)\n");
111:
112: return instructions.toString();
113:
114: }
115:
116: /**
117: * Check the Args length (i.e. make sure come in key-value pairs
118: * @param argsLength - int number of args passed in at the command line
119: * @exception NoUnitException of number of parameters is not even
120: */
121: private static void checkArgsLength(int argsLength)
122: throws NoUnitException {
123:
124: //Local Variables
125: int a;
126:
127: for (a = argsLength; a > 1; a = a - 2) {
128:
129: //Do Nothing , just loop down
130: }
131:
132: //Check results
133: if (a != 0) {
134: //Problem - uneven number of args
135: throw new NoUnitException(
136: "Please supply an even number of parameters (i.e. key-name key-value)");
137:
138: }
139:
140: }
141:
142: }
|