<commit_before>/*******************************************************************************
 *  Copyright (c) 2012 - 2013 VMware, Inc.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *      VMware, Inc. - initial API and implementation
 *******************************************************************************/
package com.vmware.vfabric.ide.eclipse.tcserver.internal.core;

import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.server.tomcat.core.internal.ITomcatServer;
import org.eclipse.jst.server.tomcat.core.internal.Messages;
import org.eclipse.jst.server.tomcat.core.internal.TomcatPlugin;
import org.eclipse.jst.server.tomcat.core.internal.TomcatServer;
import org.eclipse.jst.server.tomcat.core.internal.Trace;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.ServerPort;
import org.eclipse.wst.server.core.ServerUtil;

/**
 * @author <NAME>
 * @author <NAME>upuis
 * @author <NAME>
 * @author <NAME>
 */
public class TcServer extends TomcatServer {

	public static String ID_TC_SERVER_2_0 = "com.springsource.tcserver.60";

	public static String ID_TC_SERVER_2_1 = "com.springsource.tcserver.70";

	public static String ID_TC_SERVER_2_5 = "com.vmware.server.tc.70";

	public static final String DEFAULT_DEPLOYER_HOST = "localhost";

	public static final String DEFAULT_DEPLOYER_SERVICE = "Catalina";

	/**
	 * Default filename patters that should to avoid a webapp reload when
	 * publishing.
	 */
	public static final String DEFAULT_STATIC_FILENAMES = "*.html,*.xhtml,*.css,*.jspx,*.js,*.jsp,*.gif,*.jpg,*.png,*.swf,*-flow.xml,*.properties,*.xml,!tiles.xml,!web.xml";

	/** Boolean property that determines if the ASF layout should be used. */
	public static final String KEY_ASF_LAYOUT = "com.springsource.tcserver.asf";

	/**
	 * String property for the server instance for combined or separate layout.
	 */
	public static final String KEY_SERVER_NAME = "com.springsource.tcserver.name";

	public static final String PROPERTY_ADD_EXTRA_VMARGS = "addExtraVmArgs";

	public static final String PROPERTY_AGENT_OPTIONS = "com.springsource.tcserver.agent.options";

	public static final String PROPERTY_AGENT_REDEPLOY = "com.springsource.tcserver.agent.deploy";

	public static final String PROPERTY_DEPLOYER_HOST = "modifyDeployerHost";

	public static final String PROPERTY_DEPLOYER_SERVICE = "modifyDeployerService";

	/**
	 * Property key for a boolean that indicates managing of webapp reloading is
	 * enabled.
	 */
	public static final String PROPERTY_ENHANCED_REDEPLOY = "com.springsource.tcserver.jmx.deploy";

	public static final String PROPERTY_JMX_PASSWORD = "<PASSWORD>";

	public static final String PROPERTY_JMX_PORT = "modifyJmxPort";

	public static final String PROPERTY_JMX_USER = "modifyJmxUser";

	public static final String PROPERTY_REMOVE_EXTRA_VMARGS = "removeExtraVmArgs";

	/**
	 * Property key for list of patterns to avoid a webapp reload when
	 * publishing.
	 */
	public static final String PROPERTY_STATIC_FILENAMES = "com.springsource.tcserver.filenames.static";

	private static TcServerCallback callback;

	private static final String DEFAULT_JMX_PORT = "6969";

	@Override
	public IStatus canModifyModules(IModule[] add, IModule[] remove) {
		if (add != null) {
			int size = add.length;
			for (int i = 0; i < size; i++) {
				IModule module = add[i];

				if (ITcServerConstants.GRAILS_APP_MODULE_TYPE.equals(module.getModuleType().getId())) {
					return Status.OK_STATUS;
				}
			}
		}

		return super.canModifyModules(add, remove);
	}

	@SuppressWarnings("unchecked")
	public List<String> getAddExtraVmArgs() {
		return getAttribute(PROPERTY_ADD_EXTRA_VMARGS, Collections.EMPTY_LIST);
	}

	public String getAgentOptions() {
		return getAttribute(PROPERTY_AGENT_OPTIONS, "");
	}

