1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package helper; 28 29 import java.io.File; 30 import java.util.Properties; 31 32 import lib.TestParameters; 33 import util.PropertyName; 34 import util.utils; 35 36 /** 37 * This class parses commandline Argument and stores <br> 38 * them into TestParameter 39 */ 40 public class ClParser 41 { 42 /* 43 * Parses the commandline argument and puts them<br> 44 * into the TestParameters 45 */ 46 47 public void getCommandLineParameter(TestParameters param, String[] args) 48 { 49 Properties mapping = getMapping(); 50 51 for (int i = 0; i < args.length;) 52 { 53 String pName = getParameterFor(mapping, args[i]).trim(); 54 String pValue = ""; 55 if (pName.equals("TestJob")) 56 { 57 if (args.length > (i + 1)) 58 { 59 pValue = args[i].trim() + " " + args[i + 1].trim(); 60 i += 2; 61 } 62 else 63 { 64 pValue = args[i].trim() + " unknown"; 65 i += 2; 66 } 67 } 68 else 69 { 70 if ((i + 1) < args.length) 71 { 72 pValue = args[i + 1].trim(); 73 74 if (pValue.startsWith("-")) 75 { 76 i++; 77 pValue = "yes"; 78 } 79 else if (pValue.startsWith("'")) 80 { 81 i++; 82 while (!pValue.endsWith("'")) 83 { 84 i++; 85 pValue = pValue + " " + args[i].trim(); 86 87 } 88 pValue = utils.replaceAll13(pValue, "'", ""); 89 i++; 90 } 91 else 92 { 93 i += 2; 94 } 95 96 if (pName.equals("TestDocumentPath")) 97 { 98 System.setProperty( 99 "DOCPTH", new File(pValue).getAbsolutePath()); 100 } 101 else if (pName.equals(PropertyName.SRC_ROOT)) 102 { 103 System.setProperty(pName, pValue); 104 105 } 106 } 107 else 108 { 109 pValue = "yes"; 110 i++; 111 } 112 } 113 114 param.put(pName, pValue); 115 } 116 } 117 118 /* 119 * This method returns the path to a Configuration file <br> 120 * if defined as command line parameter, an empty String elsewhere 121 */ 122 public String getIniPath(String[] args) 123 { 124 String iniFile = ""; 125 126 for (int i = 0; i < args.length; i++) 127 { 128 if (args[i].equals("-ini")) 129 { 130 iniFile = args[i + 1]; 131 break; 132 } 133 } 134 135 return iniFile; 136 } 137 138 /* 139 * This method returns the path to a Configuration file <br> 140 * if defined as command line parameter, an empty String elsewhere 141 */ 142 public String getRunnerIniPath(String[] args) 143 { 144 String iniFile = ""; 145 146 for (int i = 0; i < args.length; i++) 147 { 148 if (args[i].equals("-runnerini")) 149 { 150 iniFile = args[i + 1]; 151 break; 152 } 153 } 154 155 return iniFile; 156 } 157 158 /* 159 * This method maps commandline Parameters to TestParameters 160 */ 161 protected Properties getMapping() 162 { 163 Properties map = new Properties(); 164 map.setProperty("-cs", "ConnectionString"); 165 map.setProperty("-tb", "TestBase"); 166 map.setProperty("-tdoc", "TestDocumentPath"); 167 map.setProperty("-objdsc", "DescriptionPath"); 168 map.setProperty("-cmd", "AppExecutionCommand"); 169 map.setProperty("-o", "TestJob"); 170 map.setProperty("-sce", "TestJob"); 171 map.setProperty("-p", "TestJob"); 172 map.setProperty("-aca", "AdditionalConnectionArguments"); 173 map.setProperty("-xcl", "ExclusionList"); 174 map.setProperty("-debug", "DebugIsActive"); 175 map.setProperty("-log", "LoggingIsActive"); 176 map.setProperty("-dbout", "DataBaseOut"); 177 map.setProperty("-nca", "NoCwsAttach"); 178 179 return map; 180 } 181 182 protected String getParameterFor(Properties map, String name) 183 { 184 String ret = map.getProperty(name); 185 186 if (ret == null) 187 { 188 ret = name.substring(1); 189 } 190 191 return ret; 192 } 193 }