KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > hook > BootClasspathStarter


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.hook;
5
6 /**
7  * Starts a target process adding a dir in -Xbootclasspath/p: option <p/>Target process is launched using
8  * <i>$JAVA_HOME/bin/java [opt] [main] </i> <br/>and [opt] is patched to use [bootDir] in -Xbootclasspath/p: option.
9  * <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 JavaDoc bootDir;
15
16   public BootClasspathStarter(String JavaDoc opt, String JavaDoc main, String JavaDoc 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:\"") + "-Xbootclasspath/p:\"".length();
36       } else if (opt.indexOf("-Xbootclasspath/p:'") >= 0) {
37         // -Xbootclasspath/p: is defined using '
38
index = opt.indexOf("-Xbootclasspath/p:'") + "-Xbootclasspath/p:'".length();
39       } else {
40         // -Xbootclasspath/p: is defined without quotes
41
index = opt.indexOf("-Xbootclasspath/p:") + "-Xbootclasspath/p:".length();
42       }
43       StringBuffer JavaDoc optB = new StringBuffer JavaDoc("");
44       optB.append(opt.substring(0, index));
45       optB.append(bootDir);
46       optB.append((System.getProperty("os.name", "").toLowerCase().indexOf("windows") >= 0) ? ";" : ":");
47       optB.append(opt.substring(index));
48       opt = optB.toString();
49     }
50   }
51 }
Popular Tags