[125002] Publish when starting server
diff --git a/plugins/org.eclipse.jst.server.generic.core/src/org/eclipse/jst/server/generic/core/internal/GenericServerLaunchConfigurationDelegate.java b/plugins/org.eclipse.jst.server.generic.core/src/org/eclipse/jst/server/generic/core/internal/GenericServerLaunchConfigurationDelegate.java
index 4bf3389..26d6990 100644
--- a/plugins/org.eclipse.jst.server.generic.core/src/org/eclipse/jst/server/generic/core/internal/GenericServerLaunchConfigurationDelegate.java
+++ b/plugins/org.eclipse.jst.server.generic.core/src/org/eclipse/jst/server/generic/core/internal/GenericServerLaunchConfigurationDelegate.java
@@ -26,6 +26,7 @@
 import org.eclipse.jdt.launching.VMRunnerConfiguration;
 import org.eclipse.jst.server.core.ServerProfilerDelegate;
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
 import org.eclipse.wst.server.core.ServerUtil;
 import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
 import org.eclipse.wst.server.core.util.SocketUtil;
@@ -47,6 +48,10 @@
 			abort(GenericServerCoreMessages.missingServer, null,
 					IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
 		}
+		
+		if (server.shouldPublish() && ServerCore.isAutoPublishing())
+			server.publish(IServer.PUBLISH_INCREMENTAL, monitor);
+		
 		GenericServerBehaviour genericServer = (GenericServerBehaviour) server.loadAdapter(ServerBehaviourDelegate.class, null);
 
 		try {
diff --git a/plugins/org.eclipse.jst.server.preview.adapter/src/org/eclipse/jst/server/preview/adapter/internal/core/PreviewLaunchConfigurationDelegate.java b/plugins/org.eclipse.jst.server.preview.adapter/src/org/eclipse/jst/server/preview/adapter/internal/core/PreviewLaunchConfigurationDelegate.java
index 94d050a..f09c39b 100644
--- a/plugins/org.eclipse.jst.server.preview.adapter/src/org/eclipse/jst/server/preview/adapter/internal/core/PreviewLaunchConfigurationDelegate.java
+++ b/plugins/org.eclipse.jst.server.preview.adapter/src/org/eclipse/jst/server/preview/adapter/internal/core/PreviewLaunchConfigurationDelegate.java
@@ -28,6 +28,7 @@
 import org.eclipse.jst.server.preview.adapter.internal.Trace;
 
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
 import org.eclipse.wst.server.core.ServerUtil;
 import org.osgi.framework.Bundle;
 /**
@@ -54,6 +55,9 @@
 			return;
 		}
 		
+		if (server.shouldPublish() && ServerCore.isAutoPublishing())
+			server.publish(IServer.PUBLISH_INCREMENTAL, monitor);
+		
 		PreviewServerBehaviour previewServer = (PreviewServerBehaviour) server.loadAdapter(PreviewServerBehaviour.class, null);
 		
 		int size = REQUIRED_BUNDLE_IDS.length;
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 794c30e..b254f1a 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
@@ -22,6 +22,7 @@
 import org.eclipse.jst.server.core.ServerProfilerDelegate;
 
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
 import org.eclipse.wst.server.core.ServerUtil;
 /**
  * 
@@ -36,6 +37,9 @@
 			return;
 		}
 		
+		if (server.shouldPublish() && ServerCore.isAutoPublishing())
+			server.publish(IServer.PUBLISH_INCREMENTAL, monitor);
+		
 		TomcatServerBehaviour tomcatServer = (TomcatServerBehaviour) server.loadAdapter(TomcatServerBehaviour.class, null);
 		
 		String mainTypeName = tomcatServer.getRuntimeClass();
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerCore.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerCore.java
index 98647f2..eb0cf97 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerCore.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerCore.java
@@ -451,4 +451,16 @@
 		registry.addRegistryChangeListener(registryListener, ServerPlugin.PLUGIN_ID);
 		ServerPlugin.setRegistryListener(registryListener);
 	}
+
+	/**
+	 * Returns <code>true</code> if the preference is set to automatically
+	 * publish when starting servers, or <code>false</code> otherwise
+	 * 
+	 * @return <code>true</code> if the preference is set to automatically
+	 *    publish when starting servers, or <code>false</code> otherwise
+	 * @since 3.0
+	 */
+	public static boolean isAutoPublishing() {
+		return ServerPreferences.getInstance().isAutoPublishing();
+	}
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/PublishServerJob.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/PublishServerJob.java
index d86f9b3..31ada68 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/PublishServerJob.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/PublishServerJob.java
@@ -19,6 +19,7 @@
 import org.eclipse.core.runtime.jobs.MultiRule;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
 /**
  * Job to publish to a particular server.
  */
@@ -62,10 +63,10 @@
 	 */
 	protected IStatus run(IProgressMonitor monitor) {
 		if (check) {
-			// don't run if we're autopublishing and there is no need for a publish.
+			// don't run if we're auto-publishing and there is no need for a publish.
 			// can't execute this code in shouldRun() because it will cancel the job
 			// instead of returning immediately
-			if (!ServerPreferences.getInstance().isAutoPublishing() || !((Server)getServer()).shouldPublish())
+			if (!ServerCore.isAutoPublishing() || !getServer().shouldPublish())
 				return Status.OK_STATUS;
 		}
 		
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Server.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Server.java
index 4e8dac6..9351eb5 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Server.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Server.java
@@ -1434,7 +1434,7 @@
 											Trace.trace(Trace.SEVERE, "Error while restarting server", e);
 										}
 									}
