/** * Retrieve the {@link CLOption} with specified id, or <code>null</code> * if no command line option is found. * * @param id * the command line option id * @return the {@link CLOption} with the specified id, or <code>null</code> * if no CLOption is found. * @see CLOption */ public CLOption GetArgumentById(int id) { CLOption option = null; m_optionIndex.TryGetValue(id, out option); return(option); }
/** * Retrieve the {@link CLOption} with specified name, or <code>null</code> * if no command line option is found. * * @param name * the command line option name * @return the {@link CLOption} with the specified name, or * <code>null</code> if no CLOption is found. * @see CLOption */ public CLOption GetArgumentByName(String name) { CLOption option = null; m_optionIndex.TryGetValue(name, out option); return(option); }
private void ParseOption(CLOptionDescriptor descriptor, String optionString) { if (null == descriptor) { throw new Exception("Unknown option " + optionString); } m_state = GetStateFor(descriptor); m_option = new CLOption(descriptor); if (STATE_NORMAL == m_state) { AddOption(m_option); } }
/** * Check for duplicates of an option. It is an error to have duplicates * unless appropriate flags is set in descriptor. * * @param arguments * the arguments */ private void CheckIncompatibilities(List <CLOption> arguments) { int size = arguments.Count; for (int i = 0; i < size; i++) { CLOption option = arguments[i]; int id = option.GetDescriptor().GetId(); CLOptionDescriptor descriptor = GetDescriptorFor(id); // this occurs when id == 0 and user has not supplied a descriptor // for arguments if (null == descriptor) { continue; } int[] incompatible = descriptor.GetIncompatible(); CheckIncompatible(arguments, incompatible, i); } }
private void CheckIncompatible(List <CLOption> arguments, int[] incompatible, int original) { int size = arguments.Count; for (int i = 0; i < size; i++) { if (original == i) { continue; } CLOption option = arguments[i]; int id = option.GetDescriptor().GetId(); for (int j = 0; j < incompatible.Length; j++) { if (id == incompatible[j]) { CLOption originalOption = arguments[original]; int originalId = originalOption.GetDescriptor().GetId(); String message = null; if (id == originalId) { message = "Duplicate options for " + DescribeDualOption(originalId) + " found."; } else { message = "Incompatible options -" + DescribeDualOption(id) + " and " + DescribeDualOption(originalId) + " found."; } throw new Exception(message); } } } }
private void ParseArguments() { if (STATE_REQUIRE_ARG == m_state) { if ('=' == m_ch || 0 == m_ch) { GetChar(); } Token token = NextToken(NULL_SEPARATORS); m_option.AddArgument(token.GetValue()); AddOption(m_option); m_state = STATE_NORMAL; } else if (STATE_OPTIONAL_ARG == m_state) { if ('-' == m_ch || 0 == m_ch) { GetChar(); // consume stray character AddOption(m_option); m_state = STATE_NORMAL; return; } if (m_isLong && '=' != m_tokesep) { // Long optional arg must have = as separator AddOption(m_option); m_state = STATE_NORMAL; return; } if ('=' == m_ch) { GetChar(); } Token token = NextToken(NULL_SEPARATORS); m_option.AddArgument(token.GetValue()); AddOption(m_option); m_state = STATE_NORMAL; } else if (STATE_REQUIRE_2ARGS == m_state) { if (0 == m_option.GetArgumentCount()) { /* * Fix bug: -D arg1=arg2 was causing parse error; however * --define arg1=arg2 is OK This seems to be because the parser * skips the terminator for the long options, but was not doing * so for the short options. */ if (!m_isLong) { if (0 == PeekAtChar()) { GetChar(); } } Token token = NextToken(ARG_SEPARATORS); if (TOKEN_SEPARATOR == token.GetType()) { CLOptionDescriptor descriptor = GetDescriptorFor(m_option.GetDescriptor().GetId()); String message = "Unable to parse first argument for option " + GetOptionDescription(descriptor); throw new Exception(message); } else { m_option.AddArgument(token.GetValue()); } // Are we about to start a new option? if (0 == m_ch && '-' == PeekAtChar()) { // Yes, so the second argument is missing m_option.AddArgument(""); m_options.Add(m_option); m_state = STATE_NORMAL; } } else // 2nd argument { StringBuilder sb = new StringBuilder(); m_ch = GetChar(); while (!isSeparator(m_ch, NULL_SEPARATORS)) { sb.Append(m_ch); m_ch = GetChar(); } String argument = sb.ToString(); // System.out.println( "Arguement:" + argument ); m_option.AddArgument(argument); AddOption(m_option); m_option = null; m_state = STATE_NORMAL; } } }
private void AddOption(CLOption option) { m_options.Add(option); m_lastOptionId = option.GetDescriptor().GetId(); m_option = null; }
// Update classloader if necessary //private void updateClassLoader() //{ // updatePath("search_paths",";"); //$NON-NLS-1$//$NON-NLS-2$ // updatePath("user.classpath",File.pathSeparator);//$NON-NLS-1$ //} //private void updatePath(String property, String sep) //{ // String userpath= NetMeterUtils.getPropDefault(property,"");// $NON-NLS-1$ // if (userpath.Length <= 0) { return; } // log.Info(property+"="+userpath); //$NON-NLS-1$ // StringTokenizer tok = new StringTokenizer(userpath, sep); // while(tok.hasMoreTokens()) // { // String path=tok.nextToken(); // File f=new File(path); // if (!f.canRead() && !f.isDirectory()) // { // log.Warn("Can't read "+path); // } // else // { // log.Info("Adding to classpath: "+path); // try // { // NewDriver.addPath(path); // } // catch (MalformedURLException e) // { // log.Warn("Error adding: "+path+" "+e.getLocalizedMessage()); // } // } // } //} //private void initializeProperties(CLArgsParser parser) //{ // if (parser.GetArgumentById(PROPFILE_OPT) != null) // { // NetMeterUtils.loadJMeterProperties(parser.GetArgumentById(PROPFILE_OPT).GetArgument()); // } // else // { // NetMeterUtils.loadJMeterProperties(NewDriver.getJMeterDir() + File.separator // + "bin" + File.separator // $NON-NLS-1$ // + "jmeter.properties");// $NON-NLS-1$ // } // if (parser.GetArgumentById(JMLOGFILE_OPT) != null){ // String jmlogfile=parser.GetArgumentById(JMLOGFILE_OPT).GetArgument(); // jmlogfile = processLAST(jmlogfile, ".log");// $NON-NLS-1$ // NetMeterUtils.setProperty(LoggingManager.LOG_FILE,jmlogfile); // } // NetMeterUtils.initLogging(); // // Bug 33845 - allow direct override of Home dir // if (parser.GetArgumentById(JMETER_HOME_OPT) == null) { // NetMeterUtils.setJMeterHome(NewDriver.getJMeterDir()); // } else { // NetMeterUtils.setJMeterHome(parser.GetArgumentById(JMETER_HOME_OPT).GetArgument()); // } // Properties jmeterProps = NetMeterUtils.getJMeterProperties(); // remoteProps = new Properties(); // // Add local JMeter properties, if the file is found // String userProp = NetMeterUtils.getPropDefault("user.properties",""); //$NON-NLS-1$ // if (userProp.length() > 0){ //$NON-NLS-1$ // FileInputStream fis=null; // try { // File file = NetMeterUtils.findFile(userProp); // if (file.canRead()){ // log.Info("Loading user properties from: "+file.getCanonicalPath()); // fis = new FileInputStream(file); // Properties tmp = new Properties(); // tmp.load(fis); // jmeterProps.putAll(tmp); // LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier // } // } // catch (IOException e) // { // log.Warn("Error loading user property file: " + userProp, e); // } // finally // { // JOrphanUtils.closeQuietly(fis); // } // } // // Add local system properties, if the file is found // String sysProp = NetMeterUtils.getPropDefault("system.properties",""); //$NON-NLS-1$ // if (sysProp.length() > 0) // { // FileInputStream fis=null; // try // { // File file = NetMeterUtils.findFile(sysProp); // if (file()) // { // log.Info("Loading system properties from: "+file.getCanonicalPath()); // fis = new FileInputStream(file); // System.getProperties().load(fis); // } // } // catch (IOException e) // { // log.Warn("Error loading system property file: " + sysProp, e); // } finally { // JOrphanUtils.closeQuietly(fis); // } // } // // Process command line property definitions // // These can potentially occur multiple times // List<CLOption> clOptions = parser.GetArguments(); // int size = clOptions.Count; // for (int i = 0; i < size; i++) // { // CLOption option = clOptions[i]; // String name = option.GetArgument(0); // String value = option.GetArgument(1); // FileInputStream fis = null; // switch (option.GetDescriptor().GetId()) // { // // Should not have any text arguments // case CLOption.TEXT_ARGUMENT: // throw new IllegalArgumentException("Unknown arg: "+option.GetArgument()); // case PROPFILE2_OPT: // Bug 33920 - allow multiple props // try // { // fis = new FileInputStream(new File(name)); // Properties tmp = new Properties(); // tmp.load(fis); // jmeterProps.putAll(tmp); // LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier // } // catch (FileNotFoundException e) // { // log.Warn("Can't find additional property file: " + name, e); // } // catch (IOException e) // { // log.Warn("Error loading additional property file: " + name, e); // } // finally // { // JOrphanUtils.closeQuietly(fis); // } // break; // case SYSTEM_PROPFILE: // log.Info("Setting System properties from file: " + name); // try // { // fis = new FileInputStream(new File(name)); // System.getProperties().load(fis); // } // catch (IOException e) // { // log.Warn("Cannot find system property file "+e.getLocalizedMessage()); // } // finally // { // JOrphanUtils.closeQuietly(fis); // } // break; // case SYSTEM_PROPERTY: // if (value.length() > 0) // { // Set it // log.Info("Setting System property: " + name + "=" + value); // System.getProperties().setProperty(name, value); // } // else // { // Reset it // log.Warn("Removing System property: " + name); // System.getProperties().remove(name); // } // break; // case JMETER_PROPERTY: // if (value.length() > 0) { // Set it // log.Info("Setting JMeter property: " + name + "=" + value); // jmeterProps.setProperty(name, value); // } else { // Reset it // log.Warn("Removing JMeter property: " + name); // jmeterProps.remove(name); // } // break; // case JMETER_GLOBAL_PROP: // if (value.length() > 0) { // Set it // log.Info("Setting Global property: " + name + "=" + value); // remoteProps.setProperty(name, value); // } else { // File propFile = new File(name); // if (propFile.canRead()) { // log.Info("Setting Global properties from the file " + name); // try // { // fis = new FileInputStream(propFile); // remoteProps.load(fis); // } // catch (FileNotFoundException e) // { // log.Warn("Could not find properties file: "+e.Message); // } // catch (IOException e) // { // log.Warn("Could not load properties file: " + e.Message); // } // finally // { // JOrphanUtils.closeQuietly(fis); // } // } // } // break; // case LOGLEVEL: // if (value.Length > 0) // { // Set category // log.Info("LogLevel: " + name + "=" + value); // LoggingManager.setPriority(value, name); // } else { // Set root level // log.Warn("LogLevel: " + name); // LoggingManager.setPriority(name); // } // break; // case REMOTE_STOP: // remoteStop = true; // break; // default: // // ignored // break; // } // } // String sample_variables = (String) jmeterProps.get(SampleEvent.SAMPLE_VARIABLES); // if (sample_variables != null){ // remoteProps.put(SampleEvent.SAMPLE_VARIABLES, sample_variables); // } // jmeterProps.put("jmeter.version", NetMeterUtils.getJMeterVersion()); //} /* * Checks for LAST or LASTsuffix. * Returns the LAST name with .JMX replaced by suffix. */ //private String processLAST(String jmlogfile, String suffix) //{ // if (USE_LAST_JMX.Equals(jmlogfile) || USE_LAST_JMX.concat(suffix).equals(jmlogfile)){ // String last = LoadRecentProject.getRecentFile(0);// most recent // String JMX_SUFFIX = ".JMX"; // $NON-NLS-1$ // if (last.ToUpper().EndsWith(JMX_SUFFIX)) // { // jmlogfile = last.Substring(0, last.Length - JMX_SUFFIX.Length).concat(suffix); // } // } // return jmlogfile; //} private void StartTest(String testFile, String logFile, CLOption remoteStart) { // add a system property so samplers can check to see if JMeter // is running in NonGui mode //System.setProperty(JMETER_NON_GUI, "true");// $NON-NLS-1$ NetMeterServer driver = new NetMeterServer();// TODO - why does it create a new instance? driver.remoteProps = this.remoteProps; driver.remoteStop = this.remoteStop; driver.parent = this; String remote_hosts_string = null; if (remoteStart != null) { remote_hosts_string = remoteStart.GetArgument(); if (remote_hosts_string == null) { remote_hosts_string = "127.0.0.1"; } } if (testFile == null) { throw new Exception("Non-GUI runs require a test plan"); } driver.RunTest(testFile, logFile, remoteStart != null, remote_hosts_string); }