1 19 20 package org.netbeans.api.debugger.jpda; 21 22 import com.sun.jdi.Bootstrap; 23 import com.sun.jdi.VirtualMachine; 24 import com.sun.jdi.connect.IllegalConnectorArgumentsException; 25 import com.sun.jdi.connect.LaunchingConnector; 26 import com.sun.jdi.connect.VMStartException; 27 import com.sun.jdi.connect.Connector.Argument; 28 29 import java.io.IOException ; 30 import java.util.Iterator ; 31 import java.util.Map ; 32 33 34 55 public final class LaunchingDICookie extends AbstractDICookie { 56 57 60 public static final String ID = "netbeans-jpda-LaunchingDICookie"; 61 62 private LaunchingConnector launchingConnector; 63 private Map <String , ? extends Argument> args; 64 65 private String mainClassName; 66 private boolean suspend; 67 68 69 private LaunchingDICookie ( 70 LaunchingConnector launchingConnector, 71 Map <String , ? extends Argument> args, 72 String mainClassName, 73 boolean suspend 74 ) { 75 this.launchingConnector = launchingConnector; 76 this.args = args; 77 this.mainClassName = mainClassName; 78 this.suspend = suspend; 79 } 80 81 90 public static LaunchingDICookie create ( 91 String mainClassName, 92 String commandLine, 93 String address, 94 boolean suspend 95 ) { 96 return new LaunchingDICookie ( 97 findLaunchingConnector (), 98 getArgs (commandLine, address), 99 mainClassName, 100 suspend 101 ); 102 } 103 104 113 public static LaunchingDICookie create ( 114 String mainClassName, 115 String [] args, 116 String classPath, 117 boolean suspend 118 ) { 119 String argss = ""; 120 int i, k = args.length; 121 for (i = 0; i < k; i++) { 122 argss += " \"" + args [i] + "\""; 123 } 124 String commandLine = System.getProperty ("java.home") + 129 "\\bin\\java -Xdebug -Xnoagent -Xrunjdwp:transport=" + 130 getTransportName () + 131 ",address=name,suspend=" + 132 (suspend ? "y" : "n") + 133 " -classpath \"" + 134 classPath + 135 "\" " + 136 mainClassName + 137 argss; 138 String address = "name"; 139 return new LaunchingDICookie ( 140 findLaunchingConnector (), 141 getArgs (commandLine, address), 142 mainClassName, 143 suspend 144 ); 145 } 146 147 152 public static String getTransportName () { 153 return findLaunchingConnector ().transport ().name (); 154 } 155 156 157 159 164 public String getClassName () { 165 return mainClassName; 166 } 167 168 173 public boolean getSuspend () { 174 return suspend; 175 } 176 177 182 public String getCommandLine () { 183 Argument a = (Argument) args.get ("command"); 184 if (a == null) return null; 185 return a.value (); 186 } 187 188 193 public VirtualMachine getVirtualMachine () throws IOException , 194 IllegalConnectorArgumentsException, VMStartException { 195 return launchingConnector.launch (args); 196 } 197 198 199 201 private static Map <String , ? extends Argument> getArgs ( 202 String commandLine, 203 String address 204 ) { 205 Map <String , ? extends Argument> args = findLaunchingConnector ().defaultArguments (); 206 args.get ("command").setValue (commandLine); 207 args.get ("address").setValue (address); 208 return args; 209 } 210 211 private static LaunchingConnector findLaunchingConnector () { 212 Iterator <LaunchingConnector> iter = Bootstrap.virtualMachineManager (). 213 launchingConnectors ().iterator (); 214 while (iter.hasNext ()) { 215 LaunchingConnector lc = iter.next (); 216 if (lc.name ().indexOf ("RawCommandLineLaunch") > -1) 217 return lc; 218 } 219 return null; 220 } 221 } 222 | Popular Tags |