| /******************************************************************************* |
| * Copyright (c) 2000, 2004 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.jdt.internal.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.DebugPlugin; |
| import org.eclipse.debug.core.ILaunch; |
| import org.eclipse.debug.core.ILaunchConfiguration; |
| 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; |
| |
| /** |
| * Launches a local VM. |
| */ |
| public class JavaLocalApplicationLaunchConfigurationDelegate extends AbstractJavaLaunchConfigurationDelegate { |
| |
| /* (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}...", new String[]{configuration.getName()}), 3); //$NON-NLS-1$ |
| // check for cancellation |
| if (monitor.isCanceled()) { |
| return; |
| } |
| |
| monitor.subTask(LaunchingMessages.getString("JavaLocalApplicationLaunchConfigurationDelegate.Verifying_launch_attributes..._1")); //$NON-NLS-1$ |
| |
| String mainTypeName = verifyMainTypeName(configuration); |
| |
| IVMInstall vm = verifyVMInstall(configuration); |
| |
| IVMRunner runner = vm.getVMRunner(mode); |
| if (runner == null) { |
| abort(MessageFormat.format(LaunchingMessages.getString("JavaLocalApplicationLaunchConfigurationDelegate.0"), new String[]{vm.getName(), mode}), null, IJavaLaunchConfigurationConstants.ERR_VM_RUNNER_DOES_NOT_EXIST); //$NON-NLS-1$ |
| } |
| |
| File workingDir = verifyWorkingDirectory(configuration); |
| String workingDirName = null; |
| if (workingDir != null) { |
| workingDirName = workingDir.getAbsolutePath(); |
| } |
| |
| // Environment variables |
| String[] envp= DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration); |
| |
| // Program & VM args |
| String pgmArgs = getProgramArguments(configuration); |
| String vmArgs = getVMArguments(configuration); |
| ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs); |
| |
| // VM-specific attributes |
| Map vmAttributesMap = getVMSpecificAttributesMap(configuration); |
| |
| // Classpath |
| String[] classpath = getClasspath(configuration); |
| |
| // Create VM config |
| VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, classpath); |
| runConfig.setProgramArguments(execArgs.getProgramArgumentsArray()); |
| runConfig.setEnvironment(envp); |
| runConfig.setVMArguments(execArgs.getVMArgumentsArray()); |
| runConfig.setWorkingDirectory(workingDirName); |
| runConfig.setVMSpecificAttributesMap(vmAttributesMap); |
| |
| // Bootpath |
| runConfig.setBootClassPath(getBootpath(configuration)); |
| |
| // check for cancellation |
| if (monitor.isCanceled()) { |
| return; |
| } |
| |
| // stop in main |
| prepareStopInMain(configuration); |
| |
| // done the verification phase |
| monitor.worked(1); |
| |
| monitor.subTask(LaunchingMessages.getString("JavaLocalApplicationLaunchConfigurationDelegate.Creating_source_locator..._2")); //$NON-NLS-1$ |
| // set the default source locator if required |
| setDefaultSourceLocator(launch, configuration); |
| monitor.worked(1); |
| |
| // Launch the configuration - 1 unit of work |
| runner.run(runConfig, launch, monitor); |
| |
| // check for cancellation |
| if (monitor.isCanceled()) { |
| return; |
| } |
| |
| monitor.done(); |
| } |
| } |
| |