	public String getDeployerHost() {
		return getAttribute(PROPERTY_DEPLOYER_HOST, DEFAULT_DEPLOYER_HOST);
	}

	public String getDeployerProperty(String key) {
		if (PROPERTY_JMX_PORT.equals(key)) {
			return getJmxPort();
		}
		if (PROPERTY_DEPLOYER_HOST.equals(key)) {
			return getDeployerHost();
		}
		if (PROPERTY_DEPLOYER_SERVICE.equals(key)) {
			return getDeployerService();
		}
		return getAttribute(key, (String) null);
	}

	public String getDeployerService() {
		return getAttribute(PROPERTY_DEPLOYER_SERVICE, DEFAULT_DEPLOYER_SERVICE);
	}

	/**
	 * The runtime may specifies the top-level tc Server directory and not the
	 * catalina home. This methods returns the actual catalina home this server
	 * is configured to use.
	 */
	public IPath getInstanceBase(IRuntime runtime) {
		IPath path = runtime.getLocation();
		if (isAsfLayout()) {
			return getTomcatRuntime().getTomcatLocation();
		}
		else {
			String instanceDir = getInstanceDirectory();
			if (instanceDir != null) {
				return Path.fromOSString(instanceDir);
			}
			String serverName = getAttribute(KEY_SERVER_NAME, (String) null);
			if (serverName != null) {
				path = path.append(serverName);
			}
			return path;
		}
	}

	public String getJmxPassword() {
		return getAttribute(PROPERTY_JMX_PASSWORD, "");
	}

	public String getJmxPort() {
		return getAttribute(PROPERTY_JMX_PORT, DEFAULT_JMX_PORT);
	}

	public String getJmxUser() {
		return getAttribute(PROPERTY_JMX_USER, "");
	}

