Line 0
Link Here
|
|
|
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.core.tests.runtime; |
12 |
|
13 |
import java.io.File; |
14 |
import java.util.Vector; |
15 |
/** |
16 |
* This is a new vm launcher to support Apache Harmony |
17 |
* (http://harmony.apache.org) settings |
18 |
*/ |
19 |
public class DRLVMLauncher extends StandardVMLauncher { |
20 |
/** |
21 |
* @see LocalVMLauncher#getCommandLine |
22 |
*/ |
23 |
public String[] getCommandLine() { |
24 |
Vector commandLine= new Vector(); |
25 |
|
26 |
// VM binary |
27 |
String vmLocation = this.vmPath + |
28 |
(this.vmPath.endsWith(File.separator) ? "" : File.separator) + |
29 |
"bin" + |
30 |
File.separator + |
31 |
"javaw"; |
32 |
final String osName = System.getProperty("os.name"); |
33 |
if (osName.indexOf("win32") != -1) { |
34 |
vmLocation += ".exe"; |
35 |
} |
36 |
if (!new File(vmLocation).exists()) { |
37 |
vmLocation = |
38 |
this.vmPath + |
39 |
(this.vmPath.endsWith(File.separator) ? "" : File.separator) + |
40 |
"bin" + |
41 |
File.separator + |
42 |
"java"; |
43 |
} |
44 |
commandLine.addElement(vmLocation); |
45 |
|
46 |
// VM arguments |
47 |
if (this.vmArguments != null) { |
48 |
for (int i = 0; i < this.vmArguments.length; i++) { |
49 |
commandLine.addElement(this.vmArguments[i]); |
50 |
} |
51 |
} |
52 |
|
53 |
// boot classpath |
54 |
commandLine.addElement("-Xbootclasspath/a:" + buildBootClassPath()); |
55 |
|
56 |
// debug mode |
57 |
if (this.debugPort != -1) { |
58 |
commandLine.addElement("-Xdebug"); |
59 |
commandLine.addElement("-Xnoagent"); |
60 |
// commandLine.addElement("-Djava.compiler=NONE"); |
61 |
commandLine.addElement( |
62 |
"-Xrunjdwp:transport=dt_socket,address=" + |
63 |
this.debugPort + |
64 |
",server=y,suspend=n"); |
65 |
} |
66 |
|
67 |
// regular classpath |
68 |
commandLine.addElement("-classpath"); |
69 |
commandLine.addElement(buildClassPath()); |
70 |
|
71 |
// code snippet runner class |
72 |
if (this.evalPort != -1) { |
73 |
commandLine.addElement(CODE_SNIPPET_RUNNER_CLASS_NAME); |
74 |
} |
75 |
|
76 |
// code snippet runner arguments |
77 |
if (this.evalPort != -1) { |
78 |
commandLine.addElement(EVALPORT_ARG); |
79 |
commandLine.addElement(Integer.toString(this.evalPort)); |
80 |
if (TARGET_HAS_FILE_SYSTEM) { |
81 |
commandLine.addElement(CODESNIPPET_CLASSPATH_ARG); |
82 |
commandLine.addElement(this.evalTargetPath + File.separator + REGULAR_CLASSPATH_DIRECTORY); |
83 |
commandLine.addElement(CODESNIPPET_BOOTPATH_ARG); |
84 |
commandLine.addElement(this.evalTargetPath + File.separator + BOOT_CLASSPATH_DIRECTORY); |
85 |
} |
86 |
} |
87 |
|
88 |
// program class |
89 |
if (this.programClass != null) { |
90 |
commandLine.addElement(this.programClass); |
91 |
} |
92 |
|
93 |
// program arguments |
94 |
if (this.programArguments != null) { |
95 |
for (int i=0;i<this.programArguments.length;i++) { |
96 |
commandLine.addElement(this.programArguments[i]); |
97 |
} |
98 |
} |
99 |
|
100 |
String[] result; |
101 |
if (this.batchFileName!= null) { |
102 |
// Write to batch file if specified |
103 |
writeBatchFile(this.batchFileName, commandLine); |
104 |
result = new String[] {this.batchFileName}; |
105 |
} else { |
106 |
result = new String[commandLine.size()]; |
107 |
commandLine.copyInto(result); |
108 |
} |
109 |
|
110 |
// check for spaces in result |
111 |
for (int i = 0; i < result.length; i++) { |
112 |
String argument = result[i]; |
113 |
if (argument.indexOf(' ') != -1) { |
114 |
result[i] = "\"" + argument + "\""; |
115 |
} |
116 |
} |
117 |
|
118 |
return result; |
119 |
} |
120 |
|
121 |
/** |
122 |
* Builds the actual boot class path that is going to be passed to the VM. |
123 |
*/ |
124 |
protected String buildBootClassPath() { |
125 |
StringBuffer bootPathString = new StringBuffer(); |
126 |
char pathSeparator = File.pathSeparatorChar; |
127 |
|
128 |
if (this.bootPath != null) { |
129 |
// Add boot class path given by client |
130 |
int length = this.bootPath.length; |
131 |
for (int i = 0; i < length; i++){ |
132 |
bootPathString.append(this.bootPath[i]); |
133 |
bootPathString.append(pathSeparator); |
134 |
} |
135 |
} |
136 |
|
137 |
// Add boot class path directory if needed |
138 |
if (this.evalTargetPath != null && TARGET_HAS_FILE_SYSTEM) { |
139 |
bootPathString.append(this.evalTargetPath); |
140 |
bootPathString.append(File.separatorChar); |
141 |
bootPathString.append(BOOT_CLASSPATH_DIRECTORY); |
142 |
} |
143 |
|
144 |
return bootPathString.toString(); |
145 |
} |
146 |
} |