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