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