0N/A/*
2362N/A * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * A Simple LaunchingConnector used by unit test :-
0N/A * test/com/sun/jdi/connect/spi/DebugUsingCustomConnector.java
0N/A */
0N/Aimport com.sun.jdi.VirtualMachine;
0N/Aimport com.sun.jdi.Bootstrap;
0N/Aimport com.sun.jdi.connect.Connector;
0N/Aimport com.sun.jdi.connect.LaunchingConnector;
0N/Aimport com.sun.jdi.connect.Transport;
0N/Aimport com.sun.jdi.connect.IllegalConnectorArgumentsException;
0N/Aimport com.sun.jdi.connect.VMStartException;
0N/Aimport com.sun.jdi.connect.spi.TransportService;
0N/Aimport com.sun.jdi.connect.spi.Connection;
0N/Aimport java.io.IOException;
0N/Aimport java.io.File;
0N/Aimport java.util.Map;
0N/Aimport java.util.HashMap;
0N/A
0N/Apublic class SimpleLaunchingConnector implements LaunchingConnector {
0N/A TransportService ts;
0N/A String ARG_NAME = "class";
0N/A
0N/A /*
0N/A * Simple implementation of Connector.StringArgument
0N/A */
0N/A static class StringArgumentImpl implements Connector.StringArgument {
0N/A String name;
0N/A String label;
0N/A String description;
0N/A String value;
0N/A
0N/A StringArgumentImpl(String name, String label, String description, String value) {
0N/A this.name = name;
0N/A this.label = label;
0N/A this.description = description;
0N/A this.value = value;
0N/A }
0N/A
0N/A public String name() {
0N/A return name;
0N/A }
0N/A
0N/A public String label() {
0N/A return label;
0N/A }
0N/A
0N/A public String description() {
0N/A return description;
0N/A }
0N/A
0N/A public String value() {
0N/A return value;
0N/A }
0N/A
0N/A public void setValue(String value) {
0N/A this.value = value;
0N/A }
0N/A
0N/A public boolean isValid(String value) {
0N/A if (value.length() > 0) {
0N/A return true;
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A public boolean mustSpecify() {
0N/A return true;
0N/A }
0N/A }
0N/A
0N/A public SimpleLaunchingConnector() {
0N/A try {
0N/A Class c = Class.forName("com.sun.tools.jdi.SocketTransportService");
0N/A ts = (TransportService)c.newInstance();
0N/A } catch (Exception x) {
0N/A throw new Error(x);
0N/A }
0N/A }
0N/A
0N/A public String name() {
0N/A return "SimpleLaunchingConnector";
0N/A }
0N/A
0N/A public String description() {
0N/A return "SimpleLaunchingConnector";
0N/A }
0N/A
0N/A public Transport transport() {
0N/A return new Transport() {
0N/A public String name() {
0N/A return ts.name();
0N/A }
0N/A };
0N/A }
0N/A
0N/A public Map defaultArguments() {
0N/A HashMap map = new HashMap();
0N/A map.put(ARG_NAME,
0N/A new StringArgumentImpl(ARG_NAME, "class name", "class name", ""));
0N/A return map;
0N/A }
0N/A
0N/A public VirtualMachine launch(Map<String, ? extends Connector.Argument> arguments) throws
0N/A IOException,
0N/A IllegalConnectorArgumentsException,
0N/A VMStartException {
0N/A
0N/A /*
0N/A * Get the class name that we are to execute
0N/A */
0N/A String className = ((StringArgumentImpl)arguments.get(ARG_NAME)).value();
0N/A if (className.length() == 0) {
0N/A throw new IllegalConnectorArgumentsException("class name missing", ARG_NAME);
0N/A }
0N/A
0N/A /*
0N/A * Listen on an emperical port; launch the debuggee; wait for
0N/A * for the debuggee to connect; stop listening;
0N/A */
0N/A TransportService.ListenKey key = ts.startListening();
0N/A
0N/A String exe = System.getProperty("java.home") + File.separator + "bin" +
0N/A File.separator;
0N/A String arch = System.getProperty("os.arch");
1947N/A String osname = System.getProperty("os.name");
1947N/A if (osname.equals("SunOS") && arch.equals("sparcv9")) {
0N/A exe += "sparcv9/java";
1947N/A } else if (osname.equals("SunOS") && arch.equals("amd64")) {
1940N/A exe += "amd64/java";
0N/A } else {
0N/A exe += "java";
0N/A }
0N/A String cmd = exe + " -Xdebug -Xrunjdwp:transport=dt_socket,timeout=15000,address=" +
1940N/A key.address() +
1940N/A " -classpath " + System.getProperty("test.classes") +
1940N/A " " + className;
0N/A Process process = Runtime.getRuntime().exec(cmd);
0N/A Connection conn = ts.accept(key, 30*1000, 9*1000);
0N/A ts.stopListening(key);
0N/A
0N/A /*
0N/A * Debugee is connected - return the virtual machine mirror
0N/A */
0N/A return Bootstrap.virtualMachineManager().createVirtualMachine(conn);
0N/A }
0N/A}