diff options
Diffstat (limited to 'plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org')
9 files changed, 540 insertions, 314 deletions
diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/ITomcatServer.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/ITomcatServer.java index 0ad623f95..fa18f8431 100644 --- a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/ITomcatServer.java +++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/ITomcatServer.java @@ -10,11 +10,6 @@ **********************************************************************/ package org.eclipse.jst.server.tomcat.core; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.model.IProcess; - import org.eclipse.wst.server.core.model.IURLProvider; /** * @@ -54,22 +49,4 @@ public interface ITomcatServer extends IURLProvider { * @return */ public String getRuntimeClass(); - - /** - * Set the process that is monitored for Tomcat startup and shutdown. - * Warning: Do not call this method unless you know what you're doing; - * it should only be used in rare cases. - * - * @param newProcess - */ - public void setProcess(IProcess newProcess); - - /** - * Setup for starting the server. - * - * @param launch ILaunch - * @param launchMode String - * @param monitor IProgressMonitor - */ - public void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException; }
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/ITomcatServerBehaviour.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/ITomcatServerBehaviour.java new file mode 100644 index 000000000..2320590b7 --- /dev/null +++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/ITomcatServerBehaviour.java @@ -0,0 +1,47 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.jst.server.tomcat.core; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IProcess; + +import org.eclipse.wst.server.core.model.IURLProvider; +/** + * + */ +public interface ITomcatServerBehaviour extends IURLProvider { + /** + * Returns the main class that is used to launch the Tomcat server. + * + * @return + */ + public String getRuntimeClass(); + + /** + * Set the process that is monitored for Tomcat startup and shutdown. + * Warning: Do not call this method unless you know what you're doing; + * it should only be used in rare cases. + * + * @param newProcess + */ + public void setProcess(IProcess newProcess); + + /** + * Setup for starting the server. + * + * @param launch ILaunch + * @param launchMode String + * @param monitor IProgressMonitor + */ + public void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException; +}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatLaunchConfigurationDelegate.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatLaunchConfigurationDelegate.java index 1ee62a352..9abaa1cb1 100644 --- a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatLaunchConfigurationDelegate.java +++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatLaunchConfigurationDelegate.java @@ -32,14 +32,14 @@ public class TomcatLaunchConfigurationDelegate extends AbstractJavaLaunchConfigu public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { String serverId = configuration.getAttribute(IServer.ATTR_SERVER_ID, (String) null); - IServer server = ServerCore.getServer(serverId); + IServer server = ServerCore.findServer(serverId); if (server == null) { Trace.trace(Trace.FINEST, "Launch configuration could not find server"); // throw CoreException(); return; } - TomcatServer tomcatServer = (TomcatServer) server.getAdapter(TomcatServer.class); + TomcatServerBehaviour tomcatServer = (TomcatServerBehaviour) server.getAdapter(TomcatServerBehaviour.class); tomcatServer.setupLaunch(launch, mode, monitor); String mainTypeName = tomcatServer.getRuntimeClass(); diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatRuntimeLocator.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatRuntimeLocator.java index df05a935b..a28611021 100644 --- a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatRuntimeLocator.java +++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatRuntimeLocator.java @@ -87,7 +87,7 @@ public class TomcatRuntimeLocator extends RuntimeLocatorDelegate { protected static IRuntimeWorkingCopy getRuntimeFromDir(File dir, IProgressMonitor monitor) { for (int i = 0; i < runtimeTypes.length; i++) { try { - IRuntimeType runtimeType = ServerCore.getRuntimeType(runtimeTypes[i]); + IRuntimeType runtimeType = ServerCore.findRuntimeType(runtimeTypes[i]); IRuntimeWorkingCopy runtime = runtimeType.createRuntime(dir.getAbsolutePath(), monitor); runtime.setName(dir.getName()); runtime.setLocation(new Path(dir.getAbsolutePath())); diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServer.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServer.java index 2ce6cfc0e..6d419c391 100644 --- a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServer.java +++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServer.java @@ -10,7 +10,6 @@ **********************************************************************/ package org.eclipse.jst.server.tomcat.core.internal; -import java.io.File; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; @@ -25,21 +24,19 @@ import org.eclipse.jdt.launching.IVMInstall; import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.jst.server.j2ee.IWebModule; import org.eclipse.jst.server.tomcat.core.ITomcatConfiguration; +import org.eclipse.jst.server.tomcat.core.ITomcatConfigurationWorkingCopy; import org.eclipse.jst.server.tomcat.core.ITomcatRuntime; import org.eclipse.jst.server.tomcat.core.ITomcatServer; +import org.eclipse.jst.server.tomcat.core.ITomcatServerWorkingCopy; import org.eclipse.jst.server.tomcat.core.WebModule; import org.eclipse.wst.server.core.*; import org.eclipse.wst.server.core.model.*; -import org.eclipse.wst.server.core.util.FileUtil; import org.eclipse.wst.server.core.util.PingThread; -import org.eclipse.wst.server.core.util.SocketUtil; /** * Generic Tomcat server. */ -public class TomcatServer extends ServerDelegate implements ITomcatServer { - private static final String ATTR_STOP = "stop-server"; - +public class TomcatServer extends ServerDelegate implements ITomcatServer, ITomcatServerWorkingCopy { protected transient IPath tempDirectory; // the thread used to ping the server to check for startup @@ -196,158 +193,6 @@ public class TomcatServer extends ServerDelegate implements ITomcatServer { return buf.toString(); } - public void setProcess(final IProcess newProcess) { - if (process != null) - return; - - process = newProcess; - processListener = new IDebugEventSetListener() { - public void handleDebugEvents(DebugEvent[] events) { - if (events != null) { - int size = events.length; - for (int i = 0; i < size; i++) { - if (process.equals(events[i].getSource()) && events[i].getKind() == DebugEvent.TERMINATE) { - DebugPlugin.getDefault().removeDebugEventListener(this); - stopImpl(); - } - } - } - } - }; - DebugPlugin.getDefault().addDebugEventListener(processListener); - } - - protected void stopImpl() { - if (ping != null) { - ping.stopPinging(); - ping = null; - } - if (process != null) { - process = null; - DebugPlugin.getDefault().removeDebugEventListener(processListener); - processListener = null; - } - setServerState(IServer.STATE_STOPPED); - } - - public void publishServer(IProgressMonitor monitor) throws CoreException { - IPath confDir = null; - if (isTestEnvironment()) { - confDir = getTempDirectory(); - File temp = confDir.append("conf").toFile(); - if (!temp.exists()) - temp.mkdirs(); - } else - confDir = getServer().getRuntime().getLocation(); - IStatus status = getTomcatConfiguration().backupAndPublish(confDir, !isTestEnvironment(), monitor); - if (status != null && !status.isOK()) - throw new CoreException(status); - - setServerPublishState(IServer.PUBLISH_STATE_NONE); - } - - /** - * Returns the project publisher that can be used to - * publish the given project. - */ - public void publishModule(IModule[] parents, IModule module, IProgressMonitor monitor) { - if (isTestEnvironment()) - return; - - // TODO - publish! - IWebModule webModule = (IWebModule) module; - IPath from = webModule.getLocation(); - IPath to = getServer().getRuntime().getLocation().append("webapps").append(webModule.getContextRoot()); - FileUtil.smartCopyDirectory(from.toOSString(), to.toOSString(), monitor); - } - - /** - * Setup for starting the server. - * - * @param launch ILaunch - * @param launchMode String - * @param monitor IProgressMonitor - */ - public void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException { - if ("true".equals(launch.getLaunchConfiguration().getAttribute(ATTR_STOP, "false"))) - return; - IStatus status = getTomcatRuntime().validate(); - if (status != null && !status.isOK()) - throw new CoreException(status); - - //setRestartNeeded(false); - TomcatConfiguration configuration = getTomcatConfiguration(); - - // check that ports are free - Iterator iterator = configuration.getServerPorts().iterator(); - while (iterator.hasNext()) { - IServerPort sp = (IServerPort) iterator.next(); - if (SocketUtil.isPortInUse(sp.getPort(), 5)) - throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, TomcatPlugin.getResource("%errorPortInUse", new String[] {sp.getPort() + "", sp.getName()}), null)); - } - - setServerState(IServer.STATE_STARTING); - - // ping server to check for startup - try { - String url = "http://localhost"; - int port = configuration.getMainPort().getPort(); - if (port != 80) - url += ":" + port; - ping = new PingThread(getServer(), this, url); - } catch (Exception e) { - Trace.trace(Trace.SEVERE, "Can't ping for Tomcat startup."); - } - } - - /** - * Cleanly shuts down and terminates the server. - */ - public void stop() { - int state = getServer().getServerState(); - if (state == IServer.STATE_STOPPED) - return; - else if (state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING) { - terminate(); - return; - } - - try { - Trace.trace(Trace.FINER, "Stopping Tomcat"); - if (state != IServer.STATE_STOPPED) - setServerState(IServer.STATE_STOPPING); - - ILaunchConfiguration launchConfig = getServer().getLaunchConfiguration(true, null); - ILaunchConfigurationWorkingCopy wc = launchConfig.getWorkingCopy(); - - String args = renderCommandLine(getRuntimeProgramArguments(false), " "); - wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args); - wc.setAttribute(ATTR_STOP, "true"); - wc.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor()); - } catch (Exception e) { - Trace.trace(Trace.SEVERE, "Error stopping Tomcat", e); - } - } - - /** - * Terminates the server. - */ - public void terminate() { - if (getServer().getServerState() == IServer.STATE_STOPPED) - return; - - try { - setServerState(IServer.STATE_STOPPING); - Trace.trace(Trace.FINER, "Killing the Tomcat process"); - if (process != null && !process.isTerminated()) { - process.terminate(); - stopImpl(); - } - } catch (Exception e) { - Trace.trace(Trace.SEVERE, "Error killing the process", e); - } - } - /** * Return a string representation of this object. * @return java.lang.String @@ -526,4 +371,87 @@ public class TomcatServer extends ServerDelegate implements ITomcatServer { list.toArray(sp); return sp; } + + public void setDefaults() { + setTestEnvironment(true); + } + + /** + * Sets this process to debug mode. This feature only works + * with Tomcat v4.0. + * + * @param b boolean + */ + public void setDebug(boolean b) { + setAttribute(PROPERTY_DEBUG, b); + } + + /** + * Sets this process to secure mode. + * @param b boolean + */ + public void setSecure(boolean b) { + setAttribute(PROPERTY_SECURE, b); + } + + /** + * Sets this server to test environment mode. + * + * @param b boolean + */ + public void setTestEnvironment(boolean b) { + setAttribute(PROPERTY_TEST_ENVIRONMENT, b); + } + + /** + * Add the given project to this configuration. The project + * has already been verified using isSupportedProject() and + * does not already exist in the configuration. + * + * @param ref java.lang.String + */ + public void modifyModules(IModule[] add, IModule[] remove, IProgressMonitor monitor) throws CoreException { + IStatus status = canModifyModules(add, remove); + if (status == null || !status.isOK()) + throw new CoreException(status); + + IServerConfigurationWorkingCopy scwc = getServer().getServerConfiguration().createWorkingCopy(); + // TODO + ITomcatConfigurationWorkingCopy wc = (ITomcatConfigurationWorkingCopy) scwc.getAdapter(ITomcatConfigurationWorkingCopy.class); + boolean change = false; + + if (add != null) { + int size = add.length; + for (int i = 0; i < size; i++) { + IModule module3 = add[i]; + IWebModule module = (IWebModule) module3.getAdapter(IWebModule.class); + String contextRoot = module.getContextRoot(); + if (contextRoot != null && !contextRoot.startsWith("/")) + contextRoot = "/" + contextRoot; + WebModule module2 = new WebModule(contextRoot, + module.getLocation().toOSString(), module3.getId(), true); + wc.addWebModule(-1, module2); + change = true; + } + } + + if (remove != null) { + int size2 = remove.length; + for (int j = 0; j < size2; j++) { + IModule module3 = remove[j]; + String memento = module3.getId(); + List modules = getTomcatConfiguration().getWebModules(); + int size = modules.size(); + for (int i = 0; i < size; i++) { + WebModule module = (WebModule) modules.get(i); + if (memento.equals(module.getMemento())) { + wc.removeWebModule(i); + change = true; + } + } + } + } + if (change) + scwc.save(false, monitor); + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java new file mode 100644 index 000000000..0eec0f99d --- /dev/null +++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java @@ -0,0 +1,400 @@ +/********************************************************************** + * Copyright (c) 2003, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.jst.server.tomcat.core.internal; + +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.*; +import org.eclipse.debug.core.*; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; +import org.eclipse.jdt.launching.IRuntimeClasspathEntry; +import org.eclipse.jdt.launching.IVMInstall; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jst.server.j2ee.IWebModule; +import org.eclipse.jst.server.tomcat.core.ITomcatRuntime; +import org.eclipse.jst.server.tomcat.core.ITomcatServerBehaviour; + +import org.eclipse.wst.server.core.*; +import org.eclipse.wst.server.core.model.*; +import org.eclipse.wst.server.core.util.FileUtil; +import org.eclipse.wst.server.core.util.PingThread; +import org.eclipse.wst.server.core.util.SocketUtil; +/** + * Generic Tomcat server. + */ +public class TomcatServerBehaviour extends ServerBehaviourDelegate implements ITomcatServerBehaviour { + private static final String ATTR_STOP = "stop-server"; + + protected transient IPath tempDirectory; + + // the thread used to ping the server to check for startup + protected transient PingThread ping = null; + protected transient IProcess process; + protected transient IDebugEventSetListener processListener; + + /** + * TomcatServer. + */ + public TomcatServerBehaviour() { + super(); + } + + public TomcatRuntime getTomcatRuntime() { + if (getServer().getRuntime() == null) + return null; + + return (TomcatRuntime) getServer().getAdapter(TomcatRuntime.class); + } + + public ITomcatVersionHandler getTomcatVersionHandler() { + if (getServer().getRuntime() == null) + return null; + + return getTomcatRuntime().getVersionHandler(); + } + + public TomcatConfiguration getTomcatConfiguration() { + IServerConfiguration configuration = getServer().getServerConfiguration(); + if (configuration == null) + return null; + + return (TomcatConfiguration) configuration.getAdapter(TomcatConfiguration.class); + } + + public TomcatServer getTomcatServer() { + return null; // TODO + } + + /** + * Return the root URL of this module. + * @param module org.eclipse.wst.server.core.model.IModule + * @return java.net.URL + */ + public URL getModuleRootURL(IModule module) { + try { + if (module == null || !(module instanceof IWebModule)) + return null; + + IServerConfiguration serverConfig = getServer().getServerConfiguration(); + if (serverConfig == null) + return null; + + TomcatConfiguration config = (TomcatConfiguration) serverConfig.getAdapter(TomcatConfiguration.class); + if (config == null) + return null; + + String url = "http://localhost"; + int port = config.getMainPort().getPort(); + port = ServerCore.getServerMonitorManager().getMonitoredPort(getServer(), port, "web"); + if (port != 80) + url += ":" + port; + + url += config.getWebModuleURL(module); + + if (!url.endsWith("/")) + url += "/"; + + return new URL(url); + } catch (Exception e) { + Trace.trace("Could not get root URL", e); + return null; + } + } + + /** + * Return the runtime class name. + * + * @return java.lang.String + */ + public String getRuntimeClass() { + return getTomcatVersionHandler().getRuntimeClass(); + } + + /** + * Return the program's runtime arguments to start or stop. + * + * @param boolean starting + * @return java.lang.String + */ + protected String[] getRuntimeProgramArguments(boolean starting) { + IPath configPath = null; + if (getTomcatServer().isTestEnvironment()) + configPath = getTempDirectory(); + return getTomcatVersionHandler().getRuntimeProgramArguments(configPath, getTomcatServer().isDebug(), starting); + } + + /** + * Return the runtime (VM) arguments. + * + * @return java.lang.String + */ + protected String[] getRuntimeVMArguments() { + IPath configPath = null; + if (getTomcatServer().isTestEnvironment()) + configPath = getTempDirectory(); + return getTomcatVersionHandler().getRuntimeVMArguments(getServer().getRuntime().getLocation(), configPath, getTomcatServer().isSecure()); + } + + /** + * Obtain a temporary directory if this server doesn't + * already have one. Otherwise, return the existing one. + * @return java.io.File + */ + public IPath getTempDirectory() { + if (tempDirectory == null) + tempDirectory = getServer().getTempDirectory(); + return tempDirectory; + } + + protected static String renderCommandLine(String[] commandLine, String separator) { + if (commandLine == null || commandLine.length < 1) + return ""; + StringBuffer buf= new StringBuffer(commandLine[0]); + for (int i = 1; i < commandLine.length; i++) { + buf.append(separator); + buf.append(commandLine[i]); + } + return buf.toString(); + } + + public void setProcess(final IProcess newProcess) { + if (process != null) + return; + + process = newProcess; + processListener = new IDebugEventSetListener() { + public void handleDebugEvents(DebugEvent[] events) { + if (events != null) { + int size = events.length; + for (int i = 0; i < size; i++) { + if (process.equals(events[i].getSource()) && events[i].getKind() == DebugEvent.TERMINATE) { + DebugPlugin.getDefault().removeDebugEventListener(this); + stopImpl(); + } + } + } + } + }; + DebugPlugin.getDefault().addDebugEventListener(processListener); + } + + protected void stopImpl() { + if (ping != null) { + ping.stopPinging(); + ping = null; + } + if (process != null) { + process = null; + DebugPlugin.getDefault().removeDebugEventListener(processListener); + processListener = null; + } + setServerState(IServer.STATE_STOPPED); + } + + public void publishServer(IProgressMonitor monitor) throws CoreException { + IPath confDir = null; + if (getTomcatServer().isTestEnvironment()) { + confDir = getTempDirectory(); + File temp = confDir.append("conf").toFile(); + if (!temp.exists()) + temp.mkdirs(); + } else + confDir = getServer().getRuntime().getLocation(); + IStatus status = getTomcatConfiguration().backupAndPublish(confDir, !getTomcatServer().isTestEnvironment(), monitor); + if (status != null && !status.isOK()) + throw new CoreException(status); + + setServerPublishState(IServer.PUBLISH_STATE_NONE); + } + + /** + * Returns the project publisher that can be used to + * publish the given project. + */ + public void publishModule(IModule[] parents, IModule module, IProgressMonitor monitor) { + if (getTomcatServer().isTestEnvironment()) + return; + + IWebModule webModule = (IWebModule) module; + IPath from = webModule.getLocation(); + IPath to = getServer().getRuntime().getLocation().append("webapps").append(webModule.getContextRoot()); + FileUtil.smartCopyDirectory(from.toOSString(), to.toOSString(), monitor); + } + + /** + * Setup for starting the server. + * + * @param launch ILaunch + * @param launchMode String + * @param monitor IProgressMonitor + */ + public void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException { + if ("true".equals(launch.getLaunchConfiguration().getAttribute(ATTR_STOP, "false"))) + return; + IStatus status = getTomcatRuntime().validate(); + if (status != null && !status.isOK()) + throw new CoreException(status); + + //setRestartNeeded(false); + TomcatConfiguration configuration = getTomcatConfiguration(); + + // check that ports are free + Iterator iterator = configuration.getServerPorts().iterator(); + while (iterator.hasNext()) { + IServerPort sp = (IServerPort) iterator.next(); + if (SocketUtil.isPortInUse(sp.getPort(), 5)) + throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, TomcatPlugin.getResource("%errorPortInUse", new String[] {sp.getPort() + "", sp.getName()}), null)); + } + + setServerState(IServer.STATE_STARTING); + + // ping server to check for startup + try { + String url = "http://localhost"; + int port = configuration.getMainPort().getPort(); + if (port != 80) + url += ":" + port; + ping = new PingThread(getServer(), this, url); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Can't ping for Tomcat startup."); + } + } + + /** + * Cleanly shuts down and terminates the server. + */ + public void stop(boolean force) { + if (force) { + terminate(); + return; + } + int state = getServer().getServerState(); + if (state == IServer.STATE_STOPPED) + return; + else if (state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING) { + terminate(); + return; + } + + try { + Trace.trace(Trace.FINER, "Stopping Tomcat"); + if (state != IServer.STATE_STOPPED) + setServerState(IServer.STATE_STOPPING); + + ILaunchConfiguration launchConfig = getServer().getLaunchConfiguration(true, null); + ILaunchConfigurationWorkingCopy wc = launchConfig.getWorkingCopy(); + + String args = renderCommandLine(getRuntimeProgramArguments(false), " "); + wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args); + wc.setAttribute(ATTR_STOP, "true"); + wc.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor()); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Error stopping Tomcat", e); + } + } + + /** + * Terminates the server. + */ + protected void terminate() { + if (getServer().getServerState() == IServer.STATE_STOPPED) + return; + + try { + setServerState(IServer.STATE_STOPPING); + Trace.trace(Trace.FINER, "Killing the Tomcat process"); + if (process != null && !process.isTerminated()) { + process.terminate(); + stopImpl(); + } + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Error killing the process", e); + } + } + + /** + * Return a string representation of this object. + * @return java.lang.String + */ + public String toString() { + return "TomcatServer"; + } + + /** + * Update the given configuration in the server. + * (i.e. publish any changes to the server, and restart if necessary) + * @param config org.eclipse.wst.server.core.model.IServerConfiguration + */ + /*public void updateConfiguration() { + Trace.trace(Trace.FINEST, "Configuration updated " + this); + //setConfigurationSyncState(SYNC_STATE_DIRTY); + //setRestartNeeded(true); + }*/ + + /** + * Respond to updates within the project tree. + */ + //public void updateModule(final IModule module, IModuleResourceDelta delta) { } + + public void setLaunchDefaults(ILaunchConfigurationWorkingCopy workingCopy) { + ITomcatRuntime runtime = getTomcatRuntime(); + IVMInstall vmInstall = runtime.getVMInstall(); + if (vmInstall != null) { + workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmInstall.getVMInstallType().getId()); + workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, vmInstall.getName()); + } + + String[] args = getRuntimeProgramArguments(true); + String args2 = renderCommandLine(args, " "); + workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args2); + + args = getRuntimeVMArguments(); + args2 = renderCommandLine(args, " "); + workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, args2); + + List cp = runtime.getRuntimeClasspath(); + + // add tools.jar to the path + if (vmInstall != null) { + try { + cp.add(JavaRuntime.newRuntimeContainerClasspathEntry(new Path(JavaRuntime.JRE_CONTAINER).append("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType").append(vmInstall.getName()), IRuntimeClasspathEntry.BOOTSTRAP_CLASSES)); + } catch (Exception e) { + // ignore + } + + IPath jrePath = new Path(vmInstall.getInstallLocation().getAbsolutePath()); + if (jrePath != null) { + IPath toolsPath = jrePath.append("lib").append("tools.jar"); + if (toolsPath.toFile().exists()) { + cp.add(JavaRuntime.newArchiveRuntimeClasspathEntry(toolsPath)); + } + } + } + + Iterator cpi = cp.iterator(); + List list = new ArrayList(); + while (cpi.hasNext()) { + IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) cpi.next(); + try { + list.add(entry.getMemento()); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could not resolve classpath entry: " + entry, e); + } + } + workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, list); + workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerLocator.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerLocator.java index db3913c04..ef50fc3ed 100644 --- a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerLocator.java +++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerLocator.java @@ -20,12 +20,12 @@ import org.eclipse.wst.server.core.model.ServerLocatorDelegate; public class TomcatServerLocator extends ServerLocatorDelegate { public void searchForServers(String host, final IServerLocator.Listener listener, final IProgressMonitor monitor) { IRuntimeLocator.Listener listener2 = new IRuntimeLocator.Listener() { - public void runtimeFound(IRuntime runtime) { + public void runtimeFound(IRuntimeWorkingCopy runtime) { String runtimeTypeId = runtime.getRuntimeType().getId(); String serverTypeId = runtimeTypeId.substring(0, runtimeTypeId.length() - 8); - IServerType serverType = ServerCore.getServerType(serverTypeId); + IServerType serverType = ServerCore.findServerType(serverTypeId); try { - IServer server = serverType.createServer(serverTypeId, null, runtime, monitor); + IServerWorkingCopy server = serverType.createServer(serverTypeId, null, runtime, monitor); listener.serverFound(server); } catch (Exception e) { Trace.trace(Trace.WARNING, "Could not create Tomcat server", e); diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerWorkingCopy.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerWorkingCopy.java deleted file mode 100644 index 3d2d01a81..000000000 --- a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerWorkingCopy.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.eclipse.jst.server.tomcat.core.internal; -/********************************************************************** - * Copyright (c) 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - **********************************************************************/ -import java.util.List; - -import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jst.server.j2ee.IWebModule; -import org.eclipse.jst.server.tomcat.core.ITomcatConfigurationWorkingCopy; -import org.eclipse.jst.server.tomcat.core.ITomcatServerWorkingCopy; -import org.eclipse.jst.server.tomcat.core.WebModule; - -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.IServer; -import org.eclipse.wst.server.core.IServerConfigurationWorkingCopy; -import org.eclipse.wst.server.core.IServerWorkingCopy; -/** - * - */ -public class TomcatServerWorkingCopy extends TomcatServer implements ITomcatServerWorkingCopy { - protected IServerWorkingCopy workingCopy; - - public TomcatServerWorkingCopy() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.wst.server.core.model.ServerWorkingCopyDelegate#initializeWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) - */ - public void initialize(IServerWorkingCopy workingCopy2) { - this.workingCopy = workingCopy2; - } - - public void setDefaults() { - setTestEnvironment(true); - } - - /** - * Sets this process to debug mode. This feature only works - * with Tomcat v4.0. - * - * @param b boolean - */ - public void setDebug(boolean b) { - //setAttribute(PROPERTY_DEBUG, b); - } - - /** - * Sets this process to secure mode. - * @param b boolean - */ - public void setSecure(boolean b) { - //workingCopy.setAttribute(PROPERTY_SECURE, b); - } - - /** - * Sets this server to test environment mode. - * - * @param b boolean - */ - public void setTestEnvironment(boolean b) { - //workingCopy.setAttribute(PROPERTY_TEST_ENVIRONMENT, b); - } - - /** - * Add the given project to this configuration. The project - * has already been verified using isSupportedProject() and - * does not already exist in the configuration. - * - * @param ref java.lang.String - */ - public void modifyModules(IModule[] add, IModule[] remove, IProgressMonitor monitor) throws CoreException { - IStatus status = canModifyModules(add, remove); - if (status == null || !status.isOK()) - throw new CoreException(status); - - IServerConfigurationWorkingCopy scwc = getServer().getServerConfiguration().createWorkingCopy(); - // TODO - ITomcatConfigurationWorkingCopy wc = (ITomcatConfigurationWorkingCopy) scwc.getAdapter(ITomcatConfigurationWorkingCopy.class); - boolean change = false; - - if (add != null) { - int size = add.length; - for (int i = 0; i < size; i++) { - IModule module3 = add[i]; - IWebModule module = (IWebModule) module3.getAdapter(IWebModule.class); - String contextRoot = module.getContextRoot(); - if (contextRoot != null && !contextRoot.startsWith("/")) - contextRoot = "/" + contextRoot; - WebModule module2 = new WebModule(contextRoot, - module.getLocation().toOSString(), module3.getId(), true); - wc.addWebModule(-1, module2); - change = true; - } - } - - if (remove != null) { - int size2 = remove.length; - for (int j = 0; j < size2; j++) { - IModule module3 = remove[j]; - String memento = module3.getId(); - List modules = getTomcatConfiguration().getWebModules(); - int size = modules.size(); - for (int i = 0; i < size; i++) { - WebModule module = (WebModule) modules.get(i); - if (memento.equals(module.getMemento())) { - wc.removeWebModule(i); - change = true; - } - } - } - } - if (change) - scwc.save(false, monitor); - setServerPublishState(IServer.PUBLISH_STATE_FULL); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatSourcePathComputerDelegate.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatSourcePathComputerDelegate.java index d76fb1265..0f4ff3cc8 100644 --- a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatSourcePathComputerDelegate.java +++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatSourcePathComputerDelegate.java @@ -39,7 +39,7 @@ public class TomcatSourcePathComputerDelegate implements ISourcePathComputerDele String serverId = configuration.getAttribute(IServer.ATTR_SERVER_ID, (String) null); - IServer server = ServerCore.getServer(serverId); + IServer server = ServerCore.findServer(serverId); if (server != null) { List list = new ArrayList(); List pathList = new ArrayList(); |