PageRenderTime 72ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/qadevOOo/runner/helper/ClParser.java

https://bitbucket.org/mst/ooo340
Java | 191 lines | 125 code | 21 blank | 45 comment | 17 complexity | 47934a9dfef5d0ceb0c0e99dc631d9d9 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
  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. import java.util.Properties;
  29. import lib.TestParameters;
  30. import util.PropertyName;
  31. import util.utils;
  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. public void getCommandLineParameter(TestParameters param, String[] args)
  43. {
  44. Properties mapping = getMapping();
  45. for (int i = 0; i < args.length;)
  46. {
  47. String pName = getParameterFor(mapping, args[i]).trim();
  48. String pValue = "";
  49. if (pName.equals("TestJob"))
  50. {
  51. if (args.length > (i + 1))
  52. {
  53. pValue = args[i].trim() + " " + args[i + 1].trim();
  54. i += 2;
  55. }
  56. else
  57. {
  58. pValue = args[i].trim() + " unknown";
  59. i += 2;
  60. }
  61. }
  62. else
  63. {
  64. if ((i + 1) < args.length)
  65. {
  66. pValue = args[i + 1].trim();
  67. if (pValue.startsWith("-"))
  68. {
  69. i++;
  70. pValue = "yes";
  71. }
  72. else if (pValue.startsWith("'"))
  73. {
  74. i++;
  75. while (!pValue.endsWith("'"))
  76. {
  77. i++;
  78. pValue = pValue + " " + args[i].trim();
  79. }
  80. pValue = utils.replaceAll13(pValue, "'", "");
  81. i++;
  82. }
  83. else
  84. {
  85. i += 2;
  86. }
  87. if (pName.equals("TestDocumentPath"))
  88. {
  89. System.setProperty("DOCPTH", pValue);
  90. }
  91. else if (pName.equals(PropertyName.SRC_ROOT))
  92. {
  93. System.setProperty(pName, pValue);
  94. }
  95. }
  96. else
  97. {
  98. pValue = "yes";
  99. i++;
  100. }
  101. }
  102. param.put(pName, pValue);
  103. }
  104. }
  105. /*
  106. * This method returns the path to a Configuration file <br>
  107. * if defined as command line parameter, an empty String elsewhere
  108. */
  109. public String getIniPath(String[] args)
  110. {
  111. String iniFile = "";
  112. for (int i = 0; i < args.length; i++)
  113. {
  114. if (args[i].equals("-ini"))
  115. {
  116. iniFile = args[i + 1];
  117. break;
  118. }
  119. }
  120. return iniFile;
  121. }
  122. /*
  123. * This method returns the path to a Configuration file <br>
  124. * if defined as command line parameter, an empty String elsewhere
  125. */
  126. public String getRunnerIniPath(String[] args)
  127. {
  128. String iniFile = "";
  129. for (int i = 0; i < args.length; i++)
  130. {
  131. if (args[i].equals("-runnerini"))
  132. {
  133. iniFile = args[i + 1];
  134. break;
  135. }
  136. }
  137. return iniFile;
  138. }
  139. /*
  140. * This method maps commandline Parameters to TestParameters
  141. */
  142. protected Properties getMapping()
  143. {
  144. Properties map = new Properties();
  145. map.setProperty("-cs", "ConnectionString");
  146. map.setProperty("-tb", "TestBase");
  147. map.setProperty("-tdoc", "TestDocumentPath");
  148. map.setProperty("-objdsc", "DescriptionPath");
  149. map.setProperty("-cmd", "AppExecutionCommand");
  150. map.setProperty("-o", "TestJob");
  151. map.setProperty("-sce", "TestJob");
  152. map.setProperty("-p", "TestJob");
  153. map.setProperty("-aca", "AdditionalConnectionArguments");
  154. map.setProperty("-xcl", "ExclusionList");
  155. map.setProperty("-debug", "DebugIsActive");
  156. map.setProperty("-log", "LoggingIsActive");
  157. map.setProperty("-dbout", "DataBaseOut");
  158. map.setProperty("-nca", "NoCwsAttach");
  159. return map;
  160. }
  161. protected String getParameterFor(Properties map, String name)
  162. {
  163. String ret = map.getProperty(name);
  164. if (ret == null)
  165. {
  166. ret = name.substring(1);
  167. }
  168. return ret;
  169. }
  170. }