// Path: com.vmware.vfabric.ide.eclipse.tcserver.core/src/com/vmware/vfabric/ide/eclipse/tcserver/internal/core/TcServer.java
// public enum Layout {
// 	/**
// 	 * Uses runtime directory. Does not have an instance directory.
// 	 * Supported by v2.0 and earlier only.
// 	 */
// 	ASF,
// 	/** Uses instance directory. Supported by v2.5 and later only. */
// 	COMBINED,
// 	/** Uses runtime and instance directory. Supported by all versions. */
// 	SEPARATE;
// 
// 	public String toString() {
// 		switch (this) {
// 		case ASF:
// 			return "ASF Layout";
// 		case COMBINED:
// 			return "Combined Layout";
// 		case SEPARATE:
// 			return "Separate Layout";
// 		}
// 		throw new IllegalStateException();
// 	};
// }
// 
// Path: com.vmware.vfabric.ide.eclipse.tcserver.reloading/src/com/vmware/vfabric/ide/eclipse/tcserver/reloading/TcServerReloadingPlugin.java
// public class TcServerReloadingPlugin extends Plugin {
// 
// 	private static final String PLUGIN_ID = "com.vmware.vfabric.ide.eclipse.tcserver.reloading";
// 
// 	private static TcServerReloadingPlugin plugin;
// 
// 	private static String agentJarPath;
// 
// 	public void start(BundleContext context) throws Exception {
// 		super.start(context);
// 		plugin = this;
// 	}
// 
// 	public void stop(BundleContext context) throws Exception {
// 		super.stop(context);
// 		plugin = null;
// 	}
// 
// 	@SuppressWarnings("unchecked")
// 	public synchronized static String getAgentJarPath() {
// 		if (agentJarPath == null) {
// 			Enumeration<URL> libs = plugin.getBundle().findEntries("/lib", "springloaded-*.jar", false);
// 			while (libs.hasMoreElements()) {
// 				try {
// 					URL nextLib = libs.nextElement();
// 					agentJarPath = new File(FileLocator.toFileURL(nextLib).getPath()).getCanonicalPath();
// 				}
// 				catch (Exception e) {
// 					plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, "Error loading tc Server Agent Jar", e));
// 				}
// 			}
// 		}
// 		return agentJarPath;
// 	}
// 
// }