	public Layout getLayout() {
		if (isAsfLayout()) {
			return Layout.ASF;
		}
		else {
			IPath path = getInstanceBase(getServer().getRuntime());<commit_msg>Original fix for STS-3340 prevented creation of new template instances<commit_after>/*******************************************************************************
 *  Copyright (c) 2012 - 2013 VMware, Inc.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *      VMware, Inc. - initial API and implementation
 *******************************************************************************/
package com.vmware.vfabric.ide.eclipse.tcserver.internal.core;

import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.server.tomcat.core.internal.ITomcatServer;
import org.eclipse.jst.server.tomcat.core.internal.Messages;
import org.eclipse.jst.server.tomcat.core.internal.TomcatPlugin;
import org.eclipse.jst.server.tomcat.core.internal.TomcatServer;
import org.eclipse.jst.server.tomcat.core.internal.Trace;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.ServerPort;
import org.eclipse.wst.server.core.ServerUtil;

/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class TcServer extends TomcatServer {

	public static String ID_TC_SERVER_2_0 = "com.springsource.tcserver.60";

	public static String ID_TC_SERVER_2_1 = "com.springsource.tcserver.70";

	public static String ID_TC_SERVER_2_5 = "com.vmware.server.tc.70";

	public static final String DEFAULT_DEPLOYER_HOST = "localhost";

	public static final String DEFAULT_DEPLOYER_SERVICE = "Catalina";

	/**
	 * Default filename patters that should to avoid a webapp reload when
	 * publishing.
	 */
	public static final String DEFAULT_STATIC_FILENAMES = "*.html,*.xhtml,*.css,*.jspx,*.js,*.jsp,*.gif,*.jpg,*.png,*.swf,*-flow.xml,*.properties,*.xml,!tiles.xml,!web.xml";

	/** Boolean property that determines if the ASF layout should be used. */
	public static final String KEY_ASF_LAYOUT = "com.springsource.tcserver.asf";

	/**
	 * String property for the server instance for combined or separate layout.
	 */
	public static final String KEY_SERVER_NAME = "com.springsource.tcserver.name";

	public static final String PROPERTY_ADD_EXTRA_VMARGS = "addExtraVmArgs";

	public static final String PROPERTY_AGENT_OPTIONS = "com.springsource.tcserver.agent.options";

	public static final String PROPERTY_AGENT_REDEPLOY = "com.springsource.tcserver.agent.deploy";

	public static final String PROPERTY_DEPLOYER_HOST = "modifyDeployerHost";

	public static final String PROPERTY_DEPLOYER_SERVICE = "modifyDeployerService";

	/**
	 * Property key for a boolean that indicates managing of webapp reloading is
	 * enabled.
	 */
	public static final String PROPERTY_ENHANCED_REDEPLOY = "com.springsource.tcserver.jmx.deploy";

	public static final String PROPERTY_JMX_PASSWORD = "<PASSWORD>";

	public static final String PROPERTY_JMX_PORT = "modifyJmxPort";

	public static final String PROPERTY_JMX_USER = "modifyJmxUser";

	public static final String PROPERTY_REMOVE_EXTRA_VMARGS = "removeExtraVmArgs";

	/**
	 * Property key for list of patterns to avoid a webapp reload when
	 * publishing.
	 */
	public static final String PROPERTY_STATIC_FILENAMES = "com.springsource.tcserver.filenames.static";

	private static TcServerCallback callback;

	private static final String DEFAULT_JMX_PORT = "6969";

	@Override
	public IStatus canModifyModules(IModule[] add, IModule[] remove) {
		if (add != null) {
			int size = add.length;
			for (int i = 0; i < size; i++) {
				IModule module = add[i];

				if (ITcServerConstants.GRAILS_APP_MODULE_TYPE.equals(module.getModuleType().getId())) {
					return Status.OK_STATUS;
				}
			}
		}

		return super.canModifyModules(add, remove);
	}

	@SuppressWarnings("unchecked")
	public List<String> getAddExtraVmArgs() {
		return getAttribute(PROPERTY_ADD_EXTRA_VMARGS, Collections.EMPTY_LIST);
	}

	public String getAgentOptions() {
		return getAttribute(PROPERTY_AGENT_OPTIONS, "");
	}

	public String getDeployerHost() {
		return getAttribute(PROPERTY_DEPLOYER_HOST, DEFAULT_DEPLOYER_HOST);
	}

	public String getDeployerProperty(String key) {
		if (PROPERTY_JMX_PORT.equals(key)) {
			return getJmxPort();
		}
		if (PROPERTY_DEPLOYER_HOST.equals(key)) {
			return getDeployerHost();
		}
		if (PROPERTY_DEPLOYER_SERVICE.equals(key)) {
			return getDeployerService();
		}
		return getAttribute(key, (String) null);
	}

	public String getDeployerService() {
		return getAttribute(PROPERTY_DEPLOYER_SERVICE, DEFAULT_DEPLOYER_SERVICE);
	}

	/**
	 * The runtime may specifies the top-level tc Server directory and not the
	 * catalina home. This methods returns the actual catalina home this server
	 * is configured to use.
	 */
	public IPath getInstanceBase(IRuntime runtime) {
		IPath path = runtime.getLocation();
		if (isAsfLayout()) {
			return getTomcatRuntime().getTomcatLocation();
		}
		else {
			String instanceDir = getInstanceDirectory();
			if (instanceDir != null) {
				path = Path.fromOSString(instanceDir);
			}
			String serverName = getAttribute(KEY_SERVER_NAME, (String) null);
			if (serverName != null && !path.toOSString().endsWith(serverName)) {
				path = path.append(serverName);
			}
			return path;
		}
	}

	public String getJmxPassword() {
		return getAttribute(PROPERTY_JMX_PASSWORD, "");
	}

	public String getJmxPort() {
		return getAttribute(PROPERTY_JMX_PORT, DEFAULT_JMX_PORT);
	}

	public String getJmxUser() {
		return getAttribute(PROPERTY_JMX_USER, "");
	}

	public Layout getLayout() {
		if (isAsfLayout()) {
			return Layout.ASF;
		}
		else {
			IPath path = getInstanceBase(getServer().getRuntime());
{'fraction_non_alphanumeric': 0.12862874675477934, 'fraction_numerical': 0.004877665014554323, 'mean_word_length': 4.951310861423221, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, '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': '540330', 'n_tokens_mistral': 4248, 'n_tokens_neox': 3969, 'n_words': 913}