<commit_before>package com.itmill.toolkit.launcher;

import java.util.HashMap;
import java.util.Map;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;

import com.itmill.toolkit.launcher.util.BrowserLauncher;

/**
 * Class for running Jetty servlet container within Eclipse project.
 * 
 */
public class ITMillToolkitWebMode {

	private final static String serverPort = "8888";

	/**
	 * Main function for running Jetty.
	 * 
	 * Command line Arguments are passed through to Jetty, see runServer method
	 * for options.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		// Pass-through of arguments for Jetty
		Map serverArgs = parseArguments(args);

		// Start Jetty
		System.out.println("Starting Jetty servlet container.");
		String url = runServer(serverArgs);

		// Start Browser
		System.out.println("Starting Web Browser.");
		if (url != null) {
			BrowserLauncher.openBrowser(url);
		}

	}

	/**
	 * Run the server with specified arguments.
	 * 
	 * @param serverArgs
	 * @return
	 */
	protected static String runServer(Map serverArgs) {

		// Add help for System.out
		System.out
				.println("-------------------------------------------------\n"
						+ "Starting IT Mill Toolkit in Web Mode.\n"
						+ "Running in http://localhost:"
						+ serverPort
						+ "\n-------------------------------------------------\n");

		// Assign default values for some arguments
		assignDefault(serverArgs, "webroot", "WebContent");
		assignDefault(serverArgs, "httpPort", serverPort);

		try {
			long started = System.currentTimeMillis();

			Server server = new Server();

			// String threadPoolName =
			// System.getProperty("jetty.threadpool.name",
			// "Jetty thread");
			// int maxIdleTimeMs = Integer.getInteger(
			// "jetty.threadpool.maxIdleTimeMs", 60000);
			// int maxThreads =
			// Integer.getInteger("jetty.threadpool.maxThreads",
			// 100);
			// int minThreads =
			// Integer.getInteger("jetty.threadpool.minThreads",
			// 1);
			// int lowThreads = Integer.getInteger(
			// "jetty.threadpool.maxIdleTimeMs", 25);
			// BoundedThreadPool threadPool = new BoundedThreadPool();
			// threadPool.setName(threadPoolName);
			// threadPool.setMaxIdleTimeMs(maxIdleTimeMs);
			// threadPool.setMaxThreads(maxThreads);
			// threadPool.setMinThreads(minThreads);
			// threadPool.setLowThreads(lowThreads);
			// server.setThreadPool(threadPool);

			Connector connector = new SelectChannelConnector();
			// FIXME httpPort hardcoded to 8888
			// connector.setPort(Integer.valueOf(serverArgs.get("httpPort")
			// .toString()));
			connector.setPort(8888);
			server.setConnectors(new Connector[] { connector });

			WebAppContext webappcontext = new WebAppContext();
			webappcontext.setContextPath("");
			webappcontext.setWar(serverArgs.get("webroot").toString());

			server.setHandler(webappcontext);
<commit_msg>Fixed #1156 (Packaging: Jetty does not reload classes if java files are updated)<commit_after>package com.itmill.toolkit.launcher;

import java.util.HashMap;
import java.util.Map;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;

import com.itmill.toolkit.launcher.util.BrowserLauncher;

/**
 * Class for running Jetty servlet container within Eclipse project.
 * 
 */
public class ITMillToolkitWebMode {

	private final static String serverPort = "8888";

	/**
	 * Main function for running Jetty.
	 * 
	 * Command line Arguments are passed through to Jetty, see runServer method
	 * for options.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		// Pass-through of arguments for Jetty
		Map serverArgs = parseArguments(args);

		// Start Jetty
		System.out.println("Starting Jetty servlet container.");
		String url = runServer(serverArgs);

		// Start Browser
		System.out.println("Starting Web Browser.");
		if (url != null) {
			BrowserLauncher.openBrowser(url);
		}

	}

	/**
	 * Run the server with specified arguments.
	 * 
	 * @param serverArgs
	 * @return
	 */
	protected static String runServer(Map serverArgs) {

		// Add help for System.out
		System.out
				.println("-------------------------------------------------\n"
						+ "Starting IT Mill Toolkit in Web Mode.\n"
						+ "Running in http://localhost:"
						+ serverPort
						+ "\n-------------------------------------------------\n");

		// Assign default values for some arguments
		assignDefault(serverArgs, "webroot", "WebContent");
		assignDefault(serverArgs, "httpPort", serverPort);

		try {
			long started = System.currentTimeMillis();

			Server server = new Server();

			// String threadPoolName =
			// System.getProperty("jetty.threadpool.name",
			// "Jetty thread");
			// int maxIdleTimeMs = Integer.getInteger(
			// "jetty.threadpool.maxIdleTimeMs", 60000);
			// int maxThreads =
			// Integer.getInteger("jetty.threadpool.maxThreads",
			// 100);
			// int minThreads =
			// Integer.getInteger("jetty.threadpool.minThreads",
			// 1);
			// int lowThreads = Integer.getInteger(
			// "jetty.threadpool.maxIdleTimeMs", 25);
			// BoundedThreadPool threadPool = new BoundedThreadPool();
			// threadPool.setName(threadPoolName);
			// threadPool.setMaxIdleTimeMs(maxIdleTimeMs);
			// threadPool.setMaxThreads(maxThreads);
			// threadPool.setMinThreads(minThreads);
			// threadPool.setLowThreads(lowThreads);
			// server.setThreadPool(threadPool);

			Connector connector = new SelectChannelConnector();
			// FIXME httpPort hardcoded to 8888
			// connector.setPort(Integer.valueOf(serverArgs.get("httpPort")
			// .toString()));
			connector.setPort(8888);
			server.setConnectors(new Connector[] { connector });

			WebAppContext webappcontext = new WebAppContext();
			webappcontext.setContextPath("");
			webappcontext.setWar(serverArgs.get("webroot").toString());
			// enable hot code replace
			webappcontext.setCopyWebDir(true);
			
			server.setHandler(webappcontext);

{'fraction_non_alphanumeric': 0.154250082047916, 'fraction_numerical': 0.008204791598293404, 'mean_word_length': 3.1490810074880873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4041010', 'n_tokens_mistral': 2132, 'n_tokens_neox': 1789, 'n_words': 401}