KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > launching > JavaLocalApplicationLaunchConfigurationDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.launching;
12
13
14 import java.io.File JavaDoc;
15 import java.text.MessageFormat JavaDoc;
16 import java.util.Map JavaDoc;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.NullProgressMonitor;
20 import org.eclipse.debug.core.DebugPlugin;
21 import org.eclipse.debug.core.ILaunch;
22 import org.eclipse.debug.core.ILaunchConfiguration;
23 import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate;
24 import org.eclipse.jdt.launching.ExecutionArguments;
25 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
26 import org.eclipse.jdt.launching.IVMInstall;
27 import org.eclipse.jdt.launching.IVMRunner;
28 import org.eclipse.jdt.launching.VMRunnerConfiguration;
29
30 /**
31  * Launches a local VM.
32  */

33 public class JavaLocalApplicationLaunchConfigurationDelegate extends AbstractJavaLaunchConfigurationDelegate {
34
35     /* (non-Javadoc)
36      * @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)
37      */

38     public void launch(ILaunchConfiguration configuration, String JavaDoc mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
39         
40         if (monitor == null) {
41             monitor = new NullProgressMonitor();
42         }
43         
44         monitor.beginTask(MessageFormat.format("{0}...", new String JavaDoc[]{configuration.getName()}), 3); //$NON-NLS-1$
45
// check for cancellation
46
if (monitor.isCanceled()) {
47             return;
48         }
49         
50         monitor.subTask(LaunchingMessages.getString("JavaLocalApplicationLaunchConfigurationDelegate.Verifying_launch_attributes..._1")); //$NON-NLS-1$
51

52         String JavaDoc mainTypeName = verifyMainTypeName(configuration);
53
54         IVMInstall vm = verifyVMInstall(configuration);
55
56         IVMRunner runner = vm.getVMRunner(mode);
57         if (runner == null) {
58             abort(MessageFormat.format(LaunchingMessages.getString("JavaLocalApplicationLaunchConfigurationDelegate.0"), new String JavaDoc[]{vm.getName(), mode}), null, IJavaLaunchConfigurationConstants.ERR_VM_RUNNER_DOES_NOT_EXIST); //$NON-NLS-1$
59
}
60
61         File JavaDoc workingDir = verifyWorkingDirectory(configuration);
62         String JavaDoc workingDirName = null;
63         if (workingDir != null) {
64             workingDirName = workingDir.getAbsolutePath();
65         }
66         
67         // Environment variables
68
String JavaDoc[] envp= DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);
69         
70         // Program & VM args
71
String JavaDoc pgmArgs = getProgramArguments(configuration);
72         String JavaDoc vmArgs = getVMArguments(configuration);
73         ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
74         
75         // VM-specific attributes
76
Map JavaDoc vmAttributesMap = getVMSpecificAttributesMap(configuration);
77         
78         // Classpath
79
String JavaDoc[] classpath = getClasspath(configuration);
80         
81         // Create VM config
82
VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, classpath);
83         runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
84         runConfig.setEnvironment(envp);
85         runConfig.setVMArguments(execArgs.getVMArgumentsArray());
86         runConfig.setWorkingDirectory(workingDirName);
87         runConfig.setVMSpecificAttributesMap(vmAttributesMap);
88
89         // Bootpath
90
runConfig.setBootClassPath(getBootpath(configuration));
91         
92         // check for cancellation
93
if (monitor.isCanceled()) {
94             return;
95         }
96         
97         // stop in main
98
prepareStopInMain(configuration);
99         
100         // done the verification phase
101
monitor.worked(1);
102         
103         monitor.subTask(LaunchingMessages.getString("JavaLocalApplicationLaunchConfigurationDelegate.Creating_source_locator..._2")); //$NON-NLS-1$
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
120
Popular Tags