/******************************************************************************* * 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.io.File; import java.text.MessageFormat; 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.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.rubypeople.rdt.internal.launching.LaunchingMessages; /** * A launch delegate for launching local Ruby applications. * <p> * Clients may subclass and instantiate this class. * </p> * @since 0.9.0 */ public class RubyLaunchDelegate extends AbstractRubyLaunchConfigurationDelegate { /* (non-Javadoc) * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor) */ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.beginTask(MessageFormat.format("{0}...", configuration.getName()), 3); //$NON-NLS-1$ // check for cancellation if (monitor.isCanceled()) { return; } monitor.subTask(LaunchingMessages.JavaLocalApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1); String mainTypeName = verifyFileToLaunch(configuration); IVMRunner runner = getVMRunner(configuration, mode); File workingDir = verifyWorkingDirectory(configuration); String workingDirName = null; if (workingDir != null) { workingDirName = workingDir.getAbsolutePath(); } // Environment variables String[] envp= getEnvironment(configuration); // Program & VM arguments String pgmArgs = getProgramArguments(configuration); String vmArgs = getVMArguments(configuration); ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs); // VM-specific attributes Map vmAttributesMap = getVMSpecificAttributesMap(configuration); // Loadpath String[] loadpath = getLoadpath(configuration); boolean isSudo = getIsSudo(configuration); String sudoMessage = getSudoMessage(configuration); // Create VM config VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, loadpath); runConfig.setProgramArguments(execArgs.getProgramArgumentsArray()); runConfig.setEnvironment(envp); runConfig.setVMArguments(execArgs.getVMArgumentsArray()); runConfig.setWorkingDirectory(workingDirName); runConfig.setVMSpecificAttributesMap(vmAttributesMap); runConfig.setIsSudo(isSudo); runConfig.setSudoMessage(sudoMessage); // check for cancellation if (monitor.isCanceled()) { return; } // done the verification phase monitor.worked(1); monitor.subTask(LaunchingMessages.JavaLocalApplicationLaunchConfigurationDelegate_Creating_source_locator____2); // set the default source locator if required setDefaultSourceLocator(launch, configuration); Map configAttributes = configuration.getAttributes(); for (Object key : configAttributes.keySet()) { Object value = configAttributes.get(key); launch.setAttribute((String) key, value.toString()); } monitor.worked(1); // Launch the configuration - 1 unit of work runner.run(runConfig, launch, monitor); // check for cancellation if (monitor.isCanceled()) { return; } monitor.done(); } }