<commit_before>/*
 * Copyright 2000-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.jmeter;

import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.StringTokenizer;

import org.apache.commons.cli.avalon.CLArgsParser;
import org.apache.commons.cli.avalon.CLOption;
import org.apache.commons.cli.avalon.CLOptionDescriptor;
import org.apache.commons.cli.avalon.CLUtil;
import org.apache.jmeter.config.gui.AbstractConfigGui;
import org.apache.jmeter.control.gui.AbstractControllerGui;
import org.apache.jmeter.control.gui.TestPlanGui;
import org.apache.jmeter.control.gui.WorkBenchGui;
import org.apache.jmeter.engine.ClientJMeterEngine;
import org.apache.jmeter.engine.JMeterEngine;
import org.apache.jmeter.engine.RemoteJMeterEngineImpl;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.exceptions.IllegalUserActionException;
import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.action.ActionRouter;
import org.apache.jmeter.gui.action.CheckDirty;
import org.apache.jmeter.gui.action.Load;
import org.apache.jmeter.gui.tree.JMeterTreeListener;
import org.apache.jmeter.gui.tree.JMeterTreeModel;
import org.apache.jmeter.plugin.JMeterPlugin;
import org.apache.jmeter.plugin.PluginManager;
// import org.apache.jmeter.processor.gui.AbstractPostProcessorGui;
// import org.apache.jmeter.processor.gui.AbstractPreProcessorGui;
import org.apache.jmeter.reporters.ResultCollector;
import org.apache.jmeter.reporters.Summariser;
import org.apache.jmeter.samplers.Remoteable;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.services.FileServer;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestListener;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.gui.ThreadGroupGui;
import org.apache.jmeter.timers.gui.AbstractTimerGui;
import org.apache.jmeter.util.BeanShellServer;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.gui.ComponentUtil;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.jorphan.util.JOrphanUtils;
import org.apache.log.Logger;

import com.thoughtworks.xstream.converters.ConversionException;

/**
 * @author mstover
 */
public class JMeter implements JMeterPlugin {
	transient private static Logger log = LoggingManager.getLoggerForClass();

	private static final int PROPFILE_OPT = 'p';

	private static final int PROPFILE2_OPT = 'q'; // Bug 33920 - additional
													// prop files

	private static final int TESTFILE_OPT = 't';

	private static final int LOGFILE_OPT = 'l';

	private static final int NONGUI_OPT = 'n';

	private static final int HELP_OPT = 'h';

	private static final int VERSION_OPT = 'v';

	private static final int SERVER_OPT = 's';

	private static final int PROXY_HOST = 'H';

	private static final int PROXY_PORT = 'P';

	private static final int PROXY_USERNAME = 'u';

	private static final int PROXY_PASSWORD = 'a';

	private static final int JMETER_PROPERTY = 'J';

	private static final int SYSTEM_PROPERTY = 'D';

	private static final int LOGLEVEL = 'L';

	private static final int REMOTE_OPT = 'r';

	private static final int JMETER_HOME_OPT = 'd';

