This commit was manufactured by cvs2svn to create tag
'Root_R3_2_maintenance'.
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.jsdt.debug.crossfire/META-INF/MANIFEST.MF
index e7e1ce9..6ed9a5f 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/META-INF/MANIFEST.MF
@@ -1,11 +1,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: JSDT Crossfire Debug Support
+Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.wst.jsdt.debug.crossfire;singleton:=true
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.0.100.qualifier
Bundle-Activator: org.eclipse.wst.jsdt.debug.internal.crossfire.CrossFirePlugin
-Bundle-Vendor: Eclipse
+Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.wst.jsdt.debug.core;bundle-version="1.0.0"
+ org.eclipse.wst.jsdt.debug.core;bundle-version="1.0.0",
+ org.eclipse.wst.jsdt.debug.transport;bundle-version="1.0.0",
+ org.eclipse.wst.jsdt.core;bundle-version="1.0.0",
+ org.eclipse.debug.core
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.wst.jsdt.debug.internal.crossfire;x-internal:=true,
+ org.eclipse.wst.jsdt.debug.internal.crossfire.connect;x-internal:=true,
+ org.eclipse.wst.jsdt.debug.internal.crossfire.event;x-internal:=true,
+ org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi;x-internal:=true,
+ org.eclipse.wst.jsdt.debug.internal.crossfire.request;x-internal:=true,
+ org.eclipse.wst.jsdt.debug.internal.crossfire.transport;x-internal:=true
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/OSGI-INF/l10n/bundle.properties b/bundles/org.eclipse.wst.jsdt.debug.crossfire/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 0000000..85bd94b
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/OSGI-INF/l10n/bundle.properties
@@ -0,0 +1,12 @@
+###############################################################################
+# Copyright (c) 2010 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+Bundle-Vendor = Eclipse Web Tools Platform
+Bundle-Name = Crossfire JavaScript Debug
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/build.properties b/bundles/org.eclipse.wst.jsdt.debug.crossfire/build.properties
index e9863e2..f64a074 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/build.properties
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/build.properties
@@ -1,5 +1,17 @@
+###############################################################################
+# Copyright (c) 2011 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
- plugin.xml
+ plugin.xml,\
+ OSGI-INF/l10n/bundle.properties,\
+ OSGI-INF/
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/CrossFirePlugin.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/CrossFirePlugin.java
index 8dc7998..7140591 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/CrossFirePlugin.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/CrossFirePlugin.java
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.crossfire;
import java.net.URI;
@@ -11,7 +21,7 @@
import org.eclipse.wst.jsdt.debug.internal.crossfire.event.CFEventQueue;
import org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi.CFMirror;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.JSON;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Packet;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFPacket;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -27,11 +37,11 @@
*/
public static final String PLUGIN_ID = "org.eclipse.wst.jsdt.debug.crossfire"; //$NON-NLS-1$
/**
- * Packet tracing option name
+ * CFPacket tracing option name
*/
public static final String TRC_PACKETS = PLUGIN_ID + "/packets"; //$NON-NLS-1$
/**
- * Event queue tracing option name
+ * CFEventPacket queue tracing option name
*/
public static final String TRC_EVENTQUEUE = PLUGIN_ID + "/eventqueue"; //$NON-NLS-1$
/**
@@ -72,6 +82,9 @@
}
}
+ /**
+ * @return the singleton instance
+ */
public static CrossFirePlugin getDefault() {
return plugin;
}
@@ -122,7 +135,7 @@
if(CrossFirePlugin.getDefault().isDebugging()) {
String option = Platform.getDebugOption(TRC_PACKETS);
if(option != null) {
- Packet.setTracing(Boolean.valueOf(option).booleanValue());
+ CFPacket.setTracing(Boolean.valueOf(option).booleanValue());
}
option = Platform.getDebugOption(TRC_EVENTQUEUE);
if(option != null) {
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/Tracing.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/Tracing.java
index 1207313..e93c4ce 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/Tracing.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/Tracing.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -27,7 +27,10 @@
* @param string
*/
public static void writeString(String string) {
- System.out.println(string.replaceAll(JSON.LINE_FEED, PRINTABLE_LINE_FEED));
+ String s = string.replaceAll(JSON.LINE_FEED, PRINTABLE_LINE_FEED);
+ s = s.replaceAll("\r", "\\\\r"); //$NON-NLS-1$//$NON-NLS-2$
+ s = s.replaceAll("\n", "\\\\n"); //$NON-NLS-1$//$NON-NLS-2$
+ System.out.println("[CROSSFIRE]" + s); //$NON-NLS-1$
}
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/ConsoleArgument.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/ConsoleArgument.java
new file mode 100644
index 0000000..80bcb67
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/ConsoleArgument.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.connect;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument;
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument;
+
+/**
+ * An {@link Argument} to enable the <code>console</code> tool
+ *
+ * @since 1.0
+ */
+public class ConsoleArgument implements BooleanArgument {
+
+ public static final String CONSOLE = "console"; //$NON-NLS-1$
+
+ private boolean fValue = true;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#description()
+ */
+ public String description() {
+ return Messages.console_arg_description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#label()
+ */
+ public String label() {
+ return Messages.console_arg_label;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#mustSpecify()
+ */
+ public boolean mustSpecify() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#name()
+ */
+ public String name() {
+ return CONSOLE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#setValue(java.lang.String)
+ */
+ public void setValue(String value) {
+ fValue = Boolean.valueOf(value).booleanValue();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#value()
+ */
+ public String value() {
+ return Boolean.toString(fValue);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#booleanValue()
+ */
+ public boolean booleanValue() {
+ return fValue;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#isValid(java.lang.String)
+ */
+ public boolean isValid(String value) {
+ return value != null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#setValue(boolean)
+ */
+ public void setValue(boolean booleanValue) {
+ fValue = booleanValue;
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/CrossfireAttachingConnector.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/CrossfireAttachingConnector.java
index 73ae3cf..3c12c1a 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/CrossfireAttachingConnector.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/CrossfireAttachingConnector.java
@@ -11,18 +11,19 @@
package org.eclipse.wst.jsdt.debug.internal.crossfire.connect;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
import org.eclipse.wst.jsdt.debug.core.jsdi.connect.AttachingConnector;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.CrossFirePlugin;
import org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi.CFVirtualMachine;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Connection;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.DebugSession;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.SocketTransportService;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.TransportService;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.TransportService.ListenerKey;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFTransportService;
+import org.eclipse.wst.jsdt.debug.transport.Connection;
+import org.eclipse.wst.jsdt.debug.transport.DebugSession;
+import org.eclipse.wst.jsdt.debug.transport.TransportService;
/**
* Attaching connector for Crossfire
@@ -32,102 +33,162 @@
public class CrossfireAttachingConnector implements AttachingConnector {
public static final String CROSSFIRE_REMOTE_ATTACH_CONNECTOR_ID = "crossfire.remote.attach.connector"; //$NON-NLS-1$
-
+
/**
* Constructor
*/
public CrossfireAttachingConnector() {
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector#defaultArguments()
*/
public Map defaultArguments() {
- Map args = new HashMap(4);
+ HashMap args = new HashMap(5);
args.put(HostArgument.HOST, new HostArgument(null));
args.put(PortArgument.PORT, new PortArgument(5000));
args.put(TimeoutArgument.TIMEOUT, new TimeoutArgument());
- args.put(BrowserArgument.BROWSER, new BrowserArgument());
+ args.put(ConsoleArgument.CONSOLE, new ConsoleArgument());
+ args.put(DOMArgument.DOM, new DOMArgument());
+ args.put(InspectorArgument.INSPECTOR, new InspectorArgument());
+ args.put(NetArgument.NET, new NetArgument());
+ args.put(TraceArgument.TRACE, new TraceArgument());
+ //XXX hack because there is no good way to find the Firefox executable on Win
+ if(!Platform.OS_WIN32.equals(Platform.getOS())) {
+ args.put(BrowserArgument.BROWSER, new BrowserArgument());
+ }
return args;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector#description()
*/
public String description() {
return Messages.attach_connector_desc;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector#name()
*/
public String name() {
return Messages.crossfire_remote_attach;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector#id()
*/
public String id() {
return CROSSFIRE_REMOTE_ATTACH_CONNECTOR_ID;
}
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.AttachingConnector#attach(java.util.Map)
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.AttachingConnector#attach
+ * (java.util.Map)
*/
public VirtualMachine attach(Map arguments) throws IOException {
- String str = (String)arguments.get(BrowserArgument.BROWSER);
- boolean browser = Boolean.valueOf(str).booleanValue();
- TransportService service = new SocketTransportService();
- String host = (String) arguments.get(HostArgument.HOST);
- String port = (String) arguments.get(PortArgument.PORT);
- if(browser && !HostArgument.isLocalhost(host)) {
- //we cannot auto launch the browser on a different host
+ String str = (String) arguments.get(BrowserArgument.BROWSER);
+ //XXX hack because there is no good way to find the Firefox executable on Win
+ boolean browser = Boolean.valueOf(str).booleanValue() && !Platform.OS_WIN32.equals(Platform.getOS());
+ if (browser && !HostArgument.isLocalhost((String) arguments.get(HostArgument.HOST))) {
+ // we cannot auto launch the browser on a different host
throw new IOException(Messages.cannot_launch_browser_not_localhost);
}
- if(browser) {
- launchBrowser(host, port);
- }
- String timeoutstr = (String) arguments.get(TimeoutArgument.TIMEOUT);
- int timeout = Integer.parseInt(timeoutstr);
- StringBuffer buffer = new StringBuffer();
- buffer.append(host).append(':').append(Integer.parseInt(port));
- ListenerKey key = service.startListening(buffer.toString());
Connection c = null;
- try {
- c = service.accept(key, timeout, timeout);
- }
- catch(IOException ioe) {
- service.stopListening(key);
- throw ioe;
+ if (browser) {
+ c = launchForBrowser(arguments);
+ } else {
+ c = launch(arguments);
}
DebugSession session = new DebugSession(c);
return new CFVirtualMachine(session);
}
-
+
/**
- * Launch the browser on the given host / port
- * @param host
- * @param port
- * @throws IOException
+ * Launches the browser and connects to it. This method will poll for the
+ * browser to be launched but only for a fixed timeout.
+ *
+ * @param arguments
+ * @return the created connection or <code>null</code> if the attempt to
+ * connect times out, the browser process terminates before we can
+ * connect
+ * @throws IOException
*/
- void launchBrowser(final String host, final String port) throws IOException {
- Thread thread = new Thread() {
- public void run() {
+ Connection launchForBrowser(final Map arguments) throws IOException {
+ String host = (String) arguments.get(HostArgument.HOST);
+ String port = (String) arguments.get(PortArgument.PORT);
+ StringBuffer buffer = new StringBuffer("firefox -ProfileManager -load-fb-modules -crossfire-server-port ").append(port); //$NON-NLS-1$
+ Process p = Runtime.getRuntime().exec(buffer.toString());
+ TransportService service = new CFTransportService(getToolArgs(arguments));
+ String timeoutstr = (String) arguments.get(TimeoutArgument.TIMEOUT);
+ int timeout = Integer.parseInt(timeoutstr);
+ buffer = new StringBuffer();
+ buffer.append(host).append(':').append(Integer.parseInt(port));
+ long timer = System.currentTimeMillis() + 20000;
+ Connection c = null;
+ while (p != null && System.currentTimeMillis() < timer && c == null) {
+ try {
+ c = service.attach(buffer.toString(), timeout,timeout);
+ } catch (IOException ioe) {
+ // ignore while pinging to connect
try {
- Thread.sleep(1000);
+ Thread.sleep(200);
} catch (InterruptedException e) {
- CrossFirePlugin.log(e);
+ //do nothing
}
- StringBuffer buffer = new StringBuffer("firefox -P crossfire -no-remote -load-fb-modules -crossfire-host "); //$NON-NLS-1$
- buffer.append(host).append(" -crossfire-port ").append(port); //$NON-NLS-1$
- try {
- Runtime.getRuntime().exec(buffer.toString());
- } catch (IOException e) {
- CrossFirePlugin.log(e);
- }
- };
- };
- thread.start();
+ }
+ }
+ if (c == null) {
+ throw new IOException(NLS.bind(Messages.failed_to_attach_to_auto_browser, new String[] {host, port }));
+ }
+ return c;
+ }
+
+ /**
+ * Tries to connect to the given
+ *
+ * @param arguments
+ * @return the {@link Connection} or throws an exception
+ * @throws IOException
+ */
+ Connection launch(Map arguments) throws IOException {
+ TransportService service = new CFTransportService(getToolArgs(arguments));
+ String host = (String) arguments.get(HostArgument.HOST);
+ String port = (String) arguments.get(PortArgument.PORT);
+ String timeoutstr = (String) arguments.get(TimeoutArgument.TIMEOUT);
+ int timeout = Integer.parseInt(timeoutstr);
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(host).append(':').append(Integer.parseInt(port));
+ return service.attach(buffer.toString(), timeout, timeout);
+ }
+
+ String[] getToolArgs(Map arguments) {
+ ArrayList tools = new ArrayList();
+ String value = (String) arguments.get(ConsoleArgument.CONSOLE);
+ if(Boolean.valueOf(value).booleanValue()) {
+ tools.add(ConsoleArgument.CONSOLE);
+ }
+ value = (String) arguments.get(DOMArgument.DOM);
+ if(Boolean.valueOf(value).booleanValue()) {
+ tools.add(DOMArgument.DOM);
+ }
+ value = (String) arguments.get(InspectorArgument.INSPECTOR);
+ if(Boolean.valueOf(value).booleanValue()) {
+ tools.add(InspectorArgument.INSPECTOR);
+ }
+ value = (String) arguments.get(NetArgument.NET);
+ if(Boolean.valueOf(value).booleanValue()) {
+ tools.add(NetArgument.NET);
+ }
+ value = (String) arguments.get(TraceArgument.TRACE);
+ if(Boolean.valueOf(value).booleanValue()) {
+ tools.add(TraceArgument.TRACE);
+ }
+ return (String[]) tools.toArray(new String[tools.size()]);
}
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/CrossfireListeningConnector.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/CrossfireListeningConnector.java
index c8d661b..5f73677 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/CrossfireListeningConnector.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/CrossfireListeningConnector.java
@@ -17,10 +17,10 @@
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
import org.eclipse.wst.jsdt.debug.core.jsdi.connect.ListeningConnector;
import org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi.CFVirtualMachine;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Connection;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.DebugSession;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.SocketTransportService;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.TransportService;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFTransportService;
+import org.eclipse.wst.jsdt.debug.transport.Connection;
+import org.eclipse.wst.jsdt.debug.transport.DebugSession;
+import org.eclipse.wst.jsdt.debug.transport.TransportService;
/**
* Default launching connector for CrossFire
@@ -44,10 +44,11 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector#defaultArguments()
*/
public Map defaultArguments() {
- Map args = new HashMap(2);
+ HashMap args = new HashMap(5);
args.put(HostArgument.HOST, new HostArgument(null));
args.put(PortArgument.PORT, new PortArgument(5000));
args.put(TimeoutArgument.TIMEOUT, new TimeoutArgument());
+ args.put(ConsoleArgument.CONSOLE, new ConsoleArgument());
return args;
}
@@ -76,7 +77,7 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.ListeningConnector#accept(java.util.Map)
*/
public VirtualMachine accept(Map arguments) throws IOException {
- TransportService service = new SocketTransportService();
+ TransportService service = new CFTransportService(null);
String host = (String) arguments.get(HostArgument.HOST);
String port = (String) arguments.get(PortArgument.PORT);
String timeoutstr = (String) arguments.get(TimeoutArgument.TIMEOUT);
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/DOMArgument.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/DOMArgument.java
new file mode 100644
index 0000000..cce787a
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/DOMArgument.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.connect;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument;
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument;
+
+/**
+ * An {@link Argument} to enable DOM tooling support in the crossfire server
+ *
+ * @since 1.0
+ */
+public class DOMArgument implements BooleanArgument {
+
+ public static final String DOM = "dom"; //$NON-NLS-1$
+
+ private boolean fValue = true;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#description()
+ */
+ public String description() {
+ return Messages.dom_arg_description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#label()
+ */
+ public String label() {
+ return Messages.dom_arg_label;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#mustSpecify()
+ */
+ public boolean mustSpecify() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#name()
+ */
+ public String name() {
+ return DOM;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#setValue(java.lang.String)
+ */
+ public void setValue(String value) {
+ fValue = Boolean.valueOf(value).booleanValue();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#value()
+ */
+ public String value() {
+ return Boolean.toString(fValue);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#booleanValue()
+ */
+ public boolean booleanValue() {
+ return fValue;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#isValid(java.lang.String)
+ */
+ public boolean isValid(String value) {
+ return value != null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#setValue(boolean)
+ */
+ public void setValue(boolean booleanValue) {
+ fValue = booleanValue;
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/HostArgument.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/HostArgument.java
index 4f67783..e188a79 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/HostArgument.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/HostArgument.java
@@ -11,7 +11,7 @@
package org.eclipse.wst.jsdt.debug.internal.crossfire.connect;
import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.StringArgument;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.TransportService;
+import org.eclipse.wst.jsdt.debug.transport.Constants;
/**
* Implementation of a string argument that describes the host argument
@@ -77,7 +77,7 @@
*/
public void setValue(String host) {
if(host == null) {
- this.host = TransportService.LOCALHOST;
+ this.host = Constants.LOCALHOST;
}
else {
if (!isValid(host)) {
@@ -100,6 +100,6 @@
* @return true if the given host it localhost (127.0.0.1) false otherwise
*/
public static boolean isLocalhost(String host) {
- return host.equals(TransportService.LOCALHOST) || host.equals(TransportService.LOCALHOST_IP);
+ return host.equals(Constants.LOCALHOST) || host.equals(Constants.LOCALHOST_IP);
}
}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/InspectorArgument.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/InspectorArgument.java
new file mode 100644
index 0000000..b0d68e1
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/InspectorArgument.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.connect;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument;
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument;
+
+/**
+ * An {@link Argument} to allow the page inspector tooling to be enabled in the
+ * Crossfire server
+ *
+ * @since 1.0
+ */
+public class InspectorArgument implements BooleanArgument {
+
+ public static final String INSPECTOR = "inspector"; //$NON-NLS-1$
+ private boolean fValue = true;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#description()
+ */
+ public String description() {
+ return Messages.inspector_arg_description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#label()
+ */
+ public String label() {
+ return Messages.inspector_arg_label;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#mustSpecify()
+ */
+ public boolean mustSpecify() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#name()
+ */
+ public String name() {
+ return INSPECTOR;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#setValue(java.lang.String)
+ */
+ public void setValue(String value) {
+ fValue = Boolean.valueOf(value).booleanValue();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#value()
+ */
+ public String value() {
+ return Boolean.toString(fValue);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#booleanValue()
+ */
+ public boolean booleanValue() {
+ return fValue;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#isValid(java.lang.String)
+ */
+ public boolean isValid(String value) {
+ return value != null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#setValue(boolean)
+ */
+ public void setValue(boolean booleanValue) {
+ fValue = booleanValue;
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/Messages.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/Messages.java
index b8791fc..192d572 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/Messages.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/Messages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -22,14 +22,24 @@
public static String auto_attach_desc;
public static String auto_attach_label;
public static String cannot_launch_browser_not_localhost;
+ public static String console_arg_description;
+ public static String console_arg_label;
public static String crossfire_remote_attach;
+ public static String dom_arg_description;
+ public static String dom_arg_label;
+ public static String failed_to_attach_to_auto_browser;
public static String host_arg_desc;
public static String host_arg_name;
- public static String only_localhost_is_supported;
+ public static String inspector_arg_description;
+ public static String inspector_arg_label;
+ public static String net_arg_description;
+ public static String net_arg_label;
public static String port_arg_desc;
public static String port_arg_name;
public static String timeout;
public static String timeout_desc;
+ public static String trace_arg_description;
+ public static String trace_arg_label;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/NetArgument.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/NetArgument.java
new file mode 100644
index 0000000..3a92428
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/NetArgument.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.connect;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument;
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument;
+
+/**
+ * An {@link Argument} to allow the the Net panel and support to be enabled in the Crossfire server
+ *
+ * @since 1.0
+ */
+public class NetArgument implements BooleanArgument {
+
+ public static final String NET = "net"; //$NON-NLS-1$
+
+ private boolean fValue = true;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#description()
+ */
+ public String description() {
+ return Messages.net_arg_description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#label()
+ */
+ public String label() {
+ return Messages.net_arg_label;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#mustSpecify()
+ */
+ public boolean mustSpecify() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#name()
+ */
+ public String name() {
+ return NET;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#setValue(java.lang.String)
+ */
+ public void setValue(String value) {
+ fValue = Boolean.valueOf(value).booleanValue();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#value()
+ */
+ public String value() {
+ return Boolean.toString(fValue);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#booleanValue()
+ */
+ public boolean booleanValue() {
+ return fValue;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#isValid(java.lang.String)
+ */
+ public boolean isValid(String value) {
+ return value != null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#setValue(boolean)
+ */
+ public void setValue(boolean booleanValue) {
+ fValue = booleanValue;
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/TraceArgument.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/TraceArgument.java
new file mode 100644
index 0000000..3754369
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/TraceArgument.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.connect;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument;
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument;
+
+/**
+ * An {@link Argument} to allow server error tracing to be reported back to the client
+ *
+ * @since 1.0
+ */
+public class TraceArgument implements BooleanArgument {
+
+ public static final String TRACE = "trace"; //$NON-NLS-1$
+
+ private boolean fValue = false;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#description()
+ */
+ public String description() {
+ return Messages.trace_arg_description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#label()
+ */
+ public String label() {
+ return Messages.trace_arg_label;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#mustSpecify()
+ */
+ public boolean mustSpecify() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#name()
+ */
+ public String name() {
+ return TRACE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#setValue(java.lang.String)
+ */
+ public void setValue(String value) {
+ fValue = Boolean.valueOf(value).booleanValue();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#value()
+ */
+ public String value() {
+ return Boolean.toString(fValue);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#booleanValue()
+ */
+ public boolean booleanValue() {
+ return fValue;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#isValid(java.lang.String)
+ */
+ public boolean isValid(String value) {
+ return value != null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.BooleanArgument#setValue(boolean)
+ */
+ public void setValue(boolean booleanValue) {
+ fValue = booleanValue;
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/messages.properties b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/messages.properties
index 4b92ca5..4b4bb54 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/messages.properties
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/connect/messages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2010 IBM Corporation and others.
+# Copyright (c) 2010, 2011 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -13,11 +13,21 @@
auto_attach_desc=Automatically launch Firefox and attach to it
auto_attach_label=Auto&matically launch Firefox and attach to it (extremely experimental)
cannot_launch_browser_not_localhost=You cannot launch a browser on a different host than localhost (127.0.0.1)
+console_arg_description=Allows Crossfire to forward messages logged in the Firebug console to the Eclipse Error Log.
+console_arg_label=Enable Firebug console message logging in the Error &Log
crossfire_remote_attach=Crossfire - Remote Attach
+dom_arg_description=Allows the client to take part in DOM inspections
+dom_arg_label=Enable DO&M inspection support
+failed_to_attach_to_auto_browser=Failed to attach to debugger at {0} on port {1}
host_arg_desc=The name of the host address to try attaching to.
host_arg_name=&Host:
-only_localhost_is_supported=Only localhost (127.0.0.1) is supported.
+inspector_arg_description=Allows the client to enable page inspections in the Crossfire server
+inspector_arg_label=Enable pa&ge inspections
+net_arg_description=Allows network traffic inspections to be enabled in the Crossfire server
+net_arg_label=Enable network tra&ffic inspections
port_arg_desc=The port on the host machine to try attaching to.
port_arg_name=&Port:
timeout=&Timeout (ms):
timeout_desc=A timeout value in milliseconds to wait for a debugger to connect
+trace_arg_description=Allows server error tracing to be enabled. When enabled exception messages and stack traces are returned with failure error codes.
+trace_arg_label=Enable server error tr&acing
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEvent.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEvent.java
index 301f40a..1e9d2f5 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEvent.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEvent.java
@@ -15,7 +15,7 @@
import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequest;
/**
- * Default implementation of an {@link Event} for Crossfire
+ * Default implementation of an {@link CFEvent} for Crossfire
*
* @since 1.0
*/
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEventQueue.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEventQueue.java
index 6c40a43..5d06d64 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEventQueue.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEventQueue.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,11 +12,16 @@
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference;
import org.eclipse.wst.jsdt.debug.core.jsdi.event.EventQueue;
import org.eclipse.wst.jsdt.debug.core.jsdi.event.EventSet;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequestManager;
+import org.eclipse.wst.jsdt.debug.core.jsdi.request.ResumeRequest;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.ScriptLoadRequest;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.SuspendRequest;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.ThreadEnterRequest;
@@ -30,10 +35,10 @@
import org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi.CFThreadReference;
import org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi.CFVirtualMachine;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Attributes;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.DisconnectedException;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Event;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFEventPacket;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.JSON;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.TimeoutException;
+import org.eclipse.wst.jsdt.debug.transport.exception.DisconnectedException;
+import org.eclipse.wst.jsdt.debug.transport.exception.TimeoutException;
/**
* Default {@link EventQueue} for Crossfire
@@ -71,23 +76,22 @@
public EventSet remove(int timeout) {
try {
while(true && !disposed) {
- Event event = crossfire().receiveEvent(timeout);
+ CFEventPacket event = crossfire().receiveEvent(timeout);
String name = event.getEvent();
CFEventSet set = new CFEventSet(crossfire());
- if(Event.CLOSED.equals(name)) {
+ if(CFEventPacket.CLOSED.equals(name)) {
List deaths = eventmgr.vmDeathRequests();
for (Iterator iter = deaths.iterator(); iter.hasNext();) {
VMDeathRequest request = (VMDeathRequest) iter.next();
set.add(new CFVMDeathEvent(crossfire(), request));
}
- crossfire().terminate();
if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.CLOSED+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.CLOSED+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
- else if(Event.ON_BREAK.equals(name)) {
+ else if(CFEventPacket.ON_BREAK.equals(name)) {
if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_BREAK+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_BREAK+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
}
String threadid = event.getContextId();
if(threadid != null) {
@@ -97,8 +101,12 @@
List suspends = eventmgr.suspendRequests();
for (Iterator iter = suspends.iterator(); iter.hasNext();) {
SuspendRequest request = (SuspendRequest) iter.next();
- String url = (String) event.getBody().get(Attributes.URL);
- Number line = (Number) event.getBody().get(Attributes.LINE);
+ Map locaction = (Map) event.getBody().get(Attributes.LOCATION);
+ if(locaction == null) {
+ continue;
+ }
+ String url = (String) locaction.get(Attributes.URL);
+ Number line = (Number) locaction.get(Attributes.LINE);
CFScriptReference script = crossfire().findScript(url);
if(script != null) {
CFLocation loc = new CFLocation(crossfire(), script, null, line.intValue());
@@ -107,53 +115,87 @@
}
thread.markSuspended(true);
}
+ else {
+ return null;
+ }
+ }
+ else {
return null;
}
}
- else if(Event.ON_RESUME.equals(name)) {
+ else if(CFEventPacket.ON_RESUME.equals(name)) {
if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_RESUME+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_RESUME+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
}
String threadid = event.getContextId();
if(threadid != null) {
CFThreadReference thread = crossfire().findThread(threadid);
- set.setThread(thread);
- if(thread != null && thread.isSuspended()) {
- thread.markSuspended(false);
+ if(thread != null) {
+ set.setThread(thread);
+ List resumes = eventmgr.resumeRequests();
+ for (Iterator iter = resumes.iterator(); iter.hasNext();) {
+ ResumeRequest request = (ResumeRequest) iter.next();
+ if(request.thread().equals(thread)) {
+ CFLocation loc = new CFLocation(crossfire(), null, null, 0);
+ set.add(new CFResumeEvent(crossfire(), request, thread, loc));
+ }
+ }
+ thread.eventResume();
}
+ else {
+ return null;
+ }
+ }
+ else {
return null;
}
}
- else if(Event.ON_SCRIPT.equals(name)) {
+ else if(CFEventPacket.ON_SCRIPT.equals(name)) {
ThreadReference thread = crossfire().findThread(event.getContextId());
if(thread != null) {
set.setThread(thread);
- CFScriptReference script = crossfire().addScript(event.getContextId(), event.getBody());
- List scripts = eventmgr.scriptLoadRequests();
- for (Iterator iter = scripts.iterator(); iter.hasNext();) {
- ScriptLoadRequest request = (ScriptLoadRequest) iter.next();
- set.add(new CFScriptLoadEvent(crossfire(), request, thread, script));
+ Map json = (Map) event.getBody().get(Attributes.SCRIPT);
+ if(json != null) {
+ CFScriptReference script = crossfire().addScript(event.getContextId(), json);
+ List scripts = eventmgr.scriptLoadRequests();
+ for (Iterator iter = scripts.iterator(); iter.hasNext();) {
+ ScriptLoadRequest request = (ScriptLoadRequest) iter.next();
+ set.add(new CFScriptLoadEvent(crossfire(), request, thread, script));
+ }
+ }
+ else {
+ return null;
}
}
- if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_SCRIPT+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- else if(Event.ON_CONTEXT_CREATED.equals(name)) {
- List threads = eventmgr.threadEnterRequests();
- CFThreadReference thread = crossfire().addThread(event.getContextId(), (String) event.getBody().get(Attributes.HREF));
- set.setThread(thread);
- for (Iterator iter = threads.iterator(); iter.hasNext();) {
- ThreadEnterRequest request = (ThreadEnterRequest) iter.next();
- set.add(new CFThreadEnterEvent(crossfire(), request, thread));
+ else {
+ return null;
}
if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_CONTEXT_CREATED+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_SCRIPT+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
- else if(Event.ON_CONTEXT_DESTROYED.equals(name)) {
+ else if(CFEventPacket.ON_CONTEXT_SELECTED.equals(name)) {
+ handleContext(set, event, true);
+ if(TRACE) {
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_CONTEXT_SELECTED+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ else if(CFEventPacket.ON_CONTEXT_CREATED.equals(name)) {
+ handleContext(set, event, true);
+ if(TRACE) {
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_CONTEXT_CREATED+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ else if(CFEventPacket.ON_CONTEXT_LOADED.equals(name)) {
+ handleContext(set, event, true);
+ if(TRACE) {
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_CONTEXT_LOADED+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ else if(CFEventPacket.ON_CONTEXT_DESTROYED.equals(name)) {
ThreadReference thread = crossfire().findThread(event.getContextId());
crossfire().removeThread(event.getContextId());
+ crossfire().removeScriptsForContext(event.getContextId());
if(thread != null) {
List threads = eventmgr.threadExitRequests();
for (Iterator iter = threads.iterator(); iter.hasNext();) {
@@ -161,44 +203,75 @@
set.add(new CFThreadExitEvent(crossfire(), request, thread));
}
}
+ else {
+ return null;
+ }
if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_CONTEXT_DESTROYED+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_CONTEXT_DESTROYED+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
- else if(Event.ON_CONSOLE_DEBUG.equals(name)) {
- if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_CONSOLE_DEBUG+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ else if(CFEventPacket.ON_CONSOLE_DEBUG.equals(name)) {
+ List info = (List) event.getBody().get(Attributes.DATA);
+ if(info != null) {
+ log(IStatus.INFO, info);
}
+ if(TRACE) {
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_CONSOLE_DEBUG+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
}
- else if(Event.ON_CONSOLE_ERROR.equals(name)) {
- if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_CONSOLE_ERROR+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ else if(CFEventPacket.ON_CONSOLE_ERROR.equals(name)) {
+ List info = (List) event.getBody().get(Attributes.VALUE);
+ if(info != null) {
+ log(IStatus.ERROR, info);
}
+ if(TRACE) {
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_CONSOLE_ERROR+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
}
- else if(Event.ON_CONSOLE_INFO.equals(name)) {
- if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_CONSOLE_INFO+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ else if(CFEventPacket.ON_CONSOLE_INFO.equals(name)) {
+ List info = (List) event.getBody().get(Attributes.DATA);
+ if(info != null) {
+ log(IStatus.INFO, info);
}
+ if(TRACE) {
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_CONSOLE_INFO+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
}
- else if(Event.ON_CONSOLE_LOG.equals(name)) {
- if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_CONSOLE_LOG+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ else if(CFEventPacket.ON_CONSOLE_LOG.equals(name)) {
+ List info = (List) event.getBody().get(Attributes.DATA);
+ if(info != null) {
+ log(IStatus.INFO, info);
}
+ if(TRACE) {
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_CONSOLE_LOG+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
}
- else if(Event.ON_CONSOLE_WARN.equals(name)) {
- if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_CONSOLE_WARN+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ else if(CFEventPacket.ON_CONSOLE_WARN.equals(name)) {
+ List info = (List) event.getBody().get(Attributes.DATA);
+ if(info != null) {
+ log(IStatus.WARNING, info);
}
+ if(TRACE) {
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_CONSOLE_WARN+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
}
- else if(Event.ON_INSPECT_NODE.equals(name)) {
+ else if(CFEventPacket.ON_INSPECT_NODE.equals(name)) {
if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_INSPECT_NODE+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_INSPECT_NODE+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
}
+ return null;
}
- else if(Event.ON_TOGGLE_BREAKPOINT.equals(name)) {
+ else if(CFEventPacket.ON_TOGGLE_BREAKPOINT.equals(name)) {
+ crossfire().toggleBreakpoint(event.getBody());
if(TRACE) {
- Tracing.writeString("QUEUE [event - "+Event.ON_TOGGLE_BREAKPOINT+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
+ Tracing.writeString("QUEUE [event - "+CFEventPacket.ON_TOGGLE_BREAKPOINT+"] "+JSON.serialize(event)); //$NON-NLS-1$ //$NON-NLS-2$
}
+ return null;
}
else {
if(TRACE) {
@@ -217,7 +290,7 @@
Tracing.writeString("QUEUE [disconnect exception]: "+de.getMessage()); //$NON-NLS-1$
}
crossfire().disconnectVM();
- handleException(de.getMessage(), de);
+ handleException(de.getMessage(), (de.getCause() == null ? de : de.getCause()));
}
catch(TimeoutException te) {
CrossFirePlugin.log(te);
@@ -226,6 +299,52 @@
}
/**
+ * Logs the entry from the queue
+ *
+ * @param kind
+ * @param objects
+ */
+ void log(int kind, List objects) {
+ IStatus status = null;
+ if(objects.size() > 1) {
+ MultiStatus mstatus = new MultiStatus(CrossFirePlugin.PLUGIN_ID, kind, "Messages logged from Crossfire", null); //$NON-NLS-1$
+ for (Iterator i = objects.iterator(); i.hasNext();) {
+ mstatus.add(new Status(kind, CrossFirePlugin.PLUGIN_ID, i.next().toString()));
+ }
+ status = mstatus;
+ }
+ else if(objects.size() == 1) {
+ status = new Status(kind, CrossFirePlugin.PLUGIN_ID, objects.iterator().next().toString());
+ }
+ if(status != null) {
+ CrossFirePlugin.log(status);
+ }
+ }
+
+ /**
+ * Handles a context created, loaded, and changed event
+ * @param set the {@link EventSet} to add to
+ * @param event the {@link CFEventPacket} received
+ * @param lookup if we should try to lookup the {@link ThreadReference} before creating a new one
+ */
+ void handleContext(CFEventSet set, CFEventPacket event, boolean lookup) {
+ List threads = eventmgr.threadEnterRequests();
+ CFThreadReference thread = null;
+ String context = event.getContextId();
+ if(lookup) {
+ thread = crossfire().findThread(context);
+ }
+ if(thread == null) {
+ thread = crossfire().addThread(context, (String) event.getBody().get(Attributes.URL));
+ }
+ set.setThread(thread);
+ for (Iterator iter = threads.iterator(); iter.hasNext();) {
+ ThreadEnterRequest request = (ThreadEnterRequest) iter.next();
+ set.add(new CFThreadEnterEvent(crossfire(), request, thread));
+ }
+ }
+
+ /**
* Flushes and cleans up the queue
*/
public void dispose() {
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEventSet.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEventSet.java
index f1d2a90..a057d35 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEventSet.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFEventSet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.crossfire.event;
-import java.util.HashSet;
+import java.util.ArrayList;
import org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference;
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
@@ -21,7 +21,7 @@
*
* @since 1.0
*/
-public class CFEventSet extends HashSet implements EventSet {
+public class CFEventSet extends ArrayList implements EventSet {
private VirtualMachine vm = null;
private ThreadReference thread = null;
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFResumeEvent.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFResumeEvent.java
new file mode 100644
index 0000000..4be5160
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/event/CFResumeEvent.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.event;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.Location;
+import org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference;
+import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
+import org.eclipse.wst.jsdt.debug.core.jsdi.event.ResumeEvent;
+import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequest;
+
+/**
+ * Crossfire implementation of {@link ResumeEvent}
+ *
+ * @since 1.0
+ */
+public class CFResumeEvent extends CFLocatableEvent implements ResumeEvent {
+
+ /**
+ * Constructor
+ * @param vm
+ * @param request
+ * @param thread
+ * @param location
+ */
+ public CFResumeEvent(VirtualMachine vm, EventRequest request, ThreadReference thread, Location location) {
+ super(vm, request, thread, location);
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFEventRequestManager.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFEventRequestManager.java
index a90c2b0..e50b6e1 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFEventRequestManager.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFEventRequestManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,6 +24,7 @@
import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequest;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequestManager;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.ExceptionRequest;
+import org.eclipse.wst.jsdt.debug.core.jsdi.request.ResumeRequest;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.ScriptLoadRequest;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.StepRequest;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.SuspendRequest;
@@ -36,6 +37,7 @@
import org.eclipse.wst.jsdt.debug.internal.crossfire.request.CFDebuggerRequest;
import org.eclipse.wst.jsdt.debug.internal.crossfire.request.CFDisconnectRequest;
import org.eclipse.wst.jsdt.debug.internal.crossfire.request.CFExceptionRequest;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.request.CFResumeRequest;
import org.eclipse.wst.jsdt.debug.internal.crossfire.request.CFScriptLoadRequest;
import org.eclipse.wst.jsdt.debug.internal.crossfire.request.CFStepRequest;
import org.eclipse.wst.jsdt.debug.internal.crossfire.request.CFSuspendRequest;
@@ -57,6 +59,7 @@
private List loads = Collections.synchronizedList(new ArrayList(4));
private List steps = Collections.synchronizedList(new ArrayList(4));
private List suspends = Collections.synchronizedList(new ArrayList(4));
+ private List resumes = Collections.synchronizedList(new ArrayList(4));
private List disconnects = Collections.synchronizedList(new ArrayList(4));
private List deaths = Collections.synchronizedList(new ArrayList(4));
@@ -77,6 +80,7 @@
kind.put(CFScriptLoadRequest.class, loads);
kind.put(CFStepRequest.class, steps);
kind.put(CFSuspendRequest.class, suspends);
+ kind.put(CFResumeRequest.class, resumes);
kind.put(CFThreadEnterRequest.class, threadenters);
kind.put(CFThreadExitRequest.class, threadexits);
kind.put(CFDisconnectRequest.class, disconnects);
@@ -88,7 +92,6 @@
*/
public BreakpointRequest createBreakpointRequest(Location location) {
CFBreakpointRequest request = new CFBreakpointRequest(vm, location);
- request.setEnabled(true);
breakpoints.add(request);
return request;
}
@@ -105,7 +108,6 @@
*/
public DebuggerStatementRequest createDebuggerStatementRequest() {
CFDebuggerRequest request = new CFDebuggerRequest(vm);
- request.setEnabled(true);
debuggers.add(request);
return request;
}
@@ -122,7 +124,6 @@
*/
public ExceptionRequest createExceptionRequest() {
CFExceptionRequest request = new CFExceptionRequest(vm);
- request.setEnabled(true);
exceptions.add(request);
return request;
}
@@ -139,7 +140,6 @@
*/
public ScriptLoadRequest createScriptLoadRequest() {
CFScriptLoadRequest request = new CFScriptLoadRequest(vm);
- request.setEnabled(true);
loads.add(request);
return request;
}
@@ -156,7 +156,6 @@
*/
public StepRequest createStepRequest(ThreadReference thread, int step) {
CFStepRequest request = new CFStepRequest(vm, thread, step);
- request.setEnabled(true);
steps.add(request);
return request;
}
@@ -174,7 +173,6 @@
*/
public SuspendRequest createSuspendRequest(ThreadReference thread) {
CFSuspendRequest request = new CFSuspendRequest(vm, thread);
- request.setEnabled(true);
suspends.add(request);
return request;
}
@@ -187,11 +185,26 @@
}
/* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequestManager#createResumeRequest(org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference)
+ */
+ public ResumeRequest createResumeRequest(ThreadReference thread) {
+ CFResumeRequest request = new CFResumeRequest(vm, thread);
+ resumes.add(request);
+ return request;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequestManager#resumeRequests()
+ */
+ public List resumeRequests() {
+ return Collections.unmodifiableList(resumes);
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequestManager#createThreadEnterRequest()
*/
public ThreadEnterRequest createThreadEnterRequest() {
CFThreadEnterRequest request = new CFThreadEnterRequest(vm);
- request.setEnabled(true);
threadenters.add(request);
return request;
}
@@ -208,7 +221,6 @@
*/
public ThreadExitRequest createThreadExitRequest() {
CFThreadExitRequest request = new CFThreadExitRequest(vm);
- request.setEnabled(true);
threadexits.add(request);
return request;
}
@@ -245,7 +257,6 @@
*/
public VMDeathRequest createVMDeathRequest() {
CFDeathRequest request = new CFDeathRequest(vm);
- request.setEnabled(true);
deaths.add(request);
return request;
}
@@ -262,7 +273,6 @@
*/
public VMDisconnectRequest createVMDisconnectRequest() {
CFDisconnectRequest request = new CFDisconnectRequest(vm);
- request.setEnabled(true);
disconnects.add(request);
return request;
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFFunctionReference.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFFunctionReference.java
index 99fc530..80a8d99 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFFunctionReference.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFFunctionReference.java
@@ -13,6 +13,7 @@
import java.util.Map;
import org.eclipse.wst.jsdt.debug.core.jsdi.FunctionReference;
+import org.eclipse.wst.jsdt.debug.core.jsdi.Value;
/**
* Default implementation of {@link FunctionReference} for Crossfire
@@ -28,6 +29,7 @@
private String funcname = null;
+
/**
* Constructor
* @param vm
@@ -42,6 +44,12 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.FunctionReference#functionName()
*/
public String functionName() {
+ synchronized (frame()) {
+ if(funcname == null) {
+ Value val = frame().lookup(id());
+ System.out.println(val);
+ }
+ }
return funcname;
}
@@ -49,6 +57,16 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.FunctionReference#functionBody()
*/
public String functionBody() {
- return null;
+ return source();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi.CFObjectReference#valueString()
+ */
+ public String valueString() {
+ if(source() != null) {
+ return source();
+ }
+ return FUNCTION;
}
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFNumberValue.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFNumberValue.java
index 09e08ce..8ad4724 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFNumberValue.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFNumberValue.java
@@ -19,7 +19,20 @@
* @since 1.0
*/
public class CFNumberValue extends CFMirror implements NumberValue {
-
+
+ /**
+ * Object representing 'Not a Number'
+ */
+ public static final Double NAN_OBJ = new Double(Double.NaN);
+ /**
+ * Object representing '-Infinity'
+ */
+ public static final Double NEG_INFINITY_OBJ = new Double(Double.NEGATIVE_INFINITY);
+ /**
+ * Object representing 'Infinity'
+ */
+ public static final Double INFINITY_OBJ = new Double(Double.POSITIVE_INFINITY);
+
private Number number = null;
/**
@@ -29,9 +42,34 @@
*/
public CFNumberValue(VirtualMachine vm, Number number) {
super(vm);
- this.number = number;
+ if(number != null) {
+ this.number = number;
+ }
+ else {
+ this.number = NAN_OBJ;
+ }
}
+ /**
+ * Constructor
+ * @param vm the backing {@link VirtualMachine}
+ * @param number the name of the number
+ * @see #INFINITY
+ * @see #NEG_INFINTY
+ */
+ public CFNumberValue(VirtualMachine vm, String number) {
+ super(vm);
+ if(INFINITY.equals(number)) {
+ this.number = INFINITY_OBJ;
+ }
+ else if(NEG_INFINITY.equals(number)) {
+ this.number = NEG_INFINITY_OBJ;
+ }
+ if(this.number == null) {
+ this.number = NAN_OBJ;
+ }
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.PrimitiveValue#intValue()
*/
@@ -78,6 +116,6 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.NumberValue#isNaN()
*/
public boolean isNaN() {
- return number == null;
+ return Double.isNaN(this.number.doubleValue());
}
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFObjectReference.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFObjectReference.java
index be7071d..a54fd0f 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFObjectReference.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFObjectReference.java
@@ -10,10 +10,14 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.wst.jsdt.debug.core.jsdi.ObjectReference;
+import org.eclipse.wst.jsdt.debug.core.jsdi.StackFrame;
import org.eclipse.wst.jsdt.debug.core.jsdi.Value;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Attributes;
@@ -32,9 +36,12 @@
private CFStackFrame frame = null;
private String classname = null;
private Number handle = null;
+ private Number constref = null;
+ private Number protoref = null;
private Value constructor = null;
private Value prototype = null;
private List properties = null;
+ private String source = null;
/**
* Constructor
@@ -46,13 +53,56 @@
super(vm);
this.frame = frame;
handle = (Number) body.get(Attributes.HANDLE);
+ source = (String) body.get(Attributes.SOURCE);
+ //init properties - we are dealing with evaluation results
+ Map props = (Map) body.get(Attributes.RESULT);
+ if(props == null) {
+ Object o = body.get(Attributes.VALUE);
+ if(o instanceof Map) {
+ props = (Map) body.get(Attributes.VALUE);
+ }
+ else if(this.handle == null) {
+ props = body;
+ }
+ }
+ if(props != null) {
+ if(properties == null) {
+ properties = new ArrayList(props.size());
+ }
+ Entry entry = null;
+ String name = null;
+ Map json = null;
+ Number ref = null;
+ for(Iterator i = props.entrySet().iterator(); i.hasNext();) {
+ entry = (Entry) i.next();
+ name = (String)entry.getKey();
+ if(entry.getValue() instanceof Map) {
+ json = (Map) entry.getValue();
+ ref = (Number) json.get(Attributes.HANDLE);
+ //don't add constructor and proto to the properties heap
+ //they are requested specially
+ if(Attributes.CONSTRUCTOR.equals(name)) {
+ constref = ref;
+ continue;
+ }
+ else if(Attributes.PROTO.equals(name)) {
+ protoref = ref;
+ continue;
+ }
+ }
+ properties.add(new CFVariable(crossfire(), frame, name, ref, json));
+ }
+ }
}
-
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.Value#valueString()
*/
public String valueString() {
- return null;
+ if(source != null) {
+ return source;
+ }
+ return OBJECT;
}
/* (non-Javadoc)
@@ -68,7 +118,10 @@
public Value constructor() {
synchronized (frame) {
if(constructor == null) {
- //TODO
+ if(constref == null) {
+ constructor = crossfire().mirrorOfUndefined();
+ }
+ constructor = frame.lookup(constref);
}
}
return constructor;
@@ -80,7 +133,10 @@
public Value prototype() {
synchronized (frame) {
if(prototype == null) {
- //TODO
+ if(protoref == null) {
+ prototype = crossfire().mirrorOfUndefined();
+ }
+ prototype = frame.lookup(protoref);
}
}
return prototype;
@@ -90,18 +146,27 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.ObjectReference#properties()
*/
public List properties() {
- synchronized (frame) {
- if(properties == null) {
- //TODO
- }
- }
return properties;
}
/* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.core.jsdi.ObjectReference#id()
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.ObjectReference#handle()
*/
public Number id() {
return handle;
}
+
+ /**
+ * @return the backing {@link StackFrame}
+ */
+ protected CFStackFrame frame() {
+ return this.frame;
+ }
+
+ /**
+ * @return the source for the body of the object, or <code>null</code>
+ */
+ protected String source() {
+ return this.source;
+ }
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFProperty.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFProperty.java
index 10386a1..90ba96f 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFProperty.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFProperty.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi;
+import org.eclipse.wst.jsdt.debug.core.jsdi.NullValue;
import org.eclipse.wst.jsdt.debug.core.jsdi.Property;
import org.eclipse.wst.jsdt.debug.core.jsdi.Value;
@@ -46,14 +47,20 @@
public String name() {
return this.name;
}
-
+
/**
- * Returns the handle reference for this property
+ * Allows the value to be set. Passing in <code>null</code> for <code>newvalue</code> will result
+ * in {@link #value} being set to {@link NullValue}
*
- * @return the handle reference
+ * @param newvalue
*/
- public Number ref() {
- return this.ref;
+ protected void setValue(Value newvalue) {
+ if(newvalue == null) {
+ this.value = crossfire().mirrorOfNull();
+ }
+ else {
+ this.value = newvalue;
+ }
}
/* (non-Javadoc)
@@ -66,7 +73,9 @@
this.value = crossfire().mirrorOfUndefined();
}
}
+ if(this.value == null) {
+ return crossfire().mirrorOfUndefined();
+ }
return this.value;
}
-
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFScriptReference.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFScriptReference.java
index 8f7cf34..873a157 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFScriptReference.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFScriptReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,11 +13,13 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.URIUtil;
import org.eclipse.wst.jsdt.debug.core.jsdi.Location;
import org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference;
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
@@ -26,8 +28,8 @@
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Attributes;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Commands;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.JSON;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Request;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Response;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFRequestPacket;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFResponsePacket;
/**
* Default implementation of {@link ScriptReference} for Crossfire
@@ -37,8 +39,7 @@
public class CFScriptReference extends CFMirror implements ScriptReference {
private String context_id = null;
- private String context_href = null;
- private String id = null;
+ private String url = null;
private int srclength = 0;
private int linecount = 0;
private int coloffset = 0;
@@ -57,17 +58,7 @@
public CFScriptReference(VirtualMachine vm, String context_id, Map json) {
super(vm);
this.context_id = context_id;
- //try "href" first -> CF 0.2 support
- this.id = (String) json.get(Attributes.HREF);
- if(id == null) {
- //try "data" next -> CF 0.1a3 support
- this.id = (String) json.get(Attributes.DATA);
- }
- if(this.id == null) {
- //try "id" last -> CF 0.1 support
- this.id = (String) json.get(Attributes.ID);
- }
- this.context_href = (String) json.get(Attributes.CONTEXT_HREF);
+ this.url = (String) json.get(Attributes.URL);
initializeScript(json);
}
@@ -94,6 +85,19 @@
this.coloffset = value.intValue();
}
source = (String) json.get(Attributes.SOURCE);
+ prepareLocations(linecount);
+ }
+
+ /**
+ * Creates the line locations
+ *
+ * @param lines
+ */
+ void prepareLocations(int lines) {
+ linelocs.clear(); //remove old line infos
+ for (int i = 1; i <= lines; i++) {
+ linelocs.add(new CFLocation(virtualMachine(), this, null, i));
+ }
}
/* (non-Javadoc)
@@ -107,6 +111,9 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference#lineLocation(int)
*/
public Location lineLocation(int lineNumber) {
+ if(lineNumber <= linelocs.size()) {
+ return (Location) linelocs.get(lineNumber-1);
+ }
return null;
}
@@ -125,22 +132,11 @@
}
/**
- * The id of the script
- * @return the id
+ * The url of the script
+ * @return the url
*/
- public String id() {
- return id;
- }
-
- /**
- * The HTTP context of the script, if any.
- * <br><br>
- * This method can return <code>null</code>
- *
- * @return the HTTP context of the script or null
- */
- public String hrefContext() {
- return context_href;
+ public String url() {
+ return url;
}
/**
@@ -159,12 +155,15 @@
*/
public synchronized String source() {
if(source == null) {
- Request request = new Request(Commands.SCRIPT, context_id);
+ CFRequestPacket request = new CFRequestPacket(Commands.SCRIPTS, context_id);
request.setArgument(Attributes.INCLUDE_SOURCE, Boolean.TRUE);
- request.setArgument(Attributes.URL, id);
- Response response = crossfire().sendRequest(request);
+ request.setArgument(Attributes.URLS, Arrays.asList(new String[] {url}));
+ CFResponsePacket response = crossfire().sendRequest(request);
if(response.isSuccess()) {
- initializeScript((Map) response.getBody().get(Attributes.SCRIPT));
+ List list = (List)response.getBody().get(Attributes.SCRIPTS);
+ if (list != null && list.size() > 0) {
+ initializeScript((Map)list.get(0));
+ }
}
else if(TRACE) {
Tracing.writeString("SCRIPTREF [failed source request]: "+JSON.serialize(request)); //$NON-NLS-1$
@@ -179,15 +178,18 @@
public synchronized URI sourceURI() {
if(sourceuri == null) {
try {
- sourceuri = URI.create(id);
+ sourceuri = URIUtil.fromString(url);
}
catch(IllegalArgumentException iae) {
try {
- sourceuri = CrossFirePlugin.fileURI(new Path(id));
+ sourceuri = CrossFirePlugin.fileURI(new Path(url));
} catch (URISyntaxException e) {
CrossFirePlugin.log(e);
}
}
+ catch(URISyntaxException urise) {
+ CrossFirePlugin.log(urise);
+ }
}
return sourceuri;
}
@@ -198,8 +200,7 @@
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("ScriptReference: [context_id - ").append(context_id).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
- buffer.append(" [context_href - ").append(context_href).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
- buffer.append(" [id - ").append(id).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ buffer.append(" [url - ").append(url).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
buffer.append(" [srclength - ").append(srclength).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
buffer.append(" [linecount - ").append(linecount).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
buffer.append(" [lineoffset - ").append(lineoffset).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFStackFrame.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFStackFrame.java
index 8e8ff12..22935a8 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFStackFrame.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFStackFrame.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,23 +11,26 @@
package org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.wst.jsdt.debug.core.jsdi.Location;
+import org.eclipse.wst.jsdt.debug.core.jsdi.NullValue;
import org.eclipse.wst.jsdt.debug.core.jsdi.StackFrame;
import org.eclipse.wst.jsdt.debug.core.jsdi.Value;
import org.eclipse.wst.jsdt.debug.core.jsdi.Variable;
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
import org.eclipse.wst.jsdt.debug.internal.crossfire.Tracing;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Attributes;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFRequestPacket;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFResponsePacket;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Commands;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.JSON;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Request;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Response;
/**
* Default implementation of {@link StackFrame} for Crossfire
@@ -37,22 +40,22 @@
public class CFStackFrame extends CFMirror implements StackFrame {
private int index = -1;
- String context_id = null;
- private String scriptid = null;
+ private String scriptUrl = null;
private String funcname = null;
private int linenumber = -1;
private List vars = null;
private Variable thisvar = null;
private CFLocation loc = null;
+ private CFThreadReference thread = null;
/**
* Constructor
* @param vm
* @param json
*/
- public CFStackFrame(VirtualMachine vm, Map json) {
+ public CFStackFrame(VirtualMachine vm, CFThreadReference thread, Map json) {
super(vm);
- context_id = (String) json.get(Attributes.CONTEXT_ID);
+ this.thread = thread;
Number value = (Number) json.get(Attributes.INDEX);
if(value != null) {
index = value.intValue();
@@ -61,51 +64,78 @@
if(value != null) {
linenumber = value.intValue();
}
- scriptid = (String) json.get(Attributes.SCRIPT);
- funcname = (String) json.get(Attributes.FUNC);
+ scriptUrl = (String) json.get(Attributes.URL);
+ funcname = (String) json.get(Attributes.FUNCTION_NAME);
+
parseLocals((Map) json.get(Attributes.LOCALS));
+ parseScopes((List) json.get(Attributes.SCOPES));
}
/**
- * Read the local variable information from the json mapping
+ * Parses the scopes object node, if there is one
+ *
+ * @param list the list of scopes
+ */
+ void parseScopes(List list) {
+ if(list != null) {
+ if(vars == null) {
+ vars = new ArrayList(list.size());
+ }
+ for (Iterator i = list.iterator(); i.hasNext();) {
+ Map map = (Map) i.next();
+ Map scope = (Map)map.get(Attributes.SCOPE);
+ if(scope != null) {
+ vars.add(0, new CFVariable(crossfire(), this, "Enclosing Scope", (Number) scope.get(Attributes.HANDLE), scope)); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ /**
+ * Read the local variable information from the JSON mapping
*
* @param json
*/
void parseLocals(Map json) {
if(json != null) {
- Map locals = (Map) json.get(Attributes.VALUE);
- if(locals != null) {
- if(locals.containsKey(Attributes.VALUE)) {
- //do CF 0.1 parsing
- locals = (Map) locals.get(Attributes.VALUE);
- if(locals.size() < 1) {
- vars = Collections.EMPTY_LIST;
- return;
- }
- }
- vars = new ArrayList(locals.size());
- Entry entry = null;
- for (Iterator iter = locals.entrySet().iterator(); iter.hasNext();) {
- entry = (Entry) iter.next();
- Map info = (Map) entry.getValue();
- String name = (String) entry.getKey();
- Object handle = info.get(Attributes.HANDLE);
- Number ref = null;
- if(handle instanceof Number) {
- ref = (Number) handle;
- }
- else if(handle instanceof String) {
- ref = new Integer((String)handle);
- }
- vars.add(new CFVariable(crossfire(), this, name, ref, false));
+ Object val = json.get(Attributes.VALUE);
+ if(val instanceof Map) {
+ Map locals = (Map) json.get(Attributes.VALUE);
+ if(locals != null) {
+ vars = new ArrayList(locals.size());
+ parseVariables(locals, vars);
}
}
+ else {
+ vars = new ArrayList();
+ }
Map thismap = (Map) json.get(Attributes.THIS);
- if(thismap != null) {
- if(vars == null) {
- vars = new ArrayList(2);
- }
- thisvar = new CFVariable(crossfire(), this, Attributes.THIS, null, false);
+ thisvar = new CFVariable(crossfire(), this, Attributes.THIS, null, (thismap == null ? new HashMap(0) : thismap));
+ }
+ }
+
+ void parseVariables(Map map, List varcollector) {
+ Entry entry = null;
+ for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
+ entry = (Entry) iter.next();
+ if(entry.getValue() instanceof Map) {
+ Map info = (Map) entry.getValue();
+ varcollector.add(
+ new CFVariable(
+ crossfire(),
+ this,
+ (String) entry.getKey(),
+ (Number) info.get(Attributes.HANDLE),
+ info));
+ }
+ else {
+ varcollector.add(
+ new CFVariable(
+ crossfire(),
+ this,
+ (String) entry.getKey(),
+ null,
+ null));
}
}
}
@@ -132,7 +162,7 @@
*/
public synchronized Location location() {
if(loc == null) {
- CFScriptReference script = crossfire().findScript(scriptid);
+ CFScriptReference script = crossfire().findScript(scriptUrl);
if(script != null) {
loc = new CFLocation(crossfire(), script, funcname, linenumber);
}
@@ -144,17 +174,17 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.StackFrame#evaluate(java.lang.String)
*/
public Value evaluate(String expression) {
- Request request = new Request(Commands.EVALUATE, context_id);
- request.setArgument(Attributes.FRAME, new Integer(index));
+ CFRequestPacket request = new CFRequestPacket(Commands.EVALUATE, thread.id());
+ request.setArgument(Attributes.FRAME_INDEX, new Integer(index));
request.setArgument(Attributes.EXPRESSION, expression);
- Response response = crossfire().sendRequest(request);
+ CFResponsePacket response = crossfire().sendRequest(request);
if(response.isSuccess()) {
- return createValue(response.getBody());
+ return createValue(response.getBody().get(Attributes.RESULT));
}
else if(TRACE) {
Tracing.writeString("STACKFRAME [failed evaluate request]: "+JSON.serialize(request)); //$NON-NLS-1$
}
- return null;
+ return virtualMachine().mirrorOfNull();
}
/**
@@ -174,17 +204,21 @@
*/
public Value lookup(Number ref) {
if(ref != null) {
- Request request = new Request(Commands.LOOKUP, context_id);
- request.setArgument(Attributes.HANDLE, ref);
- Response response = crossfire().sendRequest(request);
+ CFRequestPacket request = new CFRequestPacket(Commands.LOOKUP, thread.id());
+ request.setArgument(Attributes.HANDLES, Arrays.asList(new Number[] {ref}));
+ request.setArgument(Attributes.INCLUDE_SOURCE, Boolean.TRUE);
+ CFResponsePacket response = crossfire().sendRequest(request);
if(response.isSuccess()) {
- return createValue(response.getBody());
+ List list = (List)response.getBody().get(Attributes.VALUES);
+ if (list != null && list.size() > 0) {
+ return createValue(list.get(0));
+ }
}
else if(TRACE) {
Tracing.writeString("STACKFRAME [request for value lookup failed]: "+JSON.serialize(request)); //$NON-NLS-1$
}
}
- return null;
+ return crossfire().mirrorOfNull();
}
/**
@@ -192,47 +226,62 @@
* @param json
* @return the new {@link Value} or <code>null</code> if one could not be created
*/
- Value createValue(Map json) {
+ Value createValue(Object val) {
//resolve the smallest type from the crossfire insanity
- Map smallest = json;
- Object o = json.get(Attributes.VALUE);
- if(o instanceof Map) {
- Map temp = smallest;
- while(temp != null) {
- temp = (Map) temp.get(Attributes.VALUE);
- if(temp != null && temp.containsKey(Attributes.VALUE)) {
- smallest = temp;
- }
+ if(val instanceof Map) {
+ Map values = (Map) val;
+ String type = (String) values.get(Attributes.TYPE);
+ if(type != null) {
+ return createTypeValue(type, values);
}
}
- Object tobj = smallest.get(Attributes.TYPE);
- String type = null;
- if(tobj instanceof String) {
- type = (String) tobj;
+ else if(val instanceof String) {
+ String str = (String) val;
+ if(CFUndefinedValue.UNDEFINED.equals(str)) {
+ return crossfire().mirrorOfUndefined();
+ }
+ return crossfire().mirrorOf((String) val);
}
- else if(tobj instanceof Map) {
- type = (String) ((Map)tobj).get(Attributes.TYPE);
+ else if(val instanceof Number) {
+ return crossfire().mirrorOf((Number) val);
}
+ return crossfire().mirrorOfNull();
+ }
+
+ /**
+ * Create a new {@link Value} based on the given type
+ *
+ * @param type the type
+ * @param map the map of value information
+ * @return the new {@link Value} for the given type or {@link NullValue} if a value cannot be computed
+ */
+ Value createTypeValue(String type, Map map) {
if(CFUndefinedValue.UNDEFINED.equals(type)) {
return crossfire().mirrorOfUndefined();
}
- if(CFNullValue.NULL.equals(type) || type == null) {
- return crossfire().mirrorOfNull();
+ if(Attributes.NUMBER.equals(type)) {
+ //could be NaN, Infinity or -Infinity, check for strings
+ Object o = map.get(Attributes.VALUE);
+ if(o instanceof Number) {
+ return crossfire().mirrorOf((Number)o);
+ }
+ if(o instanceof String) {
+ return crossfire().mirrorOf((String)o);
+ }
}
if(CFStringValue.STRING.equals(type)) {
- //TODO
- return crossfire().mirrorOf(smallest.get(Attributes.VALUE).toString());
+ return crossfire().mirrorOf(map.get(Attributes.VALUE).toString());
}
- if(CFObjectReference.OBJECT.equals(type)) {
- return new CFObjectReference(crossfire(), this, json);
+ if(CFObjectReference.OBJECT.equals(type) || Attributes.REF.equals(type)) {
+ return new CFObjectReference(crossfire(), this, map);
}
if(CFArrayReference.ARRAY.equals(type)) {
- return new CFArrayReference(crossfire(), this, json);
+ return new CFArrayReference(crossfire(), this, map);
}
if(CFFunctionReference.FUNCTION.equals(type)) {
- return new CFFunctionReference(crossfire(), this, json);
+ return new CFFunctionReference(crossfire(), this, map);
}
- return null;
+ return crossfire().mirrorOfNull();
}
/**
@@ -244,4 +293,45 @@
public synchronized boolean isVisible(CFVariable variable) {
return vars != null && (thisvar == variable || vars.contains(variable));
}
+
+ /**
+ * Gets all of the scopes from Firebug
+ */
+ void allScopes() {
+ CFRequestPacket request = new CFRequestPacket(Commands.SCOPES, thread.id());
+ request.setArgument(Attributes.FRAME_INDEX, new Integer(index));
+ CFResponsePacket response = crossfire().sendRequest(request);
+ if(response.isSuccess()) {
+ List list = (List) response.getBody().get(Attributes.SCOPES);
+ if(list != null) {
+ parseScopes(list);
+ }
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed scopes request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Gets the scope for this frame
+ */
+ void scope(int frameindex, int scopeindex) {
+ CFRequestPacket request = new CFRequestPacket(Commands.SCOPES, thread.id());
+ request.setArgument(Attributes.FRAME_INDEX, new Integer(frameindex));
+ request.setArgument(Attributes.SCOPE_INDEXES, Arrays.asList(new Number[] {new Integer(scopeindex)}));
+ CFResponsePacket response = crossfire().sendRequest(request);
+ if(response.isSuccess()) {
+ if(vars == null) {
+ vars = new ArrayList();
+ }
+ List list = (List)response.getBody().get(Attributes.SCOPES);
+ if (list != null && list.size() > 0) {
+ Map scope = ((Map)list.get(0));
+ vars.add(0, new CFVariable(crossfire(), this, "Enclosing Scope", (Number) scope.get(Attributes.HANDLE), scope)); //$NON-NLS-1$
+ }
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed scopes request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFThreadReference.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFThreadReference.java
index 45b61c5..9540015 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFThreadReference.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFThreadReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,12 +19,13 @@
import org.eclipse.wst.jsdt.debug.core.jsdi.StackFrame;
import org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference;
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
+import org.eclipse.wst.jsdt.debug.core.jsdi.request.StepRequest;
import org.eclipse.wst.jsdt.debug.internal.crossfire.Tracing;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Attributes;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFRequestPacket;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFResponsePacket;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Commands;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.JSON;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Request;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Response;
/**
* Default implementation of {@link ThreadReference} for Crossfire
@@ -36,23 +37,26 @@
static final int RUNNING = 0;
static final int SUSPENDED = 1;
static final int TERMINATED = 2;
+ static final int EVENT_RESUME = 3;
private String id = null;
- private String href = null;
+ private String url = null;
+ private boolean current = false;
private int state = RUNNING;
private ArrayList frames = null;
+ private int stepkind = -1;
/**
* Constructor
*
* @param vm
* @param id
- * @param href
+ * @param url
*/
- public CFThreadReference(VirtualMachine vm, String id, String href) {
+ public CFThreadReference(VirtualMachine vm, String id, String url) {
super(vm);
this.id = id;
- this.href = href;
+ this.url = url;
}
/**
@@ -62,8 +66,12 @@
*/
public CFThreadReference(VirtualMachine vm, Map json) {
super(vm);
- this.id = (String) json.get(Attributes.CROSSFIRE_ID);
- this.href = (String) json.get(Attributes.HREF);
+ this.id = (String) json.get(Attributes.CONTEXT_ID);
+ this.url = (String) json.get(Attributes.URL);
+ Boolean bool = (Boolean) json.get(Attributes.CURRENT);
+ if(bool != null) {
+ this.current = bool.booleanValue();
+ }
}
/* (non-Javadoc)
@@ -87,24 +95,35 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference#frames()
*/
public synchronized List frames() {
- //TODO we require some way to batch retrieve the frames from a given context
- //unless there is only ever one frame?
if(frames == null) {
- Request request = new Request(Commands.BACKTRACE, id);
+ CFRequestPacket request = new CFRequestPacket(Commands.BACKTRACE, id);
request.setArgument(Attributes.FROM_FRAME, new Integer(0));
request.setArgument(Attributes.INCLUDE_SCOPES, Boolean.TRUE);
- Response response = crossfire().sendRequest(request);
+ CFResponsePacket response = crossfire().sendRequest(request);
if(response.isSuccess()) {
frames = new ArrayList();
ArrayList frms = (ArrayList) response.getBody().get(Attributes.FRAMES);
- for (int i = 0; i < frms.size(); i++) {
- frames.add(new CFStackFrame(virtualMachine(), (Map) frms.get(i)));
+ if(frms != null) {
+ Map fmap = null;
+ for (int i = 0; i < frms.size(); i++) {
+ fmap = (Map) frms.get(i);
+ //XXX hack to prevent http://code.google.com/p/fbug/issues/detail?id=4203
+ if(fmap.containsKey(Attributes.URL)) {
+ frames.add(new CFStackFrame(virtualMachine(), this, fmap));
+ }
+ else if(TRACE) {
+ Tracing.writeString("STACKFRAME [got bogus stackframe infos]: "+fmap.values().toString()); //$NON-NLS-1$
+ }
+ }
}
}
else {
if(TRACE) {
Tracing.writeString("STACKFRAME [backtrace request failed]: "+JSON.serialize(request)); //$NON-NLS-1$
}
+ if(frames != null) {
+ frames.clear();
+ }
return Collections.EMPTY_LIST;
}
}
@@ -123,18 +142,40 @@
}
}
+ /**
+ * The thread has been resumed by an event
+ */
+ public void eventResume() {
+ state = EVENT_RESUME;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference#resume()
*/
public void resume() {
- Request request = new Request(Commands.CONTINUE, id);
- Response response = crossfire().sendRequest(request);
- if(response.isSuccess()) {
- clearFrames();
- state = RUNNING;
- }
- else if(TRACE) {
- Tracing.writeString("THREAD [failed continue request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ if(isSuspended()) {
+ try {
+ if(state != EVENT_RESUME) {
+ //XXX only send an request if we were not resumed by an event
+ CFRequestPacket request = new CFRequestPacket(Commands.CONTINUE, id);
+ String step = resolveStepKind();
+ if(step != null) {
+ request.setArgument(Attributes.STEPACTION, step);
+ }
+
+ CFResponsePacket response = crossfire().sendRequest(request);
+ if(response.isSuccess()) {
+ state = RUNNING;
+ }
+ else if(TRACE) {
+ Tracing.writeString("THREAD [failed continue request] "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+ }
+ finally {
+ clearFrames();
+ state = RUNNING;
+ }
}
}
@@ -142,15 +183,21 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference#suspend()
*/
public void suspend() {
- Request request = new Request(Commands.SUSPEND, id);
- Response response = crossfire().sendRequest(request);
- if(response.isSuccess()) {
- //XXX catch in case the last resume failed
- clearFrames();
- state = SUSPENDED;
- }
- else if(TRACE) {
- Tracing.writeString("THREAD [failed suspend request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ if(isRunning()) {
+ CFRequestPacket request = new CFRequestPacket(Commands.SUSPEND, id);
+ try {
+ CFResponsePacket response = crossfire().sendRequest(request);
+ if(response.isSuccess()) {
+ //XXX catch in case the last resume failed
+ state = SUSPENDED;
+ }
+ else if(TRACE) {
+ Tracing.writeString("THREAD [failed suspend request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+ finally {
+ clearFrames();
+ }
}
}
@@ -185,14 +232,17 @@
return state == SUSPENDED;
}
+ /**
+ * @return if the thread is in a running state
+ */
+ public boolean isRunning() {
+ return state == RUNNING;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference#name()
*/
public String name() {
- String url = href;
- if(href.length() > 50) {
- url = href.substring(0, 47) + "..."; //$NON-NLS-1$
- }
return NLS.bind(Messages.thread_name, new Object[] {id, url});
}
@@ -201,7 +251,7 @@
*/
public String toString() {
StringBuffer buffer = new StringBuffer();
- buffer.append("ThreadReference: [crossfire_id - ").append(id).append("] [href - ").append(href).append("]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ buffer.append("ThreadReference: [contextId - ").append(id).append("] [url - ").append(url).append("]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return buffer.toString();
}
@@ -215,12 +265,12 @@
}
/**
- * Returns the href context for this thread
+ * Returns the URL for this thread
*
- * return the href context
+ * @return the URL
*/
- public String href() {
- return href;
+ public String url() {
+ return url;
}
/**
@@ -234,4 +284,43 @@
clearFrames();
state = suspended ? SUSPENDED : RUNNING;
}
-}
+
+ /**
+ * Sets the current step kind kind to perform, or -1 to remove the kind
+ * @param stepkind
+ */
+ public void setStep(int step) {
+ this.stepkind = step;
+ }
+
+ /**
+ * @return the step kind to use in the continue request or <code>null</code>
+ */
+ String resolveStepKind() {
+ if(stepkind != -1) {
+ switch(stepkind) {
+ case StepRequest.STEP_INTO: return Commands.STEP_IN;
+ case StepRequest.STEP_OUT: return Commands.STEP_OUT;
+ case StepRequest.STEP_OVER: return Commands.STEP_NEXT;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns if the this thread is the current (focus) context in the browser
+ *
+ * @return <code>true</code> if this thread is the current (focus) context
+ */
+ public boolean isCurrent() {
+ return this.current;
+ }
+
+ /**
+ * Allows the current (focus) status of the thread to be set
+ * @param current the new current state
+ */
+ public void setCurrent(boolean current) {
+ this.current = current;
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFVariable.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFVariable.java
index e7ae37b..ce77611 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFVariable.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFVariable.java
@@ -10,8 +10,12 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi;
+import java.util.Map;
+
import org.eclipse.wst.jsdt.debug.core.jsdi.StackFrame;
+import org.eclipse.wst.jsdt.debug.core.jsdi.Value;
import org.eclipse.wst.jsdt.debug.core.jsdi.Variable;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Attributes;
/**
* Default implementation of a {@link Variable} for Crossfire
@@ -20,26 +24,59 @@
*/
public class CFVariable extends CFProperty implements Variable {
- private boolean isarg = false;
-
/**
* Constructor
+ *
* @param vm
* @param frame
* @param name
* @param ref
- * @param isarg
+ * @param values
*/
- public CFVariable(CFVirtualMachine vm, CFStackFrame frame, String name, Number ref, boolean isarg) {
+ public CFVariable(CFVirtualMachine vm, CFStackFrame frame, String name, Number ref, Map values) {
super(vm, frame, name, ref);
- this.isarg = isarg;
+ Value value = null;
+ if(values != null) {
+ String kind = (String) values.get(Attributes.TYPE);
+ //if we have a primitive type create it value now
+ if(kind != null) {
+ if(kind.equals(Attributes.STRING)) {
+ value = new CFStringValue(vm, (String) values.get(Attributes.VALUE));
+ }
+ else if(kind.equals(Attributes.NUMBER)) {
+ Object o = values.get(Attributes.VALUE);
+ if(o instanceof Number) {
+ value = new CFNumberValue(vm, (Number)o);
+ }
+ else if(o instanceof String) {
+ value = new CFNumberValue(vm, (String)o);
+ }
+ }
+ else if(kind.equals(Attributes.BOOLEAN)) {
+ value = new CFBooleanValue(vm, ((Boolean)values.get(Attributes.VALUE)).booleanValue());
+ }
+ if(Attributes.THIS.equals(name)) {
+ //special object that has no lookup so we have to pre-populate the properties
+ value = new CFObjectReference(crossfire(), frame, values);
+ }
+ if(CFUndefinedValue.UNDEFINED.equals(kind)) {
+ value = crossfire().mirrorOfUndefined();
+ }
+ }
+ }
+ else {
+ value = crossfire().mirrorOfNull();
+ }
+ if(value != null) {
+ setValue(value);
+ }
}
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.Variable#isArgument()
*/
public boolean isArgument() {
- return this.isarg;
+ return false;
}
/* (non-Javadoc)
@@ -51,5 +88,4 @@
}
return false;
}
-
-}
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFVirtualMachine.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFVirtualMachine.java
index b71f6f2..65145ad 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFVirtualMachine.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/CFVirtualMachine.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,13 +11,26 @@
package org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Vector;
-import org.eclipse.osgi.util.NLS;
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IBreakpointListener;
+import org.eclipse.debug.core.IBreakpointManager;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.wst.jsdt.core.JavaScriptCore;
+import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptLineBreakpoint;
import org.eclipse.wst.jsdt.debug.core.jsdi.BooleanValue;
import org.eclipse.wst.jsdt.debug.core.jsdi.NullValue;
import org.eclipse.wst.jsdt.debug.core.jsdi.NumberValue;
@@ -26,26 +39,29 @@
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
import org.eclipse.wst.jsdt.debug.core.jsdi.event.EventQueue;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequestManager;
+import org.eclipse.wst.jsdt.debug.core.model.JavaScriptDebugModel;
+import org.eclipse.wst.jsdt.debug.internal.core.JavaScriptDebugPlugin;
+import org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptLineBreakpoint;
import org.eclipse.wst.jsdt.debug.internal.crossfire.Constants;
import org.eclipse.wst.jsdt.debug.internal.crossfire.CrossFirePlugin;
import org.eclipse.wst.jsdt.debug.internal.crossfire.Tracing;
import org.eclipse.wst.jsdt.debug.internal.crossfire.event.CFEventQueue;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Attributes;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFEventPacket;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFRequestPacket;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFResponsePacket;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Commands;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.DebugSession;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.DisconnectedException;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Event;
import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.JSON;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Request;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Response;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.TimeoutException;
+import org.eclipse.wst.jsdt.debug.transport.DebugSession;
+import org.eclipse.wst.jsdt.debug.transport.exception.DisconnectedException;
+import org.eclipse.wst.jsdt.debug.transport.exception.TimeoutException;
/**
* Default CrossFire implementation of {@link VirtualMachine}
*
* @since 1.0
*/
-public class CFVirtualMachine extends CFMirror implements VirtualMachine {
+public class CFVirtualMachine extends CFMirror implements VirtualMachine, IBreakpointListener {
private final NullValue nullvalue = new CFNullValue(this);
private final UndefinedValue undefinedvalue = new CFUndefinedValue(this);
@@ -57,6 +73,7 @@
private Map threads = null;
private Map scripts = null;
+ private Map breakpointHandles = new HashMap();
/**
* Constructor
@@ -66,8 +83,180 @@
public CFVirtualMachine(DebugSession session) {
super();
this.session = session;
+ initializeBreakpoints();
}
+
+ /**
+ * Synchronizes the set of breakpoints between client and server
+ */
+ void initializeBreakpoints() {
+ IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
+ manager.addBreakpointListener(this);
+ IBreakpoint[] managerBreakpoints = manager.getBreakpoints(JavaScriptDebugModel.MODEL_ID);
+ Vector allBps = new Vector();
+ for (int i = 0; i < managerBreakpoints.length; i++) {
+ IBreakpoint current = managerBreakpoints[i];
+ if (current instanceof JavaScriptLineBreakpoint) {
+ try {
+ JavaScriptLineBreakpoint breakpoint = (JavaScriptLineBreakpoint)current;
+ IResource resource = breakpoint.getMarker().getResource();
+ QualifiedName qName = new QualifiedName(JavaScriptCore.PLUGIN_ID, "scriptURL"); //$NON-NLS-1$
+ String url = resource.getPersistentProperty(qName);
+ if (url == null) {
+ String path = breakpoint.getScriptPath();
+ url = JavaScriptDebugPlugin.getExternalScriptPath(new Path(path));
+ }
+
+ if (url != null) {
+ Map location = new HashMap();
+ location.put(Attributes.LINE, new Integer(breakpoint.getLineNumber()));
+ location.put(Attributes.URL, url);
+ Map attributes = new HashMap();
+ if (breakpoint.isConditionEnabled()) {
+ String condition = breakpoint.getCondition();
+ if (condition != null) {
+ attributes.put(Attributes.CONDITION, condition);
+ }
+ }
+ int hitCount = breakpoint.getHitCount();
+ if (hitCount != -1) {
+ attributes.put(Attributes.HIT_COUNT, new Integer(hitCount));
+ }
+ Map bpMap = new HashMap();
+ bpMap.put(Attributes.TYPE, Attributes.LINE);
+ bpMap.put(Attributes.LOCATION, location);
+ bpMap.put(Attributes.ATTRIBUTES, attributes);
+ allBps.add(bpMap);
+ }
+ } catch (CoreException e) {
+ CrossFirePlugin.log(e);
+ }
+ }
+ }
+ if (allBps.size() > 0) {
+ CFRequestPacket request = new CFRequestPacket(Commands.SET_BREAKPOINTS, null);
+ request.setArgument(Attributes.BREAKPOINTS, Arrays.asList(allBps.toArray()));
+ CFResponsePacket response = ((CFVirtualMachine)virtualMachine()).sendRequest(request);
+ if (!response.isSuccess()) {
+ if(TRACE) {
+ Tracing.writeString("VM [failed setbreakpoints request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+ }
+
+ CFRequestPacket request = new CFRequestPacket(Commands.GET_BREAKPOINTS, null);
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ List list = (List) response.getBody().get(Attributes.BREAKPOINTS);
+ Map bp = null;
+ for (Iterator i = list.iterator(); i.hasNext();) {
+ bp = (Map) i.next();
+ addBreakpoint(bp);
+ }
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed getbreakpoints request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Sends the <code>getbreakpoint</code> request for the given breakpoint handle
+ * @param handle
+ * @return the {@link RemoteBreakpoint} representing the request or <code>null</code> if the breakpoint could not be found
+ */
+ public RemoteBreakpoint getBreakpoint(Number handle) {
+ CFRequestPacket request = new CFRequestPacket(Commands.GET_BREAKPOINTS, null);
+ request.setArgument(Attributes.HANDLES, Arrays.asList(new Number[] {handle}));
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ List list = (List)response.getBody().get(Attributes.BREAKPOINTS);
+ if (list != null && list.size() > 0) {
+ addBreakpoint((Map)list.get(0));
+ }
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed getbreakpoint request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ return (RemoteBreakpoint) breakpointHandles.get(handle);
+ }
+
+ /**
+ * Sends the <code>changebreakpoint</code> request for the given breakpoint handle to change the given map of attributes
+ * @param handle
+ * @param attributes
+ * @return the changed {@link RemoteBreakpoint} object or <code>null</code> if the request failed
+ */
+ public RemoteBreakpoint changeBreakpoint(Number handle, Map attributes) {
+ CFRequestPacket request = new CFRequestPacket(Commands.CHANGE_BREAKPOINTS, null);
+ request.setArgument(Attributes.HANDLES, Arrays.asList(new Number[] {handle}));
+ request.setArgument(Attributes.ATTRIBUTES, attributes);
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ updateBreakpoint(response.getBody());
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed getbreakpoint request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ return (RemoteBreakpoint) breakpointHandles.get(handle);
+ }
+
+ /**
+ * Add the breakpoint described by the given JSON to the handles list
+ * @param json
+ */
+ public void addBreakpoint(Map json) {
+ if(json != null) {
+ Number handle = (Number) json.get(Attributes.HANDLE);
+ if(handle != null) {
+ RemoteBreakpoint bp = (RemoteBreakpoint) breakpointHandles.get(handle);
+ if(bp == null) {
+ bp = new RemoteBreakpoint(this,
+ handle,
+ (Map) json.get(Attributes.LOCATION),
+ (Map) json.get(Attributes.ATTRIBUTES),
+ (String)json.get(Attributes.TYPE));
+ }
+ }
+ }
+ }
+
+ /**
+ * Locates the breakpoint for the handle given in the map and updates its attributes
+ *
+ * @param json the JSON map, cannot be <code>null</code>
+ */
+ public void updateBreakpoint(Map json) {
+ if(json != null) {
+ Number handle = (Number) json.get(Attributes.HANDLE);
+ if(handle != null) {
+ RemoteBreakpoint bp = (RemoteBreakpoint) breakpointHandles.get(handle);
+ if(bp != null) {
+ bp.setEnabled(RemoteBreakpoint.getEnabled(json));
+ bp.setCondition(RemoteBreakpoint.getCondition(json));
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds or removes the breakpoint from the cache based on the <code>isset</code> attribute
+ *
+ * @param json the JSON map, cannot be <code>null</code>
+ */
+ public void toggleBreakpoint(Map json) {
+ if(json != null) {
+ Boolean isset = (Boolean)json.get(Attributes.SET);
+ if(isset != null && isset.booleanValue()) {
+ updateBreakpoint(json);
+ }
+ else {
+ Number handle = (Number) json.get(Attributes.HANDLE);
+ breakpointHandles.remove(handle);
+ }
+ }
+ }
+
/**
* @return the 'readiness' of the VM - i.e. is it in a state to process requests, etc
*/
@@ -75,29 +264,145 @@
return !disconnected;
}
+ /**
+ * Sends an <code>createcontext</code> request for the given URL and returns the status of the request.
+ *
+ * @param url the URL to open / update in the remote target, <code>null</code> is not accepted
+ * @return <code>true</code> if the request was successful, <code>false</code> otherwise
+ */
+ boolean createContext(String url) {
+ if(url != null && ready()) {
+ CFRequestPacket request = new CFRequestPacket(Commands.CREATE_CONTEXT, null);
+ request.getArguments().put(Attributes.URL, url);
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ return true;
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed createcontext request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Sends the frame request
+ * @param contextid
+ * @param index
+ * @param includescopes
+ * @return
+ */
+ CFStackFrame getFrame(String contextid, int index, boolean includescopes) {
+ if(index > -1) {
+ CFThreadReference thread = findThread(contextid);
+ if(thread != null) {
+ CFRequestPacket request = new CFRequestPacket(Commands.FRAME, thread.id());
+ request.setArgument(Attributes.INDEX, new Integer(index));
+ request.setArgument(Attributes.INCLUDE_SCOPES, new Boolean(includescopes));
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ return new CFStackFrame(this, thread, response.getBody());
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed frame request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+ }
+ return null;
+
+ }
+
+ /**
+ * Sends a request to enable the tool with the given name in the remote Crossfire server
+ *
+ * @param tools the array of tool names to enable, <code>null</code> is not allowed
+ * @return <code>true</code> if the server reports the tool became enabled, <code>false</code> otherwise
+ */
+ boolean enableTools(String[] tools) {
+ if(tools != null && tools.length > 0 && ready()) {
+ CFRequestPacket request = new CFRequestPacket(Commands.ENABLE_TOOLS, null);
+ request.getArguments().put(Attributes.TOOLS, Arrays.asList(tools));
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ //TODO handle the tool being enabled
+ return true;
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed enabletool request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Sends a request to disable the tool with the given name in the remote Crossfire server
+ *
+ * @param tools the array of tool names to disable, <code>null</code> is not allowed
+ * @return <code>true</code> if the server reports the tool became disabled, <code>false</code> otherwise
+ */
+ boolean disableTools(String[] tools) {
+ if(tools != null && tools.length > 0 && ready()) {
+ CFRequestPacket request = new CFRequestPacket(Commands.DISABLE_TOOLS, null);
+ request.getArguments().put(Attributes.TOOLS, Arrays.asList(tools));
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ //TODO handle the tool being enabled
+ return true;
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed disabletool request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns the complete listing of tools from Crossfire regardless of their enabled state.
+ *
+ * @return the listing of tools or an empty list, never <code>null</code>
+ */
+ List allTools() {
+ if(ready()) {
+ CFRequestPacket request = new CFRequestPacket(Commands.GET_TOOLS, null);
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ //TODO do we want to make these first-class objects in our model so we can track state, etc for tools?
+ List tools = (List) response.getBody().get(Attributes.TOOLS);
+ if(tools != null) {
+ return tools;
+ }
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed alltools request]: "+JSON.serialize(request)); //$NON-NLS-1$
+ }
+ }
+ return Collections.EMPTY_LIST;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#resume()
*/
public void resume() {
if(ready()) {
- //TODO make this work
- Request request = new Request(Commands.CONTINUE, null);
- Response response = sendRequest(request);
- if(response.isSuccess()) {
- if(threads != null) {
- Entry entry = null;
- for (Iterator iter = threads.entrySet().iterator(); iter.hasNext();) {
- entry = (Entry) iter.next();
- CFThreadReference thread = (CFThreadReference) entry.getValue();
- if(thread.isSuspended()) {
- thread.markSuspended(false);
+ if(threads != null) {
+ Entry entry = null;
+ for (Iterator iter = threads.entrySet().iterator(); iter.hasNext();) {
+ entry = (Entry) iter.next();
+ CFThreadReference thread = (CFThreadReference) entry.getValue();
+ if(thread.isSuspended()) {
+ CFRequestPacket request = new CFRequestPacket(Commands.CONTINUE, thread.id());
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ if(thread.isSuspended()) {
+ thread.markSuspended(false);
+ }
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed continue request][context: "+thread.id()+"]: "+JSON.serialize(request)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
}
- else if(TRACE) {
- Tracing.writeString("VM [failed continue request]: "+JSON.serialize(request)); //$NON-NLS-1$
- }
}
}
@@ -106,24 +411,25 @@
*/
public void suspend() {
if(ready()) {
- //TODO make this work
- Request request = new Request(Commands.SUSPEND, null);
- Response response = sendRequest(request);
- if(response.isSuccess()) {
- if(threads != null) {
- Entry entry = null;
- for (Iterator iter = threads.entrySet().iterator(); iter.hasNext();) {
- entry = (Entry) iter.next();
- CFThreadReference thread = (CFThreadReference) entry.getValue();
- if(!thread.isSuspended()) {
- thread.markSuspended(true);
+ if(threads != null) {
+ Entry entry = null;
+ for (Iterator iter = threads.entrySet().iterator(); iter.hasNext();) {
+ entry = (Entry) iter.next();
+ CFThreadReference thread = (CFThreadReference) entry.getValue();
+ if(thread.isRunning()) {
+ CFRequestPacket request = new CFRequestPacket(Commands.SUSPEND, thread.id());
+ CFResponsePacket response = sendRequest(request);
+ if(response.isSuccess()) {
+ if(!thread.isSuspended()) {
+ thread.markSuspended(true);
+ }
+ }
+ else if(TRACE) {
+ Tracing.writeString("VM [failed suspend request]: "+JSON.serialize(request)); //$NON-NLS-1$
}
}
}
}
- else if(TRACE) {
- Tracing.writeString("VM [failed suspend request]: "+JSON.serialize(request)); //$NON-NLS-1$
- }
}
}
@@ -140,7 +446,7 @@
* @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#name()
*/
public String name() {
- return NLS.bind(Messages.vm_name, version());
+ return Messages.vm_name;
}
/* (non-Javadoc)
@@ -155,8 +461,8 @@
*/
public synchronized String version() {
if(ready()) {
- Request request = new Request(Commands.VERSION, null);
- Response response = sendRequest(request);
+ CFRequestPacket request = new CFRequestPacket(Commands.VERSION, null);
+ CFResponsePacket response = sendRequest(request);
if(response.isSuccess()) {
Map json = response.getBody();
return (String) json.get(Commands.VERSION);
@@ -174,8 +480,8 @@
public synchronized List allThreads() {
if(threads == null) {
threads = new HashMap();
- Request request = new Request(Commands.LISTCONTEXTS, null);
- Response response = sendRequest(request);
+ CFRequestPacket request = new CFRequestPacket(Commands.LISTCONTEXTS, null);
+ CFResponsePacket response = sendRequest(request);
if(response.isSuccess()) {
List contexts = (List) response.getBody().get(Attributes.CONTEXTS);
for (Iterator iter = contexts.iterator(); iter.hasNext();) {
@@ -195,14 +501,14 @@
* Adds a thread to the listing
*
* @param id
- * @param href
+ * @param url
* @return the new thread
*/
- public CFThreadReference addThread(String id, String href) {
+ public CFThreadReference addThread(String id, String url) {
if(threads == null) {
allThreads();
}
- CFThreadReference thread = new CFThreadReference(this, id, href);
+ CFThreadReference thread = new CFThreadReference(this, id, url);
threads.put(thread.id(), thread);
return thread;
}
@@ -247,17 +553,16 @@
List threads = allThreads();
for (Iterator iter = threads.iterator(); iter.hasNext();) {
CFThreadReference thread = (CFThreadReference) iter.next();
- Request request = new Request(Commands.SCRIPTS, thread.id());
- request.setArgument(Attributes.INCLUDE_SOURCE, Boolean.TRUE);
- Response response = sendRequest(request);
+ CFRequestPacket request = new CFRequestPacket(Commands.SCRIPTS, thread.id());
+ request.setArgument(Attributes.INCLUDE_SOURCE, Boolean.FALSE);
+ CFResponsePacket response = sendRequest(request);
if(response.isSuccess()) {
- List scriptz = (List) response.getBody().get(Commands.SCRIPTS);
+ List scriptz = (List) response.getBody().get(Attributes.SCRIPTS);
for (Iterator iter2 = scriptz.iterator(); iter2.hasNext();) {
Map smap = (Map) iter2.next();
- Map scriptjson = (Map) smap.get(Attributes.SCRIPT);
- if(scriptjson != null) {
- CFScriptReference script = new CFScriptReference(this, thread.id(), scriptjson);
- scripts.put(script.id(), script);
+ if(smap != null) {
+ CFScriptReference script = new CFScriptReference(this, thread.id(), smap);
+ scripts.put(script.url(), script);
}
}
}
@@ -265,24 +570,38 @@
Tracing.writeString("VM [failed scripts request]: "+JSON.serialize(request)); //$NON-NLS-1$
}
}
+ if(scripts.size() < 1) {
+ scripts = null;
+ return Collections.EMPTY_LIST;
+ }
}
return new ArrayList(scripts.values());
}
/**
- * Returns the script with the given id or <code>null</code>
+ * Returns the script with the given url or <code>null</code>
*
- * @param id
+ * @param url
* @return the thread or <code>null</code>
*/
- public synchronized CFScriptReference findScript(String id) {
+ public synchronized CFScriptReference findScript(String url) {
if(scripts == null) {
allScripts();
}
- CFScriptReference script = (CFScriptReference) scripts.get(id);
+ CFScriptReference script = null;
+ if(scripts != null) {
+ //the scripts collection can be null after a call to allScripts()
+ //when the remote target had no scripts loaded. In this case
+ //we do not keep the initialized collection so that any successive
+ //calls the this method or allScripts will cause the remote target
+ //to be asked for all of its scripts
+ script = (CFScriptReference) scripts.get(url);
+ }
//if we find we have a script id that is not cached, we should try a lookup + add in the vm
- if(TRACE && script == null) {
- Tracing.writeString("VM [failed to find script]: "+id); //$NON-NLS-1$
+ if(script == null) {
+ if(TRACE) {
+ Tracing.writeString("VM [failed to find script]: "+url); //$NON-NLS-1$
+ }
}
return script;
}
@@ -300,20 +619,37 @@
allScripts();
}
CFScriptReference script = new CFScriptReference(this, context_id, json);
- scripts.put(script.id(), script);
+ scripts.put(script.url(), script);
return script;
}
/**
- * Removes the script with the given id form the listing
+ * Removes all {@link CFScriptReference}s from the cache when the associated context is destroyed
*
- * @param id the script to remove
+ * @param contextid
*/
- public void removeScript(String id) {
+ public void removeScriptsForContext(String contextid) {
if(scripts != null) {
- Object obj = scripts.remove(id);
+ Entry e = null;
+ for(Iterator i = scripts.entrySet().iterator(); i.hasNext();) {
+ e = (Entry) i.next();
+ if(contextid.equals(((CFScriptReference)e.getValue()).context())) {
+ i.remove();
+ }
+ }
+ }
+ }
+
+ /**
+ * Removes the script with the given url from the listing
+ *
+ * @param url the script to remove
+ */
+ public void removeScript(String url) {
+ if(scripts != null) {
+ Object obj = scripts.remove(url);
if(TRACE && obj == null) {
- Tracing.writeString("VM [failed to remove script]: "+id); //$NON-NLS-1$
+ Tracing.writeString("VM [failed to remove script]: "+url); //$NON-NLS-1$
}
}
}
@@ -385,27 +721,27 @@
}
/**
- * Receives an {@link Event} from the underlying {@link DebugSession},
+ * Receives an {@link CFEventPacket} from the underlying {@link DebugSession},
* waiting for the {@link VirtualMachine#DEFAULT_TIMEOUT}.
*
- * @return the next {@link Event} never <code>null</code>
+ * @return the next {@link CFEventPacket} never <code>null</code>
* @throws TimeoutException
* @throws DisconnectedException
*/
- public Event receiveEvent() throws TimeoutException, DisconnectedException {
- return session.receiveEvent(DEFAULT_TIMEOUT);
+ public CFEventPacket receiveEvent() throws TimeoutException, DisconnectedException {
+ return (CFEventPacket) session.receive(CFEventPacket.EVENT, DEFAULT_TIMEOUT);
}
/**
- * Receives an {@link Event} from the underlying {@link DebugSession},
+ * Receives an {@link CFEventPacket} from the underlying {@link DebugSession},
* waiting for the {@link VirtualMachine#DEFAULT_TIMEOUT}.
* @param timeout
- * @return the next {@link Event} never <code>null</code>
+ * @return the next {@link CFEventPacket} never <code>null</code>
* @throws TimeoutException
* @throws DisconnectedException
*/
- public Event receiveEvent(int timeout) throws TimeoutException, DisconnectedException {
- return session.receiveEvent(timeout);
+ public CFEventPacket receiveEvent(int timeout) throws TimeoutException, DisconnectedException {
+ return (CFEventPacket) session.receive(CFEventPacket.EVENT, timeout);
}
/**
@@ -413,21 +749,21 @@
* for the {@link VirtualMachine#DEFAULT_TIMEOUT}.
*
* @param request
- * @return the {@link Response} for the request
+ * @return the {@link CFResponsePacket} for the request
*/
- public Response sendRequest(Request request) {
+ public CFResponsePacket sendRequest(CFRequestPacket request) {
try {
- session.sendRequest(request);
- return session.receiveResponse(request.getSequence(), 3000);
+ session.send(request);
+ return (CFResponsePacket) session.receiveResponse(request.getSequence(), 3000);
}
catch(DisconnectedException de) {
disconnectVM();
- handleException(de.getMessage(), de);
+ handleException(de.getMessage(), (de.getCause() == null ? de : de.getCause()));
}
catch(TimeoutException te) {
CrossFirePlugin.log(te);
}
- return Response.FAILED;
+ return CFResponsePacket.FAILED;
}
/**
@@ -456,6 +792,40 @@
this.session.dispose();
} finally {
disconnected = true;
+ DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.IBreakpointListener#breakpointAdded(org.eclipse.debug.core.model.IBreakpoint)
+ */
+ public void breakpointAdded(IBreakpoint breakpoint) {
+ if (JavaScriptDebugModel.MODEL_ID.equals(breakpoint.getModelIdentifier())) {
+ if (breakpoint instanceof IJavaScriptLineBreakpoint) {
+ //TODO check handle map send request as needed
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.IBreakpointListener#breakpointRemoved(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
+ */
+ public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
+ if (JavaScriptDebugModel.MODEL_ID.equals(breakpoint.getModelIdentifier())) {
+ if (breakpoint instanceof IJavaScriptLineBreakpoint) {
+ //TODO check handle map send request as needed
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
+ */
+ public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
+ if (JavaScriptDebugModel.MODEL_ID.equals(breakpoint.getModelIdentifier())) {
+ if (breakpoint instanceof IJavaScriptLineBreakpoint) {
+ //TODO check handle map send request as needed
+ }
}
}
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/RemoteBreakpoint.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/RemoteBreakpoint.java
new file mode 100644
index 0000000..d51a5c8
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/RemoteBreakpoint.java
@@ -0,0 +1,276 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Attributes;
+
+
+/**
+ * This class holds the description of a breakpoint from the crossfire server
+ *
+ * @since 1.0
+ */
+public class RemoteBreakpoint implements Comparable {
+
+ public static final String TYPE_LINE = "line"; //$NON-NLS-1$
+ public static final String TYPE_HTML_ATTRIBUTE_CHANGE = "html_attribute_change"; //$NON-NLS-1$
+ public static final String TYPE_HTML_CHILD_CHANGE = "html_child_change"; //$NON-NLS-1$
+ public static final String TYPE_HTML_REMOVE = "html_remove"; //$NON-NLS-1$
+ public static final String TYPE_HTML_TEXT = "html_text"; //$NON-NLS-1$
+ public static final String TYPE_HTML_UNKNOWN = "html_unknown_type"; //$NON-NLS-1$
+
+ CFVirtualMachine vm = null;
+ Number handle = null;
+ String kind = null;
+ Map location = null;
+ Map attributes = null;
+
+ /**
+ * Constructor
+ * @param vm
+ * @param handle
+ * @param location
+ * @param attributes
+ * @param kind
+ */
+ public RemoteBreakpoint(CFVirtualMachine vm, Number handle, Map location, Map attributes, String kind) {
+ this.vm = vm;
+ this.handle = handle;
+ this.location = location;
+ this.attributes = attributes;
+ this.kind = kind;
+ }
+
+ /**
+ * @return the handle
+ */
+ public Number getHandle() {
+ return handle;
+ }
+
+ /**
+ * @return the url
+ */
+ public String getUrl() {
+ if(this.location != null) {
+ return (String) this.location.get(Attributes.URL);
+ }
+ return null;
+ }
+
+ /**
+ * @return the line
+ */
+ public int getLine() {
+ if(this.location != null) {
+ Number line = (Number) this.location.get(Attributes.LINE);
+ if(line != null) {
+ return line.intValue();
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * @return the condition
+ */
+ public String getCondition() {
+ if(this.attributes != null) {
+ return (String) this.attributes.get(Attributes.CONDITION);
+ }
+ return null;
+ }
+
+ /**
+ * @param condition the condition to set
+ */
+ public void setCondition(String condition) {
+ if(this.attributes == null) {
+ this.attributes = new HashMap();
+ }
+ if(condition != null) {
+ this.attributes.put(Attributes.CONDITION, condition);
+ }
+ else {
+ this.attributes.remove(Attributes.CONDITION);
+ }
+ }
+
+ /**
+ * @return the enabled
+ */
+ public boolean isEnabled() {
+ if(this.attributes != null) {
+ Boolean bool = (Boolean) this.attributes.get(Attributes.ENABLED);
+ if(bool != null) {
+ return bool.booleanValue();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param enabled the enabled to set
+ */
+ public void setEnabled(boolean enabled) {
+ if(this.attributes == null) {
+ this.attributes = new HashMap();
+ }
+ this.attributes.put(Attributes.ENABLED, Boolean.valueOf(enabled));
+ }
+
+ /**
+ * @return the kind
+ */
+ public String getKind() {
+ return kind;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object o) {
+ if(o instanceof RemoteBreakpoint) {
+ RemoteBreakpoint bp = (RemoteBreakpoint) o;
+ return handle.equals(bp.handle) && mapsEqual(location, bp.location) && mapsEqual(attributes, bp.attributes) && kind.equals(bp.kind);
+ }
+ return false;
+ }
+
+ /**
+ * Returns if the given maps are equal.
+ * <br><br>
+ * They are considered equal iff:
+ * <ul>
+ * <li>both maps are <code>null</code></li>
+ * <li>the maps have the same number of values and the those values are equal using the default {@link #equals(Object)} method</li>
+ * </ul>
+ *
+ * @param m1
+ * @param m2
+ * @return <code>true</code> if the maps are equal <code>false</code> otherwise
+ */
+ boolean mapsEqual(Map m1, Map m2) {
+ if(m1 == null && m2 == null) {
+ return true;
+ }
+ if(m1 == null ^ m2 == null) {
+ return false;
+ }
+ if(m1.size() != m2.size()) {
+ return false;
+ }
+ Entry entry = null;
+ for (Iterator i = m1.entrySet().iterator(); i.hasNext();) {
+ entry = (Entry) i.next();
+ Object val = m2.get(entry.getKey());
+ if(val == null) {
+ return false;
+ }
+ if(!val.equals(entry.getValue())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return handle.hashCode() + mapHashCode(location) + mapHashCode(attributes) + kind.hashCode();
+ }
+
+ /**
+ * Computes the hash code for the given map
+ * @param m
+ * @return the hash code to use for the given map
+ */
+ int mapHashCode(Map m) {
+ int hashcode = 0;
+ for (Iterator i = m.values().iterator(); i.hasNext();) {
+ hashcode += i.next().hashCode();
+ }
+ return hashcode;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object o) {
+ if(o instanceof RemoteBreakpoint) {
+ RemoteBreakpoint bp = (RemoteBreakpoint) o;
+ return this.kind.compareTo(bp.kind);
+ }
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buff = new StringBuffer("RemoteBreakpoint\n"); //$NON-NLS-1$
+ buff.append("\t[handle: ").append(handle.toString()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ return super.toString();
+ }
+
+ /**
+ * Helper method to get the {@link Attributes#ENABLED} value from the breakpoint JSON
+ *
+ * @param json the JSON for the breakpoint
+ * @return <code>true</code> if the attribute is found and <code>true</code>, <code>false</code> otherwise
+ */
+ public static boolean getEnabled(Map json) {
+ Object val = json.get(Attributes.ATTRIBUTES);
+ if(val instanceof Map) {
+ Map map = (Map) val;
+ val = map.get(Attributes.ENABLED);
+ if(val instanceof Boolean) {
+ return ((Boolean)val).booleanValue();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Helper method to get the condition from the breakpoint JSON
+ *
+ * @param json the JSON for the breakpoint
+ * @return the condition or <code>null</code>
+ */
+ public static final String getCondition(Map json) {
+ Object val = json.get(Attributes.ATTRIBUTES);
+ if(val instanceof Map) {
+ Map map = (Map) val;
+ return (String)map.get(Attributes.CONDITION);
+ }
+ return null;
+ }
+
+ /**
+ * Helper method to get the 'set' value from the breakpoint JSON
+ *
+ * @param json the JSON for the breakpoint
+ * @return <code>true</code> if the attribute is present and <code>true</code>, <code>false</code> otherwise
+ */
+ public static final boolean isSet(Map json) {
+ Object val = json.get(Attributes.SET);
+ if(val instanceof Boolean) {
+ return ((Boolean)val).booleanValue();
+ }
+ return false;
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/messages.properties b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/messages.properties
index b63696d..faa75c2 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/messages.properties
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/jsdi/messages.properties
@@ -10,4 +10,4 @@
###############################################################################
crossfire_vm=Crossfire VM
thread_name={0} - {1}
-vm_name=CrossFire VM [version - {0}]
+vm_name=CrossFire VM
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFBreakpointRequest.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFBreakpointRequest.java
index 2797401..e32e647 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFBreakpointRequest.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFBreakpointRequest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,10 +10,21 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.crossfire.request;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.eclipse.wst.jsdt.debug.core.jsdi.Location;
import org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference;
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.BreakpointRequest;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi.CFScriptReference;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi.CFVirtualMachine;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Attributes;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFRequestPacket;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFResponsePacket;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Commands;
/**
* Default implementation of {@link BreakpointRequest} for Crossfire
@@ -25,6 +36,7 @@
private String condition = null;
private int hitcount = 0;
private Location location = null;
+ private Long bpHandle = null;
/**
* Constructor
@@ -81,4 +93,56 @@
public int getHitCount() {
return hitcount;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.request.CFEventRequest#setEnabled(boolean)
+ */
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ if(enabled) {
+ //send setbreakpoint request
+ CFScriptReference script = (CFScriptReference) location.scriptReference();
+ CFRequestPacket request = new CFRequestPacket(Commands.SET_BREAKPOINTS, null);
+ Map bp = new HashMap();
+ bp.put(Attributes.TYPE, Attributes.LINE);
+ Map loc = new HashMap();
+ loc.put(Attributes.LINE, new Integer(location.lineNumber()));
+ loc.put(Attributes.URL, script.url());
+ bp.put(Attributes.LOCATION, loc);
+ Map attribs = new HashMap();
+ if (condition != null) {
+ attribs.put(Attributes.CONDITION, condition);
+ }
+ if (hitcount > 0) {
+ attribs.put(Attributes.HIT_COUNT, new Long(hitcount));
+ }
+ attribs.put(Attributes.ENABLED, Boolean.TRUE);
+ bp.put(Attributes.ATTRIBUTES, attribs);
+ request.setArgument(Attributes.BREAKPOINTS, Arrays.asList(new Object[] {bp}));
+ CFResponsePacket response = ((CFVirtualMachine)virtualMachine()).sendRequest(request);
+ if(response.isSuccess()) {
+ //process the response to get the handle of the breakpoint
+ List list = (List)response.getBody().get(Attributes.BREAKPOINTS);
+ if (list != null && list.size() > 0) {
+ bp = (Map)list.get(0);
+ if (bp != null) {
+ Number handle = (Number) bp.get(Attributes.HANDLE);
+ bpHandle = new Long(handle.longValue());
+ }
+ }
+ else {
+ //TODO create a dummy breakpoint whose details can be filled in when an onToggleBreakpoint event is received
+ }
+ }
+ }
+ else if(bpHandle != null) {
+ //send deletebreakpoint request
+ CFRequestPacket request = new CFRequestPacket(Commands.DELETE_BREAKPOINTS, null);
+ request.getArguments().put(Attributes.HANDLES, Arrays.asList(new Number[] {bpHandle}));
+ CFResponsePacket response = ((CFVirtualMachine)virtualMachine()).sendRequest(request);
+ if(response.isSuccess()) {
+ bpHandle = null;
+ }
+ }
+ }
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFEventRequest.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFEventRequest.java
index 8d6f89d..77f1ee9 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFEventRequest.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFEventRequest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -50,5 +50,4 @@
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
-
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFResumeRequest.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFResumeRequest.java
new file mode 100644
index 0000000..ae9c06c
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFResumeRequest.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.request;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference;
+import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
+import org.eclipse.wst.jsdt.debug.core.jsdi.request.ResumeRequest;
+
+/**
+ * Crossfire implementation of {@link ResumeRequest}
+ *
+ * @since 1.0
+ */
+public class CFResumeRequest extends CFThreadEventRequest implements ResumeRequest {
+
+ /**
+ * Constructor
+ * @param vm
+ * @param thread
+ */
+ public CFResumeRequest(VirtualMachine vm, ThreadReference thread) {
+ super(vm);
+ setThread(thread);
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFStepRequest.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFStepRequest.java
index 34180a7..7695fff 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFStepRequest.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/request/CFStepRequest.java
@@ -13,6 +13,7 @@
import org.eclipse.wst.jsdt.debug.core.jsdi.ThreadReference;
import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
import org.eclipse.wst.jsdt.debug.core.jsdi.request.StepRequest;
+import org.eclipse.wst.jsdt.debug.internal.crossfire.jsdi.CFThreadReference;
/**
* Default implementation of {@link StepRequest} for Crossfire
@@ -39,4 +40,11 @@
public int step() {
return stepkind;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.request.CFEventRequest#setEnabled(boolean)
+ */
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ ((CFThreadReference)thread()).setStep((enabled ? stepkind : -1));
+ }
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Attributes.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Attributes.java
index 39ad0ea..f94030e 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Attributes.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Attributes.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -22,10 +22,30 @@
*/
public static final String ARGUMENTS = "arguments"; //$NON-NLS-1$
/**
+ * The "attributes" attribute
+ */
+ public static final String ATTRIBUTES = "attributes"; //$NON-NLS-1$
+ /**
* The "body" attribute
*/
public static final String BODY = "body"; //$NON-NLS-1$
/**
+ * The type "boolean"
+ */
+ public static final String BOOLEAN = "boolean"; //$NON-NLS-1$
+ /**
+ * The "breakpoint" attribute
+ */
+ public static final String BREAKPOINT = "breakpoint"; //$NON-NLS-1$
+ /**
+ * The "breakpoints" attribute
+ */
+ public static final String BREAKPOINTS = "breakpoints"; //$NON-NLS-1$
+ /**
+ * The code attribute for this packet
+ */
+ public static final String CODE = "code"; //$NON-NLS-1$
+ /**
* The "columnOffset" attribute
*/
public static final String COLUMN_OFFSET = "columnOffset"; //$NON-NLS-1$
@@ -34,33 +54,49 @@
*/
public static final String COMMAND = "command"; //$NON-NLS-1$
/**
+ * The "condition" argument
+ */
+ public static final String CONDITION = "condition"; //$NON-NLS-1$
+ /**
+ * the "constructor" attribute
+ */
+ public static final String CONSTRUCTOR = "constructor"; //$NON-NLS-1$
+ /**
* the "context_href" attribute
*/
public static final String CONTEXT_HREF = "context_href"; //$NON-NLS-1$
/**
- * The "context_id" attribute
+ * The "contextId" attribute
*/
- public static final String CONTEXT_ID = "context_id"; //$NON-NLS-1$
+ public static final String CONTEXT_ID = "contextId"; //$NON-NLS-1$
/**
* The "contexts" attribute
*/
public static final String CONTEXTS = "contexts"; //$NON-NLS-1$
/**
- * The "crossfire_id" attribute
+ * the "current" attribute
*/
- public static final String CROSSFIRE_ID = "crossfire_id"; //$NON-NLS-1$
+ public static final String CURRENT = "current"; //$NON-NLS-1$
/**
* The "data" attribute
*/
public static final String DATA = "data"; //$NON-NLS-1$
/**
+ * The "enabled" argument
+ */
+ public static final String ENABLED = "enabled"; //$NON-NLS-1$
+ /**
* The "expression" attribute
*/
public static final String EXPRESSION = "expression"; //$NON-NLS-1$
/**
- * The "frame" attribute
+ * The "frameIndex" argument
*/
- public static final String FRAME = "frame"; //$NON-NLS-1$
+ public static final String FRAME_INDEX = "frameIndex"; //$NON-NLS-1$
+ /**
+ * The "frameNumber" argument
+ */
+ public static final String FRAME_NUMBER = "frameNumber"; //$NON-NLS-1$
/**
* The "frames" attribute
*/
@@ -70,26 +106,34 @@
*/
public static final String FROM_FRAME = "fromFrame"; //$NON-NLS-1$
/**
- * The "func" attribute
+ * The "functionName" attribute
*/
- public static final String FUNC = "func"; //$NON-NLS-1$
+ public static final String FUNCTION_NAME = "functionName"; //$NON-NLS-1$
+ /**
+ * The type "function"
+ */
+ public static final String FUNCTION = "function"; //$NON-NLS-1$
/**
* The "handle" attribute
*/
public static final String HANDLE = "handle"; //$NON-NLS-1$
/**
+ * The "handles" attribute
+ */
+ public static final String HANDLES = "handles"; //$NON-NLS-1$
+ /**
* The "handshake" attribute
*/
public static final String HANDSHAKE = "handshake"; //$NON-NLS-1$
/**
+ * The "hitCount" attribute
+ */
+ public static final String HIT_COUNT = "hitCount"; //$NON-NLS-1$
+ /**
* The "href" attribute
*/
public static final String HREF = "href"; //$NON-NLS-1$
/**
- * The "id" attribute
- */
- public static final String ID = "id"; //$NON-NLS-1$
- /**
* The "includeScopes" attribute
*/
public static final String INCLUDE_SCOPES = "includeScopes"; //$NON-NLS-1$
@@ -118,11 +162,31 @@
*/
public static final String LOCALS = "locals"; //$NON-NLS-1$
/**
+ * The "location" attribute
+ */
+ public static final String LOCATION = "location"; //$NON-NLS-1$
+ /**
* The message attribute for this packet
*/
public static final String MESSAGE = "message"; //$NON-NLS-1$
/**
- * The "ref" attribute
+ * The "newContextId" attribute
+ */
+ public static final String NEW_CONTEXT_ID = "newContextId"; //$NON-NLS-1$
+ /**
+ * The type "number"
+ */
+ public static final String NUMBER = "number"; //$NON-NLS-1$
+ /**
+ * The type "object"
+ */
+ public static final String OBJECT = "object"; //$NON-NLS-1$
+ /**
+ * The type "proto"
+ */
+ public static final String PROTO = "proto"; //$NON-NLS-1$
+ /**
+ * The "ref" attribute / type
*/
public static final String REF = "ref"; //$NON-NLS-1$
/**
@@ -130,18 +194,42 @@
*/
public static final String REQUEST_SEQ = "request_seq"; //$NON-NLS-1$
/**
+ * The "result" attribute
+ */
+ public static final String RESULT = "result"; //$NON-NLS-1$
+ /**
* The running attribute for this packet
*/
public static final String RUNNING = "running"; //$NON-NLS-1$
/**
+ * The "scope" attribute
+ */
+ public static final String SCOPE = "scope"; //$NON-NLS-1$
+ /**
+ * The "scopes" attribute
+ */
+ public static final String SCOPES = "scopes"; //$NON-NLS-1$
+ /**
+ * The "scopeIndexes" attribute
+ */
+ public static final String SCOPE_INDEXES = "scopeIndexes"; //$NON-NLS-1$
+ /**
* The "script" attribute
*/
public static final String SCRIPT = "script"; //$NON-NLS-1$
/**
+ * The "scripts" attribute
+ */
+ public static final String SCRIPTS = "scripts"; //$NON-NLS-1$
+ /**
* The "seq" attribute
*/
public static final String SEQ = "seq"; //$NON-NLS-1$
/**
+ * The "set" attribute
+ */
+ public static final String SET = "set"; //$NON-NLS-1$
+ /**
* The "source" attribute
*/
public static final String SOURCE = "source"; //$NON-NLS-1$
@@ -150,14 +238,34 @@
*/
public static final String SOURCE_LENGTH = "sourceLength"; //$NON-NLS-1$
/**
- * The success attribute for this packet
+ * The "stacktrace" attribute
*/
- public static final String SUCCESS = "success"; //$NON-NLS-1$
+ public static final String STACKTRACE = "stackTrace"; //$NON-NLS-1$
+ /**
+ * The "status" attribute
+ */
+ public static final String STATUS = "status"; //$NON-NLS-1$
+ /**
+ * The "stepaction" attribute
+ */
+ public static final String STEPACTION = "stepAction"; //$NON-NLS-1$
+ /**
+ * The type "string"
+ */
+ public static final String STRING = "string"; //$NON-NLS-1$
/**
* The "this" attribute
*/
public static final String THIS = "this"; //$NON-NLS-1$
/**
+ * the "toFrame" attribute
+ */
+ public static final String TO_FRAME = "toFrame"; //$NON-NLS-1$
+ /**
+ * The "tools" attribute
+ */
+ public static final String TOOLS = "tools"; //$NON-NLS-1$
+ /**
* The "type" attribute
*/
public static final String TYPE = "type"; //$NON-NLS-1$
@@ -166,7 +274,15 @@
*/
public static final String URL = "url"; //$NON-NLS-1$
/**
+ * The "urls" attribute
+ */
+ public static final String URLS = "urls"; //$NON-NLS-1$
+ /**
* The "value" attribute
*/
public static final String VALUE = "value"; //$NON-NLS-1$
+ /**
+ * The "values" attribute
+ */
+ public static final String VALUES = "values"; //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Event.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFEventPacket.java
similarity index 72%
rename from bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Event.java
rename to bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFEventPacket.java
index 795fe97..3ba4654 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Event.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFEventPacket.java
@@ -10,16 +10,19 @@
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import org.eclipse.wst.jsdt.debug.transport.packet.Event;
+
/**
- * An {@link Event} is a specialized {@link Packet}
+ * An {@link CFEventPacket} is a specialized {@link CFPacket}
* that only handles <code>event</code> data.
*
* @since 1.0
*/
-public class Event extends Packet {
+public class CFEventPacket extends CFPacket implements Event {
/**
* The type of this packet
@@ -70,13 +73,21 @@
*/
public static final String ON_TOGGLE_BREAKPOINT = "onToggleBreakpoint"; //$NON-NLS-1$
/**
- * The "onContextCreated" event kind
+ * The "onContextSelected" event kind
*/
- public static final String ON_CONTEXT_CREATED = "onContextCreated"; //$NON-NLS-1$
+ public static final String ON_CONTEXT_SELECTED = "onContextSelected"; //$NON-NLS-1$
/**
* The "onContextDestroyed" event kind
*/
public static final String ON_CONTEXT_DESTROYED = "onContextDestroyed"; //$NON-NLS-1$
+ /**
+ * The "onContextCreated" event kind
+ */
+ public static final String ON_CONTEXT_CREATED = "onContextCreated"; //$NON-NLS-1$
+ /**
+ * The "onContextLoaded" event kind
+ */
+ public static final String ON_CONTEXT_LOADED = "onContextLoaded"; //$NON-NLS-1$
private final String event;
private final Map body = Collections.synchronizedMap(new HashMap());
@@ -85,7 +96,7 @@
* Constructor
* @param event
*/
- public Event(String event) {
+ public CFEventPacket(String event) {
super(EVENT, null);
this.event = event.intern();
}
@@ -94,7 +105,7 @@
* Constructor
* @param json
*/
- public Event(Map json) {
+ public CFEventPacket(Map json) {
super(json);
String packetEvent = (String) json.get(EVENT);
event = packetEvent.intern();
@@ -102,34 +113,47 @@
if(data instanceof Map) {
body.putAll((Map) data);
}
- if(data instanceof String) {
+ else if(data instanceof String ||
+ data instanceof List) {
body.put(Attributes.DATA, data);
}
+
}
- /**
- * Returns the underlying event data
- * @return the event data
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFPacket#getContextId()
+ */
+ public String getContextId() {
+ String id = super.getContextId();
+ if(id == null) {
+ id = (String) body.get(Attributes.CONTEXT_ID);
+ }
+ return id;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Event#getEvent()
*/
public String getEvent() {
return event;
}
- /**
- * Returns the underlying body of the event packet
- * @return the body of the packet
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Event#getBody()
*/
public Map getBody() {
return body;
}
/* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.Packet#toJSON()
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFPacket#toJSON()
*/
public Map toJSON() {
Map json = super.toJSON();
json.put(EVENT, event);
- json.put(Attributes.BODY, body);
+ if(body.size() > 0) {
+ json.put(Attributes.BODY, body);
+ }
return json;
}
@@ -139,7 +163,7 @@
public String toString() {
StringBuffer buffer = new StringBuffer();
Object json = toJSON();
- buffer.append("Event: "); //$NON-NLS-1$
+ buffer.append("CFEventPacket: "); //$NON-NLS-1$
JSON.writeValue(json, buffer);
return buffer.toString();
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Packet.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFPacket.java
similarity index 73%
rename from bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Packet.java
rename to bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFPacket.java
index ba4278a..14e0343 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Packet.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFPacket.java
@@ -17,28 +17,25 @@
*
* @since 1.0
*/
-public abstract class Packet {
+public abstract class CFPacket implements org.eclipse.wst.jsdt.debug.transport.packet.Packet {
/**
* Debugging flag
*/
public static boolean TRACE = false;
- private static int currentSequence = 0;
- private final int sequence;
private final String type;
private final String context_id;
/**
* Constructor
*
- * @param type the type for the {@link Packet} <code>null</code> is not accepted
+ * @param type the type for the {@link CFPacket} <code>null</code> is not accepted
*/
- protected Packet(String type, String context_id) {
+ protected CFPacket(String type, String context_id) {
if(type == null) {
throw new IllegalArgumentException("The type for a packet cannot be null"); //$NON-NLS-1$
}
- this.sequence = nextSequence();
this.type = type.intern();
this.context_id = context_id;
}
@@ -48,58 +45,34 @@
*
* @param json the pre-composed map of attributes for the packet, <code>null</code> is not accepted
*/
- protected Packet(Map json) {
+ protected CFPacket(Map json) {
if(json == null) {
throw new IllegalArgumentException("The JSON map for a packet cannot be null"); //$NON-NLS-1$
}
- Number packetSeq = (Number) json.get(Attributes.SEQ);
- this.sequence = packetSeq.intValue();
String packetType = (String) json.get(Attributes.TYPE);
this.type = packetType.intern();
this.context_id = (String) json.get(Attributes.CONTEXT_ID);
}
/**
- * @return a next value for the sequence
- */
- private static synchronized int nextSequence() {
- return ++currentSequence;
- }
-
- /**
- * @return the current sequence
- */
- public int getSequence() {
- return sequence;
- }
-
- /**
* @return the context id or <code>null</code>
*/
public String getContextId() {
return context_id;
}
- /**
- * Returns the type of this packet.<br>
- * <br>
- * This method cannot return <code>null</code>
- *
- * @return the type, never <code>null</code>
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Packet#getType()
*/
public String getType() {
return type;
}
- /**
- * Returns the type and sequence composed in a JSON map.<br>
- * <br>
- * This method cannot return <code>null</code>
- * @return the JSON map
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Packet#toJSON()
*/
public Map toJSON() {
Map json = new HashMap();
- json.put(Attributes.SEQ, new Integer(sequence));
json.put(Attributes.TYPE, type);
if(context_id != null) {
json.put(Attributes.CONTEXT_ID, context_id);
@@ -129,7 +102,7 @@
public String toString() {
StringBuffer buffer = new StringBuffer();
Object json = toJSON();
- buffer.append("Packet: "); //$NON-NLS-1$
+ buffer.append("CFPacket: "); //$NON-NLS-1$
JSON.writeValue(json, buffer);
return buffer.toString();
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Request.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFRequestPacket.java
similarity index 72%
rename from bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Request.java
rename to bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFRequestPacket.java
index eea2a88..fe122e2 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Request.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFRequestPacket.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
+ * Copyright (c) 2010, 2011 IBM Corporation and others All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -14,12 +14,14 @@
import java.util.Map;
import java.util.Map.Entry;
+import org.eclipse.wst.jsdt.debug.transport.packet.Request;
+
/**
* Default request implementation using JSON
*
* @since 1.0
*/
-public class Request extends Packet {
+public class CFRequestPacket extends CFPacket implements Request {
/**
* The type of this packet
@@ -29,7 +31,8 @@
private final String command;
private final Map arguments = Collections.synchronizedMap(new HashMap());
private final Map params = Collections.synchronizedMap(new HashMap());
-
+ private static int currentSequence = 0;
+ private final int sequence;
/**
* Constructor
@@ -39,11 +42,12 @@
* @see http://getfirebug.com/wiki/index.php/Crossfire_Protocol_Reference for
* requests that do not require a context id.
*/
- public Request(String command, String context_id) {
+ public CFRequestPacket(String command, String context_id) {
super(REQUEST, context_id);
if(command == null) {
throw new IllegalArgumentException("The request command kind cannot be null"); //$NON-NLS-1$
}
+ this.sequence = nextSequence();
this.command = command.intern();
}
@@ -52,7 +56,7 @@
*
* @param json map of JSON attributes, <code>null</code> is not accepted
*/
- public Request(Map json) {
+ public CFRequestPacket(Map json) {
super(json);
if(json == null) {
throw new IllegalArgumentException("The JSON map for a request packet cannot be null"); //$NON-NLS-1$
@@ -61,9 +65,25 @@
this.command = value.intern();
Map packetArguments = (Map) json.get(Attributes.ARGUMENTS);
arguments.putAll(packetArguments);
+ Number packetSeq = (Number) json.get(Attributes.SEQ);
+ this.sequence = packetSeq.intValue();
}
/**
+ * @return a next value for the sequence
+ */
+ private static synchronized int nextSequence() {
+ return ++currentSequence;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Request#getSequence()
+ */
+ public int getSequence() {
+ return sequence;
+ }
+
+ /**
* Allows additional parameters to be added to the request
*
* @param key
@@ -73,24 +93,15 @@
params.put(key, value);
}
- /**
- * Returns the command that this {@link Request} will was created for.<br>
- * <br>
- * This method cannot return <code>null</code>
- *
- * @return the underlying command, never <code>null</code>
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Request#getCommand()
*/
public String getCommand() {
return command;
}
- /**
- * Returns the complete collection of JSON arguments in the {@link Request}.<br>
- * <br>
- * This method cannot return <code>null</code>, an empty map will be returned
- * if there are no properties.
- *
- * @return the arguments or an empty map never <code>null</code>
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Request#getArguments()
*/
public Map getArguments() {
return arguments;
@@ -100,23 +111,21 @@
* Sets the given argument in the JSON map.
*
* @param key the key for the attribute, <code>null</code> is not accepted
- * @param argument the value for the argument, <code>null</code> is not accepted
+ * @param argument the value for the argument
*/
public void setArgument(String key, Object argument) {
if(key == null) {
throw new IllegalArgumentException("The argument key cannot be null"); //$NON-NLS-1$
}
- if(argument == null) {
- throw new IllegalArgumentException("A null argument is not allowed"); //$NON-NLS-1$
- }
arguments.put(key, argument);
}
/* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.Packet#toJSON()
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFPacket#toJSON()
*/
public Map toJSON() {
Map json = super.toJSON();
+ json.put(Attributes.SEQ, new Integer(sequence));
json.put(Attributes.COMMAND, command);
if(!arguments.isEmpty()) {
json.put(Attributes.ARGUMENTS, arguments);
@@ -135,7 +144,7 @@
public String toString() {
StringBuffer buffer = new StringBuffer();
Object json = toJSON();
- buffer.append("Request: "); //$NON-NLS-1$
+ buffer.append("CFRequestPacket: "); //$NON-NLS-1$
JSON.writeValue(json, buffer);
return buffer.toString();
}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFResponsePacket.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFResponsePacket.java
new file mode 100644
index 0000000..27a4cfc
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFResponsePacket.java
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.wst.jsdt.debug.transport.packet.Response;
+
+/**
+ * Default {@link CFResponsePacket} implementation using JSON
+ *
+ * @since 1.0
+ */
+public class CFResponsePacket extends CFPacket implements Response {
+
+ /**
+ * The type of this packet
+ */
+ public static final String RESPONSE = "response"; //$NON-NLS-1$
+
+ /**
+ * Response codes
+ */
+ public static final int CODE_OK = 0;
+ public static final int CODE_MALFORMED_PACKET = 1;
+ public static final int CODE_MALFORMED_REQUEST = 2;
+ public static final int CODE_COMMAND_NOT_IMPLEMENTED = 3;
+ public static final int CODE_INVALID_ARGUMENTS = 4;
+ public static final int CODE_UNEXPECTED_EXCEPTION = 5;
+ public static final int CODE_COMMAND_FAILED = 6;
+ public static final int CODE_INVALID_STATE = 7;
+
+ static final Map failed_attributes;
+ static {
+ failed_attributes = new HashMap();
+ Integer value = new Integer(-1);
+ failed_attributes.put(Attributes.SEQ, value);
+ failed_attributes.put(Attributes.TYPE, RESPONSE);
+ failed_attributes.put(Attributes.REQUEST_SEQ, value);
+ failed_attributes.put(Attributes.COMMAND, "failed"); //$NON-NLS-1$
+ Map status = new HashMap();
+ failed_attributes.put(Attributes.STATUS, status);
+ status.put(Attributes.CODE, new Integer(CODE_UNEXPECTED_EXCEPTION));
+ status.put(Attributes.RUNNING, Boolean.FALSE);
+ status.put(Attributes.MESSAGE, "failed"); //$NON-NLS-1$
+ }
+
+ public static final CFResponsePacket FAILED = new CFResponsePacket(failed_attributes);
+
+ private String command;
+ private int requestSequence;
+ private Map body = Collections.synchronizedMap(new HashMap());
+ private volatile int code = 0;
+ private volatile boolean running = true;
+ private volatile String message;
+ private Map stackTrace = Collections.synchronizedMap(new HashMap());
+
+ /**
+ * Constructor
+ *
+ * @param requestSequence the sequence
+ * @param command the command, <code>null</code> is not accepted
+ */
+ public CFResponsePacket(int requestSequence, String command) {
+ super(RESPONSE, null);
+ if(command == null) {
+ throw new IllegalArgumentException("The command string for a response packet cannot be null"); //$NON-NLS-1$
+ }
+ this.requestSequence = requestSequence;
+ this.command = command.intern();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param json the JSON map for a response, <code>null</code> is not accepted
+ */
+ public CFResponsePacket(Map json) {
+ super(json);
+ Number packetRequestSeq = (Number) json.get(Attributes.REQUEST_SEQ);
+ requestSequence = packetRequestSeq.intValue();
+
+ String packetCommand = (String) json.get(Attributes.COMMAND);
+ command = packetCommand.intern();
+
+ Object bdy = json.get(Attributes.BODY);
+ if(bdy instanceof Map) {
+ Map packetBody = (Map)bdy;
+ body.putAll(packetBody);
+ }
+
+ Object status = json.get(Attributes.STATUS);
+ if (status != null && status instanceof Map) {
+ Map packetStatus = (Map)status;
+ Object codeObj = packetStatus.get(Attributes.CODE);
+ if (codeObj != null) {
+ code = ((Number)codeObj).intValue();
+ }
+ Boolean runningObj = (Boolean)packetStatus.get(Attributes.RUNNING);
+ if (runningObj != null) {
+ running = runningObj.booleanValue();
+ }
+ message = (String)packetStatus.get(Attributes.MESSAGE);
+ stackTrace = (Map)packetStatus.get(Attributes.STACKTRACE);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#getRequestSequence()
+ */
+ public int getRequestSequence() {
+ return requestSequence;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#getCommand()
+ */
+ public String getCommand() {
+ return command;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#getBody()
+ */
+ public Map getBody() {
+ return body;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#isSuccess()
+ */
+ public boolean isSuccess() {
+ return code == CODE_OK;
+ }
+
+ /**
+ * Set the success code for the response
+ *
+ * @param code the new success code
+ */
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+ /**
+ * Get the success code for the response
+ *
+ * return the success code
+ */
+ public int getCode() {
+ return code;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#isRunning()
+ */
+ public boolean isRunning() {
+ return running;
+ }
+
+ /**
+ * Sets the running state of the underlying command
+ *
+ * @param running the new running state for the underlying command
+ */
+ public void setRunning(boolean running) {
+ this.running = running;
+ }
+
+ /**
+ * Returns the status message for this {@link CFResponsePacket}.<br>
+ * <br>
+ * This method can return <code>null</code>
+ *
+ * @return the status message for this {@link CFResponsePacket} or <code>null</code>
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Set the status message for this {@link CFResponsePacket}
+ *
+ * @param message the new message, <code>null</code> is accepted
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ /**
+ * Returns the stack trace for this {@link CFResponsePacket}.<br>
+ * <br>
+ * This method can return <code>null</code>
+ *
+ * @return the stack trace for this {@link CFResponsePacket} or <code>null</code>
+ */
+ public Map getStackTrace() {
+ return stackTrace;
+ }
+
+ /**
+ * Set the stack trace for this {@link CFResponsePacket}
+ *
+ * @param stackTrace the new stack trace, <code>null</code> is accepted
+ */
+ public void setStackTrace(Map stackTrace) {
+ this.stackTrace = stackTrace;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFPacket#toJSON()
+ */
+ public Map toJSON() {
+ Map json = super.toJSON();
+ json.put(Attributes.REQUEST_SEQ, new Integer(requestSequence));
+ json.put(Attributes.COMMAND, command);
+ if(body != null && body.size() > 0) {
+ json.put(Attributes.BODY, body);
+ }
+ Map status = new HashMap();
+ json.put(Attributes.STATUS, status);
+ status.put(Attributes.RUNNING, new Boolean(running));
+ status.put(Attributes.CODE, new Integer(code));
+ if (message != null) {
+ status.put(Attributes.MESSAGE, message);
+ }
+ if (stackTrace != null) {
+ status.put(Attributes.STACKTRACE, stackTrace);
+ }
+ return json;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ Object json = toJSON();
+ buffer.append("CFResponsePacket: "); //$NON-NLS-1$
+ JSON.writeValue(json, buffer);
+ return buffer.toString();
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFSocketConnection.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFSocketConnection.java
new file mode 100644
index 0000000..dcfa42e
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFSocketConnection.java
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 IBM Corporation and others All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.Socket;
+import java.util.Map;
+
+import org.eclipse.wst.jsdt.debug.internal.crossfire.Tracing;
+import org.eclipse.wst.jsdt.debug.transport.Connection;
+import org.eclipse.wst.jsdt.debug.transport.packet.Packet;
+import org.eclipse.wst.jsdt.debug.transport.socket.SocketConnection;
+
+/**
+ * A specialized {@link Connection} that communicates using {@link Socket}s
+ *
+ * @since 1.0
+ */
+public class CFSocketConnection extends SocketConnection {
+
+ /**
+ * Constructor
+ *
+ * @param socket the underlying {@link Socket}, <code>null</code> is not accepted
+ *
+ * @throws IOException
+ */
+ public CFSocketConnection(Socket socket) throws IOException {
+ super(socket);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.socket.SocketConnection#writePacket(org.eclipse.wst.jsdt.debug.transport.packet.Packet)
+ */
+ public void writePacket(Packet packet) throws IOException {
+ String serialized = JSON.serialize((CFPacket) packet);
+ if(CFPacket.TRACE) {
+ Tracing.writeString("WRITE PACKET: "+serialized); //$NON-NLS-1$
+ }
+ Writer writer = getWriter();
+ writer.write(serialized);
+ writer.flush();
+ }
+
+ /**
+ * Writes the standard handshake packet to connect
+ *
+ * @param tools the {@link String} array of tools to enable by default
+ * @throws IOException
+ */
+ public void writeHandShake(String[] tools) throws IOException {
+ if(CFPacket.TRACE) {
+ Tracing.writeString("WRITE HANDSHAKE: "+HandShakePacket.getHandshake(tools)); //$NON-NLS-1$
+ }
+ Writer writer = getWriter();
+ writer.write(HandShakePacket.getHandshake(tools));
+ writer.flush();
+ }
+
+ /**
+ * Reads the {@link HandShakePacket} packet from the the stream
+ *
+ * @return the {@link HandShakePacket}, never <code>null</code>
+ * @throws IOException
+ */
+ public CFPacket readHandShake() throws IOException {
+ StringBuffer buffer = new StringBuffer();
+ //read the header first
+ int c = 0;
+ boolean r = false;
+ Reader reader = getReader();
+ while((c = reader.read()) > -1) {
+ buffer.append((char)c);
+ if(r) {
+ if(c == '\n') {
+ break;
+ }
+ }
+ r = c == '\r';
+ }
+ //chew up the tool heading if there is one
+ r = false;
+ while(reader.ready() && (c = reader.read()) > -1) {
+ if(r) {
+ if(c == '\n') {
+ buffer.append((char)c);
+ break;
+ }
+ }
+ r = c == '\r';
+ if(r) {
+ buffer.append((char)c);
+ }
+ }
+ //XXX hack, we should be properly parsing and accounting for the tool header
+ if(buffer.toString().equals(HandShakePacket.getHandshake(null))) {
+ HandShakePacket ack = new HandShakePacket();
+ if(CFPacket.TRACE) {
+ Tracing.writeString("ACK HANDSHAKE: "+buffer.toString()); //$NON-NLS-1$
+ }
+ return ack;
+ }
+ if(CFPacket.TRACE) {
+ Tracing.writeString("Did not get correct CrossFire handshake: "+buffer.toString()); //$NON-NLS-1$
+ }
+ throw new IOException("Did not get correct CrossFire handshake: "+buffer.toString()); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.socket.SocketConnection#readPacket()
+ */
+ public Packet readPacket() throws IOException {
+ StringBuffer buffer = new StringBuffer();
+ StringBuffer raw = new StringBuffer();
+ int c = -1;
+ boolean r = false;
+ String len = null;
+ Reader reader = getReader();
+ while((c = reader.read()) > -1) {
+ if(CFPacket.TRACE) {
+ raw.append((char)c);
+ }
+ if(r) {
+ if(c == '\n') {
+ String str = buffer.toString();
+ if(str.startsWith(JSON.CONTENT_LENGTH)) {
+ len = grabAttrib(str);
+ }
+ else if(str.equals("\r")) { //$NON-NLS-1$
+ break;
+ }
+ buffer = new StringBuffer();
+ r = false;
+ }
+ continue;
+ }
+ buffer.append((char)c);
+ r = c == '\r';
+ }
+ int length = 0;
+ try {
+ length = Integer.parseInt(len);
+ } catch (NumberFormatException e) {
+ if(CFPacket.TRACE) {
+ Tracing.writeString("[SOCKET] failed to read content length: "+raw.toString()); //$NON-NLS-1$
+ }
+ throw new IOException("Failed to parse content length: " + raw.toString()); //$NON-NLS-1$
+ }
+ char[] message = new char[length];
+ int n = 0;
+ int off = 0;
+ while (n < length) {
+ int count = reader.read(message, off + n, length - n);
+ if (count < 0) {
+ throw new EOFException();
+ }
+ n += count;
+ }
+ if(CFPacket.TRACE) {
+ raw.append(message);
+ Tracing.writeString("READ PACKET: " + raw.toString()); //$NON-NLS-1$
+ }
+ Map json = (Map) JSON.read(new String(message));
+ String type = CFPacket.getType(json);
+ if (CFEventPacket.EVENT.equals(type)) {
+ return new CFEventPacket(json);
+ }
+ if (CFRequestPacket.REQUEST.equals(type)) {
+ return new CFRequestPacket(json);
+ }
+ if (CFResponsePacket.RESPONSE.equals(type)) {
+ return new CFResponsePacket(json);
+ }
+ throw new IOException("Unknown packet type: " + type); //$NON-NLS-1$
+ }
+
+ /**
+ * Grabs the attribute from the RHS of the header. Where all headers
+ * have the form <code>[name]:[value]</code>.
+ *
+ * @param str the string to parse
+ * @return the <code>[value]</code> from the header
+ */
+ String grabAttrib(String str) {
+ if(str != null) {
+ int idx = str.indexOf(':');
+ if(idx > -1) {
+ return str.substring(idx+1, str.length()-1);
+ }
+ }
+ return null;
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFTransportService.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFTransportService.java
new file mode 100644
index 0000000..f0f2ee2
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/CFTransportService.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.wst.jsdt.debug.transport.Connection;
+import org.eclipse.wst.jsdt.debug.transport.ListenerKey;
+import org.eclipse.wst.jsdt.debug.transport.packet.Packet;
+import org.eclipse.wst.jsdt.debug.transport.socket.SocketConnection;
+import org.eclipse.wst.jsdt.debug.transport.socket.SocketTransportService;
+
+
+/**
+ * Implementation of a transport service that using a {@link Socket} for communication
+ *
+ * @since 1.0
+ */
+public class CFTransportService extends SocketTransportService {
+
+ static final Class serverSocketClass = ServerSocket.class; // temporary used to pre-load the ServerSocket.class
+
+ /**
+ * Map of {@link ListenerKey} to {@link ServerSocket}s
+ */
+ Map listeners = new HashMap();
+
+ String[] tools = null;
+
+ /**
+ * Constructor
+ */
+ public CFTransportService(String[] tools) {
+ this.tools = tools;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.socket.SocketTransportService#getConnection(java.net.Socket)
+ */
+ public SocketConnection getConnection(Socket socket) throws IOException {
+ return new CFSocketConnection(socket);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.socket.SocketTransportService#handleAccept(org.eclipse.wst.jsdt.debug.transport.Connection)
+ */
+ public void handleAccept(Connection connection) throws IOException {
+ if(connection instanceof CFSocketConnection) {
+ CFSocketConnection cfconn = (CFSocketConnection) connection;
+ Packet packet = cfconn.readHandShake();
+ if (!(packet instanceof HandShakePacket)) {
+ throw new IOException("failure establishing connection"); //$NON-NLS-1$
+ }
+ cfconn.writeHandShake(this.tools);
+ return;
+ }
+ throw new IOException("failure establishing connection"); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.socket.SocketTransportService#handleAttach(org.eclipse.wst.jsdt.debug.transport.Connection)
+ */
+ public void handleAttach(Connection connection) throws IOException {
+ if(connection instanceof CFSocketConnection) {
+ CFSocketConnection cfconn = (CFSocketConnection) connection;
+ cfconn.writeHandShake(this.tools);
+ Packet packet = cfconn.readHandShake();
+ if (!(packet instanceof HandShakePacket)) {
+ throw new IOException("failure establishing connection"); //$NON-NLS-1$
+ }
+ return;
+ }
+ throw new IOException("failure establishing connection"); //$NON-NLS-1$
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Commands.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Commands.java
index d6aa100..bfcad4f 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Commands.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Commands.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,16 +24,24 @@
/**
* The "changebreakpoint" command
*/
- public static final String CHANGE_BREAKPOINT = "changebreakpoint"; //$NON-NLS-1$
+ public static final String CHANGE_BREAKPOINTS = "changebreakpoints"; //$NON-NLS-1$
/**
- * The "clearbreakpoint" command
+ * The "deletebreakpoint" command
*/
- public static final String CLEAR_BREAKPOINT = "clearbreakpoint"; //$NON-NLS-1$
+ public static final String DELETE_BREAKPOINTS = "deletebreakpoints"; //$NON-NLS-1$
/**
* The "continue" command
*/
public static final String CONTINUE = "continue"; //$NON-NLS-1$
/**
+ * The "disabletools" command
+ */
+ public static final String DISABLE_TOOLS = "disabletools"; //$NON-NLS-1$
+ /**
+ * The "enabletools" command
+ */
+ public static final String ENABLE_TOOLS = "enabletools"; //$NON-NLS-1$
+ /**
* The "evaluate" command
*/
public static final String EVALUATE = "evaluate"; //$NON-NLS-1$
@@ -42,14 +50,14 @@
*/
public static final String FRAME = "frame"; //$NON-NLS-1$
/**
- * The "getbreakpoint" command
- */
- public static final String GET_BREAKPOINT = "getbreakpoint"; //$NON-NLS-1$
- /**
* The "getbreakpoints" command
*/
public static final String GET_BREAKPOINTS = "getbreakpoints"; //$NON-NLS-1$
/**
+ * The "gettools" command
+ */
+ public static final String GET_TOOLS = "gettools"; //$NON-NLS-1$
+ /**
* The "inspect" command
*/
public static final String INSPECT = "inspect"; //$NON-NLS-1$
@@ -66,17 +74,25 @@
*/
public static final String SCOPES = "scopes"; //$NON-NLS-1$
/**
- * The "script" command
- */
- public static final String SCRIPT = "script"; //$NON-NLS-1$
- /**
* The "scripts" command
*/
public static final String SCRIPTS = "scripts"; //$NON-NLS-1$
/**
* The "setbreakpoint" command
*/
- public static final String SET_BREAKPOINT = "setbreakpoint"; //$NON-NLS-1$
+ public static final String SET_BREAKPOINTS = "setbreakpoints"; //$NON-NLS-1$
+ /**
+ * The "in" step action
+ */
+ public static final String STEP_IN = "in"; //$NON-NLS-1$
+ /**
+ * The "next" step action
+ */
+ public static final String STEP_NEXT = "next"; //$NON-NLS-1$
+ /**
+ * The "out" step action
+ */
+ public static final String STEP_OUT = "out"; //$NON-NLS-1$
/**
* The "source" command
*/
@@ -85,6 +101,10 @@
* The "suspend" command
*/
public static final String SUSPEND = "suspend"; //$NON-NLS-1$
+ /**
+ * The "createcontext" command
+ */
+ public static final String CREATE_CONTEXT = "createcontext"; //$NON-NLS-1$
/**
* The "version" command
*/
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Connection.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Connection.java
deleted file mode 100644
index e638a07..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Connection.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import java.io.IOException;
-
-
-/**
- * Describes a socket connection to a debugger
- *
- * @since 1.0
- */
-public interface Connection {
-
- /**
- * Returns if the debug connection is open.
- *
- * @return <code>true</code> if the connection is open <code>false</code> otherwise
- */
- public abstract boolean isOpen();
-
- /**
- * Closes the connection.
- *
- * @throws IOException if the connection failed to close or is already closed
- */
- public abstract void close() throws IOException;
-
- /**
- * Writes the given packet to the connection
- *
- * @param packet the packet to write, <code>null</code> is not accepted
- * @throws IOException if the write failed
- */
- public abstract void writePacket(Packet packet) throws IOException;
-
- /**
- * Reads the next packet from the connection. This is non-blocking.<br>
- * <br>
- * This method cannot return <code>null</code>
- *
- * @return the next {@link Packet} from the connection
- * @throws IOException if the connection is prematurely closed or the read failed
- */
- public abstract Packet readPacket() throws IOException;
-
-}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/DebugSession.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/DebugSession.java
deleted file mode 100644
index 0c3e69a..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/DebugSession.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import org.eclipse.wst.jsdt.debug.internal.crossfire.Tracing;
-
-
-/**
- * A {@link DebugSession} controls a {@link PacketSendManager} and {@link PacketReceiveManager}
- * that is uses to communicate to a debug target using the underlying {@link Connection}
- *
- * @since 1.0
- */
-public class DebugSession {
-
- /**
- * The default receive manager
- */
- private final PacketReceiveManager packetReceiveManager;
- /**
- * The default send manager
- */
- private final PacketSendManager packetSendManager;
-
- /**
- * Constructor
- *
- * Starts the send / receive managers on the given connection.
- *
- * @param connection
- */
- public DebugSession(Connection connection) {
- packetReceiveManager = new PacketReceiveManager(connection);
- Thread receiveThread = new Thread(packetReceiveManager, "Debug Session - Receive Manager"); //$NON-NLS-1$
- receiveThread.setDaemon(true);
-
- packetSendManager = new PacketSendManager(connection);
- Thread sendThread = new Thread(packetSendManager, "Debug Session - Send Manager"); //$NON-NLS-1$
- sendThread.setDaemon(true);
-
- packetReceiveManager.setPartnerThread(sendThread);
- packetSendManager.setPartnerThread(receiveThread);
-
- receiveThread.start();
- sendThread.start();
- }
-
- /**
- * Stops the debug sessions and disconnects the send / receive managers
- */
- public void dispose() {
- packetReceiveManager.disconnect();
- packetSendManager.disconnect();
- }
-
- /**
- * Sends the given {@link Request} using the underlying {@link PacketSendManager}.
- *
- * @param request the request to send, <code>null</code> is not accepted
- * @throws DisconnectedException if the {@link PacketSendManager} has been disconnected
- */
- public void sendRequest(Request request) throws DisconnectedException {
- if(request == null) {
- throw new IllegalArgumentException("You cannot send a null request"); //$NON-NLS-1$
- }
- if(Packet.TRACE) {
- Tracing.writeString("SEND REQUEST: "+request); //$NON-NLS-1$
- }
- packetSendManager.sendPacket(request);
- }
-
- /**
- * Sends the given {@link Event} using the underlying {@link PacketSendManager}.
- *
- * @param event the event to send, <code>null</code> is not accepted
- * @throws DisconnectedException if the {@link PacketSendManager} has been disconnected
- */
- public void sendEvent(Event event) throws DisconnectedException {
- if(event == null) {
- throw new IllegalArgumentException("You cannot send a null event"); //$NON-NLS-1$
- }
- if(Packet.TRACE) {
- Tracing.writeString("SEND EVENT: "+event); //$NON-NLS-1$
- }
- packetSendManager.sendPacket(event);
- }
-
- /**
- * Sends the given {@link Response} using the underlying {@link PacketSendManager}.
- *
- * @param response the response to send, <code>null</code> is not accepted
- * @throws DisconnectedException if the {@link PacketSendManager} has been disconnected
- */
- public void sendResponse(Response response) throws DisconnectedException {
- if(response == null) {
- throw new IllegalArgumentException("You cannot send a null response"); //$NON-NLS-1$
- }
- if(Packet.TRACE) {
- Tracing.writeString("SEND RESPONSE: "+response); //$NON-NLS-1$
- }
- packetSendManager.sendPacket(response);
- }
-
- /**
- * Waits for the given timeout for a {@link Response} response in the given sequence
- * from the {@link PacketReceiveManager}.<br>
- * <br>
- * This method does not return <code>null</code> - one of the listed exceptions will be thrown
- * if an {@link Response} cannot be returned.
- *
- * @param timeout the amount of time in milliseconds to wait to a {@link Response}
- * @return a new {@link Request} from the {@link PacketReceiveManager} never <code>null</code>
- * @throws TimeoutException if the timeout lapses with no {@link Response} returned
- * @throws DisconnectedException if the {@link PacketReceiveManager} has been disconnected
- */
- public Response receiveResponse(int requestSequence, int timeout) throws TimeoutException, DisconnectedException {
- Response response = packetReceiveManager.getResponse(requestSequence, timeout);
- if(Packet.TRACE) {
- Tracing.writeString("REC RESPONSE: "+response); //$NON-NLS-1$
- }
- return response;
- }
-
- /**
- * Waits for the given timeout for a {@link Event} response from the {@link PacketReceiveManager}.<br>
- * <br>
- * This method does not return <code>null</code> - one of the listed exceptions will be thrown
- * if an {@link Event} cannot be returned.
- *
- * @param timeout the amount of time in milliseconds to wait to a {@link Event}
- * @return a new {@link Request} from the {@link PacketReceiveManager} never <code>null</code>
- * @throws TimeoutException if the timeout lapses with no {@link Event} returned
- * @throws DisconnectedException if the {@link PacketReceiveManager} has been disconnected
- */
- public Event receiveEvent(int timeout) throws TimeoutException, DisconnectedException {
- Event event = (Event) packetReceiveManager.getCommand(Event.EVENT, timeout);
- if(Packet.TRACE) {
- Tracing.writeString("REC EVENT: "+event); //$NON-NLS-1$
- }
- return event;
- }
-
- /**
- * Waits for the given timeout for a request response from the {@link PacketReceiveManager}.<br>
- * <br>
- * This method does not return <code>null</code> - one of the listed exceptions will be thrown
- * if a {@link Request} cannot be returned.
- *
- * @param timeout the amount of time in milliseconds to wait to a {@link Request}
- * @return a new {@link Request} from the {@link PacketReceiveManager} never <code>null</code>
- * @throws TimeoutException if the timeout lapses with no {@link Request} returned
- * @throws DisconnectedException if the {@link PacketReceiveManager} has been disconnected
- */
- public Request receiveRequest(int timeout) throws TimeoutException, DisconnectedException {
- Request request = (Request) packetReceiveManager.getCommand(Request.REQUEST, timeout);
- if(Packet.TRACE) {
- Tracing.writeString("REC REQUEST: "+request); //$NON-NLS-1$
- }
- return request;
- }
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/DisconnectedException.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/DisconnectedException.java
deleted file mode 100644
index d029db4..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/DisconnectedException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-
-/**
- * A {@link DisconnectedException} is thrown by either of the {@link PacketSendManager}
- * or {@link PacketReceiveManager} when a request is made and they have been disconnected
- *
- * @since 1.0
- */
-public final class DisconnectedException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 3233213787459625769L;
-
- /**
- * Constructor
- *
- * @param message
- * @param exception
- */
- public DisconnectedException(String message, Exception exception) {
- super(message, exception);
- }
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/HandShake.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/HandShake.java
deleted file mode 100644
index f0628c7..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/HandShake.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * {@link Packet} for replying to the Crossfire handshake request
- *
- * @since 1.0
- */
-public class HandShake extends Packet {
-
- /**
- * handshake
- */
- private static String CROSSFIRE_HANDSHAKE;
- static {
- String hs = "CrossfireHandshake\r\n"; //$NON-NLS-1$
- try {
- CROSSFIRE_HANDSHAKE = new String(hs.getBytes(), "utf-8"); //$NON-NLS-1$
- } catch (UnsupportedEncodingException e) {
- CROSSFIRE_HANDSHAKE = hs;
- }
- }
-
- /**
- * Constructor
- * @param type
- */
- protected HandShake() {
- super(Response.RESPONSE, null);
- }
-
- /**
- * @return the handshake
- */
- public static String getHandshake() {
- return CROSSFIRE_HANDSHAKE;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Packet#toString()
- */
- public String toString() {
- return CROSSFIRE_HANDSHAKE;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.crossfire.transport.Packet#toJSON()
- */
- public Map toJSON() {
- Map json = new HashMap(1);
- json.put(Attributes.HANDSHAKE, CROSSFIRE_HANDSHAKE);
- return json;
- }
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/HandShakePacket.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/HandShakePacket.java
new file mode 100644
index 0000000..ed005e3
--- /dev/null
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/HandShakePacket.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * {@link CFPacket} for replying to the Crossfire handshake request
+ *
+ * @since 1.0
+ */
+public class HandShakePacket extends CFPacket {
+
+ /**
+ * handshake String
+ */
+ private static String CROSSFIRE_HANDSHAKE = "CrossfireHandshake\r\n"; //$NON-NLS-1$
+
+
+ /**
+ * Constructor
+ * @param type
+ */
+ protected HandShakePacket() {
+ super(CFResponsePacket.RESPONSE, null);
+ }
+
+ /**
+ * Creates a handshake object with the given set of tools
+ *
+ * @param tools the {@link String} array of tools to enable
+ * @return the handshake
+ */
+ public static String getHandshake(String[] tools) {
+ StringBuffer buffer = new StringBuffer(CROSSFIRE_HANDSHAKE);
+ if(tools != null) {
+ for (int i = 0; i < tools.length; i++) {
+ if(tools[i] != null) {
+ buffer.append(tools[i]);
+ }
+ if(i < tools.length -1) {
+ buffer.append(',');
+ }
+ }
+ }
+ return buffer.append(JSON.LINE_FEED).toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFPacket#toString()
+ */
+ public String toString() {
+ return CROSSFIRE_HANDSHAKE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFPacket#toJSON()
+ */
+ public Map toJSON() {
+ Map json = new HashMap(1);
+ json.put(Attributes.HANDSHAKE, CROSSFIRE_HANDSHAKE);
+ return json;
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/JSON.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/JSON.java
index 3105a3e..f503bb5 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/JSON.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/JSON.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -49,10 +49,9 @@
*/
public static final String LINE_FEED = "\r\n"; //$NON-NLS-1$
/**
- * The default <code>Content-Length:</code> pre-amble
+ * The default <code>Content-Length:</code> preamble
*/
public static final String CONTENT_LENGTH = "Content-Length:"; //$NON-NLS-1$
-
/**
* Enables / Disables tracing in the all of the JSDI implementations
*
@@ -208,31 +207,31 @@
}
/**
- * Writes the <code>Content-Length:N</code> pre-amble to the head of the given buffer
+ * Writes the <code>Content-Length:N</code> preamble to the head of the given buffer
*
* @param buffer
* @param length
*/
public static void writeContentLength(StringBuffer buffer, int length) {
StringBuffer buff = new StringBuffer(18);
- buff.append(CONTENT_LENGTH).append(length).append(LINE_FEED);
- buffer.insert(0, buff);
+ buff.append(CONTENT_LENGTH).append(length).append(LINE_FEED).append(LINE_FEED);
+ buffer.insert(0, buff.toString());
}
/**
- * Serializes the given {@link Packet} to a {@link String}
+ * Serializes the given {@link CFPacket} to a {@link String}
*
* @param packet the packet to serialize
*
* @return the serialized {@link String}, never <code>null</code>
*/
- public static String serialize(Packet packet) {
+ public static String serialize(CFPacket packet) {
Object json = packet.toJSON();
StringBuffer buffer = new StringBuffer();
writeValue(json, buffer);
int length = buffer.length();
- buffer.append(LINE_FEED);
writeContentLength(buffer, length);
+ buffer.append(LINE_FEED);
if(TRACE) {
Tracing.writeString("SERIALIZE: " + packet.getType() +" packet as "+buffer.toString()); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -240,7 +239,7 @@
}
/**
- * Reads and returns a new object from the given json {@link String}. This method
+ * Reads and returns a new object from the given JSON {@link String}. This method
* will throw an {@link IllegalStateException} if parsing fails.
*
* @param jsonString
@@ -252,7 +251,7 @@
/**
* Reads and returns a new object form the given {@link CharacterIterator} that corresponds to
- * a properly formatted json string. This method will throw an {@link IllegalStateException} if
+ * a properly formatted JSON string. This method will throw an {@link IllegalStateException} if
* parsing fails.
*
* @param it the {@link CharacterIterator} to parse
@@ -362,9 +361,12 @@
return ""; //$NON-NLS-1$
}
StringBuffer buffer = new StringBuffer();
- while (c != '"') {
+ while (c != CharacterIterator.DONE && c != '"') {
if (Character.isISOControl(c)) {
- throw error("illegal iso control character: '" + Integer.toHexString(c) + "'", it); //$NON-NLS-1$ //$NON-NLS-2$);
+ //ignore it and continue
+ c = it.next();
+ continue;
+ //throw error("illegal ISO control character: '" + Integer.toHexString(c) + "'", it); //$NON-NLS-1$ //$NON-NLS-2$);
}
if (c == '\\') {
c = it.next();
@@ -436,7 +438,7 @@
}
Map map = new HashMap();
- while (true) {
+ while (it.current() != CharacterIterator.DONE) {
if (it.current() != '"') {
throw error("expected a string start '\"' but was '" + it.current() + "'", it); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -483,7 +485,7 @@
}
List list = new ArrayList();
- while (true) {
+ while (it.current() != CharacterIterator.DONE) {
Object value = parseValue(it);
list.add(value);
parseWhitespace(it);
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/PacketManager.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/PacketManager.java
deleted file mode 100644
index a350448..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/PacketManager.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import java.io.IOException;
-
-/**
- * Default manager for sending / receiving packets to / from the connected {@link VirtualMachine}
- *
- * @since 1.0
- */
-public abstract class PacketManager implements Runnable {
-
- /**
- * Connector that performs IO to Virtual Machine.
- */
- private final Connection connection;
- /**
- * Thread that handles the communication the other way (e.g. if we are sending, the receiving thread).
- */
- private volatile Thread partnerThread;
- /**
- * The disconnected exception, if there is one
- */
- private volatile IOException disconnectedException;
-
- /**
- * Constructor
- *
- * @param connection the connection to communicate on, <code>null</code> is not accepted
- */
- protected PacketManager(Connection connection) {
- if(connection == null) {
- throw new IllegalArgumentException("You cannot create a new PacketManager with a null Connection"); //$NON-NLS-1$
- }
- this.connection = connection;
- }
-
- /**
- * Returns the {@link Connection} this manager is communicating on.<br>
- * <br>
- * This method cannot return <code>null</code>
- *
- * @return the backing {@link Connection} to the {@link VirtualMachine}
- */
- public Connection getConnection() {
- return this.connection;
- }
-
- /**
- * Used to indicate that an IO exception occurred, closes the {@link Connection}
- * to the {@link VirtualMachine}.
- *
- * @param disconnectedException the IOException that occurred or <code>null</code>
- */
- public void disconnect(IOException exception) {
- this.disconnectedException = exception;
- disconnect();
- }
-
- /**
- * Closes the {@link Connection} to the {@link VirtualMachine}.
- */
- public void disconnect() {
- try {
- this.connection.close();
- } catch (IOException e) {
- this.disconnectedException = e;
- }
- if (this.partnerThread != null) {
- this.partnerThread.interrupt();
- }
- }
-
- /**
- * Returns if the manager is disconnected or not.
- *
- * @return <code>true</code> if the manager is disconnected false otherwise
- */
- public boolean isDisconnected() {
- return this.connection == null || !this.connection.isOpen();
- }
-
- /**
- * Returns the underlying {@link IOException} from a disconnect.<br>
- * <br>
- * This method can return <code>null</code> if the manager has not been disconnected
- *
- * @return the underlying {@link IOException} from a disconnect or <code>null</code> if none
- */
- public IOException getDisconnectedException() {
- return this.disconnectedException;
- }
-
- /**
- * Assigns thread of partner, to be notified if we have an {@link IOException}.
- *
- * @param thread the new partner thread, <code>null</code> is not accepted
- */
- public void setPartnerThread(Thread thread) {
- if(thread == null) {
- throw new IllegalArgumentException("You cannot send a null partner thread on the PacketManager"); //$NON-NLS-1$
- }
- this.partnerThread = thread;
- }
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/PacketReceiveManager.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/PacketReceiveManager.java
deleted file mode 100644
index e70f47c..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/PacketReceiveManager.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * Default implementation of {@link PacketManager} for receiving packets from the
- * {@link VirtualMachine}
- *
- * @since 1.0
- */
-public class PacketReceiveManager extends PacketManager {
-
- /**
- * Generic timeout value for not blocking. <br>
- * Value is: <code>0</code>
- */
- public static final int TIMEOUT_NOT_BLOCKING = 0;
- /**
- * Generic timeout value for infinite timeout. <br>
- * Value is: <code>-1</code>
- */
- public static final int TIMEOUT_INFINITE = -1;
- /**
- * List of Command packets received from Virtual Machine.
- */
- private List commandPackets = new LinkedList();
- /**
- * List of Reply packets received from Virtual Machine.
- */
- private List responsePackets = new LinkedList();
- /**
- * List of Packets that have timed out already. Maintained so that responses can be discarded if/when they are received.
- */
- private List timedOutPackets = new ArrayList();
-
- /**
- * Constructor
- *
- * @param connection the underlying connection to communicate on, <code>null</code> is not accepted
- */
- public PacketReceiveManager(Connection connection) {
- super(connection);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.PacketManager#disconnect()
- */
- public void disconnect() {
- super.disconnect();
- synchronized (this.commandPackets) {
- this.commandPackets.notifyAll();
- }
- synchronized (this.responsePackets) {
- this.responsePackets.notifyAll();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Runnable#run()
- */
- public void run() {
- try {
- while (!isDisconnected()) {
- // Read a packet from the input stream.
- readAvailablePacket();
- }
- }
- // if the remote runtime is interrupted, drop the connection and clean up, don't wait for it to happen on its own
- catch (InterruptedIOException e) {
- disconnect(e);
- } catch (IOException e) {
- disconnect(e);
- }
- }
-
- /**
- * Returns a specified command {@link Packet} from the {@link VirtualMachine}.<br>
- * <br>
- * This method cannot return <code>null</code> an exception is thrown if the desired packet cannot
- * be returned.
- *
- * @param type the type of the packet to get
- * @param timeToWait the amount of time to wait for the {@link Packet} to arrive
- *
- * @return the specified command packet never <code>null</code>
- * @throws TimeoutException if the request times out
- * @throws DisconnectedException if the manager is disconnected
- */
- public Packet getCommand(String type, long timeToWait) throws TimeoutException, DisconnectedException {
- synchronized (this.commandPackets) {
- long remainingTime = timeToWait;
- // Wait until command is available.
- //even if disconnected try to send the remaining events
- while (!isDisconnected() || !this.commandPackets.isEmpty()) {
- Packet packet = removeCommandPacket(type);
- if (packet != null)
- return packet;
-
- if (remainingTime < 0 && timeToWait != TIMEOUT_INFINITE)
- break;
-
- long timeBeforeWait = System.currentTimeMillis();
- try {
- waitForPacketAvailable(remainingTime, this.commandPackets);
- } catch (InterruptedException e) {
- break;
- }
- long waitedTime = System.currentTimeMillis() - timeBeforeWait;
- remainingTime -= waitedTime;
- }
- }
- // Check for an IO Exception.
- if (isDisconnected()) {
- throw new DisconnectedException("Runtime disconnected", getDisconnectedException()); //$NON-NLS-1$
- }
- // Check for a timeout.
- throw new TimeoutException("Timed out waiting for command packet: " + type); //$NON-NLS-1$
- }
-
- /**
- * Returns a specified response packet from the {@link VirtualMachine}.<br>
- * <br>
- * This method cannot return <code>null</code> an exception is thrown if the desired response cannot
- * be returned.
- *
- * @param requestSequence the sequence of the response to acquire
- * @param timeToWait the amount of time to wait for the {@link Response}
- *
- * @return a specified response packet from the {@link VirtualMachine} never <code>null</code>
- * @throws TimeoutException if the request times out
- * @throws DisconnectedException if the manager is disconnected
- */
- public Response getResponse(int requestSequence, long timeToWait) throws TimeoutException, DisconnectedException {
- synchronized (this.responsePackets) {
- long remainingTime = timeToWait;
- // Wait until command is available.
- while (!isDisconnected()) {
- Response response = removeResponsePacket(requestSequence);
- if (response != null)
- return response;
-
- if (remainingTime < 0 && timeToWait != TIMEOUT_INFINITE)
- break;
-
- long timeBeforeWait = System.currentTimeMillis();
- try {
- waitForPacketAvailable(remainingTime, this.responsePackets);
- } catch (InterruptedException e) {
- break;
- }
- long waitedTime = System.currentTimeMillis() - timeBeforeWait;
- remainingTime -= waitedTime;
- }
- }
- // Check for an IO Exception.
- if (isDisconnected()) {
- throw new DisconnectedException("Runtime disconnected", getDisconnectedException()); //$NON-NLS-1$
- }
-
- synchronized (this.responsePackets) {
- this.timedOutPackets.add(new Integer(requestSequence));
- }
- throw new TimeoutException("Timed out waiting for packet: " + requestSequence); //$NON-NLS-1$
- }
-
- /**
- * Wait for an available packet from the Virtual Machine.
- */
- private void waitForPacketAvailable(long timeToWait, Object lock) throws InterruptedException {
- if (timeToWait == 0)
- return;
- else if (timeToWait < 0)
- lock.wait();
- else
- lock.wait(timeToWait);
- }
-
- /**
- * Removes and returns the command packet for the given type or <code>null</code> if there is no command packet for the given type.
- *
- * @param type
- * @return The command packet for the given type that has been removed
- */
- private Packet removeCommandPacket(String type) {
- ListIterator iter = this.commandPackets.listIterator();
- while (iter.hasNext()) {
- Packet packet = (Packet) iter.next();
- if (type == null || packet.getType().equals(type)) {
- iter.remove();
- return packet;
- }
- }
- return null;
- }
-
- /**
- * Removes and returns the response packet with the given request sequence or <code>null</code> if there is no response packet with the given request sequence
- *
- * @param requestSequence
- * @return the response packet with the given request sequence that has been removed
- */
- private Response removeResponsePacket(int requestSequence) {
- ListIterator iter = this.responsePackets.listIterator();
- while (iter.hasNext()) {
- Response response = (Response) iter.next();
- if (requestSequence == response.getRequestSequence()) {
- iter.remove();
- return response;
- }
- }
- return null;
- }
-
- /**
- * Adds the given command packet to the listing of command packets. This method is a no-op if the given packet is <code>null</code>
- *
- * @param packet
- */
- private void addCommandPacket(Packet packet) {
- if (packet == null) {
- return;
- }
- synchronized (this.commandPackets) {
- this.commandPackets.add(packet);
- this.commandPackets.notifyAll();
- }
- }
-
- /**
- * Adds the given response packet to the listing of response packets. This method is a no-op if the given packet is <code>null</code>
- *
- * @param response
- */
- private void addResponsePacket(Response response) {
- if (response == null) {
- return;
- }
- synchronized (this.responsePackets) {
- if (!this.timedOutPackets.isEmpty()) {
- Integer requestSeq = new Integer(response.getRequestSequence());
- if (this.timedOutPackets.remove(requestSeq))
- return; // already timed out. No need to keep this one
- }
- this.responsePackets.add(response);
- this.responsePackets.notifyAll();
- }
- }
-
- /**
- * Reads the next packet from the underlying connection and adds it to the correct packet listing.
- *
- * @throws IOException
- */
- private void readAvailablePacket() throws IOException {
- // Read a packet from the Input Stream.
- Packet packet = getConnection().readPacket();
- if (packet instanceof Response) {
- addResponsePacket((Response) packet);
- }
- else {
- addCommandPacket(packet);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/PacketSendManager.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/PacketSendManager.java
deleted file mode 100644
index 5050d3f..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/PacketSendManager.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * Default implementation of {@link PacketManager} for sending packets to the
- * {@link VirtualMachine}
- *
- * @since 1.0
- */
-public class PacketSendManager extends PacketManager {
-
- /**
- * List of packets to be sent to Virtual Machine
- */
- private final List outgoingPackets = new ArrayList();
-
- /**
- * Create a new thread that send packets to the {@link VirtualMachine}.
- *
- * @param connection the underlying connection to communicate on, <code>null</code> is not accepted
- */
- public PacketSendManager(Connection connection) {
- super(connection);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.PacketManager#disconnect()
- */
- public void disconnect() {
- super.disconnect();
- synchronized (outgoingPackets) {
- outgoingPackets.notifyAll();
- }
- }
-
- /* (non-Javadoc)
- * @see java.lang.Runnable#run()
- */
- public void run() {
- while (!isDisconnected()) {
- try {
- sendAvailablePackets();
- }
- // in each case if the remote runtime fails, or has been interrupted, disconnect and force a clean up, don't wait for it to happen
- catch (InterruptedException e) {
- disconnect();
- } catch (InterruptedIOException e) {
- disconnect(e);
- } catch (IOException e) {
- disconnect(e);
- }
- }
- }
-
- /**
- * Sends the given {@link Packet}.
- *
- * @param packet the packet to send, <code>null</code> is not accepted
- *
- * @throws DisconnectedException
- */
- public void sendPacket(Packet packet) throws DisconnectedException {
- if(packet == null) {
- throw new IllegalArgumentException("You cannot send a null packet"); //$NON-NLS-1$
- }
- if (isDisconnected()) {
- throw new DisconnectedException("Runtime disconnected", getDisconnectedException()); //$NON-NLS-1$
- }
- synchronized (outgoingPackets) {
- // Add packet to list of packets to send.
- outgoingPackets.add(packet);
- // Notify PacketSendThread that data is available.
- outgoingPackets.notifyAll();
- }
- }
-
- /**
- * Send available packets to the Virtual Machine.
- */
- private void sendAvailablePackets() throws InterruptedException, IOException {
- Object[] packetsToSend;
- synchronized (outgoingPackets) {
- while (outgoingPackets.size() == 0) {
- outgoingPackets.wait();
- }
- packetsToSend = outgoingPackets.toArray();
- outgoingPackets.clear();
- }
-
- // Put available packets on Output Stream.
- for (int i = 0; i < packetsToSend.length; i++) {
- getConnection().writePacket((Packet) packetsToSend[i]);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Response.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Response.java
deleted file mode 100644
index b2b427b..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/Response.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Default {@link Response} implementation using JSON
- *
- * @since 1.0
- */
-public class Response extends Packet {
-
- /**
- * The type of this packet
- */
- public static final String RESPONSE = "response"; //$NON-NLS-1$
-
- static final Map failed_attributes;
- static {
- failed_attributes = new HashMap();
- Integer value = new Integer(-1);
- failed_attributes.put(Attributes.SEQ, value);
- failed_attributes.put(Attributes.TYPE, RESPONSE);
- failed_attributes.put(Attributes.REQUEST_SEQ, value);
- failed_attributes.put(Attributes.COMMAND, "failed"); //$NON-NLS-1$
- failed_attributes.put(Attributes.SUCCESS, Boolean.FALSE);
- failed_attributes.put(Attributes.RUNNING, Boolean.FALSE);
- }
-
- public static final Response FAILED = new Response(failed_attributes);
-
- private String command;
- private int requestSequence;
- private Map body = Collections.synchronizedMap(new HashMap());
- private volatile boolean success = true;
- private volatile boolean running = true;
- private volatile String message;
-
- /**
- * Constructor
- *
- * @param requestSequence the sequence
- * @param command the command, <code>null</code> is not accepted
- */
- public Response(int requestSequence, String command) {
- super(RESPONSE, null);
- if(command == null) {
- throw new IllegalArgumentException("The command string for a response packet cannot be null"); //$NON-NLS-1$
- }
- this.requestSequence = requestSequence;
- this.command = command.intern();
- }
-
- /**
- * Constructor
- *
- * @param json the JSON map for a response, <code>null</code> is not accepted
- */
- public Response(Map json) {
- super(json);
- Number packetRequestSeq = (Number) json.get(Attributes.REQUEST_SEQ);
- requestSequence = packetRequestSeq.intValue();
-
- String packetCommand = (String) json.get(Attributes.COMMAND);
- command = packetCommand.intern();
-
- Object bdy = json.get(Attributes.BODY);
- if(bdy instanceof Map) {
- Map packetBody = (Map)bdy;
- body.putAll(packetBody);
- }
-
- Boolean packetSuccess = (Boolean) json.get(Attributes.SUCCESS);
- success = packetSuccess.booleanValue();
-
- Boolean packetRunning = (Boolean) json.get(Attributes.RUNNING);
- running = packetRunning.booleanValue();
-
- message = (String) json.get(Attributes.MESSAGE);
- }
-
- /**
- * Returns the request sequence
- *
- * @return the request sequence
- */
- public int getRequestSequence() {
- return requestSequence;
- }
-
- /**
- * Returns the underlying command.<br>
- * <br>
- * This method cannot return <code>null</code>
- *
- * @return the underlying command, never <code>null</code>
- */
- public String getCommand() {
- return command;
- }
-
- /**
- * Returns the body of the command.<br>
- * <br>
- * This method cannot return <code>null</code>, if there is no body
- * an empty {@link Map} is returned.
- *
- * @return the body of the JSON response or an empty {@link Map} never <code>null</code>
- */
- public Map getBody() {
- return body;
- }
-
- /**
- * Returns <code>true</code> if the {@link Request} was successful
- *
- * @return <code>true</code> if the {@link Request} was successful, <code>false</code> otherwise
- */
- public boolean isSuccess() {
- return success;
- }
-
- /**
- * Set the success flag for the response
- *
- * @param success the new success flag
- */
- public void setSuccess(boolean success) {
- this.success = success;
- }
-
- /**
- * Returns <code>true</code> if the underlying command is currently running.
- *
- * @return <code>true</code> if the underlying command is running, <code>false</code> otherwise
- */
- public boolean isRunning() {
- return running;
- }
-
- /**
- * Sets the running state of the underlying command
- *
- * @param running the new running state for the underlying command
- */
- public void setRunning(boolean running) {
- this.running = running;
- }
-
- /**
- * Returns the status message for this {@link Response}.<br>
- * <br>
- * This method can return <code>null</code>
- *
- * @return the status message for this {@link Response} or <code>null</code>
- */
- public String getMessage() {
- return message;
- }
-
- /**
- * Set the status message for this {@link Response}
- *
- * @param message the new message, <code>null</code> is accepted
- */
- public void setMessage(String message) {
- this.message = message;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.Packet#toJSON()
- */
- public Map toJSON() {
- Map json = super.toJSON();
- json.put(Attributes.REQUEST_SEQ, new Integer(requestSequence));
- json.put(Attributes.COMMAND, command);
- json.put(Attributes.BODY, body);
- json.put(Attributes.SUCCESS, new Boolean(success));
- json.put(Attributes.RUNNING, new Boolean(running));
- if (message != null) {
- json.put(Attributes.MESSAGE, message);
- }
- return json;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- Object json = toJSON();
- buffer.append("Response: "); //$NON-NLS-1$
- JSON.writeValue(json, buffer);
- return buffer.toString();
- }
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/SocketConnection.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/SocketConnection.java
deleted file mode 100644
index 9f13e6a..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/SocketConnection.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.Socket;
-import java.util.Map;
-
-import org.eclipse.wst.jsdt.debug.internal.crossfire.Constants;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.CrossFirePlugin;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.Tracing;
-
-/**
- * A specialized {@link Connection} that communicates using {@link Socket}s
- *
- * @since 1.0
- */
-public class SocketConnection implements Connection {
-
- private Writer writer;
- private Reader reader;
- private Socket socket;
-
- /**
- * Constructor
- *
- * @param socket the underlying {@link Socket}, <code>null</code> is not accepted
- *
- * @throws IOException
- */
- public SocketConnection(Socket socket) throws IOException {
- if(socket == null) {
- throw new IllegalArgumentException("You cannot create a new SocketConnection on a null Socket"); //$NON-NLS-1$
- }
- this.socket = socket;
- writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), Constants.UTF_8));
- reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), Constants.UTF_8));
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.Connection#isOpen()
- */
- public boolean isOpen() {
- return !socket.isClosed();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.Connection#close()
- */
- public void close() throws IOException {
- socket.close();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.Connection#writePacket(org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.Packet)
- */
- public void writePacket(Packet packet) throws IOException {
- String serialized = JSON.serialize(packet);
- if(Packet.TRACE) {
- Tracing.writeString("WRITE PACKET: "+serialized); //$NON-NLS-1$
- }
- writer.write(serialized);
- writer.flush();
- }
-
- /**
- * Writes the standard handshake packet to connect
- *
- * @param packet
- * @throws IOException
- */
- public void writeHandShake() throws IOException {
- if(Packet.TRACE) {
- Tracing.writeString("WRITE HANDSHAKE: "+HandShake.getHandshake()); //$NON-NLS-1$
- }
- writer.write(HandShake.getHandshake());
- writer.flush();
- waitForReadyRead();
- }
-
- /**
- * Method to wait for the socket reader to become ready after the handshake
- *
- * @throws IOException
- */
- void waitForReadyRead() throws IOException {
- long timeout = System.currentTimeMillis() + 1000;
- boolean timedout = System.currentTimeMillis() > timeout;
- while(!reader.ready() && !timedout) {
- try {
- Thread.sleep(100);
- timedout = System.currentTimeMillis() > timeout;
- } catch (InterruptedException e) {
- CrossFirePlugin.log(e);
- }
- }
- if(timedout) {
- if(Packet.TRACE) {
- Tracing.writeString("HANDSHAKE: Timed out waiting for ready read from handshake"); //$NON-NLS-1$
- }
- //throw new IOException("Waiting for the socket to become available after receiving handshake timed out."); //$NON-NLS-1$
- }
- }
-
- /**
- * Reads the {@link HandShake} packet from the the stream
- *
- * @return the {@link HandShake}, never <code>null</code>
- * @throws IOException
- */
- public Packet readHandShake() throws IOException {
- StringBuffer buffer = new StringBuffer();
- //read the header first
- int c = 0;
- boolean r = false;
- while((c = reader.read()) > -1) {
- buffer.append((char)c);
- if(r) {
- if(c == '\n') {
- break;
- }
- }
- r = c == '\r';
- }
- if(buffer.toString().equals(HandShake.getHandshake())) {
- HandShake ack = new HandShake();
- if(Packet.TRACE) {
- Tracing.writeString("ACK HANDSHAKE: "+ack); //$NON-NLS-1$
- }
- return ack;
- }
- while(reader.ready()) {
- c = reader.read();
- if(Packet.TRACE) {
- Tracing.writeString("Reading extra post-amble from socket: "+(char)c); //$NON-NLS-1$
- }
- }
-
- throw new IOException("Did not get correct CrossFire handshake"); //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.Connection#readPacket()
- */
- public Packet readPacket() throws IOException {
- StringBuffer buffer = new StringBuffer();
- int c = -1;
- boolean len = false;
- while((c = reader.read()) > -1) {
- if(c == '\r') {
- break;
- }
- if(len) {
- buffer.append((char)c);
- continue;
- }
- len = c == ':';
- }
- int length = 0;
- try {
- length = Integer.parseInt(buffer.toString());
- } catch (NumberFormatException e) {
- throw new IOException("Failed to parse content length: " + buffer.toString()); //$NON-NLS-1$
- }
- c = reader.read();
- if(c != '\n') {
- throw new IOException("Failed to parse content length: " + buffer.toString() + "next char was not '\n'" + (char)c); //$NON-NLS-1$ //$NON-NLS-2$
- }
- char[] message = new char[length];
- int n = 0;
- int off = 0;
- while (n < length) {
- int count = reader.read(message, off + n, length - n);
- if (count < 0) {
- throw new EOFException();
- }
- n += count;
- }
- if(Packet.TRACE) {
- Tracing.writeString("READ PACKET: [length - "+length+"]"+new String(message)); //$NON-NLS-1$ //$NON-NLS-2$
- }
- Map json = (Map) JSON.read(new String(message));
- String type = Packet.getType(json);
- if (Event.EVENT.equals(type)) {
- return new Event(json);
- }
- if (Request.REQUEST.equals(type)) {
- return new Request(json);
- }
- if (Response.RESPONSE.equals(type)) {
- return new Response(json);
- }
- throw new IOException("Unknown packet type: " + type); //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/SocketTransportService.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/SocketTransportService.java
deleted file mode 100644
index 230d137..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/SocketTransportService.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.wst.jsdt.debug.internal.crossfire.Constants;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.connect.HostArgument;
-import org.eclipse.wst.jsdt.debug.internal.crossfire.connect.Messages;
-
-
-/**
- * Implementation of a transport service that using a {@link Socket} for communication
- *
- * @since 1.0
- */
-public class SocketTransportService implements TransportService {
-
- static final Class serverSocketClass = ServerSocket.class; // temporary used to pre-load the ServerSocket.class
-
- /**
- * Key implementation
- */
- public static class SocketListenerKey implements ListenerKey {
-
- private String address;
-
- public SocketListenerKey(String address) {
- this.address = address;
- }
-
- public String address() {
- return address;
- }
- }
-
- /**
- * Map of {@link ListenerKey} to {@link ServerSocket}s
- */
- Map listeners = new HashMap();
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.TransportService#startListening(java.lang.String)
- */
- public synchronized ListenerKey startListening(String address) throws IOException {
- String host = null;
- int port = 0;
- if (address != null) {
- String[] strings = address.split(Constants.COLON);
- if (strings.length == 2) {
- host = strings[0];
- port = Integer.parseInt(strings[1]);
- } else {
- port = Integer.parseInt(strings[0]);
- }
- }
- if (host == null) {
- host = LOCALHOST;
- }
- if (!HostArgument.isLocalhost(host)) {
- throw new IllegalArgumentException(Messages.only_localhost_is_supported);
- }
- ListenerKey key = new SocketListenerKey(host + Constants.COLON + port);
- ServerSocket serverSocket = new ServerSocket(port);
- listeners.put(key, serverSocket);
- return key;
-
- };
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.TransportService#stopListening(org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.TransportService.ListenerKey)
- */
- public void stopListening(ListenerKey key) throws IOException {
- ServerSocket serverSocket = (ServerSocket) listeners.remove(key);
- if (serverSocket != null) {
- serverSocket.close();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.TransportService#accept(org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.TransportService.ListenerKey, long, long)
- */
- public Connection accept(ListenerKey key, long attachTimeout, long handshakeTimeout) throws IOException {
- ServerSocket serverSocket = (ServerSocket) listeners.get(key);
- if (serverSocket == null) {
- throw new IllegalStateException("Accept failed. Not listening for address: key.address()"); //$NON-NLS-1$
- }
- int timeout = (int) attachTimeout;
- if (timeout > 0) {
- if (timeout > Integer.MAX_VALUE) {
- timeout = Integer.MAX_VALUE; // approximately 25 days!
- }
- serverSocket.setSoTimeout(timeout);
- }
- SocketConnection connection = new SocketConnection(serverSocket.accept());
- Packet packet = connection.readHandShake();
- if (!(packet instanceof HandShake)) {
- throw new IOException("failure establishing connection"); //$NON-NLS-1$
- }
- connection.writeHandShake();
- return connection;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.jsdt.debug.internal.core.jsdi.connect.TransportService#attach(java.lang.String, long, long)
- */
- public Connection attach(String address, long attachTimeout, long handshakeTimeout) throws IOException {
- String host = null;
- int port = 0;
- if (address != null) {
- String[] strings = address.split(Constants.COLON);
- if (strings.length == 2) {
- host = strings[0];
- port = Integer.parseInt(strings[1]);
- } else {
- port = Integer.parseInt(strings[0]);
- }
- }
- if (host == null) {
- host = LOCALHOST;
- }
- SocketConnection connection = new SocketConnection(new Socket(host, port));
- connection.writeHandShake();
- Packet packet = connection.readPacket();
- if (!(packet instanceof HandShake)) {
- throw new IOException("failure establishing connection"); //$NON-NLS-1$
- }
- return connection;
- }
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/TimeoutException.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/TimeoutException.java
deleted file mode 100644
index 0c93e70..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/TimeoutException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-/**
- * This exception is thrown if the {@link PacketSendManager} or {@link PacketReceiveManager}
- * times out while waiting for a response
- *
- * @since 1.0
- */
-public final class TimeoutException extends Exception {
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor
- *
- * @param message the message for the exception
- */
- public TimeoutException(String message) {
- super(message);
- }
-
-}
diff --git a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/TransportService.java b/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/TransportService.java
deleted file mode 100644
index 3d88d89..0000000
--- a/bundles/org.eclipse.wst.jsdt.debug.crossfire/src/org/eclipse/wst/jsdt/debug/internal/crossfire/transport/TransportService.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.debug.internal.crossfire.transport;
-
-import java.io.IOException;
-
-
-/**
- * A transport service is used to attach and / or listen to a
- * {@link Connection} exactly how the service communicates is an implementation detail.
- *
- * @since 1.0
- */
-public interface TransportService {
-
- public static final String LOCALHOST = "localhost"; //$NON-NLS-1$
- public static final String PORT = "port"; //$NON-NLS-1$
-
- /**
- * Describes a unique address to listen on
- */
- public interface ListenerKey {
- public String address();
- }
-
- /**
- * The IP address representation of <code>localhost</code>
- */
- public static final String LOCALHOST_IP = "127.0.0.1"; //$NON-NLS-1$
-
- /**
- * Registers that this service should begin listening to the given address
- *
- * @param address the address to listen on - e.g. localhost:12000
- * @return the key that uniquely identifies this service
- * @throws IOException
- */
- public ListenerKey startListening(String address) throws IOException;
-
- /**
- * Stops listening for the given key
- *
- * @param listenerKey
- * @throws IOException
- */
- public void stopListening(ListenerKey listenerKey) throws IOException;
-
- /**
- * Listens for a connection to be made to and accepts it. The method can block until a connection is made.
- *
- * @param listenerKey
- * @param attachTimeout
- * @param handshakeTimeout
- * @return the resulting {@link Connection}
- * @throws IOException
- */
- public Connection accept(ListenerKey listenerKey, long attachTimeout, long handshakeTimeout) throws IOException;
-
- /**
- * Attaches to the given address and returns the resulting connection. This method can block until a connection is made
- *
- * @param address
- * @param attachTimeout
- * @param handshakeTimeout
- * @return the resulting {@link Connection}
- * @throws IOException
- */
- public Connection attach(String address, long attachTimeout, long handshakeTimeout) throws IOException;
-
-}
\ No newline at end of file