PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/libreoffice-3.6.0.2/qadevOOo/runner/helper/ClParser.java

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