author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45714 | jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/RawCommandLineLauncher.java@1820d351198d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
45714 | 2 |
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.jdi; |
|
27 |
||
45714 | 28 |
import java.io.IOException; |
29 |
import java.lang.reflect.InvocationTargetException; |
|
30 |
import java.util.Map; |
|
31 |
||
2 | 32 |
import com.sun.jdi.VirtualMachine; |
45714 | 33 |
import com.sun.jdi.connect.Connector; |
34 |
import com.sun.jdi.connect.IllegalConnectorArgumentsException; |
|
35 |
import com.sun.jdi.connect.Transport; |
|
36 |
import com.sun.jdi.connect.VMStartException; |
|
37 |
import com.sun.jdi.connect.spi.TransportService; |
|
2 | 38 |
|
45714 | 39 |
public class RawCommandLineLauncher extends AbstractLauncher { |
2 | 40 |
|
41 |
static private final String ARG_COMMAND = "command"; |
|
42 |
static private final String ARG_ADDRESS = "address"; |
|
43 |
static private final String ARG_QUOTE = "quote"; |
|
44 |
||
45 |
TransportService transportService; |
|
46 |
Transport transport; |
|
47 |
||
48 |
public TransportService transportService() { |
|
49 |
return transportService; |
|
50 |
} |
|
51 |
||
52 |
public Transport transport() { |
|
53 |
return transport; |
|
54 |
} |
|
55 |
||
56 |
public RawCommandLineLauncher() { |
|
57 |
super(); |
|
58 |
||
59 |
try { |
|
45714 | 60 |
transportService = (TransportService)Class. |
61 |
forName("com.sun.tools.jdi.SharedMemoryTransportService"). |
|
62 |
getDeclaredConstructor().newInstance(); |
|
2 | 63 |
transport = new Transport() { |
64 |
public String name() { |
|
65 |
return "dt_shmem"; |
|
66 |
} |
|
67 |
}; |
|
37782
ad8fe7507ecc
6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents:
25859
diff
changeset
|
68 |
} catch (ClassNotFoundException | |
ad8fe7507ecc
6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents:
25859
diff
changeset
|
69 |
UnsatisfiedLinkError | |
ad8fe7507ecc
6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents:
25859
diff
changeset
|
70 |
InstantiationException | |
45714 | 71 |
InvocationTargetException | |
72 |
IllegalAccessException | |
|
73 |
NoSuchMethodException x) { |
|
2 | 74 |
}; |
75 |
||
76 |
if (transportService == null) { |
|
77 |
transportService = new SocketTransportService(); |
|
78 |
transport = new Transport() { |
|
79 |
public String name() { |
|
80 |
return "dt_socket"; |
|
81 |
} |
|
82 |
}; |
|
83 |
} |
|
84 |
||
85 |
addStringArgument( |
|
86 |
ARG_COMMAND, |
|
87 |
getString("raw.command.label"), |
|
88 |
getString("raw.command"), |
|
89 |
"", |
|
90 |
true); |
|
91 |
addStringArgument( |
|
92 |
ARG_QUOTE, |
|
93 |
getString("raw.quote.label"), |
|
94 |
getString("raw.quote"), |
|
95 |
"\"", |
|
96 |
true); |
|
97 |
||
98 |
addStringArgument( |
|
99 |
ARG_ADDRESS, |
|
100 |
getString("raw.address.label"), |
|
101 |
getString("raw.address"), |
|
102 |
"", |
|
103 |
true); |
|
104 |
} |
|
105 |
||
106 |
||
107 |
public VirtualMachine |
|
45714 | 108 |
launch(Map<String, ? extends Connector.Argument> arguments) |
2 | 109 |
throws IOException, IllegalConnectorArgumentsException, |
110 |
VMStartException |
|
111 |
{ |
|
112 |
String command = argument(ARG_COMMAND, arguments).value(); |
|
113 |
String address = argument(ARG_ADDRESS, arguments).value(); |
|
114 |
String quote = argument(ARG_QUOTE, arguments).value(); |
|
115 |
||
116 |
if (quote.length() > 1) { |
|
117 |
throw new IllegalConnectorArgumentsException("Invalid length", |
|
118 |
ARG_QUOTE); |
|
119 |
} |
|
120 |
||
121 |
TransportService.ListenKey listener = transportService.startListening(address); |
|
122 |
||
123 |
try { |
|
124 |
return launch(tokenizeCommand(command, quote.charAt(0)), |
|
125 |
address, listener, transportService); |
|
126 |
} finally { |
|
127 |
transportService.stopListening(listener); |
|
128 |
} |
|
129 |
} |
|
130 |
||
131 |
public String name() { |
|
132 |
return "com.sun.jdi.RawCommandLineLaunch"; |
|
133 |
} |
|
134 |
||
135 |
public String description() { |
|
136 |
return getString("raw.description"); |
|
137 |
} |
|
138 |
} |