	/**
	 * Define the understood options. Each CLOptionDescriptor contains:
	 * <ul>
	 * <li>The "long" version of the option. Eg, "help" means that "--help"
	 * will be recognised.</li>
	 * <li>The option flags, governing the option's argument(s).</li>
	 * <li>The "short" version of the option. Eg, 'h' means that "-h" will be
	 * recognised.</li>
	 * <li>A description of the option.</li>
	 * </ul>
	 */
	private static final CLOptionDescriptor[] options = new CLOptionDescriptor[] {
			new CLOptionDescriptor("help", CLOptionDescriptor.ARGUMENT_DISALLOWED, HELP_OPT,
					"print usage information and exit"),
			new CLOptionDescriptor("version", CLOptionDescriptor.ARGUMENT_DISALLOWED, VERSION_OPT,
					"print the version information and exit"),
			new CLOptionDescriptor("propfile", CLOptionDescriptor.ARGUMENT_REQUIRED, PROPFILE_OPT,
					"the jmeter property file to use"),
			new CLOptionDescriptor("addprop", CLOptionDescriptor.ARGUMENT_REQUIRED
					| CLOptionDescriptor.DUPLICATES_ALLOWED, // Bug 33920 -
																// allow
																// multiple
																// props
					PROPFILE2_OPT, "additional property file(s)"),
			new CLOptionDescriptor("testfile", CLOptionDescriptor.ARGUMENT_REQUIRED, TESTFILE_OPT,
					"the jmeter test(.jmx) file to run"),
			new CLOptionDescriptor("logfile", CLOptionDescriptor.ARGUMENT_REQUIRED, LOGFILE_OPT,
					"the file to log samples to"),
			new CLOptionDescriptor("nongui", CLOptionDescriptor.ARGUMENT_DISALLOWED, NONGUI_OPT,
					"run JMeter in nongui mode"),
			new CLOptionDescriptor("server", CLOptionDescriptor.ARGUMENT_DISALLOWED, SERVER_OPT,
					"run the JMeter server"),
			new CLOptionDescriptor("proxyHost", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_HOST,
					"Set a proxy server for JMeter to use"),
			new CLOptionDescriptor("proxyPort", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_PORT,
					"Set proxy server port for JMeter to use"),
			new CLOptionDescriptor("username", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_USERNAME,
					"Set username for proxy server that JMeter is to use"),
			new CLOptionDescriptor("password", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_PASSWORD,
					"Set password for proxy server that JMeter is to use"),
			new CLOptionDescriptor("jmeterproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
					| CLOptionDescriptor.ARGUMENTS_REQUIRED_2, JMETER_PROPERTY, "Define additional JMeter properties"),
			new CLOptionDescriptor("systemproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
					| CLOptionDescriptor.ARGUMENTS_REQUIRED_2, SYSTEM_PROPERTY, "Define additional JMeter properties"),
			new CLOptionDescriptor("loglevel", CLOptionDescriptor.DUPLICATES_ALLOWED
					| CLOptionDescriptor.ARGUMENTS_REQUIRED_2, LOGLEVEL,
					"Define loglevel: [category=]level e.g. jorphan=INFO or " + "jmeter.util=DEBUG"),
			new CLOptionDescriptor("runremote", CLOptionDescriptor.ARGUMENT_DISALLOWED, REMOTE_OPT,
					"Start remote servers from non-gui mode"),
			new CLOptionDescriptor("homedir", CLOptionDescriptor.ARGUMENT_REQUIRED, JMETER_HOME_OPT,
					"the jmeter home directory to use"), };

	public JMeter() {
	}

	// Hack to allow automated tests to find when test has ended
	//transient boolean testEnded = false;

	private JMeter parent;

