geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sppa...@apache.org
Subject svn commit: r398149 - in /geronimo/devtools/eclipse-plugin/trunk/plugins: org.apache.geronimo.st.core/META-INF/ org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/ org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/ org.apach...
Date Sat, 29 Apr 2006 13:37:29 GMT
Author: sppatel
Date: Sat Apr 29 06:37:27 2006
New Revision: 398149

URL: http://svn.apache.org/viewcvs?rev=398149&view=rev
Log:
push common deployment to core, add inplace option

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/ServerLifeCycleListener.java   (with props)
Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GenericGeronimoServerBehaviour.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DeploymentCommandFactory.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DistributeCommand.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/RedeployCommand.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/Activator.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServer.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF?rev=398149&r1=398148&r2=398149&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/META-INF/MANIFEST.MF Sat Apr 29 06:37:27 2006
@@ -27,7 +27,8 @@
  org.eclipse.wst.common.project.facet.core,
  org.eclipse.jem.util,
  org.eclipse.jdt.core,
- org.apache.geronimo.runtime.common
+ org.apache.geronimo.runtime.common,
+ org.eclipse.debug.core
 Eclipse-AutoStart: true
 Export-Package: org.apache.geronimo.st.core,
  org.apache.geronimo.st.core.commands,

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GenericGeronimoServerBehaviour.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GenericGeronimoServerBehaviour.java?rev=398149&r1=398148&r2=398149&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GenericGeronimoServerBehaviour.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/GenericGeronimoServerBehaviour.java Sat Apr 29 06:37:27 2006
@@ -15,11 +15,47 @@
  */
 package org.apache.geronimo.st.core;
 
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Timer;
+
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.TargetModuleID;
+
+import org.apache.geronimo.st.core.commands.DeploymentCommandFactory;
+import org.apache.geronimo.st.core.commands.IDeploymentCommand;
+import org.apache.geronimo.st.core.commands.TargetModuleIdNotFoundException;
+import org.apache.geronimo.st.core.internal.Messages;
+import org.apache.geronimo.st.core.internal.Trace;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jst.server.generic.core.internal.CorePlugin;
 import org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour;
