1 11 package org.eclipse.jdi.internal.connect; 12 13 14 import java.io.IOException ; 15 import java.io.InterruptedIOException ; 16 import com.ibm.icu.text.MessageFormat; 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import org.eclipse.jdi.internal.VirtualMachineImpl; 21 import org.eclipse.jdi.internal.VirtualMachineManagerImpl; 22 23 import com.sun.jdi.VirtualMachine; 24 import com.sun.jdi.connect.Connector; 25 import com.sun.jdi.connect.IllegalConnectorArgumentsException; 26 import com.sun.jdi.connect.LaunchingConnector; 27 import com.sun.jdi.connect.VMStartException; 28 29 30 public class SocketRawLaunchingConnectorImpl extends ConnectorImpl implements LaunchingConnector { 31 32 private static final int ACCEPT_TIMEOUT = 10000; 33 34 35 private String fCommand; 36 37 private String fAddress; 38 39 42 public SocketRawLaunchingConnectorImpl(VirtualMachineManagerImpl virtualMachineManager) { 43 super(virtualMachineManager); 44 45 SocketTransportImpl transport = new SocketTransportImpl(); 47 setTransport(transport); 48 } 49 50 53 public Map defaultArguments() { 54 HashMap arguments = new HashMap (3); 55 56 StringArgumentImpl strArg = new StringArgumentImpl("command", ConnectMessages.SocketRawLaunchingConnectorImpl_Raw_command_to_start_the_debugged_application_VM_1, ConnectMessages.SocketRawLaunchingConnectorImpl_Command_2, true); arguments.put(strArg.name(), strArg); 59 60 strArg = new StringArgumentImpl("address", ConnectMessages.SocketRawLaunchingConnectorImpl_Address_from_which_to_listen_for_a_connection_after_the_raw_command_is_run_3, ConnectMessages.SocketRawLaunchingConnectorImpl_Address_4, true); arguments.put(strArg.name(), strArg); 63 64 strArg = new StringArgumentImpl("quote", ConnectMessages.SocketRawLaunchingConnectorImpl_Character_used_to_combine_space_delimited_text_into_a_single_command_line_argument_5, ConnectMessages.SocketRawLaunchingConnectorImpl_Quote_6, true); strArg.setValue("\""); arguments.put(strArg.name(), strArg); 68 69 return arguments; 70 } 71 72 75 public String name() { 76 return "com.sun.jdi.RawCommandLineLaunch"; } 78 79 82 public String description() { 83 return ConnectMessages.SocketRawLaunchingConnectorImpl_Launches_target_using_user_specified_command_line_and_attaches_to_it_7; 84 } 85 86 89 private void getConnectionArguments(Map connectionArgs) throws IllegalConnectorArgumentsException { 90 String attribute = ""; try { 92 attribute = "command"; fCommand = ((Connector.StringArgument)connectionArgs.get(attribute)).value(); 94 attribute = "address"; fAddress = ((Connector.StringArgument)connectionArgs.get(attribute)).value(); 96 attribute = "quote"; ((Connector.StringArgument)connectionArgs.get(attribute)).value(); 98 } catch (ClassCastException e) { 99 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketRawLaunchingConnectorImpl_Connection_argument_is_not_of_the_right_type_8, attribute); 100 } catch (NullPointerException e) { 101 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketRawLaunchingConnectorImpl_Necessary_connection_argument_is_null_9, attribute); 102 } catch (NumberFormatException e) { 103 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketRawLaunchingConnectorImpl_Connection_argument_is_not_a_number_10, attribute); 104 } 105 } 106 107 111 public VirtualMachine launch(Map connectionArgs) throws IOException , IllegalConnectorArgumentsException, VMStartException { 112 getConnectionArguments(connectionArgs); 113 114 SocketListeningConnectorImpl listenConnector = new SocketListeningConnectorImpl(virtualMachineManager()); 117 Map args = listenConnector.defaultArguments(); 118 ((Connector.IntegerArgument)args.get("port")).setValue(fAddress); ((Connector.IntegerArgument)args.get("timeout")).setValue(ACCEPT_TIMEOUT); listenConnector.startListening(args); 121 122 Process proc = Runtime.getRuntime().exec(fCommand); 124 125 VirtualMachineImpl virtualMachine; 127 try { 128 virtualMachine = (VirtualMachineImpl)listenConnector.accept(args); 129 } catch (InterruptedIOException e) { 130 proc.destroy(); 131 String message= MessageFormat.format(ConnectMessages.SocketLaunchingConnectorImpl_VM_did_not_connect_within_given_time___0__ms_1, new String []{((Connector.IntegerArgument)args.get("timeout")).value()}); throw new VMStartException(message, proc); 133 } 134 135 virtualMachine.setLaunchedProcess(proc); 136 return virtualMachine; 137 } 138 } 139 | Popular Tags |