1 64 65 package com.jcorporate.expresso.services.test; 66 67 import java.util.ArrayList ; 68 import java.util.HashMap ; 69 import java.util.StringTokenizer ; 70 71 72 82 public class CommandLineParser { 83 static ArrayList returnValues = new ArrayList (); 84 85 public CommandLineParser() { 86 } 87 88 92 public static String [] parseCommandLine(String [] args) 93 throws Exception { 94 HashMap commandArgs = new HashMap (); 95 96 for (int i = 0; i < args.length; i++) { 97 if (args[i].indexOf("=") > 0) { 98 parseArgv(args[i], commandArgs); 99 } else { 100 returnValues.add(args[i]); 101 } 102 } 103 if (commandArgs.get("configDir") == null) { 104 if (System.getProperty("junit.argv.configDir") == null) { 105 throw new Exception ("missing configDir parameter"); 106 } 107 } else { 108 System.setProperty("junit.argv.configDir", 109 (String ) commandArgs.get("configDir")); 110 } 111 if (commandArgs.get("webAppDir") == null) { 112 if (System.getProperty("junit.argv.webAppDir") == null) { 113 throw new Exception ("missing webAppDir parameter"); 114 } 115 } else { 116 System.setProperty("junit.argv.webAppDir", 117 (String ) commandArgs.get("webAppDir")); 118 } 119 if (returnValues.isEmpty()) { 120 return null; 121 } else { 122 Object [] tempValues = returnValues.toArray(); 123 String [] values = new String [tempValues.length]; 124 125 130 for (int i = 0; i < tempValues.length; i++) { 131 values[i] = (String ) tempValues[i]; 132 } 133 134 return values; 135 } 136 } 137 138 144 protected static void parseArgv(String argv, HashMap commandArgs) { 145 String paramCode = null; 146 String paramValue = null; 147 StringTokenizer stk = new StringTokenizer (argv, "="); 148 149 if (!stk.hasMoreTokens()) { 150 return; 151 } 152 153 paramCode = stk.nextToken(); 154 155 if (!stk.hasMoreTokens()) { 156 return; 157 } 158 159 paramValue = stk.nextToken(); 160 commandArgs.put(paramCode, paramValue); 161 } 162 163 } | Popular Tags |