01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.hook;
05:
06: /**
07: * Starts a target process adding a dir in -Xbootclasspath/p: option <p/>Target process is launched using
08: * <i>$JAVA_HOME/bin/java [opt] [main] </i> <br/>and [opt] is patched to use [bootDir] in -Xbootclasspath/p: option.
09: * <br/>This is suitable for java 1.3. <br/>This can be use with java 1.4 to avoid running in JDWP mode.
10: *
11: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
12: */
13: public class BootClasspathStarter extends AbstractStarter {
14: private String bootDir;
15:
16: public BootClasspathStarter(String opt, String main, String bootDir) {
17: super (opt, main);
18: this .bootDir = bootDir;
19: patchBootclasspath();
20: }
21:
22: /**
23: * add dir in first position of -Xbootclasspath/p option for target VM
24: */
25: private void patchBootclasspath() {
26: // prepend dir in -Xbootclasspath/p:
27: if (opt.indexOf("-Xbootclasspath/p:") < 0) {
28: opt = "-Xbootclasspath/p:\"" + bootDir + "\" " + opt;
29:
30: //todo ? is \" ok on *nix
31: } else {
32: int index = -1;
33: if (opt.indexOf("-Xbootclasspath/p:\"") >= 0) {
34: // -Xbootclasspath/p: is defined using "
35: index = opt.indexOf("-Xbootclasspath/p:\"")
36: + "-Xbootclasspath/p:\"".length();
37: } else if (opt.indexOf("-Xbootclasspath/p:'") >= 0) {
38: // -Xbootclasspath/p: is defined using '
39: index = opt.indexOf("-Xbootclasspath/p:'")
40: + "-Xbootclasspath/p:'".length();
41: } else {
42: // -Xbootclasspath/p: is defined without quotes
43: index = opt.indexOf("-Xbootclasspath/p:")
44: + "-Xbootclasspath/p:".length();
45: }
46: StringBuffer optB = new StringBuffer("");
47: optB.append(opt.substring(0, index));
48: optB.append(bootDir);
49: optB
50: .append((System.getProperty("os.name", "")
51: .toLowerCase().indexOf("windows") >= 0) ? ";"
52: : ":");
53: optB.append(opt.substring(index));
54: opt = optB.toString();
55: }
56: }
57: }
|