import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeoutException;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.lang.StringUtils;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jst.server.tomcat.core.internal.FileUtil;
import org.eclipse.jst.server.tomcat.core.internal.ITomcatVersionHandler;
import org.eclipse.jst.server.tomcat.core.internal.Messages;
import org.eclipse.jst.server.tomcat.core.internal.PingThread;
import org.eclipse.jst.server.tomcat.core.internal.ProgressUtil;
import org.eclipse.jst.server.tomcat.core.internal.TomcatServerBehaviour;
import org.eclipse.jst.server.tomcat.core.internal.TomcatVersionHelper;
import org.eclipse.jst.server.tomcat.core.internal.Trace;
import org.eclipse.mylyn.commons.net.WebLocation;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.ServerPort;
import org.eclipse.wst.server.core.model.IModuleResource;
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
import com.vmware.vfabric.ide.eclipse.tcserver.internal.core.TcServer.Layout;
import com.vmware.vfabric.ide.eclipse.tcserver.reloading.TcServerReloadingPlugin;
		super.setupLaunchConfiguration(workingCopy, monitor);

		TcServer.getCallback().setupLaunchConfiguration(getTomcatServer(), workingCopy, monitor);

		if (getTomcatServer().isTestEnvironment()) {
			setupRuntimeClasspathForTestEnvironment(workingCopy, monitor);
		}

		String existingVMArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
				(String) null);
		String[] parsedVMArgs = null;
		if (existingVMArgs != null) {
			parsedVMArgs = DebugPlugin.parseArguments(existingVMArgs);
		}

		List<String> argsToAdd = new ArrayList<String>();
		List<String> argsToRemove = new ArrayList<String>();

		if (getTomcatServer().isAgentRedeployEnabled() && TcServerReloadingPlugin.getAgentJarPath() != null) {
			argsToAdd.add("-javaagent:\"" + TcServerReloadingPlugin.getAgentJarPath() + "\"");
			argsToAdd.add("-noverify");
			String agentOptions = getTomcatServer().getAgentOptions();
			if (StringUtils.isNotBlank(agentOptions)) {
				argsToAdd.add("-Dspringloaded=\"" + agentOptions + "\"");
			}
			else {
				argsToRemove.add("-Dspringloaded");
			}
		}
		else {
// Path: com.vmware.vfabric.ide.eclipse.tcserver.core/src/com/vmware/vfabric/ide/eclipse/tcserver/internal/core/TcServer.java
// public enum Layout {
// 	/**
// 	 * Uses runtime directory. Does not have an instance directory.
// 	 * Supported by v2.0 and earlier only.
// 	 */
// 	ASF,
// 	/** Uses instance directory. Supported by v2.5 and later only. */
// 	COMBINED,
// 	/** Uses runtime and instance directory. Supported by all versions. */
// 	SEPARATE;
// 
// 	public String toString() {
// 		switch (this) {
// 		case ASF:
// 			return "ASF Layout";
// 		case COMBINED:
// 			return "Combined Layout";
// 		case SEPARATE:
// 			return "Separate Layout";
// 		}
// 		throw new IllegalStateException();
// 	};
// }
// 
// Path: com.vmware.vfabric.ide.eclipse.tcserver.reloading/src/com/vmware/vfabric/ide/eclipse/tcserver/reloading/TcServerReloadingPlugin.java
// public class TcServerReloadingPlugin extends Plugin {
// 
// 	private static final String PLUGIN_ID = "com.vmware.vfabric.ide.eclipse.tcserver.reloading";
// 
// 	private static TcServerReloadingPlugin plugin;
// 
// 	private static String agentJarPath;
// 
// 	public void start(BundleContext context) throws Exception {
// 		super.start(context);
// 		plugin = this;
// 	}
// 
// 	public void stop(BundleContext context) throws Exception {
// 		super.stop(context);
// 		plugin = null;
// 	}
// 
// 	@SuppressWarnings("unchecked")
// 	public synchronized static String getAgentJarPath() {
// 		if (agentJarPath == null) {
// 			Enumeration<URL> libs = plugin.getBundle().findEntries("/lib", "springloaded-*.jar", false);
// 			while (libs.hasMoreElements()) {
// 				try {
// 					URL nextLib = libs.nextElement();
// 					agentJarPath = new File(FileLocator.toFileURL(nextLib).getPath()).getCanonicalPath();
// 				}
// 				catch (Exception e) {
// 					plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, "Error loading tc Server Agent Jar", e));
// 				}
// 			}
// 		}
// 		return agentJarPath;
// 	}
// 
// }


// Path: com.vmware.vfabric.ide.eclipse.tcserver.core/src/com/vmware/vfabric/ide/eclipse/tcserver/internal/core/TcServerBehaviour.java
import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeoutException;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.lang.StringUtils;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jst.server.tomcat.core.internal.FileUtil;
import org.eclipse.jst.server.tomcat.core.internal.ITomcatVersionHandler;
import org.eclipse.jst.server.tomcat.core.internal.Messages;
import org.eclipse.jst.server.tomcat.core.internal.PingThread;
import org.eclipse.jst.server.tomcat.core.internal.ProgressUtil;
import org.eclipse.jst.server.tomcat.core.internal.TomcatServerBehaviour;
import org.eclipse.jst.server.tomcat.core.internal.TomcatVersionHelper;
import org.eclipse.jst.server.tomcat.core.internal.Trace;
import org.eclipse.mylyn.commons.net.WebLocation;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.ServerPort;
import org.eclipse.wst.server.core.model.IModuleResource;
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
import com.vmware.vfabric.ide.eclipse.tcserver.internal.core.TcServer.Layout;
import com.vmware.vfabric.ide.eclipse.tcserver.reloading.TcServerReloadingPlugin;

		super.setupLaunchConfiguration(workingCopy, monitor);

		TcServer.getCallback().setupLaunchConfiguration(getTomcatServer(), workingCopy, monitor);

		if (getTomcatServer().isTestEnvironment()) {
			setupRuntimeClasspathForTestEnvironment(workingCopy, monitor);
		}

		String existingVMArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
				(String) null);
		String[] parsedVMArgs = null;
		if (existingVMArgs != null) {
			parsedVMArgs = DebugPlugin.parseArguments(existingVMArgs);
		}

		List<String> argsToAdd = new ArrayList<String>();
		List<String> argsToRemove = new ArrayList<String>();

		if (getTomcatServer().isAgentRedeployEnabled() && TcServerReloadingPlugin.getAgentJarPath() != null) {
			argsToAdd.add("-javaagent:\"" + TcServerReloadingPlugin.getAgentJarPath() + "\"");
			argsToAdd.add("-noverify");
			String agentOptions = getTomcatServer().getAgentOptions();
			if (StringUtils.isNotBlank(agentOptions)) {
				argsToAdd.add("-Dspringloaded=\"" + agentOptions + "\"");
			}
			else {
				argsToRemove.add("-Dspringloaded");
			}
		}
		else {
			argsToRemove.add("-javaagent:\"" + TcServerReloadingPlugin.getAgentJarPath() + "\"");