001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.launching;
011:
012: import java.io.File;
013: import com.ibm.icu.text.MessageFormat;
014: import java.util.Map;
015:
016: import org.eclipse.core.runtime.CoreException;
017: import org.eclipse.core.runtime.IProgressMonitor;
018: import org.eclipse.core.runtime.NullProgressMonitor;
019: import org.eclipse.debug.core.ILaunch;
020: import org.eclipse.debug.core.ILaunchConfiguration;
021: import org.eclipse.jdt.internal.launching.LaunchingMessages;
022:
023: /**
024: * A launch delegate for launching local Java applications.
025: * <p>
026: * Clients may subclass and instantiate this class.
027: * </p>
028: * @since 3.1
029: */
030: public class JavaLaunchDelegate extends
031: AbstractJavaLaunchConfigurationDelegate {
032:
033: /* (non-Javadoc)
034: * @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)
035: */
036: public void launch(ILaunchConfiguration configuration, String mode,
037: ILaunch launch, IProgressMonitor monitor)
038: throws CoreException {
039:
040: if (monitor == null) {
041: monitor = new NullProgressMonitor();
042: }
043:
044: monitor.beginTask(MessageFormat.format(
045: "{0}...", new String[] { configuration.getName() }), 3); //$NON-NLS-1$
046: // check for cancellation
047: if (monitor.isCanceled()) {
048: return;
049: }
050:
051: monitor
052: .subTask(LaunchingMessages.JavaLocalApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1);
053:
054: String mainTypeName = verifyMainTypeName(configuration);
055: IVMRunner runner = getVMRunner(configuration, mode);
056:
057: File workingDir = verifyWorkingDirectory(configuration);
058: String workingDirName = null;
059: if (workingDir != null) {
060: workingDirName = workingDir.getAbsolutePath();
061: }
062:
063: // Environment variables
064: String[] envp = getEnvironment(configuration);
065:
066: // Program & VM arguments
067: String pgmArgs = getProgramArguments(configuration);
068: String vmArgs = getVMArguments(configuration);
069: ExecutionArguments execArgs = new ExecutionArguments(vmArgs,
070: pgmArgs);
071:
072: // VM-specific attributes
073: Map vmAttributesMap = getVMSpecificAttributesMap(configuration);
074:
075: // Classpath
076: String[] classpath = getClasspath(configuration);
077:
078: // Create VM config
079: VMRunnerConfiguration runConfig = new VMRunnerConfiguration(
080: mainTypeName, classpath);
081: runConfig.setProgramArguments(execArgs
082: .getProgramArgumentsArray());
083: runConfig.setEnvironment(envp);
084: runConfig.setVMArguments(execArgs.getVMArgumentsArray());
085: runConfig.setWorkingDirectory(workingDirName);
086: runConfig.setVMSpecificAttributesMap(vmAttributesMap);
087:
088: // Bootpath
089: runConfig.setBootClassPath(getBootpath(configuration));
090:
091: // check for cancellation
092: if (monitor.isCanceled()) {
093: return;
094: }
095:
096: // stop in main
097: prepareStopInMain(configuration);
098:
099: // done the verification phase
100: monitor.worked(1);
101:
102: monitor
103: .subTask(LaunchingMessages.JavaLocalApplicationLaunchConfigurationDelegate_Creating_source_locator____2);
104: // set the default source locator if required
105: setDefaultSourceLocator(launch, configuration);
106: monitor.worked(1);
107:
108: // Launch the configuration - 1 unit of work
109: runner.run(runConfig, launch, monitor);
110:
111: // check for cancellation
112: if (monitor.isCanceled()) {
113: return;
114: }
115:
116: monitor.done();
117: }
118:
119: }
|