+import org.eclipse.jst.server.generic.core.internal.GenericServerCoreMessages;
+import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerListener;
+import org.eclipse.wst.server.core.ServerEvent;
+import org.eclipse.wst.server.core.ServerPort;
+import org.eclipse.wst.server.core.util.SocketUtil;
 
 abstract public class GenericGeronimoServerBehaviour extends
 		GenericServerBehaviour implements IGeronimoServerBehavior {
+	
+	public static final String ATTR_STOP = "stop-server";
+
+	public static final int TIMER_TASK_INTERVAL = 10;
+
+	protected IProgressMonitor _monitor;
+
+	protected Timer timer = null;
+
+	protected PingThread pingThread;
 
 	public void setServerStarted() {
 		setServerState(IServer.STATE_STARTED);
@@ -27,5 +63,294 @@
 
 	public void setServerStopped() {
 		setServerState(IServer.STATE_STOPPED);
+	}
+
+	public IGeronimoServer getGeronimoServer() {
+		return (IGeronimoServer) getServer().loadAdapter(IGeronimoServer.class,
+				null);
+	}
+
+	abstract public String getConfigId(IModule module);
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#publishModule(int,
+	 *      int, org.eclipse.wst.server.core.IModule[],
+	 *      org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public void publishModule(int kind, int deltaKind, IModule[] module,
+			IProgressMonitor monitor) throws CoreException {
+
+		Trace.trace(Trace.INFO, ">> publishModule(), deltaKind = " + deltaKind);
+		Trace.trace(Trace.INFO, Arrays.asList(module).toString());
+		_monitor = monitor;
+
+		if (module.length == 1 && (deltaKind == ADDED || deltaKind == REMOVED)) {
+			invokeCommand(deltaKind, module[0]);
+		} else if (deltaKind == CHANGED) {
+			// TODO This case is flawed due to WTP Bugzilla 123676
+			invokeCommand(deltaKind, module[0]);
+		}
+
+		setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
+
+		Trace.trace(Trace.INFO, "<< publishModule()");
+	}
+
+	protected void invokeCommand(int deltaKind, IModule module)
+			throws CoreException {
+		try {
+			switch (deltaKind) {
+			case ADDED: {
+				doDeploy(module);
+				break;
+			}
+			case CHANGED: {
+				doRedeploy(module);
+				break;
+			}
+			case REMOVED: {
+				doUndeploy(module);
+				break;
+			}
+			default:
+				throw new IllegalArgumentException();
+			}
+		} catch (CoreException e) {
+			throw e;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	protected void doDeploy(IModule module) throws Exception {
+		Trace.trace(Trace.INFO, ">> doDeploy() " + module.toString());
+
+		DeploymentManager dm = DeploymentCommandFactory
+				.getDeploymentManager(getServer());
+
+		if (!DeploymentUtils.configurationExists(module, dm)) {
+			IStatus status = distribute(module);
+			if (!status.isOK()) {
+				doFail(status, Messages.DISTRIBUTE_FAIL);
+			}
+
+			status = start(module);
+			if (!status.isOK()) {
+				doFail(status, Messages.START_FAIL);
+			}
+		} else {
+			String id = getConfigId(module);
+			String message = id
+					+ "already exists.  Existing configuration will be overwritten.";
+			Activator.log(Status.ERROR, message, null);
+			doRedeploy(module);
+		}
+
+		Trace.trace(Trace.INFO, "<< doDeploy() " + module.toString());
+	}
+
+	protected void doRedeploy(IModule module) throws Exception {
+		Trace.trace(Trace.INFO, ">> doRedeploy() " + module.toString());
+
+		try {
+			IStatus status = reDeploy(module);
+			if (!status.isOK()) {
+				doFail(status, Messages.REDEPLOY_FAIL);
+			}
+		} catch (TargetModuleIdNotFoundException e) {
+			Activator.log(Status.WARNING,
+					"Module may have been uninstalled outside the workspace.",
+					e);
+			doDeploy(module);
+		}
+
+		Trace.trace(Trace.INFO, "<< doRedeploy() " + module.toString());
+	}
+
+	protected void doUndeploy(IModule module) throws Exception {
+		Trace.trace(Trace.INFO, ">> doUndeploy() " + module.toString());
+
+		IStatus status = stop(module);
+		if (!status.isOK()) {
+			doFail(status, Messages.STOP_FAIL);
+		}
+
+		status = unDeploy(module);
+		if (!status.isOK()) {
+			doFail(status, Messages.UNDEPLOY_FAIL);
+		}
+
+		Trace.trace(Trace.INFO, "<< doUndeploy()" + module.toString());
+	}
+
+	protected void doRestart(IModule module) throws Exception {
+		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
+
+		IStatus status = stop(module);
+		if (!status.isOK()) {
+			doFail(status, Messages.STOP_FAIL);
+		}
+
+		status = start(module);
+		if (!status.isOK()) {
+			doFail(status, Messages.START_FAIL);
+		}
+
+		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
+	}
+
+	protected void doFail(IStatus status, String message) throws CoreException {
+		throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+				0, message, new Exception(status.getMessage())));
+	}
+
+	protected IStatus distribute(IModule module) throws Exception {
+		IDeploymentCommand cmd = DeploymentCommandFactory
+				.createDistributeCommand(module, getServer(), true);
+		return cmd.execute(_monitor);
+	}
+
+	protected IStatus start(IModule module) throws Exception {
+		TargetModuleID id = DeploymentUtils.getTargetModuleID(module,
+				DeploymentCommandFactory.getDeploymentManager(getServer()));
+		IDeploymentCommand cmd = DeploymentCommandFactory.createStartCommand(
+				new TargetModuleID[] { id }, module, getServer());
+		return cmd.execute(_monitor);
+	}
+
+	protected IStatus stop(IModule module) throws Exception {
+		IDeploymentCommand cmd = DeploymentCommandFactory.createStopCommand(
+				module, getServer());
+		return cmd.execute(_monitor);
+	}
+
+	protected IStatus unDeploy(IModule module) throws Exception {
+		IDeploymentCommand cmd = DeploymentCommandFactory
+				.createUndeployCommand(module, getServer());
+		return cmd.execute(_monitor);
+	}
+
+	protected IStatus reDeploy(IModule module) throws Exception {
+		IDeploymentCommand cmd = DeploymentCommandFactory
+				.createRedeployCommand(module, getServer(), true);
+		return cmd.execute(_monitor);
+	}
+
+	public Map getServerInstanceProperties() {
+		return getRuntimeDelegate().getServerInstanceProperties();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#setupLaunchConfiguration(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy,
+	 *      org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public void setupLaunchConfiguration(
+			ILaunchConfigurationWorkingCopy workingCopy,
+			IProgressMonitor monitor) throws CoreException {
+		String defaultArgs = getServerDefinition().getResolver()
+				.resolveProperties(
+						getServerDefinition().getStart()
+								.getProgramArgumentsAsString());
+		String existingPrgArgs = workingCopy.getAttribute(
+				IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
+				defaultArgs);
+		super.setupLaunchConfiguration(workingCopy, monitor);
+		if (existingPrgArgs != null) {
+			workingCopy.setAttribute(
+					IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
+					existingPrgArgs);
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour#setupLaunch(org.eclipse.debug.core.ILaunch,
+	 *      java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	protected void setupLaunch(ILaunch launch, String launchMode,
+			IProgressMonitor monitor) throws CoreException {
+		Trace.trace(Trace.INFO, "--> GeronimoServerBehavior.setupLaunch()");
+
+		if ("true".equals(launch.getLaunchConfiguration().getAttribute(
+				ATTR_STOP, "false")))
+			return;
+
+		if (!SocketUtil.isLocalhost(getServer().getHost()))
+			return;
+
+		ServerPort[] ports = getServer().getServerPorts(null);
+		for (int i = 0; i < ports.length; i++) {
+			ServerPort sp = ports[i];
+			if (SocketUtil.isPortInUse(ports[i].getPort(), 5))
+				throw new CoreException(new Status(IStatus.ERROR,
+						CorePlugin.PLUGIN_ID, 0, GenericServerCoreMessages
+								.bind(GenericServerCoreMessages.errorPortInUse,
+										Integer.toString(sp.getPort()), sp
+												.getName()), null));
+		}
+
+		stopUpdateServerStateTask();
+		setServerState(IServer.STATE_STARTING);
+		setMode(launchMode);
+
+		IServerListener listener = new IServerListener() {
+			public void serverChanged(ServerEvent event) {
+				int eventKind = event.getKind();
+				if (eventKind == (ServerEvent.SERVER_CHANGE | ServerEvent.STATE_CHANGE)) {
+					IServer server = event.getServer();
+					int state = server.getServerState();
+					if (state == IServer.STATE_STARTED
+							|| state == IServer.STATE_STOPPED) {
+						GenericGeronimoServerBehaviour.this.getServer()
+								.removeServerListener(this);
+						startUpdateServerStateTask();
+					}
+				}
+			}
+		};
+
+		getServer().addServerListener(listener);
+		pingThread = new PingThread(this, getServer());
+		pingThread.start();
+		Trace.trace(Trace.INFO, "<-- GeronimoServerBehavior.setupLaunch()");
+	}
+
+	protected void startUpdateServerStateTask() {
+		Trace.trace(Trace.INFO, "startUpdateServerStateTask() "
+				+ getServer().getName());
+		timer = new Timer(true);
+		timer.schedule(new UpdateServerStateTask(this, getServer()), 10000,
+				TIMER_TASK_INTERVAL * 1000);
+	}
+
+	protected void stopUpdateServerStateTask() {
+		Trace.trace(Trace.INFO, "stopUpdateServerStateTask() "
+				+ getServer().getName());
+		if (timer != null)
+			timer.cancel();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#initialize(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	protected void initialize(IProgressMonitor monitor) {
+		Trace.trace(Trace.INFO, "GeronimoServerBehavior.initialize()");
+		startUpdateServerStateTask();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#dispose()
+	 */
+	public void dispose() {
+		stopUpdateServerStateTask();
 	}
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DeploymentCommandFactory.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DeploymentCommandFactory.java?rev=398149&r1=398148&r2=398149&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DeploymentCommandFactory.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DeploymentCommandFactory.java Sat Apr 29 06:37:27 2006
@@ -46,8 +46,8 @@
 	 * @throws CoreException
 	 */
 	public static IDeploymentCommand createDistributeCommand(IModule module,
-			IServer server) throws CoreException {
-		return new SynchronizedDeploymentOp(new DistributeCommand(module, getDeploymentManager(server)));
+			IServer server, boolean inPlace) throws CoreException {
+		return new SynchronizedDeploymentOp(new DistributeCommand(module, getDeploymentManager(server), inPlace));
 	}
 
 	/**
@@ -80,8 +80,8 @@
 	 * @throws CoreException
 	 */
 	public static IDeploymentCommand createRedeployCommand(IModule module,
-			IServer server) throws CoreException {
-		return new SynchronizedDeploymentOp(new RedeployCommand(module, getDeploymentManager(server)));
+			IServer server, boolean inPlace) throws CoreException {
+		return new SynchronizedDeploymentOp(new RedeployCommand(module, getDeploymentManager(server), inPlace));
 	}
 
 	/**

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DistributeCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DistributeCommand.java?rev=398149&r1=398148&r2=398149&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DistributeCommand.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/DistributeCommand.java Sat Apr 29 06:37:27 2006
@@ -27,9 +27,12 @@
 import org.eclipse.wst.server.core.IModule;
 
 class DistributeCommand extends AbstractDeploymentCommand {
-
-	public DistributeCommand(IModule module, DeploymentManager dm) {
+	
+	boolean inPlace;
+	
+	public DistributeCommand(IModule module, DeploymentManager dm, boolean inPlace) {
 		super(dm, module);
+		this.inPlace = inPlace;
 	}
 
 	/*
@@ -39,8 +42,15 @@
 	 */
 	public IStatus execute(IProgressMonitor monitor) {
 		Target[] targets = getDeploymentManager().getTargets();
-		File jarFile = DeploymentUtils.createJarFile(getModule());
-		return new DeploymentCmdStatus(Status.OK_STATUS, getDeploymentManager().distribute(targets, jarFile, null));
+		File file = null;
+		
+		if(inPlace) {
+			file = getModule().getProject().getLocation().toFile();
+		} else {
+			file = DeploymentUtils.createJarFile(getModule());
+		}
+		
+		return new DeploymentCmdStatus(Status.OK_STATUS, getDeploymentManager().distribute(targets, file, null));
 	}
 
 	/*
@@ -51,5 +61,6 @@
 	public CommandType getCommandType() {
 		return CommandType.DISTRIBUTE;
 	}
+	
 
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/RedeployCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/RedeployCommand.java?rev=398149&r1=398148&r2=398149&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/RedeployCommand.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/org/apache/geronimo/st/core/commands/RedeployCommand.java Sat Apr 29 06:37:27 2006
@@ -28,9 +28,12 @@
 import org.eclipse.wst.server.core.IModule;
 
 class RedeployCommand extends AbstractDeploymentCommand {
+	
+	boolean inPlace;
 
-	public RedeployCommand(IModule module, DeploymentManager dm) {
+	public RedeployCommand(IModule module, DeploymentManager dm, boolean inPlace) {
 		super(dm, module);
+		this.inPlace = inPlace;
 	}
 
 	/*
@@ -40,10 +43,15 @@
 	 */
 	public IStatus execute(IProgressMonitor monitor)
 			throws TargetModuleIdNotFoundException {
-
+		
+		File file = null;
+		if(inPlace) {
+			file = getModule().getProject().getLocation().toFile();
+		} else {
+			file = DeploymentUtils.createJarFile(getModule());
+		}
 		TargetModuleID id = DeploymentUtils.getTargetModuleID(getModule(), getDeploymentManager());
-		File jarFile = DeploymentUtils.createJarFile(getModule());
-		return new DeploymentCmdStatus(Status.OK_STATUS, getDeploymentManager().redeploy(new TargetModuleID[] { id }, jarFile, null));
+		return new DeploymentCmdStatus(Status.OK_STATUS, getDeploymentManager().redeploy(new TargetModuleID[] { id }, file, null));
 	}
 
 	/*
@@ -54,5 +62,4 @@
 	public CommandType getCommandType() {
 		return CommandType.REDEPLOY;
 	}
-
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java?rev=398149&r1=398148&r2=398149&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v1.core/src/org/apache/geronimo/st/v1/core/GeronimoServerBehaviour.java Sat Apr 29 06:37:27 2006
@@ -16,14 +16,10 @@
 package org.apache.geronimo.st.v1.core;
 
 import java.net.MalformedURLException;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
-import java.util.Timer;
 
-import javax.enterprise.deploy.spi.DeploymentManager;
-import javax.enterprise.deploy.spi.TargetModuleID;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 import javax.management.remote.JMXConnector;
@@ -36,46 +32,17 @@
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.config.PersistentConfigurationList;
 import org.apache.geronimo.kernel.jmx.KernelDelegate;
-import org.apache.geronimo.st.core.DeploymentUtils;
 import org.apache.geronimo.st.core.GenericGeronimoServerBehaviour;
 import org.apache.geronimo.st.core.GeronimoConnectionFactory;
-import org.apache.geronimo.st.core.IGeronimoServer;
-import org.apache.geronimo.st.core.PingThread;
-import org.apache.geronimo.st.core.UpdateServerStateTask;
-import org.apache.geronimo.st.core.commands.DeploymentCommandFactory;
-import org.apache.geronimo.st.core.commands.IDeploymentCommand;
-import org.apache.geronimo.st.core.commands.TargetModuleIdNotFoundException;
-import org.apache.geronimo.st.v1.core.internal.Messages;
 import org.apache.geronimo.st.v1.core.internal.Trace;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.jst.server.generic.core.internal.CorePlugin;
-import org.eclipse.jst.server.generic.core.internal.GenericServerCoreMessages;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.IServerListener;
-import org.eclipse.wst.server.core.ServerEvent;
-import org.eclipse.wst.server.core.ServerPort;
-import org.eclipse.wst.server.core.util.SocketUtil;
 
 public class GeronimoServerBehaviour extends GenericGeronimoServerBehaviour {
 
-	private static final String ATTR_STOP = "stop-server";
-
-	private static final int TIMER_TASK_INTERVAL = 10;
-
-	private IProgressMonitor _monitor = null;
-
 	private Kernel kernel = null;
 
-	private Timer timer = null;
-	PingThread pingThread;
-
 	public GeronimoServerBehaviour() {
 		super();
 	}
@@ -136,6 +103,9 @@
 		return kernel;
 	}
 
+	/* (non-Javadoc)
+	 * @see org.apache.geronimo.st.core.IGeronimoServerBehavior#isKernelAlive()
+	 */
 	public boolean isKernelAlive() {
 		try {
 			return getKernel() != null && kernel.isRunning();
@@ -152,6 +122,9 @@
 		return false;
 	}
 
+	/* (non-Javadoc)
+	 * @see org.apache.geronimo.st.core.IGeronimoServerBehavior#isFullyStarted()
+	 */
 	public boolean isFullyStarted() {
 		if (isKernelAlive()) {
 			Set configLists = kernel.listGBeans(new GBeanQuery(null, PersistentConfigurationList.class.getName()));
@@ -174,265 +147,11 @@
 		return false;
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#publishModule(int,
-	 *      int, org.eclipse.wst.server.core.IModule[],
-	 *      org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	public void publishModule(int kind, int deltaKind, IModule[] module,
-			IProgressMonitor monitor) throws CoreException {
-		Trace.trace(Trace.INFO, ">> publishModule(), deltaKind = " + deltaKind);
-		Trace.trace(Trace.INFO, Arrays.asList(module).toString());
-		_monitor = monitor;
-
-		if (module.length == 1 && (deltaKind == ADDED || deltaKind == REMOVED)) {
-			invokeCommand(deltaKind, module[0]);
-		} else if (deltaKind == CHANGED) {
-			// TODO This case is flawed due to WTP Bugzilla 123676
-			invokeCommand(deltaKind, module[0]);
-		}
-
-		setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
-
-		Trace.trace(Trace.INFO, "<< publishModule()");
-	}
-
-	private void invokeCommand(int deltaKind, IModule module)
-			throws CoreException {
-		try {
-			switch (deltaKind) {
-			case ADDED: {
-				doDeploy(module);
-				break;
-			}
-			case CHANGED: {
-				doRedeploy(module);
-				break;
-			}
-			case REMOVED: {
-				doUndeploy(module);
-				break;
-			}
-			default:
-				throw new IllegalArgumentException();
-			}
-		} catch (CoreException e) {
-			throw e;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	private void doDeploy(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doDeploy() " + module.toString());
-
-		DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(getServer());
-
-		if (!DeploymentUtils.configurationExists(module, dm)) {
-			IStatus status = distribute(module);
-			if (!status.isOK()) {
-				doFail(status, Messages.DISTRIBUTE_FAIL);
-			}
-
-			status = start(module);
-			if (!status.isOK()) {
-				doFail(status, Messages.START_FAIL);
-			}
-		} else {
-			String id = GeronimoV1Utils.getConfigId(module);
-			String message = id
-					+ "already exists.  Existing configuration will be overwritten.";
-			Activator.log(Status.ERROR, message, null);
-			doRedeploy(module);
-		}
-
-		Trace.trace(Trace.INFO, "<< doDeploy() " + module.toString());
-	}
-
-	private void doRedeploy(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doRedeploy() " + module.toString());
-
-		try {
-			IStatus status = reDeploy(module);
-			if (!status.isOK()) {
-				doFail(status, Messages.REDEPLOY_FAIL);
-			}
-		} catch (TargetModuleIdNotFoundException e) {
-			Activator.log(Status.WARNING, "Module may have been uninstalled outside the workspace.", e);
-			doDeploy(module);
-		}
-
-		Trace.trace(Trace.INFO, "<< doRedeploy() " + module.toString());
-	}
-
-	private void doUndeploy(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doUndeploy() " + module.toString());
-
-		IStatus status = stop(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.STOP_FAIL);
-		}
-
-		status = unDeploy(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.UNDEPLOY_FAIL);
-		}
-
-		Trace.trace(Trace.INFO, "<< doUndeploy()" + module.toString());
-	}
-
-	private void doRestart(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
-
-		IStatus status = stop(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.STOP_FAIL);
-		}
-
-		status = start(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.START_FAIL);
-		}
-
-		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
-	}
-
-	private void doFail(IStatus status, String message) throws CoreException {
-		throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, message, new Exception(status.getMessage())));
-	}
-
-	private IStatus distribute(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory.createDistributeCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus start(IModule module) throws Exception {
-		TargetModuleID id = DeploymentUtils.getTargetModuleID(module, DeploymentCommandFactory.getDeploymentManager(getServer()));
-		IDeploymentCommand cmd = DeploymentCommandFactory.createStartCommand(new TargetModuleID[] { id }, module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus stop(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory.createStopCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus unDeploy(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory.createUndeployCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus reDeploy(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory.createRedeployCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	public Map getServerInstanceProperties() {
-		return getRuntimeDelegate().getServerInstanceProperties();
-	}
-
-	public IGeronimoServer getGeronimoServer() {
-		return (IGeronimoServer) getServer().loadAdapter(IGeronimoServer.class, null);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#setupLaunchConfiguration(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy,
-	 *      org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	public void setupLaunchConfiguration(
-			ILaunchConfigurationWorkingCopy workingCopy,
-			IProgressMonitor monitor) throws CoreException {
-		String defaultArgs = getServerDefinition().getResolver().resolveProperties(getServerDefinition().getStart().getProgramArgumentsAsString());
-		String existingPrgArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, defaultArgs);
-		super.setupLaunchConfiguration(workingCopy, monitor);
-		if (existingPrgArgs != null) {
-			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, existingPrgArgs);
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour#setupLaunch(org.eclipse.debug.core.ILaunch,
-	 *      java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	protected void setupLaunch(ILaunch launch, String launchMode,
-			IProgressMonitor monitor) throws CoreException {
-		Trace.trace(Trace.INFO, "--> GeronimoServerBehavior.setupLaunch()");
-
-		if ("true".equals(launch.getLaunchConfiguration().getAttribute(ATTR_STOP, "false")))
-			return;
-
-		if (!SocketUtil.isLocalhost(getServer().getHost()))
-			return;
-
-		ServerPort[] ports = getServer().getServerPorts(null);
-		for (int i = 0; i < ports.length; i++) {
-			ServerPort sp = ports[i];
-			if (SocketUtil.isPortInUse(ports[i].getPort(), 5))
-				throw new CoreException(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, GenericServerCoreMessages.bind(GenericServerCoreMessages.errorPortInUse, Integer.toString(sp.getPort()), sp.getName()), null));
-		}
-
-		stopUpdateServerStateTask();
-		setServerState(IServer.STATE_STARTING);
-		setMode(launchMode);
-
-		IServerListener listener = new IServerListener() {
-			public void serverChanged(ServerEvent event) {
-				int eventKind = event.getKind();
-				if (eventKind == (ServerEvent.SERVER_CHANGE | ServerEvent.STATE_CHANGE)) {
-					IServer server = event.getServer();
-					int state = server.getServerState();
-					if (state == IServer.STATE_STARTED
-							|| state == IServer.STATE_STOPPED) {
-						GeronimoServerBehaviour.this.getServer().removeServerListener(this);
-						startUpdateServerStateTask();
-					}
-				}
-			}
-		};
-
-		getServer().addServerListener(listener);
-		pingThread = new PingThread(this, getServer());
-		pingThread.start();
-		Trace.trace(Trace.INFO, "<-- GeronimoServerBehavior.setupLaunch()");
-	}
-
-	private void startUpdateServerStateTask() {
-		Trace.trace(Trace.INFO, "startUpdateServerStateTask() "
-				+ getServer().getName());
-		timer = new Timer(true);
-		timer.schedule(new UpdateServerStateTask(this, getServer()), 10000, TIMER_TASK_INTERVAL * 1000);
-	}
-
-	private void stopUpdateServerStateTask() {
-		Trace.trace(Trace.INFO, "stopUpdateServerStateTask() "
-				+ getServer().getName());
-		if (timer != null)
-			timer.cancel();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#initialize(org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	protected void initialize(IProgressMonitor monitor) {
-		Trace.trace(Trace.INFO, "GeronimoServerBehavior.initialize()");
-		startUpdateServerStateTask();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#dispose()
+	/* (non-Javadoc)
+	 * @see org.apache.geronimo.st.core.GenericGeronimoServerBehaviour#getConfigId(org.eclipse.wst.server.core.IModule)
 	 */
-	public void dispose() {
-		stopUpdateServerStateTask();
+	public String getConfigId(IModule module) {
+		return GeronimoV1Utils.getConfigId(module);
 	}
 
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/Activator.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/Activator.java?rev=398149&r1=398148&r2=398149&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/Activator.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/Activator.java Sat Apr 29 06:37:27 2006
@@ -5,6 +5,8 @@
 import org.apache.geronimo.st.jmxagent.JMXAgent;
 import org.eclipse.core.runtime.Plugin;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IServerLifecycleListener;
+import org.eclipse.wst.server.core.ServerCore;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -17,6 +19,8 @@
 
 	// The shared instance
 	private static Activator plugin;
+	
+	private IServerLifecycleListener listener = new ServerLifeCycleListener();
 
 	/**
 	 * The constructor
@@ -32,6 +36,7 @@
 	 */
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
+		ServerCore.addServerLifecycleListener(listener);
 	}
 
 	/*
@@ -44,7 +49,8 @@
 			JMXAgent.getInstance().stop();
 		} catch (IOException e) {
 			e.printStackTrace();
-		}
+		} 
+		ServerCore.removeServerLifecycleListener(listener);
 		plugin = null;
 		super.stop(context);
 	}
@@ -61,5 +67,4 @@
 	public static void log(int severity, String message, Throwable throwable) {
 		plugin.getLog().log(new Status(severity, PLUGIN_ID, 0, message, throwable));
 	}
-
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServer.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServer.java?rev=398149&r1=398148&r2=398149&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServer.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServer.java Sat Apr 29 06:37:27 2006
@@ -109,6 +109,7 @@
 	 */
 	public void configureDeploymentManager(DeploymentManager dm) {
 		((JMXDeploymentManager) dm).setLogConfiguration(true, true);
+		((JMXDeploymentManager) dm).setInPlace(true);
 	}
 
 	/*

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java?rev=398149&r1=398148&r2=398149&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerBehaviour.java Sat Apr 29 06:37:27 2006
@@ -16,14 +16,10 @@
 package org.apache.geronimo.st.v11.core;
 
 import java.net.MalformedURLException;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
-import java.util.Timer;
 
-import javax.enterprise.deploy.spi.DeploymentManager;
-import javax.enterprise.deploy.spi.TargetModuleID;
 import javax.management.MBeanServerConnection;
 import javax.management.remote.JMXConnector;
 import javax.management.remote.JMXConnectorFactory;
@@ -35,47 +31,19 @@
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.config.PersistentConfigurationList;
-import org.apache.geronimo.st.core.DeploymentUtils;
 import org.apache.geronimo.st.core.GenericGeronimoServerBehaviour;
 import org.apache.geronimo.st.core.GeronimoConnectionFactory;
-import org.apache.geronimo.st.core.IGeronimoServer;
-import org.apache.geronimo.st.core.PingThread;
-import org.apache.geronimo.st.core.UpdateServerStateTask;
-import org.apache.geronimo.st.core.commands.DeploymentCommandFactory;
-import org.apache.geronimo.st.core.commands.IDeploymentCommand;
-import org.apache.geronimo.st.core.commands.TargetModuleIdNotFoundException;
-import org.apache.geronimo.st.v11.core.internal.Messages;
+import org.apache.geronimo.st.jmxagent.Activator;
 import org.apache.geronimo.st.v11.core.internal.Trace;
 import org.apache.geronimo.system.jmx.KernelDelegate;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.jst.server.generic.core.internal.CorePlugin;
-import org.eclipse.jst.server.generic.core.internal.GenericServerCoreMessages;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.IServerListener;
-import org.eclipse.wst.server.core.ServerEvent;
-import org.eclipse.wst.server.core.ServerPort;
-import org.eclipse.wst.server.core.util.SocketUtil;
 
 public class GeronimoServerBehaviour extends GenericGeronimoServerBehaviour {
 
-	private static final String ATTR_STOP = "stop-server";
-
-	private static final int TIMER_TASK_INTERVAL = 10;
-
-	private IProgressMonitor _monitor = null;
-
 	private Kernel kernel = null;
 
-	private Timer timer = null;
-	PingThread pingThread;
-
 	public GeronimoServerBehaviour() {
 		super();
 	}
@@ -119,8 +87,10 @@
 					return null;
 				JMXServiceURL address = new JMXServiceURL(url);
 				try {
-					JMXConnector jmxConnector = JMXConnectorFactory.connect(address, map);
-					MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection();
+					JMXConnector jmxConnector = JMXConnectorFactory.connect(
+							address, map);
+					MBeanServerConnection mbServerConnection = jmxConnector
+							.getMBeanServerConnection();
 					kernel = new KernelDelegate(mbServerConnection);
 					Trace.trace(Trace.INFO, "Connected to kernel.");
 				} catch (SecurityException e) {
@@ -135,7 +105,12 @@
 
 		return kernel;
 	}
-	
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.geronimo.st.core.IGeronimoServerBehavior#isKernelAlive()
+	 */
 	public boolean isKernelAlive() {
 		try {
 			return getKernel() != null && kernel.isRunning();
@@ -146,20 +121,31 @@
 				stop(true);
 			}
 		} catch (Exception e) {
-			Activator.log(Status.WARNING, "Geronimo Server may have been terminated manually outside of workspace.", e);
+			Activator
+					.log(
+							Status.WARNING,
+							"Geronimo Server may have been terminated manually outside of workspace.",
+							e);
 			kernel = null;
 		}
 		return false;
 	}
 
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.geronimo.st.core.IGeronimoServerBehavior#isFullyStarted()
+	 */
 	public boolean isFullyStarted() {
 		if (isKernelAlive()) {
-			AbstractNameQuery query = new AbstractNameQuery(PersistentConfigurationList.class.getName());
+			AbstractNameQuery query = new AbstractNameQuery(
+					PersistentConfigurationList.class.getName());
 			Set configLists = kernel.listGBeans(query);
 			if (!configLists.isEmpty()) {
 				AbstractName on = (AbstractName) configLists.toArray()[0];
 				try {
-					Boolean b = (Boolean) kernel.getAttribute(on, "kernelFullyStarted");
+					Boolean b = (Boolean) kernel.getAttribute(on,
+							"kernelFullyStarted");
 					return b.booleanValue();
 				} catch (GBeanNotFoundException e) {
 					// ignore
@@ -178,263 +164,9 @@
 	/*
 	 * (non-Javadoc)
 	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#publishModule(int,
-	 *      int, org.eclipse.wst.server.core.IModule[],
-	 *      org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	public void publishModule(int kind, int deltaKind, IModule[] module,
-			IProgressMonitor monitor) throws CoreException {
-		
-		Trace.trace(Trace.INFO, ">> publishModule(), deltaKind = " + deltaKind);
-		Trace.trace(Trace.INFO, Arrays.asList(module).toString());
-		_monitor = monitor;
-
-		if (module.length == 1 && (deltaKind == ADDED || deltaKind == REMOVED)) {
-			invokeCommand(deltaKind, module[0]);
-		} else if (deltaKind == CHANGED) {
-			// TODO This case is flawed due to WTP Bugzilla 123676
-			invokeCommand(deltaKind, module[0]);
-		}
-
-		setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
-
-		Trace.trace(Trace.INFO, "<< publishModule()");
-	}
-
-	private void invokeCommand(int deltaKind, IModule module)
-			throws CoreException {
-		try {
-			switch (deltaKind) {
-			case ADDED: {
-				doDeploy(module);
-				break;
-			}
-			case CHANGED: {
-				doRedeploy(module);
-				break;
-			}
-			case REMOVED: {
-				doUndeploy(module);
-				break;
-			}
-			default:
-				throw new IllegalArgumentException();
-			}
-		} catch (CoreException e) {
-			throw e;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	private void doDeploy(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doDeploy() " + module.toString());
-
-		DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(getServer());
-
-		if (!DeploymentUtils.configurationExists(module, dm)) {
-			IStatus status = distribute(module);
-			if (!status.isOK()) {
-				doFail(status, Messages.DISTRIBUTE_FAIL);
-			}
-
-			status = start(module);
-			if (!status.isOK()) {
-				doFail(status, Messages.START_FAIL);
-			}
-		} else {
-			String id = GeronimoV11Utils.getConfigId(module);
-			String message = id
-					+ "already exists.  Existing configuration will be overwritten.";
-			Activator.log(Status.ERROR, message, null);
-			doRedeploy(module);
-		}
-
-		Trace.trace(Trace.INFO, "<< doDeploy() " + module.toString());
-	}
-
-	private void doRedeploy(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doRedeploy() " + module.toString());
-
-		try {
-			IStatus status = reDeploy(module);
-			if (!status.isOK()) {
-				doFail(status, Messages.REDEPLOY_FAIL);
-			}
-		} catch (TargetModuleIdNotFoundException e) {
-			Activator.log(Status.WARNING, "Module may have been uninstalled outside the workspace.", e);
-			doDeploy(module);
-		}
-
-		Trace.trace(Trace.INFO, "<< doRedeploy() " + module.toString());
-	}
-
-	private void doUndeploy(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doUndeploy() " + module.toString());
-
-		IStatus status = stop(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.STOP_FAIL);
-		}
-
-		status = unDeploy(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.UNDEPLOY_FAIL);
-		}
-
-		Trace.trace(Trace.INFO, "<< doUndeploy()" + module.toString());
-	}
-
-	private void doRestart(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
-
-		IStatus status = stop(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.STOP_FAIL);
-		}
-
-		status = start(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.START_FAIL);
-		}
-
-		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
-	}
-
-	private void doFail(IStatus status, String message) throws CoreException {
-		throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, message, new Exception(status.getMessage())));
-	}
-
-	private IStatus distribute(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory.createDistributeCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus start(IModule module) throws Exception {
-		TargetModuleID id = DeploymentUtils.getTargetModuleID(module, DeploymentCommandFactory.getDeploymentManager(getServer()));
-		IDeploymentCommand cmd = DeploymentCommandFactory.createStartCommand(new TargetModuleID[] { id }, module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus stop(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory.createStopCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus unDeploy(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory.createUndeployCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus reDeploy(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory.createRedeployCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	public Map getServerInstanceProperties() {
-		return getRuntimeDelegate().getServerInstanceProperties();
-	}
-
-	public IGeronimoServer getGeronimoServer() {
-		return (IGeronimoServer) getServer().loadAdapter(IGeronimoServer.class, null);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#setupLaunchConfiguration(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy,
-	 *      org.eclipse.core.runtime.IProgressMonitor)
+	 * @see org.apache.geronimo.st.core.GenericGeronimoServerBehaviour#getConfigId(org.eclipse.wst.server.core.IModule)
 	 */
-	public void setupLaunchConfiguration(
-			ILaunchConfigurationWorkingCopy workingCopy,
-			IProgressMonitor monitor) throws CoreException {
-		String defaultArgs = getServerDefinition().getResolver().resolveProperties(getServerDefinition().getStart().getProgramArgumentsAsString());
-		String existingPrgArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, defaultArgs);
-		super.setupLaunchConfiguration(workingCopy, monitor);
-		if (existingPrgArgs != null) {
-			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, existingPrgArgs);
-		}
+	public String getConfigId(IModule module) {
+		return GeronimoV11Utils.getConfigId(module);
 	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour#setupLaunch(org.eclipse.debug.core.ILaunch,
-	 *      java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	protected void setupLaunch(ILaunch launch, String launchMode,
-			IProgressMonitor monitor) throws CoreException {
-		Trace.trace(Trace.INFO, "--> GeronimoServerBehavior.setupLaunch()");
-
-		if ("true".equals(launch.getLaunchConfiguration().getAttribute(ATTR_STOP, "false")))
-			return;
-
-		if (!SocketUtil.isLocalhost(getServer().getHost()))
-			return;
-
-		ServerPort[] ports = getServer().getServerPorts(null);
-		for (int i = 0; i < ports.length; i++) {
-			ServerPort sp = ports[i];
-			if (SocketUtil.isPortInUse(ports[i].getPort(), 5))
-				throw new CoreException(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, GenericServerCoreMessages.bind(GenericServerCoreMessages.errorPortInUse, Integer.toString(sp.getPort()), sp.getName()), null));
-		}
-
-		stopUpdateServerStateTask();
-		setServerState(IServer.STATE_STARTING);
-		setMode(launchMode);
-
-		IServerListener listener = new IServerListener() {
-			public void serverChanged(ServerEvent event) {
-				int eventKind = event.getKind();
-				if (eventKind == (ServerEvent.SERVER_CHANGE | ServerEvent.STATE_CHANGE)) {
-					IServer server = event.getServer();
-					int state = server.getServerState();
-					if (state == IServer.STATE_STARTED
-							|| state == IServer.STATE_STOPPED) {
-						GeronimoServerBehaviour.this.getServer().removeServerListener(this);
-						startUpdateServerStateTask();
-					}
-				}
-			}
-		};
-
-		getServer().addServerListener(listener);
-		pingThread = new PingThread(this, getServer());
-		pingThread.start();
-		Trace.trace(Trace.INFO, "<-- GeronimoServerBehavior.setupLaunch()");
-	}
-
-	private void startUpdateServerStateTask() {
-		Trace.trace(Trace.INFO, "startUpdateServerStateTask() "
-				+ getServer().getName());
-		timer = new Timer(true);
-		timer.schedule(new UpdateServerStateTask(this, getServer()), 10000, TIMER_TASK_INTERVAL * 1000);
-	}
-
-	private void stopUpdateServerStateTask() {
-		Trace.trace(Trace.INFO, "stopUpdateServerStateTask() "
-				+ getServer().getName());
-		if (timer != null)
-			timer.cancel();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#initialize(org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	protected void initialize(IProgressMonitor monitor) {
-		Trace.trace(Trace.INFO, "GeronimoServerBehavior.initialize()");
-		startUpdateServerStateTask();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#dispose()
-	 */
-	public void dispose() {
-		stopUpdateServerStateTask();
-	}
-
 }

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/ServerLifeCycleListener.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/ServerLifeCycleListener.java?rev=398149&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/ServerLifeCycleListener.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/ServerLifeCycleListener.java Sat Apr 29 06:37:27 2006
@@ -0,0 +1,83 @@
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ *  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.geronimo.st.v11.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.geronimo.kernel.config.IOUtil;
+import org.apache.geronimo.st.jmxagent.Activator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.wst.server.core.IServer;
+
+import org.eclipse.wst.server.core.IServerLifecycleListener;
+
+public class ServerLifeCycleListener implements IServerLifecycleListener {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.IServerLifecycleListener#serverAdded(org.eclipse.wst.server.core.IServer)
+	 */
+	public void serverAdded(IServer server) {
+		if (isSupportedServer(server)) {
+			copyToSharedLib(server, "hessian-3.0.8.jar");
+			copyToSharedLib(server, "mx4j-tools-3.0.1.jar");
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.IServerLifecycleListener#serverChanged(org.eclipse.wst.server.core.IServer)
+	 */
+	public void serverChanged(IServer server) {
+
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.IServerLifecycleListener#serverRemoved(org.eclipse.wst.server.core.IServer)
+	 */
+	public void serverRemoved(IServer server) {
+
+	}
+
+	private void copyToSharedLib(IServer server, String path) {
+		IPath sharedLib = server.getRuntime().getLocation().append(
+				new Path("/var/shared"));
+
+		IPath destFile = sharedLib.append(path);
+
+		if (!destFile.toFile().exists()) {
+			try {
+				URL url = Platform.resolve(Activator.getDefault().getBundle()
+						.getEntry(path));
+				IOUtil.copyFile(new File(url.getFile()), destFile.toFile());
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	private boolean isSupportedServer(IServer server) {
+		return server.getAdapter(GeronimoServer.class) != null;
+	}
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/ServerLifeCycleListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/ServerLifeCycleListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/ServerLifeCycleListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message