KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > hook > BootClasspathStarter


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 JavaDoc bootDir;
19
20     public BootClasspathStarter(String JavaDoc opt, String JavaDoc main, String JavaDoc 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         // prepend dir in -Xbootclasspath/p:
31
if (opt.indexOf("-Xbootclasspath/p:") < 0) {
32             opt = "-Xbootclasspath/p:\"" + bootDir + "\" " + opt;
33
34             //todo ? is \" ok on *nix
35
} else {
36             int index = -1;
37             if (opt.indexOf("-Xbootclasspath/p:\"") >= 0) {
38                 // -Xbootclasspath/p: is defined using "
39
index = opt.indexOf("-Xbootclasspath/p:\"") + "-Xbootclasspath/p:\"".length();
40             } else if (opt.indexOf("-Xbootclasspath/p:'") >= 0) {
41                 // -Xbootclasspath/p: is defined using '
42
index = opt.indexOf("-Xbootclasspath/p:'") + "-Xbootclasspath/p:'".length();
43             } else {
44                 // -Xbootclasspath/p: is defined without quotes
45
index = opt.indexOf("-Xbootclasspath/p:") + "-Xbootclasspath/p:".length();
46             }
47             StringBuffer JavaDoc optB = new StringBuffer JavaDoc("");
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 }
Popular Tags