-									if (ServerPreferences.getInstance().isAutoPublishing() && shouldPublish()) {
+									if (ServerCore.isAutoPublishing() && shouldPublish()) {
 										publish(PUBLISH_INCREMENTAL, null);
 									}
 									if (getServerState() != IServer.STATE_STARTED) {
@@ -1471,7 +1471,7 @@
 		if (getServerType() == null)
 			return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorMissingAdapter, null);
 		
-		if (getServerState() == STATE_STOPPED)
+		if (getServerState() == STATE_STOPPED || getServerState() == STATE_STOPPING)
 			return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorStopAlreadyStopped, null);
 		
 		if (!getServerType().supportsLaunchMode(getMode()))
@@ -1786,7 +1786,7 @@
 											Trace.trace(Trace.SEVERE, "Error while restarting server", e);
 										}
 									}
-									if (ServerPreferences.getInstance().isAutoPublishing() && shouldPublish()) {
+									if (ServerCore.isAutoPublishing() && shouldPublish()) {
 										publish(PUBLISH_INCREMENTAL, null);
 									}
 									if (getServerState() != IServer.STATE_STARTED) {
diff --git a/plugins/org.eclipse.wst.server.preview.adapter/src/org/eclipse/wst/server/preview/adapter/internal/core/PreviewLaunchConfigurationDelegate.java b/plugins/org.eclipse.wst.server.preview.adapter/src/org/eclipse/wst/server/preview/adapter/internal/core/PreviewLaunchConfigurationDelegate.java
index 47e9645..a398bd6 100644
--- a/plugins/org.eclipse.wst.server.preview.adapter/src/org/eclipse/wst/server/preview/adapter/internal/core/PreviewLaunchConfigurationDelegate.java
+++ b/plugins/org.eclipse.wst.server.preview.adapter/src/org/eclipse/wst/server/preview/adapter/internal/core/PreviewLaunchConfigurationDelegate.java
@@ -29,6 +29,7 @@
 import org.eclipse.osgi.service.environment.Constants;
 
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
 import org.eclipse.wst.server.core.ServerUtil;
 import org.osgi.framework.Bundle;
 /**
@@ -58,6 +59,9 @@
 			return;
 		}
 		
+		if (server.shouldPublish() && ServerCore.isAutoPublishing())
+			server.publish(IServer.PUBLISH_INCREMENTAL, monitor);
+		
 		PreviewServerBehaviour previewServer = (PreviewServerBehaviour) server.loadAdapter(PreviewServerBehaviour.class, null);
 		
 		int size = REQUIRED_BUNDLE_IDS.length;
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/view/servers/StartAction.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/view/servers/StartAction.java
index 59e92ea..d6fc6eb 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/view/servers/StartAction.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/view/servers/StartAction.java
@@ -16,9 +16,9 @@
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
 import org.eclipse.wst.server.core.internal.PublishServerJob;
 import org.eclipse.wst.server.core.internal.RestartServerJob;
-import org.eclipse.wst.server.core.internal.ServerPreferences;
 import org.eclipse.wst.server.core.internal.ServerType;
 import org.eclipse.wst.server.core.internal.StartServerJob;
 import org.eclipse.wst.server.ui.internal.ImageResource;
@@ -152,7 +152,7 @@
 			if (!ServerUIPlugin.saveEditors())
 				return;
 			
-			if (!ServerPreferences.getInstance().isAutoPublishing()) {
+			if (!ServerCore.isAutoPublishing()) {
 				StartServerJob startJob = new StartServerJob(server, launchMode);
 				startJob.schedule();
 				return;