KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.internal.launching;
12
13
14 import java.io.File JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.NullProgressMonitor;
21 import org.eclipse.core.runtime.SubProgressMonitor;
22 import org.eclipse.debug.core.DebugPlugin;
23 import org.eclipse.debug.core.ILaunch;
24 import org.eclipse.debug.core.model.IProcess;
25 import org.eclipse.jdt.launching.IVMInstall;
26 import org.eclipse.jdt.launching.JavaRuntime;
27 import org.eclipse.jdt.launching.LibraryLocation;
28 import org.eclipse.jdt.launching.VMRunnerConfiguration;
29
30 /**
31  * A 1.1.x VM runner
32  */

33 public class Standard11xVMRunner extends StandardVMRunner {
34
35     public Standard11xVMRunner(IVMInstall vmInstance) {
36         super(vmInstance);
37     }
38
39     /* (non-Javadoc)
40      * @see org.eclipse.jdt.launching.IVMRunner#run(org.eclipse.jdt.launching.VMRunnerConfiguration, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
41      */

42     public void run(VMRunnerConfiguration config, ILaunch launch, IProgressMonitor monitor) throws CoreException {
43
44         if (monitor == null) {
45             monitor = new NullProgressMonitor();
46         }
47         
48         IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
49         subMonitor.beginTask(LaunchingMessages.StandardVMRunner_Launching_VM____1, 2);
50         subMonitor.subTask(LaunchingMessages.StandardVMRunner_Constructing_command_line____2); //
51

52         String JavaDoc program= constructProgramString(config);
53         
54         List JavaDoc arguments= new ArrayList JavaDoc();
55         arguments.add(program);
56                 
57         // VM args are the first thing after the java program so that users can specify
58
// options like '-client' & '-server' which are required to be the first option
59
String JavaDoc[] vmArgs= combineVmArgs(config, fVMInstance);
60         addArguments(vmArgs, arguments);
61                 
62         String JavaDoc[] bootCP= config.getBootClassPath();
63         String JavaDoc[] classPath = config.getClassPath();
64         
65         String JavaDoc[] combinedPath = null;
66         if (bootCP == null) {
67             LibraryLocation[] locs = JavaRuntime.getLibraryLocations(fVMInstance);
68             bootCP = new String JavaDoc[locs.length];
69             for (int i = 0; i < locs.length; i++) {
70                 bootCP[i] = locs[i].getSystemLibraryPath().toOSString();
71             }
72         }
73
74         combinedPath = new String JavaDoc[bootCP.length + classPath.length];
75         int offset = 0;
76         for (int i = 0; i < bootCP.length; i++) {
77             combinedPath[offset] = bootCP[i];
78             offset++;
79         }
80         for (int i = 0; i < classPath.length; i++) {
81             combinedPath[offset] = classPath[i];
82             offset++;
83         }
84         
85         if (combinedPath.length > 0) {
86             arguments.add("-classpath"); //$NON-NLS-1$
87
arguments.add(convertClassPath(combinedPath));
88         }
89         arguments.add(config.getClassToLaunch());
90         
91         String JavaDoc[] programArgs= config.getProgramArguments();
92         addArguments(programArgs, arguments);
93                 
94         String JavaDoc[] cmdLine= new String JavaDoc[arguments.size()];
95         arguments.toArray(cmdLine);
96
97         // check for cancellation
98
if (monitor.isCanceled()) {
99             return;
100         }
101         
102         subMonitor.worked(1);
103         subMonitor.subTask(LaunchingMessages.StandardVMRunner_Starting_virtual_machine____3);
104         
105         Process JavaDoc p= null;
106         File JavaDoc workingDir = getWorkingDir(config);
107         p= exec(cmdLine, workingDir);
108         if (p == null) {
109             return;
110         }
111         
112         // check for cancellation
113
if (monitor.isCanceled()) {
114             p.destroy();
115             return;
116         }
117         
118         IProcess process= DebugPlugin.newProcess(launch, p, renderProcessLabel(cmdLine));
119         process.setAttribute(IProcess.ATTR_CMDLINE, renderCommandLine(cmdLine));
120         subMonitor.worked(1);
121     }
122 }
123
124
Popular Tags