	/**
	 * Starts up JMeter in GUI mode
	 */
	public void startGui(CLOption testFile) {

		PluginManager.install(this, true);
		JMeterTreeModel treeModel = new JMeterTreeModel();
		JMeterTreeListener treeLis = new JMeterTreeListener(treeModel);
		treeLis.setActionHandler(ActionRouter.getInstance());
		// NOTUSED: GuiPackage guiPack =
		GuiPackage.getInstance(treeLis, treeModel);
		org.apache.jmeter.gui.MainFrame main = new org.apache.jmeter.gui.MainFrame(ActionRouter.getInstance(),
				treeModel, treeLis);
		main.setTitle("Apache JMeter");
		main.setIconImage(JMeterUtils.getImage("jmeter.jpg").getImage());
		ComponentUtil.centerComponentInWindow(main, 80);
		main.show();
		ActionRouter.getInstance().actionPerformed(new ActionEvent(main, 1, CheckDirty.ADD_ALL));
		if (testFile != null) {
			try {
				File f = new File(testFile.getArgument());
				log.info("Loading file: " + f);
				FileInputStream reader = new FileInputStream(f);
				HashTree tree = SaveService.loadTree(reader);

				GuiPackage.getInstance().setTestPlanFile(f.getAbsolutePath());

				new Load().insertLoadedTree(1, tree);
            } catch (ConversionException e) {
                log.error("Failure loading test file", e);
                JMeterUtils.reportErrorToUser(SaveService.CEtoString(e));
			} catch (Exception e) {<commit_msg>Action names are now all in ActionNames class<commit_after>/*
 * Copyright 2000-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.jmeter;

import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.StringTokenizer;

import org.apache.commons.cli.avalon.CLArgsParser;
import org.apache.commons.cli.avalon.CLOption;
import org.apache.commons.cli.avalon.CLOptionDescriptor;
import org.apache.commons.cli.avalon.CLUtil;
import org.apache.jmeter.config.gui.AbstractConfigGui;
import org.apache.jmeter.control.gui.AbstractControllerGui;
import org.apache.jmeter.control.gui.TestPlanGui;
import org.apache.jmeter.control.gui.WorkBenchGui;
import org.apache.jmeter.engine.ClientJMeterEngine;
import org.apache.jmeter.engine.JMeterEngine;
import org.apache.jmeter.engine.RemoteJMeterEngineImpl;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.exceptions.IllegalUserActionException;
import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.action.ActionNames;
import org.apache.jmeter.gui.action.ActionRouter;
import org.apache.jmeter.gui.action.Load;
import org.apache.jmeter.gui.tree.JMeterTreeListener;
import org.apache.jmeter.gui.tree.JMeterTreeModel;
import org.apache.jmeter.plugin.JMeterPlugin;
import org.apache.jmeter.plugin.PluginManager;
// import org.apache.jmeter.processor.gui.AbstractPostProcessorGui;
// import org.apache.jmeter.processor.gui.AbstractPreProcessorGui;
import org.apache.jmeter.reporters.ResultCollector;
import org.apache.jmeter.reporters.Summariser;
import org.apache.jmeter.samplers.Remoteable;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.services.FileServer;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestListener;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.gui.ThreadGroupGui;
import org.apache.jmeter.timers.gui.AbstractTimerGui;
import org.apache.jmeter.util.BeanShellServer;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.gui.ComponentUtil;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.jorphan.util.JOrphanUtils;
import org.apache.log.Logger;

import com.thoughtworks.xstream.converters.ConversionException;

/**
 * @author mstover
 */
public class JMeter implements JMeterPlugin {
	transient private static Logger log = LoggingManager.getLoggerForClass();

	private static final int PROPFILE_OPT = 'p';

	private static final int PROPFILE2_OPT = 'q'; // Bug 33920 - additional
													// prop files

	private static final int TESTFILE_OPT = 't';

	private static final int LOGFILE_OPT = 'l';

	private static final int NONGUI_OPT = 'n';

	private static final int HELP_OPT = 'h';

	private static final int VERSION_OPT = 'v';

	private static final int SERVER_OPT = 's';

	private static final int PROXY_HOST = 'H';

	private static final int PROXY_PORT = 'P';

	private static final int PROXY_USERNAME = 'u';

	private static final int PROXY_PASSWORD = 'a';

	private static final int JMETER_PROPERTY = 'J';

	private static final int SYSTEM_PROPERTY = 'D';

	private static final int LOGLEVEL = 'L';

	private static final int REMOTE_OPT = 'r';

	private static final int JMETER_HOME_OPT = 'd';

	/**
	 * Define the understood options. Each CLOptionDescriptor contains:
	 * <ul>
	 * <li>The "long" version of the option. Eg, "help" means that "--help"
	 * will be recognised.</li>
	 * <li>The option flags, governing the option's argument(s).</li>
	 * <li>The "short" version of the option. Eg, 'h' means that "-h" will be
	 * recognised.</li>
	 * <li>A description of the option.</li>
	 * </ul>
	 */
	private static final CLOptionDescriptor[] options = new CLOptionDescriptor[] {
			new CLOptionDescriptor("help", CLOptionDescriptor.ARGUMENT_DISALLOWED, HELP_OPT,
					"print usage information and exit"),
			new CLOptionDescriptor("version", CLOptionDescriptor.ARGUMENT_DISALLOWED, VERSION_OPT,
					"print the version information and exit"),
			new CLOptionDescriptor("propfile", CLOptionDescriptor.ARGUMENT_REQUIRED, PROPFILE_OPT,
					"the jmeter property file to use"),
			new CLOptionDescriptor("addprop", CLOptionDescriptor.ARGUMENT_REQUIRED
					| CLOptionDescriptor.DUPLICATES_ALLOWED, // Bug 33920 -
																// allow
																// multiple
																// props
					PROPFILE2_OPT, "additional property file(s)"),
			new CLOptionDescriptor("testfile", CLOptionDescriptor.ARGUMENT_REQUIRED, TESTFILE_OPT,
					"the jmeter test(.jmx) file to run"),
			new CLOptionDescriptor("logfile", CLOptionDescriptor.ARGUMENT_REQUIRED, LOGFILE_OPT,
					"the file to log samples to"),
			new CLOptionDescriptor("nongui", CLOptionDescriptor.ARGUMENT_DISALLOWED, NONGUI_OPT,
					"run JMeter in nongui mode"),
			new CLOptionDescriptor("server", CLOptionDescriptor.ARGUMENT_DISALLOWED, SERVER_OPT,
					"run the JMeter server"),
			new CLOptionDescriptor("proxyHost", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_HOST,
					"Set a proxy server for JMeter to use"),
			new CLOptionDescriptor("proxyPort", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_PORT,
					"Set proxy server port for JMeter to use"),
			new CLOptionDescriptor("username", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_USERNAME,
					"Set username for proxy server that JMeter is to use"),
			new CLOptionDescriptor("password", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_PASSWORD,
					"Set password for proxy server that JMeter is to use"),
			new CLOptionDescriptor("jmeterproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
					| CLOptionDescriptor.ARGUMENTS_REQUIRED_2, JMETER_PROPERTY, "Define additional JMeter properties"),
			new CLOptionDescriptor("systemproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
					| CLOptionDescriptor.ARGUMENTS_REQUIRED_2, SYSTEM_PROPERTY, "Define additional JMeter properties"),
			new CLOptionDescriptor("loglevel", CLOptionDescriptor.DUPLICATES_ALLOWED
					| CLOptionDescriptor.ARGUMENTS_REQUIRED_2, LOGLEVEL,
					"Define loglevel: [category=]level e.g. jorphan=INFO or " + "jmeter.util=DEBUG"),
			new CLOptionDescriptor("runremote", CLOptionDescriptor.ARGUMENT_DISALLOWED, REMOTE_OPT,
					"Start remote servers from non-gui mode"),
			new CLOptionDescriptor("homedir", CLOptionDescriptor.ARGUMENT_REQUIRED, JMETER_HOME_OPT,
					"the jmeter home directory to use"), };

	public JMeter() {
	}

	// Hack to allow automated tests to find when test has ended
	//transient boolean testEnded = false;

	private JMeter parent;

	/**
	 * Starts up JMeter in GUI mode
	 */
	public void startGui(CLOption testFile) {

		PluginManager.install(this, true);
		JMeterTreeModel treeModel = new JMeterTreeModel();
		JMeterTreeListener treeLis = new JMeterTreeListener(treeModel);
		treeLis.setActionHandler(ActionRouter.getInstance());
		// NOTUSED: GuiPackage guiPack =
		GuiPackage.getInstance(treeLis, treeModel);
		org.apache.jmeter.gui.MainFrame main = new org.apache.jmeter.gui.MainFrame(ActionRouter.getInstance(),
				treeModel, treeLis);
		main.setTitle("Apache JMeter");
		main.setIconImage(JMeterUtils.getImage("jmeter.jpg").getImage());
		ComponentUtil.centerComponentInWindow(main, 80);
		main.show();
		ActionRouter.getInstance().actionPerformed(new ActionEvent(main, 1, ActionNames.ADD_ALL));
		if (testFile != null) {
			try {
				File f = new File(testFile.getArgument());
				log.info("Loading file: " + f);
				FileInputStream reader = new FileInputStream(f);
				HashTree tree = SaveService.loadTree(reader);

				GuiPackage.getInstance().setTestPlanFile(f.getAbsolutePath());

				new Load().insertLoadedTree(1, tree);
            } catch (ConversionException e) {
                log.error("Failure loading test file", e);
                JMeterUtils.reportErrorToUser(SaveService.CEtoString(e));
			} catch (Exception e) {
{'fraction_non_alphanumeric': 0.10058243727598566, 'fraction_numerical': 0.003472222222222222, 'mean_word_length': 4.897291941875825, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1067906', 'n_tokens_mistral': 6059, 'n_tokens_neox': 5436, 'n_words': 1323}