KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > launching > JavaLaunchDelegate


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

11 package org.eclipse.jdt.launching;
12
13 import java.io.File JavaDoc;
14 import com.ibm.icu.text.MessageFormat;
15 import java.util.Map JavaDoc;
16
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.ILaunch;
21 import org.eclipse.debug.core.ILaunchConfiguration;
22 import org.eclipse.jdt.internal.launching.LaunchingMessages;
23
24 /**
25  * A launch delegate for launching local Java applications.
26  * <p>
27  * Clients may subclass and instantiate this class.
28  * </p>
29  * @since 3.1
30  */

31 public class JavaLaunchDelegate extends AbstractJavaLaunchConfigurationDelegate {
32
33     /* (non-Javadoc)
34      * @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)
35      */

36     public void launch(ILaunchConfiguration configuration, String JavaDoc mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
37         
38         if (monitor == null) {
39             monitor = new NullProgressMonitor();
40         }
41         
42         monitor.beginTask(MessageFormat.format("{0}...", new String JavaDoc[]{configuration.getName()}), 3); //$NON-NLS-1$
43
// check for cancellation
44
if (monitor.isCanceled()) {
45             return;
46         }
47         
48         monitor.subTask(LaunchingMessages.JavaLocalApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1);
49                         
50         String JavaDoc mainTypeName = verifyMainTypeName(configuration);
51         IVMRunner runner = getVMRunner(configuration, mode);
52
53         File JavaDoc workingDir = verifyWorkingDirectory(configuration);
54         String JavaDoc workingDirName = null;
55         if (workingDir != null) {
56             workingDirName = workingDir.getAbsolutePath();
57         }
58         
59         // Environment variables
60
String JavaDoc[] envp= getEnvironment(configuration);
61         
62         // Program & VM arguments
63
String JavaDoc pgmArgs = getProgramArguments(configuration);
64         String JavaDoc vmArgs = getVMArguments(configuration);
65         ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
66         
67         // VM-specific attributes
68
Map JavaDoc vmAttributesMap = getVMSpecificAttributesMap(configuration);
69         
70         // Classpath
71
String JavaDoc[] classpath = getClasspath(configuration);
72         
73         // Create VM config
74
VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, classpath);
75         runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
76         runConfig.setEnvironment(envp);
77         runConfig.setVMArguments(execArgs.getVMArgumentsArray());
78         runConfig.setWorkingDirectory(workingDirName);
79         runConfig.setVMSpecificAttributesMap(vmAttributesMap);
80
81         // Bootpath
82
runConfig.setBootClassPath(getBootpath(configuration));
83         
84         // check for cancellation
85
if (monitor.isCanceled()) {
86             return;
87         }
88         
89         // stop in main
90
prepareStopInMain(configuration);
91         
92         // done the verification phase
93
monitor.worked(1);
94         
95         monitor.subTask(LaunchingMessages.JavaLocalApplicationLaunchConfigurationDelegate_Creating_source_locator____2);
96         // set the default source locator if required
97
setDefaultSourceLocator(launch, configuration);
98         monitor.worked(1);
99         
100         // Launch the configuration - 1 unit of work
101
runner.run(runConfig, launch, monitor);
102         
103         // check for cancellation
104
if (monitor.isCanceled()) {
105             return;
106         }
107         
108         monitor.done();
109     }
110
111 }
112
Popular Tags