[jboss-cvs] jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server ...

Robert Stryker rawb at belmont.prod.atl2.jboss.com
Tue Aug 29 12:49:08 EDT 2006


  User: rawb    
  Date: 06/08/29 12:49:08

  Modified:    as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server   
                        JBossServerBehavior.java ServerStateChecker.java
                        JBossLaunchConfigurationDelegate.java
  Log:
  Refactored launch configuration, its associated UI tabs, and moved some behavior from the JBossServerBehavior class to the JBossLaunchConfigurationDelegate instead. 
  
  Also had to change which configuration attributes were checked or set, so twiddle launches and start and stop of server were modified. 
  
  Revision  Changes    Path
  1.8       +39 -59    jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JBossServerBehavior.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- JBossServerBehavior.java	27 Jul 2006 15:59:30 -0000	1.7
  +++ JBossServerBehavior.java	29 Aug 2006 16:49:08 -0000	1.8
  @@ -132,24 +132,9 @@
   
   		try {
   			// Set up our launch configuration for a STOP call (to shutdown.jar)
  -			ILaunchConfiguration launchConfig = ((Server)getServer()).getLaunchConfiguration(true, null);
  -			ILaunchConfigurationWorkingCopy wc = launchConfig.getWorkingCopy();
  -			
  -			List cp = getJBossServer().getJBossRuntime().getVersionDelegate().getRuntimeClasspath(jbServer, IJBossServerRuntimeDelegate.ACTION_SHUTDOWN);
  -			String args = runtimeDelegate.getStopArgs(jbServer);
  -			wc.setAttribute(ATTR_ACTION, ACTION_STOPPING);
  -
  +			ILaunchConfiguration wc = JBossLaunchConfigurationDelegate.setupLaunchConfiguration(jbServer, ACTION_STOPPING);
   			ServerAttributeHelper helper = getJBossServer().getAttributeHelper();
   
  -			
  -			// Set our attributes from our runtime configuration
  -			wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, cp);
  -			wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, 
  -					helper.getServerHome());
  -			wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args);
  -			wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, runtimeDelegate.getVMArgs(jbServer));
  -			wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, runtimeDelegate.getStopMainType());
  -			
   			wc.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
   			
   			int maxWait = helper.getStopTimeout();
  @@ -191,15 +176,8 @@
   					if( stopProcesses[0].getExitValue() != 0 ) {
   						// Our stop process ended with exceptions. That means the server is still running.
   						// We need to shut it down.  
  -
  -						String text = "\n\n" + 
  -								"The server shutdown script failed. The server has been terminated manually.\n" + 
  -								"The most common cause of this is that a minimal configuration does not respond to the shutdown script\n" +
  -								"The shutdown script's exception trace can be seen above \n\n";
  -//						JBossServerCore.getDefault().sendToConsole(text);
   						forceStop();
   						return;
  -						
   					}
   				}
   
  @@ -239,43 +217,45 @@
   	
   	
   	public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor) throws CoreException {
  -		JBossServerRuntime runtime = getJBossServer().getJBossRuntime();
  -		AbstractServerRuntimeDelegate runtimeDelegate = runtime.getVersionDelegate();
  +		JBossLaunchConfigurationDelegate.setupLaunchConfiguration(workingCopy, getJBossServer(), ACTION_STARTING);
   		
  -		ServerAttributeHelper helper = getJBossServer().getAttributeHelper();
  -		
  -		String action = workingCopy.getAttribute(ATTR_ACTION, ACTION_STARTING);
  -		if( action.equals(ACTION_STARTING)) {
  -			try {
  -				
  -				String pgArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null); 
  -				if( pgArgs == null ) {
  -					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, runtime.getVersionDelegate().getStartArgs(jbServer));
  -				}
  -				String vmArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, (String)null);
  -				if( vmArgs == null ) {
  -					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, runtime.getVersionDelegate().getVMArgs(jbServer));
  -				}
  -				
  -				
  -				workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, runtime.getVersionDelegate().getStartMainType());
  -		        workingCopy.setAttribute(
  -		                IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
  -		                helper.getServerHome() + Path.SEPARATOR + "bin");
  -
  -				
  -		        boolean defaultCPVal = workingCopy.getAttribute(JBossServerBehavior.LAUNCH_CONFIG_DEFAULT_CLASSPATH, true);
  -		        if( defaultCPVal ) {
  -					List classpath = runtimeDelegate.getRuntimeClasspath(getJBossServer(), IJBossServerRuntimeDelegate.ACTION_START);
  -					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
  -					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);
  -		        }
  -			} catch( Exception e ) {
  -				e.printStackTrace();
  -			}
  -		} else {
  -			// do nothing
  -		}
  +//		JBossServerRuntime runtime = getJBossServer().getJBossRuntime();
  +//		AbstractServerRuntimeDelegate runtimeDelegate = runtime.getVersionDelegate();
  +//		
  +//		ServerAttributeHelper helper = getJBossServer().getAttributeHelper();
  +//		
  +//		String action = workingCopy.getAttribute(ATTR_ACTION, ACTION_STARTING);
  +//		if( action.equals(ACTION_STARTING)) {
  +//			try {
  +//				
  +//				String pgArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null); 
  +//				if( pgArgs == null ) {
  +//					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, runtime.getVersionDelegate().getStartArgs(jbServer));
  +//				}
  +//				String vmArgs = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, (String)null);
  +//				if( vmArgs == null ) {
  +//					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, runtime.getVersionDelegate().getVMArgs(jbServer));
  +//				}
  +//				
  +//				
  +//				workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, runtime.getVersionDelegate().getStartMainType());
  +//		        workingCopy.setAttribute(
  +//		                IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
  +//		                helper.getServerHome() + Path.SEPARATOR + "bin");
  +//
  +//				
  +//		        boolean defaultCPVal = workingCopy.getAttribute(JBossServerBehavior.LAUNCH_CONFIG_DEFAULT_CLASSPATH, true);
  +//		        if( defaultCPVal ) {
  +//					List classpath = runtimeDelegate.getRuntimeClasspath(getJBossServer(), IJBossServerRuntimeDelegate.ACTION_START);
  +//					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
  +//					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);
  +//		        }
  +//			} catch( Exception e ) {
  +//				e.printStackTrace();
  +//			}
  +//		} else {
  +//			// do nothing
  +//		}
   	}
   	
   	/**
  
  
  
  1.14      +1 -4      jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/ServerStateChecker.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ServerStateChecker.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/ServerStateChecker.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -b -r1.13 -r1.14
  --- ServerStateChecker.java	26 Aug 2006 02:33:20 -0000	1.13
  +++ ServerStateChecker.java	29 Aug 2006 16:49:08 -0000	1.14
  @@ -78,10 +78,7 @@
   	}
   	
   	public void run() {
  -		int jndiPort = jbServer.getDescriptorModel().getJNDIPort();
  -		String host = jbServer.getServer().getHost();
  -		String args = "-s " + host + ":" + jndiPort +  " -a jmx/rmi/RMIAdaptor " + 
  -						"get \"jboss.system:type=Server\" Started";
  +		String args = "get \"jboss.system:type=Server\" Started";
   		
   		ent =  ServerProcessModel.getDefault().getModel(jbServer.getServer().getId());
   		eventLog = new StateCheckerLogEvent(expectedState);
  
  
  
  1.3       +192 -1    jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossLaunchConfigurationDelegate.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JBossLaunchConfigurationDelegate.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossLaunchConfigurationDelegate.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- JBossLaunchConfigurationDelegate.java	2 Jun 2006 16:47:56 -0000	1.2
  +++ JBossLaunchConfigurationDelegate.java	29 Aug 2006 16:49:08 -0000	1.3
  @@ -22,30 +22,217 @@
   package org.jboss.ide.eclipse.as.core.server;
   
   import java.io.File;
  +import java.util.List;
   import java.util.Map;
   
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.IProgressMonitor;
   import org.eclipse.core.runtime.NullProgressMonitor;
  +import org.eclipse.core.runtime.Path;
   import org.eclipse.debug.core.DebugEvent;
   import org.eclipse.debug.core.DebugPlugin;
   import org.eclipse.debug.core.IDebugEventSetListener;
   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.AbstractJavaLaunchConfigurationDelegate;
   import org.eclipse.jdt.launching.ExecutionArguments;
  +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
   import org.eclipse.jdt.launching.IVMInstall;
   import org.eclipse.jdt.launching.IVMRunner;
   import org.eclipse.jdt.launching.VMRunnerConfiguration;
   import org.eclipse.wst.server.core.IServer;
   import org.eclipse.wst.server.core.ServerUtil;
  +import org.eclipse.wst.server.core.internal.Server;
  +import org.eclipse.wst.server.core.internal.ServerType;
  +import org.eclipse.wst.server.core.internal.Trace;
   import org.jboss.ide.eclipse.as.core.model.ServerProcessModel;
   import org.jboss.ide.eclipse.as.core.model.ServerProcessModel.ServerProcessModelEntity;
  +import org.jboss.ide.eclipse.as.core.server.runtime.AbstractServerRuntimeDelegate;
  +import org.jboss.ide.eclipse.as.core.server.runtime.IJBossServerRuntimeDelegate;
  +import org.jboss.ide.eclipse.as.core.server.runtime.JBossServerRuntime;
  +import org.jboss.ide.eclipse.as.core.util.ASDebug;
   
   public class JBossLaunchConfigurationDelegate extends
   	AbstractJavaLaunchConfigurationDelegate {
   	
  +	protected static final char[] INVALID_CHARS = new char[] {'\\', '/', ':', '*', '?', '"', '<', '>', '|', '\0', '@', '&'};
  +	public static final String PRGM_ARGS_START_SUFFIX = "_SERVER_START_"; 
  +	public static final String PRGM_ARGS_STOP_SUFFIX = "_SERVER_STOP_";
  +	public static final String PRGM_ARGS_TWIDDLE_SUFFIX = "_SERVER_TWIDDLE_"; 
  +
  +	public static ILaunchConfigurationWorkingCopy setupLaunchConfiguration(JBossServer server, String action) throws CoreException {
  +		ILaunchConfigurationWorkingCopy config = createLaunchConfiguration(server);
  +		setupLaunchConfiguration(config, server, action);
  +		return config;
  +	}
  +	
  +	public static void setupLaunchConfiguration(
  +			ILaunchConfigurationWorkingCopy workingCopy, JBossServer server, String action) throws CoreException {
  +
  +		JBossServerRuntime runtime = server.getJBossRuntime();
  +		AbstractServerRuntimeDelegate runtimeDelegate = runtime.getVersionDelegate();
  +		
  +		ServerAttributeHelper helper = server.getAttributeHelper();
  +		
  +		String argsKey = IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS;
  +		String vmArgsKey = IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS;
  +		workingCopy.setAttribute(JBossServerBehavior.ATTR_ACTION, action);	
  +
  +		if( JBossServerBehavior.ACTION_STARTING.equals(action)) {
  +			String suffix = PRGM_ARGS_START_SUFFIX;
  +			try {
  +				String pgArgs = workingCopy.getAttribute(argsKey + suffix, (String)null); 
  +				if( pgArgs == null ) {
  +					pgArgs =  runtime.getVersionDelegate().getStartArgs(server);
  +					workingCopy.setAttribute(argsKey + suffix, pgArgs);
  +				}
  +				workingCopy.setAttribute(argsKey,pgArgs);
  +				
  +
  +				String vmArgs = workingCopy.getAttribute(vmArgsKey + suffix, (String)null);
  +				if( vmArgs == null ) {
  +					vmArgs = runtime.getVersionDelegate().getVMArgs(server);
  +					workingCopy.setAttribute(vmArgsKey + suffix, vmArgs);
  +				}
  +				workingCopy.setAttribute(vmArgsKey, vmArgs);
  +				
  +				workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, runtime.getVersionDelegate().getStartMainType());
  +		        workingCopy.setAttribute(
  +		                IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
  +		                helper.getServerHome() + Path.SEPARATOR + "bin");
  +
  +				
  +		        boolean defaultCPVal = workingCopy.getAttribute(JBossServerBehavior.LAUNCH_CONFIG_DEFAULT_CLASSPATH, true);
  +		        if( defaultCPVal ) {
  +					List classpath = runtimeDelegate.getRuntimeClasspath(server, IJBossServerRuntimeDelegate.ACTION_START);
  +					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
  +					workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);
  +		        }
  +
  +			} catch( Exception e ) {
  +				e.printStackTrace();
  +			}
  +
  +		} else if( JBossServerBehavior.ACTION_STOPPING.equals(action)) {
  +			String suffix = PRGM_ARGS_STOP_SUFFIX;
  +			
  +			String args = workingCopy.getAttribute(argsKey + suffix, (String)null);
  +			if( args == null ) {
  +				args = runtimeDelegate.getStopArgs(server);
  +				workingCopy.setAttribute(argsKey + suffix, args);
  +			}
  +			workingCopy.setAttribute(argsKey,args);
  +			
  +			
  +			String vmArgs = workingCopy.getAttribute(vmArgsKey + suffix, (String)null);
  +			if( vmArgs == null ) {
  +				vmArgs = runtimeDelegate.getVMArgs(server);
  +				workingCopy.setAttribute(vmArgsKey + suffix, vmArgs);
  +			}
  +			workingCopy.setAttribute(vmArgsKey,vmArgs);
  +			
  +			
  +			List cp = server.getJBossRuntime().getVersionDelegate().getRuntimeClasspath(server, IJBossServerRuntimeDelegate.ACTION_SHUTDOWN);
  +			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, cp);
  +			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, 
  +					helper.getServerHome());
  +			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args);
  +			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, runtimeDelegate.getStopMainType());
  +			
  +		} else if( JBossServerBehavior.ACTION_TWIDDLE.equals(action)) {
  +			String suffix = PRGM_ARGS_TWIDDLE_SUFFIX;
  +
  +			String vmArgs = workingCopy.getAttribute(vmArgsKey + suffix, (String)null);
  +			if( vmArgs == null ) {
  +				vmArgs = "";
  +				workingCopy.setAttribute(vmArgsKey + suffix, (String)null);
  +			}
  +			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs);
  +			
  +			String args = workingCopy.getAttribute(argsKey + suffix, (String)null);
  +			if( args == null ) {
  +		 		int jndiPort = server.getDescriptorModel().getJNDIPort();
  +				String host = server.getServer().getHost();
  +				args = "-s " + host + ":" + jndiPort +  " -a jmx/rmi/RMIAdaptor ";
  +				workingCopy.setAttribute(argsKey + suffix, args);
  +			}
  +			workingCopy.setAttribute(argsKey, args);
  +			
  +
  +			
  +			
  +			List classpath = runtimeDelegate.getRuntimeClasspath(server, IJBossServerRuntimeDelegate.ACTION_TWIDDLE);
  +			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);
  +			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
  +			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, runtimeDelegate.getTwiddleMainType());
  +			workingCopy.setAttribute(Server.ATTR_SERVER_ID, server.getServer().getId());
  +			workingCopy.setAttribute(JBossServerBehavior.ATTR_ACTION, JBossServerBehavior.ACTION_TWIDDLE);
  +			
  +	        workingCopy.setAttribute(
  +	                IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
  +	                server.getAttributeHelper().getServerHome() + Path.SEPARATOR + "bin");
  +
  +		}
  +
  +
  +	
  +	}
  +	
  +	public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(JBossServer server) throws CoreException {
  +		ILaunchConfigurationType launchConfigType = 
  +			((ServerType) server.getServer().getServerType()).getLaunchConfigurationType();
  +		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.getServer().getId().equals(serverId)) {
  +						ILaunchConfigurationWorkingCopy wc = launchConfigs[i].getWorkingCopy();
  +						return wc;
  +					}
  +				} catch (CoreException e) {
  +					Trace.trace(Trace.SEVERE, "Error configuring launch", e);
  +				}
  +			}
  +		}
  +		
  +		// create a new launch configuration
  +		String launchName = getValidLaunchConfigurationName(server.getServer().getName());
  +		launchName = launchManager.generateUniqueLaunchConfigurationNameFrom(launchName); 
  +		ILaunchConfigurationWorkingCopy wc = launchConfigType.newInstance(null, launchName);
  +		wc.setAttribute("server-id", server.getServer().getId());
  +		return wc;
  +	}
  +
  +	protected static String getValidLaunchConfigurationName(String s) {
  +		if (s == null || s.length() == 0)
  +			return "1";
  +		int size = INVALID_CHARS.length;
  +		for (int i = 0; i < size; i++) {
  +			s = s.replace(INVALID_CHARS[i], '_');
  +		}
  +		return s;
  +	}
  +	
  +
  +	
  +	
  +	
   	private IProcess[] processes;
   
   	public void launch(ILaunchConfiguration configuration, String mode,
  @@ -54,6 +241,10 @@
   		String action = configuration.getAttribute(JBossServerBehavior.ATTR_ACTION, 
   				JBossServerBehavior.ACTION_STARTING);	
   		
  +		/* temp */
  +		String programArgs = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
  +		String vmArgs = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, (String)null);
  +				
   		if( action.equals(JBossServerBehavior.ACTION_STARTING)) {
   			launchServerStart(configuration, mode, launch,  monitor);
   		} else if( action.equals(JBossServerBehavior.ACTION_STOPPING)) {
  
  
  



More information about the jboss-cvs-commits mailing list