KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > ui > command > CommandLineProcessor


1 package net.firstpartners.nounit.ui.command;
2
3 /**
4  * Title: NoUnit - Identify Classes that are not being unit Tested
5  *
6  * Copyright (C) 2001 Paul Browne , FirstPartners.net
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @author Paul Browne
24  * @version 0.7
25  */

26
27 import org.apache.log4j.Logger;
28
29 import net.firstpartners.nounit.ui.common.*;
30 import net.firstpartners.nounit.utility.*;
31
32 /**
33  * Find information about java file / class
34  * and convert to whatever format required
35  * Main entry point into System
36  * @deprecated as @see net.firstpartners.nounit.ant.NoUnitTask takes over most
37  * of the functions
38  */

39 public class CommandLineProcessor {
40
41     //handle to logger
42
static Logger log = Logger.getLogger(CommandLineProcessor.class);
43
44   /**
45    * Get the informaton about the particular class
46    * @param args - key_name , key_value pairs , as per instructions
47    * @deprecated in favour of @see net.firstpartners.nounit.ant.NoUnitTask
48    */

49   public static void main(String JavaDoc[] args)
50         throws NoUnitException {
51    
52             log.debug(""); // blank line before any results
53

54       //Local Variables
55
CommandPackage userArgs;
56       CommandPackage results;
57       Processor mainProcessor = new Processor();
58       
59       //Check for no args
60
if (args.length==0) {
61         log.debug(getInstructions());
62         return;
63       } else {
64         
65           try{
66             
67             //Check for an even number of arguments
68
checkArgsLength(args.length);
69               
70             //Put the Args into a command Package
71
userArgs = new CommandPackage(args);
72
73             //Pass to common processor
74
results = mainProcessor.transform(userArgs);
75
76             //show the result if any
77
log.debug(results.getString(CommandPackage.USER_MESSAGE));
78             
79           } catch (NoUnitException nue) {
80                 
81                 //Print Debugging info
82
nue.printStackTrace();
83                 log.debug("----------------");
84                 Exception JavaDoc e = nue.getOriginalException();
85                 if (e!=null) {
86                     e.printStackTrace();
87                 }
88           }
89       }
90   }
91
92   /**
93    * Get user friendly Instruction Message
94    * @return instructions - String
95    */

96   private static String JavaDoc getInstructions(){
97
98       StringBuffer JavaDoc instructions = new StringBuffer JavaDoc();
99       
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.append("start_dir (directory to start looking for java files)\n");
107       instructions.append("output_dir (directory to output to)\n");
108       instructions.append("report_class (Class to Generate NoUnit Report)\n");
109
110       
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("Please supply an even number of parameters (i.e. key-name key-value)");
136             
137         }
138         
139   }
140   
141 }
Popular Tags