|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2002, 2005 IBM Corporation. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 7-120
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Lester Lopez (IBM Corp.) - Support latest version of JVM and Eclipse. |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.internal.launching.j9; |
12 |
package org.eclipse.jdt.internal.launching.j9; |
| 12 |
|
13 |
|
| 13 |
import java.io.File; |
14 |
import java.io.File; |
|
|
15 |
import java.io.FileNotFoundException; |
| 16 |
import java.io.IOException; |
| 17 |
import java.net.URL; |
| 14 |
import java.util.ArrayList; |
18 |
import java.util.ArrayList; |
|
|
19 |
import java.util.Arrays; |
| 15 |
import java.util.List; |
20 |
import java.util.List; |
|
|
21 |
import java.util.Locale; |
| 16 |
import java.util.Map; |
22 |
import java.util.Map; |
| 17 |
|
23 |
|
| 18 |
import org.eclipse.core.runtime.CoreException; |
24 |
import org.eclipse.core.runtime.CoreException; |
| 19 |
import org.eclipse.core.runtime.IProgressMonitor; |
25 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
|
26 |
import org.eclipse.core.runtime.IStatus; |
| 20 |
import org.eclipse.core.runtime.NullProgressMonitor; |
27 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 21 |
import org.eclipse.core.runtime.SubProgressMonitor; |
28 |
import org.eclipse.core.runtime.Platform; |
|
|
29 |
import org.eclipse.core.runtime.Status; |
| 30 |
import org.eclipse.debug.core.DebugPlugin; |
| 22 |
import org.eclipse.debug.core.ILaunch; |
31 |
import org.eclipse.debug.core.ILaunch; |
|
|
32 |
import org.eclipse.debug.core.IStatusHandler; |
| 23 |
import org.eclipse.debug.core.model.IProcess; |
33 |
import org.eclipse.debug.core.model.IProcess; |
|
|
34 |
import org.eclipse.debug.internal.core.DebugCoreMessages; |
| 24 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
35 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
| 25 |
import org.eclipse.jdt.launching.IVMInstall; |
36 |
import org.eclipse.jdt.launching.IVMInstall; |
|
|
37 |
import org.eclipse.jdt.launching.LibraryLocation; |
| 26 |
import org.eclipse.jdt.launching.VMRunnerConfiguration; |
38 |
import org.eclipse.jdt.launching.VMRunnerConfiguration; |
|
|
39 |
import org.eclipse.jdt.launching.j9.J9Launching; |
| 40 |
import org.eclipse.jdt.launching.j9.J9VMOptionsParser; |
| 27 |
|
41 |
|
| 28 |
public class J9VMRunner extends JavaVMRunner { |
42 |
public class J9VMRunner extends JavaVMRunner { |
| 29 |
|
43 |
// boolean DEBUG; |
|
|
44 |
// private static J9LaunchingPlugin plugin; |
| 45 |
|
| 30 |
public J9VMRunner(IVMInstall vmInstance) { |
46 |
public J9VMRunner(IVMInstall vmInstance) { |
| 31 |
super(vmInstance); |
47 |
super(vmInstance); |
|
|
48 |
|
| 49 |
// String dprop = System.getProperty("debug"); |
| 50 |
// if ( (dprop != null) && (dprop.equals("true"))) { |
| 51 |
// DEBUG = true; |
| 52 |
// } |
| 32 |
} |
53 |
} |
| 33 |
|
54 |
|
| 34 |
/** |
55 |
public String[] getCmdLine(int port, int debugServerPort, String debugHost, |
| 35 |
* @see org.eclipse.jdt.launching.IVMRunner#run(VMRunnerConfiguration, ILaunch, IProgressMonitor) |
56 |
VMRunnerConfiguration config) throws CoreException { |
| 36 |
*/ |
57 |
String location = getJDKLocation(); |
| 37 |
public void run(VMRunnerConfiguration config, ILaunch launch, IProgressMonitor monitor) throws CoreException { |
|
|
| 38 |
|
| 39 |
if (monitor == null) { |
| 40 |
monitor = new NullProgressMonitor(); |
| 41 |
} |
| 42 |
|
| 43 |
// check for cancellation |
| 44 |
if (monitor.isCanceled()) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1); |
| 49 |
subMonitor.beginTask(J9LauncherMessages.getString("J9VMRunner.Launching_virtual_machine..._1"), 2); //$NON-NLS-1$ |
| 50 |
subMonitor.subTask(J9LauncherMessages.getString("J9VMRunner.Constructing_command_line..._2")); //$NON-NLS-1$ |
| 51 |
|
| 52 |
File workingDir = getWorkingDir(config); |
| 53 |
String location= getJDKLocation(); |
| 54 |
String program = constructProgramString(location, config); |
58 |
String program = constructProgramString(location, config); |
| 55 |
List arguments= new ArrayList(); |
59 |
List arguments = new ArrayList(); |
| 56 |
|
60 |
|
| 57 |
arguments.add(program); |
61 |
arguments.add(program); |
|
|
62 |
|
| 63 |
String[] bootCP = config.getBootClassPath(); |
| 64 |
String[] cp = config.getClassPath(); |
| 65 |
String[] vmArgs = config.getVMArguments(); |
| 66 |
String[] programArgs = config.getProgramArguments(); |
| 67 |
|
| 58 |
|
68 |
|
| 59 |
arguments.add("-jit"); //$NON-NLS-1$ |
69 |
// 12-08-05 cf Commented out for J2 options |
| 60 |
|
70 |
// Set up the the bootclasspath |
| 61 |
addBootClassPathArguments(arguments, config); |
71 |
// if (bootCP != null) { |
|
|
72 |
// String bootpathOpt = isOldJ9Version() ? "-bp:" : "-Xbootclasspath:"; |
| 73 |
// //$NON-NLS-1$ //$NON-NLS-2$ |
| 74 |
// if (bootCP.length > 0) { |
| 75 |
// arguments.add(bootpathOpt+convertClassPath(bootCP)); |
| 76 |
// } else { |
| 77 |
// // empty |
| 78 |
// arguments.add(bootpathOpt); |
| 79 |
// } |
| 80 |
// } |
| 62 |
|
81 |
|
| 63 |
String[] cp= config.getClassPath(); |
|
|
| 64 |
if (cp.length > 0) { |
82 |
if (cp.length > 0) { |
| 65 |
arguments.add("-classpath"); //$NON-NLS-1$ |
83 |
arguments.add("-classpath"); //$NON-NLS-1$ |
| 66 |
arguments.add(convertClassPath(cp)); |
84 |
arguments.add(convertClassPath(cp)); |
| 67 |
} |
85 |
} |
| 68 |
String[] vmArgs= config.getVMArguments(); |
86 |
|
|
|
87 |
if (port != -1) { |
| 88 |
if (isNewJ9Version()) { |
| 89 |
arguments |
| 90 |
.add("-Xrunjdwp:transport=dt_socket,address=" + debugHost + ":" + port); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 91 |
arguments.add("-Xdebug"); //$NON-NLS-1$ |
| 92 |
if (debugServerPort != -1) { |
| 93 |
arguments |
| 94 |
.add("-Xrdbginfo:" + debugHost + ":" + debugServerPort); //$NON-NLS-1$ //$NON-NLS-2$ |
| 95 |
} |
| 96 |
} else { |
| 97 |
arguments.add("-debug:" + port); //$NON-NLS-1$ |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 69 |
addArguments(vmArgs, arguments); |
101 |
addArguments(vmArgs, arguments); |
| 70 |
|
102 |
|
| 71 |
arguments.add(config.getClassToLaunch()); |
103 |
String classToLaunch = config.getClassToLaunch(); |
| 72 |
|
104 |
if (classToLaunch.length() > 0) { |
| 73 |
String[] programArgs= config.getProgramArguments(); |
105 |
arguments.add(classToLaunch); |
|
|
106 |
} |
| 107 |
|
| 74 |
addArguments(programArgs, arguments); |
108 |
addArguments(programArgs, arguments); |
| 75 |
|
109 |
|
| 76 |
String[] cmdLine= new String[arguments.size()]; |
110 |
String[] cmdLine = new String[arguments.size()]; |
| 77 |
arguments.toArray(cmdLine); |
111 |
arguments.toArray(cmdLine); |
| 78 |
|
112 |
|
| 79 |
String[] envp= config.getEnvironment(); |
113 |
return cmdLine; |
| 80 |
|
114 |
} |
|
|
115 |
|
| 116 |
public void addVMOptionsFromRules(VMRunnerConfiguration config) |
| 117 |
throws CoreException { |
| 118 |
List additionalOptions = extractVMOptionsFromRules(config); |
| 119 |
if (additionalOptions.size() > 0) { |
| 120 |
List newArgList = new ArrayList(); |
| 121 |
newArgList.addAll(additionalOptions); |
| 122 |
newArgList.addAll(Arrays.asList(config.getVMArguments())); |
| 123 |
String[] newVmArgs = (String[]) newArgList |
| 124 |
.toArray(new String[newArgList.size()]); |
| 125 |
config.setVMArguments(newVmArgs); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
public void addJitArgumentWhenNotDefault(VMRunnerConfiguration config) |
| 130 |
throws CoreException { |
| 131 |
if (isOldJ9Version()) { |
| 132 |
if (!containsOption(config.getVMArguments(), "-jit")) { //$NON-NLS-1$ |
| 133 |
List newArgList = new ArrayList(); |
| 134 |
newArgList.add("-jit"); //$NON-NLS-1$ |
| 135 |
newArgList.addAll(Arrays.asList(config.getVMArguments())); |
| 136 |
String[] newVmArgs = (String[]) newArgList |
| 137 |
.toArray(new String[newArgList.size()]); |
| 138 |
config.setVMArguments(newVmArgs); |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
protected J9VMInstall getJ9VMInstall() { |
| 144 |
return (J9VMInstall) fVMInstance; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* @see org.eclipse.jdt.launching.IVMRunner#run(VMRunnerConfiguration, |
| 149 |
* ILaunch, IProgressMonitor) |
| 150 |
*/ |
| 151 |
public void run(VMRunnerConfiguration config, ILaunch launch, |
| 152 |
IProgressMonitor monitor) throws CoreException { |
| 153 |
|
| 154 |
if (monitor == null) { |
| 155 |
monitor = new NullProgressMonitor(); |
| 156 |
} |
| 157 |
|
| 81 |
// check for cancellation |
158 |
// check for cancellation |
| 82 |
if (monitor.isCanceled()) { |
159 |
if (monitor.isCanceled()) { |
| 83 |
return; |
160 |
return; |
| 84 |
} |
161 |
} |
| 85 |
|
162 |
|
| 86 |
subMonitor.worked(1); |
163 |
// Add -jit argument for old VMs |
| 87 |
subMonitor.subTask(J9LauncherMessages.getString("J9VMRunner.Starting_virtual_machine..._3")); //$NON-NLS-1$ |
164 |
addJitArgumentWhenNotDefault(config); |
| 88 |
|
165 |
|
| 89 |
Process p= exec(cmdLine, workingDir, envp); |
166 |
// Convert configuration to use -jxe option if requested. |
|
|
167 |
config = J9Launching.adaptVMRunnerConfiguration(config, |
| 168 |
getJ9VMInstall()); |
| 169 |
|
| 170 |
// Add VM options extracted from rules found on the bootclasspath |
| 171 |
addVMOptionsFromRules(config); |
| 172 |
|
| 173 |
String[] cmdLine = getCmdLine(-1, -1, null, config); |
| 174 |
File workingDir = getWorkingDir(config); |
| 175 |
|
| 176 |
// Added plugin tracing, this can be activated in the Run-time Workspace |
| 177 |
if (J9LaunchingPlugin.getDefault().isDebugging()) { |
| 178 |
// Display the command line args in the Console |
| 179 |
System.out.println("Command Line Args:"); |
| 180 |
for (int i = 0; i < cmdLine.length; i++) { |
| 181 |
// If it starts with "-", it's an option so join it to the next |
| 182 |
// string. |
| 183 |
if ((cmdLine[i].startsWith("-classpath")) ||(cmdLine[i].startsWith("-cp")) ) { |
| 184 |
String tStr = cmdLine[i++].toString(); |
| 185 |
if (!cmdLine[i].startsWith("-")) { |
| 186 |
System.out.println("\t" + tStr + " " |
| 187 |
+ cmdLine[i].toString()); |
| 188 |
} else { |
| 189 |
System.out.println("\t" + tStr); |
| 190 |
System.out.println("\t" + cmdLine[i].toString()); |
| 191 |
} |
| 192 |
} else { |
| 193 |
System.out.println("\t" + cmdLine[i].toString()); |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
// check for cancellation |
| 199 |
if (monitor.isCanceled()) { |
| 200 |
return; |
| 201 |
} |
| 202 |
|
| 203 |
Process p = exec(cmdLine, workingDir); |
| 90 |
if (p != null) { |
204 |
if (p != null) { |
| 91 |
IProcess process= newProcess(launch, p, renderProcessLabel(cmdLine), getDefaultProcessMap()); |
205 |
IProcess process = DebugPlugin.newProcess(launch, p, J9Launching |
| 92 |
process.setAttribute(IProcess.ATTR_CMDLINE, renderCommandLine(cmdLine)); |
206 |
.renderProcessLabel(cmdLine)); |
|
|
207 |
process.setAttribute(IProcess.ATTR_CMDLINE, J9Launching |
| 208 |
.renderCommandLine(cmdLine)); |
| 93 |
} |
209 |
} |
| 94 |
subMonitor.worked(1); |
|
|
| 95 |
subMonitor.done(); |
| 96 |
} |
210 |
} |
| 97 |
|
211 |
|
| 98 |
protected String constructProgramString(String location, VMRunnerConfiguration config) { |
212 |
/** |
| 99 |
String command= null; |
213 |
* Launch the VM. If the OS is Linux, you must set teh LD_LIBRARY_PATH |
| 100 |
Map map= config.getVMSpecificAttributesMap(); |
214 |
* environment variable to {ive}\bin prior to launch. NOTE! This may cause |
|
|
215 |
* some expectations to break. There is no way from within Java to get the |
| 216 |
* environment variables used to launch your VM so there is no way to simply |
| 217 |
* append LD_LIBRARY_PATH to the environment variables. This code will |
| 218 |
* replace them with that variable. See Bug 98297 for further discussions. |
| 219 |
*/ |
| 220 |
protected Process exec(String[] cmdLine, File workingDirectory) |
| 221 |
throws CoreException { |
| 222 |
String[] env = null; |
| 223 |
try { |
| 224 |
//Defect 99510- modified by Sri! -start |
| 225 |
//On Linux systems, AWT apps seem to need these 3 environment |
| 226 |
// variables to run. |
| 227 |
// So we use the env to get these and if env is not set on systems |
| 228 |
// then use the |
| 229 |
// java environment (using properties to get the same and as a third |
| 230 |
// option use default values. |
| 231 |
String osName = System.getProperty("os.name"); //$NON-NLS-1$ |
| 232 |
if (osName != null) { |
| 233 |
osName = osName.toLowerCase(); |
| 234 |
if (osName.indexOf("linux") != -1) { //$NON-NLS-1$ |
| 235 |
|
| 236 |
//Get the LD_LIBRARY_PATH value |
| 237 |
String libPath = getJ9VMInstall().getInstallLocation() |
| 238 |
.getAbsolutePath() |
| 239 |
+ File.separator + "bin"; |
| 240 |
|
| 241 |
//execute env to get the environment for HOME and DISPLAY |
| 242 |
String homeEnv = null; |
| 243 |
String dispEnv = null; |
| 244 |
String localeEnv = null; |
| 245 |
String gdmlangEnv = null; |
| 246 |
String lppathEnv = null; |
| 247 |
try { |
| 248 |
|
| 249 |
java.util.Properties prop = new java.util.Properties(); |
| 250 |
prop.load(Runtime.getRuntime().exec("env") |
| 251 |
.getInputStream()); |
| 252 |
homeEnv = (String) prop.get("HOME"); |
| 253 |
dispEnv = (String) prop.get("DISPLAY"); |
| 254 |
localeEnv = (String) prop.get("LANG"); |
| 255 |
gdmlangEnv = (String) prop.get("GDM_LANG"); |
| 256 |
lppathEnv = (String) prop.get("LD_LIBRARY_PATH"); |
| 257 |
|
| 258 |
} catch (IOException e) { |
| 259 |
} |
| 260 |
|
| 261 |
//env is not set on system, use the java environment |
| 262 |
if (homeEnv == null) { |
| 263 |
try { |
| 264 |
homeEnv = System.getProperty("user.home"); |
| 265 |
} catch (SecurityException e) { |
| 266 |
} |
| 267 |
}//homeEnv |
| 268 |
|
| 269 |
//if at this point we don't have proper values, give |
| 270 |
// default values |
| 271 |
if (homeEnv == null) |
| 272 |
homeEnv = "/root"; |
| 273 |
if (dispEnv == null) |
| 274 |
dispEnv = ":0"; |
| 275 |
if (localeEnv == null) |
| 276 |
localeEnv = Locale.getDefault().toString(); |
| 277 |
if (gdmlangEnv == null) |
| 278 |
gdmlangEnv = localeEnv + ".UTF-8"; //uses format |
| 279 |
// en_US.UTF-8 |
| 280 |
|
| 281 |
// Make environment list |
| 282 |
env = new String[] { |
| 283 |
"LD_LIBRARY_PATH=" + libPath + ":" + lppathEnv, |
| 284 |
"HOME=" + homeEnv, "LANG=" + localeEnv, |
| 285 |
"GDM_LANG=" + gdmlangEnv, "DISPLAY=" + dispEnv }; |
| 286 |
|
| 287 |
}//linux specific |
| 288 |
|
| 289 |
} |
| 290 |
} catch (Exception e) { |
| 291 |
} |
| 292 |
//Defect 99510- modified by Sri! - end |
| 293 |
return exec(cmdLine, env, workingDirectory); |
| 294 |
} |
| 295 |
|
| 296 |
/** |
| 297 |
* The version process method needs to use the LD_LIBRARY_PATH fix as well. |
| 298 |
* |
| 299 |
* @return |
| 300 |
* @throws IOException |
| 301 |
*/ |
| 302 |
public Process getVersionProcess() throws IOException { |
| 303 |
VMRunnerConfiguration config = new VMRunnerConfiguration( |
| 304 |
"", new String[] {}); //$NON-NLS-1$ |
| 305 |
String JDKLocation = getJDKLocation(); |
| 306 |
String j9Command = constructProgramString(JDKLocation, config); |
| 307 |
|
| 308 |
// String versionCommand[] = { j9Command, "-version" }; //$NON-NLS-1$ |
| 309 |
|
| 310 |
List arguments = new ArrayList(); |
| 311 |
|
| 312 |
arguments.add(j9Command); |
| 313 |
|
| 314 |
J9VMInstallType j9VMInstallType = (J9VMInstallType) getJ9VMInstall() |
| 315 |
.getVMInstallType(); |
| 316 |
LibraryLocation[] libraryLocation = j9VMInstallType |
| 317 |
.getDefaultLibraryLocations(new File(JDKLocation)); |
| 318 |
|
| 319 |
if (libraryLocation != null) { |
| 320 |
String bootpathOpt = "-Xbootclasspath:"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 321 |
if (libraryLocation.length > 0) { |
| 322 |
arguments.add(bootpathOpt + convertClassPath(libraryLocation)); |
| 323 |
} else { |
| 324 |
// empty |
| 325 |
arguments.add(bootpathOpt); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
String cp = null; |
| 330 |
|
| 331 |
/* |
| 332 |
* LL: Migration to 3.0: getDescriptor().getInstallURL() are both now |
| 333 |
* deprecated. |
| 334 |
*/ |
| 335 |
URL pluginURL = J9LaunchingPlugin.getDefault().getBundle() |
| 336 |
.getEntry("/"); |
| 337 |
/* |
| 338 |
* LL: 108345: Check for existence of jar file. If it doesn't exist, |
| 339 |
* assume it is a runtime workbench and look for the bin folder then. |
| 340 |
* Note that we are harcoding the name of the output folder to bin. This |
| 341 |
* is not necessarily true since it can be configured. |
| 342 |
*/ |
| 343 |
URL newURL = null; |
| 344 |
|
| 345 |
try { |
| 346 |
newURL = Platform.resolve(new URL(pluginURL + "j9launching.jar")); |
| 347 |
} catch (FileNotFoundException e) { |
| 348 |
newURL = Platform.resolve(new URL(pluginURL + "bin")); |
| 349 |
} |
| 350 |
|
| 351 |
if (newURL != null && newURL.getProtocol().equals("file")) { |
| 352 |
cp = newURL.getFile().replace('/', File.separatorChar); |
| 353 |
arguments.add("-classpath"); //$NON-NLS-1$ |
| 354 |
arguments.add(cp); |
| 355 |
} |
| 356 |
arguments.add("-jcl:foun10"); |
| 357 |
arguments.add("org.eclipse.jdt.internal.launching.j9.J9VMVersion"); |
| 358 |
String[] cmdLine = new String[arguments.size()]; |
| 359 |
arguments.toArray(cmdLine); |
| 360 |
|
| 361 |
try { |
| 362 |
//return exec(versionCommand, null); |
| 363 |
return exec(cmdLine, null); |
| 364 |
} catch (CoreException e) { |
| 365 |
// since we use a copy of the DebugPluging.exec to launch this, |
| 366 |
// we'll need to worry about CoreExceptions, not IOExceptions. |
| 367 |
// However, if we DO catch a CoreException chances are it's been |
| 368 |
// caused by an IOException. Try to extract and rethrow such a |
| 369 |
// beast. Otherwise create and throw a new one. |
| 370 |
Throwable t = e.getStatus().getException(); |
| 371 |
if (t instanceof IOException) { |
| 372 |
throw (IOException) t; |
| 373 |
} else { |
| 374 |
throw new IOException(); |
| 375 |
} |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
/** |
| 380 |
* Copy of DebugPlugin.exec() that supports environment variables. |
| 381 |
* |
| 382 |
* @param cmdLine |
| 383 |
* @param env |
| 384 |
* @param workingDirectory |
| 385 |
* @return |
| 386 |
* @throws CoreException |
| 387 |
*/ |
| 388 |
public static Process exec(String[] cmdLine, String[] env, |
| 389 |
File workingDirectory) throws CoreException { |
| 390 |
Process p = null; |
| 391 |
try { |
| 392 |
if (workingDirectory == null) { |
| 393 |
p = Runtime.getRuntime().exec(cmdLine, env); |
| 394 |
} else { |
| 395 |
p = Runtime.getRuntime().exec(cmdLine, env, workingDirectory); |
| 396 |
} |
| 397 |
} catch (IOException e) { |
| 398 |
if (p != null) { |
| 399 |
p.destroy(); |
| 400 |
} |
| 401 |
Status status = new Status( |
| 402 |
IStatus.ERROR, |
| 403 |
DebugPlugin.getUniqueIdentifier(), |
| 404 |
DebugPlugin.INTERNAL_ERROR, |
| 405 |
DebugCoreMessages.DebugPlugin_Exception_occurred_executing_command_line__1, e); //$NON-NLS-1$ |
| 406 |
throw new CoreException(status); |
| 407 |
} catch (NoSuchMethodError e) { |
| 408 |
//attempting launches on 1.2.* - no ability to set working |
| 409 |
// directory |
| 410 |
IStatus status = new Status( |
| 411 |
IStatus.ERROR, |
| 412 |
DebugPlugin.getUniqueIdentifier(), |
| 413 |
DebugPlugin.ERR_WORKING_DIRECTORY_NOT_SUPPORTED, |
| 414 |
DebugCoreMessages.DebugPlugin_Eclipse_runtime_does_not_support_working_directory_2, e); //$NON-NLS-1$ |
| 415 |
IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler( |
| 416 |
status); |
| 417 |
|
| 418 |
if (handler != null) { |
| 419 |
Object result = handler.handleStatus(status, null); |
| 420 |
if (result instanceof Boolean |
| 421 |
&& ((Boolean) result).booleanValue()) { |
| 422 |
p = exec(cmdLine, env, null); |
| 423 |
} |
| 424 |
} |
| 425 |
} |
| 426 |
return p; |
| 427 |
} |
| 428 |
|
| 429 |
protected String constructProgramString(String location, |
| 430 |
VMRunnerConfiguration config) { |
| 431 |
String command = null; |
| 432 |
Map map = config.getVMSpecificAttributesMap(); |
| 101 |
if (map != null) { |
433 |
if (map != null) { |
| 102 |
command= (String)map.get(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND); |
434 |
command = (String) map |
|
|
435 |
.get(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND); |
| 103 |
} |
436 |
} |
| 104 |
|
437 |
|
| 105 |
StringBuffer program= new StringBuffer(); |
438 |
StringBuffer program = new StringBuffer(); |
| 106 |
program.append(location).append(File.separator).append("bin").append(File.separator); //$NON-NLS-1$ |
439 |
program.append(location).append(File.separator) |
| 107 |
int directoryLength= program.length(); |
440 |
.append("bin").append(File.separator); //$NON-NLS-1$ |
| 108 |
if (command == null) { |
441 |
if (command == null) { |
|
|
442 |
int directoryLength = program.length(); |
| 109 |
program.append("j9w.exe"); //$NON-NLS-1$ |
443 |
program.append("j9w.exe"); //$NON-NLS-1$ |
| 110 |
File j9w= new File(program.toString()); |
444 |
File j9w = new File(program.toString()); |
|
|
445 |
|
| 446 |
boolean localMachine = false; |
| 447 |
if (location != null) { |
| 448 |
if (location.indexOf("\\win32\\") != -1) // if win32 is in the |
| 449 |
// path I am local |
| 450 |
localMachine = true; |
| 451 |
else if (location.indexOf("\\linux\\") != -1) // if linux is in |
| 452 |
// the path I am |
| 453 |
// local |
| 454 |
localMachine = true; |
| 455 |
else if (location.indexOf("\\runtimes\\") == -1) // if runtimes |
| 456 |
// is not in |
| 457 |
// the path, I |
| 458 |
// am local |
| 459 |
localMachine = true; |
| 460 |
} |
| 111 |
if (!j9w.exists()) { |
461 |
if (!j9w.exists()) { |
| 112 |
program.replace(directoryLength, program.length(), "j9"); //$NON-NLS-1$ |
462 |
program.replace(directoryLength, program.length(), "j9"); //$NON-NLS-1$ |
| 113 |
} |
463 |
} |
|
|
464 |
// only check to see if runAsConsole is set for platforms that are |
| 465 |
// not emulator/local platforms |
| 466 |
if (!localMachine && J9Launching.runAsConsole(map)) |
| 467 |
program.replace(directoryLength, program.length(), "j9"); //$NON-NLS-1$ |
| 114 |
} else { |
468 |
} else { |
| 115 |
program.append(command); |
469 |
program.append(command); |
| 116 |
} |
470 |
} |
| 117 |
|
471 |
|
| 118 |
return program.toString(); |
472 |
return program.toString(); |
| 119 |
} |
473 |
} |
| 120 |
} |
474 |
|
|
|
475 |
protected boolean shouldIncludeInPath(String path) { |
| 476 |
return true; |
| 477 |
} |
| 478 |
|
| 479 |
protected String convertClassPath(String[] cp) { |
| 480 |
int pathCount = 0; |
| 481 |
StringBuffer buf = new StringBuffer(); |
| 482 |
for (int i = 0; i < cp.length; i++) { |
| 483 |
if (pathCount > 0) { |
| 484 |
buf.append(File.pathSeparator); |
| 485 |
} |
| 486 |
buf.append(cp[i]); |
| 487 |
pathCount++; |
| 488 |
} |
| 489 |
return buf.toString(); |
| 490 |
} |
| 491 |
|
| 492 |
protected String convertClassPath(LibraryLocation[] cp) { |
| 493 |
int pathCount = 0; |
| 494 |
StringBuffer buf = new StringBuffer(); |
| 495 |
for (int i = 0; i < cp.length; i++) { |
| 496 |
if (pathCount > 0) { |
| 497 |
buf.append(File.pathSeparator); |
| 498 |
} |
| 499 |
buf.append(cp[i].getSystemLibraryPath()); |
| 500 |
pathCount++; |
| 501 |
} |
| 502 |
return buf.toString(); |
| 503 |
} |
| 504 |
|
| 505 |
protected boolean isOldJ9Version() throws CoreException { |
| 506 |
return ((J9VMInstall) fVMInstance).isPre20J9Version(); |
| 507 |
} |
| 508 |
|
| 509 |
protected boolean isNewJ9Version() throws CoreException { |
| 510 |
return ((J9VMInstall) fVMInstance).is21J9Version(); |
| 511 |
} |
| 512 |
|
| 513 |
public List extractVMOptionsFromRules(VMRunnerConfiguration config) |
| 514 |
throws CoreException { |
| 515 |
String[] bootCP = config.getBootClassPath(); |
| 516 |
String[] vmArgs = config.getVMArguments(); |
| 517 |
String optionName = extractOptionName(config.getClassToLaunch()); |
| 518 |
// When executing using -jar, the jar is not on the boot path |
| 519 |
boolean executeFromArchive = optionName.equalsIgnoreCase("jxe") || //$NON-NLS-1$ |
| 520 |
containsOption(vmArgs, "-jxe"); //$NON-NLS-1$ |
| 521 |
|
| 522 |
// When using default bootclaspath, make sure that the libraries |
| 523 |
// on the default bootclasspath are searched for rules |
| 524 |
if (bootCP == null && !executeFromArchive) { |
| 525 |
LibraryLocation libraries[] = fVMInstance.getLibraryLocations(); |
| 526 |
if (libraries == null) { |
| 527 |
libraries = fVMInstance.getVMInstallType() |
| 528 |
.getDefaultLibraryLocations( |
| 529 |
fVMInstance.getInstallLocation()); |
| 530 |
} |
| 531 |
bootCP = new String[libraries.length]; |
| 532 |
for (int i = 0; i < libraries.length; i++) { |
| 533 |
bootCP[i] = libraries[i].getSystemLibraryPath().toOSString(); |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
ArrayList result = new ArrayList(); |
| 538 |
if (bootCP != null) { |
| 539 |
for (int i = 0; i < bootCP.length; i++) { |
| 540 |
result.addAll(J9VMOptionsParser.extractVMOptions(bootCP[i])); |
| 541 |
} |
| 542 |
|
| 543 |
for (int j = result.size() - 1; j >= 0; j--) { |
| 544 |
String option = (String) result.get(j); |
| 545 |
if (containsOption(vmArgs, option)) { |
| 546 |
result.remove(j); |
| 547 |
} |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
return result; |
| 552 |
} |
| 553 |
|
| 554 |
private static boolean containsOption(String[] vmArgs, String option) { |
| 555 |
String optionName = extractOptionName(option); |
| 556 |
for (int i = 0; i < vmArgs.length; i++) { |
| 557 |
if (extractOptionName(vmArgs[i]).equalsIgnoreCase(optionName)) { |
| 558 |
return true; |
| 559 |
} |
| 560 |
} |
| 561 |
return false; |
| 562 |
} |
| 563 |
|
| 564 |
public static String extractOptionName(String option) { |
| 565 |
if (option.startsWith("-no")) { //$NON-NLS-1$ |
| 566 |
option = option.substring(3); |
| 567 |
} else if (option.startsWith("-")) { //$NON-NLS-1$ |
| 568 |
option = option.substring(1); |
| 569 |
} else { |
| 570 |
return ""; //$NON-NLS-1$ |
| 571 |
} |
| 572 |
int p = option.indexOf(':'); |
| 573 |
if (p == -1) |
| 574 |
p = option.indexOf(' '); |
| 575 |
return p == -1 ? option : option.substring(0, p); |
| 576 |
} |
| 577 |
|
| 578 |
/** |
| 579 |
* Tests whether the current execution is a runtime workbench. |
| 580 |
* |
| 581 |
* @return true if the current execution is a runtime workbench, otherwise |
| 582 |
* false. |
| 583 |
*/ |
| 584 |
public static boolean isRunTimeWorkBench() { |
| 585 |
String[] sCmdList = Platform.getCommandLineArgs(); |
| 586 |
|
| 587 |
for (int iCount = 0; iCount < sCmdList.length; iCount++) { |
| 588 |
/* |
| 589 |
* LL: -pdelaunch is passed as a command line argument when running |
| 590 |
* a runtime-workbench. |
| 591 |
*/ |
| 592 |
if (sCmdList[iCount].toString().equalsIgnoreCase("-pdelaunch")) { |
| 593 |
return true; |
| 594 |
} |
| 595 |
} |
| 596 |
return false; |
| 597 |
} //isRunTimeWorkBench |
| 598 |
} |