1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package helper; 24 25 import java.io.File; 26 import java.util.Properties; 27 28 import lib.TestParameters; 29 import util.PropertyName; 30 import util.utils; 31 32 /** 33 * This class parses commandline Argument and stores <br> 34 * them into TestParameter 35 */ 36 public class ClParser 37 { 38 /* 39 * Parses the commandline argument and puts them<br> 40 * into the TestParameters 41 */ 42 getCommandLineParameter(TestParameters param, String[] args)43 public void getCommandLineParameter(TestParameters param, String[] args) 44 { 45 Properties mapping = getMapping(); 46 47 for (int i = 0; i < args.length;) 48 { 49 String pName = getParameterFor(mapping, args[i]).trim(); 50 String pValue = ""; 51 if (pName.equals("TestJob")) 52 { 53 if (args.length > (i + 1)) 54 { 55 pValue = args[i].trim() + " " + args[i + 1].trim(); 56 i += 2; 57 } 58 else 59 { 60 pValue = args[i].trim() + " unknown"; 61 i += 2; 62 } 63 } 64 else 65 { 66 if ((i + 1) < args.length) 67 { 68 pValue = args[i + 1].trim(); 69 70 if (pValue.startsWith("-")) 71 { 72 i++; 73 pValue = "yes"; 74 } 75 else if (pValue.startsWith("'")) 76 { 77 i++; 78 while (!pValue.endsWith("'")) 79 { 80 i++; 81 pValue = pValue + " " + args[i].trim(); 82 83 } 84 pValue = utils.replaceAll13(pValue, "'", ""); 85 i++; 86 } 87 else 88 { 89 i += 2; 90 } 91 92 if (pName.equals("TestDocumentPath")) 93 { 94 System.setProperty( 95 "DOCPTH", new File(pValue).getAbsolutePath()); 96 } 97 else if (pName.equals(PropertyName.SRC_ROOT)) 98 { 99 System.setProperty(pName, pValue); 100 101 } 102 } 103 else 104 { 105 pValue = "yes"; 106 i++; 107 } 108 } 109 110 param.put(pName, pValue); 111 } 112 } 113 114 /* 115 * This method returns the path to a Configuration file <br> 116 * if defined as command line parameter, an empty String elsewhere 117 */ getIniPath(String[] args)118 public String getIniPath(String[] args) 119 { 120 String iniFile = ""; 121 122 for (int i = 0; i < args.length; i++) 123 { 124 if (args[i].equals("-ini")) 125 { 126 iniFile = args[i + 1]; 127 break; 128 } 129 } 130 131 return iniFile; 132 } 133 134 /* 135 * This method returns the path to a Configuration file <br> 136 * if defined as command line parameter, an empty String elsewhere 137 */ getRunnerIniPath(String[] args)138 public String getRunnerIniPath(String[] args) 139 { 140 String iniFile = ""; 141 142 for (int i = 0; i < args.length; i++) 143 { 144 if (args[i].equals("-runnerini")) 145 { 146 iniFile = args[i + 1]; 147 break; 148 } 149 } 150 151 return iniFile; 152 } 153 154 /* 155 * This method maps commandline Parameters to TestParameters 156 */ getMapping()157 protected Properties getMapping() 158 { 159 Properties map = new Properties(); 160 map.setProperty("-cs", "ConnectionString"); 161 map.setProperty("-tb", "TestBase"); 162 map.setProperty("-tdoc", "TestDocumentPath"); 163 map.setProperty("-objdsc", "DescriptionPath"); 164 map.setProperty("-cmd", "AppExecutionCommand"); 165 map.setProperty("-o", "TestJob"); 166 map.setProperty("-sce", "TestJob"); 167 map.setProperty("-p", "TestJob"); 168 map.setProperty("-aca", "AdditionalConnectionArguments"); 169 map.setProperty("-xcl", "ExclusionList"); 170 map.setProperty("-debug", "DebugIsActive"); 171 map.setProperty("-log", "LoggingIsActive"); 172 map.setProperty("-dbout", "DataBaseOut"); 173 map.setProperty("-nca", "NoCwsAttach"); 174 175 return map; 176 } 177 getParameterFor(Properties map, String name)178 protected String getParameterFor(Properties map, String name) 179 { 180 String ret = map.getProperty(name); 181 182 if (ret == null) 183 { 184 ret = name.substring(1); 185 } 186 187 return ret; 188 } 189 }