|
From: <caw...@us...> - 2007-01-19 15:44:18
|
Revision: 1806
http://svn.sourceforge.net/rubyeclipse/?rev=1806&view=rev
Author: cawilliams
Date: 2007-01-19 07:44:11 -0800 (Fri, 19 Jan 2007)
Log Message:
-----------
yay, our new interpreter stuff is hooked in and works. Now I need to slowly remove the old stuff in the pipeline (like InterpreterRunner and InterpreterRunnerConfiguration).
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DataFlowTypeInferrer.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultTypeInferrer.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunner.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunnerConfiguration.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IRubyLaunchConfigurationConstants.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IVMInstall.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IVMRunner.java
trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java
trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TS_InternalLaunching.java
trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/launching/tests/TS_Launching.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMRunner.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/AbstractVMRunner.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/VMRunnerConfiguration.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DataFlowTypeInferrer.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DataFlowTypeInferrer.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DataFlowTypeInferrer.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -37,9 +37,10 @@
import org.rubypeople.rdt.internal.ti.util.ScopedNodeLocator;
public class DataFlowTypeInferrer implements ITypeInferrer {
+ private static final boolean VERBOSE = false;
+
private void sysout(String string) {
- // false to suppress debug
- if ( true ) {
+ if ( VERBOSE ) {
System.out.println(string);
}
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultTypeInferrer.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultTypeInferrer.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultTypeInferrer.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -174,7 +174,7 @@
private void tryLocalVarNode(Node node, List<ITypeGuess> guesses)
{
- System.out.println(node.getClass().getName());
+ //System.out.println(node.getClass().getName());
if ( node instanceof LocalVarNode )
{
LocalVarNode localVarNode = (LocalVarNode)node;
@@ -209,12 +209,12 @@
if ( argsNode != null )
{
int argNumber = getArgumentIndex(argsNode,localVarName);
- System.out.println("Variable " + localVarName + " is the " + argNumber + "th argument to the enclosing method ");
+ //System.out.println("Variable " + localVarName + " is the " + argNumber + "th argument to the enclosing method ");
// Find enclosing method
Node defNode = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(rootNode, nodeStart, new INodeAcceptor(){
public boolean doesAccept(Node node) {
- System.out.println("Looking for enclosing method, checking: " + node.getClass().getName() + "[" + node.getPosition().getStartOffset() + ".." + node.getPosition().getEndOffset() + "]" );
+ //System.out.println("Looking for enclosing method, checking: " + node.getClass().getName() + "[" + node.getPosition().getStartOffset() + ".." + node.getPosition().getEndOffset() + "]" );
ArgsNode argsNode = null;
if ( node instanceof DefnNode ) argsNode = ((DefnNode)node).getArgsNode();
if ( node instanceof DefsNode ) argsNode = ((DefsNode)node).getArgsNode();
@@ -227,7 +227,7 @@
if ( defNode instanceof DefnNode ) methodName = ((DefnNode)defNode).getName();
if ( defNode instanceof DefsNode ) methodName = ((DefsNode)defNode).getName();
- System.out.println("Variable " + localVarName + " is the " + argNumber + "th argument to method " + methodName );
+ //System.out.println("Variable " + localVarName + " is the " + argNumber + "th argument to method " + methodName );
// Find all invocations of the surrounding method.
//todo: from easiest to hardest:
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunner.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunner.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunner.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -44,6 +44,8 @@
buffer.append(configuration.getFileName());
} catch (IllegalCommandException e) {
// can't happen because renderLabel assumes that a successful launch has been done
+ } catch(CoreException ce) {
+
}
return buffer.toString();
@@ -62,6 +64,8 @@
return commandLine;
}
+
+
protected void addDebugCommandLineArgument(List<String> commandLine) {
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunnerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunnerConfiguration.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/InterpreterRunnerConfiguration.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -117,15 +117,14 @@
protected List<String> renderLoadPath() {
List<String> loadPath = new ArrayList<String>();
RubyProject project = this.getProject();
- addToLoadPath(loadPath, project.getProject());
+// addToLoadPath(loadPath, project.getProject());
try {
ILoadpathEntry[] entries = project.getResolvedLoadpath(true, false);
for (int i = 0; i < entries.length; i++) {
- addToLoadPath(loadPath, entries[i].getPath().toOSString());
+ addToLoadPath(loadPath, entries[i].getPath().makeAbsolute().toFile().getAbsolutePath());
}
} catch (RubyModelException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
if (new Path(this.getFileName()).segmentCount() > 1) { ;
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -30,6 +30,20 @@
public static String StandardVMType_Not_a_JDK_Root__Java_executable_was_not_found_1;
public static String StandardVMType_ok_2;
public static String StandardVMType_Not_a_JDK_root__System_library_was_not_found__1;
+
+ public static String AbstractVMRunner_0;
+ public static String vmRunnerConfig_assert_classNotNull;
+ public static String vmRunnerConfig_assert_classPathNotNull;
+ public static String vmRunnerConfig_assert_vmArgsNotNull;
+ public static String vmRunnerConfig_assert_programArgsNotNull;
+ public static String StandardVMRunner__0__at_localhost__1__1;
+ public static String StandardVMRunner__0____1___2;
+ public static String StandardVMRunner_Specified_working_directory_does_not_exist_or_is_not_a_directory___0__3;
+ public static String StandardVMRunner_Unable_to_locate_executable_for__0__1;
+ public static String StandardVMRunner_Specified_executable__0__does_not_exist_for__1__4;
+ public static String StandardVMRunner_Launching_VM____1;
+ public static String StandardVMRunner_Constructing_command_line____2;
+ public static String StandardVMRunner_Starting_virtual_machine____3;
private LaunchingMessages() {}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -2,6 +2,7 @@
import java.io.File;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@@ -9,6 +10,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.rubypeople.rdt.launching.AbstractVMInstall;
+import org.rubypeople.rdt.launching.IRubyLaunchConfigurationConstants;
import org.rubypeople.rdt.launching.IVMInstallType;
public class StandardVM extends AbstractVMInstall {
@@ -26,7 +28,7 @@
LaunchingPlugin.debug("Launching: " + args) ;
LaunchingPlugin.debug("Working Dir: " + workingDirectory) ;
List rubyCmd = new ArrayList();
- rubyCmd.add(this.getCommand());
+ rubyCmd.add(getCommand());
rubyCmd.addAll(args);
return fCommandExecutor.exec((String[]) rubyCmd.toArray(new String[] {}), workingDirectory);
} catch (IOException e) {
@@ -34,16 +36,46 @@
"Unable to execute interpreter: " + args + workingDirectory, e);
throw new CoreException(errorStatus) ;
}
- catch (IllegalCommandException e) {
- IStatus errorStatus = new Status(IStatus.ERROR, LaunchingPlugin.PLUGIN_ID, IStatus.OK, e.getMessage(), e);
- throw new CoreException(errorStatus) ;
- }
}
- public String getCommand() throws IllegalCommandException {
- // TODO Auto-generated method stub
- return null;
+ // FIXME This stuff should be in the VMRunner like in JDT!
+ public String getCommand() throws CoreException {
+// Look for the user-specified ruby executable command
+ String command= null;
+// Map map= config.getVMSpecificAttributesMap();
+// if (map != null) {
+// command = (String)map.get(IRubyLaunchConfigurationConstants.ATTR_RUBY_COMMAND);
+// }
+
+ // If no ruby command was specified, use default executable
+ if (command == null) {
+ File exe = StandardVMType.findRubyExecutable(getInstallLocation());
+ if (exe == null) {
+ abort(MessageFormat.format(LaunchingMessages.StandardVMRunner_Unable_to_locate_executable_for__0__1, new String[]{getName()}), null, IRubyLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
+ }
+ return exe.getAbsolutePath();
+ }
+
+ // Build the path to the ruby executable. First try 'bin'
+ String installLocation = getInstallLocation().getAbsolutePath() + File.separatorChar;
+ File exe = new File(installLocation + "bin" + File.separatorChar + command); //$NON-NLS-1$
+ if (fileExists(exe)){
+ return exe.getAbsolutePath();
+ }
+ exe = new File(exe.getAbsolutePath() + ".exe"); //$NON-NLS-1$
+ if (fileExists(exe)){
+ return exe.getAbsolutePath();
+ }
+
+ // not found
+ abort(MessageFormat.format(LaunchingMessages.StandardVMRunner_Specified_executable__0__does_not_exist_for__1__4, new String[]{command, getName()}), null, IRubyLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
+ // NOTE: an exception will be thrown - null cannot be returned
+ return null;
}
+
+ protected boolean fileExists(File file) {
+ return file.exists() && file.isFile();
+ }
public String getRubyVersion() {
StandardVMType installType = (StandardVMType) getVMInstallType();
Added: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMRunner.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMRunner.java (rev 0)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMRunner.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -0,0 +1,246 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.launching;
+
+
+import java.io.File;
+import java.text.DateFormat;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Date;
+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.SubProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IProcess;
+import org.rubypeople.rdt.launching.AbstractVMRunner;
+import org.rubypeople.rdt.launching.IRubyLaunchConfigurationConstants;
+import org.rubypeople.rdt.launching.IVMInstall;
+import org.rubypeople.rdt.launching.VMRunnerConfiguration;
+
+public class StandardVMRunner extends AbstractVMRunner {
+ protected IVMInstall fVMInstance;
+
+ public StandardVMRunner(IVMInstall vmInstance) {
+ fVMInstance= vmInstance;
+ }
+
+ protected String renderDebugTarget(String classToRun, int host) {
+ String format= LaunchingMessages.StandardVMRunner__0__at_localhost__1__1;
+ return MessageFormat.format(format, new String[] { classToRun, String.valueOf(host) });
+ }
+
+ public static String renderProcessLabel(String[] commandLine) {
+ String format= LaunchingMessages.StandardVMRunner__0____1___2;
+ String timestamp= DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(System.currentTimeMillis()));
+ return MessageFormat.format(format, new String[] { commandLine[0], timestamp });
+ }
+
+ protected static String renderCommandLine(String[] commandLine) {
+ if (commandLine.length < 1)
+ return ""; //$NON-NLS-1$
+ StringBuffer buf= new StringBuffer();
+ for (int i= 0; i < commandLine.length; i++) {
+ buf.append(' ');
+ char[] characters= commandLine[i].toCharArray();
+ StringBuffer command= new StringBuffer();
+ boolean containsSpace= false;
+ for (int j = 0; j < characters.length; j++) {
+ char character= characters[j];
+ if (character == '\"') {
+ command.append('\\');
+ } else if (character == ' ') {
+ containsSpace = true;
+ }
+ command.append(character);
+ }
+ if (containsSpace) {
+ buf.append('\"');
+ buf.append(command.toString());
+ buf.append('\"');
+ } else {
+ buf.append(command.toString());
+ }
+ }
+ return buf.toString();
+ }
+
+ protected void addArguments(String[] args, List v) {
+ if (args == null) {
+ return;
+ }
+ for (int i= 0; i < args.length; i++) {
+ v.add(args[i]);
+ }
+ }
+
+ /**
+ * Returns the working directory to use for the launched VM,
+ * or <code>null</code> if the working directory is to be inherited
+ * from the current process.
+ *
+ * @return the working directory to use
+ * @exception CoreException if the working directory specified by
+ * the configuration does not exist or is not a directory
+ */
+ protected File getWorkingDir(VMRunnerConfiguration config) throws CoreException {
+ String path = config.getWorkingDirectory();
+ if (path == null) {
+ return null;
+ }
+ File dir = new File(path);
+ if (!dir.isDirectory()) {
+ abort(MessageFormat.format(LaunchingMessages.StandardVMRunner_Specified_working_directory_does_not_exist_or_is_not_a_directory___0__3, new String[] {path}), null, IRubyLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
+ }
+ return dir;
+ }
+
+ /**
+ * @see VMRunner#getPluginIdentifier()
+ */
+ protected String getPluginIdentifier() {
+ return LaunchingPlugin.getUniqueIdentifier();
+ }
+
+ /**
+ * Construct and return a String containing the full path of a java executable
+ * command such as 'java' or 'javaw.exe'. If the configuration specifies an
+ * explicit executable, that is used.
+ *
+ * @return full path to java executable
+ * @exception CoreException if unable to locate an executeable
+ */
+ protected String constructProgramString(VMRunnerConfiguration config) throws CoreException {
+
+ // Look for the user-specified java executable command
+ String command= null;
+ Map map= config.getVMSpecificAttributesMap();
+ if (map != null) {
+ command = (String)map.get(IRubyLaunchConfigurationConstants.ATTR_RUBY_COMMAND);
+ }
+
+ // If no java command was specified, use default executable
+ if (command == null) {
+ File exe = StandardVMType.findRubyExecutable(fVMInstance.getInstallLocation());
+ if (exe == null) {
+ abort(MessageFormat.format(LaunchingMessages.StandardVMRunner_Unable_to_locate_executable_for__0__1, new String[]{fVMInstance.getName()}), null, IRubyLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
+ }
+ return exe.getAbsolutePath();
+ }
+
+ // Build the path to the ruby executable. First try 'bin'
+ String installLocation = fVMInstance.getInstallLocation().getAbsolutePath() + File.separatorChar;
+ File exe = new File(installLocation + "bin" + File.separatorChar + command); //$NON-NLS-1$
+ if (fileExists(exe)){
+ return exe.getAbsolutePath();
+ }
+ exe = new File(exe.getAbsolutePath() + ".exe"); //$NON-NLS-1$
+ if (fileExists(exe)){
+ return exe.getAbsolutePath();
+ }
+
+ // not found
+ abort(MessageFormat.format(LaunchingMessages.StandardVMRunner_Specified_executable__0__does_not_exist_for__1__4, new String[]{command, fVMInstance.getName()}), null, IRubyLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
+ // NOTE: an exception will be thrown - null cannot be returned
+ return null;
+ }
+
+ protected boolean fileExists(File file) {
+ return file.exists() && file.isFile();
+ }
+
+ protected String convertClassPath(String[] cp) {
+ int pathCount= 0;
+ StringBuffer buf= new StringBuffer();
+ if (cp.length == 0) {
+ return ""; //$NON-NLS-1$
+ }
+ for (int i= 0; i < cp.length; i++) {
+ if (pathCount > 0) {
+ buf.append(File.pathSeparator);
+ }
+ buf.append(cp[i]);
+ pathCount++;
+ }
+ return buf.toString();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.launching.IVMRunner#run(org.eclipse.jdt.launching.VMRunnerConfiguration, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(VMRunnerConfiguration config, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+
+ IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
+ subMonitor.beginTask(LaunchingMessages.StandardVMRunner_Launching_VM____1, 2);
+ subMonitor.subTask(LaunchingMessages.StandardVMRunner_Constructing_command_line____2);
+
+ String program= constructProgramString(config);
+
+ List arguments= new ArrayList();
+ arguments.add(program);
+
+ // VM args are the first thing after the java program so that users can specify
+ // options like '-client' & '-server' which are required to be the first option
+ String[] allVMArgs = combineVmArgs(config, fVMInstance);
+ addArguments(allVMArgs, arguments);
+
+ String[] cp= config.getClassPath();
+ if (cp.length > 0) {
+ arguments.add("-I"); //$NON-NLS-1$
+ arguments.add(convertClassPath(cp));
+ }
+ arguments.add(config.getClassToLaunch());
+
+ String[] programArgs= config.getProgramArguments();
+ addArguments(programArgs, arguments);
+
+ String[] cmdLine= new String[arguments.size()];
+ arguments.toArray(cmdLine);
+
+ String[] envp= config.getEnvironment();
+
+ subMonitor.worked(1);
+
+ // check for cancellation
+ if (monitor.isCanceled()) {
+ return;
+ }
+
+ subMonitor.subTask(LaunchingMessages.StandardVMRunner_Starting_virtual_machine____3);
+ Process p= null;
+ File workingDir = getWorkingDir(config);
+ p= exec(cmdLine, workingDir, envp);
+ if (p == null) {
+ return;
+ }
+
+ // check for cancellation
+ if (monitor.isCanceled()) {
+ p.destroy();
+ return;
+ }
+
+ IProcess process= newProcess(launch, p, renderProcessLabel(cmdLine), getDefaultProcessMap());
+ process.setAttribute(IProcess.ATTR_CMDLINE, renderCommandLine(cmdLine));
+ subMonitor.worked(1);
+ subMonitor.done();
+ }
+
+}
Added: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/AbstractVMRunner.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/AbstractVMRunner.java (rev 0)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/AbstractVMRunner.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.launching;
+
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IProcess;
+import org.rubypeople.rdt.internal.launching.LaunchingMessages;
+
+/**
+ * Abstract implementation of a VM runner.
+ * <p>
+ * Clients implementing VM runners should subclass this class.
+ * </p>
+ * @see IVMRunner
+ * @since 2.0
+ */
+public abstract class AbstractVMRunner implements IVMRunner {
+
+ /**
+ * Throws a core exception with an error status object built from
+ * the given message, lower level exception, and error code.
+ *
+ * @param message the status message
+ * @param exception lower level exception associated with the
+ * error, or <code>null</code> if none
+ * @param code error code
+ * @throws CoreException The exception encapsulating the reason for the abort
+ */
+ protected void abort(String message, Throwable exception, int code) throws CoreException {
+ throw new CoreException(new Status(IStatus.ERROR, getPluginIdentifier(), code, message, exception));
+ }
+
+ /**
+ * Returns the identifier of the plug-in this VM runner
+ * originated from.
+ *
+ * @return plug-in identifier
+ */
+ protected abstract String getPluginIdentifier();
+
+ /**
+ * @see DebugPlugin#exec(String[], File)
+ */
+ protected Process exec(String[] cmdLine, File workingDirectory) throws CoreException {
+ return DebugPlugin.exec(cmdLine, workingDirectory);
+ }
+
+ /**
+ * @since 3.0
+ * @see DebugPlugin#exec(String[], File, String[])
+ */
+ protected Process exec(String[] cmdLine, File workingDirectory, String[] envp) throws CoreException {
+ return DebugPlugin.exec(cmdLine, workingDirectory, envp);
+ }
+
+ /**
+ * Returns the given array of strings as a single space-delimited string.
+ *
+ * @param cmdLine array of strings
+ * @return a single space-delimited string
+ */
+ protected String getCmdLineAsString(String[] cmdLine) {
+ StringBuffer buff= new StringBuffer();
+ for (int i = 0, numStrings= cmdLine.length; i < numStrings; i++) {
+ buff.append(cmdLine[i]);
+ buff.append(' ');
+ }
+ return buff.toString().trim();
+ }
+
+ /**
+ * Returns the default process attribute map for Ruby processes.
+ *
+ * @return default process attribute map for Ruby processes
+ */
+ protected Map getDefaultProcessMap() {
+ Map map = new HashMap();
+ map.put(IProcess.ATTR_PROCESS_TYPE, IRubyLaunchConfigurationConstants.ID_RUBY_PROCESS_TYPE);
+ return map;
+ }
+
+ /**
+ * Returns a new process aborting if the process could not be created.
+ * @param launch the launch the process is contained in
+ * @param p the system process to wrap
+ * @param label the label assigned to the process
+ * @param attributes values for the attribute map
+ * @return the new process
+ * @throws CoreException problems occurred creating the process
+ * @since 3.0
+ */
+ protected IProcess newProcess(ILaunch launch, Process p, String label, Map attributes) throws CoreException {
+ IProcess process= DebugPlugin.newProcess(launch, p, label, attributes);
+ if (process == null) {
+ p.destroy();
+ abort(LaunchingMessages.AbstractVMRunner_0, null, IRubyLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
+ }
+ return process;
+ }
+
+ /**
+ * Combines and returns VM arguments specified by the runner configuration,
+ * with those specified by the VM install, if any.
+ *
+ * @param configuration runner configuration
+ * @param vmInstall vm install
+ * @return combined VM arguments specified by the runner configuration
+ * and VM install
+ * @since 0.9.0
+ */
+ protected String[] combineVmArgs(VMRunnerConfiguration configuration, IVMInstall vmInstall) {
+ String[] launchVMArgs= configuration.getVMArguments();
+ String[] vmVMArgs = vmInstall.getVMArguments();
+ if (vmVMArgs == null || vmVMArgs.length == 0) {
+ return launchVMArgs;
+ }
+ String[] allVMArgs = new String[launchVMArgs.length + vmVMArgs.length];
+ System.arraycopy(launchVMArgs, 0, allVMArgs, 0, launchVMArgs.length);
+ System.arraycopy(vmVMArgs, 0, allVMArgs, launchVMArgs.length, vmVMArgs.length);
+ return allVMArgs;
+ }
+}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IRubyLaunchConfigurationConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IRubyLaunchConfigurationConstants.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IRubyLaunchConfigurationConstants.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -1,10 +1,33 @@
package org.rubypeople.rdt.launching;
+import org.rubypeople.rdt.internal.launching.LaunchingPlugin;
+
public interface IRubyLaunchConfigurationConstants {
/**
+ * Status code indicating the specified working directory
+ * does not exist.
+ */
+ public static final int ERR_WORKING_DIRECTORY_DOES_NOT_EXIST = 108;
+
+ /**
* Status code indicating an unexpected internal error.
*/
- public static final int ERR_INTERNAL_ERROR = 150;
+ public static final int ERR_INTERNAL_ERROR = 150;
+ /**
+ * Identifier for the ruby process type, which is annotated on processes created
+ * by the local ruby application launch delegate.
+ *
+ * (value <code>"ruby"</code>).
+ */
+ public static final String ID_RUBY_PROCESS_TYPE = "ruby"; //$NON-NLS-1$
+
+ /**
+ * Attribute key for VM specific attributes found in the
+ * <code>ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP</code>. The value is a String,
+ * indicating the String to use to invoke the Ruby VM.
+ */
+ public static final String ATTR_RUBY_COMMAND = LaunchingPlugin.getUniqueIdentifier() + ".RUBY_COMMAND"; //$NON-NLS-1$
+
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IVMInstall.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IVMInstall.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IVMInstall.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -20,10 +20,10 @@
/**
*
* @return
- * @throws IllegalCommandException
+ * @throws CoreException
* @deprecated
*/
- public String getCommand() throws IllegalCommandException;
+ public String getCommand() throws CoreException, IllegalCommandException;
/**
*
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IVMRunner.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IVMRunner.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IVMRunner.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -14,7 +14,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
-import org.rubypeople.rdt.internal.launching.InterpreterRunnerConfiguration;
@@ -36,6 +35,6 @@
* @param monitor progress monitor or <code>null</code>
* @exception CoreException if an exception occurs while launching
*/
- public void run(InterpreterRunnerConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException;
+ public void run(VMRunnerConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException;
}
Added: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/VMRunnerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/VMRunnerConfiguration.java (rev 0)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/VMRunnerConfiguration.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -0,0 +1,266 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.rubypeople.rdt.launching;
+
+
+import java.util.Map;
+
+import org.rubypeople.rdt.internal.launching.LaunchingMessages;
+
+/**
+ * Holder for various arguments passed to a VM runner.
+ * Mandatory parameters are passed in the constructor; optional arguments, via setters.
+ * <p>
+ * Clients may instantiate this class; it is not intended to be subclassed.
+ * </p>
+ */
+public class VMRunnerConfiguration {
+ private String fClassToLaunch;
+ private String[] fVMArgs;
+ private String[] fProgramArgs;
+ private String[] fEnvironment;
+ private String[] fClassPath;
+ private String[] fBootClassPath;
+ private String fWorkingDirectory;
+ private Map fVMSpecificAttributesMap;
+ private boolean fResume = true;
+
+ private static final String[] fgEmpty= new String[0];
+
+ /**
+ * Creates a new configuration for launching a VM to run the given main class
+ * using the given class path.
+ *
+ * @param classToLaunch The fully qualified name of the class to launch. May not be null.
+ * @param classPath The classpath. May not be null.
+ */
+ public VMRunnerConfiguration(String classToLaunch, String[] classPath) {
+ if (classToLaunch == null) {
+ throw new IllegalArgumentException(LaunchingMessages.vmRunnerConfig_assert_classNotNull);
+ }
+ if (classPath == null) {
+ throw new IllegalArgumentException(LaunchingMessages.vmRunnerConfig_assert_classPathNotNull);
+ }
+ fClassToLaunch= classToLaunch;
+ fClassPath= classPath;
+ }
+
+ /**
+ * Sets the <code>Map</code> that contains String name/value pairs that represent
+ * VM-specific attributes.
+ *
+ * @param map the <code>Map</code> of VM-specific attributes.
+ * @since 2.0
+ */
+ public void setVMSpecificAttributesMap(Map map) {
+ fVMSpecificAttributesMap = map;
+ }
+
+ /**
+ * Sets the custom VM arguments. These arguments will be appended to the list of
+ * VM arguments that a VM runner uses when launching a VM. Typically, these VM arguments
+ * are set by the user.
+ * These arguments will not be interpreted by a VM runner, the client is responsible for
+ * passing arguments compatible with a particular VM runner.
+ *
+ * @param args the list of VM arguments
+ */
+ public void setVMArguments(String[] args) {
+ if (args == null) {
+ throw new IllegalArgumentException(LaunchingMessages.vmRunnerConfig_assert_vmArgsNotNull);
+ }
+ fVMArgs= args;
+ }
+
+ /**
+ * Sets the custom program arguments. These arguments will be appended to the list of
+ * program arguments that a VM runner uses when launching a VM (in general: none).
+ * Typically, these VM arguments are set by the user.
+ * These arguments will not be interpreted by a VM runner, the client is responsible for
+ * passing arguments compatible with a particular VM runner.
+ *
+ * @param args the list of arguments
+ */
+ public void setProgramArguments(String[] args) {
+ if (args == null) {
+ throw new IllegalArgumentException(LaunchingMessages.vmRunnerConfig_assert_programArgsNotNull);
+ }
+ fProgramArgs= args;
+ }
+
+ /**
+ * Sets the environment for the Java program. The Java VM will be
+ * launched in the given environment.
+ *
+ * @param environment the environment for the Java program specified as an array
+ * of strings, each element specifying an environment variable setting in the
+ * format <i>name</i>=<i>value</i>
+ * @since 3.0
+ */
+ public void setEnvironment(String[] environment) {
+ fEnvironment= environment;
+ }
+
+ /**
+ * Sets the boot classpath. Note that the boot classpath will be passed to the
+ * VM "as is". This means it has to be complete. Interpretation of the boot class path
+ * is up to the VM runner this object is passed to.
+ * <p>
+ * In release 3.0, support has been added for appending and prepending the
+ * boot classpath. Generally an <code>IVMRunner</code> should use the prepend,
+ * main, and append boot classpaths provided. However, in the case that an
+ * <code>IVMRunner</code> does not support these options, a complete bootpath
+ * should also be specified.
+ * </p>
+ * @param bootClassPath The boot classpath. An empty array indicates an empty
+ * bootpath and <code>null</code> indicates a default bootpath.
+ */
+ public void setBootClassPath(String[] bootClassPath) {
+ fBootClassPath= bootClassPath;
+ }
+
+ /**
+ * Returns the <code>Map</code> that contains String name/value pairs that represent
+ * VM-specific attributes.
+ *
+ * @return The <code>Map</code> of VM-specific attributes or <code>null</code>.
+ * @since 2.0
+ */
+ public Map getVMSpecificAttributesMap() {
+ return fVMSpecificAttributesMap;
+ }
+
+ /**
+ * Returns the name of the class to launch.
+ *
+ * @return The fully qualified name of the class to launch. Will not be <code>null</code>.
+ */
+ public String getClassToLaunch() {
+ return fClassToLaunch;
+ }
+
+ /**
+ * Returns the classpath.
+ *
+ * @return the classpath
+ */
+ public String[] getClassPath() {
+ return fClassPath;
+ }
+
+ /**
+ * Returns the boot classpath. An empty array indicates an empty
+ * bootpath and <code>null</code> indicates a default bootpath.
+ * <p>
+ * In 3.0, support has been added for prepending and appending to the
+ * boot classpath. The new attributes are stored in the VM specific
+ * attributes map using the following keys defined in
+ * <code>IJavaLaunchConfigurationConstants</code>:
+ * <ul>
+ * <li>ATTR_BOOTPATH_PREPEND</li>
+ * <li>ATTR_BOOTPATH_APPEND</li>
+ * <li>ATTR_BOOTPATH</li>
+ * </ul>
+ * </p>
+ * @return The boot classpath. An empty array indicates an empty
+ * bootpath and <code>null</code> indicates a default bootpath.
+ * @see #setBootClassPath(String[])
+ * @see IJavaLaunchConfigurationConstants
+ */
+ public String[] getBootClassPath() {
+ return fBootClassPath;
+ }
+
+ /**
+ * Returns the arguments to the VM itself.
+ *
+ * @return The VM arguments. Default is an empty array. Will not be <code>null</code>.
+ * @see #setVMArguments(String[])
+ */
+ public String[] getVMArguments() {
+ if (fVMArgs == null) {
+ return fgEmpty;
+ }
+ return fVMArgs;
+ }
+
+ /**
+ * Returns the arguments to the Java program.
+ *
+ * @return The Java program arguments. Default is an empty array. Will not be <code>null</code>.
+ * @see #setProgramArguments(String[])
+ */
+ public String[] getProgramArguments() {
+ if (fProgramArgs == null) {
+ return fgEmpty;
+ }
+ return fProgramArgs;
+ }
+
+ /**
+ * Returns the environment for the Java program or <code>null</code>
+ *
+ * @return The Java program environment. Default is <code>null</code>
+ * @since 3.0
+ */
+ public String[] getEnvironment() {
+ return fEnvironment;
+ }
+
+ /**
+ * Sets the working directory for a launched VM.
+ *
+ * @param path the absolute path to the working directory
+ * to be used by a launched VM, or <code>null</code> if
+ * the default working directory is to be inherited from the
+ * current process
+ * @since 2.0
+ */
+ public void setWorkingDirectory(String path) {
+ fWorkingDirectory = path;
+ }
+
+ /**
+ * Returns the working directory of a launched VM.
+ *
+ * @return the absolute path to the working directory
+ * of a launched VM, or <code>null</code> if the working
+ * directory is inherited from the current process
+ * @since 2.0
+ */
+ public String getWorkingDirectory() {
+ return fWorkingDirectory;
+ }
+
+ /**
+ * Sets whether the VM is resumed on startup when launched in
+ * debug mode. Has no effect when not in debug mode.
+ *
+ * @param resume whether to resume the VM on startup
+ * @since 3.0
+ */
+ public void setResumeOnStartup(boolean resume) {
+ fResume = resume;
+ }
+
+ /**
+ * Returns whether the VM is resumed on startup when launched
+ * in debug mode. Has no effect when no in debug mode. Default
+ * value is <code>true</code> for backwards compatibility.
+ *
+ * @return whether to resume the VM on startup
+ * @since 3.0
+ */
+ public boolean isResumeOnStartup() {
+ return fResume;
+ }
+}
Modified: trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java
===================================================================
--- trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -65,7 +65,7 @@
RubyRuntime.saveVMConfiguration();
assertEquals(
"XML should indicate only one interpreter with it being the selected.",
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings>\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"\" defaultVMConnector=\"\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
getVMsXML());
VMStandin standin2 = new VMStandin(vmType, "InterpreterTwo");
@@ -75,13 +75,13 @@
RubyRuntime.saveVMConfiguration();
assertEquals(
"XML should indicate both interpreters with the first one being selected.",
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings>\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"C:\\RubyInstallRootTwo\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"\" defaultVMConnector=\"\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"C:\\RubyInstallRootTwo\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
getVMsXML());
RubyRuntime.setSelectedInterpreter(standin2);
assertEquals(
"XML should indicate both interpreters with the first one being selected.",
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"" + RubyRuntime.getCompositeIdFromVM(standin2) + "\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"C:\\RubyInstallRootTwo\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"" + RubyRuntime.getCompositeIdFromVM(standin2) + "\" defaultVMConnector=\"\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"C:\\RubyInstallRootTwo\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
getVMsXML());
} finally {
vmType.disposeVMInstall("InterpreterOne");
Modified: trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TS_InternalLaunching.java
===================================================================
--- trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TS_InternalLaunching.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TS_InternalLaunching.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -6,8 +6,7 @@
public class TS_InternalLaunching {
public static Test suite() {
- TestSuite suite = new TestSuite();
-
+ TestSuite suite = new TestSuite("Internal Launching");
suite.addTestSuite(TC_RubyInterpreter.class);
suite.addTestSuite(TC_RubyRuntime.class);
suite.addTestSuite(TC_RunnerLaunching.class) ;
Modified: trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/launching/tests/TS_Launching.java
===================================================================
--- trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/launching/tests/TS_Launching.java 2007-01-18 21:47:02 UTC (rev 1805)
+++ trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/launching/tests/TS_Launching.java 2007-01-19 15:44:11 UTC (rev 1806)
@@ -8,7 +8,7 @@
public class TS_Launching {
public static Test suite() {
- TestSuite suite = new TestSuite();
+ TestSuite suite = new TestSuite("Launching");
suite.addTest(TS_InternalLaunching.suite());
return suite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|