Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 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 |
|
14 |
import java.io.*; |
15 |
|
16 |
import java.util.Vector; |
17 |
import java.util.Enumeration; |
18 |
|
19 |
/** |
20 |
* A standard VM launcher launches an external standard VM with |
21 |
* the given arguments on the same machine. |
22 |
*/ |
23 |
public class JRockitVMLauncher extends LocalVMLauncher implements RuntimeConstants { |
24 |
String batchFileName; |
25 |
/** |
26 |
* Creates a new StandardVMLauncher that launches a standard VM |
27 |
* on the same machine. |
28 |
*/ |
29 |
public JRockitVMLauncher() { |
30 |
super(); |
31 |
} |
32 |
/** |
33 |
* Builds the actual boot class path that is going to be passed to the VM. |
34 |
*/ |
35 |
protected String buildBootClassPath() { |
36 |
StringBuffer bootPathString = new StringBuffer(); |
37 |
|
38 |
// Add boot class path directory if needed |
39 |
if (this.evalTargetPath != null && TARGET_HAS_FILE_SYSTEM) { |
40 |
bootPathString.append(this.evalTargetPath); |
41 |
bootPathString.append(File.separatorChar); |
42 |
bootPathString.append(BOOT_CLASSPATH_DIRECTORY); |
43 |
} |
44 |
|
45 |
return bootPathString.toString(); |
46 |
} |
47 |
/** |
48 |
* Returns the name of the batch file used to launch the VM. |
49 |
*/ |
50 |
public String getBatchFileName() { |
51 |
return this.batchFileName; |
52 |
} |
53 |
/** |
54 |
* @see LocalVMLauncher#getCommandLine |
55 |
*/ |
56 |
public String[] getCommandLine() { |
57 |
Vector commandLine= new Vector(); |
58 |
|
59 |
// VM binary |
60 |
if (System.getProperty("java.vm.version").startsWith("1.4.2")) { |
61 |
commandLine.addElement( |
62 |
this.vmPath + |
63 |
(this.vmPath.endsWith(File.separator) ? "" : File.separator) + |
64 |
"bin" + |
65 |
File.separator + |
66 |
"java"); |
67 |
} else { |
68 |
String vmLocation = this.vmPath + |
69 |
(this.vmPath.endsWith(File.separator) ? "" : File.separator) + |
70 |
"bin" + |
71 |
File.separator + |
72 |
"javaw"; |
73 |
final String osName = System.getProperty("os.name"); |
74 |
if (osName.indexOf("win32") != -1) { |
75 |
vmLocation += ".exe"; |
76 |
} |
77 |
if (!new File(vmLocation).exists()) { |
78 |
vmLocation = |
79 |
this.vmPath + |
80 |
(this.vmPath.endsWith(File.separator) ? "" : File.separator) + |
81 |
"bin" + |
82 |
File.separator + |
83 |
"java"; |
84 |
} |
85 |
commandLine.addElement(vmLocation); |
86 |
} |
87 |
|
88 |
// VM arguments |
89 |
if (this.vmArguments != null) { |
90 |
for (int i = 0; i < this.vmArguments.length; i++) { |
91 |
commandLine.addElement(this.vmArguments[i]); |
92 |
} |
93 |
} |
94 |
|
95 |
// debug mode |
96 |
if (this.debugPort != -1) { |
97 |
commandLine.addElement("-Xdebug"); |
98 |
commandLine.addElement("-Xnoagent"); |
99 |
commandLine.addElement( |
100 |
"-Xrunjdwp:transport=dt_socket,address=" + |
101 |
this.debugPort + |
102 |
",server=y,suspend=n"); |
103 |
} |
104 |
|
105 |
// set the classpath |
106 |
// we don't set the bootclasspath as for StandardVMLauncher as this breaks the debug mode of JRockit |
107 |
// we would get: [JRockit] ERROR: failed to set up MAPI gc reporting |
108 |
commandLine.addElement("-classpath"); |
109 |
String classpath = buildBootClassPath() + File.pathSeparator + buildClassPath(); |
110 |
System.out.println(classpath); |
111 |
commandLine.addElement(classpath); |
112 |
|
113 |
// code snippet runner class |
114 |
if (this.evalPort != -1) { |
115 |
commandLine.addElement(CODE_SNIPPET_RUNNER_CLASS_NAME); |
116 |
} |
117 |
|
118 |
// code snippet runner arguments |
119 |
if (this.evalPort != -1) { |
120 |
commandLine.addElement(EVALPORT_ARG); |
121 |
commandLine.addElement(Integer.toString(this.evalPort)); |
122 |
if (TARGET_HAS_FILE_SYSTEM) { |
123 |
commandLine.addElement(CODESNIPPET_CLASSPATH_ARG); |
124 |
commandLine.addElement(this.evalTargetPath + File.separator + REGULAR_CLASSPATH_DIRECTORY); |
125 |
commandLine.addElement(CODESNIPPET_BOOTPATH_ARG); |
126 |
commandLine.addElement(this.evalTargetPath + File.separator + BOOT_CLASSPATH_DIRECTORY); |
127 |
} |
128 |
} |
129 |
|
130 |
// program class |
131 |
if (this.programClass != null) { |
132 |
commandLine.addElement(this.programClass); |
133 |
} |
134 |
|
135 |
// program arguments |
136 |
if (this.programArguments != null) { |
137 |
for (int i=0;i<this.programArguments.length;i++) { |
138 |
commandLine.addElement(this.programArguments[i]); |
139 |
} |
140 |
} |
141 |
|
142 |
String[] result; |
143 |
if (this.batchFileName!= null) { |
144 |
// Write to batch file if specified |
145 |
writeBatchFile(this.batchFileName, commandLine); |
146 |
result = new String[] {this.batchFileName}; |
147 |
} else { |
148 |
result = new String[commandLine.size()]; |
149 |
commandLine.copyInto(result); |
150 |
} |
151 |
|
152 |
// check for spaces in result |
153 |
for (int i = 0; i < result.length; i++) { |
154 |
String argument = result[i]; |
155 |
if (argument.indexOf(' ') != -1) { |
156 |
result[i] = "\"" + argument + "\""; |
157 |
} |
158 |
} |
159 |
|
160 |
return result; |
161 |
} |
162 |
/** |
163 |
* Sets the name of the batch file used to launch the VM. |
164 |
* When this option is set, the launcher writes the command line to the given batch file, |
165 |
* and it launches the batch file. This causes a DOS console to be opened. Note it |
166 |
* doesn't delete the batch file when done. |
167 |
*/ |
168 |
public void setBatchFileName(String batchFileName) { |
169 |
this.batchFileName = batchFileName; |
170 |
} |
171 |
protected void writeBatchFile(String fileName, Vector commandLine) { |
172 |
FileOutputStream output = null; |
173 |
try { |
174 |
output = new FileOutputStream(fileName); |
175 |
PrintWriter out= new PrintWriter(output); |
176 |
for (Enumeration e = commandLine.elements(); e.hasMoreElements();) { |
177 |
out.print((String)e.nextElement()); |
178 |
out.print(" "); |
179 |
} |
180 |
out.println("pause"); |
181 |
out.close(); |
182 |
} catch (IOException e) { |
183 |
e.printStackTrace(); |
184 |
if (output != null) { |
185 |
try { |
186 |
output.close(); |
187 |
} catch (IOException e2) { |
188 |
// ignore |
189 |
} |
190 |
} |
191 |
} |
192 |
} |
193 |
} |