Author: rob.stryker(a)jboss.com
Date: 2010-08-06 06:29:45 -0400 (Fri, 06 Aug 2010)
New Revision: 23966
Added:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossBehaviorDelegate.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/LocalJBossServerStartupLaunchUtil.java
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/extensions/polling/ProcessTerminatedPoller.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/RunJarContainerWrapper.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
workspace/rstryker/rse/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/MockTests.java
workspace/rstryker/rse/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/StartupShutdownTest.java
Log:
JBIDE-6796 - extracting local launch behaviour into separate classes
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/extensions/polling/ProcessTerminatedPoller.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/extensions/polling/ProcessTerminatedPoller.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/extensions/polling/ProcessTerminatedPoller.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -14,9 +14,11 @@
import java.util.Properties;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.debug.core.model.IProcess;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
+import
org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior.JBossBehaviourDelegate;
import org.jboss.ide.eclipse.as.core.server.internal.PollThread;
import org.jboss.ide.eclipse.as.core.server.internal.ServerStatePollerType;
@@ -32,7 +34,11 @@
public class ProcessTerminatedPoller implements IServerStatePoller {
public static final String POLLER_ID =
"org.jboss.ide.eclipse.as.core.runtime.server.processTerminatedPoller";
//$NON-NLS-1$
+ public static interface IProcessProvider {
+ public IProcess getProcess();
+ }
+
private ServerStatePollerType type;
private JBossServerBehavior server;
public void beginPolling(IServer server, boolean expectedState,
@@ -55,7 +61,12 @@
}
public boolean isComplete() throws PollingException {
- return server.getProcess() == null || server.getProcess().isTerminated();
+ JBossBehaviourDelegate del = server.getDelegate();
+ if( del instanceof IProcessProvider ) {
+ IProcess p = ((IProcessProvider)del).getProcess();
+ return p == null || p.isTerminated();
+ }
+ return true;
}
public void failureHandled(Properties properties) {
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -18,7 +18,6 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jst.server.core.IEnterpriseApplication;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
@@ -27,9 +26,7 @@
import org.eclipse.wst.server.core.model.ServerDelegate;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.util.ModuleUtil;
import org.jboss.ide.eclipse.as.core.util.ServerUtil;
-import org.jboss.ide.eclipse.as.wtp.core.modules.IJBTModule;
import org.jboss.ide.eclipse.as.wtp.core.util.ServerModelUtilities;
public class DeployableServer extends ServerDelegate implements IDeployableServer {
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -20,35 +20,15 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal;
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
+import java.util.HashMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugEvent;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.IDebugEventSetListener;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
-import org.jboss.ide.eclipse.as.core.extensions.events.ServerLogger;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JBossServerConnectionProvider;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXClassLoaderRepository;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
-import
org.jboss.ide.eclipse.as.core.server.internal.launch.JBossServerStartupLaunchConfiguration;
-import org.jboss.ide.eclipse.as.core.server.internal.launch.StopLaunchConfiguration;
-import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
-import org.jboss.tools.jmx.core.IJMXRunnable;
-import org.jboss.tools.jmx.core.JMXException;
+import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
+import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader;
/**
*
@@ -57,239 +37,82 @@
*/
public class JBossServerBehavior extends DeployableServerBehavior {
- private PollThread pollThread = null;
- protected IProcess process;
- protected boolean nextStopRequiresForce = false;
+ public static interface JBossBehaviourDelegate {
+ public void setActualBehaviour(JBossServerBehavior actualBehaviour);
+ public void stop(boolean force);
+ public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy,
IProgressMonitor monitor) throws CoreException;
+ public void publishStart(final IProgressMonitor monitor) throws CoreException;
+ public void publishFinish(final IProgressMonitor monitor) throws CoreException;
+ public void serverStarting();
+ public void serverStopping();
+ public IStatus canChangeState(String launchMode);
+ }
+
+ public static HashMap<String, Class> delegateClassMap;
+ static {
+ delegateClassMap = new HashMap<String, Class>();
+ delegateClassMap.put(LocalPublishMethod.LOCAL_PUBLISH_METHOD,
LocalJBossBehaviorDelegate.class);
+ }
+ public static void addDelegateMapping(String s, Class c) {
+ delegateClassMap.put(s, c);
+ }
+
public JBossServerBehavior() {
super();
}
- public void stop(boolean force) {
- int state = getServer().getServerState();
- if( force || process == null || process.isTerminated() || state ==
IServer.STATE_STOPPED || nextStopRequiresForce) {
- forceStop();
- return;
- }
+ private JBossBehaviourDelegate delegate;
+ private String lastModeId;
+ public JBossBehaviourDelegate getDelegate() {
+ IJBossServerPublishMethodType type =
DeploymentPreferenceLoader.getCurrentDeploymentMethodType(getServer());
+ String id = type == null ? LocalPublishMethod.LOCAL_PUBLISH_METHOD : type.getId();
+ if( id.equals(lastModeId))
+ return delegate;
- // if we're starting up or shutting down and they've tried again,
- // then force it to stop.
- if( state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING ) {
- pollThread.cancel();
- forceStop();
- return;
+ Class c = delegateClassMap.get(id);
+ try {
+ JBossBehaviourDelegate o = (JBossBehaviourDelegate)c.newInstance();
+ o.setActualBehaviour(this);
+ lastModeId = id;
+ delegate = o;
+ } catch( InstantiationException ie) {
+ } catch( IllegalAccessException iae) {
}
-
- serverStopping();
- new Thread() {public void run() {
- boolean success = StopLaunchConfiguration.stop(getServer());
- if( !success ) {
- if( process != null && !process.isTerminated() ) {
- setServerStarted();
- pollThread.cancel(Messages.STOP_FAILED_MESSAGE);
- nextStopRequiresForce = true;
- }
- }
- }}.start();
+ return delegate;
}
- public synchronized void forceStop() {
- // just terminate the process.
- if( process != null && !process.isTerminated()) {
- try {
- process.terminate();
- addForceStopEvent();
- } catch( DebugException e ) {
- addForceStopFailedEvent(e);
- }
- }
- process = null;
- setServerStopped();
+ public void stop(boolean force) {
+ getDelegate().stop(force);
}
- protected void addForceStopFailedEvent(DebugException e) {
- IStatus status = new Status(IStatus.ERROR,
- JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_FORCE_STOP_FAILED,
- Messages.FORCE_TERMINATE_FAILED, e);
- ServerLogger.getDefault().log(getServer(), status);
- }
- protected void addForceStopEvent() {
- IStatus status = new Status(IStatus.ERROR,
- JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_FORCE_STOP,
- Messages.FORCE_TERMINATED, null);
- ServerLogger.getDefault().log(getServer(), status);
- }
-
- protected void addProcessTerminatedEvent() {
- IStatus status = new Status(IStatus.INFO,
- JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_PROCESS_TERMINATED,
- Messages.TERMINATED, null);
- ServerLogger.getDefault().log(getServer(), status);
- }
-
public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy,
IProgressMonitor monitor) throws CoreException {
- JBossServerStartupLaunchConfiguration.setupLaunchConfiguration(workingCopy,
getServer());
+ getDelegate().setupLaunchConfiguration(workingCopy, monitor);
}
-
- protected transient IDebugEventSetListener processListener;
- public synchronized void setProcess(final IProcess newProcess) {
- if (process != null) {
- return;
- }
- process = newProcess;
- if (processListener != null)
- DebugPlugin.getDefault().removeDebugEventListener(processListener);
- if (newProcess == null)
- return;
-
- processListener = new IDebugEventSetListener() {
- public void handleDebugEvents(DebugEvent[] events) {
- if (events != null) {
- int size = events.length;
- for (int i = 0; i < size; i++) {
- if (process != null && process.equals(events[i].getSource()) &&
events[i].getKind() == DebugEvent.TERMINATE) {
- DebugPlugin.getDefault().removeDebugEventListener(this);
- forceStop();
- addProcessTerminatedEvent();
- }
- }
- }
- }
- };
- DebugPlugin.getDefault().addDebugEventListener(processListener);
- }
-
-
public void setRunMode(String mode) {
setMode(mode);
}
public void serverStarting() {
- nextStopRequiresForce = false;
setServerStarting();
- pollServer(IServerStatePoller.SERVER_UP);
+ getDelegate().serverStarting();
}
public void serverStopping() {
setServerStopping();
- pollServer(IServerStatePoller.SERVER_DOWN);
+ getDelegate().serverStopping();
}
- public synchronized IProcess getProcess() {
- return process;
- }
-
- protected void pollServer(final boolean expectedState) {
- if( this.pollThread != null ) {
- pollThread.cancel();
- }
- this.pollThread = new PollThread(Messages.ServerPollerThreadName, expectedState,
this);
- pollThread.start();
- }
-
-
protected void publishStart(final IProgressMonitor monitor) throws CoreException {
super.publishStart(monitor);
- if( shouldSuspendScanner()) {
- JMXClassLoaderRepository.getDefault().addConcerned(getServer(), this);
- IJMXRunnable r = new IJMXRunnable() {
- public void run(MBeanServerConnection connection) throws Exception {
- suspendDeployment(connection, monitor);
- }
- };
- try {
- JBossServerConnectionProvider.run(getServer(), r);
- } catch( JMXException jmxe ) {
- IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID,
IEventCodes.SUSPEND_DEPLOYMENT_SCANNER, Messages.JMXPauseScannerError, jmxe);
- ServerLogger.getDefault().log(getServer(), status);
- }
- }
+ getDelegate().publishStart(monitor);
}
protected void publishFinish(final IProgressMonitor monitor) throws CoreException {
- if( shouldSuspendScanner()) {
- IJMXRunnable r = new IJMXRunnable() {
- public void run(MBeanServerConnection connection) throws Exception {
- resumeDeployment(connection, monitor);
- }
- };
- try {
- JBossServerConnectionProvider.run(getServer(), r);
- } catch( JMXException jmxe ) {
- IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID,
IEventCodes.RESUME_DEPLOYMENT_SCANNER, Messages.JMXResumeScannerError, jmxe);
- ServerLogger.getDefault().log(getServer(), status);
- } finally {
- JMXClassLoaderRepository.getDefault().removeConcerned(getServer(), this);
- }
- }
+ getDelegate().publishFinish(monitor);
super.publishFinish(monitor);
}
- protected boolean shouldSuspendScanner() {
-// if( getServer().getServerType().getId().equals(IConstants.AS_50))
-// return false;
- if( getServer().getServerState() != IServer.STATE_STARTED)
- return false;
- return true;
- }
-
- protected void suspendDeployment(final MBeanServerConnection connection,
IProgressMonitor monitor) throws Exception {
- ObjectName name = new
ObjectName(IJBossRuntimeConstants.DEPLOYMENT_SCANNER_MBEAN_NAME);
- launchDeployCommand(connection, name, IJBossRuntimeConstants.STOP, monitor);
- }
-
-
-
- protected void resumeDeployment(final MBeanServerConnection connection, IProgressMonitor
monitor) throws Exception {
- ObjectName name = new
ObjectName(IJBossRuntimeConstants.DEPLOYMENT_SCANNER_MBEAN_NAME);
- launchDeployCommand(connection, name, IJBossRuntimeConstants.START, monitor);
- }
-
- protected void launchDeployCommand(final MBeanServerConnection connection, final
ObjectName objectName,
- final String methodName, IProgressMonitor monitor) throws Exception {
- final Exception[] e = new Exception[1];
- final Object waitObject = new Object();
- final Boolean[] subtaskComplete = new Boolean[1];
- subtaskComplete[0] = new Boolean(false);
- Thread t = new Thread() {
- public void run() {
- Exception exception = null;
- try {
- executeDeploymentCommand(connection, objectName, methodName);
- } catch( Exception ex ) {
- exception = ex;
- }
- synchronized(waitObject) {
- e[0] = exception;
- subtaskComplete[0] = new Boolean(true);
- waitObject.notifyAll();
- }
- }
- };
- t.start();
- int count = 0;
- while(t.isAlive() && !monitor.isCanceled() && count <= 4000) {
- count+= 1000;
- synchronized(waitObject) {
- if( subtaskComplete[0].booleanValue() )
- break;
- waitObject.wait(1000);
- }
- }
- synchronized(waitObject) {
- if( !subtaskComplete[0].booleanValue()) {
- t.interrupt();
- IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID,
IEventCodes.DEPLOYMENT_SCANNER_TRANSITION_CANCELED, Messages.JMXScannerCanceled, null);
- ServerLogger.getDefault().log(getServer(), status);
- }
- }
- }
-
- protected void executeDeploymentCommand(MBeanServerConnection connection, ObjectName
objectName, String methodName) throws Exception {
- connection.invoke(objectName, methodName, new Object[] { }, new String[] {});
- }
-
-
// Can start / stop / restart etc
public IStatus canStart(String launchMode) {
return canChangeState(launchMode);
@@ -304,21 +127,6 @@
return canChangeState(launchMode);
}
protected IStatus canChangeState(String launchMode) {
- if( getServer() != null && getServer().getRuntime() != null &&
- getRuntime().getVM() != null )
- return Status.OK_STATUS;
- return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- "This server does not have a valid runtime environment"); //$NON-NLS-1$
+ return getDelegate().canChangeState(launchMode);
}
-
- private IJBossServerRuntime getRuntime() {
- IRuntime r = getServer().getRuntime();
- IJBossServerRuntime ajbsrt = null;
- if (r != null) {
- ajbsrt = (IJBossServerRuntime) r
- .loadAdapter(IJBossServerRuntime.class,
- new NullProgressMonitor());
- }
- return ajbsrt;
- }
}
Added:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossBehaviorDelegate.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossBehaviorDelegate.java
(rev 0)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossBehaviorDelegate.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -0,0 +1,327 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.server.internal;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.Messages;
+import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
+import org.jboss.ide.eclipse.as.core.extensions.events.ServerLogger;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JBossServerConnectionProvider;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXClassLoaderRepository;
+import
org.jboss.ide.eclipse.as.core.extensions.polling.ProcessTerminatedPoller.IProcessProvider;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
+import
org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior.JBossBehaviourDelegate;
+import
org.jboss.ide.eclipse.as.core.server.internal.launch.LocalJBossServerStartupLaunchUtil;
+import org.jboss.ide.eclipse.as.core.server.internal.launch.StopLaunchConfiguration;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
+import org.jboss.tools.jmx.core.IJMXRunnable;
+import org.jboss.tools.jmx.core.JMXException;
+
+/**
+ *
+ * @author Rob Stryker
+ *
+ */
+public class LocalJBossBehaviorDelegate implements JBossBehaviourDelegate,
IProcessProvider {
+
+ private PollThread pollThread = null;
+ protected IProcess process;
+ protected boolean nextStopRequiresForce = false;
+ private JBossServerBehavior actualBehavior;
+ public LocalJBossBehaviorDelegate() {
+ super();
+ }
+
+ public void setActualBehaviour(JBossServerBehavior actualBehaviour) {
+ this.actualBehavior = actualBehaviour;
+ }
+
+ protected IServer getServer() {
+ return actualBehavior.getServer();
+ }
+
+ public void stop(boolean force) {
+ int state = getServer().getServerState();
+ if( force || process == null || process.isTerminated() || state ==
IServer.STATE_STOPPED || nextStopRequiresForce) {
+ forceStop();
+ return;
+ }
+
+ // if we're starting up or shutting down and they've tried again,
+ // then force it to stop.
+ if( state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING ) {
+ pollThread.cancel();
+ forceStop();
+ return;
+ }
+
+ serverStopping();
+ new Thread() {public void run() {
+ boolean success = StopLaunchConfiguration.stop(getServer());
+ if( !success ) {
+ if( process != null && !process.isTerminated() ) {
+ actualBehavior.setServerStarted();
+ pollThread.cancel(Messages.STOP_FAILED_MESSAGE);
+ nextStopRequiresForce = true;
+ }
+ }
+ }}.start();
+ }
+
+ public synchronized void forceStop() {
+ // just terminate the process.
+ if( process != null && !process.isTerminated()) {
+ try {
+ process.terminate();
+ addForceStopEvent();
+ } catch( DebugException e ) {
+ addForceStopFailedEvent(e);
+ }
+ }
+ process = null;
+ actualBehavior.setServerStopped();
+ }
+
+ protected void addForceStopFailedEvent(DebugException e) {
+ IStatus status = new Status(IStatus.ERROR,
+ JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_FORCE_STOP_FAILED,
+ Messages.FORCE_TERMINATE_FAILED, e);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+ protected void addForceStopEvent() {
+ IStatus status = new Status(IStatus.ERROR,
+ JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_FORCE_STOP,
+ Messages.FORCE_TERMINATED, null);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+
+ protected void addProcessTerminatedEvent() {
+ IStatus status = new Status(IStatus.INFO,
+ JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_PROCESS_TERMINATED,
+ Messages.TERMINATED, null);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+
+ public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy,
IProgressMonitor monitor) throws CoreException {
+ LocalJBossServerStartupLaunchUtil.setupLaunchConfiguration(workingCopy, getServer());
+ }
+
+
+ protected transient IDebugEventSetListener processListener;
+ public synchronized void setProcess(final IProcess newProcess) {
+ if (process != null) {
+ return;
+ }
+ process = newProcess;
+ if (processListener != null)
+ DebugPlugin.getDefault().removeDebugEventListener(processListener);
+ if (newProcess == null)
+ return;
+
+ processListener = new IDebugEventSetListener() {
+ public void handleDebugEvents(DebugEvent[] events) {
+ if (events != null) {
+ int size = events.length;
+ for (int i = 0; i < size; i++) {
+ if (process != null && process.equals(events[i].getSource()) &&
events[i].getKind() == DebugEvent.TERMINATE) {
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ forceStop();
+ addProcessTerminatedEvent();
+ }
+ }
+ }
+ }
+ };
+ DebugPlugin.getDefault().addDebugEventListener(processListener);
+ }
+
+
+ public void serverStarting() {
+ nextStopRequiresForce = false;
+ pollServer(IServerStatePoller.SERVER_UP);
+ }
+
+ public void serverStopping() {
+ actualBehavior.setServerStopping();
+ pollServer(IServerStatePoller.SERVER_DOWN);
+ }
+
+ public synchronized IProcess getProcess() {
+ return process;
+ }
+
+ protected void pollServer(final boolean expectedState) {
+ if( this.pollThread != null ) {
+ pollThread.cancel();
+ }
+ this.pollThread = new PollThread(Messages.ServerPollerThreadName, expectedState,
actualBehavior);
+ pollThread.start();
+ }
+
+
+ public void publishStart(final IProgressMonitor monitor) throws CoreException {
+ if( shouldSuspendScanner()) {
+ JMXClassLoaderRepository.getDefault().addConcerned(getServer(), this);
+ IJMXRunnable r = new IJMXRunnable() {
+ public void run(MBeanServerConnection connection) throws Exception {
+ suspendDeployment(connection, monitor);
+ }
+ };
+ try {
+ JBossServerConnectionProvider.run(getServer(), r);
+ } catch( JMXException jmxe ) {
+ IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID,
IEventCodes.SUSPEND_DEPLOYMENT_SCANNER, Messages.JMXPauseScannerError, jmxe);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+ }
+ }
+
+ public void publishFinish(final IProgressMonitor monitor) throws CoreException {
+ if( shouldSuspendScanner()) {
+ IJMXRunnable r = new IJMXRunnable() {
+ public void run(MBeanServerConnection connection) throws Exception {
+ resumeDeployment(connection, monitor);
+ }
+ };
+ try {
+ JBossServerConnectionProvider.run(getServer(), r);
+ } catch( JMXException jmxe ) {
+ IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID,
IEventCodes.RESUME_DEPLOYMENT_SCANNER, Messages.JMXResumeScannerError, jmxe);
+ ServerLogger.getDefault().log(getServer(), status);
+ } finally {
+ JMXClassLoaderRepository.getDefault().removeConcerned(getServer(), this);
+ }
+ }
+ }
+
+ protected boolean shouldSuspendScanner() {
+ if( getServer().getServerState() != IServer.STATE_STARTED)
+ return false;
+ return true;
+ }
+
+ protected void suspendDeployment(final MBeanServerConnection connection,
IProgressMonitor monitor) throws Exception {
+ ObjectName name = new
ObjectName(IJBossRuntimeConstants.DEPLOYMENT_SCANNER_MBEAN_NAME);
+ launchDeployCommand(connection, name, IJBossRuntimeConstants.STOP, monitor);
+ }
+
+
+
+ protected void resumeDeployment(final MBeanServerConnection connection, IProgressMonitor
monitor) throws Exception {
+ ObjectName name = new
ObjectName(IJBossRuntimeConstants.DEPLOYMENT_SCANNER_MBEAN_NAME);
+ launchDeployCommand(connection, name, IJBossRuntimeConstants.START, monitor);
+ }
+
+ protected void launchDeployCommand(final MBeanServerConnection connection, final
ObjectName objectName,
+ final String methodName, IProgressMonitor monitor) throws Exception {
+ final Exception[] e = new Exception[1];
+ final Object waitObject = new Object();
+ final Boolean[] subtaskComplete = new Boolean[1];
+ subtaskComplete[0] = new Boolean(false);
+ Thread t = new Thread() {
+ public void run() {
+ Exception exception = null;
+ try {
+ executeDeploymentCommand(connection, objectName, methodName);
+ } catch( Exception ex ) {
+ exception = ex;
+ }
+ synchronized(waitObject) {
+ e[0] = exception;
+ subtaskComplete[0] = new Boolean(true);
+ waitObject.notifyAll();
+ }
+ }
+ };
+ t.start();
+ int count = 0;
+ while(t.isAlive() && !monitor.isCanceled() && count <= 4000) {
+ count+= 1000;
+ synchronized(waitObject) {
+ if( subtaskComplete[0].booleanValue() )
+ break;
+ waitObject.wait(1000);
+ }
+ }
+ synchronized(waitObject) {
+ if( !subtaskComplete[0].booleanValue()) {
+ t.interrupt();
+ IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID,
IEventCodes.DEPLOYMENT_SCANNER_TRANSITION_CANCELED, Messages.JMXScannerCanceled, null);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+ }
+ }
+
+ protected void executeDeploymentCommand(MBeanServerConnection connection, ObjectName
objectName, String methodName) throws Exception {
+ connection.invoke(objectName, methodName, new Object[] { }, new String[] {});
+ }
+
+
+ // Can start / stop / restart etc
+ public IStatus canStart(String launchMode) {
+ return canChangeState(launchMode);
+ }
+ public IStatus canRestart(String launchMode) {
+ return canChangeState(launchMode);
+ }
+ public IStatus canStop() {
+ return canChangeState(null);
+ }
+ public IStatus canStop(String launchMode) {
+ return canChangeState(launchMode);
+ }
+
+ public IStatus canChangeState(String launchMode) {
+ if( getServer() != null && getServer().getRuntime() != null &&
+ getRuntime().getVM() != null )
+ return Status.OK_STATUS;
+ return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ "This server does not have a valid runtime environment"); //$NON-NLS-1$
+ }
+
+ private IJBossServerRuntime getRuntime() {
+ IRuntime r = getServer().getRuntime();
+ IJBossServerRuntime ajbsrt = null;
+ if (r != null) {
+ ajbsrt = (IJBossServerRuntime) r
+ .loadAdapter(IJBossServerRuntime.class,
+ new NullProgressMonitor());
+ }
+ return ajbsrt;
+ }
+}
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -218,14 +218,14 @@
protected void alertBehavior(boolean currentState, boolean finalAlert) {
if (currentState != expectedState) {
// it didnt work... cancel all processes! force stop
- behavior.forceStop();
+ behavior.stop(true);
if (finalAlert)
alertEventLogFailure();
} else {
if (currentState == IServerStatePoller.SERVER_UP)
behavior.setServerStarted();
else
- behavior.forceStop();
+ behavior.stop(true);
if (finalAlert)
alertEventLogSuccess(currentState);
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -55,11 +55,11 @@
return true;
}
- protected void preLaunch(ILaunchConfiguration configuration,
+ public void preLaunch(ILaunchConfiguration configuration,
String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
// override me
}
- protected void postLaunch(ILaunchConfiguration configuration,
+ public void postLaunch(ILaunchConfiguration configuration,
String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
// override me
}
@@ -135,7 +135,7 @@
}
- protected static JBossServer findJBossServer(String serverId) throws CoreException {
+ public static JBossServer findJBossServer(String serverId) throws CoreException {
if( serverId == null )
throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
NLS.bind(Messages.ServerNotFound, serverId)));
@@ -153,7 +153,7 @@
return jbs;
}
- protected static IJBossServerRuntime findJBossServerRuntime(IServer server) throws
CoreException {
+ public static IJBossServerRuntime findJBossServerRuntime(IServer server) throws
CoreException {
IRuntime rt = server.getRuntime();
IJBossServerRuntime jbrt = null;
if( rt != null )
@@ -164,14 +164,14 @@
return jbrt;
}
- protected static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list,
JBossServer jbs, String relative) {
+ public static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list, JBossServer
jbs, String relative) {
addCPEntry(list, new Path(getServerHome(jbs)).append(relative));
}
- protected static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list, IPath
path) {
+ public static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list, IPath path)
{
list.add(JavaRuntime.newArchiveRuntimeClasspathEntry(path));
}
- protected static void addJREEntry(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall
vmInstall) {
+ public static void addJREEntry(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall
vmInstall) {
if (vmInstall != null) {
try {
cp.add(JavaRuntime.newRuntimeContainerClasspathEntry(
@@ -186,7 +186,7 @@
}
}
- protected static void addToolsJar(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall
vmInstall) {
+ public static void addToolsJar(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall
vmInstall) {
File f = vmInstall.getInstallLocation();
File c1 = new File(f, IConstants.LIB);
File c2 = new File(c1, IConstants.TOOLS_JAR);
@@ -195,7 +195,7 @@
}
- protected static ArrayList<String>
convertClasspath(ArrayList<IRuntimeClasspathEntry> cp) {
+ public static ArrayList<String>
convertClasspath(ArrayList<IRuntimeClasspathEntry> cp) {
Iterator<IRuntimeClasspathEntry> cpi = cp.iterator();
ArrayList<String> list = new ArrayList<String>();
while (cpi.hasNext()) {
@@ -211,7 +211,7 @@
return list;
}
- protected static void addDirectory(String serverHome,
ArrayList<IRuntimeClasspathEntry> classpath,
+ public static void addDirectory(String serverHome,
ArrayList<IRuntimeClasspathEntry> classpath,
String dirName) {
String libPath = serverHome + File.separator + dirName;
File libDir = new File(libPath);
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -10,384 +10,69 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal.launch;
-import java.io.File;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.ILaunchManager;
-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.jdt.launching.StandardClasspathProvider;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.ServerCore;
import org.eclipse.wst.server.core.ServerUtil;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
-import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
-import org.jboss.ide.eclipse.as.core.util.IConstants;
-import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
-import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
-import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
+import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
public class JBossServerStartupLaunchConfiguration extends AbstractJBossLaunchConfigType
{
-
- static final char[] INVALID_CHARS = new char[] {'\\', '/', ':',
'*', '?', '"', '<', '>', '|',
'\0', '@', '&'};
- static final String LAUNCH_TYPE =
"org.jboss.ide.eclipse.as.core.server.startupConfiguration"; //$NON-NLS-1$
- static final String DEFAULTS_SET = "jboss.defaults.been.set"; //$NON-NLS-1$
- static final String START_JAR_LOC = IJBossRuntimeResourceConstants.BIN + Path.SEPARATOR
+ IJBossRuntimeResourceConstants.START_JAR;
- static final String START_MAIN_TYPE = IJBossRuntimeConstants.START_MAIN_TYPE;
-
- public static ILaunchConfigurationWorkingCopy setupLaunchConfiguration(IServer server,
String action) throws CoreException {
- ILaunchConfigurationWorkingCopy config = createLaunchConfiguration(server);
- setupLaunchConfiguration(config, server);
- return config;
- }
-
- public static void setupLaunchConfiguration(
- ILaunchConfigurationWorkingCopy workingCopy, IServer server) throws CoreException {
- if(!workingCopy.getAttributes().containsKey(DEFAULTS_SET)) {
- forceDefaultsSet(workingCopy, server);
- }
+ public static interface StartLaunchDelegate {
+ public void actualLaunch(JBossServerStartupLaunchConfiguration launchConfig,
+ ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException;
- // Upgrade old launch configs
- JBossServer jbs = findJBossServer(server.getId());
- if( jbs == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.CannotSetUpImproperServer, server.getName())));
-
- String cpProvider =
workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
(String)null);
- if( !DEFAULT_CP_PROVIDER_ID.equals(cpProvider)) {
- workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
DEFAULT_CP_PROVIDER_ID);
- workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH,
getClasspath(jbs));
- workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
false);
- }
+ public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode,
IProgressMonitor monitor) throws CoreException;
+ public void preLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException;
+ public void postLaunch(ILaunchConfiguration configuration, String mode,
+ ILaunch launch, IProgressMonitor monitor) throws CoreException;
- // Force the launch to get certain fields from the runtime
- updateMandatedFields(workingCopy, jbs);
}
-
- /*
- * Ensures that the working directory and classpath are 100% accurate.
- * Merges proper required params into args and vm args
- */
- protected static void updateMandatedFields(ILaunchConfigurationWorkingCopy wc,
JBossServer jbs) throws CoreException{
- String serverHome = getServerHome(jbs);
- if( serverHome == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.CannotLocateServerHome, jbs.getServer().getName())));
-
- IRuntime rt = jbs.getServer().getRuntime();
- IJBossServerRuntime jbrt = null;
- if( rt != null )
- jbrt = (IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
-
- if( jbrt == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.ServerRuntimeNotFound, jbs.getServer().getName())));
-
- /* Args and vm args */
-
- String args = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
""); //$NON-NLS-1$
- String vmArgs = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
""); //$NON-NLS-1$
- String host = jbs.getServer().getHost();
- String host2 = ArgsUtil.getValue(args,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG);
- if( !host.equals(host2))
- args = ArgsUtil.setArg(args,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG, host);
-
- IJBossServerRuntime runtime = (IJBossServerRuntime)
- jbs.getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
- String config = runtime.getJBossConfiguration();
- args = ArgsUtil.setArg(args,
- IJBossRuntimeConstants.STARTUP_ARG_CONFIG_SHORT,
- IJBossRuntimeConstants.STARTUP_ARG_CONFIG_LONG, config);
-
- try {
- if( !runtime.getConfigLocation().equals(IConstants.SERVER)) {
- args = ArgsUtil.setArg(args, null,
- IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JBOSS_SERVER_HOME_URL,
- runtime.getConfigLocationFullPath().toFile().toURL().toString());
- }
- } catch( MalformedURLException murle) {}
-
-
- vmArgs= ArgsUtil.setArg(vmArgs, null,
- IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.ENDORSED_DIRS,
- runtime.getRuntime().getLocation().append(
- IJBossRuntimeResourceConstants.LIB).append(
- IJBossRuntimeResourceConstants.ENDORSED).toOSString(), true);
-
- if( runtime.getRuntime().getLocation().append(
- IJBossRuntimeResourceConstants.BIN).append(
- IJBossRuntimeResourceConstants.NATIVE).toFile().exists() ) {
- String argVal = ArgsUtil.getValue(vmArgs, null,
- IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JAVA_LIB_PATH);
-
- String libPath =
- runtime.getRuntime().getLocation()
- .append(IJBossRuntimeResourceConstants.BIN)
- .append(IJBossRuntimeResourceConstants.NATIVE).toOSString();
- if( argVal != null ) {
- if( argVal.startsWith("\"")) //$NON-NLS-1$
- argVal = argVal.substring(1);
- if( argVal.endsWith("\"")) //$NON-NLS-1$
- argVal = argVal.substring(0, argVal.length()-1);
- if( argVal.startsWith(":")) //$NON-NLS-1$
- argVal = argVal.substring(1);
-
- String[] asArr = argVal.split(File.pathSeparator);
- asArr[0] = libPath;
- String implode = ""; //$NON-NLS-1$
- for( int i = 0; i < asArr.length; i++ )
- implode += asArr[i] + File.pathSeparator;
- libPath = implode;
- }
- vmArgs = ArgsUtil.setArg(vmArgs, null,
- IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JAVA_LIB_PATH,
- libPath, true);
+ private StartLaunchDelegate del = null;
+ protected StartLaunchDelegate getDelegate(ILaunchConfiguration configuration) throws
CoreException {
+ if( del != null )
+ return del;
+ IServer server = ServerUtil.getServer(configuration);
+ DeployableServerBehavior beh = ServerConverter.getDeployableServerBehavior(server);
+ IJBossServerPublishMethodType type = beh.createPublishMethod().getPublishMethodType();
+ if( type.getId().equals(LocalPublishMethod.LOCAL_PUBLISH_METHOD)) {
+ del = new LocalJBossServerStartupLaunchUtil();
}
-
- /* Claspath */
- List<String> cp =
wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, new
ArrayList<String>());
- List<String> newCP = fixCP(cp, jbs);
-
- IVMInstall vmInstall = runtime.getVM();
- if( vmInstall != null )
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH,
JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome +
Path.SEPARATOR + IJBossRuntimeResourceConstants.BIN);
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
args.trim());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs.trim());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, newCP);
- wc.setAttribute(SERVER_ID,jbs.getServer().getId());
-
+ return del;
}
-
- protected static List<String> fixCP(List<String> list, JBossServer jbs) {
- try {
- boolean found = false;
- String[] asString = (String[]) list.toArray(new String[list.size()]);
- for( int i = 0; i < asString.length; i++ ) {
- if( asString[i].contains(RunJarContainerWrapper.ID)) {
- found = true;
- asString[i] = getRunJarRuntimeCPEntry(jbs).getMemento();
- }
- }
- ArrayList<String> result = new ArrayList<String>();
- result.addAll(Arrays.asList(asString));
- if( !found )
- result.add(getRunJarRuntimeCPEntry(jbs).getMemento());
- return result;
- } catch( CoreException ce) {
- return list;
- }
+ public void actualLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ getDelegate(configuration).actualLaunch(this, configuration, mode, launch, monitor);
}
- protected static void forceDefaultsSet(ILaunchConfigurationWorkingCopy wc, IServer
server) throws CoreException {
- JBossServer jbs = findJBossServer(server.getId());
- if( jbs == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.CannotSetUpImproperServer, server.getName())));
-
- String serverHome = getServerHome(jbs);
- if( serverHome == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.CannotLocateServerHome, server.getName())));
-
- IRuntime rt = jbs.getServer().getRuntime();
- IJBossServerRuntime jbrt = null;
- if( rt != null ) {
- jbrt = (IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
- }
-
- if( jbrt == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.ServerRuntimeNotFound, jbs.getServer().getName())));
-
- IVMInstall vmInstall = jbrt.getVM();
- if( vmInstall != null )
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH,
JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
getDefaultArgs(jbs));
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
jbrt.getDefaultRunVMArgs());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
START_MAIN_TYPE);
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome +
Path.SEPARATOR + IJBossRuntimeResourceConstants.BIN);
- wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES,
jbrt.getDefaultRunEnvVars());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, getClasspath(jbs));
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
DEFAULT_CP_PROVIDER_ID);
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
-
- wc.setAttribute(DEFAULTS_SET, true);
- }
-
- protected static ArrayList<String> getClasspath(JBossServer jbs) throws
CoreException {
- IJBossServerRuntime jbrt = findJBossServerRuntime(jbs.getServer());
- ArrayList<IRuntimeClasspathEntry> classpath = new
ArrayList<IRuntimeClasspathEntry>();
- classpath.add(getRunJarRuntimeCPEntry(jbs));
- addJREEntry(classpath, jbrt.getVM());
-
- String version = jbs.getServer().getRuntime().getRuntimeType().getVersion();
- if( version.equals(IJBossToolingConstants.AS_40))
- addToolsJar(classpath, jbrt.getVM());
-
- ArrayList<String> runtimeClassPaths = convertClasspath(classpath);
- return runtimeClassPaths;
-
- }
+ public void superActualLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ super.actualLaunch(configuration, mode, launch, monitor);
+ }
+ /*
+ * Ensures that the working directory and classpath are 100% accurate.
+ * Merges proper required params into args and vm args
+ */
- protected static IRuntimeClasspathEntry getRunJarRuntimeCPEntry(JBossServer jbs) throws
CoreException {
- IPath containerPath = new
Path(RunJarContainerWrapper.ID).append(jbs.getServer().getName());
- return JavaRuntime.newRuntimeContainerClasspathEntry(containerPath,
IRuntimeClasspathEntry.USER_CLASSES);
- }
-
- protected static String getDefaultArgs(JBossServer jbs) throws CoreException {
- IJBossServerRuntime rt = findJBossServerRuntime(jbs.getServer());
- if (rt != null) {
- return rt.getDefaultRunArgs() +
- IJBossRuntimeConstants.SPACE + IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT +
- IJBossRuntimeConstants.SPACE + jbs.getServer().getHost();
- }
- return null;
- }
-
public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode,
IProgressMonitor monitor) throws CoreException {
- JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
- if( !jbsBehavior.canStart(mode).isOK())
- throw new CoreException(jbsBehavior.canStart(mode));
- return true;
+ return getDelegate(configuration).preLaunchCheck(configuration, mode, monitor);
}
- protected void preLaunch(ILaunchConfiguration configuration,
+ public void preLaunch(ILaunchConfiguration configuration,
String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
- try {
- JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
- jbsBehavior.setRunMode(mode);
- jbsBehavior.serverStarting();
- } catch( CoreException ce ) {
- // report it
- }
+ getDelegate(configuration).preLaunch(configuration, mode, launch, monitor);
}
public void postLaunch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
- try {
- IProcess[] processes = launch.getProcesses();
- JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
- jbsBehavior.setProcess(processes[0]);
- } catch( CoreException ce ) {
- // report
- }
+ getDelegate(configuration).postLaunch(configuration, mode, launch, monitor);
}
-
- public static JBossServerBehavior getServerBehavior(ILaunchConfiguration configuration)
throws CoreException {
- IServer server = ServerUtil.getServer(configuration);
- JBossServerBehavior jbossServerBehavior = (JBossServerBehavior)
server.getAdapter(JBossServerBehavior.class);
- return jbossServerBehavior;
- }
-
- protected static String getValidLaunchConfigurationName(String s) {
- if (s == null || s.length() == 0)
- return "1"; //$NON-NLS-1$
- int size = INVALID_CHARS.length;
- for (int i = 0; i < size; i++) {
- s = s.replace(INVALID_CHARS[i], '_');
- }
- return s;
- }
-
- /**
- * Will create a launch configuration for the server
- * if one does not already exist.
- */
- public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IServer server)
throws CoreException {
- ILaunchConfigurationType launchConfigType =
DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(LAUNCH_TYPE);
- if (launchConfigType == null)
- return null;
-
- ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfiguration[] launchConfigs = null;
- try {
- launchConfigs = launchManager.getLaunchConfigurations(launchConfigType);
- } catch (CoreException e) {
- // ignore
- }
-
- if (launchConfigs != null) {
- int size = launchConfigs.length;
- for (int i = 0; i < size; i++) {
- try {
- String serverId = launchConfigs[i].getAttribute(SERVER_ID, (String) null);
- if (server.getId().equals(serverId)) {
- ILaunchConfigurationWorkingCopy wc = launchConfigs[i].getWorkingCopy();
- return wc;
- }
- } catch (CoreException e) {
- }
- }
- }
-
- // create a new launch configuration
- String launchName = getValidLaunchConfigurationName(server.getName());
- launchName = launchManager.generateUniqueLaunchConfigurationNameFrom(launchName);
- ILaunchConfigurationWorkingCopy wc = launchConfigType.newInstance(null, launchName);
- wc.setAttribute(SERVER_ID, server.getId());
- return wc;
- }
-
- /* For "restore defaults" functionality */
- private static final String DEFAULT_CP_PROVIDER_ID =
"org.jboss.ide.eclipse.as.core.server.internal.launch.serverClasspathProvider";
//$NON-NLS-1$
- public static class JBossServerDefaultClasspathProvider extends
StandardClasspathProvider {
- public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration
configuration) throws CoreException {
- boolean useDefault =
configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
true);
- if (useDefault) {
- return defaultEntries(configuration);
- }
- return super.computeUnresolvedClasspath(configuration);
- }
-
- protected IRuntimeClasspathEntry[] defaultEntries(ILaunchConfiguration config) {
- try {
- String server = config.getAttribute(SERVER_ID, (String)null);
- IServer s = ServerCore.findServer(server);
- IJBossServerRuntime ibjsrt =
(IJBossServerRuntime)s.getRuntime().loadAdapter(IJBossServerRuntime.class, new
NullProgressMonitor());
- JBossServer jbs = (JBossServer)s.loadAdapter(JBossServer.class, new
NullProgressMonitor());
- IVMInstall install = ibjsrt.getVM();
- ArrayList<IRuntimeClasspathEntry> list = new
ArrayList<IRuntimeClasspathEntry>();
- addJREEntry(list, install);
- list.add(getRunJarRuntimeCPEntry(jbs));
- return (IRuntimeClasspathEntry[]) list
- .toArray(new IRuntimeClasspathEntry[list.size()]);
- } catch( CoreException ce) {
- }
- try {
- return super.computeUnresolvedClasspath(config);
- } catch( CoreException ce ) {}
- return new IRuntimeClasspathEntry[]{};
- }
- }
}
Added:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/LocalJBossServerStartupLaunchUtil.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/LocalJBossServerStartupLaunchUtil.java
(rev 0)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/LocalJBossServerStartupLaunchUtil.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -0,0 +1,408 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.server.internal.launch;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+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.jdt.launching.StandardClasspathProvider;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.Messages;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.internal.LocalJBossBehaviorDelegate;
+import
org.jboss.ide.eclipse.as.core.server.internal.launch.JBossServerStartupLaunchConfiguration.StartLaunchDelegate;
+import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
+import org.jboss.ide.eclipse.as.core.util.IConstants;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+
+public class LocalJBossServerStartupLaunchUtil implements StartLaunchDelegate {
+
+ static final char[] INVALID_CHARS = new char[] {'\\', '/', ':',
'*', '?', '"', '<', '>', '|',
'\0', '@', '&'};
+ static final String LAUNCH_TYPE =
"org.jboss.ide.eclipse.as.core.server.startupConfiguration"; //$NON-NLS-1$
+ static final String DEFAULTS_SET = "jboss.defaults.been.set"; //$NON-NLS-1$
+ static final String START_JAR_LOC = IJBossRuntimeResourceConstants.BIN + Path.SEPARATOR
+ IJBossRuntimeResourceConstants.START_JAR;
+ static final String START_MAIN_TYPE = IJBossRuntimeConstants.START_MAIN_TYPE;
+
+ public static ILaunchConfigurationWorkingCopy setupLaunchConfiguration(IServer server,
String action) throws CoreException {
+ ILaunchConfigurationWorkingCopy config = createLaunchConfiguration(server);
+ setupLaunchConfiguration(config, server);
+ return config;
+ }
+
+ public static void setupLaunchConfiguration(
+ ILaunchConfigurationWorkingCopy workingCopy, IServer server) throws CoreException {
+ if(!workingCopy.getAttributes().containsKey(DEFAULTS_SET)) {
+ forceDefaultsSet(workingCopy, server);
+ }
+
+ // Upgrade old launch configs
+ JBossServer jbs = AbstractJBossLaunchConfigType.findJBossServer(server.getId());
+ if( jbs == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.CannotSetUpImproperServer, server.getName())));
+
+ String cpProvider =
workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
(String)null);
+ if( !DEFAULT_CP_PROVIDER_ID.equals(cpProvider)) {
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
DEFAULT_CP_PROVIDER_ID);
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH,
getClasspath(jbs));
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
false);
+ }
+
+ // Force the launch to get certain fields from the runtime
+ updateMandatedFields(workingCopy, jbs);
+ }
+
+ /*
+ * Ensures that the working directory and classpath are 100% accurate.
+ * Merges proper required params into args and vm args
+ */
+
+ protected static void updateMandatedFields(ILaunchConfigurationWorkingCopy wc,
JBossServer jbs) throws CoreException{
+ String serverHome = AbstractJBossLaunchConfigType.getServerHome(jbs);
+ if( serverHome == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.CannotLocateServerHome, jbs.getServer().getName())));
+
+ IRuntime rt = jbs.getServer().getRuntime();
+ IJBossServerRuntime jbrt = null;
+ if( rt != null )
+ jbrt = (IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
+
+ if( jbrt == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.ServerRuntimeNotFound, jbs.getServer().getName())));
+
+ /* Args and vm args */
+
+ String args = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
""); //$NON-NLS-1$
+ String vmArgs = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
""); //$NON-NLS-1$
+ String host = jbs.getServer().getHost();
+ String host2 = ArgsUtil.getValue(args,
+ IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
+ IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG);
+ if( !host.equals(host2))
+ args = ArgsUtil.setArg(args,
+ IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
+ IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG, host);
+
+ IJBossServerRuntime runtime = (IJBossServerRuntime)
+ jbs.getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
+ String config = runtime.getJBossConfiguration();
+ args = ArgsUtil.setArg(args,
+ IJBossRuntimeConstants.STARTUP_ARG_CONFIG_SHORT,
+ IJBossRuntimeConstants.STARTUP_ARG_CONFIG_LONG, config);
+
+ try {
+ if( !runtime.getConfigLocation().equals(IConstants.SERVER)) {
+ args = ArgsUtil.setArg(args, null,
+ IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JBOSS_SERVER_HOME_URL,
+ runtime.getConfigLocationFullPath().toFile().toURL().toString());
+ }
+ } catch( MalformedURLException murle) {}
+
+
+ vmArgs= ArgsUtil.setArg(vmArgs, null,
+ IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.ENDORSED_DIRS,
+ runtime.getRuntime().getLocation().append(
+ IJBossRuntimeResourceConstants.LIB).append(
+ IJBossRuntimeResourceConstants.ENDORSED).toOSString(), true);
+
+ if( runtime.getRuntime().getLocation().append(
+ IJBossRuntimeResourceConstants.BIN).append(
+ IJBossRuntimeResourceConstants.NATIVE).toFile().exists() ) {
+ String argVal = ArgsUtil.getValue(vmArgs, null,
+ IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JAVA_LIB_PATH);
+
+ String libPath =
+ runtime.getRuntime().getLocation()
+ .append(IJBossRuntimeResourceConstants.BIN)
+ .append(IJBossRuntimeResourceConstants.NATIVE).toOSString();
+ if( argVal != null ) {
+ if( argVal.startsWith("\"")) //$NON-NLS-1$
+ argVal = argVal.substring(1);
+ if( argVal.endsWith("\"")) //$NON-NLS-1$
+ argVal = argVal.substring(0, argVal.length()-1);
+ if( argVal.startsWith(":")) //$NON-NLS-1$
+ argVal = argVal.substring(1);
+
+ String[] asArr = argVal.split(File.pathSeparator);
+ asArr[0] = libPath;
+ String implode = ""; //$NON-NLS-1$
+ for( int i = 0; i < asArr.length; i++ )
+ implode += asArr[i] + File.pathSeparator;
+ libPath = implode;
+ }
+ vmArgs = ArgsUtil.setArg(vmArgs, null,
+ IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JAVA_LIB_PATH,
+ libPath, true);
+ }
+
+ /* Claspath */
+ List<String> cp =
wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, new
ArrayList<String>());
+ List<String> newCP = fixCP(cp, jbs);
+
+ IVMInstall vmInstall = runtime.getVM();
+ if( vmInstall != null )
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH,
JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome +
Path.SEPARATOR + IJBossRuntimeResourceConstants.BIN);
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
args.trim());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs.trim());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, newCP);
+ wc.setAttribute(AbstractJBossLaunchConfigType.SERVER_ID,jbs.getServer().getId());
+
+ }
+
+ protected static List<String> fixCP(List<String> list, JBossServer jbs) {
+ try {
+ boolean found = false;
+ String[] asString = (String[]) list.toArray(new String[list.size()]);
+ for( int i = 0; i < asString.length; i++ ) {
+ if( asString[i].contains(RunJarContainerWrapper.ID)) {
+ found = true;
+ asString[i] = getRunJarRuntimeCPEntry(jbs).getMemento();
+ }
+ }
+ ArrayList<String> result = new ArrayList<String>();
+ result.addAll(Arrays.asList(asString));
+ if( !found )
+ result.add(getRunJarRuntimeCPEntry(jbs).getMemento());
+ return result;
+ } catch( CoreException ce) {
+ return list;
+ }
+ }
+
+ protected static void forceDefaultsSet(ILaunchConfigurationWorkingCopy wc, IServer
server) throws CoreException {
+ JBossServer jbs = AbstractJBossLaunchConfigType.findJBossServer(server.getId());
+ if( jbs == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.CannotSetUpImproperServer, server.getName())));
+
+ String serverHome = AbstractJBossLaunchConfigType.getServerHome(jbs);
+ if( serverHome == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.CannotLocateServerHome, server.getName())));
+
+ IRuntime rt = jbs.getServer().getRuntime();
+ IJBossServerRuntime jbrt = null;
+ if( rt != null ) {
+ jbrt = (IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
+ }
+
+ if( jbrt == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.ServerRuntimeNotFound, jbs.getServer().getName())));
+
+ IVMInstall vmInstall = jbrt.getVM();
+ if( vmInstall != null )
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH,
JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
getDefaultArgs(jbs));
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
jbrt.getDefaultRunVMArgs());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
START_MAIN_TYPE);
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome +
Path.SEPARATOR + IJBossRuntimeResourceConstants.BIN);
+ wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES,
jbrt.getDefaultRunEnvVars());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, getClasspath(jbs));
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
DEFAULT_CP_PROVIDER_ID);
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
+
+ wc.setAttribute(DEFAULTS_SET, true);
+ }
+
+ protected static ArrayList<String> getClasspath(JBossServer jbs) throws
CoreException {
+ IJBossServerRuntime jbrt =
AbstractJBossLaunchConfigType.findJBossServerRuntime(jbs.getServer());
+ ArrayList<IRuntimeClasspathEntry> classpath = new
ArrayList<IRuntimeClasspathEntry>();
+ classpath.add(getRunJarRuntimeCPEntry(jbs));
+ AbstractJBossLaunchConfigType.addJREEntry(classpath, jbrt.getVM());
+
+ String version = jbs.getServer().getRuntime().getRuntimeType().getVersion();
+ if( version.equals(IJBossToolingConstants.AS_40))
+ AbstractJBossLaunchConfigType.addToolsJar(classpath, jbrt.getVM());
+
+ ArrayList<String> runtimeClassPaths =
AbstractJBossLaunchConfigType.convertClasspath(classpath);
+ return runtimeClassPaths;
+
+ }
+
+ protected static IRuntimeClasspathEntry getRunJarRuntimeCPEntry(JBossServer jbs) throws
CoreException {
+ IPath containerPath = new
Path(RunJarContainerWrapper.ID).append(jbs.getServer().getName());
+ return JavaRuntime.newRuntimeContainerClasspathEntry(containerPath,
IRuntimeClasspathEntry.USER_CLASSES);
+ }
+
+ protected static String getDefaultArgs(JBossServer jbs) throws CoreException {
+ IJBossServerRuntime rt =
AbstractJBossLaunchConfigType.findJBossServerRuntime(jbs.getServer());
+ if (rt != null) {
+ return rt.getDefaultRunArgs() +
+ IJBossRuntimeConstants.SPACE + IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT +
+ IJBossRuntimeConstants.SPACE + jbs.getServer().getHost();
+ }
+ return null;
+ }
+
+
+ public static JBossServerBehavior getServerBehavior(ILaunchConfiguration configuration)
throws CoreException {
+ IServer server = ServerUtil.getServer(configuration);
+ JBossServerBehavior jbossServerBehavior = (JBossServerBehavior)
server.getAdapter(JBossServerBehavior.class);
+ return jbossServerBehavior;
+ }
+
+ protected static String getValidLaunchConfigurationName(String s) {
+ if (s == null || s.length() == 0)
+ return "1"; //$NON-NLS-1$
+ int size = INVALID_CHARS.length;
+ for (int i = 0; i < size; i++) {
+ s = s.replace(INVALID_CHARS[i], '_');
+ }
+ return s;
+ }
+
+ /**
+ * Will create a launch configuration for the server
+ * if one does not already exist.
+ */
+ public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IServer server)
throws CoreException {
+ ILaunchConfigurationType launchConfigType =
DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(LAUNCH_TYPE);
+ if (launchConfigType == null)
+ return null;
+
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfiguration[] launchConfigs = null;
+ try {
+ launchConfigs = launchManager.getLaunchConfigurations(launchConfigType);
+ } catch (CoreException e) {
+ // ignore
+ }
+
+ if (launchConfigs != null) {
+ int size = launchConfigs.length;
+ for (int i = 0; i < size; i++) {
+ try {
+ String serverId =
launchConfigs[i].getAttribute(AbstractJBossLaunchConfigType.SERVER_ID, (String) null);
+ if (server.getId().equals(serverId)) {
+ ILaunchConfigurationWorkingCopy wc = launchConfigs[i].getWorkingCopy();
+ return wc;
+ }
+ } catch (CoreException e) {
+ }
+ }
+ }
+
+ // create a new launch configuration
+ String launchName = getValidLaunchConfigurationName(server.getName());
+ launchName = launchManager.generateUniqueLaunchConfigurationNameFrom(launchName);
+ ILaunchConfigurationWorkingCopy wc = launchConfigType.newInstance(null, launchName);
+ wc.setAttribute(AbstractJBossLaunchConfigType.SERVER_ID, server.getId());
+ return wc;
+ }
+
+ /* For "restore defaults" functionality */
+ private static final String DEFAULT_CP_PROVIDER_ID =
"org.jboss.ide.eclipse.as.core.server.internal.launch.serverClasspathProvider";
//$NON-NLS-1$
+ public static class JBossServerDefaultClasspathProvider extends
StandardClasspathProvider {
+ public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration
configuration) throws CoreException {
+ boolean useDefault =
configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
true);
+ if (useDefault) {
+ return defaultEntries(configuration);
+ }
+ return super.computeUnresolvedClasspath(configuration);
+ }
+
+ protected IRuntimeClasspathEntry[] defaultEntries(ILaunchConfiguration config) {
+ try {
+ String server = config.getAttribute(AbstractJBossLaunchConfigType.SERVER_ID,
(String)null);
+ IServer s = ServerCore.findServer(server);
+ IJBossServerRuntime ibjsrt =
(IJBossServerRuntime)s.getRuntime().loadAdapter(IJBossServerRuntime.class, new
NullProgressMonitor());
+ JBossServer jbs = (JBossServer)s.loadAdapter(JBossServer.class, new
NullProgressMonitor());
+ IVMInstall install = ibjsrt.getVM();
+ ArrayList<IRuntimeClasspathEntry> list = new
ArrayList<IRuntimeClasspathEntry>();
+ AbstractJBossLaunchConfigType.addJREEntry(list, install);
+ list.add(getRunJarRuntimeCPEntry(jbs));
+ return (IRuntimeClasspathEntry[]) list
+ .toArray(new IRuntimeClasspathEntry[list.size()]);
+ } catch( CoreException ce) {
+ }
+ try {
+ return super.computeUnresolvedClasspath(config);
+ } catch( CoreException ce ) {}
+ return new IRuntimeClasspathEntry[]{};
+ }
+ }
+
+
+
+ /*
+ * Actual instance methods
+ */
+ public void actualLaunch(
+ JBossServerStartupLaunchConfiguration launchConfig,
+ ILaunchConfiguration configuration, String mode, ILaunch launch,
+ IProgressMonitor monitor) throws CoreException {
+ launchConfig.superActualLaunch(configuration, mode, launch, monitor);
+ }
+
+ public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode,
IProgressMonitor monitor) throws CoreException {
+ JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
+ if( !jbsBehavior.canStart(mode).isOK())
+ throw new CoreException(jbsBehavior.canStart(mode));
+ return true;
+ }
+
+ public void preLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ try {
+ JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
+ jbsBehavior.setRunMode(mode);
+ jbsBehavior.serverStarting();
+ } catch( CoreException ce ) {
+ // report it
+ }
+ }
+
+ public void postLaunch(ILaunchConfiguration configuration, String mode,
+ ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ try {
+ IProcess[] processes = launch.getProcesses();
+ JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
+ ((LocalJBossBehaviorDelegate)(jbsBehavior.getDelegate())).setProcess(processes[0]);
+ } catch( CoreException ce ) {
+ // report
+ }
+ }
+
+}
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/RunJarContainerWrapper.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/RunJarContainerWrapper.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/RunJarContainerWrapper.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -82,7 +82,7 @@
if( s != null ) {
IRuntime rt = s.getRuntime();
IPath home = rt.getLocation();
- IPath runJar = home.append(JBossServerStartupLaunchConfiguration.START_JAR_LOC);
+ IPath runJar = home.append(LocalJBossServerStartupLaunchUtil.START_JAR_LOC);
return new IClasspathEntry[] {
JavaRuntime.newArchiveRuntimeClasspathEntry(
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java
===================================================================
---
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -68,7 +68,7 @@
}
}
- protected void preLaunch(ILaunchConfiguration configuration,
+ public void preLaunch(ILaunchConfiguration configuration,
String mode, ILaunch launch, IProgressMonitor monitor) {
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2010-08-06
09:19:37 UTC (rev 23965)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2010-08-06
10:29:45 UTC (rev 23966)
@@ -1019,7 +1019,7 @@
<extension
point="org.eclipse.jdt.launching.classpathProviders">
<classpathProvider
-
class="org.jboss.ide.eclipse.as.core.server.internal.launch.JBossServerStartupLaunchConfiguration$JBossServerDefaultClasspathProvider"
+
class="org.jboss.ide.eclipse.as.core.server.internal.launch.LocalJBossServerStartupLaunchUtil$JBossServerDefaultClasspathProvider"
id="org.jboss.ide.eclipse.as.core.server.internal.launch.serverClasspathProvider">
</classpathProvider>
</extension>
Modified:
workspace/rstryker/rse/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/MockTests.java
===================================================================
---
workspace/rstryker/rse/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/MockTests.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/MockTests.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -4,13 +4,13 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerWorkingCopy;
+import
org.jboss.ide.eclipse.as.core.extensions.polling.ProcessTerminatedPoller.IProcessProvider;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
import org.jboss.ide.eclipse.as.core.server.internal.LocalJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
@@ -90,10 +90,10 @@
int loops = 0;
JBossServerBehavior behavior =
(JBossServerBehavior)server.loadAdapter(JBossServerBehavior.class, null);
-
+
while(loops < 50) {
- if( behavior.getProcess() != null ) {
- return behavior.getProcess();
+ if( ((IProcessProvider)behavior.getDelegate()).getProcess() != null ) {
+ return ((IProcessProvider)behavior.getDelegate()).getProcess();
}
try {
loops++;
Modified:
workspace/rstryker/rse/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/StartupShutdownTest.java
===================================================================
---
workspace/rstryker/rse/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/StartupShutdownTest.java 2010-08-06
09:19:37 UTC (rev 23965)
+++
workspace/rstryker/rse/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/StartupShutdownTest.java 2010-08-06
10:29:45 UTC (rev 23966)
@@ -34,9 +34,10 @@
import org.eclipse.swt.SWTException;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServer.IOperationListener;
import org.eclipse.wst.server.core.IServerListener;
import org.eclipse.wst.server.core.ServerEvent;
-import org.eclipse.wst.server.core.IServer.IOperationListener;
+import
org.jboss.ide.eclipse.as.core.extensions.polling.ProcessTerminatedPoller.IProcessProvider;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.ide.eclipse.as.test.ASTest;
@@ -259,8 +260,8 @@
JBossServerBehavior behavior =
(JBossServerBehavior)currentServer.loadAdapter(JBossServerBehavior.class, null);
if( behavior != null ) {
- if( behavior.getProcess() != null ) {
- return behavior.getProcess().getStreamsProxy().getOutputStreamMonitor();
+ if( ((IProcessProvider)behavior.getDelegate()).getProcess() != null ) {
+ return
((IProcessProvider)behavior.getDelegate()).getProcess().getStreamsProxy().getOutputStreamMonitor();
}
}
return null;