From eb5f7f9d042f832bef13e7435e9b43f37b496269 Mon Sep 17 00:00:00 2001 From: pombredanne Date: Thu, 6 Dec 2007 20:48:20 +0000 Subject: [PATCH 1/1] Importing the XDebugProxy code in the HEAD. The repo was tagged with T_BEFORE_XDEBUGPROXY_BRANCH_IMPORT_INHEAD_20071206 prior to that commit. --- .../META-INF/MANIFEST.MF | 14 +- .../build.properties | 6 - net.sourceforge.phpeclipse.xdebug.core/plugin.xml | 13 + .../xdebug/core/AbstractDebugConnection.java | 27 + .../sourceforge/phpeclipse/xdebug/core/Base64.java | 2835 ++++++++++---------- .../xdebug/core/BreakpointResponseData.java | 25 - .../phpeclipse/xdebug/core/DebugConnection.java | 431 --- .../phpeclipse/xdebug/core/IDebugConnection.java | 116 + .../phpeclipse/xdebug/core/IPHPDebugEvent.java | 9 + .../xdebug/core/IProxyEventListener.java | 7 + .../xdebug/core/IXDebugPreferenceConstants.java | 2 - .../phpeclipse/xdebug/core/ListenerList.java | 128 + .../phpeclipse/xdebug/core/ListenerMap.java | 125 + .../phpeclipse/xdebug/core/PHPDebugUtils.java | 47 +- .../phpeclipse/xdebug/core/PathMapItem.java | 132 + .../phpeclipse/xdebug/core/ResponseData.java | 18 - .../phpeclipse/xdebug/core/XDebugCorePlugin.java | 104 +- .../phpeclipse/xdebug/core/XDebugProxy.java | 281 ++ .../xdebug/core/xdebug/ResponseList.java | 34 + .../xdebug/core/xdebug/ResponseListener.java | 347 +++ .../xdebug/core/xdebug/XDebugConnection.java | 538 ++++ .../xdebug/php/launching/IXDebugConstants.java | 43 +- .../launching/PHPLaunchConfigurationDelegate.java | 131 +- .../PHPRemoteLaunchConfigurationDelegate.java | 50 + .../php/launching/PHPSourceLookupDirector.java | 19 +- .../php/launching/PHPSourceLookupParticipant.java | 140 +- .../launching/PHPSourcePathComputerDelegate.java | 56 +- .../xdebug/php/model/XDebugAbstractValue.java | 303 ++- .../xdebug/php/model/XDebugArrayValue.java | 11 +- .../xdebug/php/model/XDebugBooleanValue.java | 38 +- .../phpeclipse/xdebug/php/model/XDebugElement.java | 94 +- .../xdebug/php/model/XDebugFloatValue.java | 20 +- .../xdebug/php/model/XDebugIntValue.java | 26 +- .../xdebug/php/model/XDebugLineBreakpoint.java | 140 +- .../xdebug/php/model/XDebugObjectValue.java | 10 +- .../xdebug/php/model/XDebugResourceValue.java | 40 + .../xdebug/php/model/XDebugStackFrame.java | 417 ++-- .../xdebug/php/model/XDebugStringValue.java | 18 +- .../phpeclipse/xdebug/php/model/XDebugTarget.java | 664 +++--- .../phpeclipse/xdebug/php/model/XDebugThread.java | 247 +- .../phpeclipse/xdebug/php/model/XDebugValue.java | 19 +- .../xdebug/php/model/XDebugVariable.java | 307 ++- .../php/model/XDebugWatchExpressionDelegate.java | 53 + .../php/model/XDebugWatchExpressionResult.java | 37 + .../META-INF/MANIFEST.MF | 16 +- .../build.properties | 14 +- .../icons/obj16/xdebug.gif | Bin 347 -> 0 bytes .../icons/xdebug.gif | Bin 0 -> 178 bytes net.sourceforge.phpeclipse.xdebug.ui/plugin.xml | 131 +- .../phpeclipse/xdebug/ui/EditPathMapDialog.java | 104 + .../phpeclipse/xdebug/ui/EnvironmentVariable.java | 47 +- .../phpeclipse/xdebug/ui/MultipleInputDialog.java | 262 +- .../phpeclipse/xdebug/ui/XDebugUIPlugin.java | 84 +- .../phpeclipse/xdebug/ui/XDebugUIPluginImages.java | 176 +- .../ui/actions/BreakpointRulerActionDelegate.java | 4 +- .../ui/actions/ToggleBreakpointRulerAction.java | 106 +- .../php/launching/PHPDebugModelPresentation.java | 98 +- .../xdebug/ui/php/launching/PHPEnvironmentTab.java | 44 +- .../xdebug/ui/php/launching/PHPMainTab.java | 167 +- .../xdebug/ui/php/launching/PHPPathMapTab.java | 476 ++++ .../xdebug/ui/php/launching/PHPRemoteDebug.java | 222 ++ .../xdebug/ui/php/launching/PHPRemoteTabGroup.java | 21 + .../xdebug/ui/php/launching/PHPTabGroup.java | 11 +- .../xdebug/ui/php/launching/XDebugTab.java | 58 +- .../ui/php/model/PHPBreakpointAdapterFactory.java | 2 +- .../ui/php/model/PHPLineBreakpointAdapter.java | 24 +- .../xdebug/ui/preference/XDebugPreferencePage.java | 44 +- 67 files changed, 6435 insertions(+), 3798 deletions(-) create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/AbstractDebugConnection.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/BreakpointResponseData.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/DebugConnection.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IDebugConnection.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IPHPDebugEvent.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IProxyEventListener.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ListenerList.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ListenerMap.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/PathMapItem.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ResponseData.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugProxy.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseList.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPRemoteLaunchConfigurationDelegate.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugResourceValue.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionDelegate.java create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionResult.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/icons/obj16/xdebug.gif create mode 100644 net.sourceforge.phpeclipse.xdebug.ui/icons/xdebug.gif create mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/EditPathMapDialog.java create mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPPathMapTab.java create mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPRemoteDebug.java create mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPRemoteTabGroup.java diff --git a/net.sourceforge.phpeclipse.xdebug.core/META-INF/MANIFEST.MF b/net.sourceforge.phpeclipse.xdebug.core/META-INF/MANIFEST.MF index 823ab16..48ca86f 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/META-INF/MANIFEST.MF +++ b/net.sourceforge.phpeclipse.xdebug.core/META-INF/MANIFEST.MF @@ -1,20 +1,18 @@ Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: XDebug Core +Bundle-Name: XDebug Core Plug-in Bundle-SymbolicName: net.sourceforge.phpeclipse.xdebug.core;singleton:=true -Bundle-Version: 0.0.1 +Bundle-Version: 0.0.0 Bundle-ClassPath: core.jar Bundle-Activator: net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin -Bundle-Vendor: PHPEclipse project team Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.debug.core, - org.eclipse.core.resources + org.eclipse.core.resources, + net.sourceforge.phpeclipse, + net.sourceforge.phpeclipse.externaltools Provide-Package: net.sourceforge.phpeclipse.xdebug.core, net.sourceforge.phpeclipse.xdebug.php.launching, net.sourceforge.phpeclipse.xdebug.php.model -Export-Package: net.sourceforge.phpeclipse.xdebug.core, - net.sourceforge.phpeclipse.xdebug.php.launching, - net.sourceforge.phpeclipse.xdebug.php.model Bundle-RequiredExecutionEnvironment: J2SE-1.4 Eclipse-LazyStart: true +Bundle-ManifestVersion: 2 diff --git a/net.sourceforge.phpeclipse.xdebug.core/build.properties b/net.sourceforge.phpeclipse.xdebug.core/build.properties index 6132541..2ef0d6b 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/build.properties +++ b/net.sourceforge.phpeclipse.xdebug.core/build.properties @@ -3,9 +3,3 @@ output.core.jar = bin/ bin.includes = META-INF/,\ core.jar,\ plugin.xml -src.includes = src/,\ - plugin.xml,\ - build.properties,\ - META-INF/,\ - .project,\ - .classpath diff --git a/net.sourceforge.phpeclipse.xdebug.core/plugin.xml b/net.sourceforge.phpeclipse.xdebug.core/plugin.xml index 5f73f82..69af34e 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/plugin.xml +++ b/net.sourceforge.phpeclipse.xdebug.core/plugin.xml @@ -10,6 +10,13 @@ name="PHP XDebug Script" sourceLocatorId="net.sourceforge.phpeclipse.xdebug.core.sourceLookupDirector.php" sourcePathComputerId="net.sourceforge.phpeclipse.xdebug.core.sourcePathComputer.php"/> + @@ -38,4 +45,10 @@ + + + diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/AbstractDebugConnection.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/AbstractDebugConnection.java new file mode 100644 index 0000000..e3efc17 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/AbstractDebugConnection.java @@ -0,0 +1,27 @@ +/** + * + */ +package net.sourceforge.phpeclipse.xdebug.core; + +/** + * @author Christian Perkonig + * + */ +public abstract class AbstractDebugConnection implements IDebugConnection { + protected boolean fInitialized = false; + protected boolean fIsClosed = true; + + protected String fSessionID = ""; + + public String getSessionID() { + return fSessionID; + } + + public boolean isInitialized() { + return fInitialized; + } + + public boolean isClosed() { + return fIsClosed; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/Base64.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/Base64.java index 1499af2..64cd0ae 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/Base64.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/Base64.java @@ -1,1413 +1,1450 @@ package net.sourceforge.phpeclipse.xdebug.core; - /** * Encodes and decodes to and from Base64 notation. - * + * *

* Change Log: *

* - * + * *

- * I am placing this code in the Public Domain. Do with it as you will. This - * software comes with no guarantees or warranties but with plenty of - * well-wishing instead! Please visit http://iharder.net/base64 periodically - * to check for updates or to contribute improvements. + * I am placing this code in the Public Domain. Do with it as you will. + * This software comes with no guarantees or warranties but with + * plenty of well-wishing instead! + * Please visit http://iharder.net/base64 + * periodically to check for updates or to contribute improvements. *

- * + * * @author Robert Harder * @author rob@iharder.net * @version 2.1 */ -public class Base64 { - - /* ******** P U B L I C F I E L D S ******** */ - - /** No options specified. Value is zero. */ - public final static int NO_OPTIONS = 0; - - /** Specify encoding. */ - public final static int ENCODE = 1; - - /** Specify decoding. */ - public final static int DECODE = 0; - - /** Specify that data should be gzip-compressed. */ - public final static int GZIP = 2; - - /** Don't break lines when encoding (violates strict Base64 specification) */ - public final static int DONT_BREAK_LINES = 8; - - /* ******** P R I V A T E F I E L D S ******** */ - - /** Maximum line length (76) of Base64 output. */ - private final static int MAX_LINE_LENGTH = 76; - - /** The equals sign (=) as a byte. */ - private final static byte EQUALS_SIGN = (byte) '='; - - /** The new line character (\n) as a byte. */ - private final static byte NEW_LINE = (byte) '\n'; - - /** Preferred encoding. */ - private final static String PREFERRED_ENCODING = "UTF-8"; - - /** The 64 valid Base64 values. */ - private final static byte[] ALPHABET; - - private final static byte[] _NATIVE_ALPHABET = /* - * May be something funny - * like EBCDIC - */ - { (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', - (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', - (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', - (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', - (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', - (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', - (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', - (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', - (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', - (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', - (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', - (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', - (byte) '9', (byte) '+', (byte) '/' }; - - /** Determine which ALPHABET to use. */ - static { - byte[] __bytes; - try { - __bytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" - .getBytes(PREFERRED_ENCODING); - } // end try - catch (java.io.UnsupportedEncodingException use) { - __bytes = _NATIVE_ALPHABET; // Fall back to native encoding - } // end catch - ALPHABET = __bytes; - } // end static - - /** - * Translates a Base64 value to either its 6-bit reconstruction value or a - * negative number indicating some other meaning. - */ - private final static byte[] DECODABET = { -9, -9, -9, -9, -9, -9, -9, -9, - -9, // Decimal 0 - 8 - -5, -5, // Whitespace: Tab and Linefeed - -9, -9, // Decimal 11 - 12 - -5, // Whitespace: Carriage Return - -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - - // 26 - -9, -9, -9, -9, -9, // Decimal 27 - 31 - -5, // Whitespace: Space - -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42 - 62, // Plus sign at decimal 43 - -9, -9, -9, // Decimal 44 - 46 - 63, // Slash at decimal 47 - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine - -9, -9, -9, // Decimal 58 - 60 - -1, // Equals sign at decimal 61 - -9, -9, -9, // Decimal 62 - 64 - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' - // through 'N' - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' - // through 'Z' - -9, -9, -9, -9, -9, -9, // Decimal 91 - 96 - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // Letters 'a' - // through 'm' - 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // Letters 'n' - // through 'z' - -9, -9, -9, -9 // Decimal 123 - 126 - /* - * ,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139 - * -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 - * -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 - * -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178 - * -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191 - * -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204 - * -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 - * -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 - * -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 - * -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 - */ - }; - - // I think I end up not using the BAD_ENCODING indicator. - // private final static byte BAD_ENCODING = -9; // Indicates error in - // encoding - private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in - // encoding - - private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in - // encoding - - /** Defeats instantiation. */ - private Base64() { - } - - /* ******** E N C O D I N G M E T H O D S ******** */ - - /** - * Encodes up to the first three bytes of array threeBytes and - * returns a four-byte array in Base64 notation. The actual number of - * significant bytes in your array is given by numSigBytes. The - * array threeBytes needs only be as big as numSigBytes. - * Code can reuse a byte array by passing a four-byte array as b4. - * - * @param b4 - * A reusable byte array to reduce array instantiation - * @param threeBytes - * the array to convert - * @param numSigBytes - * the number of significant bytes in your array - * @return four byte array in Base64 notation. - * @since 1.5.1 - */ - private static byte[] encode3to4(byte[] b4, byte[] threeBytes, - int numSigBytes) { - encode3to4(threeBytes, 0, numSigBytes, b4, 0); - return b4; - } // end encode3to4 - - /** - * Encodes up to three bytes of the array source and writes the - * resulting four Base64 bytes to destination. The source and - * destination arrays can be manipulated anywhere along their length by - * specifying srcOffset and destOffset. This method - * does not check to make sure your arrays are large enough to accomodate - * srcOffset + 3 for the source array or - * destOffset + 4 for the destination array. The - * actual number of significant bytes in your array is given by - * numSigBytes. - * - * @param source - * the array to convert - * @param srcOffset - * the index where conversion begins - * @param numSigBytes - * the number of significant bytes in your array - * @param destination - * the array to hold the conversion - * @param destOffset - * the index where output will be put - * @return the destination array - * @since 1.3 - */ - private static byte[] encode3to4(byte[] source, int srcOffset, - int numSigBytes, byte[] destination, int destOffset) { - // 1 2 3 - // 01234567890123456789012345678901 Bit position - // --------000000001111111122222222 Array position from threeBytes - // --------| || || || | Six bit groups to index ALPHABET - // >>18 >>12 >> 6 >> 0 Right shift necessary - // 0x3f 0x3f 0x3f Additional AND - - // Create buffer with zero-padding if there are only one or two - // significant bytes passed in the array. - // We have to shift left 24 in order to flush out the 1's that appear - // when Java treats a value as negative that is cast from a byte to an - // int. - int inBuff = (numSigBytes > 0 ? ((source[srcOffset] << 24) >>> 8) : 0) - | (numSigBytes > 1 ? ((source[srcOffset + 1] << 24) >>> 16) : 0) - | (numSigBytes > 2 ? ((source[srcOffset + 2] << 24) >>> 24) : 0); - - switch (numSigBytes) { - case 3: - destination[destOffset] = ALPHABET[(inBuff >>> 18)]; - destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f]; - destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f]; - destination[destOffset + 3] = ALPHABET[(inBuff) & 0x3f]; - return destination; - - case 2: - destination[destOffset] = ALPHABET[(inBuff >>> 18)]; - destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f]; - destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f]; - destination[destOffset + 3] = EQUALS_SIGN; - return destination; - - case 1: - destination[destOffset] = ALPHABET[(inBuff >>> 18)]; - destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f]; - destination[destOffset + 2] = EQUALS_SIGN; - destination[destOffset + 3] = EQUALS_SIGN; - return destination; - - default: - return destination; - } // end switch - } // end encode3to4 - - /** - * Serializes an object and returns the Base64-encoded version of that - * serialized object. If the object cannot be serialized or there is another - * error, the method will return null. The object is not - * GZip-compressed before being encoded. - * - * @param serializableObject - * The object to encode - * @return The Base64-encoded object - * @since 1.4 - */ - public static String encodeObject(java.io.Serializable serializableObject) { - return encodeObject(serializableObject, NO_OPTIONS); - } // end encodeObject - - /** - * Serializes an object and returns the Base64-encoded version of that - * serialized object. If the object cannot be serialized or there is another - * error, the method will return null. - *

- * Valid options: - * - *

-	 *    GZIP: gzip-compresses object before encoding it.
-	 *    DONT_BREAK_LINES: don't break lines at 76 characters
-	 *      <i>Note: Technically, this makes your encoding non-compliant.</i>
-	 * 
- * - *

- * Example: encodeObject( myObj, Base64.GZIP ) or - *

- * Example: - * encodeObject( myObj, Base64.GZIP | Base64.DONT_BREAK_LINES ) - * - * @param serializableObject - * The object to encode - * @param options - * Specified options - * @return The Base64-encoded object - * @see Base64#GZIP - * @see Base64#DONT_BREAK_LINES - * @since 2.0 - */ - public static String encodeObject(java.io.Serializable serializableObject, - int options) { - // Streams - java.io.ByteArrayOutputStream baos = null; - java.io.OutputStream b64os = null; - java.io.ObjectOutputStream oos = null; - java.util.zip.GZIPOutputStream gzos = null; - - // Isolate options - int gzip = (options & GZIP); - int dontBreakLines = (options & DONT_BREAK_LINES); - - try { - // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream - baos = new java.io.ByteArrayOutputStream(); - b64os = new Base64.OutputStream(baos, ENCODE | dontBreakLines); - - // GZip? - if (gzip == GZIP) { - gzos = new java.util.zip.GZIPOutputStream(b64os); - oos = new java.io.ObjectOutputStream(gzos); - } // end if: gzip - else - oos = new java.io.ObjectOutputStream(b64os); - - oos.writeObject(serializableObject); - } // end try - catch (java.io.IOException e) { - e.printStackTrace(); - return null; - } // end catch - finally { - try { - oos.close(); - } catch (Exception e) { - } - try { - gzos.close(); - } catch (Exception e) { - } - try { - b64os.close(); - } catch (Exception e) { - } - try { - baos.close(); - } catch (Exception e) { - } - } // end finally - - // Return value according to relevant encoding. - try { - return new String(baos.toByteArray(), PREFERRED_ENCODING); - } // end try - catch (java.io.UnsupportedEncodingException uue) { - return new String(baos.toByteArray()); - } // end catch - - } // end encode - - /** - * Encodes a byte array into Base64 notation. Does not GZip-compress data. - * - * @param source - * The data to convert - * @since 1.4 - */ - public static String encodeBytes(byte[] source) { - return encodeBytes(source, 0, source.length, NO_OPTIONS); - } // end encodeBytes - - /** - * Encodes a byte array into Base64 notation. - *

- * Valid options: - * - *

-	 *    GZIP: gzip-compresses object before encoding it.
-	 *    DONT_BREAK_LINES: don't break lines at 76 characters
-	 *      <i>Note: Technically, this makes your encoding non-compliant.</i>
-	 * 
- * - *

- * Example: encodeBytes( myData, Base64.GZIP ) or - *

- * Example: - * encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES ) - * - * - * @param source - * The data to convert - * @param options - * Specified options - * @see Base64#GZIP - * @see Base64#DONT_BREAK_LINES - * @since 2.0 - */ - public static String encodeBytes(byte[] source, int options) { - return encodeBytes(source, 0, source.length, options); - } // end encodeBytes - - /** - * Encodes a byte array into Base64 notation. Does not GZip-compress data. - * - * @param source - * The data to convert - * @param off - * Offset in array where conversion should begin - * @param len - * Length of data to convert - * @since 1.4 - */ - public static String encodeBytes(byte[] source, int off, int len) { - return encodeBytes(source, off, len, NO_OPTIONS); - } // end encodeBytes - - /** - * Encodes a byte array into Base64 notation. - *

- * Valid options: - * - *

-	 *    GZIP: gzip-compresses object before encoding it.
-	 *    DONT_BREAK_LINES: don't break lines at 76 characters
-	 *      <i>Note: Technically, this makes your encoding non-compliant.</i>
-	 * 
- * - *

- * Example: encodeBytes( myData, Base64.GZIP ) or - *

- * Example: - * encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES ) - * - * - * @param source - * The data to convert - * @param off - * Offset in array where conversion should begin - * @param len - * Length of data to convert - * @param options - * Specified options - * @see Base64#GZIP - * @see Base64#DONT_BREAK_LINES - * @since 2.0 - */ - public static String encodeBytes(byte[] source, int off, int len, - int options) { - // Isolate options - int dontBreakLines = (options & DONT_BREAK_LINES); - int gzip = (options & GZIP); - - // Compress? - if (gzip == GZIP) { - java.io.ByteArrayOutputStream baos = null; - java.util.zip.GZIPOutputStream gzos = null; - Base64.OutputStream b64os = null; - - try { - // GZip -> Base64 -> ByteArray - baos = new java.io.ByteArrayOutputStream(); - b64os = new Base64.OutputStream(baos, ENCODE | dontBreakLines); - gzos = new java.util.zip.GZIPOutputStream(b64os); - - gzos.write(source, off, len); - gzos.close(); - } // end try - catch (java.io.IOException e) { - e.printStackTrace(); - return null; - } // end catch - finally { - try { - gzos.close(); - } catch (Exception e) { - } - try { - b64os.close(); - } catch (Exception e) { - } - try { - baos.close(); - } catch (Exception e) { - } - } // end finally - - // Return value according to relevant encoding. - try { - return new String(baos.toByteArray(), PREFERRED_ENCODING); - } // end try - catch (java.io.UnsupportedEncodingException uue) { - return new String(baos.toByteArray()); - } // end catch - } // end if: compress - - // Else, don't compress. Better not to use streams at all then. - else { - // Convert option to boolean in way that code likes it. - boolean breakLines = dontBreakLines == 0; - - int len43 = len * 4 / 3; - byte[] outBuff = new byte[(len43) // Main 4:3 - + ((len % 3) > 0 ? 4 : 0) // Account for padding - + (breakLines ? (len43 / MAX_LINE_LENGTH) : 0)]; // New - // lines - int d = 0; - int e = 0; - int len2 = len - 2; - int lineLength = 0; - for (; d < len2; d += 3, e += 4) { - encode3to4(source, d + off, 3, outBuff, e); - - lineLength += 4; - if (breakLines && lineLength == MAX_LINE_LENGTH) { - outBuff[e + 4] = NEW_LINE; - e++; - lineLength = 0; - } // end if: end of line - } // en dfor: each piece of array - - if (d < len) { - encode3to4(source, d + off, len - d, outBuff, e); - e += 4; - } // end if: some padding needed - - // Return value according to relevant encoding. - try { - return new String(outBuff, 0, e, PREFERRED_ENCODING); - } // end try - catch (java.io.UnsupportedEncodingException uue) { - return new String(outBuff, 0, e); - } // end catch - - } // end else: don't compress - - } // end encodeBytes - - /* ******** D E C O D I N G M E T H O D S ******** */ - - /** - * Decodes four bytes from array source and writes the resulting - * bytes (up to three of them) to destination. The source and - * destination arrays can be manipulated anywhere along their length by - * specifying srcOffset and destOffset. This method - * does not check to make sure your arrays are large enough to accomodate - * srcOffset + 4 for the source array or - * destOffset + 3 for the destination array. This - * method returns the actual number of bytes that were converted from the - * Base64 encoding. - * - * - * @param source - * the array to convert - * @param srcOffset - * the index where conversion begins - * @param destination - * the array to hold the conversion - * @param destOffset - * the index where output will be put - * @return the number of decoded bytes converted - * @since 1.3 - */ - private static int decode4to3(byte[] source, int srcOffset, - byte[] destination, int destOffset) { - // Example: Dk== - if (source[srcOffset + 2] == EQUALS_SIGN) { - // Two ways to do the same thing. Don't know which way I like best. - // int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 - // ) - // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 ); - int outBuff = ((DECODABET[source[srcOffset]] & 0xFF) << 18) - | ((DECODABET[source[srcOffset + 1]] & 0xFF) << 12); - - destination[destOffset] = (byte) (outBuff >>> 16); - return 1; - } - - // Example: DkL= - else if (source[srcOffset + 3] == EQUALS_SIGN) { - // Two ways to do the same thing. Don't know which way I like best. - // int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 - // ) - // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) - // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ); - int outBuff = ((DECODABET[source[srcOffset]] & 0xFF) << 18) - | ((DECODABET[source[srcOffset + 1]] & 0xFF) << 12) - | ((DECODABET[source[srcOffset + 2]] & 0xFF) << 6); - - destination[destOffset] = (byte) (outBuff >>> 16); - destination[destOffset + 1] = (byte) (outBuff >>> 8); - return 2; - } - - // Example: DkLE - else { - try { - // Two ways to do the same thing. Don't know which way I like - // best. - // int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) - // >>> 6 ) - // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) - // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ) - // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 ); - int outBuff = ((DECODABET[source[srcOffset]] & 0xFF) << 18) - | ((DECODABET[source[srcOffset + 1]] & 0xFF) << 12) - | ((DECODABET[source[srcOffset + 2]] & 0xFF) << 6) - | ((DECODABET[source[srcOffset + 3]] & 0xFF)); - - destination[destOffset] = (byte) (outBuff >> 16); - destination[destOffset + 1] = (byte) (outBuff >> 8); - destination[destOffset + 2] = (byte) (outBuff); - - return 3; - } catch (Exception e) { - System.out.println("" + source[srcOffset] + ": " - + (DECODABET[source[srcOffset]])); - System.out.println("" + source[srcOffset + 1] + ": " - + (DECODABET[source[srcOffset + 1]])); - System.out.println("" + source[srcOffset + 2] + ": " - + (DECODABET[source[srcOffset + 2]])); - System.out.println("" + source[srcOffset + 3] + ": " - + (DECODABET[source[srcOffset + 3]])); - return -1; - } // e nd catch - } - } // end decodeToBytes - - /** - * Very low-level access to decoding ASCII characters in the form of a byte - * array. Does not support automatically gunzipping or any other "fancy" - * features. - * - * @param source - * The Base64 encoded data - * @param off - * The offset of where to begin decoding - * @param len - * The length of characters to decode - * @return decoded data - * @since 1.3 - */ - public static byte[] decode(byte[] source, int off, int len) { - int len34 = len * 3 / 4; - byte[] outBuff = new byte[len34]; // Upper limit on size of output - int outBuffPosn = 0; - - byte[] b4 = new byte[4]; - int b4Posn = 0; - int i = 0; - byte sbiCrop = 0; - byte sbiDecode = 0; - for (i = off; i < off + len; i++) { - sbiCrop = (byte) (source[i] & 0x7f); // Only the low seven bits - sbiDecode = DECODABET[sbiCrop]; - - if (sbiDecode >= WHITE_SPACE_ENC) // White space, Equals sign or - // better - { - if (sbiDecode >= EQUALS_SIGN_ENC) { - b4[b4Posn++] = sbiCrop; - if (b4Posn > 3) { - outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn); - b4Posn = 0; - - // If that was the equals sign, break out of 'for' loop - if (sbiCrop == EQUALS_SIGN) - break; - } // end if: quartet built - - } // end if: equals sign or better - - } // end if: white space, equals sign or better - else { - System.err.println("Bad Base64 input character at " + i + ": " - + source[i] + "(decimal)"); - return null; - } // end else: - } // each input character - - byte[] out = new byte[outBuffPosn]; - System.arraycopy(outBuff, 0, out, 0, outBuffPosn); - return out; - } // end decode - - /** - * Decodes data from Base64 notation, automatically detecting - * gzip-compressed data and decompressing it. - * - * @param s - * the string to decode - * @return the decoded data - * @since 1.4 - */ - public static byte[] decode(String s) { - byte[] bytes; - try { - bytes = s.getBytes(PREFERRED_ENCODING); - } // end try - catch (java.io.UnsupportedEncodingException uee) { - bytes = s.getBytes(); - } // end catch - // - - // Decode - bytes = decode(bytes, 0, bytes.length); - - // Check to see if it's gzip-compressed - // GZIP Magic Two-Byte Number: 0x8b1f (35615) - if (bytes != null && bytes.length >= 4) { - - int head = ((int) bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); - if (java.util.zip.GZIPInputStream.GZIP_MAGIC == head) { - java.io.ByteArrayInputStream bais = null; - java.util.zip.GZIPInputStream gzis = null; - java.io.ByteArrayOutputStream baos = null; - byte[] buffer = new byte[2048]; - int length = 0; - - try { - baos = new java.io.ByteArrayOutputStream(); - bais = new java.io.ByteArrayInputStream(bytes); - gzis = new java.util.zip.GZIPInputStream(bais); - - while ((length = gzis.read(buffer)) >= 0) { - baos.write(buffer, 0, length); - } // end while: reading input - - // No error? Get new bytes. - bytes = baos.toByteArray(); - - } // end try - catch (java.io.IOException e) { - // Just return originally-decoded bytes - } // end catch - finally { - try { - baos.close(); - } catch (Exception e) { - } - try { - gzis.close(); - } catch (Exception e) { - } - try { - bais.close(); - } catch (Exception e) { - } - } // end finally - - } // end if: gzipped - } // end if: bytes.length >= 2 - - return bytes; - } // end decode - - /** - * Attempts to decode Base64 data and deserialize a Java Object within. - * Returns null if there was an error. - * - * @param encodedObject - * The Base64 data to decode - * @return The decoded and deserialized object - * @since 1.5 - */ - public static Object decodeToObject(String encodedObject) { - // Decode and gunzip if necessary - byte[] objBytes = decode(encodedObject); - - java.io.ByteArrayInputStream bais = null; - java.io.ObjectInputStream ois = null; - Object obj = null; - - try { - bais = new java.io.ByteArrayInputStream(objBytes); - ois = new java.io.ObjectInputStream(bais); - - obj = ois.readObject(); - } // end try - catch (java.io.IOException e) { - e.printStackTrace(); - obj = null; - } // end catch - catch (java.lang.ClassNotFoundException e) { - e.printStackTrace(); - obj = null; - } // end catch - finally { - try { - bais.close(); - } catch (Exception e) { - } - try { - ois.close(); - } catch (Exception e) { - } - } // end finally - - return obj; - } // end decodeObject - - /** - * Convenience method for encoding data to a file. - * - * @param dataToEncode - * byte array of data to encode in base64 form - * @param filename - * Filename for saving encoded data - * @return true if successful, false otherwise - * - * @since 2.1 - */ - public static boolean encodeToFile(byte[] dataToEncode, String filename) { - boolean success = false; - Base64.OutputStream bos = null; - try { - bos = new Base64.OutputStream( - new java.io.FileOutputStream(filename), Base64.ENCODE); - bos.write(dataToEncode); - success = true; - } // end try - catch (java.io.IOException e) { - - success = false; - } // end catch: IOException - finally { - try { - bos.close(); - } catch (Exception e) { - } - } // end finally - - return success; - } // end encodeToFile - - /** - * Convenience method for decoding data to a file. - * - * @param dataToDecode - * Base64-encoded data as a string - * @param filename - * Filename for saving decoded data - * @return true if successful, false otherwise - * - * @since 2.1 - */ - public static boolean decodeToFile(String dataToDecode, String filename) { - boolean success = false; - Base64.OutputStream bos = null; - try { - bos = new Base64.OutputStream( - new java.io.FileOutputStream(filename), Base64.DECODE); - bos.write(dataToDecode.getBytes(PREFERRED_ENCODING)); - success = true; - } // end try - catch (java.io.IOException e) { - success = false; - } // end catch: IOException - finally { - try { - bos.close(); - } catch (Exception e) { - } - } // end finally - - return success; - } // end decodeToFile - - /** - * Convenience method for reading a base64-encoded file and decoding it. - * - * @param filename - * Filename for reading encoded data - * @return decoded byte array or null if unsuccessful - * - * @since 2.1 - */ - public static byte[] decodeFromFile(String filename) { - byte[] decodedData = null; - Base64.InputStream bis = null; - try { - // Set up some useful variables - java.io.File file = new java.io.File(filename); - byte[] buffer = null; - int length = 0; - int numBytes = 0; - - // Check for size of file - if (file.length() > Integer.MAX_VALUE) { - System.err - .println("File is too big for this convenience method (" - + file.length() + " bytes)."); - return null; - } // end if: file too big for int index - buffer = new byte[(int) file.length()]; - - // Open a stream - bis = new Base64.InputStream(new java.io.BufferedInputStream( - new java.io.FileInputStream(file)), Base64.DECODE); - - // Read until done - while ((numBytes = bis.read(buffer, length, 4096)) >= 0) - length += numBytes; - - // Save in a variable to return - decodedData = new byte[length]; - System.arraycopy(buffer, 0, decodedData, 0, length); - - } // end try - catch (java.io.IOException e) { - System.err.println("Error decoding from file " + filename); - } // end catch: IOException - finally { - try { - bis.close(); - } catch (Exception e) { - } - } // end finally - - return decodedData; - } // end decodeFromFile - - /** - * Convenience method for reading a binary file and base64-encoding it. - * - * @param filename - * Filename for reading binary data - * @return base64-encoded string or null if unsuccessful - * - * @since 2.1 - */ - public static String encodeFromFile(String filename) { - String encodedData = null; - Base64.InputStream bis = null; - try { - // Set up some useful variables - java.io.File file = new java.io.File(filename); - byte[] buffer = new byte[(int) (file.length() * 1.4)]; - int length = 0; - int numBytes = 0; - - // Open a stream - bis = new Base64.InputStream(new java.io.BufferedInputStream( - new java.io.FileInputStream(file)), Base64.ENCODE); - - // Read until done - while ((numBytes = bis.read(buffer, length, 4096)) >= 0) - length += numBytes; - - // Save in a variable to return - encodedData = new String(buffer, 0, length, - Base64.PREFERRED_ENCODING); - - } // end try - catch (java.io.IOException e) { - System.err.println("Error encoding from file " + filename); - } // end catch: IOException - finally { - try { - bis.close(); - } catch (Exception e) { - } - } // end finally - - return encodedData; - } // end encodeFromFile - - /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */ - - /** - * A {@link Base64.InputStream} will read data from another - * java.io.InputStream, given in the constructor, and - * encode/decode to/from Base64 notation on the fly. - * - * @see Base64 - * @since 1.3 - */ - public static class InputStream extends java.io.FilterInputStream { - private boolean encode; // Encoding or decoding - - private int position; // Current position in the buffer - - private byte[] buffer; // Small buffer holding converted data - - private int bufferLength; // Length of buffer (3 or 4) - - private int numSigBytes; // Number of meaningful bytes in the buffer - - private int lineLength; - - private boolean breakLines; // Break lines at less than 80 characters - - /** - * Constructs a {@link Base64.InputStream} in DECODE mode. - * - * @param in - * the java.io.InputStream from which to read - * data. - * @since 1.3 - */ - public InputStream(java.io.InputStream in) { - this(in, DECODE); - } // end constructor - - /** - * Constructs a {@link Base64.InputStream} in either ENCODE or DECODE - * mode. - *

- * Valid options: - * - *

-		 *    ENCODE or DECODE: Encode or Decode as data is read.
-		 *    DONT_BREAK_LINES: don't break lines at 76 characters
-		 *      (only meaningful when encoding)
-		 *      <i>Note: Technically, this makes your encoding non-compliant.</i>
-		 * 
- * - *

- * Example: new Base64.InputStream( in, Base64.DECODE ) - * - * - * @param in - * the java.io.InputStream from which to read - * data. - * @param options - * Specified options - * @see Base64#ENCODE - * @see Base64#DECODE - * @see Base64#DONT_BREAK_LINES - * @since 2.0 - */ - public InputStream(java.io.InputStream in, int options) { - super(in); - this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; - this.encode = (options & ENCODE) == ENCODE; - this.bufferLength = encode ? 4 : 3; - this.buffer = new byte[bufferLength]; - this.position = -1; - this.lineLength = 0; - } // end constructor - - /** - * Reads enough of the input stream to convert to/from Base64 and - * returns the next byte. - * - * @return next byte - * @since 1.3 - */ - public int read() throws java.io.IOException { - // Do we need to get data? - if (position < 0) { - if (encode) { - byte[] b3 = new byte[3]; - int numBinaryBytes = 0; - for (int i = 0; i < 3; i++) { - try { - int b = in.read(); - - // If end of stream, b is -1. - if (b >= 0) { - b3[i] = (byte) b; - numBinaryBytes++; - } // end if: not end of stream - - } // end try: read - catch (java.io.IOException e) { - // Only a problem if we got no data at all. - if (i == 0) - throw e; - - } // end catch - } // end for: each needed input byte - - if (numBinaryBytes > 0) { - encode3to4(b3, 0, numBinaryBytes, buffer, 0); - position = 0; - numSigBytes = 4; - } // end if: got data - else { - return -1; - } // end else - } // end if: encoding - - // Else decoding - else { - byte[] b4 = new byte[4]; - int i = 0; - for (i = 0; i < 4; i++) { - // Read four "meaningful" bytes: - int b = 0; - do { - b = in.read(); - } while (b >= 0 - && DECODABET[b & 0x7f] <= WHITE_SPACE_ENC); - - if (b < 0) - break; // Reads a -1 if end of stream - - b4[i] = (byte) b; - } // end for: each needed input byte - - if (i == 4) { - numSigBytes = decode4to3(b4, 0, buffer, 0); - position = 0; - } // end if: got four characters - else if (i == 0) { - return -1; - } // end else if: also padded correctly - else { - // Must have broken out from above. - throw new java.io.IOException( - "Improperly padded Base64 input."); - } // end - - } // end else: decode - } // end else: get data - - // Got data? - if (position >= 0) { - // End of relevant data? - if ( /* !encode && */position >= numSigBytes) - return -1; - - if (encode && breakLines && lineLength >= MAX_LINE_LENGTH) { - lineLength = 0; - return '\n'; - } // end if - else { - lineLength++; // This isn't important when decoding - // but throwing an extra "if" seems - // just as wasteful. - - int b = buffer[position++]; - - if (position >= bufferLength) - position = -1; - - return b & 0xFF; // This is how you "cast" a byte that's - // intended to be unsigned. - } // end else - } // end if: position >= 0 - - // Else error - else { - // When JDK1.4 is more accepted, use an assertion here. - throw new java.io.IOException( - "Error in Base64 code reading stream."); - } // end else - } // end read - - /** - * Calls {@link #read()} repeatedly until the end of stream is reached - * or len bytes are read. Returns number of bytes read into - * array or -1 if end of stream is encountered. - * - * @param dest - * array to hold values - * @param off - * offset for array - * @param len - * max number of bytes to read into array - * @return bytes read into array or -1 if end of stream is encountered. - * @since 1.3 - */ - public int read(byte[] dest, int off, int len) - throws java.io.IOException { - int i; - int b; - for (i = 0; i < len; i++) { - b = read(); - - // if( b < 0 && i == 0 ) - // return -1; - - if (b >= 0) - dest[off + i] = (byte) b; - else if (i == 0) - return -1; - else - break; // Out of 'for' loop - } // end for: each byte read - return i; - } // end read - - } // end inner class InputStream - - /* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */ - - /** - * A {@link Base64.OutputStream} will write data to another - * java.io.OutputStream, given in the constructor, and - * encode/decode to/from Base64 notation on the fly. - * - * @see Base64 - * @since 1.3 - */ - public static class OutputStream extends java.io.FilterOutputStream { - private boolean encode; - - private int position; - - private byte[] buffer; - - private int bufferLength; - - private int lineLength; - - private boolean breakLines; - - private byte[] b4; // Scratch used in a few places - - private boolean suspendEncoding; - - /** - * Constructs a {@link Base64.OutputStream} in ENCODE mode. - * - * @param out - * the java.io.OutputStream to which data will be - * written. - * @since 1.3 - */ - public OutputStream(java.io.OutputStream out) { - this(out, ENCODE); - } // end constructor - - /** - * Constructs a {@link Base64.OutputStream} in either ENCODE or DECODE - * mode. - *

- * Valid options: - * - *

-		 *    ENCODE or DECODE: Encode or Decode as data is read.
-		 *    DONT_BREAK_LINES: don't break lines at 76 characters
-		 *      (only meaningful when encoding)
-		 *      <i>Note: Technically, this makes your encoding non-compliant.</i>
-		 * 
- * - *

- * Example: new Base64.OutputStream( out, Base64.ENCODE ) - * - * @param out - * the java.io.OutputStream to which data will be - * written. - * @param options - * Specified options. - * @see Base64#ENCODE - * @see Base64#DECODE - * @see Base64#DONT_BREAK_LINES - * @since 1.3 - */ - public OutputStream(java.io.OutputStream out, int options) { - super(out); - this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; - this.encode = (options & ENCODE) == ENCODE; - this.bufferLength = encode ? 3 : 4; - this.buffer = new byte[bufferLength]; - this.position = 0; - this.lineLength = 0; - this.suspendEncoding = false; - this.b4 = new byte[4]; - } // end constructor - - /** - * Writes the byte to the output stream after converting to/from Base64 - * notation. When encoding, bytes are buffered three at a time before - * the output stream actually gets a write() call. When decoding, bytes - * are buffered four at a time. - * - * @param theByte - * the byte to write - * @since 1.3 - */ - public void write(int theByte) throws java.io.IOException { - // Encoding suspended? - if (suspendEncoding) { - super.out.write(theByte); - return; - } // end if: supsended - - // Encode? - if (encode) { - buffer[position++] = (byte) theByte; - if (position >= bufferLength) // Enough to encode. - { - out.write(encode3to4(b4, buffer, bufferLength)); - - lineLength += 4; - if (breakLines && lineLength >= MAX_LINE_LENGTH) { - out.write(NEW_LINE); - lineLength = 0; - } // end if: end of line - - position = 0; - } // end if: enough to output - } // end if: encoding - - // Else, Decoding - else { - // Meaningful Base64 character? - if (DECODABET[theByte & 0x7f] > WHITE_SPACE_ENC) { - buffer[position++] = (byte) theByte; - if (position >= bufferLength) // Enough to output. - { - int len = Base64.decode4to3(buffer, 0, b4, 0); - out.write(b4, 0, len); - // out.write( Base64.decode4to3( buffer ) ); - position = 0; - } // end if: enough to output - } // end if: meaningful base64 character - else if (DECODABET[theByte & 0x7f] != WHITE_SPACE_ENC) { - throw new java.io.IOException( - "Invalid character in Base64 data."); - } // end else: not white space either - } // end else: decoding - } // end write - - /** - * Calls {@link #write(int)} repeatedly until len bytes are - * written. - * - * @param theBytes - * array from which to read bytes - * @param off - * offset for array - * @param len - * max number of bytes to read into array - * @since 1.3 - */ - public void write(byte[] theBytes, int off, int len) - throws java.io.IOException { - // Encoding suspended? - if (suspendEncoding) { - super.out.write(theBytes, off, len); - return; - } // end if: supsended - - for (int i = 0; i < len; i++) { - write(theBytes[off + i]); - } // end for: each byte written - - } // end write - - /** - * Method added by PHIL. [Thanks, PHIL. -Rob] This pads the buffer - * without closing the stream. - */ - public void flushBase64() throws java.io.IOException { - if (position > 0) { - if (encode) { - out.write(encode3to4(b4, buffer, position)); - position = 0; - } // end if: encoding - else { - throw new java.io.IOException( - "Base64 input not properly padded."); - } // end else: decoding - } // end if: buffer partially full - - } // end flush - - /** - * Flushes and closes (I think, in the superclass) the stream. - * - * @since 1.3 - */ - public void close() throws java.io.IOException { - // 1. Ensure that pending characters are written - flushBase64(); - - // 2. Actually close the stream - // Base class both flushes and closes. - super.close(); - - buffer = null; - out = null; - } // end close - - /** - * Suspends encoding of the stream. May be helpful if you need to embed - * a piece of base640-encoded data in a stream. - * - * @since 1.5.1 - */ - public void suspendEncoding() throws java.io.IOException { - flushBase64(); - this.suspendEncoding = true; - } // end suspendEncoding - - /** - * Resumes encoding of the stream. May be helpful if you need to embed a - * piece of base640-encoded data in a stream. - * - * @since 1.5.1 - */ - public void resumeEncoding() { - this.suspendEncoding = false; - } // end resumeEncoding - - } // end inner class OutputStream - -} // end class Base64 +public class Base64 +{ + +/* ******** P U B L I C F I E L D S ******** */ + + + /** No options specified. Value is zero. */ + public final static int NO_OPTIONS = 0; + + /** Specify encoding. */ + public final static int ENCODE = 1; + + + /** Specify decoding. */ + public final static int DECODE = 0; + + + /** Specify that data should be gzip-compressed. */ + public final static int GZIP = 2; + + + /** Don't break lines when encoding (violates strict Base64 specification) */ + public final static int DONT_BREAK_LINES = 8; + + +/* ******** P R I V A T E F I E L D S ******** */ + + + /** Maximum line length (76) of Base64 output. */ + private final static int MAX_LINE_LENGTH = 76; + + + /** The equals sign (=) as a byte. */ + private final static byte EQUALS_SIGN = (byte)'='; + + + /** The new line character (\n) as a byte. */ + private final static byte NEW_LINE = (byte)'\n'; + + + /** Preferred encoding. */ + private final static String PREFERRED_ENCODING = "UTF-8"; + + + /** The 64 valid Base64 values. */ + private final static byte[] ALPHABET; + private final static byte[] _NATIVE_ALPHABET = /* May be something funny like EBCDIC */ + { + (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', + (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', + (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', + (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', + (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', + (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', + (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', + (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z', + (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', + (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/' + }; + + /** Determine which ALPHABET to use. */ + static + { + byte[] __bytes; + try + { + __bytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes( PREFERRED_ENCODING ); + } // end try + catch (java.io.UnsupportedEncodingException use) + { + __bytes = _NATIVE_ALPHABET; // Fall back to native encoding + } // end catch + ALPHABET = __bytes; + } // end static + + + /** + * Translates a Base64 value to either its 6-bit reconstruction value + * or a negative number indicating some other meaning. + **/ + private final static byte[] DECODABET = + { + -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 + -5,-5, // Whitespace: Tab and Linefeed + -9,-9, // Decimal 11 - 12 + -5, // Whitespace: Carriage Return + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26 + -9,-9,-9,-9,-9, // Decimal 27 - 31 + -5, // Whitespace: Space + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42 + 62, // Plus sign at decimal 43 + -9,-9,-9, // Decimal 44 - 46 + 63, // Slash at decimal 47 + 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine + -9,-9,-9, // Decimal 58 - 60 + -1, // Equals sign at decimal 61 + -9,-9,-9, // Decimal 62 - 64 + 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N' + 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z' + -9,-9,-9,-9,-9,-9, // Decimal 91 - 96 + 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm' + 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z' + -9,-9,-9,-9 // Decimal 123 - 126 + /*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */ + }; + + // I think I end up not using the BAD_ENCODING indicator. + //private final static byte BAD_ENCODING = -9; // Indicates error in encoding + private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding + private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding + + + /** Defeats instantiation. */ + private Base64(){} + + + +/* ******** E N C O D I N G M E T H O D S ******** */ + + + /** + * Encodes up to the first three bytes of array threeBytes + * and returns a four-byte array in Base64 notation. + * The actual number of significant bytes in your array is + * given by numSigBytes. + * The array threeBytes needs only be as big as + * numSigBytes. + * Code can reuse a byte array by passing a four-byte array as b4. + * + * @param b4 A reusable byte array to reduce array instantiation + * @param threeBytes the array to convert + * @param numSigBytes the number of significant bytes in your array + * @return four byte array in Base64 notation. + * @since 1.5.1 + */ + private static byte[] encode3to4( byte[] b4, byte[] threeBytes, int numSigBytes ) + { + encode3to4( threeBytes, 0, numSigBytes, b4, 0 ); + return b4; + } // end encode3to4 + + + /** + * Encodes up to three bytes of the array source + * and writes the resulting four Base64 bytes to destination. + * The source and destination arrays can be manipulated + * anywhere along their length by specifying + * srcOffset and destOffset. + * This method does not check to make sure your arrays + * are large enough to accomodate srcOffset + 3 for + * the source array or destOffset + 4 for + * the destination array. + * The actual number of significant bytes in your array is + * given by numSigBytes. + * + * @param source the array to convert + * @param srcOffset the index where conversion begins + * @param numSigBytes the number of significant bytes in your array + * @param destination the array to hold the conversion + * @param destOffset the index where output will be put + * @return the destination array + * @since 1.3 + */ + private static byte[] encode3to4( + byte[] source, int srcOffset, int numSigBytes, + byte[] destination, int destOffset ) + { + // 1 2 3 + // 01234567890123456789012345678901 Bit position + // --------000000001111111122222222 Array position from threeBytes + // --------| || || || | Six bit groups to index ALPHABET + // >>18 >>12 >> 6 >> 0 Right shift necessary + // 0x3f 0x3f 0x3f Additional AND + + // Create buffer with zero-padding if there are only one or two + // significant bytes passed in the array. + // We have to shift left 24 in order to flush out the 1's that appear + // when Java treats a value as negative that is cast from a byte to an int. + int inBuff = ( numSigBytes > 0 ? ((source[ srcOffset ] << 24) >>> 8) : 0 ) + | ( numSigBytes > 1 ? ((source[ srcOffset + 1 ] << 24) >>> 16) : 0 ) + | ( numSigBytes > 2 ? ((source[ srcOffset + 2 ] << 24) >>> 24) : 0 ); + + switch( numSigBytes ) + { + case 3: + destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; + destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; + destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; + destination[ destOffset + 3 ] = ALPHABET[ (inBuff ) & 0x3f ]; + return destination; + + case 2: + destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; + destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; + destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; + destination[ destOffset + 3 ] = EQUALS_SIGN; + return destination; + + case 1: + destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; + destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; + destination[ destOffset + 2 ] = EQUALS_SIGN; + destination[ destOffset + 3 ] = EQUALS_SIGN; + return destination; + + default: + return destination; + } // end switch + } // end encode3to4 + + + + /** + * Serializes an object and returns the Base64-encoded + * version of that serialized object. If the object + * cannot be serialized or there is another error, + * the method will return null. + * The object is not GZip-compressed before being encoded. + * + * @param serializableObject The object to encode + * @return The Base64-encoded object + * @since 1.4 + */ + public static String encodeObject( java.io.Serializable serializableObject ) + { + return encodeObject( serializableObject, NO_OPTIONS ); + } // end encodeObject + + + + /** + * Serializes an object and returns the Base64-encoded + * version of that serialized object. If the object + * cannot be serialized or there is another error, + * the method will return null. + *

+ * Valid options:

+     *   GZIP: gzip-compresses object before encoding it.
+     *   DONT_BREAK_LINES: don't break lines at 76 characters
+     *     Note: Technically, this makes your encoding non-compliant.
+     * 
+ *

+ * Example: encodeObject( myObj, Base64.GZIP ) or + *

+ * Example: encodeObject( myObj, Base64.GZIP | Base64.DONT_BREAK_LINES ) + * + * @param serializableObject The object to encode + * @param options Specified options + * @return The Base64-encoded object + * @see Base64#GZIP + * @see Base64#DONT_BREAK_LINES + * @since 2.0 + */ + public static String encodeObject( java.io.Serializable serializableObject, int options ) + { + // Streams + java.io.ByteArrayOutputStream baos = null; + java.io.OutputStream b64os = null; + java.io.ObjectOutputStream oos = null; + java.util.zip.GZIPOutputStream gzos = null; + + // Isolate options + int gzip = (options & GZIP); + int dontBreakLines = (options & DONT_BREAK_LINES); + + try + { + // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream + baos = new java.io.ByteArrayOutputStream(); + b64os = new Base64.OutputStream( baos, ENCODE | dontBreakLines ); + + // GZip? + if( gzip == GZIP ) + { + gzos = new java.util.zip.GZIPOutputStream( b64os ); + oos = new java.io.ObjectOutputStream( gzos ); + } // end if: gzip + else + oos = new java.io.ObjectOutputStream( b64os ); + + oos.writeObject( serializableObject ); + } // end try + catch( java.io.IOException e ) + { + e.printStackTrace(); + return null; + } // end catch + finally + { + try{ oos.close(); } catch( Exception e ){} + try{ gzos.close(); } catch( Exception e ){} + try{ b64os.close(); } catch( Exception e ){} + try{ baos.close(); } catch( Exception e ){} + } // end finally + + // Return value according to relevant encoding. + try + { + return new String( baos.toByteArray(), PREFERRED_ENCODING ); + } // end try + catch (java.io.UnsupportedEncodingException uue) + { + return new String( baos.toByteArray() ); + } // end catch + + } // end encode + + + + /** + * Encodes a byte array into Base64 notation. + * Does not GZip-compress data. + * + * @param source The data to convert + * @since 1.4 + */ + public static String encodeBytes( byte[] source ) + { + return encodeBytes( source, 0, source.length, NO_OPTIONS ); + } // end encodeBytes + + + + /** + * Encodes a byte array into Base64 notation. + *

+ * Valid options:

+     *   GZIP: gzip-compresses object before encoding it.
+     *   DONT_BREAK_LINES: don't break lines at 76 characters
+     *     Note: Technically, this makes your encoding non-compliant.
+     * 
+ *

+ * Example: encodeBytes( myData, Base64.GZIP ) or + *

+ * Example: encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES ) + * + * + * @param source The data to convert + * @param options Specified options + * @see Base64#GZIP + * @see Base64#DONT_BREAK_LINES + * @since 2.0 + */ + public static String encodeBytes( byte[] source, int options ) + { + return encodeBytes( source, 0, source.length, options ); + } // end encodeBytes + + + /** + * Encodes a byte array into Base64 notation. + * Does not GZip-compress data. + * + * @param source The data to convert + * @param off Offset in array where conversion should begin + * @param len Length of data to convert + * @since 1.4 + */ + public static String encodeBytes( byte[] source, int off, int len ) + { + return encodeBytes( source, off, len, NO_OPTIONS ); + } // end encodeBytes + + + + /** + * Encodes a byte array into Base64 notation. + *

+ * Valid options:

+     *   GZIP: gzip-compresses object before encoding it.
+     *   DONT_BREAK_LINES: don't break lines at 76 characters
+     *     Note: Technically, this makes your encoding non-compliant.
+     * 
+ *

+ * Example: encodeBytes( myData, Base64.GZIP ) or + *

+ * Example: encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES ) + * + * + * @param source The data to convert + * @param off Offset in array where conversion should begin + * @param len Length of data to convert + * @param options Specified options + * @see Base64#GZIP + * @see Base64#DONT_BREAK_LINES + * @since 2.0 + */ + public static String encodeBytes( byte[] source, int off, int len, int options ) + { + // Isolate options + int dontBreakLines = ( options & DONT_BREAK_LINES ); + int gzip = ( options & GZIP ); + + // Compress? + if( gzip == GZIP ) + { + java.io.ByteArrayOutputStream baos = null; + java.util.zip.GZIPOutputStream gzos = null; + Base64.OutputStream b64os = null; + + + try + { + // GZip -> Base64 -> ByteArray + baos = new java.io.ByteArrayOutputStream(); + b64os = new Base64.OutputStream( baos, ENCODE | dontBreakLines ); + gzos = new java.util.zip.GZIPOutputStream( b64os ); + + gzos.write( source, off, len ); + gzos.close(); + } // end try + catch( java.io.IOException e ) + { + e.printStackTrace(); + return null; + } // end catch + finally + { + try{ gzos.close(); } catch( Exception e ){} + try{ b64os.close(); } catch( Exception e ){} + try{ baos.close(); } catch( Exception e ){} + } // end finally + + // Return value according to relevant encoding. + try + { + return new String( baos.toByteArray(), PREFERRED_ENCODING ); + } // end try + catch (java.io.UnsupportedEncodingException uue) + { + return new String( baos.toByteArray() ); + } // end catch + } // end if: compress + + // Else, don't compress. Better not to use streams at all then. + else + { + // Convert option to boolean in way that code likes it. + boolean breakLines = dontBreakLines == 0; + + int len43 = len * 4 / 3; + byte[] outBuff = new byte[ ( len43 ) // Main 4:3 + + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding + + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines + int d = 0; + int e = 0; + int len2 = len - 2; + int lineLength = 0; + for( ; d < len2; d+=3, e+=4 ) + { + encode3to4( source, d+off, 3, outBuff, e ); + + lineLength += 4; + if( breakLines && lineLength == MAX_LINE_LENGTH ) + { + outBuff[e+4] = NEW_LINE; + e++; + lineLength = 0; + } // end if: end of line + } // en dfor: each piece of array + + if( d < len ) + { + encode3to4( source, d+off, len - d, outBuff, e ); + e += 4; + } // end if: some padding needed + + + // Return value according to relevant encoding. + try + { + return new String( outBuff, 0, e, PREFERRED_ENCODING ); + } // end try + catch (java.io.UnsupportedEncodingException uue) + { + return new String( outBuff, 0, e ); + } // end catch + + } // end else: don't compress + + } // end encodeBytes + + + + + +/* ******** D E C O D I N G M E T H O D S ******** */ + + + /** + * Decodes four bytes from array source + * and writes the resulting bytes (up to three of them) + * to destination. + * The source and destination arrays can be manipulated + * anywhere along their length by specifying + * srcOffset and destOffset. + * This method does not check to make sure your arrays + * are large enough to accomodate srcOffset + 4 for + * the source array or destOffset + 3 for + * the destination array. + * This method returns the actual number of bytes that + * were converted from the Base64 encoding. + * + * + * @param source the array to convert + * @param srcOffset the index where conversion begins + * @param destination the array to hold the conversion + * @param destOffset the index where output will be put + * @return the number of decoded bytes converted + * @since 1.3 + */ + private static int decode4to3( byte[] source, int srcOffset, byte[] destination, int destOffset ) + { + // Example: Dk== + if( source[ srcOffset + 2] == EQUALS_SIGN ) + { + // Two ways to do the same thing. Don't know which way I like best. + //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) + // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 ); + int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) + | ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 ); + + destination[ destOffset ] = (byte)( outBuff >>> 16 ); + return 1; + } + + // Example: DkL= + else if( source[ srcOffset + 3 ] == EQUALS_SIGN ) + { + // Two ways to do the same thing. Don't know which way I like best. + //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) + // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) + // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ); + int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) + | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) + | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 ); + + destination[ destOffset ] = (byte)( outBuff >>> 16 ); + destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 ); + return 2; + } + + // Example: DkLE + else + { + try{ + // Two ways to do the same thing. Don't know which way I like best. + //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) + // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) + // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ) + // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 ); + int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) + | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) + | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6) + | ( ( DECODABET[ source[ srcOffset + 3 ] ] & 0xFF ) ); + + + destination[ destOffset ] = (byte)( outBuff >> 16 ); + destination[ destOffset + 1 ] = (byte)( outBuff >> 8 ); + destination[ destOffset + 2 ] = (byte)( outBuff ); + + return 3; + }catch( Exception e){ + System.out.println(""+source[srcOffset]+ ": " + ( DECODABET[ source[ srcOffset ] ] ) ); + System.out.println(""+source[srcOffset+1]+ ": " + ( DECODABET[ source[ srcOffset + 1 ] ] ) ); + System.out.println(""+source[srcOffset+2]+ ": " + ( DECODABET[ source[ srcOffset + 2 ] ] ) ); + System.out.println(""+source[srcOffset+3]+ ": " + ( DECODABET[ source[ srcOffset + 3 ] ] ) ); + return -1; + } //e nd catch + } + } // end decodeToBytes + + + + + /** + * Very low-level access to decoding ASCII characters in + * the form of a byte array. Does not support automatically + * gunzipping or any other "fancy" features. + * + * @param source The Base64 encoded data + * @param off The offset of where to begin decoding + * @param len The length of characters to decode + * @return decoded data + * @since 1.3 + */ + public static byte[] decode( byte[] source, int off, int len ) + { + int len34 = len * 3 / 4; + byte[] outBuff = new byte[ len34 ]; // Upper limit on size of output + int outBuffPosn = 0; + + byte[] b4 = new byte[4]; + int b4Posn = 0; + int i = 0; + byte sbiCrop = 0; + byte sbiDecode = 0; + for( i = off; i < off+len; i++ ) + { + sbiCrop = (byte)(source[i] & 0x7f); // Only the low seven bits + sbiDecode = DECODABET[ sbiCrop ]; + + if( sbiDecode >= WHITE_SPACE_ENC ) // White space, Equals sign or better + { + if( sbiDecode >= EQUALS_SIGN_ENC ) + { + b4[ b4Posn++ ] = sbiCrop; + if( b4Posn > 3 ) + { + outBuffPosn += decode4to3( b4, 0, outBuff, outBuffPosn ); + b4Posn = 0; + + // If that was the equals sign, break out of 'for' loop + if( sbiCrop == EQUALS_SIGN ) + break; + } // end if: quartet built + + } // end if: equals sign or better + + } // end if: white space, equals sign or better + else + { + System.err.println( "Bad Base64 input character at " + i + ": " + source[i] + "(decimal)" ); + return null; + } // end else: + } // each input character + + byte[] out = new byte[ outBuffPosn ]; + System.arraycopy( outBuff, 0, out, 0, outBuffPosn ); + return out; + } // end decode + + + + + /** + * Decodes data from Base64 notation, automatically + * detecting gzip-compressed data and decompressing it. + * + * @param s the string to decode + * @return the decoded data + * @since 1.4 + */ + public static byte[] decode( String s ) + { + byte[] bytes; + try + { + bytes = s.getBytes( PREFERRED_ENCODING ); + } // end try + catch( java.io.UnsupportedEncodingException uee ) + { + bytes = s.getBytes(); + } // end catch + // + + // Decode + bytes = decode( bytes, 0, bytes.length ); + + + // Check to see if it's gzip-compressed + // GZIP Magic Two-Byte Number: 0x8b1f (35615) + if( bytes != null && bytes.length >= 4 ) + { + + int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); + if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) + { + java.io.ByteArrayInputStream bais = null; + java.util.zip.GZIPInputStream gzis = null; + java.io.ByteArrayOutputStream baos = null; + byte[] buffer = new byte[2048]; + int length = 0; + + try + { + baos = new java.io.ByteArrayOutputStream(); + bais = new java.io.ByteArrayInputStream( bytes ); + gzis = new java.util.zip.GZIPInputStream( bais ); + + while( ( length = gzis.read( buffer ) ) >= 0 ) + { + baos.write(buffer,0,length); + } // end while: reading input + + // No error? Get new bytes. + bytes = baos.toByteArray(); + + } // end try + catch( java.io.IOException e ) + { + // Just return originally-decoded bytes + } // end catch + finally + { + try{ baos.close(); } catch( Exception e ){} + try{ gzis.close(); } catch( Exception e ){} + try{ bais.close(); } catch( Exception e ){} + } // end finally + + } // end if: gzipped + } // end if: bytes.length >= 2 + + return bytes; + } // end decode + + + + + /** + * Attempts to decode Base64 data and deserialize a Java + * Object within. Returns null if there was an error. + * + * @param encodedObject The Base64 data to decode + * @return The decoded and deserialized object + * @since 1.5 + */ + public static Object decodeToObject( String encodedObject ) + { + // Decode and gunzip if necessary + byte[] objBytes = decode( encodedObject ); + + java.io.ByteArrayInputStream bais = null; + java.io.ObjectInputStream ois = null; + Object obj = null; + + try + { + bais = new java.io.ByteArrayInputStream( objBytes ); + ois = new java.io.ObjectInputStream( bais ); + + obj = ois.readObject(); + } // end try + catch( java.io.IOException e ) + { + e.printStackTrace(); + obj = null; + } // end catch + catch( java.lang.ClassNotFoundException e ) + { + e.printStackTrace(); + obj = null; + } // end catch + finally + { + try{ bais.close(); } catch( Exception e ){} + try{ ois.close(); } catch( Exception e ){} + } // end finally + + return obj; + } // end decodeObject + + + + /** + * Convenience method for encoding data to a file. + * + * @param dataToEncode byte array of data to encode in base64 form + * @param filename Filename for saving encoded data + * @return true if successful, false otherwise + * + * @since 2.1 + */ + public static boolean encodeToFile( byte[] dataToEncode, String filename ) + { + boolean success = false; + Base64.OutputStream bos = null; + try + { + bos = new Base64.OutputStream( + new java.io.FileOutputStream( filename ), Base64.ENCODE ); + bos.write( dataToEncode ); + success = true; + } // end try + catch( java.io.IOException e ) + { + + success = false; + } // end catch: IOException + finally + { + try{ bos.close(); } catch( Exception e ){} + } // end finally + + return success; + } // end encodeToFile + + + /** + * Convenience method for decoding data to a file. + * + * @param dataToDecode Base64-encoded data as a string + * @param filename Filename for saving decoded data + * @return true if successful, false otherwise + * + * @since 2.1 + */ + public static boolean decodeToFile( String dataToDecode, String filename ) + { + boolean success = false; + Base64.OutputStream bos = null; + try + { + bos = new Base64.OutputStream( + new java.io.FileOutputStream( filename ), Base64.DECODE ); + bos.write( dataToDecode.getBytes( PREFERRED_ENCODING ) ); + success = true; + } // end try + catch( java.io.IOException e ) + { + success = false; + } // end catch: IOException + finally + { + try{ bos.close(); } catch( Exception e ){} + } // end finally + + return success; + } // end decodeToFile + + + + + /** + * Convenience method for reading a base64-encoded + * file and decoding it. + * + * @param filename Filename for reading encoded data + * @return decoded byte array or null if unsuccessful + * + * @since 2.1 + */ + public static byte[] decodeFromFile( String filename ) + { + byte[] decodedData = null; + Base64.InputStream bis = null; + try + { + // Set up some useful variables + java.io.File file = new java.io.File( filename ); + byte[] buffer = null; + int length = 0; + int numBytes = 0; + + // Check for size of file + if( file.length() > Integer.MAX_VALUE ) + { + System.err.println( "File is too big for this convenience method (" + file.length() + " bytes)." ); + return null; + } // end if: file too big for int index + buffer = new byte[ (int)file.length() ]; + + // Open a stream + bis = new Base64.InputStream( + new java.io.BufferedInputStream( + new java.io.FileInputStream( file ) ), Base64.DECODE ); + + // Read until done + while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) + length += numBytes; + + // Save in a variable to return + decodedData = new byte[ length ]; + System.arraycopy( buffer, 0, decodedData, 0, length ); + + } // end try + catch( java.io.IOException e ) + { + System.err.println( "Error decoding from file " + filename ); + } // end catch: IOException + finally + { + try{ bis.close(); } catch( Exception e) {} + } // end finally + + return decodedData; + } // end decodeFromFile + + + + /** + * Convenience method for reading a binary file + * and base64-encoding it. + * + * @param filename Filename for reading binary data + * @return base64-encoded string or null if unsuccessful + * + * @since 2.1 + */ + public static String encodeFromFile( String filename ) + { + String encodedData = null; + Base64.InputStream bis = null; + try + { + // Set up some useful variables + java.io.File file = new java.io.File( filename ); + byte[] buffer = new byte[ (int)(file.length() * 1.4) ]; + int length = 0; + int numBytes = 0; + + // Open a stream + bis = new Base64.InputStream( + new java.io.BufferedInputStream( + new java.io.FileInputStream( file ) ), Base64.ENCODE ); + + // Read until done + while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) + length += numBytes; + + // Save in a variable to return + encodedData = new String( buffer, 0, length, Base64.PREFERRED_ENCODING ); + + } // end try + catch( java.io.IOException e ) + { + System.err.println( "Error encoding from file " + filename ); + } // end catch: IOException + finally + { + try{ bis.close(); } catch( Exception e) {} + } // end finally + + return encodedData; + } // end encodeFromFile + + + + + /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */ + + + + /** + * A {@link Base64.InputStream} will read data from another + * java.io.InputStream, given in the constructor, + * and encode/decode to/from Base64 notation on the fly. + * + * @see Base64 + * @since 1.3 + */ + public static class InputStream extends java.io.FilterInputStream + { + private boolean encode; // Encoding or decoding + private int position; // Current position in the buffer + private byte[] buffer; // Small buffer holding converted data + private int bufferLength; // Length of buffer (3 or 4) + private int numSigBytes; // Number of meaningful bytes in the buffer + private int lineLength; + private boolean breakLines; // Break lines at less than 80 characters + + + /** + * Constructs a {@link Base64.InputStream} in DECODE mode. + * + * @param in the java.io.InputStream from which to read data. + * @since 1.3 + */ + public InputStream( java.io.InputStream in ) + { + this( in, DECODE ); + } // end constructor + + + /** + * Constructs a {@link Base64.InputStream} in + * either ENCODE or DECODE mode. + *

+ * Valid options:

+         *   ENCODE or DECODE: Encode or Decode as data is read.
+         *   DONT_BREAK_LINES: don't break lines at 76 characters
+         *     (only meaningful when encoding)
+         *     Note: Technically, this makes your encoding non-compliant.
+         * 
+ *

+ * Example: new Base64.InputStream( in, Base64.DECODE ) + * + * + * @param in the java.io.InputStream from which to read data. + * @param options Specified options + * @see Base64#ENCODE + * @see Base64#DECODE + * @see Base64#DONT_BREAK_LINES + * @since 2.0 + */ + public InputStream( java.io.InputStream in, int options ) + { + super( in ); + this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; + this.encode = (options & ENCODE) == ENCODE; + this.bufferLength = encode ? 4 : 3; + this.buffer = new byte[ bufferLength ]; + this.position = -1; + this.lineLength = 0; + } // end constructor + + /** + * Reads enough of the input stream to convert + * to/from Base64 and returns the next byte. + * + * @return next byte + * @since 1.3 + */ + public int read() throws java.io.IOException + { + // Do we need to get data? + if( position < 0 ) + { + if( encode ) + { + byte[] b3 = new byte[3]; + int numBinaryBytes = 0; + for( int i = 0; i < 3; i++ ) + { + try + { + int b = in.read(); + + // If end of stream, b is -1. + if( b >= 0 ) + { + b3[i] = (byte)b; + numBinaryBytes++; + } // end if: not end of stream + + } // end try: read + catch( java.io.IOException e ) + { + // Only a problem if we got no data at all. + if( i == 0 ) + throw e; + + } // end catch + } // end for: each needed input byte + + if( numBinaryBytes > 0 ) + { + encode3to4( b3, 0, numBinaryBytes, buffer, 0 ); + position = 0; + numSigBytes = 4; + } // end if: got data + else + { + return -1; + } // end else + } // end if: encoding + + // Else decoding + else + { + byte[] b4 = new byte[4]; + int i = 0; + for( i = 0; i < 4; i++ ) + { + // Read four "meaningful" bytes: + int b = 0; + do{ b = in.read(); } + while( b >= 0 && DECODABET[ b & 0x7f ] <= WHITE_SPACE_ENC ); + + if( b < 0 ) + break; // Reads a -1 if end of stream + + b4[i] = (byte)b; + } // end for: each needed input byte + + if( i == 4 ) + { + numSigBytes = decode4to3( b4, 0, buffer, 0 ); + position = 0; + } // end if: got four characters + else if( i == 0 ){ + return -1; + } // end else if: also padded correctly + else + { + // Must have broken out from above. + throw new java.io.IOException( "Improperly padded Base64 input." ); + } // end + + } // end else: decode + } // end else: get data + + // Got data? + if( position >= 0 ) + { + // End of relevant data? + if( /*!encode &&*/ position >= numSigBytes ) + return -1; + + if( encode && breakLines && lineLength >= MAX_LINE_LENGTH ) + { + lineLength = 0; + return '\n'; + } // end if + else + { + lineLength++; // This isn't important when decoding + // but throwing an extra "if" seems + // just as wasteful. + + int b = buffer[ position++ ]; + + if( position >= bufferLength ) + position = -1; + + return b & 0xFF; // This is how you "cast" a byte that's + // intended to be unsigned. + } // end else + } // end if: position >= 0 + + // Else error + else + { + // When JDK1.4 is more accepted, use an assertion here. + throw new java.io.IOException( "Error in Base64 code reading stream." ); + } // end else + } // end read + + + /** + * Calls {@link #read()} repeatedly until the end of stream + * is reached or len bytes are read. + * Returns number of bytes read into array or -1 if + * end of stream is encountered. + * + * @param dest array to hold values + * @param off offset for array + * @param len max number of bytes to read into array + * @return bytes read into array or -1 if end of stream is encountered. + * @since 1.3 + */ + public int read( byte[] dest, int off, int len ) throws java.io.IOException + { + int i; + int b; + for( i = 0; i < len; i++ ) + { + b = read(); + + //if( b < 0 && i == 0 ) + // return -1; + + if( b >= 0 ) + dest[off + i] = (byte)b; + else if( i == 0 ) + return -1; + else + break; // Out of 'for' loop + } // end for: each byte read + return i; + } // end read + + } // end inner class InputStream + + + + + + + /* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */ + + + + /** + * A {@link Base64.OutputStream} will write data to another + * java.io.OutputStream, given in the constructor, + * and encode/decode to/from Base64 notation on the fly. + * + * @see Base64 + * @since 1.3 + */ + public static class OutputStream extends java.io.FilterOutputStream + { + private boolean encode; + private int position; + private byte[] buffer; + private int bufferLength; + private int lineLength; + private boolean breakLines; + private byte[] b4; // Scratch used in a few places + private boolean suspendEncoding; + + /** + * Constructs a {@link Base64.OutputStream} in ENCODE mode. + * + * @param out the java.io.OutputStream to which data will be written. + * @since 1.3 + */ + public OutputStream( java.io.OutputStream out ) + { + this( out, ENCODE ); + } // end constructor + + + /** + * Constructs a {@link Base64.OutputStream} in + * either ENCODE or DECODE mode. + *

+ * Valid options:

+         *   ENCODE or DECODE: Encode or Decode as data is read.
+         *   DONT_BREAK_LINES: don't break lines at 76 characters
+         *     (only meaningful when encoding)
+         *     Note: Technically, this makes your encoding non-compliant.
+         * 
+ *

+ * Example: new Base64.OutputStream( out, Base64.ENCODE ) + * + * @param out the java.io.OutputStream to which data will be written. + * @param options Specified options. + * @see Base64#ENCODE + * @see Base64#DECODE + * @see Base64#DONT_BREAK_LINES + * @since 1.3 + */ + public OutputStream( java.io.OutputStream out, int options ) + { + super( out ); + this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; + this.encode = (options & ENCODE) == ENCODE; + this.bufferLength = encode ? 3 : 4; + this.buffer = new byte[ bufferLength ]; + this.position = 0; + this.lineLength = 0; + this.suspendEncoding = false; + this.b4 = new byte[4]; + } // end constructor + + + /** + * Writes the byte to the output stream after + * converting to/from Base64 notation. + * When encoding, bytes are buffered three + * at a time before the output stream actually + * gets a write() call. + * When decoding, bytes are buffered four + * at a time. + * + * @param theByte the byte to write + * @since 1.3 + */ + public void write(int theByte) throws java.io.IOException + { + // Encoding suspended? + if( suspendEncoding ) + { + super.out.write( theByte ); + return; + } // end if: supsended + + // Encode? + if( encode ) + { + buffer[ position++ ] = (byte)theByte; + if( position >= bufferLength ) // Enough to encode. + { + out.write( encode3to4( b4, buffer, bufferLength ) ); + + lineLength += 4; + if( breakLines && lineLength >= MAX_LINE_LENGTH ) + { + out.write( NEW_LINE ); + lineLength = 0; + } // end if: end of line + + position = 0; + } // end if: enough to output + } // end if: encoding + + // Else, Decoding + else + { + // Meaningful Base64 character? + if( DECODABET[ theByte & 0x7f ] > WHITE_SPACE_ENC ) + { + buffer[ position++ ] = (byte)theByte; + if( position >= bufferLength ) // Enough to output. + { + int len = Base64.decode4to3( buffer, 0, b4, 0 ); + out.write( b4, 0, len ); + //out.write( Base64.decode4to3( buffer ) ); + position = 0; + } // end if: enough to output + } // end if: meaningful base64 character + else if( DECODABET[ theByte & 0x7f ] != WHITE_SPACE_ENC ) + { + throw new java.io.IOException( "Invalid character in Base64 data." ); + } // end else: not white space either + } // end else: decoding + } // end write + + + + /** + * Calls {@link #write(int)} repeatedly until len + * bytes are written. + * + * @param theBytes array from which to read bytes + * @param off offset for array + * @param len max number of bytes to read into array + * @since 1.3 + */ + public void write( byte[] theBytes, int off, int len ) throws java.io.IOException + { + // Encoding suspended? + if( suspendEncoding ) + { + super.out.write( theBytes, off, len ); + return; + } // end if: supsended + + for( int i = 0; i < len; i++ ) + { + write( theBytes[ off + i ] ); + } // end for: each byte written + + } // end write + + + + /** + * Method added by PHIL. [Thanks, PHIL. -Rob] + * This pads the buffer without closing the stream. + */ + public void flushBase64() throws java.io.IOException + { + if( position > 0 ) + { + if( encode ) + { + out.write( encode3to4( b4, buffer, position ) ); + position = 0; + } // end if: encoding + else + { + throw new java.io.IOException( "Base64 input not properly padded." ); + } // end else: decoding + } // end if: buffer partially full + + } // end flush + + + /** + * Flushes and closes (I think, in the superclass) the stream. + * + * @since 1.3 + */ + public void close() throws java.io.IOException + { + // 1. Ensure that pending characters are written + flushBase64(); + + // 2. Actually close the stream + // Base class both flushes and closes. + super.close(); + + buffer = null; + out = null; + } // end close + + + + /** + * Suspends encoding of the stream. + * May be helpful if you need to embed a piece of + * base640-encoded data in a stream. + * + * @since 1.5.1 + */ + public void suspendEncoding() throws java.io.IOException + { + flushBase64(); + this.suspendEncoding = true; + } // end suspendEncoding + + + /** + * Resumes encoding of the stream. + * May be helpful if you need to embed a piece of + * base640-encoded data in a stream. + * + * @since 1.5.1 + */ + public void resumeEncoding() + { + this.suspendEncoding = false; + } // end resumeEncoding + + + + } // end inner class OutputStream + + +} // end class Base64 diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/BreakpointResponseData.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/BreakpointResponseData.java deleted file mode 100644 index b0f3444..0000000 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/BreakpointResponseData.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.sourceforge.phpeclipse.xdebug.core; - -public class BreakpointResponseData extends ResponseData { - - private int BreakpointID = -1; - - BreakpointResponseData(int transactionID, int breakpointID) { - super(transactionID); - BreakpointID = breakpointID; - } - - // public BreakpointResponseData(ResponseData data,int breakpointID) { - // setTransactionID(data.getTransactionID()); - // BreakpointID=breakpointID; - // } - - public int getBreakpointID() { - return BreakpointID; - } - - public void setBreakpointID(int breakpointID) { - BreakpointID = breakpointID; - } - -} diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/DebugConnection.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/DebugConnection.java deleted file mode 100644 index e28b56b..0000000 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/DebugConnection.java +++ /dev/null @@ -1,431 +0,0 @@ -package net.sourceforge.phpeclipse.xdebug.core; - -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.EOFException; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.UnknownHostException; -import java.util.HashMap; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint; -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IBreakpoint; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -public class DebugConnection { - - private ServerSocket fDebugServerSocket; - - private DebugResponse lastResponse; - - private Socket fDebugSocket; - - private OutputStreamWriter fDebugWriter; - - private DataInputStream fDebugReader; - - private ResponseListenerJob fResponseListener; - - // Settings for Debug Process - private int fTransactionID = 0; - - private String fileuri = ""; - - private String appID = ""; - - private String lastCommand = ""; - - private XDebugTarget fDebugTarget; - - private HashMap ResponseList; - - public class DebugResponse { - - private Node parentNode; - - private int fTransactionID = -1; - - private String fCommand = ""; - - private String fStatus; - - private String fReason; - - private String fName; - - private boolean fError; - - public synchronized void setParentNode(String xmlInput) { - DocumentBuilderFactory factory = DocumentBuilderFactory - .newInstance(); - DocumentBuilder builder = null; - Document doc = null; - try { - builder = factory.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - ByteArrayInputStream InputXMLStream = new ByteArrayInputStream( - xmlInput.getBytes()); - - try { - doc = builder.parse(InputXMLStream); - } catch (SAXException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - parentNode = doc.getFirstChild(); - fName = parentNode.getNodeName(); - String idStr = getAttributeValue("transaction_id"); - if (idStr != "") - fTransactionID = Integer.parseInt(idStr); - fCommand = getAttributeValue("command"); - fStatus = getAttributeValue("status"); - fReason = getAttributeValue("reason"); - // notifyAll(); - } - - public String getAttributeValue(String AttributeName) { - String strValue = ""; - if (parentNode.hasAttributes()) { - NamedNodeMap listAttribute = parentNode.getAttributes(); - Node attribute = listAttribute.getNamedItem(AttributeName); - if (attribute != null) - strValue = attribute.getNodeValue(); - } - return strValue; - } - - public synchronized Node getParentNode() { - return parentNode; - } - - public synchronized String getCommand() { - return fCommand; - } - - public synchronized String getName() { - return fName; - } - - DebugResponse() { - fTransactionID = -1; - fCommand = ""; - fStatus = ""; - fReason = ""; - fName = ""; - } - - DebugResponse(String XMLInput) { - setParentNode(XMLInput); - } - - public synchronized String getReason() { - return fReason; - } - - public synchronized String getStatus() { - return fStatus; - } - - public synchronized int getTransactionID() { - return fTransactionID; - } - - private synchronized DebugResponse waitforTransactionID(int id) { - while (fTransactionID != id) { - try { - wait(); - } catch (InterruptedException e) { - } - } - // XDebugCorePlugin.log(IStatus.INFO,"got TransID: "+id); - - return this; - } - - public boolean isError() { - return fError; - } - - public void setError(boolean error) { - fError = error; - } - - protected synchronized void notifyWait() { - notifyAll(); - } - } - - /** - * Listens to events from the XDebug and fires corresponding debug events. - */ - class ResponseListenerJob extends Job { - - public ResponseListenerJob() { - super("XDebug Event Dispatch"); - setSystem(true); - - } - - private void checkResponse(DebugResponse response) { - Node node = response.getParentNode(); - if (node.hasChildNodes()) { - Node child = node.getFirstChild(); - if (child.getNodeName().equals("error")) { - int code = Integer.parseInt(PHPDebugUtils - .getAttributeValue(child, "code")); - String text = (child.getFirstChild()).getNodeValue(); - XDebugCorePlugin.log(IStatus.ERROR, lastCommand + " ERROR " - + code + ": " + text); - lastResponse.setError(true); - return; - } - } - lastResponse.setError(false); - if (response.getStatus().equals("stopped")) - terminated(); - else if (response.getStatus().equals("break") - && response.getReason().equals("ok")) { - if (response.getCommand().equals("run")) { // breakpoint hit - int id = -1; - try { - id = sendRequest("stack_get"); - } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - String InputXML = readData(); - if (InputXML != null) { - XDebugCorePlugin.log(IStatus.INFO, InputXML); - lastResponse.setParentNode(InputXML); - fDebugTarget - .breakpointHit(lastResponse.getParentNode()); - } - - } else if (response.getCommand().equals("step_into")) { // step_into - fDebugTarget.suspended(DebugEvent.STEP_END); - // XDebugCorePlugin.log(IStatus.INFO,response.getCommand()+" - // STEP_END sent"); - } else if (response.getCommand().equals("step_over")) { // step_over - fDebugTarget.suspended(DebugEvent.STEP_END); - // XDebugCorePlugin.log(IStatus.INFO,response.getCommand()+" - // STEP_END sent"); - } else if (response.getCommand().equals("step_out")) { // step_over - fDebugTarget.suspended(DebugEvent.STEP_END); - // XDebugCorePlugin.log(IStatus.INFO,response.getCommand()+" - // STEP_END sent"); - } - } else if (response.getCommand().equals("breakpoint_set")) { // step_over - String idStr = response.getAttributeValue("id"); - if (idStr != "") { - int targetID = response.getTransactionID(); - BreakpointResponseData ResponseData = new BreakpointResponseData( - response.getTransactionID(), Integer - .parseInt(idStr)); - - fDebugTarget.fireDebugResponseEvent(ResponseData); - IBreakpoint[] breakpoints = XDebugCorePlugin - .getBreakpoints(); - for (int i = 0; i < breakpoints.length; i++) { - XDebugLineBreakpoint breakpoint = (XDebugLineBreakpoint) breakpoints[i]; - try { - if (breakpoint.getID() == targetID) - breakpoint.setID(Integer.parseInt(idStr)); - } catch (NumberFormatException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) - */ - protected IStatus run(IProgressMonitor monitor) { - String InputXML = ""; - while (!fDebugTarget.isTerminated() && (InputXML != null)) { - InputXML = readData(); - if (InputXML != null) { - XDebugCorePlugin.log(IStatus.INFO, InputXML); - lastResponse.setParentNode(InputXML); - if (lastResponse.getName() == "init") { - Node myNode = lastResponse.getParentNode(); - appID = PHPDebugUtils - .getAttributeValue(myNode, "appid"); - fileuri = PHPDebugUtils.getAttributeValue(myNode, - "fileuri"); - // fDebugTarget.started(); - fDebugTarget.fireCreationEvent(); - } else if (lastResponse.getName() == "response") { - checkResponse(lastResponse); - } - ResponseList.put(new Integer(lastResponse - .getTransactionID()), lastResponse); - lastResponse.notifyWait(); - } - } - return Status.OK_STATUS; - } - - } - - public DebugConnection(XDebugTarget debugTarget, int debugPort) { - fDebugTarget = debugTarget; - lastResponse = new DebugResponse(); - ResponseList = new HashMap(); - - try { - fDebugServerSocket = new ServerSocket(debugPort); - fDebugSocket = fDebugServerSocket.accept(); - fDebugWriter = new OutputStreamWriter(fDebugSocket - .getOutputStream(), "UTF8"); - fDebugReader = new DataInputStream(fDebugSocket.getInputStream()); - // fDebugReader = new BufferedReader(new - // InputStreamReader(fDebugSocket.getInputStream())); - - } catch (UnknownHostException e) { - // abort("Unable to connect to PHP Debuger", e); - } catch (IOException e) { - // abort("Unable to connect to PHP Debuger", e); - } - fResponseListener = new ResponseListenerJob(); - fResponseListener.schedule(); - - } - - private void terminated() { - try { - fDebugReader.close(); - fDebugWriter.close(); - fDebugSocket.close(); - fDebugServerSocket.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - fDebugTarget.terminated(); - - } - - private String readData() { - byte byteBuffer[] = null, b; - int count = 0; - - try { - while ((b = fDebugReader.readByte()) != 0) { - count = count * 10 + b - '0'; - // count=count*10+Integer.parseInt(b); - } - // System.out.println(count); - byteBuffer = new byte[count]; - int readCount = 0; - int attempts = 0; - while ((count > 0) && (attempts < 5)) { - int rc = fDebugReader.read(byteBuffer, readCount, count); - count -= rc; - readCount += rc; - attempts++; - } - if ((b = fDebugReader.readByte()) != 0) // reads the NULL Byte at - // the end; - System.out.println("NULL-Byte missing!!"); - } catch (IOException e) { - // TODO Auto-generated catch block - if (e instanceof EOFException == false) - e.printStackTrace(); - return null; - } - return new String(byteBuffer); - } - - /** - * Sends a request to the Debugengine and waits for an OK. - * - * @param command - * debug command - * @throws DebugException - * if the request fails - */ - - public int sendRequest(String command) throws DebugException { - return sendRequest(command, ""); - } - - /** - * Sends a request to the Debugengine and waits for an OK. - * - * @param command - * debug command - * @arguments arguments for the command - * @throws DebugException - * if the request fails - */ - - public synchronized int sendRequest(String command, String arguments) - throws DebugException { - - // System.out.println(command+" -i "+transactionID+" "+arguments); - XDebugCorePlugin.log(IStatus.INFO, command + " -i " + fTransactionID - + " " + arguments); - synchronized (fDebugSocket) { - try { - fDebugWriter.write(command); - fDebugWriter.write(" -i " + fTransactionID); - if (arguments != "") - fDebugWriter.write(" " + arguments); - fDebugWriter.write(0); - fDebugWriter.flush(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return fTransactionID++; - } - - public DebugResponse waitforTransID(int id) { - if (ResponseList.containsKey(new Integer(id))) { - // return (DebugResponse)ResponseList.get(new Integer(id)); - return (DebugResponse) ResponseList.remove(new Integer(id)); - } else - return lastResponse.waitforTransactionID(id); - } - - public DebugResponse getResponse(int id) { - if (ResponseList.containsKey(new Integer(id))) - return (DebugResponse) ResponseList.get(new Integer(id)); - else - return waitforTransID(id); - } - -} diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IDebugConnection.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IDebugConnection.java new file mode 100644 index 0000000..0dfd129 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IDebugConnection.java @@ -0,0 +1,116 @@ +package net.sourceforge.phpeclipse.xdebug.core; + +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.core.model.IVariable; + +import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse; + +public interface IDebugConnection { + /** + * + * @param featureName + * @return true if debugger supports feature + */ + DebugResponse featureGet(String featureName); + + boolean featureSet(String featureName, String value); + + DebugResponse sendRequestA(String command, String parameter); + + /** + * + * @param breakpoint breakpoint to set + * @throws DebugException + */ + void addBreakpoint(IBreakpoint breakpoint, IPath filePath) throws DebugException; + + /** + * + * @param breakpoint breakpoint to remove + * @throws DebugException + */ + void removeBreakpoint(IBreakpoint breakpoint) throws DebugException; + + /** + * + * @param thread + * @return stackframes + * @throws DebugException + */ + IStackFrame[] getStackFrames(XDebugThread thread) throws DebugException; + + /** + * Single stepOver the interpreter. + * + * @throws DebugException if the request fails + */ + void stepOver() throws DebugException; + + /** + * Single Stepinto the interpreter. + * + * @throws DebugException if the request fails + * @throws + */ + void stepInto() throws DebugException; + + /** + * Single stepOut the interpreter. + * + * @throws DebugException if the request fails + */ + void stepOut() throws DebugException; + + /** + * Resume the debug process. + * + * @throws DebugException if the request fails + */ + void run() throws DebugException; + + /** + * Stops the debug process. + * + * @throws DebugException if the request fails + */ + void stop() throws DebugException; + + + boolean isClosed(); + + /** + * + * @param name variable name + * @param value value of the variable + * @return true if successfull + */ + + public boolean setVarValue(String name, String value); + + boolean isInitialized(); + + /** + * Get the SessionID of the current Connection. + * + * @throws DebugException if the request fails + */ + String getSessionID(); + + void setResponseListerner(Job listener); + + void startListener(); + /** + * + * @param frame + * @param level context-level + * @return the variables for the context + */ + public IVariable[] getVariables(XDebugStackFrame frame ,int level); +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IPHPDebugEvent.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IPHPDebugEvent.java new file mode 100644 index 0000000..a35e9ac --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IPHPDebugEvent.java @@ -0,0 +1,9 @@ +package net.sourceforge.phpeclipse.xdebug.core; + +public interface IPHPDebugEvent { + + int BREAKPOINT_HIT = 0; + int STEP_END = 1; + int STOPPED = 2; + +} diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IProxyEventListener.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IProxyEventListener.java new file mode 100644 index 0000000..c3ac70b --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IProxyEventListener.java @@ -0,0 +1,7 @@ +package net.sourceforge.phpeclipse.xdebug.core; + + +public interface IProxyEventListener { + public void handleProxyEvent(String ideKey, String initString, AbstractDebugConnection connectin); + +} diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IXDebugPreferenceConstants.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IXDebugPreferenceConstants.java index 0662af4..51486ae 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IXDebugPreferenceConstants.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/IXDebugPreferenceConstants.java @@ -2,8 +2,6 @@ package net.sourceforge.phpeclipse.xdebug.core; public interface IXDebugPreferenceConstants { public static final String DEBUGPORT_PREFERENCE = "debugport"; - public static final int DEFAULT_DEBUGPORT = 9000; - public static final String PHP_INTERPRETER_PREFERENCE = "phpInterpreter"; } diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ListenerList.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ListenerList.java new file mode 100644 index 0000000..e6cc007 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ListenerList.java @@ -0,0 +1,128 @@ +package net.sourceforge.phpeclipse.xdebug.core; + + +/** + * Local version of org.eclipse.jface.util.ListenerList (modified)s + */ +public class ListenerList { + /** + * The current number of listeners. + * Maintains invariant: 0 <= fSize <= listeners.length. + */ + private int fSize; + + /** + * The list of listeners. Initially null but initialized + * to an array of size capacity the first time a listener is added. + * Maintains invariant: listeners != null if and only if fSize != 0 + */ + private Object[] fListeners= null; + + /** + * The empty array singleton instance, returned by getListeners() + * when size == 0. + */ + private static final Object[] EmptyArray= new Object[0]; + + /** + * Creates a listener list with the given initial capacity. + * + * @param capacity the number of listeners which this list can initially accept + * without growing its internal representation; must be at least 1 + */ + public ListenerList(int capacity) { + if (capacity < 1) { + throw new IllegalArgumentException(); + } + fListeners= new Object[capacity]; + fSize= 0; + } + + /** + * Adds a listener to the list. + * Has no effect if an identical listener is already registered. + * + * @param listener a listener + */ + public synchronized void add(Object listener) { + if (listener == null) { + throw new IllegalArgumentException(); + } + // check for duplicates using identity + for (int i= 0; i < fSize; ++i) { + if (fListeners[i] == listener) { + return; + } + } + // grow array if necessary + if (fSize == fListeners.length) { + Object[] temp= new Object[(fSize * 2) + 1]; + System.arraycopy(fListeners, 0, temp, 0, fSize); + fListeners= temp; + } + fListeners[fSize++]= listener; + } + + /** + * Returns an array containing all the registered listeners. + * The resulting array is unaffected by subsequent adds or removes. + * If there are no listeners registered, the result is an empty array + * singleton instance (no garbage is created). + * Use this method when notifying listeners, so that any modifications + * to the listener list during the notification will have no effect on the + * notification itself. + */ + public synchronized Object[] getListeners() { + if (fSize == 0) { + return EmptyArray; + } + Object[] result= new Object[fSize]; + System.arraycopy(fListeners, 0, result, 0, fSize); + return result; + } + + /** + * Removes a listener from the list. + * Has no effect if an identical listener was not already registered. + * + * @param listener a listener + */ + public synchronized void remove(Object listener) { + if (listener == null) { + throw new IllegalArgumentException(); + } + + for (int i= 0; i < fSize; ++i) { + if (fListeners[i] == listener) { + if (--fSize == 0) { + fListeners= new Object[1]; + } else { + if (i < fSize) { + fListeners[i]= fListeners[fSize]; + } + fListeners[fSize]= null; + } + return; + } + } + } + + /** + * Removes all the listeners from the list. + */ + public synchronized void removeAll() { + fListeners= new Object[0]; + fSize= 0; + } + + /** + * Returns the number of registered listeners + * + * @return the number of registered listeners + */ + public int size() { + return fSize; + } +} + + diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ListenerMap.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ListenerMap.java new file mode 100644 index 0000000..9b51572 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ListenerMap.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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 net.sourceforge.phpeclipse.xdebug.core; + +import java.util.HashMap; + + +/** + * Local version of org.eclipse.jface.util.ListenerList (modified)s + */ +public class ListenerMap { + /** + * The current number of listeners. + * Maintains invariant: 0 <= fSize <= listeners.length. + */ + private int fSize; + + /** + * The map of listeners. Initially null but initialized + * to an array of size capacity the first time a listener is added. + * Maintains invariant: listeners != null if and only if fSize != 0 + */ + private HashMap fListeners = null; +// private HashMap fListeners = null; + + /** + * Creates a listener map with the given initial capacity. + * + * @param capacity the number of listeners which this list can initially accept + * without growing its internal representation; must be at least 1 + */ + public ListenerMap(int capacity) { + if (capacity < 1) { + throw new IllegalArgumentException(); + } + fListeners = new HashMap(capacity); + fSize = 0; + } + + /** + * Adds a listener to the Map. + * Overwrites an existing listener with the same IDE_Key. + * + * @param listener a listener + * @param ideKey IDE-key of the listener + */ + public synchronized void add(Object listener,String ideKey) { + if (listener == null) { + throw new IllegalArgumentException(); + } + // check for duplicates using identity + if (fListeners.get(ideKey) != null) + fSize++; + fListeners.put(ideKey,listener); + } + + /** + * Returns a map containing all the registered listeners. + * The resulting map is unaffected by subsequent adds or removes. + * If there are no listeners registered, the result is an empty map. + * Use this method when notifying listeners, so that any modifications + * to the listener list during the notification will have no effect on the + * notification itself. + */ + public synchronized HashMap getListeners() { + if (fSize == 0) { + return null; + } + HashMap result = new HashMap(fListeners); + return result; + } + + /** + * Returns the listener associated with the ideKey. + * If there is no listener registered, the result is null. + * Use this method when notifying listeners, so that any modifications + * to the listener list during the notification will have no effect on the + * notification itself. + */ + public synchronized Object getListener(String ideKey) { + return fListeners.get(ideKey); + } + + /** + * Removes a listener from the list. + * Has no effect if an identical listener was not already registered. + * + * @param listener a listener + */ + public synchronized void remove(Object listener,String ideKey) { + if (listener == null) { + throw new IllegalArgumentException(); + } + + if (fListeners.get(ideKey) == listener) { + fListeners.remove(ideKey); + fSize--; + } + } + + /** + * Removes all the listeners from the list. + */ + public synchronized void removeAll() { + fListeners.clear(); + fSize = 0; + } + + /** + * Returns the number of registered listeners + * + * @return the number of registered listeners + */ + public int size() { + return fSize; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/PHPDebugUtils.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/PHPDebugUtils.java index 8bdba0b..8b377a7 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/PHPDebugUtils.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/PHPDebugUtils.java @@ -7,52 +7,51 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class PHPDebugUtils { - public static String getAttributeValue(Node CurrentNode, - String AttributeName) { + public static String getAttributeValue (Node CurrentNode, String AttributeName) { String strValue = ""; if (CurrentNode.hasAttributes()) { NamedNodeMap listAttribute = CurrentNode.getAttributes(); Node attribute = listAttribute.getNamedItem(AttributeName); - if (attribute != null) + if (attribute !=null) strValue = attribute.getNodeValue(); } return strValue; } - + public static String escapeString(String string) { - StringBuffer escString = new StringBuffer(); - Pattern pattern = Pattern.compile("[a-zA-Z0-9\\._-]"); - Matcher matcher; - for (int i = 0; i < string.length(); i++) { - char c = string.charAt(i); - matcher = pattern.matcher("" + c); - if (matcher.find()) + StringBuffer escString=new StringBuffer(); + Pattern pattern = Pattern.compile("[a-zA-Z0-9\\._-]"); + Matcher matcher; + for (int i= 0; i 2) - string.append(s[i].substring(2)); - + for(int i=1 ; i2) + string.append(s[i].substring(2)); + } return string.toString(); } + } diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/PathMapItem.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/PathMapItem.java new file mode 100644 index 0000000..dbe28ac --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/PathMapItem.java @@ -0,0 +1,132 @@ +package net.sourceforge.phpeclipse.xdebug.core; + +//import java.net.MalformedURLException; +//import java.net.URL; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +public class PathMapItem { + private IPath local; + private IPath remote; + + // String.split() uses regular expressions + static final String DELIMITER_REGEX = "\\+\\*\\+"; + static final String DELIMITER = "+*+"; + + static private String MakeStringData(IPath local, IPath remote) { + //IPath b = new Path("file:/var/www/index.php"); + + if(local.getDevice() == "file://") { + local = local.setDevice(""); + } + String data = local.toString()+DELIMITER+remote.toString(); + return data; + } + + public PathMapItem(String newLocal, String newRemote) { + IPath localPath = sanitizePath(newLocal); + IPath remotePath = sanitizePath(newRemote); + local = localPath; + remote = remotePath; + } + + private IPath sanitizePath(String newPath) { + IPath sanitizePath = null; + IPath computePath = new Path(newPath); + /*if(computePath.getDevice() == null) { + sanitizePath = new Path("file://", newPath); + } else { + if(computePath.getDevice() == "file:") { + sanitizePath = computePath; + } else {*/ + sanitizePath = computePath; + /*} + }*/ + return sanitizePath; + } + + public PathMapItem(String data) { + String[] strData = data.split(DELIMITER_REGEX); + IPath localPath = sanitizePath(strData[0]); + IPath remotePath = sanitizePath(strData[1]); + local = localPath; + remote = remotePath; + } + + public String getStringData() { + return PathMapItem.MakeStringData(local, remote); + } + + /** + * Returns the local path, which serves as the key in the local/remote + * pair this variable represents + * + * @return local path + */ + public IPath getLocalPath() { + return new Path(local.toString()); + } + + /** + * Returns the remote path. + * + * @return remote path + */ + public IPath getRemotePath() { + return new Path(remote.toString()); + } + + /** + * Sets the local path + * @param local path + * @throws MalformedURLException + */ + public void setLocalPath(String path) { + this.local = sanitizePath(path); + } + + /** + * Sets the local path + * @param local path + */ + public void setLocalPath(IPath path) { + this.local = path; + } + + /** + * Sets the remote path + * @param remote path + */ + public void setRemotePath(IPath path) { + this.remote = path; + } + + /** + * Sets the remote path + * @param remote path + * @throws MalformedURLException + */ + public void setRemotePath(String path) { + this.remote = sanitizePath(path); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return local.toString()+"->"+remote.toString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + boolean equal = false; + if (obj instanceof PathMapItem) { + PathMapItem var = (PathMapItem) obj; + equal = var.getLocalPath().equals(local); + } + return equal; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ResponseData.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ResponseData.java deleted file mode 100644 index 58e4b9b..0000000 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/ResponseData.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.sourceforge.phpeclipse.xdebug.core; - -public class ResponseData { - - private int fTransactionID = -1; - - ResponseData(int transactionID) { - fTransactionID = transactionID; - } - - public int getTransactionID() { - return fTransactionID; - } - - public void setTransactionID(int transactionID) { - fTransactionID = transactionID; - } -} diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugCorePlugin.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugCorePlugin.java index a7ffee0..bbba27c 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugCorePlugin.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugCorePlugin.java @@ -1,28 +1,34 @@ package net.sourceforge.phpeclipse.xdebug.core; -import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; +import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; +//import org.eclipse.ui.plugin.AbstractUIPlugin;// *; +import org.eclipse.ui.preferences.ScopedPreferenceStore; +//import org.eclipse.core.resources.IWorkspace; +//import org.eclipse.core.resources.ResourcesPlugin; +//import org.eclipse.core.resources.IWorkspace; +//import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +//import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManager; import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.jface.preference.IPreferenceStore; +//import org.eclipse.jface.resource.ImageDescriptor; import org.osgi.framework.BundleContext; -/** - * The main plugin class to be used in the desktop. - */ -public class XDebugCorePlugin extends AbstractUIPlugin { - - // The shared instance. +public class XDebugCorePlugin extends Plugin { private static XDebugCorePlugin plugin; - public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.xdebug.core"; //$NON-NLS-1$ + + private XDebugProxy fXDebugProxy; + + private ScopedPreferenceStore preferenceStore; + /** * The constructor. */ @@ -42,6 +48,8 @@ public class XDebugCorePlugin extends AbstractUIPlugin { */ public void stop(BundleContext context) throws Exception { super.stop(context); + if (fXDebugProxy != null) + fXDebugProxy.stop(); plugin = null; } @@ -51,33 +59,22 @@ public class XDebugCorePlugin extends AbstractUIPlugin { public static XDebugCorePlugin getDefault() { return plugin; } - + + /*public static IWorkspace getWorkspace() { + return ResourcesPlugin.getWorkspace(); + }*/ + public static IBreakpoint[] getBreakpoints() { - return getBreakpointManager().getBreakpoints( - IXDebugConstants.ID_PHP_DEBUG_MODEL); + return getBreakpointManager().getBreakpoints(IXDebugConstants.ID_PHP_DEBUG_MODEL); } - - public static IBreakpointManager getBreakpointManager() { + + public static /*static*/ IBreakpointManager getBreakpointManager() { return DebugPlugin.getDefault().getBreakpointManager(); } - /** - * Returns an image descriptor for the image file at the given plug-in - * relative path. - * - * @param path - * the path - * @return the image descriptor - */ - public static ImageDescriptor getImageDescriptor(String path) { - return AbstractUIPlugin.imageDescriptorFromPlugin( - "net.sourceforge.phpeclipse.xdebug.core", path); - } - public static void log(int severity, String message) { - Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, - null); - XDebugCorePlugin.log(status); + Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null) ; + XDebugCorePlugin.log(status) ; } public static void log(IStatus status) { @@ -85,15 +82,38 @@ public class XDebugCorePlugin extends AbstractUIPlugin { } public static void log(Throwable e) { - log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, - "PHPLaunchingPlugin.internalErrorOccurred", e)); //$NON-NLS-1$ + log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPLaunchingPlugin.internalErrorOccurred", e)); //$NON-NLS-1$ } - - /** - * Returns the workspace instance. - */ - public static IWorkspace getWorkspace() { - return ResourcesPlugin.getWorkspace(); + + public static String getUniqueIdentifier() { + return PLUGIN_ID; + } + + public void setProxyPort(int port) { + if(fXDebugProxy!=null) { + if (fXDebugProxy.isRunning()) { + fXDebugProxy.stop(); + } + fXDebugProxy=null; + } } -} + public XDebugProxy getXDebugProxy() { + if (fXDebugProxy == null) { + int debugPort=getPreferenceStore().getInt(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE); + if (debugPort<1024) + debugPort=IXDebugPreferenceConstants.DEFAULT_DEBUGPORT; + fXDebugProxy= new XDebugProxy(debugPort); + } + return fXDebugProxy; + } + + public IPreferenceStore getPreferenceStore() { + // Create the preference store lazily. + if (preferenceStore == null) { + preferenceStore = new ScopedPreferenceStore(new InstanceScope(),getBundle().getSymbolicName()); + + } + return preferenceStore; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugProxy.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugProxy.java new file mode 100644 index 0000000..3d6396a --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/XDebugProxy.java @@ -0,0 +1,281 @@ +package net.sourceforge.phpeclipse.xdebug.core; + +import java.io.DataInputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.UnknownHostException; + +import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugConnection; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.IDebugEventFilter; +import org.eclipse.debug.core.IDebugEventSetListener; + +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget; + +public class XDebugProxy { + private XDebugTarget fTarget; + + protected String fInitString; + protected String fIdeKey; + + protected AbstractDebugConnection fConnection; + + class ProxyListenerJob extends Job { + public ProxyListenerJob() { + super("XDebug Proxy Connection Dispatch"); + setSystem(true); + + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + protected IStatus run(IProgressMonitor monitor) { + boolean timeout; + boolean error; + Socket socket=null; + DataInputStream reader=null; + OutputStreamWriter writer=null; + + while (!fTerminate) { + timeout = false; + error = false; + socket=null; + reader=null; + writer=null; + if (monitor.isCanceled()) return Status.CANCEL_STATUS; + try { + socket = fProxyServerSocket.accept(); + } catch (java.net.SocketTimeoutException e) { + timeout=true; + } catch (IOException e) { + error=true; +// e.printStackTrace(); + } + if (!(timeout || error)) { + XDebugCorePlugin.log(IStatus.INFO,"Proxy: someone tries to connect"); + + try { + writer = new OutputStreamWriter(socket.getOutputStream(), "UTF8"); + reader = new DataInputStream(socket.getInputStream()); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + fConnection=(AbstractDebugConnection) new XDebugConnection(socket,reader,writer); + if (fConnection.isInitialized()) { + fIdeKey=fConnection.getSessionID(); + XDebugCorePlugin.log(IStatus.INFO,""); + + fireProxyEvent(); + } + } + + } + return Status.OK_STATUS; + } + } + + /** + * Filters and dispatches events in a safe runnable to handle any + * exceptions. + */ + class EventNotifier implements ISafeRunnable { + + private IProxyEventListener fListener; + + /** + * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable) + */ + public void handleException(Throwable exception) { + IStatus status = new Status(IStatus.ERROR, XDebugCorePlugin.getUniqueIdentifier(), IStatus.ERROR, "An exception occurred while dispatching proxy", exception); //$NON-NLS-1$ + XDebugCorePlugin.log(status); + } + + /** + * @see org.eclipse.core.runtime.ISafeRunnable#run() + */ + public void run() throws Exception { + + fListener.handleProxyEvent(fIdeKey, fInitString, fConnection); + } + + /** + * Filter and dispatch the given events. If an exception occurs in one + * listener, events are still fired to subsequent listeners. + * + * @param events debug events + */ + public void dispatch() { + fListener = (IProxyEventListener) getEventListener(fIdeKey); + if (fListener==null) { // no listener is found so start the script + try { + fConnection.run(); + } catch (DebugException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else + Platform.run(this); + fListener = null; + } + + } + + + private ServerSocket fProxyServerSocket; + private ProxyListenerJob fProxyListener; + private boolean fTerminate; + private int fProxyPort; + private ListenerMap fEventListeners; + private boolean fIsRunning; + + + public XDebugProxy (int port) { + fProxyPort=port; + } + + public void setTarget( XDebugTarget Target ) { + fTarget = Target; + } + + public XDebugTarget getTarget() { + return fTarget; + } + + public void start() { + if (fIsRunning) + return; + try { + fProxyServerSocket = new ServerSocket(fProxyPort); + // set 5sek as timeout + fProxyServerSocket.setSoTimeout(5000); + XDebugCorePlugin.log(IStatus.INFO,"Proxy listens on port "+fProxyPort); + +// fDebugReader = new BufferedReader(new InputStreamReader(fDebugSocket.getInputStream())); + + } catch (UnknownHostException e) { + e.printStackTrace(); +// abort("Unable to connect to PHP Debuger", e); + } catch (IOException e) { + e.printStackTrace(); +// abort("Unable to connect to PHP Debuger", e); + } + fTerminate=false; + fProxyListener = new ProxyListenerJob(); + fProxyListener.schedule(); + fIsRunning=true; + + } + +/* public void stop() { + if (!fIsRunning) + return; + fTerminate=true; + fProxyListener.cancel(); + try { + fProxyServerSocket.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + fIsRunning = false; + XDebugCorePlugin.log(IStatus.INFO,"Proxy stopped"); + + }*/ + + public void stop() { + if (fIsRunning) { + fProxyListener.cancel(); + fTerminate = true; + try { + fProxyServerSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + fIsRunning = false; + XDebugCorePlugin.log(IStatus.INFO,"Proxy stopped"); + } + } + + /** + * Adds the given listener to the collection of registered proxy + * event listeners. Has no effect if an identical listener is already + * registered. + * + * @param listener the listener to add + + */ + public void addProxyEventListener(IProxyEventListener listener, String key) { + if (fEventListeners == null) { + fEventListeners = new ListenerMap(5); + } + fEventListeners.add(listener, key); + } + + /** + * Removes the given listener from the collection of registered proxy + * event listeners. Has no effect if an identical listener is not already + * registered. + * + * @param listener the listener to remove + */ + public void removeProxyEventListener(IProxyEventListener listener,String key) { + if (fEventListeners != null) { + fEventListeners.remove(listener,key); + } + } + + /** + * Notifies all registered proxy event set listeners of the given + * proxy events. Events which are filtered by a registered debug event + * filter are not fired. + * + * @param events array of debug events to fire + * @see IDebugEventFilter + * @see IDebugEventSetListener + * @since 2.0 + */ + public void fireProxyEvent() { + EventNotifier fNotifier = new EventNotifier(); + fNotifier.dispatch(); + } + + /** + * Returns the collection of registered proxy event listeners + * + * @return list of registered proxy event listeners, instances + * of IProxyEventListeners + */ + /*private Map getEventListeners() { + return fEventListeners.getListeners(); + }*/ + + private Object getEventListener(String ideKey) { + return fEventListeners.getListener(ideKey); + } + + /** + * @return Returns the fProxyPort. + */ + public int getProxyPort() { + return fProxyPort; + } + + public boolean isRunning() { + return fIsRunning; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseList.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseList.java new file mode 100644 index 0000000..af980d4 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseList.java @@ -0,0 +1,34 @@ +package net.sourceforge.phpeclipse.xdebug.core.xdebug; + +import java.util.HashMap; +import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse; + +public class ResponseList { + int fLastId; + HashMap fList; + + public ResponseList() { + fLastId = -1; + fList = new HashMap(); + } + + public synchronized void add(DebugResponse response, int id) { + fList.put(new Integer(id), response); + fLastId = id; + notifyAll(); + } + + public synchronized DebugResponse get(int id) { + while (id > fLastId) { + try { + wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + if (fList.containsKey(new Integer(id))) + return (DebugResponse) fList.remove(new Integer(id)); + else + return null; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java new file mode 100644 index 0000000..d700859 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java @@ -0,0 +1,347 @@ +package net.sourceforge.phpeclipse.xdebug.core.xdebug; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import net.sourceforge.phpeclipse.xdebug.core.IPHPDebugEvent; +import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils; +import net.sourceforge.phpeclipse.xdebug.core.PathMapItem; +import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; +import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.core.model.ILineBreakpoint; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; +import org.w3c.dom.CDATASection; + +/** + * Listens to events from the XDebug and fires corresponding + * debug events. + */ + +public class ResponseListener extends Job { + + + public class DebugResponse { + + private Node parentNode; + private int fTransactionID=-1; + private String fCommand=""; + private String fStatus; + private String fReason; + private String fName; + private boolean fError; + + private String fValue; + private String fType; + private String fAddress; + + public synchronized void setParentNode (String xmlInput){ + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder=null; + Document doc=null; + try { + builder = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + ByteArrayInputStream InputXMLStream = new ByteArrayInputStream(xmlInput.getBytes()); + + try { + doc = builder.parse(InputXMLStream); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + parentNode=doc.getFirstChild(); + + fName=parentNode.getNodeName(); + String idStr = getAttributeValue("transaction_id"); + if (!"".equals(idStr)) + fTransactionID = Integer.parseInt(idStr); + fCommand = getAttributeValue("command"); + fStatus = getAttributeValue("status"); + fReason = getAttributeValue("reason"); + + if( fCommand.compareTo("eval") == 0 ) { + try { + Node property = parentNode.getFirstChild(); + + NamedNodeMap listAttribute = property.getAttributes(); + Node attribute = listAttribute.getNamedItem("type"); + if (attribute !=null) { + fType = attribute.getNodeValue(); + } + + Node attribute1 = listAttribute.getNamedItem("address"); + if (attribute1 !=null) { + fAddress = attribute1.getNodeValue(); + } + + Node firstChild1 = (Node) property.getFirstChild(); + + if( firstChild1 != null ) { + fValue = firstChild1.getNodeValue(); + } + } catch (Exception e) { + // TODO: handle exception + } + } else { + try { + CDATASection firstChild = (CDATASection) parentNode.getFirstChild(); + + if( firstChild != null ) { + fValue = parentNode.getFirstChild().getNodeValue(); + } + } catch (Exception e) { + // TODO: handle exception + } + } + } + + public String getAttributeValue (String AttributeName) { + String strValue = ""; + if (parentNode.hasAttributes()) { + NamedNodeMap listAttribute = parentNode.getAttributes(); + Node attribute = listAttribute.getNamedItem(AttributeName); + if (attribute !=null) + strValue = attribute.getNodeValue(); + } + return strValue; + } + + public synchronized Node getParentNode(){ + return parentNode; + } + + public synchronized String getCommand() { + return fCommand; + } + public synchronized String getName() { + return fName; + } + + public synchronized String getValue() { + return fValue; + } + + public synchronized String getType() { + return fType; + } + + public synchronized String getAddress() { + return fAddress; + } + + DebugResponse () { + fTransactionID = -1; + fCommand = ""; + fStatus = ""; + fReason = ""; + fName= ""; + } + + DebugResponse (String XMLInput) { + setParentNode(XMLInput); + } + + public synchronized String getReason() { + return fReason; + } + + public synchronized String getStatus() { + return fStatus; + } + + public synchronized int getTransactionID() { + return fTransactionID; + } + + public boolean isError() { + return fError; + } + + public void setError(boolean error) { + fError = error; + } + + } + + + private XDebugConnection fConnection; + //private XDebugTarget fDebugTarget; + private DebugResponse lastResponse; + + public ResponseListener(XDebugConnection connection) { + super("XDebug Event Dispatch"); + setSystem(true); + fConnection=connection; + lastResponse= new DebugResponse(); + } + + + + + private void checkResponse(DebugResponse response) { + Node node=response.getParentNode(); + if (node.hasChildNodes()) { + Node child=node.getFirstChild(); + if (child.getNodeName().equals("error")) { + int code = Integer.parseInt(PHPDebugUtils.getAttributeValue(child, "code")); + String text=(child.getFirstChild()).getNodeValue(); + XDebugCorePlugin.log(IStatus.ERROR," ERROR "+code+": "+text); + lastResponse.setError(true); + return; + } + } + lastResponse.setError(false); + if (response.getStatus().equals("stopping")) { + //if (response.getStatus().equals("stopped")) { + fConnection.close(); + fireEvent(IPHPDebugEvent.STOPPED); + } else if (response.getStatus().equals("break") && response.getReason().equals("ok")){ + if (response.getCommand().equals("run")) { // breakpoint hit + int id=-1; + try { + id=fConnection.sendRequest("stack_get"); + } catch (DebugException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String InputXML = fConnection.readData(); + if (InputXML != null) { + XDebugCorePlugin.log(IStatus.INFO, InputXML); + lastResponse.setParentNode(InputXML); + breakpointHit(lastResponse.getParentNode()); + } + + } else if (response.getCommand().equals("step_into")) { // step_into + fireEvent(IPHPDebugEvent.STEP_END); +// XDebugCorePlugin.log(IStatus.INFO,response.getCommand()+" STEP_END sent"); + } else if (response.getCommand().equals("step_over")) { // step_over + fireEvent(IPHPDebugEvent.STEP_END); +// XDebugCorePlugin.log(IStatus.INFO,response.getCommand()+" STEP_END sent"); + } else if (response.getCommand().equals("step_out")) { // step_over + fireEvent(IPHPDebugEvent.STEP_END); +// XDebugCorePlugin.log(IStatus.INFO,response.getCommand()+" STEP_END sent"); + } + } + + } + + protected void fireEvent(int detail) { + DebugEvent event = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, detail); + DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event}); + } + + protected void fireEvent(int detail, Object data) { + DebugEvent event = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, detail); + event.setData(data); + DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event}); + } + + + protected void breakpointHit(Node node) { + Node child=node.getFirstChild(); + if (child.getNodeName().equals("stack")) { + int lineNumber = Integer.parseInt(PHPDebugUtils.getAttributeValue(child, "lineno")); + String filename=PHPDebugUtils.getAttributeValue(child, "filename"); + IBreakpoint[] breakpoints = XDebugCorePlugin.getBreakpoints(); + for (int i = 0; i < breakpoints.length; i++) { + IBreakpoint breakpoint = breakpoints[i]; + if (supportsBreakpoint(breakpoint)) { + if (breakpoint instanceof ILineBreakpoint) { + ILineBreakpoint lineBreakpoint = (ILineBreakpoint) breakpoint; + try { + if (breakpoint.isEnabled()) { + IMarker marker = breakpoint.getMarker(); + if (marker != null) { + String endfilename; + + if( XDebugCorePlugin.getDefault().getXDebugProxy().getTarget().getProcess() == null ) { + endfilename = marker.getResource().getLocation().lastSegment(); + } else { + endfilename = marker.getResource().getLocation().toOSString(); + } + + if(PHPDebugUtils.unescapeString(filename).endsWith(endfilename) && (lineBreakpoint.getLineNumber() == lineNumber) ) { + fireEvent(IPHPDebugEvent.BREAKPOINT_HIT,breakpoint); + break; + } + } + } + } catch (CoreException e) { + } + } + } + } + } + +// DebugEvent event = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, IPHPDebugEvent.STEP_END); +// DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event}); + } + + private boolean supportsBreakpoint(IBreakpoint breakpoint) { + if (breakpoint.getModelIdentifier().equals(IXDebugConstants.ID_PHP_DEBUG_MODEL)) { + return true; + } + return false; + } + + + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + protected IStatus run(IProgressMonitor monitor) { + String InputXML = ""; + while (!fConnection.isClosed() && (InputXML != null)) { + InputXML = fConnection.readData(); + if (InputXML != null) { + XDebugCorePlugin.log(IStatus.INFO, InputXML); + lastResponse.setParentNode(InputXML); +// if (lastResponse.getName() == "init") { +// Node myNode=lastResponse.getParentNode(); +// appID = PHPDebugUtils.getAttributeValue(myNode, "appid"); +// fileuri = PHPDebugUtils.getAttributeValue(myNode, "fileuri"); +// fDebugTarget.started(); +// fDebugTarget.fireCreationEvent(); + if (lastResponse.getName() == "response") { + fConnection.addResponse(lastResponse,lastResponse.getTransactionID()); + checkResponse(lastResponse); + } +// fConnection.addResponse(lastResponse,lastResponse.getTransactionID()); +// lastResponse.notifyWait(); + } + } + return Status.OK_STATUS; + } + +} diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java new file mode 100644 index 0000000..c2d800c --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java @@ -0,0 +1,538 @@ +/** + * + */ +package net.sourceforge.phpeclipse.xdebug.core.xdebug; + +import java.io.DataInputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.OutputStreamWriter; +//import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.Socket; +import java.net.URL; + +import net.sourceforge.phpeclipse.xdebug.core.AbstractDebugConnection; +import net.sourceforge.phpeclipse.xdebug.core.Base64; +import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils; +import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; +import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugAbstractValue; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +//import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.core.model.ILineBreakpoint; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.core.model.IVariable; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * @author Christian Perkonig + * + */ +public class XDebugConnection extends AbstractDebugConnection { + int fTransactionID = 0; + private Socket fDebugSocket; + private OutputStreamWriter fDebugWriter; + private DataInputStream fDebugReader; + private ResponseList fResponseList; + private ResponseListener fResponseListener; + + + public XDebugConnection(Socket debugSocket, DataInputStream reader, OutputStreamWriter writer) { + fResponseList = new ResponseList(); + fDebugWriter = writer; + fDebugReader = reader; + fDebugSocket = debugSocket; + fTransactionID = 0; + init(); + } + + private void init() { + fInitialized = false; + String initString=readData(); + XDebugCorePlugin.log(IStatus.INFO,initString); + + int startIdx=initString.indexOf("idekey=\""); + if (startIdx==-1) + return; + startIdx+=8; + int endIdx=initString.indexOf('"',startIdx); + if (endIdx==-1) + return; + fSessionID=initString.substring(startIdx,endIdx); + + fInitialized=true; + fIsClosed=false; + fResponseListener=new ResponseListener(this); + } + + protected String readData() { + byte byteBuffer[]=null,b; + int count=0; + + try { + while ((b =fDebugReader.readByte()) != 0) { + count = count * 10 + b - '0'; +// count=count*10+Integer.parseInt(b); + } +// System.out.println(count); + byteBuffer = new byte[count]; + int readCount=0; + int attempts=0; + while ((count >0) && (attempts < 50)) { +// while ((count >0) && (attempts <5)) { + int rc=fDebugReader.read(byteBuffer,readCount,count); + count-=rc; + readCount+=rc; + if (count>65530) + try { + Thread.sleep(200); + } catch (InterruptedException e) { + } + else + attempts++; + } + if((b= fDebugReader.readByte())!=0) // reads the NULL Byte at the end; + System.out.println("NULL-Byte missing!!"); + } catch (IOException e) { + // TODO Auto-generated catch block + if (e instanceof EOFException==false) + e.printStackTrace(); + return null; + } + return new String(byteBuffer); + } + + + /** + * Sends a request to the Debugengine and waits for an OK. + * + * @param command debug command + * @throws DebugException if the request fails + */ + + + public int sendRequest(String command) throws DebugException { + return sendRequest(command,""); + } + + public DebugResponse sendRequestA(String command, String parameter) { + int result = -1; + + try { + result = sendRequest(command, parameter); + } catch( DebugException e ){ + e.printStackTrace(); + } + + DebugResponse response = getResponse(result); + + return response; + } + + /** + * Sends a request to the Debugengine. + * + * @param command debug command + * @arguments arguments for the command + * @throws DebugException if the request fails + */ + + public synchronized int sendRequest(String command, String arguments) throws DebugException { + + XDebugCorePlugin.log(IStatus.INFO,command+" -i "+fTransactionID+" "+arguments); + synchronized (fDebugSocket) { + try { + fDebugWriter.write(command); + fDebugWriter.write(" -i " + fTransactionID); + if (!"".equals(arguments)) + fDebugWriter.write(" " + arguments); + fDebugWriter.write(0); + fDebugWriter.flush(); + } catch (IOException e) { + //e.printStackTrace(); + } + } + return fTransactionID++; + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#featureGet(java.lang.String) + */ + public DebugResponse featureGet(String featureName) { + int id=-1; + + try { + id= sendRequest("feature_get","-n "+featureName); + } catch (DebugException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + DebugResponse response = getResponse(id); + + return response; + } + + public boolean featureSet(String featureName, String value) { + int id=-1; + + try { + id= sendRequest("feature_set","-n "+featureName + " -v " + value); + } catch (DebugException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + if (getResponse(id).getAttributeValue("success").equals("1") ) + return true; + else + return false; + } + + protected DebugResponse getResponse(int id) { + return fResponseList.get(id); + } + + protected void addResponse(DebugResponse response, int id) { + fResponseList.add(response,id); + + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#addBreakpoint(org.eclipse.debug.core.model.IBreakpoint) + */ + public void addBreakpoint(IBreakpoint breakpoint, IPath filePath) throws DebugException { + try { + if (breakpoint.isEnabled()) { + IMarker marker = breakpoint.getMarker(); + if (marker != null) { + try { + String arg; + + arg = "-t line -f file://"+PHPDebugUtils.escapeString(filePath.toString())+" -n "+((ILineBreakpoint)breakpoint).getLineNumber(); + int id = sendRequest("breakpoint_set", arg); + String bpid = getResponse(id).getAttributeValue("id"); + + if (!"".equals(bpid)) + marker.setAttribute(XDebugLineBreakpoint.BREAKPOINT_ID,Integer.parseInt(bpid)); + + } catch (CoreException e) { + XDebugCorePlugin.log(IStatus.INFO,"Exception set break point"); + } + } + } + } catch (CoreException e) { + XDebugCorePlugin.log(IStatus.INFO,"Exception in breakpoint"); + } + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#removeBreakpoint(int) + */ + public void removeBreakpoint(IBreakpoint breakpoint) throws DebugException { + try { + int id =((XDebugLineBreakpoint)breakpoint).getID(); + if (id >0) + sendRequest("breakpoint_remove","-d "+id); + } catch (CoreException e) { + } + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#getStackFrames(net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread) + */ + public IStackFrame[] getStackFrames(XDebugThread thread) throws DebugException { + int id = sendRequest("stack_get"); + DebugResponse lastResponse = getResponse(id); + if (lastResponse.isError()) + return new IStackFrame[0]; + Node response = lastResponse.getParentNode(); + NodeList frames = response.getChildNodes(); + IStackFrame[] theFrames = new IStackFrame[frames.getLength()]; + for (int i = 0; i < frames.getLength(); i++) { + Node stackNode = frames.item(i); + XDebugStackFrame frame = new XDebugStackFrame(thread, i); + String level =PHPDebugUtils.getAttributeValue(stackNode,"level"); + if (!"".equals(level)) + frame.setLevel(Integer.parseInt(level)); + + frame.setType(PHPDebugUtils.getAttributeValue(stackNode,"type")); + String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename")); + String lineNo=PHPDebugUtils.getAttributeValue(stackNode,"lineno"); + + if (!"".equals(lineNo)) + frame.setLineNumber(Integer.parseInt(lineNo)); + + frame.setWhere(PHPDebugUtils.getAttributeValue(stackNode,"where")); + + try { + frame.setFullName(new URL(fileName)); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + frame.incrementStepCounter(); + + theFrames[i] = frame; + } + + return theFrames; + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#stepOver() + */ + public void stepOver() throws DebugException { + sendRequest ("step_over"); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#stepInto() + */ + public void stepInto() throws DebugException { + sendRequest("step_into"); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#stepOut() + */ + public void stepOut() throws DebugException { + sendRequest ("step_out"); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#run() + */ + public void run() throws DebugException { + sendRequest ("run"); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#stop() + */ + public void stop() throws DebugException { + sendRequest ("stop"); + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#setResponseListerner(org.eclipse.core.runtime.jobs.Job) + */ + public void setResponseListerner(Job listener) { +// fResponseListener=(ResponseListener)listener;; + } + + /* (non-Javadoc) + * @see net.sourceforge.phpeclipse.xdebug.core.IDebugConnection#startListener() + */ + public void startListener() { + fResponseListener.schedule(); + } + + public boolean setVarValue(String name, String value) { + int id=-1; + String str=Base64.encodeBytes(value.getBytes()); + int len=str.length(); + + try { + id =sendRequest("property_set","-n "+name+" -l "+len + " -- "+str); + } catch (DebugException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + DebugResponse dr=getResponse(id); + if ((dr.getAttributeValue("success")).equals("1")) + return true; + + return false; + + } + + public void close() { + fResponseListener.cancel(); + try { + fDebugReader.close(); + fDebugWriter.close(); + fDebugSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + fIsClosed=true; + } + + + public XDebugVariable getVariableFromNodeA(XDebugStackFrame frame, Node property) { + String address = PHPDebugUtils.getAttributeValue(property, "address"); + String varName; + String Name = PHPDebugUtils.getAttributeValue(property,"name"); + if ("".equals(Name)) { + varName = address; + } else { + varName = Name; + } + + String varEncoding=PHPDebugUtils.getAttributeValue(property,"encoding"); + int varNumChildren = 0; + if (PHPDebugUtils.getAttributeValue(property,"numchildren").equals("")) + varNumChildren = 0; + else + varNumChildren=Integer.parseInt(PHPDebugUtils.getAttributeValue(property,"numchildren")); + + String typeName=PHPDebugUtils.getAttributeValue(property,"type"); + + XDebugVariable variable = new XDebugVariable(typeName, varName); + variable.setEncoding(varEncoding); + variable.setNumChildren(varNumChildren); + XDebugAbstractValue val=null; + try { + val = (XDebugAbstractValue) variable.getValue(); + } catch (DebugException e1) { + e1.printStackTrace(); + } + if (val.getType()!= XDebugAbstractValue.VALUETYPE_UNINITIALIZED) { + if (variable.hasChildren()) { + NodeList varNodes = property.getChildNodes(); + val.renderValueString(""+varNodes.getLength()); + IVariable[] variables = new IVariable[varNodes.getLength()]; + for (int i = 0; iet.sourceforge.phpeclipse.debug.). */ public static final String ID_PHP_DEBUG_MODEL = "net.sourceforge.phpeclipse.xdebug.php"; - + /** - * Launch configuration key. Value is a PHPProject name program. The path is - * a string representing a full path to a perl program in the workspace. + * Launch configuration key. Value is a PHPProject name + * program. The path is a string representing a full path + * to a perl program in the workspace. */ - public static final String ATTR_PHP_PROJECT = ID_PHP_DEBUG_MODEL - + ".ATTR_PDA_PROFECT"; - + public static final String ATTR_PHP_PROJECT = ID_PHP_DEBUG_MODEL + ".ATTR_PDA_PROFECT"; /** - * Launch configuration key. Value is a php program. The path is a string - * representing a relative path to a php program in the project. + * Launch configuration key. Value is a php program. + * The path is a string representing a relative path + * to a php program in the project. */ - public static final String ATTR_PHP_FILE = ID_PHP_DEBUG_MODEL - + ".ATTR_PDA_FILE"; + public static final String ATTR_PHP_FILE = ID_PHP_DEBUG_MODEL + ".ATTR_PDA_FILE"; + + public static final String ATTR_PHP_DEFAULT_INTERPRETER = ID_PHP_DEBUG_MODEL + ".ATTR_PHP_DEFAULT_INTERPRETER"; - public static final String ATTR_PHP_DEFAULT_INTERPRETER = ID_PHP_DEBUG_MODEL - + ".ATTR_PHP_DEFAULT_INTERPRETER"; + public static final String ATTR_PHP_INTERPRETER = ID_PHP_DEBUG_MODEL + ".ATTR_PHP_INTERPRETER"; - public static final String ATTR_PHP_INTERPRETER = ID_PHP_DEBUG_MODEL - + ".ATTR_PHP_INTERPRETER"; + public static final String ATTR_PHP_DEFAULT_DEBUGPORT = ID_PHP_DEBUG_MODEL + ".ATTR_PHP_DEFAULT_DEBUGPORT"; - public static final String ATTR_PHP_DEFAULT_DEBUGPORT = ID_PHP_DEBUG_MODEL - + ".ATTR_PHP_DEFAULT_DEBUGPORT"; + public static final String ATTR_PHP_DEBUGPORT = ID_PHP_DEBUG_MODEL + ".ATTR_PHP_DEBUGPORT"; + + public static final String ATTR_PHP_IDE_ID = ID_PHP_DEBUG_MODEL + ".ATTR_PHP_IDE_ID"; + + public static final String ATTR_PHP_REMOTE_LOCATION = ID_PHP_DEBUG_MODEL + ".ATTR_PHP_REMOTE_LOCATION"; + + public static final String ATTR_PHP_PATHMAP = ID_PHP_DEBUG_MODEL + ".ATTR_PHP_PATHMAP"; - public static final String ATTR_PHP_DEBUGPORT = ID_PHP_DEBUG_MODEL - + ".ATTR_PHP_DEBUGPORT"; } + diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPLaunchConfigurationDelegate.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPLaunchConfigurationDelegate.java index 5880ca0..d464f64 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPLaunchConfigurationDelegate.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPLaunchConfigurationDelegate.java @@ -18,6 +18,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; import net.sourceforge.phpeclipse.xdebug.core.IXDebugPreferenceConstants; import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget; @@ -38,118 +39,104 @@ import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.LaunchConfigurationDelegate; -public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate { +public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate { + /** - * @see ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, - * ILaunch, IProgressMonitor) + * @see ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor) */ - public void launch(ILaunchConfiguration configuration, String mode, - ILaunch launch, IProgressMonitor monitor) throws CoreException { + public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { List commandList = new ArrayList(); - - String phpInterpreter = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_INTERPRETER, (String) null); - boolean useDefaultInterpreter = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, true); - - if (useDefaultInterpreter) - phpInterpreter = XDebugCorePlugin - .getDefault() - .getPreferenceStore() - .getString( - IXDebugPreferenceConstants.PHP_INTERPRETER_PREFERENCE); - + + String phpInterpreter = configuration.getAttribute(IXDebugConstants.ATTR_PHP_INTERPRETER, (String)null); + boolean useDefaultInterpreter= configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, true); + + if (useDefaultInterpreter) { + phpInterpreter=XDebugCorePlugin.getDefault().getPreferenceStore().getString(IXDebugPreferenceConstants.PHP_INTERPRETER_PREFERENCE); + if (phpInterpreter=="") { + phpInterpreter=ExternalToolsPlugin.getDefault().getPreferenceStore().getString(ExternalToolsPlugin.PHP_RUN_PREF); + } + } File exe = new File(phpInterpreter); // Just to get sure that the interpreter exists if (!exe.exists()) { - abort( - MessageFormat - .format( - "Specified PHP executable {0} does not exist. Check value of PHP-Interpreter.", - new String[] { phpInterpreter }), null); + abort(MessageFormat.format("Specified PHP executable {0} does not exist. Check value of PHP-Interpreter.", new String[]{phpInterpreter}), null); } commandList.add(phpInterpreter); - + // Project name - String projectName = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_PROJECT, (String) null); - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( - projectName); - // Just to get sure that the project exists + String projectName = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); +// Just to get sure that the project exists if (project == null) { abort("Project does not exist.", null); } - String fileName = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_FILE, (String) null); + String fileName = configuration.getAttribute(IXDebugConstants.ATTR_PHP_FILE, (String)null); IFile file = project.getFile(fileName); // Just to get sure that the script exists if (!file.exists()) { - abort(MessageFormat.format("PHP-Script {0} does not exist.", - new String[] { file.getFullPath().toString() }), null); + abort(MessageFormat.format("PHP-Script {0} does not exist.", new String[] {file.getFullPath().toString()}), null); } - + commandList.add(file.getLocation().toOSString()); - // Get de Debugport form the Launchconfiguration or from the preferences - int debugPort = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_DEBUGPORT, -1); - boolean useDefaultPort = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT, true); - if (useDefaultPort) - debugPort = XDebugCorePlugin.getDefault().getPreferenceStore() - .getInt(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE); - if (debugPort < 1024) - debugPort = IXDebugPreferenceConstants.DEFAULT_DEBUGPORT; + // Get the Debugport from the preferences + int debugPort=XDebugCorePlugin.getDefault().getPreferenceStore().getInt(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE); + + // check for default port + if (debugPort==0) + debugPort=IXDebugPreferenceConstants.DEFAULT_DEBUGPORT; - String[] envp = DebugPlugin.getDefault().getLaunchManager() - .getEnvironment(configuration); + String[] envp=DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration); // appends the environment to the native environment - if (envp == null) { - Map stringVars = DebugPlugin.getDefault().getLaunchManager() - .getNativeEnvironment(); - int idx = 0; - envp = new String[stringVars.size()]; + if (envp==null) { + Map stringVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment(); + int idx=0; + envp= new String[stringVars.size()]; for (Iterator i = stringVars.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); String value = (String) stringVars.get(key); - envp[idx++] = key + "=" + value; + envp[idx++]=key+"="+value; } } + String idekey=fileName+"-"+(int)(Math.random()*100000); if (mode.equals(ILaunchManager.DEBUG_MODE)) { - String[] env = new String[envp.length + 1]; - for (int i = 0; i < envp.length; i++) - env[i + 1] = envp[i]; - env[0] = "XDEBUG_CONFIG=idekey=xdebug_test remote_enable=1"; - envp = env; + String[] env = new String[envp.length+1]; + for(int i=0;i 1) { + return resolveSourceElement(element, sources); + } else { + return null; + } + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourceLookupParticipant.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourceLookupParticipant.java index 59cdae3..3e7a34d 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourceLookupParticipant.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourceLookupParticipant.java @@ -1,12 +1,27 @@ package net.sourceforge.phpeclipse.xdebug.php.launching; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.phpeclipse.xdebug.core.PathMapItem; import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages; public class PHPSourceLookupParticipant extends AbstractSourceLookupParticipant { + /* (non-Javadoc) + * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#getSourceName(Object) + */ public String getSourceName(Object object) throws CoreException { if (object instanceof XDebugStackFrame) { return ((XDebugStackFrame) object).getSourceName(); @@ -14,4 +29,127 @@ public class PHPSourceLookupParticipant extends AbstractSourceLookupParticipant return null; } -} + /* (non-Javadoc) + * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#findSourceElements(java.lang.Object) + */ + public Object[] findSourceElements(Object object) throws CoreException { + if (object == null) { + return new Object[] {}; + } + XDebugStackFrame stackFrame = null; + if (object instanceof XDebugStackFrame) { + stackFrame = (XDebugStackFrame) object; + } else { + return new Object[] {}; + } + + List results = null; + CoreException single = null; + MultiStatus multiStatus = null; + + if (isFindDuplicates()) { + results = new ArrayList(); + } + + String name = getSourceName(object); + if (name == null || name.length() == 0) { + return new Object[] {}; + } + + // here our stackframe is guaranteed not to be null + IPath sLocalPath = null; + + if (((XDebugStackFrame) object).getThread() == null) { + IPath sPath = new Path(stackFrame.getFullName().getPath()); + List pathMap = getDirector().getLaunchConfiguration() + .getAttribute(IXDebugConstants.ATTR_PHP_PATHMAP, (List) null); + + PathMapItem pmi = null; + for (int k = 0; k < pathMap.size(); k++) { + pmi = new PathMapItem((String) pathMap.get(k)); + + IPath local = new Path(pmi.getLocalPath().toString())/* .removeFirstSegments(1) */; + IPath remote = new Path(pmi.getRemotePath().toString())/* .removeFirstSegments(1) */; + + if (remote.matchingFirstSegments(sPath) == remote.segmentCount()) { + sLocalPath = local; + } + } + } else { + + } + + String Type = stackFrame.getType(); + + if (Type.equals("eval")) { + results.add("pippo"); + return results.toArray(); + } + + ISourceContainer[] containers = getSourceContainers(); + for (int i = 0; i < containers.length; i++) { + ISourceContainer container = getDelegateContainer(containers[i]); + if (container == null) { + continue; + } + + try { + Object[] objects = container.findSourceElements(name); + if (objects.length > 0) { + if (isFindDuplicates()) { + if (((XDebugStackFrame) object).getThread() == null) { + addMatching(results, sLocalPath, objects); + } else { + return objects; + } + } else { + if (objects.length == 1) { + return objects; + } + return new Object[] { objects[0] }; + } + } + } catch (CoreException e) { + if (single == null) { + single = e; + } else if (multiStatus == null) { + multiStatus = new MultiStatus(DebugPlugin + .getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, + new IStatus[] { single.getStatus() }, + SourceLookupMessages.CompositeSourceContainer_0, + null); + multiStatus.add(e.getStatus()); + } else { + multiStatus.add(e.getStatus()); + } + } + } + if (results == null) { + if (multiStatus != null) { + throw new CoreException(multiStatus); + } else if (single != null) { + throw single; + } + return EMPTY; + } + return results.toArray(); + } + + static void addMatching(List results, IPath localPath, Object[] objects) { + if (results == null || localPath == null || objects == null) { + return; + } + for (int j = 0; j < objects.length; j++) { + if (objects[j] == null || !(objects[j] instanceof IFile)) { + continue; + } + IFile file = (IFile) objects[j]; + + IPath path = new Path(file.getLocation().toString()); + if (localPath.matchingFirstSegments(path) == localPath + .segmentCount()) { + results.add(objects[j]); + } + } + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourcePathComputerDelegate.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourcePathComputerDelegate.java index 909cb8d..60f3455 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourcePathComputerDelegate.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourcePathComputerDelegate.java @@ -1,5 +1,6 @@ package net.sourceforge.phpeclipse.xdebug.php.launching; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -10,39 +11,30 @@ import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate; import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer; -public class PHPSourcePathComputerDelegate implements - ISourcePathComputerDelegate { +public class PHPSourcePathComputerDelegate implements ISourcePathComputerDelegate { - public ISourceContainer[] computeSourceContainers( - ILaunchConfiguration configuration, IProgressMonitor monitor) - throws CoreException { - // String path = - // configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROGRAM, - // (String)null); - // ISourceContainer sourceContainer = null; - // if (path != null) { - // IResource resource = - // ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path)); - // if (resource != null) { - // IContainer container = resource.getParent(); - // if (container.getType() == IResource.PROJECT) { - // sourceContainer = new ProjectSourceContainer((IProject)container, - // false); - // } else if (container.getType() == IResource.FOLDER) { - // sourceContainer = new FolderSourceContainer(container, false); - // } - // } - // } - // if (sourceContainer == null) { - // sourceContainer = new WorkspaceSourceContainer(); - // } - // return new ISourceContainer[]{sourceContainer}; - String project = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_PROJECT, (String) null); + public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { +// String path = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROGRAM, (String)null); +// ISourceContainer sourceContainer = null; +// if (path != null) { +// IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path)); +// if (resource != null) { +// IContainer container = resource.getParent(); +// if (container.getType() == IResource.PROJECT) { +// sourceContainer = new ProjectSourceContainer((IProject)container, false); +// } else if (container.getType() == IResource.FOLDER) { +// sourceContainer = new FolderSourceContainer(container, false); +// } +// } +// } +// if (sourceContainer == null) { +// sourceContainer = new WorkspaceSourceContainer(); +// } +// return new ISourceContainer[]{sourceContainer}; + String project = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null); ISourceContainer sourceContainer = null; if (project != null) { - IProject resource = ResourcesPlugin.getWorkspace().getRoot() - .getProject(project); + IProject resource = ResourcesPlugin.getWorkspace().getRoot().getProject(project); if (resource != null) { sourceContainer = new ProjectSourceContainer(resource, false); } @@ -50,8 +42,8 @@ public class PHPSourcePathComputerDelegate implements if (sourceContainer == null) { sourceContainer = new WorkspaceSourceContainer(); } - return new ISourceContainer[] { sourceContainer }; - + return new ISourceContainer[]{sourceContainer}; + } } diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugAbstractValue.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugAbstractValue.java index a3c7cdd..37494f7 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugAbstractValue.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugAbstractValue.java @@ -17,158 +17,319 @@ import org.w3c.dom.NodeList; /** * @author Axel - * - * TODO To change the template for this generated type comment go to Window - - * Preferences - Java - Code Style - Code Templates + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates */ -public abstract class XDebugAbstractValue extends XDebugElement implements - IValue { - +public abstract class XDebugAbstractValue extends XDebugElement implements IValue { + public static final int VALUETYPE_UNKNOWN = -1; - public static final int VALUETYPE_UNINITIALIZED = 0; - public static final int VALUETYPE_STRING = 1; - public static final int VALUETYPE_INT = 4; - public static final int VALUETYPE_FLOAT = 5; - public static final int VALUETYPE_BOOLEAN = 6; - public static final int VALUETYPE_ARRAY = 8; - public static final int VALUETYPE_HASH = 9; - public static final int VALUETYPE_OBJECT = 10; + public static final int VALUETYPE_RESOURCE = 11; + protected XDebugVariable fVariable; - private IVariable[] fVariables; - protected String fValueString; - protected int fType; - protected String fTypeName; + + private boolean fhasChanged; + + public XDebugAbstractValue(XDebugVariable variable, String typeName) { + super((XDebugTarget) variable.getDebugTarget()); + fVariable = variable; + setType(typeName); + fVariables= new IVariable[0]; + } - public XDebugAbstractValue(XDebugVariable variable, Node varNode, - String typeName) { + + public XDebugAbstractValue(XDebugVariable variable,Node varNode,String typeName) { super((XDebugTarget) variable.getDebugTarget()); fVariable = variable; - if (varNode == null) { + if (varNode==null){ try { - System.out.println(variable.getName() + "=null"); + System.out.println(variable.getName()+"=null"); } catch (DebugException e) { // TODO Auto-generated catch block e.printStackTrace(); } - return; + return; } setType(typeName); NodeList property = varNode.getChildNodes(); if (variable.hasChildren()) { - renderValueString("" + property.getLength()); + renderValueString(""+property.getLength()); fVariables = new IVariable[property.getLength()]; - for (int i = 0; i < property.getLength(); i++) { + for (int i = 0; i 0); } - + public boolean isArray() { return ((fType & VALUETYPE_ARRAY) > 0); } - + public abstract void setType(String typeName); - public abstract void renderValueString(String data); public abstract boolean verifyValue(String expression); - + public boolean setValue(String expression) { if (!verifyValue(expression)) return false; - if (fTarget.setVarValue(fVariable.getFullName(), expression)) { - renderValueString(expression); - return true; - } + if( fTarget == null ) { + renderValueString(expression); + } else { + if(fTarget.setVarValue(fVariable.getFullName(),expression)) { + renderValueString(expression); + return true; + } + } return false; } + + public boolean setValueA(String expression) { + if(! fValueString.toString().equals(expression)) { + fVariables= new IVariable[0]; + fValueString = expression; + fhasChanged = true; + } else { + fhasChanged = false; + } + + return true; + } + + public boolean setValueB(IValue value) { + try { + fTypeName = value.getReferenceTypeName(); + } catch (DebugException e) { + } + + fhasChanged = false; + + switch (((XDebugAbstractValue) value). getType()) { + case VALUETYPE_UNINITIALIZED: + case VALUETYPE_STRING: + case VALUETYPE_INT: + case VALUETYPE_FLOAT: + case VALUETYPE_BOOLEAN: + try { + if (! fValueString.equals(value.getValueString())) { + fValueString = value.getValueString(); + fhasChanged = true; + } + } catch (DebugException e) { + int a = 10; + a++; + } + break; + + case VALUETYPE_RESOURCE: + try { + if (! fValueString.equals(value.getValueString())) { + fValueString = value.getValueString(); + fhasChanged = true; + } + } catch (DebugException e) { + int a = 10; + a++; + } + break; + + case VALUETYPE_HASH: + int a = 20; + a = a +2; + break; + + case VALUETYPE_OBJECT: + case VALUETYPE_ARRAY: + try { + IVariable[] newVariable = value.getVariables(); + + if (fVariables.length == 0) { + if (newVariable.length > 0) { + fValueString = value.getValueString(); + fVariables = newVariable; + fhasChanged = true; + } + } else { + for(int i = 0; i < fVariables.length; i++) { + // da capire quando e perche' + try { + if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) { + //fVariables[i].setValue(newVariable[i].getValue()); + fhasChanged = true; + } + } catch (Exception e) { + int b = 1; + } + } + if (fhasChanged) { + fValueString = value.getValueString(); + for(int i = 0; i < fVariables.length; i++) { + try { + fVariables[i].setValue(newVariable[i].getValue()); + } catch (Exception e) { + int b = 1; + } + } + } + } + } catch (DebugException e) { + int b = 10; + b++; + } + + break; + } + + return true; + } + + public boolean setValueBOld(IValue value) { + fhasChanged = false; + + switch (((XDebugAbstractValue) value). getType()) { + case VALUETYPE_UNINITIALIZED: + case VALUETYPE_STRING: + case VALUETYPE_INT: + case VALUETYPE_FLOAT: + case VALUETYPE_BOOLEAN: + try { + if (! fValueString.equals(value.getValueString())) { + fValueString = value.getValueString(); + fhasChanged = true; + } + } catch (DebugException e) { + } + break; + + case VALUETYPE_HASH: + int a = 20; + a = a +2; + break; + + case VALUETYPE_OBJECT: + case VALUETYPE_ARRAY: + try { + IVariable[] newVariable = value.getVariables(); + + if (fVariables.length == 0) { + if (newVariable.length > 0) { + fValueString = value.getValueString(); + fVariables = newVariable; + fhasChanged = true; + } + } else { + for(int i = 0; i < fVariables.length; i++) { + if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) { + //fVariables[i].setValue(newVariable[i].getValue()); + fhasChanged = true; + } + } + if (fhasChanged) { + fValueString = value.getValueString(); + for(int i = 0; i < fVariables.length; i++) { + fVariables[i].setValue(newVariable[i].getValue()); + } + } + } + } catch (DebugException e) { + } + + break; + } + + return true; + } + + public int getType() { + return fType; + } public boolean supportsValueModification() { return false; } -} +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugArrayValue.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugArrayValue.java index e7075f8..f0117cd 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugArrayValue.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugArrayValue.java @@ -8,15 +8,20 @@ public class XDebugArrayValue extends XDebugAbstractValue { String typeName) { super(variable, varNode, typeName); } + + public XDebugArrayValue(XDebugVariable variable, String typeName) { + super(variable, typeName); + } + public void setType(String typeName) { - fType = XDebugAbstractValue.VALUETYPE_ARRAY; - fTypeName = typeName; + fType=XDebugAbstractValue.VALUETYPE_ARRAY; + fTypeName=typeName; } public void renderValueString(String data) { - fValueString = data + " element(s)"; + fValueString= data +" element(s)"; } public boolean verifyValue(String expression) { diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugBooleanValue.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugBooleanValue.java index 678a955..113f7c2 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugBooleanValue.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugBooleanValue.java @@ -8,47 +8,51 @@ public class XDebugBooleanValue extends XDebugAbstractValue { String typeName) { super(variable, varNode, typeName); } + + public XDebugBooleanValue(XDebugVariable variable,String typeName) { + super(variable, typeName); + } + public boolean supportsValueModification() { return true; } public void setType(String typeName) { - fType = XDebugAbstractValue.VALUETYPE_BOOLEAN; - fTypeName = typeName; - } + fType=XDebugAbstractValue.VALUETYPE_BOOLEAN; + fTypeName=typeName; } public void renderValueString(String data) { - int value = -1; + int value=-1; try { - value = Integer.parseInt(data); + value=Integer.parseInt(data); } catch (NumberFormatException e) { - data = data.toLowerCase(); + data=data.toLowerCase(); if (data.equals("true") || data.equals("false")) - fValueString = data; + fValueString=data; else - fValueString = "not defined"; + fValueString="not defined"; } - if (value == 0) - fValueString = "false"; - else if (value == 1) - fValueString = "true"; + if (value==0) + fValueString="false"; + else if (value==1) + fValueString="true"; else - fValueString = "not defined"; + fValueString="not defined"; } public boolean verifyValue(String expression) { - int value = -1; + int value=-1; try { - value = Integer.parseInt(expression); + value=Integer.parseInt(expression); } catch (NumberFormatException e) { - expression = expression.toLowerCase(); + expression=expression.toLowerCase(); if (expression.equals("true") || expression.equals("false")) return true; else return false; } - if ((value >= 0) && (value <= 1)) + if ((value>=0)&& (value <=1)) return true; return false; } diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugElement.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugElement.java index 7242bd4..b103f17 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugElement.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugElement.java @@ -3,7 +3,8 @@ */ package net.sourceforge.phpeclipse.xdebug.php.model; -import net.sourceforge.phpeclipse.xdebug.core.ResponseData; + + import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; import org.eclipse.core.runtime.PlatformObject; @@ -16,53 +17,51 @@ import org.eclipse.debug.core.model.IDebugTarget; /** * @author Christian - * + * */ public class XDebugElement extends PlatformObject implements IDebugElement { - - // containing target + + // containing target protected XDebugTarget fTarget; - + /** - * Constructs a new debug element contained in the given debug target. + * Constructs a new debug element contained in the given + * debug target. * - * @param target - * debug target (PDA VM) + * @param target debug target (PDA VM) */ public XDebugElement(XDebugTarget target) { fTarget = target; } - - /* - * (non-Javadoc) - * + + public XDebugElement() { + fTarget = null; + } + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier() */ public String getModelIdentifier() { return IXDebugConstants.ID_PHP_DEBUG_MODEL; } - - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget() */ public IDebugTarget getDebugTarget() { return fTarget; } + + public void setDebugTarget(XDebugTarget target) { + fTarget=target; + } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugElement#getLaunch() */ public ILaunch getLaunch() { return getDebugTarget().getLaunch(); } - - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ public Object getAdapter(Class adapter) { @@ -71,65 +70,56 @@ public class XDebugElement extends PlatformObject implements IDebugElement { } return super.getAdapter(adapter); } - + protected void abort(String message, Throwable e) throws DebugException { - /* - * Axel auskommentiert throw new DebugException(new - * Status(IStatus.ERROR, - * DebugExamplesPlugin.getDefault().getDescriptor().getUniqueIdentifier(), - * DebugPlugin.INTERNAL_ERROR, message, e)); - */ - } - +/* Axel auskommentiert + throw new DebugException(new Status(IStatus.ERROR, DebugExamplesPlugin.getDefault().getDescriptor().getUniqueIdentifier(), + DebugPlugin.INTERNAL_ERROR, message, e)); +*/ + } + /** * Fires a debug event * - * @param event - * the event to be fired + * @param event the event to be fired */ protected void fireEvent(DebugEvent event) { - DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { event }); + DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event}); } - + /** * Fires a CREATE event for this element. */ public void fireCreationEvent() { fireEvent(new DebugEvent(this, DebugEvent.CREATE)); - } - + } + /** - * Fires a RESUME event for this element with the given - * detail. + * Fires a RESUME event for this element with + * the given detail. * - * @param detail - * event detail code + * @param detail event detail code */ public void fireResumeEvent(int detail) { fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail)); } /** - * Fires a SUSPEND event for this element with the given - * detail. + * Fires a SUSPEND event for this element with + * the given detail. * - * @param detail - * event detail code + * @param detail event detail code */ public void fireSuspendEvent(int detail) { fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail)); } - + /** * Fires a TERMINATE event for this element. */ protected void fireTerminateEvent() { fireEvent(new DebugEvent(this, DebugEvent.TERMINATE)); } + - public void fireDebugResponseEvent(ResponseData data) { - DebugEvent de = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC); - de.setData(data); - fireEvent(de); - } } \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugFloatValue.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugFloatValue.java index 03a6439..0086c2a 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugFloatValue.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugFloatValue.java @@ -4,23 +4,29 @@ import org.w3c.dom.Node; public class XDebugFloatValue extends XDebugAbstractValue { - public XDebugFloatValue(XDebugVariable variable, Node varNode, - String TypeName) { - super(variable, varNode, TypeName); - + public XDebugFloatValue(XDebugVariable variable, Node varNode,String TypeName) { + super(variable, varNode,TypeName); + + } + + public XDebugFloatValue(XDebugVariable variable,String TypeName) { + super(variable,TypeName); + } + public boolean supportsValueModification() { return true; } + public void setType(String typeName) { - fType = XDebugAbstractValue.VALUETYPE_FLOAT; - fTypeName = typeName; + fType=XDebugAbstractValue.VALUETYPE_FLOAT; + fTypeName=typeName; } public void renderValueString(String data) { - fValueString = data; + fValueString=data; } public boolean verifyValue(String expression) { diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugIntValue.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugIntValue.java index 9002c3e..31a35e1 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugIntValue.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugIntValue.java @@ -4,24 +4,30 @@ import org.w3c.dom.Node; public class XDebugIntValue extends XDebugAbstractValue { - public XDebugIntValue(XDebugVariable variable, Node varNode, String TypeName) { - super(variable, varNode, TypeName); - + public XDebugIntValue(XDebugVariable variable, Node varNode,String TypeName) { + super(variable, varNode,TypeName); + } - + + public XDebugIntValue(XDebugVariable variable,String TypeName) { + super(variable,TypeName); + + } + public void setType(String typeName) { - fType = XDebugAbstractValue.VALUETYPE_INT; - fTypeName = typeName; + fType=XDebugAbstractValue.VALUETYPE_INT; + fTypeName=typeName; } - + public boolean supportsValueModification() { return true; } - + public void renderValueString(String dataString) { - fValueString = dataString; + fValueString=dataString; } + public boolean verifyValue(String expression) { try { Integer.parseInt(expression); @@ -30,7 +36,7 @@ public class XDebugIntValue extends XDebugAbstractValue { } return true; } - + public String toString() { return fValueString; } diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugLineBreakpoint.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugLineBreakpoint.java index bdfe73d..a626e8c 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugLineBreakpoint.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugLineBreakpoint.java @@ -1,3 +1,4 @@ + /* * Created on 25.11.2004 * @@ -6,6 +7,7 @@ */ package net.sourceforge.phpeclipse.xdebug.php.model; + import java.util.HashMap; import java.util.Map; @@ -20,96 +22,85 @@ import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.LineBreakpoint; + /** * @author Axel - * - * TODO To change the template for this generated type comment go to Window - - * Preferences - Java - Code Style - Code Templates + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates */ -public class XDebugLineBreakpoint extends LineBreakpoint { - +public class XDebugLineBreakpoint extends LineBreakpoint { + /** - * Default constructor is required for the breakpoint manager to re-create - * persisted breakpoints. After instantiating a breakpoint, the - * setMarker(...) method is called to restore this - * breakpoint's attributes. + * Default constructor is required for the breakpoint manager + * to re-create persisted breakpoints. After instantiating a breakpoint, + * the setMarker(...) method is called to restore + * this breakpoint's attributes. */ private static final String XDEBUG_LINE_BREAKPOINT = "net.sourceforge.phpeclipse.xdebug.core.XDebugLineBreakpoint"; //$NON-NLS-1$ /** - * Breakpoint attribute storing the fully qualified name of the type this - * breakpoint is located in. (value - * "net.sourceforge.phpeclipse.debug.typeName"). This - * attribute is a String. + * Breakpoint attribute storing the fully qualified name of the type + * this breakpoint is located in. + * (value "net.sourceforge.phpeclipse.debug.typeName"). This attribute is a String. */ protected static final String TYPE_NAME = "net.sourceforge.phpeclipse.debug.typeName"; //$NON-NLS-1$ - // public PHPLineBreakpoint() { - // } - // - // public PHPLineBreakpoint(IResource resource, int lineNumber, int - // charStart, int charEnd, int hitCount, boolean add, Map attributes) throws - // DebugException { - // this(resource, lineNumber, charStart, charEnd, hitCount, add, attributes, - // PHP_LINE_BREAKPOINT); - // } - // - // public PHPLineBreakpoint(IResource resource, int lineNumber, int - // hitCount, boolean add, Map attributes) throws DebugException { - // this(resource, lineNumber, -1, -1, hitCount, add, attributes, - // PHP_LINE_BREAKPOINT); - // } - - public static final String BREAKPOINT_ID = "XDebugLineBreakpointID"; - +// public PHPLineBreakpoint() { +// } +// +// public PHPLineBreakpoint(IResource resource, int lineNumber, int charStart, int charEnd, int hitCount, boolean add, Map attributes) throws DebugException { +// this(resource, lineNumber, charStart, charEnd, hitCount, add, attributes, PHP_LINE_BREAKPOINT); +// } +// +// public PHPLineBreakpoint(IResource resource, int lineNumber, int hitCount, boolean add, Map attributes) throws DebugException { +// this(resource, lineNumber, -1, -1, hitCount, add, attributes, PHP_LINE_BREAKPOINT); +// } + + + public static final String BREAKPOINT_ID ="XDebugLineBreakpointID"; + public XDebugLineBreakpoint() { } - + /** - * Constructs a line breakpoint on the given resource at the given line - * number. The line number is 1-based (i.e. the first line of a file is line - * number 1). + * Constructs a line breakpoint on the given resource at the given + * line number. The line number is 1-based (i.e. the first line of a + * file is line number 1). * - * @param resource - * file on which to set the breakpoint - * @param lineNumber - * 1-based line number of the breakpoint - * @throws CoreException - * if unable to create the breakpoint + * @param resource file on which to set the breakpoint + * @param lineNumber 1-based line number of the breakpoint + * @throws CoreException if unable to create the breakpoint */ - public XDebugLineBreakpoint(final IResource resource, final int lineNumber) - throws CoreException { - // IMarker marker = - // resource.createMarker("net.sourceforge.phpeclipse.xdebug.core.XDebugLineBreakpoint"); - // setMarker(marker); - // setEnabled(true); - // XDebugCorePlugin.log(IStatus.INFO,"Markertype: "+ marker.getType()); - // ensureMarker().setAttribute(IMarker.LINE_NUMBER, lineNumber); - // ensureMarker().setAttribute(IBreakpoint.ID, - // IXDebugConstants.ID_PHP_DEBUG_MODEL); - // ensureMarker().setAttribute(BREAKPOINT_ID,-1); - IWorkspaceRunnable wr = new IWorkspaceRunnable() { + public XDebugLineBreakpoint(final IResource resource, final int lineNumber) throws CoreException { +// IMarker marker = resource.createMarker("net.sourceforge.phpeclipse.xdebug.core.XDebugLineBreakpoint"); +// setMarker(marker); +// setEnabled(true); +// XDebugCorePlugin.log(IStatus.INFO,"Markertype: "+ marker.getType()); +// ensureMarker().setAttribute(IMarker.LINE_NUMBER, lineNumber); +// ensureMarker().setAttribute(IBreakpoint.ID, IXDebugConstants.ID_PHP_DEBUG_MODEL); +// ensureMarker().setAttribute(BREAKPOINT_ID,-1); + IWorkspaceRunnable wr= new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { - + // create the marker setMarker(resource.createMarker(XDEBUG_LINE_BREAKPOINT)); // add attributes Map attributes = new HashMap(10); - addLineBreakpointAttributes(attributes, getModelIdentifier(), - true, lineNumber, -1, -1); + addLineBreakpointAttributes(attributes, getModelIdentifier(), true, lineNumber, -1, -1); // set attributes ensureMarker().setAttributes(attributes); - + // add to breakpoint manager if requested - register(true); + register(true); } }; run(getMarkerRule(resource), wr); } - + protected void register(boolean register) throws CoreException { if (register) { DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(this); @@ -117,35 +108,34 @@ public class XDebugLineBreakpoint extends LineBreakpoint { setRegistered(false); } } - - public void addLineBreakpointAttributes(Map attributes, - String modelIdentifier, boolean enabled, int lineNumber, - int charStart, int charEnd) { + + public void addLineBreakpointAttributes(Map attributes, String modelIdentifier, boolean enabled, int lineNumber, int charStart, int charEnd) { attributes.put(IBreakpoint.ID, modelIdentifier); attributes.put(IBreakpoint.ENABLED, new Boolean(enabled)); attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber)); - if (charStart != -1) { + if (charStart!=-1) + { attributes.put(IMarker.CHAR_START, new Integer(charStart)); attributes.put(IMarker.CHAR_END, new Integer(charEnd)); } attributes.put(TYPE_NAME, "typeName"); - attributes.put(BREAKPOINT_ID, new Integer(-1)); - } + attributes.put(BREAKPOINT_ID,new Integer(-1)); + } - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IBreakpoint#getModelIdentifier() */ public String getModelIdentifier() { return IXDebugConstants.ID_PHP_DEBUG_MODEL; } - - public void setID(int id) throws CoreException { - ensureMarker().setAttribute(BREAKPOINT_ID, id); + + public void setID(int id) throws CoreException + { + ensureMarker().setAttribute(BREAKPOINT_ID,id); } - - public int getID() throws CoreException { - return ensureMarker().getAttribute(BREAKPOINT_ID, -1); + public int getID() throws CoreException + { + return ensureMarker().getAttribute(BREAKPOINT_ID,-1); } } diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugObjectValue.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugObjectValue.java index 2f3c66d..370e44d 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugObjectValue.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugObjectValue.java @@ -10,18 +10,18 @@ public class XDebugObjectValue extends XDebugAbstractValue { } public void setType(String typeName) { - fType = XDebugAbstractValue.VALUETYPE_OBJECT; - fTypeName = typeName; + fType=XDebugAbstractValue.VALUETYPE_OBJECT; + fTypeName=typeName; } public void renderValueString(String data) { - fValueString = data; + fValueString= data; } - + public String toString() { - return "class " + fValueString; + return "class "+fValueString; } public boolean verifyValue(String expression) { diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugResourceValue.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugResourceValue.java new file mode 100644 index 0000000..2ce4f1c --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugResourceValue.java @@ -0,0 +1,40 @@ +package net.sourceforge.phpeclipse.xdebug.php.model; + +import org.w3c.dom.Node; + +public class XDebugResourceValue extends XDebugAbstractValue { + private String fDataString; + + public XDebugResourceValue(XDebugVariable variable, Node varNode, String typeName) { + super(variable, varNode, typeName); + fDataString=null; + } + + public XDebugResourceValue(XDebugVariable variable, String typeName) { + super(variable, typeName); + fDataString=null; + } + + + public void setType(String typeName) { + fType = XDebugAbstractValue.VALUETYPE_RESOURCE; + fTypeName = typeName; + } + + public void renderValueString(String data) { + fDataString = data; + fValueString = "\""+data+"\""; + } + + public boolean supportsValueModification() { + return true; + } + + public String toString() { + return fDataString; + } + + public boolean verifyValue(String expression) { + return true; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStackFrame.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStackFrame.java index 575520d..1bc38bb 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStackFrame.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStackFrame.java @@ -6,361 +6,364 @@ */ package net.sourceforge.phpeclipse.xdebug.php.model; -import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils; -import net.sourceforge.phpeclipse.xdebug.core.DebugConnection.DebugResponse; +//import java.net.MalformedURLException; +import java.net.URL; -import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IRegisterGroup; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IVariable; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; +//import net.sourceforge.phpeclipse.xdebug.core.IDebugConnection; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; /** + * @author PHPeclipse team * @author Axel - * - * TODO To change the template for this generated type comment go to Window - - * Preferences - Java - Code Style - Code Templates + * */ -public class XDebugStackFrame extends XDebugElement implements IStackFrame { - +public class XDebugStackFrame extends XDebugElement implements IStackFrame { private XDebugThread fThread; - // private String fName; - private int fLineNo; - - private String fFileName; - private int fId; - - private IVariable[] fVariables; - - private String fLevel; - + + //private IPath fName; + + private URL fName; + + private int fLineNumber; + private int fLevel; private String fType; - private String fWhere; + private IVariable[] fVariables; + + private int fStepCount = 0; + //private int fCurrentStepCount = 0; + /** - * Constructs a stack frame in the given thread with the given frame data. + * Constructs a stack frame in the given thread with the given + * frame data. * * @param thread - * @param data - * frame data - * @param id - * stack frame id (0 is the bottom of the stack) + * @param data frame data + * @param id stack frame id (0 is the bottom of the stack) */ - public XDebugStackFrame(XDebugThread thread, Node stackNode, int id) { - super((XDebugTarget) thread.getDebugTarget()); + public XDebugStackFrame(XDebugThread thread, int id) { + super(thread == null ? null : (XDebugTarget) thread.getDebugTarget()); fId = id; fThread = thread; - init(stackNode); } - - /** - * Initializes this frame based on its data - * - * @param data - */ - private void init(Node stackNode) { - - fLevel = PHPDebugUtils.getAttributeValue(stackNode, "level"); - fType = PHPDebugUtils.getAttributeValue(stackNode, "type"); - String fileName = PHPDebugUtils.unescapeString(PHPDebugUtils - .getAttributeValue(stackNode, "filename")); - String lineNo = PHPDebugUtils.getAttributeValue(stackNode, "lineno"); - - if (lineNo != "") - fLineNo = Integer.parseInt(lineNo); - - fWhere = PHPDebugUtils.getAttributeValue(stackNode, "where"); - - fFileName = (new Path(fileName)).lastSegment(); - int id = -1; - try { - id = ((XDebugTarget) getDebugTarget()).sendRequest("context_get", - "-d " + fLevel); - } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - DebugResponse response = ((XDebugTarget) getDebugTarget()) - .getResponse(id); - Node responseNode = response.getParentNode(); - NodeList property = responseNode.getChildNodes(); - fVariables = new IVariable[property.getLength()]; - for (int i = 0; i < property.getLength(); i++) { - Node propertyNode = property.item(i); - fVariables[i] = new XDebugVariable(this, propertyNode); - } - - // int numVars = strings.length - 3; - // fVariables = new IVariable[numVars]; - // for (int i = 0; i < numVars; i++) { - // fVariables[i] = new XDebugVariable(this, strings[i + 3]); - // } + + public void incrementStepCounter() { + fStepCount++; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getThread() */ public IThread getThread() { return fThread; } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#getVariables() - */ + public IVariable[] getVariables() throws DebugException { + if (fVariables == null) { + fVariables = fTarget.getVariables(this, fLevel); + } + return fVariables; } - - /* - * (non-Javadoc) - * + + public void evaluateChange(IStackFrame OldStackFrame) throws DebugException { + IVariable[] OldVariable = ((XDebugStackFrame) OldStackFrame).getVariables(); + for (int i = 0; i < fVariables.length; i++) { + ((XDebugVariable) fVariables[i]).setChange(OldVariable[i]); + } + } + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#hasVariables() */ public boolean hasVariables() throws DebugException { - return fVariables.length > 0; + /*return fVariables.length > 0;*/ + return true; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber() */ public int getLineNumber() throws DebugException { - return fLineNo; + return fLineNumber; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getCharStart() */ public int getCharStart() throws DebugException { return -1; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd() */ public int getCharEnd() throws DebugException { return -1; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc)fName * @see org.eclipse.debug.core.model.IStackFrame#getName() */ public String getName() throws DebugException { - return fFileName + "::" + fWhere + " : lineno " + fLineNo; + //String a = fName.getFile(); + //return fName.lastSegment().toString()+"::"+fWhere+ " line: "+ fLineNumber; + return fName.toString()+"::"+fWhere+ " line: "+ fLineNumber; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups() */ public IRegisterGroup[] getRegisterGroups() throws DebugException { return null; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups() */ public boolean hasRegisterGroups() throws DebugException { return false; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#canStepInto() */ public boolean canStepInto() { - return getThread().canStepInto(); + return fThread.canStepInto(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#canStepOver() */ public boolean canStepOver() { - return getThread().canStepOver(); + return fThread.canStepOver(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#canStepReturn() */ public boolean canStepReturn() { - return getThread().canStepReturn(); + return fThread.canStepReturn(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#isStepping() */ public boolean isStepping() { - return getThread().isStepping(); + return fThread.isStepping(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#stepInto() */ public void stepInto() throws DebugException { - getThread().stepInto(); + fThread.stepInto(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#stepOver() */ public void stepOver() throws DebugException { - getThread().stepOver(); + fThread.stepOver(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#stepReturn() */ public void stepReturn() throws DebugException { - getThread().stepReturn(); + fThread.stepReturn(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#canResume() */ public boolean canResume() { - return getThread().canResume(); + return fThread.canResume(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() */ public boolean canSuspend() { - return getThread().canSuspend(); + return fThread.canSuspend(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() */ public boolean isSuspended() { - return getThread().isSuspended(); + return fThread.isSuspended(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#resume() */ public void resume() throws DebugException { - getThread().resume(); + fThread.resume(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#suspend() */ public void suspend() throws DebugException { - getThread().suspend(); + fThread.suspend(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#canTerminate() */ public boolean canTerminate() { - return getThread().canTerminate(); + return fThread.canTerminate(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#isTerminated() */ public boolean isTerminated() { - return getThread().isTerminated(); + return fThread.isTerminated(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#terminate() */ public void terminate() throws DebugException { - getThread().terminate(); + fThread.terminate(); } - + /** - * Returns the name of the source file this stack frame is associated with. + * Returns the name of the source file this stack frame is associated + * with. * - * @return the name of the source file this stack frame is associated with + * @return the name of the source file this stack frame is associated + * with. If the file associated with this frame does not exists, it returns null. */ public String getSourceName() { - return fFileName; + if (fName == null) { + return null; + } + IPath a = new Path(fName.getFile()); + return a.lastSegment(); } - /* - * (non-Javadoc) - * + public boolean isSameStackFrame(Object obj) { + boolean isSameStackFrame = false; + + if (obj instanceof XDebugStackFrame) { + XDebugStackFrame sf = (XDebugStackFrame)obj; + //try { + isSameStackFrame = sf.getSourceName().equals(getSourceName()) && + /*sf.getLineNumber() == getLineNumber() &&*/ + /*sf.getLevel() == getLevel() &&*/ + sf.getType().equals(getType()) && + sf.getWhere().equals(getWhere()); //&& + /*sf.fId == fId;*/ + /*} catch (DebugException e) { + }*/ + } + + return isSameStackFrame; + } + + /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (obj instanceof XDebugStackFrame) { - XDebugStackFrame sf = (XDebugStackFrame) obj; + XDebugStackFrame sf = (XDebugStackFrame)obj; try { - return sf.getSourceName().equals(getSourceName()) - && sf.getLineNumber() == getLineNumber() - && sf.fId == fId; + return sf.getSourceName().equals(getSourceName()) && + sf.getLineNumber() == getLineNumber() && + sf.getLevel() == getLevel() && + sf.getType().equals(getType()) && + sf.getWhere().equals(getWhere()); +/* sf.getType() == getType() && + sf.getWhere() == getWhere() &&*/ + /*sf.fId == fId;*/ } catch (DebugException e) { } } + return false; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equalsOld(Object obj) { + if (obj instanceof XDebugStackFrame) { + XDebugStackFrame sf = (XDebugStackFrame)obj; + try { + return sf.getSourceName().equals(getSourceName()) && + sf.getLineNumber() == getLineNumber() && + sf.fId == fId; + } catch (DebugException e) { + } + } + return false; + } + + /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { - return getSourceName().hashCode() + fId; +// return getSourceName().hashCode() + fId; + return getSourceName().hashCode() + fLevel; } - + /** - * Returns this stack frame's unique identifier within its thread * * @return this stack frame's unique identifier within its thread */ protected int getIdentifier() { return fId; } -} + + + public void setFullName(URL name) { + fName = name; + } + + + public URL getFullName() { + return fName; + } + + + public int getLevel() { + return fLevel; + } + + public void setLevel(int level) { + fLevel = level; + fId = level; + } + + public String getType() { + return fType; + } + + public void setType(String type) { + fType = type; + } + + public String getWhere() { + return fWhere; + } + + public void setWhere(String where) { + fWhere = where; + } + + public void setLineNumber(int newlineNumber) { + fLineNumber = newlineNumber; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStringValue.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStringValue.java index b2d0231..17168e3 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStringValue.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStringValue.java @@ -5,28 +5,34 @@ import org.w3c.dom.Node; public class XDebugStringValue extends XDebugAbstractValue { private String fDataString; - public XDebugStringValue(XDebugVariable variable, Node varNode, String typeName) { super(variable, varNode, typeName); - fDataString = null; + fDataString=null; + } + + public XDebugStringValue(XDebugVariable variable, String typeName) { + super(variable, typeName); + fDataString=null; } + public void setType(String typeName) { - fType = XDebugAbstractValue.VALUETYPE_STRING; - fTypeName = typeName; + fType=XDebugAbstractValue.VALUETYPE_STRING; + fTypeName=typeName; } public void renderValueString(String data) { - fDataString = data; - fValueString = "\"" + data + "\""; + fDataString=data; + fValueString="\""+data+"\""; } public boolean supportsValueModification() { return true; } + public String toString() { return fDataString; } diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugTarget.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugTarget.java index 04099c4..9f31828 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugTarget.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugTarget.java @@ -3,394 +3,419 @@ */ package net.sourceforge.phpeclipse.xdebug.php.model; -import net.sourceforge.phpeclipse.xdebug.core.Base64; -import net.sourceforge.phpeclipse.xdebug.core.DebugConnection; -import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils; +import java.util.List; + +import net.sourceforge.phpeclipse.xdebug.core.AbstractDebugConnection; +import net.sourceforge.phpeclipse.xdebug.core.IDebugConnection; +import net.sourceforge.phpeclipse.xdebug.core.IPHPDebugEvent; +import net.sourceforge.phpeclipse.xdebug.core.IProxyEventListener; +import net.sourceforge.phpeclipse.xdebug.core.PathMapItem; import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; -import net.sourceforge.phpeclipse.xdebug.core.DebugConnection.DebugResponse; +import net.sourceforge.phpeclipse.xdebug.core.XDebugProxy; import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarkerDelta; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IDebugEventSetListener; import org.eclipse.debug.core.ILaunch; + +import org.eclipse.debug.core.ILaunchListener; + import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.ILineBreakpoint; import org.eclipse.debug.core.model.IMemoryBlock; import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IValue; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; +import org.eclipse.debug.core.model.IVariable; + +import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse; /** * @author Christian - * + * */ -public class XDebugTarget extends XDebugElement implements IDebugTarget, - IDebugEventSetListener { +public class XDebugTarget extends XDebugElement implements IDebugTarget, ILaunchListener, IDebugEventSetListener, IProxyEventListener{ // associated system process (VM) private IProcess fProcess; - + // containing launch object private ILaunch fLaunch; - + // debugPort private int fDebugPort; - - // program name - // private String fName; - + // suspend state - private boolean fSuspended = true; - + private boolean fSuspended = false; + // terminated state private boolean fTerminated = false; - + // threads private XDebugThread fThread; - private IThread[] fThreads; + + private AbstractDebugConnection fDebugConnection; - // event dispatch job - // private EventDispatchJob fEventDispatch; + private String fIdeKey; - private DebugConnection fDebugConnection; - // private DebugResponse lastResponse; + public XDebugTarget() { + super(null); + } /** - * Constructs a new debug target in the given launch for the associated PDA - * VM process. + * Constructs a new debug target in the given launch and waits until + * someone with the ideKey connects to the Debugproxy + * * - * @param launch - * containing launch - * @param debugPort - * port to read events from - * @exception CoreException - * if unable to connect to host - */ - public XDebugTarget(ILaunch launch, IProcess process, int debugPort) - throws CoreException { + * @param launch containing launch + * @param process process of the interpreter + * @param ideKey + * @exception CoreException if unable to connect to host + */ + + public XDebugTarget(ILaunch launch, IProcess process, String ideKey) throws CoreException { + init(launch, process, ideKey); + } + + /** + * Constructs a new debug target in the given launch and waits until + * someone with the ideKey connects to the Debugproxy + * + * + * @param launch containing launch + * @param process process of the interpreter + * @param ideKey + * @param pathMap Pathmap for the debug session + * @exception CoreException if unable to connect to host + */ + + /*public XDebugTarget(ILaunch launch, IProcess process, String ideKey, List pathMap) throws CoreException { super(null); + init(launch, process, ideKey,pathMap); + }*/ + + private void init(ILaunch launch, IProcess process, String ideKey/*,List pathMap*/) { fLaunch = launch; fProcess = process; fTarget = this; - fDebugConnection = new DebugConnection(this, debugPort); - fThread = new XDebugThread(this); - fThreads = new IThread[] { fThread }; - DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener( - this); + fDebugConnection = null; + fThread = null; + fThreads = new IThread[0]; + fIdeKey = ideKey; + + XDebugProxy proxy = XDebugCorePlugin.getDefault().getXDebugProxy(); + proxy.addProxyEventListener(this,ideKey); + if (!proxy.isRunning()) + proxy.start(); + + proxy.setTarget(this); + + fDebugPort = proxy.getProxyPort(); + + DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); DebugPlugin.getDefault().addDebugEventListener(this); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugTarget#getProcess() */ public IProcess getProcess() { return fProcess; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugTarget#getThreads() */ public IThread[] getThreads() throws DebugException { return fThreads; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugTarget#hasThreads() */ public boolean hasThreads() throws DebugException { - return (fThreads.length > 0); + return (fThreads.length>0); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugTarget#getName() */ public String getName() throws DebugException { return "PHP XDebug Client at localhost:" + fDebugPort; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugTarget#supportsBreakpoint(org.eclipse.debug.core.model.IBreakpoint) */ public boolean supportsBreakpoint(IBreakpoint breakpoint) { - if (breakpoint.getModelIdentifier().equals( - IXDebugConstants.ID_PHP_DEBUG_MODEL)) { + if (breakpoint.getModelIdentifier().equals(IXDebugConstants.ID_PHP_DEBUG_MODEL)) { return true; } return false; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget() */ public IDebugTarget getDebugTarget() { return this; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDebugElement#getLaunch() */ public ILaunch getLaunch() { return fLaunch; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#canTerminate() */ public boolean canTerminate() { - return getProcess().canTerminate(); - // return false; + if (getProcess()!=null) // ther is no running Process in remote debugging + return getProcess().canTerminate(); + return true; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#isTerminated() */ public boolean isTerminated() { - // return getProcess().isTerminated(); +// return getProcess().isTerminated(); return fTerminated; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#terminate() */ public void terminate() throws DebugException { - fDebugConnection.sendRequest("stop"); + //IThread t = fThreads.length(); + //fTerminated=true; + XDebugProxy proxy=XDebugCorePlugin.getDefault().getXDebugProxy(); + proxy.stop(); + proxy.removeProxyEventListener(this,fIdeKey); + System.out.println("XDebug.Target: ProxyEventlistener removed"); + fTerminated = true; + //fDisconnected = true; + fSuspended = false; + XDebugCorePlugin.getBreakpointManager().removeBreakpointListener(this); + fireTerminateEvent(); + DebugPlugin.getDefault().removeDebugEventListener(this); + if (fThread!=null) + fThread.removeEventListeners(); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#canResume() */ public boolean canResume() { - return !isTerminated() && isSuspended(); +// return !isTerminated() && isSuspended(); + return false; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() */ public boolean canSuspend() { - return !isTerminated() && !isSuspended(); +// return !isTerminated() && !isSuspended(); + return false; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() */ public boolean isSuspended() { return fSuspended; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#resume() */ public void resume() throws DebugException { - fDebugConnection.sendRequest("run"); + if (fDebugConnection != null) { + fThread.setBreakpoints(null); + fDebugConnection.run(); + } } - + /** * Notification the target has resumed for the given reason * - * @param detail - * reason for the resume + * @param detail reason for the resume */ private void resumed(int detail) { fSuspended = false; fThread.fireResumeEvent(detail); } - + /** * Notification the target has suspended for the given reason * - * @param detail - * reason for the suspend + * @param detail reason for the suspend */ public void suspended(int detail) { fSuspended = true; fThread.fireSuspendEvent(detail); - } - - /* - * (non-Javadoc) - * + } + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#suspend() */ public void suspend() throws DebugException { } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.IBreakpointListener#breakpointAdded(org.eclipse.debug.core.model.IBreakpoint) */ public void breakpointAdded(IBreakpoint breakpoint) { + IMarker marker = breakpoint.getMarker(); + IPath path = marker.getResource().getLocation(); + IPath cp = path.removeLastSegments(1); + List pathMap = null; + try { + pathMap = fLaunch.getLaunchConfiguration().getAttribute(IXDebugConstants.ATTR_PHP_PATHMAP,(List)null); + } catch (CoreException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } - if (supportsBreakpoint(breakpoint)) { - try { - if (breakpoint.isEnabled()) { - IMarker marker = breakpoint.getMarker(); - if (marker != null) { - try { - String fileName = PHPDebugUtils.escapeString(marker - .getResource().getLocation().toString()); - String arg = "-t line -f file:///" - + fileName - + " -n " - + ((ILineBreakpoint) breakpoint) - .getLineNumber(); - int id = fDebugConnection.sendRequest( - "breakpoint_set", arg); - // set the marker Attribute to make later - // idetification possible - // TODO: make sure that attribute is set before - // response from debugger is beeing prosessed - marker.setAttribute( - XDebugLineBreakpoint.BREAKPOINT_ID, id); - - } catch (CoreException e) { + if (!fDebugConnection.isClosed()) { + if (fProcess == null) { + PathMapItem pmi = null; + for (int i = 0; i < pathMap.size(); i++) { + pmi = new PathMapItem((String) pathMap.get(i)); + IPath local = (IPath)pmi.getLocalPath().clone(); + local = local./*removeFirstSegments(1).*/makeAbsolute(); + int matchedSegments = local.segmentCount(); + if (local.matchingFirstSegments(cp) == matchedSegments) { + IPath newPath = pmi.getRemotePath(); + //newPath = newPath.removeFirstSegments(1); + newPath = newPath.append(path.removeFirstSegments(matchedSegments)); + newPath = newPath.makeAbsolute(); + if (supportsBreakpoint(breakpoint)) { + try { + fDebugConnection.addBreakpoint(breakpoint, newPath); + } catch (DebugException e) { + e.printStackTrace(); + } } } + } + } else { + if (supportsBreakpoint(breakpoint)) { + try { + fDebugConnection.addBreakpoint(breakpoint, path); + } catch (DebugException e) { + e.printStackTrace(); + } } - } catch (CoreException e) { - } } } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.IBreakpointListener#breakpointRemoved(org.eclipse.debug.core.model.IBreakpoint, - * org.eclipse.core.resources.IMarkerDelta) + + /* (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 (supportsBreakpoint(breakpoint)) { try { - int id = ((XDebugLineBreakpoint) breakpoint).getID(); - if (id > 0) - fDebugConnection.sendRequest("breakpoint_remove", "-d " - + id); + fDebugConnection.removeBreakpoint(breakpoint); } catch (CoreException e) { } } } - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse.debug.core.model.IBreakpoint, - * org.eclipse.core.resources.IMarkerDelta) + /* (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 (supportsBreakpoint(breakpoint)) { - // try { - // if (breakpoint.isEnabled()) { - // breakpointAdded(breakpoint); - // } else { - // breakpointRemoved(breakpoint, null); - // } - // } catch (CoreException e) { - // } - // } - } - - /* - * (non-Javadoc) - * +// if (supportsBreakpoint(breakpoint)) { +// try { +// if (breakpoint.isEnabled()) { +// breakpointAdded(breakpoint); +// } else { +// breakpointRemoved(breakpoint, null); +// } +// } catch (CoreException e) { +// } +// } + } + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDisconnect#canDisconnect() */ public boolean canDisconnect() { return false; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDisconnect#disconnect() */ public void disconnect() throws DebugException { } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IDisconnect#isDisconnected() */ public boolean isDisconnected() { - return false; + return (fDebugConnection==null); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#supportsStorageRetrieval() */ public boolean supportsStorageRetrieval() { return false; } - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#getMemoryBlock(long, - * long) + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#getMemoryBlock(long, long) */ - public IMemoryBlock getMemoryBlock(long startAddress, long length) - throws DebugException { + public IMemoryBlock getMemoryBlock(long startAddress, long length) throws DebugException { return null; } /** - * Notification we have connected to the PHP debugger and it has started. + * Notification we have connected to the PHP debugger and it has been started. * Resume the the debugger. */ - public void started() { - + public void started() throws DebugException { fThread.setBreakpoints(null); fThread.setStepping(false); + /*boolean CanDisconnect =*/ Integer.parseInt(fDebugConnection.featureGet("detach").getValue()) /*!= 0*/; + + System.out.println("in Target.started()"); + DebugResponse response = fDebugConnection.featureGet("max_children"); + String a1 = response.getValue(); + System.out.println("max children:"+a1); + DebugResponse response1 = fDebugConnection.featureGet("max_children"); + String a2 = response1.getValue(); + System.out.println("max depth:"+a2); + + + boolean res = fDebugConnection.featureSet("max_depth", "100" ); + if( res == true ) { + System.out.println("Set depth to 100 (hack)"); + } + installDeferredBreakpoints(); try { resume(); - // step(); +// step(); } catch (DebugException e) { + e.printStackTrace(); } } - + /** * Install breakpoints that are already registered with the breakpoint * manager. @@ -401,7 +426,7 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, breakpointAdded(breakpoints[i]); } } - + /** * Called when this debug target terminates. */ @@ -411,228 +436,181 @@ public class XDebugTarget extends XDebugElement implements IDebugTarget, XDebugCorePlugin.getBreakpointManager().removeBreakpointListener(this); fireTerminateEvent(); DebugPlugin.getDefault().removeDebugEventListener(this); - fThread.removeEventListeners(); + fThread.removeEventListeners(); } - + /** * Returns the current stack frames in the target. * * @return the current stack frames in the target - * @throws DebugException - * if unable to perform the request + * @throws DebugException if unable to perform the request */ protected IStackFrame[] getStackFrames() throws DebugException { - int id = fDebugConnection.sendRequest("stack_get"); - DebugResponse lastResponse = fDebugConnection.waitforTransID(id); - if (lastResponse.isError()) - return new IStackFrame[0]; - Node response = lastResponse.getParentNode(); - NodeList frames = response.getChildNodes(); - IStackFrame[] theFrames = new IStackFrame[frames.getLength()]; - for (int i = 0; i < frames.getLength(); i++) { - Node stackNode = frames.item(i); - theFrames[i] = new XDebugStackFrame(fThread, stackNode, i); - } - return theFrames; + return fDebugConnection.getStackFrames(fThread); } - + /** * Single step the interpreter. * - * @throws DebugException - * if the request fails + * @throws DebugException if the request fails */ protected void step_over() throws DebugException { fThread.setStepping(true); resumed(DebugEvent.STEP_OVER); - fDebugConnection.sendRequest("step_over"); + fDebugConnection.stepOver(); } - + /** * Single step the interpreter. * - * @throws DebugException - * if the request fails + * @throws DebugException if the request fails */ protected void step_into() throws DebugException { fThread.setStepping(true); resumed(DebugEvent.STEP_INTO); - fDebugConnection.sendRequest("step_into"); + fDebugConnection.stepInto(); } - + /** * Single step the interpreter. * - * @throws DebugException - * if the request fails + * @throws DebugException if the request fails */ protected void step_out() throws DebugException { fThread.setStepping(true); resumed(DebugEvent.STEP_RETURN); - fDebugConnection.sendRequest("step_out"); + fDebugConnection.stepOut(); } - + /** * Returns the current value of the given variable. * * @param variable * @return variable value - * @throws DebugException - * if the request fails - */ - protected IValue getVariableValue(XDebugVariable variable) - throws DebugException { - // synchronized (fDebugSocket) { - // fDebugConnection.sendRequest("var","" + - // variable.getStackFrame().getIdentifier() + " " + variable.getName()); - // try { - // String value = fDebugReader.readLine(); - // //return new XDebugValue(this, value); - // - // } catch (IOException e) { - // abort(MessageFormat.format("Unable to retrieve value for variable - // {0}", new String[]{variable.getName()}), e); - // } - // } + * @throws DebugException if the request fails + */ + protected IValue getVariableValue(XDebugVariable variable) throws DebugException { return null; } - + /** * Returns the values on the data stack (top down) * * @return the values on the data stack (top down) */ public IValue[] getDataStack() throws DebugException { - // synchronized (fDebugSocket) { - // fDebugConnection.sendRequest ("data"); - // try { - // String valueString = fDebugReader.readLine(); - // if (valueString != null && valueString.length() > 0) { - // String[] values = valueString.split("\\|"); - // IValue[] theValues = new IValue[values.length]; - // for (int i = 0; i < values.length; i++) { - // String value = values[values.length - i - 1]; - // // theValues[i] = new XDebugValue(this, value); - // } - // return theValues; - // } - // } catch (IOException e) { - // abort("Unable to retrieve data stack", e); - // } - // } - return new IValue[0]; + return new IValue[0]; } - + public boolean setVarValue(String name, String value) { - int id = -1; - String str = Base64.encodeBytes(value.getBytes()); - int len = str.length(); - - try { - id = fDebugConnection.sendRequest("property_set", "-n " + name - + " -l " + len + " -- " + str); - } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + return fDebugConnection.setVarValue(name,value); + } + + public void handleDebugEvents(DebugEvent[] events) { + for (int i=0;inull if none. - */ - - private IStackFrame[] fStackFrames = null; - +public class XDebugThread extends XDebugElement implements IThread, IDebugEventSetListener { + private IStackFrame[] fStackFrames; + private IBreakpoint[] fBreakpoints; - - /** - * Whether this thread is stepping - */ + + /* Whether this thread is stepping */ private boolean fStepping = false; - + private boolean fTerminated = false; + + private int fStepCount = 0; + private int fCurrentStepCount = 0; + /** * Constructs a new thread for the given target * - * @param target - * VM + * @param target VM */ public XDebugThread(XDebugTarget target) { super(target); DebugPlugin.getDefault().addDebugEventListener(this); + fStackFrames = null; } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IThread#getStackFrames() - */ + + public void incrementStepCounter() { + fStepCount++; + } + public IStackFrame[] getStackFrames() throws DebugException { - if (isSuspended()) { - if (fStackFrames == null) { - // XDebugCorePlugin.log(IStatus.INFO,"vor getStackFrames"); - fStackFrames = ((XDebugTarget) getDebugTarget()) - .getStackFrames(); - // XDebugCorePlugin.log(IStatus.INFO,"nach getStackFrames"); + IStackFrame[] newStackFrames = null; + + if (isSuspended()) { + if (fStepCount > fCurrentStepCount) { + newStackFrames = ((XDebugTarget) getDebugTarget()).getStackFrames(); + + for (int i = 0; i < newStackFrames.length; i++) { + ((XDebugStackFrame)newStackFrames[i]).getVariables(); + } + + if (fStackFrames != null) { + if (newStackFrames.length >= fStackFrames.length) { + int delta = newStackFrames.length - fStackFrames.length + 1; + + for (int i = fStackFrames.length - 1; i >= 0; i--) { + if (((XDebugStackFrame) fStackFrames[i]).equals(((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]))) { + int b = 2; b++; + //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]); + } else if (((XDebugStackFrame) fStackFrames[i]).isSameStackFrame(newStackFrames[newStackFrames.length - delta])) { + //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]); + } + + delta ++; + } + } else { + } + } + + fCurrentStepCount++; + + fStackFrames = newStackFrames; } return fStackFrames; } else { return new IStackFrame[0]; } } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IThread#hasStackFrames() */ public boolean hasStackFrames() throws DebugException { return isSuspended(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IThread#getPriority() */ public int getPriority() throws DebugException { return 0; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IThread#getTopStackFrame() */ public IStackFrame getTopStackFrame() throws DebugException { @@ -94,24 +108,18 @@ public class XDebugThread extends XDebugElement implements IThread, if (frames.length > 0) { return frames[0]; } + return null; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IThread#getName() */ public String getName() throws DebugException { - // if (fStackFrames!=null) - // return fStackFrames[0].getName(); - // else return "Thread[1]"; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IThread#getBreakpoints() */ public IBreakpoint[] getBreakpoints() { @@ -120,171 +128,140 @@ public class XDebugThread extends XDebugElement implements IThread, } return fBreakpoints; } - + /** * Sets the breakpoints this thread is suspended at, or null * if none. * - * @param breakpoints - * the breakpoints this thread is suspended at, or - * null if none + * @param breakpoints the breakpoints this thread is suspended at, or null + * if none */ protected void setBreakpoints(IBreakpoint[] breakpoints) { fBreakpoints = breakpoints; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#canResume() */ public boolean canResume() { return isSuspended(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() */ public boolean canSuspend() { - return !isSuspended(); + return !isTerminated() && !isSuspended(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() */ public boolean isSuspended() { - return getDebugTarget().isSuspended(); + return fTarget.isSuspended(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#resume() */ public void resume() throws DebugException { - fStackFrames = null; - fBreakpoints = null; - getDebugTarget().resume(); + fBreakpoints=null; + fTarget.resume(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ISuspendResume#suspend() */ public void suspend() throws DebugException { - getDebugTarget().suspend(); + fTarget.suspend(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#canStepInto() */ public boolean canStepInto() { return isSuspended(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#canStepOver() */ public boolean canStepOver() { return isSuspended(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#canStepReturn() */ public boolean canStepReturn() { - if (fStackFrames != null) + if (fStackFrames != null) { return (fStackFrames.length > 1); - else + } else { return false; + } } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#isStepping() */ public boolean isStepping() { return fStepping; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#stepInto() */ public void stepInto() throws DebugException { - fStackFrames = null; - fBreakpoints = null; - ((XDebugTarget) getDebugTarget()).step_into(); + fBreakpoints=null; + fTarget.step_into(); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#stepOver() */ public void stepOver() throws DebugException { - fStackFrames = null; - fBreakpoints = null; - ((XDebugTarget) getDebugTarget()).step_over(); + fBreakpoints=null; + fTarget.step_over(); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IStep#stepReturn() */ public void stepReturn() throws DebugException { - fStackFrames = null; - fBreakpoints = null; - ((XDebugTarget) getDebugTarget()).step_out(); - + fBreakpoints=null; + fTarget.step_out(); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#canTerminate() */ public boolean canTerminate() { return !isTerminated(); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#isTerminated() */ public boolean isTerminated() { - return getDebugTarget().isTerminated(); + return fTerminated; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.ITerminate#terminate() */ public void terminate() throws DebugException { - getDebugTarget().terminate(); + fTarget.getDebugConnection().stop(); + fTerminated = true; + } + + public void terminated() throws DebugException { + fTerminated = true; } /** * Sets whether this thread is stepping * - * @param stepping - * whether stepping + * @param stepping whether stepping */ protected void setStepping(boolean stepping) { fStepping = stepping; @@ -292,12 +269,10 @@ public class XDebugThread extends XDebugElement implements IThread, public void handleDebugEvents(DebugEvent[] events) { DebugEvent de = events[0]; - System.out.println(de.toString()); - + System.out.println(de.toString()); } public void removeEventListeners() { DebugPlugin.getDefault().removeDebugEventListener(this); - } -} +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugValue.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugValue.java index 72a1e70..62f9347 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugValue.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugValue.java @@ -7,19 +7,28 @@ public class XDebugValue extends XDebugAbstractValue { public XDebugValue(XDebugVariable variable, Node varNode, String typeName) { super(variable, varNode, typeName); // TODO Auto-generated constructor stub + fValueString="uninitialized"; + fType=XDebugAbstractValue.VALUETYPE_UNINITIALIZED; + fTypeName="unknown"; + } + + public XDebugValue(XDebugVariable variable, String typeName) { + super(variable, typeName); + fValueString="uninitialized"; + fType=XDebugAbstractValue.VALUETYPE_UNINITIALIZED; + fTypeName="unknown"; - public void setType(String typeName) { - fType = XDebugAbstractValue.VALUETYPE_UNINITIALIZED; - fTypeName = "unknown"; } + + public void setType(String typeName) { + } + public void renderValueString(String data) { - fValueString = "uninitialized"; } public boolean verifyValue(String expression) { - // TODO Auto-generated method stub return false; } diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugVariable.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugVariable.java index 21663d3..969c718 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugVariable.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugVariable.java @@ -7,130 +7,138 @@ package net.sourceforge.phpeclipse.xdebug.php.model; import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils; - -import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IVariable; import org.w3c.dom.Node; /** * @author Axel - * - * TODO To change the template for this generated type comment go to Window - - * Preferences - Java - Code Style - Code Templates + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates */ -public class XDebugVariable extends XDebugElement implements IVariable { - +public class XDebugVariable extends XDebugElement implements IVariable { public static final int VARTYPE_UNKNOWN = -1; - public static final int VARTYPE_UNINITIALIZED = 0; - public static final int VARTYPE_STRING = 1; - public static final int VARTYPE_INT = 2; - public static final int VARTYPE_FLOAT = 3; - public static final int VARTYPE_ARRAY = 8; - public static final int VARTYPE_HASH = 9; - public static final int VARTYPE_OBJECT = 10; - + public static final int VARTYPE_RESOURCE = 11; + // name & stack frmae private String fName; - private XDebugStackFrame fFrame; - private String fFullName; - - // private String fTypeName; - // private int fType; private XDebugAbstractValue fValue; - private String fEncoding; - private int fNumChildren; - - // private Node fVariableNode; - + /** - * Constructs a variable contained in the given stack frame with the given - * name. + * Constructs a variable contained in the given stack frame + * with the given name. * - * @param frame - * owning stack frame - * @param name - * variable name + * @param frame owning stack frame + * @param name variable name */ + public XDebugVariable( String typeName, String fullname ) { + fFullName = fullname; + fName = fullname; + if (typeName.equals("int") ) + fValue= new XDebugIntValue(this,typeName); + else if (typeName.equals("float") ) + fValue= new XDebugFloatValue(this,typeName); + else if (typeName.equals("bool") ) + fValue= new XDebugBooleanValue(this,typeName); + else if (typeName.equals("string") ) + fValue= new XDebugStringValue(this,typeName); + else if (typeName.equals("array") ) + fValue= new XDebugArrayValue(this,typeName); + else if (typeName.equals("hash") ) + fValue= new XDebugArrayValue(this,typeName); + else if (typeName.equals("object") ) + fValue= new XDebugArrayValue(this,typeName); + else if (typeName.equals("resource") ) + fValue= new XDebugResourceValue(this,typeName); + else + fValue= new XDebugValue(this,typeName); + } + public XDebugVariable(XDebugStackFrame frame, Node property) { super((XDebugTarget) frame.getDebugTarget()); fFrame = frame; init(property); - } - - private void init(Node property) { - fFullName = PHPDebugUtils.getAttributeValue(property, "fullname"); - fName = PHPDebugUtils.getAttributeValue(property, "name"); - fEncoding = PHPDebugUtils.getAttributeValue(property, "encoding"); - if (PHPDebugUtils.getAttributeValue(property, "numchildren").equals("")) + + public XDebugVariable(XDebugStackFrame frame, String fullname, String name, String typeName) { + super((XDebugTarget) frame.getDebugTarget()); + fFrame = frame; + fFullName = fullname; + fName = name; + if (typeName.equals("int") ) + fValue= new XDebugIntValue(this,typeName); + else if (typeName.equals("float") ) + fValue= new XDebugFloatValue(this,typeName); + else if (typeName.equals("bool") ) + fValue= new XDebugBooleanValue(this,typeName); + else if (typeName.equals("string") ) + fValue= new XDebugStringValue(this,typeName); + else if (typeName.equals("array") ) + fValue= new XDebugArrayValue(this,typeName); + else if (typeName.equals("hash") ) + fValue= new XDebugArrayValue(this,typeName); + else if (typeName.equals("object") ) + fValue= new XDebugArrayValue(this,typeName); + else if (typeName.equals("resource") ) + fValue= new XDebugResourceValue(this,typeName); + else + fValue= new XDebugValue(this,typeName); + } + + private void init(Node property) { + fFullName=PHPDebugUtils.getAttributeValue(property,"fullname"); + fName=PHPDebugUtils.getAttributeValue(property,"name"); + fEncoding=PHPDebugUtils.getAttributeValue(property,"encoding"); + if (PHPDebugUtils.getAttributeValue(property,"numchildren").equals("")) fNumChildren = 0; else - fNumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue( - property, "numchildren")); - - String typeName = PHPDebugUtils.getAttributeValue(property, "type"); - - // if (typeName.equals("uninitialized") ) - // fValue= new XDebugValue(this,property,typeName); - if (typeName.equals("int")) - fValue = new XDebugIntValue(this, property, typeName); - else if (typeName.equals("float")) - fValue = new XDebugFloatValue(this, property, typeName); - else if (typeName.equals("bool")) - fValue = new XDebugBooleanValue(this, property, typeName); - else if (typeName.equals("string")) - fValue = new XDebugStringValue(this, property, typeName); - else if (typeName.equals("array")) - fValue = new XDebugArrayValue(this, property, typeName); - else if (typeName.equals("hash")) - fValue = new XDebugArrayValue(this, property, typeName); - else if (typeName.equals("object")) - fValue = new XDebugArrayValue(this, property, typeName); + fNumChildren=Integer.parseInt(PHPDebugUtils.getAttributeValue(property,"numchildren")); + + String typeName=PHPDebugUtils.getAttributeValue(property,"type"); + +// if (typeName.equals("uninitialized") ) +// fValue= new XDebugValue(this,property,typeName); + if (typeName.equals("int") ) + fValue= new XDebugIntValue(this,property,typeName); + else if (typeName.equals("float") ) + fValue= new XDebugFloatValue(this,property,typeName); + else if (typeName.equals("bool") ) + fValue= new XDebugBooleanValue(this,property,typeName); + else if (typeName.equals("string") ) + fValue= new XDebugStringValue(this,property,typeName); + else if (typeName.equals("array") ) + fValue= new XDebugArrayValue(this,property,typeName); + else if (typeName.equals("hash") ) + fValue= new XDebugArrayValue(this,property,typeName); + else if (typeName.equals("object") ) + fValue= new XDebugArrayValue(this,property,typeName); else - fValue = new XDebugValue(this, property, typeName); - - // else if (typeName.equals("float") ) - // fTypeName= VARTYPE_FLOAT; - // else if (typeName.equals("string") ) - // fTypeName= VARTYPE_STRING; - // else if (typeName.equals("hash") ) - // fTypeName= VARTYPE_HASH; - // else if (typeName.equals("array") ) - // fTypeName= VARTYPE_ARRAY; - // else if (typeName.equals("object") ) - // fTypeName= VARTYPE_OBJECT; - - // fTypeName=type; - // - // fValue= new XDebugValue(this,property); - } - - /* - * (non-Javadoc) - * + fValue= new XDebugValue(this,property,typeName); + } + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IVariable#getValue() */ public IValue getValue() throws DebugException { return fValue; - // return ((XDebugTarget)getDebugTarget()).getVariableValue(this); +// return ((XDebugTarget)getDebugTarget()).getVariableValue(this); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IVariable#getName() */ public String getName() throws DebugException { @@ -139,72 +147,58 @@ public class XDebugVariable extends XDebugElement implements IVariable { else return fName; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName() */ public String getReferenceTypeName() throws DebugException { return fValue.getReferenceTypeName(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IVariable#hasValueChanged() */ public boolean hasValueChanged() throws DebugException { - // TODO Auto-generated method stub - return false; + return fValue.hasChanged(); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String) */ public void setValue(String expression) throws DebugException { - if (fValue.setValue(expression)) - fireEvent(new DebugEvent(this, DebugEvent.CHANGE, - DebugEvent.CONTENT)); + if(fValue.setValue(expression)) + fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT)); + //fValue.setValueA(expression); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue) */ public void setValue(IValue value) throws DebugException { + fValue.setValueB(value); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification() */ public boolean supportsValueModification() { return fValue.supportsValueModification(); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String) */ public boolean verifyValue(String expression) throws DebugException { return fValue.verifyValue(expression); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue) */ public boolean verifyValue(IValue value) throws DebugException { return false; } - + /** * Returns the stack frame owning this variable. * @@ -213,15 +207,24 @@ public class XDebugVariable extends XDebugElement implements IVariable { protected XDebugStackFrame getStackFrame() { return fFrame; } + + public void setStackFrame(XDebugStackFrame frame) { + fFrame=frame; + super.setDebugTarget((XDebugTarget)frame.getDebugTarget()); + } - // public int getType() { - // return fType; - // } +// public int getType() { +// return fType; +// } public String getValueString() throws DebugException { return fValue.getValueString(); } - + + /*public setValueString(String newValueStrig) throws DebugException { + fValue.setValueString getValueString(); + }*/ + public boolean hasChildren() { return (fNumChildren > 0); } @@ -237,7 +240,7 @@ public class XDebugVariable extends XDebugElement implements IVariable { public void setEncoding(String encoding) { fEncoding = encoding; } - + public String toString() { return fValue.toString(); } @@ -246,4 +249,64 @@ public class XDebugVariable extends XDebugElement implements IVariable { return fFullName; } -} + public int getNumChildren() { + return fNumChildren; + } + + public void setNumChildren(int numChildren) { + fNumChildren = numChildren; + } + + public void setChange(IVariable oldVariable) throws DebugException { + XDebugAbstractValue oldValue = null; + IVariable[] newVariable = null; + IVariable[] oldVariable1 = null; + + try { + oldValue = (XDebugAbstractValue) oldVariable.getValue(); + } catch (DebugException e) { + } + + try { + oldVariable1 = ((XDebugVariable)oldVariable).getValue().getVariables(); + newVariable = fValue.getVariables(); + } catch (DebugException e) { + } + + + if(((XDebugVariable) oldVariable).getNumChildren() > 0) { + if ( this.getNumChildren() == 0) { + try { + if (!fValue.getValueString().equals(((XDebugAbstractValue)oldValue).getValueString())) { + fValue.sethasChanged(true); + } else { + fValue.sethasChanged(false); + } + } catch (DebugException e) { + } + } else { + for(int i = 0; i < newVariable.length; i++) { + ((XDebugVariable)newVariable[i]).setChange(((XDebugVariable)oldVariable1[i])); + } + } + } else { + if ( this.getNumChildren() == 0) { + // controllare anche il tipo (unknow) + //if (!fValue.getValueString().equals("uninitialized")) { + if (!fValue.getValueString().equals(oldValue.getValueString())) { + fValue.sethasChanged(true); + } else { + fValue.sethasChanged(false); + } + } else { + IVariable dummy = new XDebugVariable("UNKNOWN", ""); + dummy.setValue("uninitialized"); + for(int i = 0; i < newVariable.length; i++) { + ((XDebugVariable)newVariable[i]).setChange(dummy); + } + fValue.sethasChanged(true); + } + } + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionDelegate.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionDelegate.java new file mode 100644 index 0000000..64dbc32 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionDelegate.java @@ -0,0 +1,53 @@ +package net.sourceforge.phpeclipse.xdebug.php.model; + + +import net.sourceforge.phpeclipse.xdebug.core.Base64; +import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugConnection; +import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable; +import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IWatchExpressionDelegate; +import org.eclipse.debug.core.model.IWatchExpressionListener; +import org.eclipse.debug.core.model.IWatchExpressionResult; +import org.w3c.dom.Node; + +public class XDebugWatchExpressionDelegate implements IWatchExpressionDelegate { + public void evaluateExpression(String expression, IDebugElement context, IWatchExpressionListener listener) { + IWatchExpressionResult x; + XDebugConnection connection; + XDebugTarget s; + + x = new XDebugWatchExpressionResult(expression, null, null); + + s = (XDebugTarget) context.getDebugTarget(); + connection = (XDebugConnection) s.getDebugConnection(); + + if( connection != null ) { + try { + if( ! connection.isClosed() ) { + String encoded = Base64.encodeBytes(expression.getBytes()); + DebugResponse evalCommand = connection.sendRequestA( "eval", "-- "+encoded ); + + Node evalNode = evalCommand.getParentNode(); + XDebugVariable var= connection.getVariableFromNodeA( null, evalNode.getFirstChild()); + XDebugVariable result[] = {var}; + + if (result.length == 0) { + x = new XDebugWatchExpressionResult(expression, null, null); + } else { + x = new XDebugWatchExpressionResult(expression, result[0].getValue(), null); + } + } + } catch (Exception e) { + String[] s1; + + s1 = new String[1]; + s1[0] = e.toString(); + x = new XDebugWatchExpressionResult(expression, null, s1); + } + } + + listener.watchEvaluationFinished(x); + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionResult.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionResult.java new file mode 100644 index 0000000..4e702f9 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionResult.java @@ -0,0 +1,37 @@ +package net.sourceforge.phpeclipse.xdebug.php.model; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.core.model.IWatchExpressionResult; + +public class XDebugWatchExpressionResult implements IWatchExpressionResult { + private String text; + private IValue result; + private String[] err; + + public XDebugWatchExpressionResult(String t, IValue v, String[] e) { + text = t; + result = v; + err = e; + } + + public IValue getValue() { + return result; + } + + public boolean hasErrors() { + return err != null; + } + + public String[] getErrorMessages() { + return err; + } + + public String getExpressionText() { + return text; + } + + public DebugException getException() { + return null; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.ui/META-INF/MANIFEST.MF b/net.sourceforge.phpeclipse.xdebug.ui/META-INF/MANIFEST.MF index a7b83a3..f304999 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/META-INF/MANIFEST.MF +++ b/net.sourceforge.phpeclipse.xdebug.ui/META-INF/MANIFEST.MF @@ -1,25 +1,21 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: XDebug UI -Bundle-SymbolicName: net.sourceforge.phpeclipse.xdebug.ui ; singleton:=true -Bundle-Version: 0.0.1 +Bundle-Name: XDebug Ui Plug-in +Bundle-SymbolicName: net.sourceforge.phpeclipse.xdebug.ui;singleton:=true +Bundle-Version: 0.0.0 +Bundle-ClassPath: ui.jar Bundle-Activator: net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin -Bundle-Vendor: PHPEclipse project team Require-Bundle: org.eclipse.core.resources, org.eclipse.core.runtime, org.eclipse.debug.core, org.eclipse.debug.ui, org.eclipse.jface.text, org.eclipse.ui, + org.eclipse.ui.editors, org.eclipse.ui.ide, org.eclipse.ui.workbench.texteditor, net.sourceforge.phpeclipse, net.sourceforge.phpeclipse.externaltools, net.sourceforge.phpeclipse.xdebug.core -Export-Package: net.sourceforge.phpeclipse.xdebug.ui, - net.sourceforge.phpeclipse.xdebug.ui.actions, - net.sourceforge.phpeclipse.xdebug.ui.php.launching, - net.sourceforge.phpeclipse.xdebug.ui.php.model, - net.sourceforge.phpeclipse.xdebug.ui.preference -Bundle-RequiredExecutionEnvironment: J2SE-1.4 Eclipse-LazyStart: true +Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/net.sourceforge.phpeclipse.xdebug.ui/build.properties b/net.sourceforge.phpeclipse.xdebug.ui/build.properties index 4f6be16..845c8ca 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/build.properties +++ b/net.sourceforge.phpeclipse.xdebug.ui/build.properties @@ -1,13 +1,5 @@ -source.. = src/ -output.. = bin/ +source.ui.jar = src/ +output.ui.jar = bin/ bin.includes = META-INF/,\ - .,\ - icons/,\ - plugin.xml -src.includes = src/,\ plugin.xml,\ - icons/,\ - build.properties,\ - META-INF/,\ - .project,\ - .classpath + icons/ diff --git a/net.sourceforge.phpeclipse.xdebug.ui/icons/obj16/xdebug.gif b/net.sourceforge.phpeclipse.xdebug.ui/icons/obj16/xdebug.gif deleted file mode 100644 index 35382c70980a1ed21ec8388d86caa422db01673b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 347 zcmZ?wbhEHb6krfwSZcrk1WZhP9U0r*1?WU%d zZQb3Ir%#`^Y4fFR+pq3FaO>FddlxU=xqkiOjT?_{+<0;C-s^k!-#mHp{^_$1&!2yM z{^H|@58pn1{QjRrp!k!8k&D5eK?md$ke?XXDh|vKh|rX3KQTWr)rN1jsM;2fn9d+s zQ4P^eN!q8nxQi_r&h-{PiqY8CrE+-Zmp%rGDUY;^Ei=!_S93{+i0UY7$fz+f@ac%j z$s~9MxpJoq@%y>B2{1Bngm}&oW?^7nyqLj0eWl0hHEY*xaN4xWGkwd}oz6QqIWkxS E09i|<-v9sr diff --git a/net.sourceforge.phpeclipse.xdebug.ui/icons/xdebug.gif b/net.sourceforge.phpeclipse.xdebug.ui/icons/xdebug.gif new file mode 100644 index 0000000000000000000000000000000000000000..449bb6690fc8f313cb0b7b6377aa19e4e106c18c GIT binary patch literal 178 zcmZ?wbhEHb6krfwc+AVNINhwip|Q2Cy}PGx(&VW#X3m+vVDXx@8+Ps9d*Z~YGiNVc zyLSD_lPCXSK=Gfbb5UwyNotBhd1gt5LP$ocg1e`00E6OB7Dg@xeg+)|AOIQ8z~c6y z(S7w&VS@wuY+l<^#3jNUoRYc>BN?2U)~U-z{=U_)`nJJQ&JM$ttONHr18yAbF>VTG Za`j}hzHFj=qSQvlA;ERZlw3guYXGk6ON#&i literal 0 HcmV?d00001 diff --git a/net.sourceforge.phpeclipse.xdebug.ui/plugin.xml b/net.sourceforge.phpeclipse.xdebug.ui/plugin.xml index 5ad53ff..db39686 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/plugin.xml +++ b/net.sourceforge.phpeclipse.xdebug.ui/plugin.xml @@ -1,73 +1,96 @@ - + - + point="org.eclipse.debug.ui.launchConfigurationTypeImages"> + + - + point="org.eclipse.debug.ui.launchConfigurationTabGroups"> + + - - - + point="org.eclipse.debug.ui.debugModelPresentations"> + - - - + point="org.eclipse.core.runtime.adapters"> + + + - + point="org.eclipse.ui.editorActions"> + + + - - - + point="org.eclipse.ui.views"> + + - + point="org.eclipse.ui.contexts"> + - + point="org.eclipse.ui.popupMenus"> + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/EditPathMapDialog.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/EditPathMapDialog.java new file mode 100644 index 0000000..6f1e882 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/EditPathMapDialog.java @@ -0,0 +1,104 @@ +/* + * Created on 12.02.2004 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package net.sourceforge.phpeclipse.xdebug.ui; + +import net.sourceforge.phpdt.internal.ui.dialogs.StatusDialog; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * @author Christian + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class EditPathMapDialog extends StatusDialog { + + + private Text fLocalPathText; + private Text fRemotePathText; + private String[] fInitialValues; + private String fLocalPath; + private String fRemotePath; + + public EditPathMapDialog(Shell parentShell, String aDialogTitle, String[] initialValues) { + super(parentShell); + setTitle(aDialogTitle); + fInitialValues= initialValues; + } + + protected void okPressed() { + fLocalPath= fLocalPathText.getText(); + fRemotePath = fRemotePathText.getText(); + super.okPressed(); + } + protected Control createDialogArea(Composite composite) { + Composite comp = new Composite(composite, SWT.NONE); + comp.setLayout(new GridLayout()); + + Composite fileComp= new Composite(comp,SWT.NONE); + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 3; +// gridLayout.marginHeight = 0; +// gridLayout.marginWidth = 0; + fileComp.setLayout(gridLayout); + + Label label= new Label(fileComp,SWT.NONE); + label.setText("Local_Path"); + + + fLocalPathText = new Text(fileComp,SWT.SINGLE | SWT.BORDER); + GridData gd = new GridData(); + gd.widthHint=250; + fLocalPathText.setLayoutData(gd); + fLocalPathText.setText(fInitialValues[0]); + Button button= new Button(fileComp, SWT.PUSH); + button.setText("Browse"); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleBrowseButtonSelected(); + } + }); + label= new Label(fileComp,SWT.NONE); + label.setText("Remote Path"); + fRemotePathText = new Text(fileComp,SWT.SINGLE | SWT.BORDER); + fRemotePathText.setText(fInitialValues[1]); + gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan = 2; + fRemotePathText.setLayoutData(gd); + + return composite; + } + + public String[] getPathPair() { + return new String[] {fLocalPath,fRemotePath}; + } + + + private void handleBrowseButtonSelected() { + DirectoryDialog dd = new DirectoryDialog(getShell(),SWT.OPEN); + dd.setMessage("Select the directory to map"); + String path=dd.open(); + + if (path != null) + fLocalPathText.setText(path); + + } + + +} diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/EnvironmentVariable.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/EnvironmentVariable.java index 293bfe4..f615429 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/EnvironmentVariable.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/EnvironmentVariable.java @@ -3,14 +3,16 @@ package net.sourceforge.phpeclipse.xdebug.ui; /** * A key/value set whose data is passed into Runtime.exec(...) */ -public class EnvironmentVariable { +public class EnvironmentVariable +{ // The name of the environment variable private String name; - + // The value of the environment variable private String value; - - public EnvironmentVariable(String name, String value) { + + public EnvironmentVariable(String name, String value) + { this.name = name; this.value = value; } @@ -21,57 +23,54 @@ public class EnvironmentVariable { * * @return this variable's name */ - public String getName() { + public String getName() + { return name; } - + /** * Returns this variables value. * * @return this variable's value */ - public String getValue() { + public String getValue() + { return value; } - + /** * Sets this variable's value - * * @param value */ - public void setValue(String value) { + public void setValue(String value) + { this.value = value; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { return getName(); } - - /* - * (non-Javadoc) - * + + + /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { boolean equal = false; if (obj instanceof EnvironmentVariable) { - EnvironmentVariable var = (EnvironmentVariable) obj; + EnvironmentVariable var = (EnvironmentVariable)obj; equal = var.getName().equals(name); } - return equal; + return equal; } - - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { return name.hashCode(); } } + diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/MultipleInputDialog.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/MultipleInputDialog.java index 0f23c3e..3af109a 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/MultipleInputDialog.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/MultipleInputDialog.java @@ -28,34 +28,28 @@ import org.eclipse.swt.widgets.Text; public class MultipleInputDialog extends Dialog { protected static final String FIELD_NAME = "FIELD_NAME"; //$NON-NLS-1$ - protected static final int TEXT = 100; - protected static final int BROWSE = 101; - protected static final int VARIABLE = 102; - + protected Composite panel; - + protected List fieldList = new ArrayList(); - protected List controlList = new ArrayList(); - protected List validators = new ArrayList(); - protected Map valueMap = new HashMap(); private String title; - + + + public MultipleInputDialog(Shell shell, String title) { super(shell); this.title = title; setShellStyle(getShellStyle() | SWT.RESIZE); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell(Shell shell) { @@ -63,12 +57,10 @@ public class MultipleInputDialog extends Dialog { if (title != null) { shell.setText(title); } - + } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#createButtonBar(org.eclipse.swt.widgets.Composite) */ protected Control createButtonBar(Composite parent) { @@ -76,80 +68,66 @@ public class MultipleInputDialog extends Dialog { validateFields(); return bar; } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea(Composite parent) { - Composite container = (Composite) super.createDialogArea(parent); + Composite container = (Composite)super.createDialogArea(parent); container.setLayout(new GridLayout(2, false)); container.setLayoutData(new GridData(GridData.FILL_BOTH)); - + panel = new Composite(container, SWT.NONE); GridLayout layout = new GridLayout(2, false); panel.setLayout(layout); panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - + for (Iterator i = fieldList.iterator(); i.hasNext();) { - FieldSummary field = (FieldSummary) i.next(); - switch (field.type) { - case TEXT: - createTextField(field.name, field.initialValue, - field.allowsEmpty); - break; - case BROWSE: - createBrowseField(field.name, field.initialValue, - field.allowsEmpty); - break; - case VARIABLE: - createVariablesField(field.name, field.initialValue, - field.allowsEmpty); - break; + FieldSummary field = (FieldSummary)i.next(); + switch(field.type) { + case TEXT: + createTextField(field.name, field.initialValue, field.allowsEmpty); + break; + case BROWSE: + createBrowseField(field.name, field.initialValue, field.allowsEmpty); + break; + case VARIABLE: + createVariablesField(field.name, field.initialValue, field.allowsEmpty); + break; } } - + fieldList = null; // allow it to be gc'd Dialog.applyDialogFont(container); return container; } - - public void addBrowseField(String labelText, String initialValue, - boolean allowsEmpty) { - fieldList.add(new FieldSummary(BROWSE, labelText, initialValue, - allowsEmpty)); + + public void addBrowseField(String labelText, String initialValue, boolean allowsEmpty) { + fieldList.add(new FieldSummary(BROWSE, labelText, initialValue, allowsEmpty)); } - - public void addTextField(String labelText, String initialValue, - boolean allowsEmpty) { - fieldList.add(new FieldSummary(TEXT, labelText, initialValue, - allowsEmpty)); + public void addTextField(String labelText, String initialValue, boolean allowsEmpty) { + fieldList.add(new FieldSummary(TEXT, labelText, initialValue, allowsEmpty)); } - - public void addVariablesField(String labelText, String initialValue, - boolean allowsEmpty) { - fieldList.add(new FieldSummary(VARIABLE, labelText, initialValue, - allowsEmpty)); + public void addVariablesField(String labelText, String initialValue, boolean allowsEmpty) { + fieldList.add(new FieldSummary(VARIABLE, labelText, initialValue, allowsEmpty)); } - protected void createTextField(String labelText, String initialValue, - boolean allowEmpty) { + protected void createTextField(String labelText, String initialValue, boolean allowEmpty) { Label label = new Label(panel, SWT.NONE); label.setText(labelText); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - + final Text text = new Text(panel, SWT.SINGLE | SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.setData(FIELD_NAME, labelText); - + // make sure rows are the same height on both panels. - label.setSize(label.getSize().x, text.getSize().y); - + label.setSize(label.getSize().x, text.getSize().y); + if (initialValue != null) { text.setText(initialValue); } - + if (!allowEmpty) { validators.add(new Validator() { public boolean validate() { @@ -162,23 +140,22 @@ public class MultipleInputDialog extends Dialog { } }); } - + controlList.add(text); } - - protected void createBrowseField(String labelText, String initialValue, - boolean allowEmpty) { + + protected void createBrowseField(String labelText, String initialValue, boolean allowEmpty) { Label label = new Label(panel, SWT.NONE); label.setText(labelText); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - + Composite comp = new Composite(panel, SWT.NONE); GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; + layout.marginHeight=0; + layout.marginWidth=0; comp.setLayout(layout); comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - + final Text text = new Text(comp, SWT.SINGLE | SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = 200; @@ -186,8 +163,8 @@ public class MultipleInputDialog extends Dialog { text.setData(FIELD_NAME, labelText); // make sure rows are the same height on both panels. - label.setSize(label.getSize().x, text.getSize().y); - + label.setSize(label.getSize().x, text.getSize().y); + if (initialValue != null) { text.setText(initialValue); } @@ -205,45 +182,44 @@ public class MultipleInputDialog extends Dialog { } }); } - - Button button = createButton(comp, IDialogConstants.IGNORE_ID, - "&Browse...", false); + + Button button = createButton(comp, IDialogConstants.IGNORE_ID, "&Browse...", false); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new DirectoryDialog(getShell()); - dialog.setMessage("Select a file:"); + dialog.setMessage("Select a file:"); String currentWorkingDir = text.getText(); if (!currentWorkingDir.trim().equals("")) { //$NON-NLS-1$ File path = new File(currentWorkingDir); if (path.exists()) { dialog.setFilterPath(currentWorkingDir); - } + } } - + String selectedDirectory = dialog.open(); if (selectedDirectory != null) { text.setText(selectedDirectory); - } + } } }); controlList.add(text); - + } - - public void createVariablesField(String labelText, String initialValue, - boolean allowEmpty) { + + + public void createVariablesField(String labelText, String initialValue, boolean allowEmpty) { Label label = new Label(panel, SWT.NONE); label.setText(labelText); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - + Composite comp = new Composite(panel, SWT.NONE); GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; + layout.marginHeight=0; + layout.marginWidth=0; comp.setLayout(layout); comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - + final Text text = new Text(comp, SWT.SINGLE | SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = 200; @@ -251,8 +227,8 @@ public class MultipleInputDialog extends Dialog { text.setData(FIELD_NAME, labelText); // make sure rows are the same height on both panels. - label.setSize(label.getSize().x, text.getSize().y); - + label.setSize(label.getSize().x, text.getSize().y); + if (initialValue != null) { text.setText(initialValue); } @@ -270,13 +246,11 @@ public class MultipleInputDialog extends Dialog { } }); } - - Button button = createButton(comp, IDialogConstants.IGNORE_ID, - "Varia&bles...", false); + + Button button = createButton(comp, IDialogConstants.IGNORE_ID, "Varia&bles...", false); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - StringVariableSelectionDialog dialog = new StringVariableSelectionDialog( - getShell()); + StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); int code = dialog.open(); if (code == IDialogConstants.OK_ID) { String variable = dialog.getVariableExpression(); @@ -288,46 +262,42 @@ public class MultipleInputDialog extends Dialog { }); controlList.add(text); - + } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { - for (Iterator i = controlList.iterator(); i.hasNext();) { - Control control = (Control) i.next(); + for (Iterator i = controlList.iterator(); i.hasNext(); ) { + Control control = (Control)i.next(); if (control instanceof Text) { - valueMap.put(control.getData(FIELD_NAME), ((Text) control) - .getText()); + valueMap.put(control.getData(FIELD_NAME), ((Text)control).getText()); } } controlList = null; super.okPressed(); } - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.jface.window.Window#open() */ public int open() { applyDialogFont(panel); return super.open(); } - + public Object getValue(String key) { return valueMap.get(key); } - + public String getStringValue(String key) { - return (String) getValue(key); + return (String) getValue(key); } - + public void validateFields() { - for (Iterator i = validators.iterator(); i.hasNext();) { + for(Iterator i = validators.iterator(); i.hasNext(); ) { Validator validator = (Validator) i.next(); if (!validator.validate()) { getButton(IDialogConstants.OK_ID).setEnabled(false); @@ -337,60 +307,52 @@ public class MultipleInputDialog extends Dialog { getButton(IDialogConstants.OK_ID).setEnabled(true); } - // /* (non-Javadoc) - // * @see - // org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point) - // */ - // protected Point getInitialLocation(Point initialSize) { - // Point initialLocation= - // DialogSettingsHelper.getInitialLocation(getDialogSettingsSectionName()); - // if (initialLocation != null) { - // return initialLocation; - // } - // return super.getInitialLocation(initialSize); - // } - +// /* (non-Javadoc) +// * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point) +// */ +// protected Point getInitialLocation(Point initialSize) { +// Point initialLocation= DialogSettingsHelper.getInitialLocation(getDialogSettingsSectionName()); +// if (initialLocation != null) { +// return initialLocation; +// } +// return super.getInitialLocation(initialSize); +// } + + protected String getDialogSettingsSectionName() { return IDebugUIConstants.PLUGIN_ID + ".MULTIPLE_INPUT_DIALOG_2"; //$NON-NLS-1$ } - - // /* (non-Javadoc) - // * @see org.eclipse.jface.window.Window#getInitialSize() - // */ - // protected Point getInitialSize() { - // Point size = super.getInitialSize(); - // return - // DialogSettingsHelper.getInitialSize(getDialogSettingsSectionName(), - // size); - // } - - // /* (non-Javadoc) - // * @see org.eclipse.jface.window.Window#close() - // */ - // public boolean close() { - // DialogSettingsHelper.persistShellGeometry(getShell(), - // getDialogSettingsSectionName()); - // return super.close(); - // } + +// /* (non-Javadoc) +// * @see org.eclipse.jface.window.Window#getInitialSize() +// */ +// protected Point getInitialSize() { +// Point size = super.getInitialSize(); +// return DialogSettingsHelper.getInitialSize(getDialogSettingsSectionName(), size); +// } + +// /* (non-Javadoc) +// * @see org.eclipse.jface.window.Window#close() +// */ +// public boolean close() { +// DialogSettingsHelper.persistShellGeometry(getShell(), getDialogSettingsSectionName()); +// return super.close(); +// } protected class FieldSummary { int type; - String name; - String initialValue; - boolean allowsEmpty; - - public FieldSummary(int type, String name, String initialValue, - boolean allowsEmpty) { + + public FieldSummary(int type, String name, String initialValue, boolean allowsEmpty) { this.type = type; this.name = name; this.initialValue = initialValue; this.allowsEmpty = allowsEmpty; } } - + protected class Validator { boolean validate() { return true; diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/XDebugUIPlugin.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/XDebugUIPlugin.java index a069314..03dc4a5 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/XDebugUIPlugin.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/XDebugUIPlugin.java @@ -3,14 +3,14 @@ package net.sourceforge.phpeclipse.xdebug.ui; import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.plugin.*; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** @@ -22,12 +22,13 @@ public class XDebugUIPlugin extends AbstractUIPlugin { private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle .getBundle(BUNDLE_NAME); + + private static final String PLUGIN_ID ="net.sourceforge.phpeclipse.xdebug.ui"; - private static final String PLUGIN_ID = "net.sourceforge.phpeclipse.xdebug.ui"; - - // The shared instance. + + //The shared instance. private static XDebugUIPlugin plugin; - + /** * The constructor. */ @@ -58,57 +59,51 @@ public class XDebugUIPlugin extends AbstractUIPlugin { } /** - * Returns an image descriptor for the image file at the given plug-in - * relative path. - * - * @param path - * the path + * Returns an image descriptor for the image file at the given + * plug-in relative path. + * + * @param path the path * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { - return AbstractUIPlugin.imageDescriptorFromPlugin( - "net.sourceforge.phpeclipse.xdebug.ui", path); + return AbstractUIPlugin.imageDescriptorFromPlugin("net.sourceforge.phpeclipse.xdebug.ui", path); } - + /** * Convenience method which returns the unique identifier of this plugin. */ public static String getUniqueIdentifier() { return PLUGIN_ID; } - + /** * Utility method with conventions */ - public static void errorDialog(Shell shell, String title, String message, - IStatus s) { - // if the 'message' resource string and the IStatus' message are the - // same, + public static void errorDialog(Shell shell, String title, String message, IStatus s) { + // if the 'message' resource string and the IStatus' message are the same, // don't show both in the dialog if (s != null && message.equals(s.getMessage())) { - message = null; + message= null; } ErrorDialog.openError(shell, title, message, s); } + /** * Utility method with conventions */ - public static void errorDialog(Shell shell, String title, String message, - Throwable t) { + public static void errorDialog(Shell shell, String title, String message, Throwable t) { IStatus status; if (t instanceof CoreException) { - status = ((CoreException) t).getStatus(); - // if the 'message' resource string and the IStatus' message are the - // same, + status= ((CoreException)t).getStatus(); + // if the 'message' resource string and the IStatus' message are the same, // don't show both in the dialog if (status != null && message.equals(status.getMessage())) { - message = null; + message= null; } } else { - status = new Status(IStatus.ERROR, getUniqueIdentifier(), - IStatus.ERROR, "Error within Debug UI: ", t); //$NON-NLS-1$ - log(status); + status= new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, "Error within Debug UI: ", t); //$NON-NLS-1$ + log(status); } ErrorDialog.openError(shell, title, message, status); } @@ -116,35 +111,32 @@ public class XDebugUIPlugin extends AbstractUIPlugin { /** * Logs the specified status with this plug-in's log. * - * @param status - * status to log + * @param status status to log */ public static void log(IStatus status) { getDefault().getLog().log(status); } - + /** * Logs an internal error with the specified throwable * - * @param e - * the exception to be logged - */ + * @param e the exception to be logged + */ public static void log(Throwable e) { - log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, - "Internal Error", e)); + log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, "Internal Error", e)); } - + /** - * Returns the standard display to be used. The method first checks, if the - * thread calling this method has an associated display. If so, this display - * is returned. Otherwise the method returns the default display. + * Returns the standard display to be used. The method first checks, if + * the thread calling this method has an associated display. If so, this + * display is returned. Otherwise the method returns the default display. */ public static Display getStandardDisplay() { Display display; - display = Display.getCurrent(); + display= Display.getCurrent(); if (display == null) - display = Display.getDefault(); - return display; + display= Display.getDefault(); + return display; } public static String getString(String key) { @@ -154,5 +146,5 @@ public class XDebugUIPlugin extends AbstractUIPlugin { return '!' + key + '!'; } } - + } diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/XDebugUIPluginImages.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/XDebugUIPluginImages.java index 1c48a08..69e49cc 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/XDebugUIPluginImages.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/XDebugUIPluginImages.java @@ -10,6 +10,7 @@ *******************************************************************************/ package net.sourceforge.phpeclipse.xdebug.ui; + import java.net.MalformedURLException; import java.net.URL; @@ -19,160 +20,143 @@ import org.eclipse.swt.graphics.Image; public class XDebugUIPluginImages { + /* Declare Common paths */ - private static URL ICON_BASE_URL = null; + private static URL ICON_BASE_URL= null; static { String pathSuffix = "icons/"; //$NON-NLS-1$ - ICON_BASE_URL = XDebugUIPlugin.getDefault().getBundle().getEntry( - pathSuffix); + ICON_BASE_URL= XDebugUIPlugin.getDefault().getBundle().getEntry(pathSuffix); } - + // The plugin registry private static ImageRegistry fgImageRegistry = null; - + /* * Set of predefined Image Descriptors. */ - private static final String T_OBJ = "obj16/"; //$NON-NLS-1$ - // private static final String T_OVR= "ovr16/"; //$NON-NLS-1$ - - private static final String T_EVIEW = "eview16/"; //$NON-NLS-1$ - - private static final String T_LCL = "elcl16/"; + private static final String T_OBJ= "obj16/"; //$NON-NLS-1$ +// private static final String T_OVR= "ovr16/"; //$NON-NLS-1$ + private static final String T_EVIEW= "eview16/"; //$NON-NLS-1$ + private static final String T_LCL="elcl16/"; public static final String IMG_EVIEW_ARGUMENTS_TAB = "IMG_EVIEW_ARGUMENTS_TAB"; - public static final String IMG_EVIEW_ENVIROMENT_TAB = "IMG_EVIEW_ENVIROMENT_TAB"; - public static final String IMG_PREV_EVENT = "IMG_PREV_EVENT"; - - public static final String DESC_NEXT_EVENT = "DESC_NEXT_EVENT"; + + public static final String IMG_PREV_EVENT="IMG_PREV_EVENT"; + public static final String DESC_NEXT_EVENT="DESC_NEXT_EVENT"; + public static final String IMG_ERROR_ST_OBJ="IMG_ERROR_ST_OBJ"; + public static final String IMG_WARNING_ST_OBJ="IMG_WARNING_ST_OBJ"; + public static final String IMG_INFO_ST_OBJ="IMG_INFO_ST_OBJ"; + public static final String IMG_ERROR_STACK_OBJ="IMG_ERROR_STACK_OBJ"; - public static final String IMG_ERROR_ST_OBJ = "IMG_ERROR_ST_OBJ"; - public static final String IMG_WARNING_ST_OBJ = "IMG_WARNING_ST_OBJ"; + public static final String IMG_PROPERTIES = "IMG_PROPERTIES"; +// public static final String IMG_PROPERTIES_DISABLED = "IMG_PROPERTIES_DISABLED"; + public static final String IMG_CLEAR = "IMG_CLEAR"; +// public static final String IMG_CLEAR_DISABLED = "IMG_CLEAR_DISABLED"; + public static final String IMG_READ_LOG = "IMG_READ_LOG"; +// public static final String IMG_READ_LOG_DISABLED = "IMG_READ_LOG_DISABLED"; + public static final String IMG_REMOVE_LOG = "IMG_REMOVE_LOG"; +// public static final String IMG_REMOVE_LOG_DISABLED = "IMG_REMOVE_LOG_DISABLED"; + public static final String IMG_FILTER = "IMG_FILTER"; +// public static final String IMG_FILTER_DISABLED = "IMG_FILTER_DISABLED"; + public static final String IMG_EXPORT = "IMG_EXPORT"; +// public static final String IMG_EXPORT_DISABLED = "IMG_EXPORT_DISABLED"; + public static final String IMG_IMPORT = "IMG_IMPORT"; +// public static final String IMG_IMPORT_DISABLED = "IMG_IMPORT_DISABLED"; + public static final String IMG_OPEN_LOG = "IMG_OPEN_LOG"; - public static final String IMG_INFO_ST_OBJ = "IMG_INFO_ST_OBJ"; - public static final String IMG_ERROR_STACK_OBJ = "IMG_ERROR_STACK_OBJ"; - public static final String IMG_PROPERTIES = "IMG_PROPERTIES"; - // public static final String IMG_PROPERTIES_DISABLED = - // "IMG_PROPERTIES_DISABLED"; - public static final String IMG_CLEAR = "IMG_CLEAR"; - - // public static final String IMG_CLEAR_DISABLED = "IMG_CLEAR_DISABLED"; - public static final String IMG_READ_LOG = "IMG_READ_LOG"; - - // public static final String IMG_READ_LOG_DISABLED = - // "IMG_READ_LOG_DISABLED"; - public static final String IMG_REMOVE_LOG = "IMG_REMOVE_LOG"; - - // public static final String IMG_REMOVE_LOG_DISABLED = - // "IMG_REMOVE_LOG_DISABLED"; - public static final String IMG_FILTER = "IMG_FILTER"; - - // public static final String IMG_FILTER_DISABLED = "IMG_FILTER_DISABLED"; - public static final String IMG_EXPORT = "IMG_EXPORT"; - - // public static final String IMG_EXPORT_DISABLED = "IMG_EXPORT_DISABLED"; - public static final String IMG_IMPORT = "IMG_IMPORT"; - - // public static final String IMG_IMPORT_DISABLED = "IMG_IMPORT_DISABLED"; - public static final String IMG_OPEN_LOG = "IMG_OPEN_LOG"; /** * Returns the image managed under the given key in this registry. * - * @param key - * the image's key + * @param key the image's key * @return the image managed under the given key - */ + */ public static Image get(String key) { return getImageRegistry().get(key); } - + /** * Returns the ImageDescriptor identified by the given key, * or null if it does not exist. */ public static ImageDescriptor getImageDescriptor(String key) { return getImageRegistry().getDescriptor(key); - } - + } + /* * Helper method to access the image registry from the XDebugUIPlugin class. */ - public static ImageRegistry getImageRegistry() { + public static ImageRegistry getImageRegistry() { if (fgImageRegistry == null) { initializeImageRegistry(); } return fgImageRegistry; } - + public static void initializeImageRegistry() { - fgImageRegistry = new ImageRegistry(XDebugUIPlugin.getStandardDisplay()); + fgImageRegistry= new ImageRegistry(XDebugUIPlugin.getStandardDisplay()); declareImages(); } - + private static void declareImages() { - declareRegistryImage(IMG_EVIEW_ARGUMENTS_TAB, T_EVIEW - + "arguments_tab.gif"); //$NON-NLS-1$ - declareRegistryImage(IMG_EVIEW_ENVIROMENT_TAB, T_EVIEW - + "environment_tab.gif"); //$NON-NLS-1$ - - declareRegistryImage(IMG_ERROR_ST_OBJ, T_OBJ + "error_st_obj.gif"); - declareRegistryImage(IMG_WARNING_ST_OBJ, T_OBJ + "warning_st_obj.gif"); - declareRegistryImage(IMG_INFO_ST_OBJ, T_OBJ + "info_st_obj.gif"); - declareRegistryImage(IMG_ERROR_STACK_OBJ, T_OBJ + "error_stack.gif"); - - declareRegistryImage(IMG_PROPERTIES, T_LCL + "properties.gif"); - // declareRegistryImage(IMG_PROPERTIES_DISABLED - declareRegistryImage(IMG_CLEAR, T_LCL + "clear_log.gif"); - // declareRegistryImage(IMG_CLEAR_DISABLED - declareRegistryImage(IMG_READ_LOG, T_LCL + "restore_log.gif"); - // declareRegistryImage(IMG_READ_LOG_DISABLED - declareRegistryImage(IMG_REMOVE_LOG, T_LCL + "remove_log.gif"); - // declareRegistryImage(IMG_REMOVE_LOG_DISABLED - declareRegistryImage(IMG_FILTER, T_LCL + "filter_log.gif"); - // declareRegistryImage(IMG_FILTER_DISABLED - declareRegistryImage(IMG_EXPORT, T_LCL + "export_log.gif"); - // declareRegistryImage(IMG_EXPORT_DISABLED - declareRegistryImage(IMG_IMPORT, T_LCL + "import_log.gif"); - // declareRegistryImage(IMG_IMPORT_DISABLED - declareRegistryImage(IMG_OPEN_LOG, T_LCL + "open_log.gif"); - - } - + declareRegistryImage(IMG_EVIEW_ARGUMENTS_TAB, T_EVIEW + "arguments_tab.gif"); //$NON-NLS-1$ + declareRegistryImage(IMG_EVIEW_ENVIROMENT_TAB, T_EVIEW + "environment_tab.gif"); //$NON-NLS-1$ + + declareRegistryImage(IMG_ERROR_ST_OBJ,T_OBJ+"error_st_obj.gif"); + declareRegistryImage(IMG_WARNING_ST_OBJ,T_OBJ + "warning_st_obj.gif"); + declareRegistryImage(IMG_INFO_ST_OBJ,T_OBJ +"info_st_obj.gif"); + declareRegistryImage(IMG_ERROR_STACK_OBJ,T_OBJ +"error_stack.gif"); + + declareRegistryImage(IMG_PROPERTIES,T_LCL + "properties.gif"); +// declareRegistryImage(IMG_PROPERTIES_DISABLED + declareRegistryImage(IMG_CLEAR,T_LCL + "clear_log.gif"); +// declareRegistryImage(IMG_CLEAR_DISABLED + declareRegistryImage(IMG_READ_LOG ,T_LCL + "restore_log.gif"); +// declareRegistryImage(IMG_READ_LOG_DISABLED + declareRegistryImage(IMG_REMOVE_LOG,T_LCL + "remove_log.gif"); +// declareRegistryImage(IMG_REMOVE_LOG_DISABLED + declareRegistryImage(IMG_FILTER,T_LCL + "filter_log.gif"); +// declareRegistryImage(IMG_FILTER_DISABLED + declareRegistryImage(IMG_EXPORT,T_LCL + "export_log.gif"); +// declareRegistryImage(IMG_EXPORT_DISABLED + declareRegistryImage(IMG_IMPORT,T_LCL + "import_log.gif"); +// declareRegistryImage(IMG_IMPORT_DISABLED + declareRegistryImage(IMG_OPEN_LOG,T_LCL + "open_log.gif"); + + } + /** * Declare an Image in the registry table. - * - * @param key - * The key to use when registering the image - * @param path - * The path where the image can be found. This path is relative - * to where this plugin class is found (i.e. typically the - * packages directory) + * @param key The key to use when registering the image + * @param path The path where the image can be found. This path is relative to where + * this plugin class is found (i.e. typically the packages directory) */ private final static void declareRegistryImage(String key, String path) { - ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor(); + ImageDescriptor desc= ImageDescriptor.getMissingImageDescriptor(); try { - desc = ImageDescriptor.createFromURL(makeIconFileURL(path)); + desc= ImageDescriptor.createFromURL(makeIconFileURL(path)); } catch (MalformedURLException me) { XDebugUIPlugin.log(me); } fgImageRegistry.put(key, desc); - } - - private static URL makeIconFileURL(String iconPath) - throws MalformedURLException { + } + + private static URL makeIconFileURL(String iconPath) throws MalformedURLException { if (ICON_BASE_URL == null) { throw new MalformedURLException(); } - + return new URL(ICON_BASE_URL, iconPath); - } + } + + + } diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/actions/BreakpointRulerActionDelegate.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/actions/BreakpointRulerActionDelegate.java index d222c4e..5f906be 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/actions/BreakpointRulerActionDelegate.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/actions/BreakpointRulerActionDelegate.java @@ -5,13 +5,15 @@ import org.eclipse.jface.text.source.IVerticalRulerInfo; import org.eclipse.ui.texteditor.AbstractRulerActionDelegate; import org.eclipse.ui.texteditor.ITextEditor; + + public class BreakpointRulerActionDelegate extends AbstractRulerActionDelegate { private ToggleBreakpointRulerAction fTargetAction; protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) { - fTargetAction = new ToggleBreakpointRulerAction(editor, rulerInfo); + fTargetAction = new ToggleBreakpointRulerAction( editor, rulerInfo ); return fTargetAction; } diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/actions/ToggleBreakpointRulerAction.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/actions/ToggleBreakpointRulerAction.java index 98e294d..d6a03d2 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/actions/ToggleBreakpointRulerAction.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/actions/ToggleBreakpointRulerAction.java @@ -1,14 +1,14 @@ /********************************************************************** - Copyright (c) 2000, 2002 IBM Corp. and others. - All rights reserved. This program and the accompanying materials - are made available under the terms of the Common Public License v1.0 - which accompanies this distribution, and is available at - http://www.eclipse.org/legal/cpl-v10.html - - Contributors: - IBM Corporation - Initial implementation - Vicente Fernando - www.alfersoft.com.ar - **********************************************************************/ +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Vicente Fernando - www.alfersoft.com.ar +**********************************************************************/ package net.sourceforge.phpeclipse.xdebug.ui.actions; import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin; @@ -27,52 +27,47 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; -public class ToggleBreakpointRulerAction extends Action { - +public class ToggleBreakpointRulerAction extends Action { + static class EmptySelection implements ISelection { public boolean isEmpty() { return true; - } + } } - + private IVerticalRulerInfo fRuler; - private IWorkbenchPart fTargetPart; - private PHPLineBreakpointAdapter fBreakpointAdapter; + private static final ISelection EMPTY_SELECTION = new EmptySelection(); + + public ToggleBreakpointRulerAction( IWorkbenchPart part, IVerticalRulerInfo ruler ) { + super( "Toggle Breakpoint" ); //$NON-NLS-1$ - private static final ISelection EMPTY_SELECTION = new EmptySelection(); - - public ToggleBreakpointRulerAction(IWorkbenchPart part, - IVerticalRulerInfo ruler) { - super("Toggle Breakpoint"); //$NON-NLS-1$ - - fRuler = ruler; + fRuler= ruler; fRuler = ruler; - setTargetPart(part); + setTargetPart( part ); fBreakpointAdapter = new PHPLineBreakpointAdapter(); - // part.getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp( - // this, ICDebugHelpContextIds.TOGGLE_BREAKPOINT_ACTION ); - // setId( IInternalCDebugUIConstants.ACTION_TOGGLE_BREAKPOINT ); +// part.getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp( this, ICDebugHelpContextIds.TOGGLE_BREAKPOINT_ACTION ); +// setId( IInternalCDebugUIConstants.ACTION_TOGGLE_BREAKPOINT ); } - + + /** * @see Action#run() */ public void run() { try { - fBreakpointAdapter.toggleLineBreakpoints(getTargetPart(), - getTargetSelection()); - } catch (CoreException e) { - XDebugUIPlugin.errorDialog(getTargetPart().getSite().getShell(), - "Error", "Operation failed", e.getStatus()); + fBreakpointAdapter.toggleLineBreakpoints( getTargetPart(), getTargetSelection() ); + } + catch( CoreException e ) { + XDebugUIPlugin.errorDialog( getTargetPart().getSite().getShell(),"Error", "Operation failed" , e.getStatus() ); } } - + /** * Returns this action's vertical ruler info. - * + * * @return this action's vertical ruler */ protected IVerticalRulerInfo getVerticalRulerInfo() { @@ -83,46 +78,45 @@ public class ToggleBreakpointRulerAction extends Action { return this.fTargetPart; } - private void setTargetPart(IWorkbenchPart targetPart) { + private void setTargetPart( IWorkbenchPart targetPart ) { this.fTargetPart = targetPart; } /** - * Returns the current selection in the active part, possibly and empty - * selection, but never null. + * Returns the current selection in the active part, possibly + * and empty selection, but never null. * * @return the selection in the active part, possibly empty */ private ISelection getTargetSelection() { IDocument doc = getDocument(); - if (doc != null) { - int line = getVerticalRulerInfo() - .getLineOfLastMouseButtonActivity(); + if ( doc != null ) { + int line = getVerticalRulerInfo().getLineOfLastMouseButtonActivity(); try { - IRegion region = doc.getLineInformation(line); - return new TextSelection(doc, region.getOffset(), region - .getLength()); - } catch (BadLocationException e) { - DebugPlugin.log(e); + IRegion region = doc.getLineInformation( line ); + return new TextSelection( doc, region.getOffset(), region.getLength() ); } + catch( BadLocationException e ) { + DebugPlugin.log( e ); + } } return EMPTY_SELECTION; } private IDocument getDocument() { IWorkbenchPart targetPart = getTargetPart(); - if (targetPart instanceof ITextEditor) { - ITextEditor textEditor = (ITextEditor) targetPart; + if ( targetPart instanceof ITextEditor ) { + ITextEditor textEditor = (ITextEditor)targetPart; IDocumentProvider provider = textEditor.getDocumentProvider(); - if (provider != null) - return provider.getDocument(textEditor.getEditorInput()); + if ( provider != null ) + return provider.getDocument( textEditor.getEditorInput() ); } - // else if ( targetPart instanceof DisassemblyView ) { - // DisassemblyView dv = (DisassemblyView)targetPart; - // IDocumentProvider provider = dv.getDocumentProvider(); - // if ( provider != null ) - // return provider.getDocument( dv.getInput() ); - // } +// else if ( targetPart instanceof DisassemblyView ) { +// DisassemblyView dv = (DisassemblyView)targetPart; +// IDocumentProvider provider = dv.getDocumentProvider(); +// if ( provider != null ) +// return provider.getDocument( dv.getInput() ); +// } return null; } diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPDebugModelPresentation.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPDebugModelPresentation.java index 07b24f1..567771e 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPDebugModelPresentation.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPDebugModelPresentation.java @@ -1,5 +1,9 @@ package net.sourceforge.phpeclipse.xdebug.ui.php.launching; + + +import java.io.File; + import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint; import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame; import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget; @@ -9,21 +13,75 @@ import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.PlatformObject; import org.eclipse.debug.core.model.ILineBreakpoint; import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.IValueDetailListener; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorRegistry; +import org.eclipse.ui.IPersistableElement; +import org.eclipse.ui.IStorageEditorInput; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.FileEditorInput; public class PHPDebugModelPresentation implements IDebugModelPresentation { + + class StorageEditorInput extends PlatformObject implements + IStorageEditorInput { + private File fFile; + + private IStorage fStorage; + + public StorageEditorInput(IStorage storage, File file) { + super(); + fStorage = storage; + fFile = file; + } + + public IStorage getStorage() { + return fStorage; + } + + public ImageDescriptor getImageDescriptor() { + return null; + } + + public String getName() { + return getStorage().getName(); + } + + public IPersistableElement getPersistable() { + return null; + } + + public String getToolTipText() { + return getStorage().getFullPath().toOSString(); + } + + public boolean equals(Object object) { + return object instanceof StorageEditorInput + && getStorage().equals( + ((StorageEditorInput) object).getStorage()); + } + + public int hashCode() { + return getStorage().hashCode(); + } + + public boolean exists() { + return fFile.exists(); + } + } + public void setAttribute(String attribute, Object value) { // TODO Auto-generated method stub @@ -38,28 +96,26 @@ public class PHPDebugModelPresentation implements IDebugModelPresentation { return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT); } else if (element instanceof IMarker) { return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT); - } else if (element instanceof XDebugStackFrame - || element instanceof XDebugThread - || element instanceof XDebugTarget) { + } else if (element instanceof XDebugStackFrame || element instanceof XDebugThread || element instanceof XDebugTarget) { return null; } else if (element instanceof XDebugVariable) { - return getVariableImage((XDebugVariable) element); + return getVariableImage((XDebugVariable)element); } else if (element instanceof XDebugValue) { - return getValueImage((XDebugValue) element); + return getValueImage((XDebugValue)element); } return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT); } - private Image getVariableImage(XDebugVariable phpVar) { - /* - * if (phpVar != null) { if (phpVar.isLocal()) return - * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); if - * (phpVar.isHashValue()) return - * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); } + /* if (phpVar != null) { + if (phpVar.isLocal()) + return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); + if (phpVar.isHashValue()) + return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); + } */ return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); } - + private Image getValueImage(XDebugValue phpVar) { if (phpVar != null) { return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); @@ -67,6 +123,7 @@ public class PHPDebugModelPresentation implements IDebugModelPresentation { return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); } + public String getText(Object element) { // TODO Auto-generated method stub return null; @@ -100,23 +157,24 @@ public class PHPDebugModelPresentation implements IDebugModelPresentation { public IEditorInput getEditorInput(Object element) { if (element instanceof IFile) { - return new FileEditorInput((IFile) element); + return new FileEditorInput((IFile)element); + } + if( element instanceof LocalFileStorage) { + LocalFileStorage lfc= (LocalFileStorage)element; + return new StorageEditorInput(lfc,lfc.getFile()); } if (element instanceof ILineBreakpoint) { - return new FileEditorInput((IFile) ((ILineBreakpoint) element) - .getMarker().getResource()); + return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource()); } return null; } public String getEditorId(IEditorInput input, Object element) { - IEditorRegistry registry = PlatformUI.getWorkbench() - .getEditorRegistry(); - IEditorDescriptor descriptor = registry.getDefaultEditor(input - .getName()); + IEditorRegistry registry= PlatformUI.getWorkbench().getEditorRegistry(); + IEditorDescriptor descriptor= registry.getDefaultEditor(input.getName()); if (descriptor != null) return descriptor.getId(); - + return null; } diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPEnvironmentTab.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPEnvironmentTab.java index eb99160..e1e0e30 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPEnvironmentTab.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPEnvironmentTab.java @@ -419,14 +419,8 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab { EnvironmentVariable existingVariable = (EnvironmentVariable) items[i] .getData(); if (existingVariable.getName().equals(name)) { - boolean overWrite = MessageDialog - .openQuestion( - getShell(), - "Overwrite variable?", - MessageFormat - .format( - "A variable named {0} already exists. Overwrite?", - new String[] { name })); + boolean overWrite = MessageDialog.openQuestion(getShell(),"Overwrite variable?", + MessageFormat.format("A variable named {0} already exists. Overwrite?",new String[] { name })); if (!overWrite) { return false; } @@ -762,9 +756,8 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab { * * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage() */ - public Image getImage() { - return XDebugUIPluginImages - .get(XDebugUIPluginImages.IMG_EVIEW_ENVIROMENT_TAB); + public Image getImage() { + return XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_EVIEW_ENVIROMENT_TAB); } /* @@ -794,8 +787,8 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab { } protected IDialogSettings getDialogSettings() { - IDialogSettings settings = XDebugCorePlugin.getDefault() - .getDialogSettings(); +// IDialogSettings settings = XDebugCorePlugin.getDefault().getDialogSettings(); + IDialogSettings settings = getDialogSettings(); IDialogSettings section = settings .getSection(getDialogSettingsSectionName()); if (section == null) { @@ -833,19 +826,16 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab { // * @see org.eclipse.jface.window.Window#getInitialSize() // */ // protected Point getInitialSize() { - // Point size = super.getInitialSize(); - // return - // DialogSettingsHelper.getInitialSize(getDialogSettingsSectionName(), - // size); - // } - - // /* (non-Javadoc) - // * @see org.eclipse.jface.window.Window#close() - // */ - // public boolean close() { - // DialogSettingsHelper.persistShellGeometry(getShell(), - // getDialogSettingsSectionName()); - // return super.close(); - // } + // Point size = super.getInitialSize(); + // return DialogSettingsHelper.getInitialSize(getDialogSettingsSectionName(), size); + // } + + // /* (non-Javadoc) + // * @see org.eclipse.jface.window.Window#close() + // */ + // public boolean close() { + // DialogSettingsHelper.persistShellGeometry(getShell(), getDialogSettingsSectionName()); + // return super.close(); + // } } } diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPMainTab.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPMainTab.java index ed5f1b0..ac4628a 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPMainTab.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPMainTab.java @@ -1,11 +1,13 @@ package net.sourceforge.phpeclipse.xdebug.ui.php.launching; import java.io.File; +//import java.text.MessageFormat; import net.sourceforge.phpdt.internal.ui.PHPUiImages; import net.sourceforge.phpdt.internal.ui.util.PHPFileSelector; import net.sourceforge.phpdt.internal.ui.util.PHPProjectSelector; -import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; +//import net.sourceforge.phpeclipse.xdebug.core.IXDebugPreferenceConstants; +//import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; import org.eclipse.core.resources.IFile; @@ -35,27 +37,21 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; public class PHPMainTab extends AbstractLaunchConfigurationTab { // Project UI widgets protected Text fProjText; - protected Button fProjButton; // Main class UI widgets protected Text fMainText; - protected Button fSearchButton; - protected PHPProjectSelector projectSelector; - protected PHPFileSelector fileSelector; - private Button fUseDefaultInterpreterButton; - private Button fInterpreterButton; - private Text fInterpreterText; public PHPMainTab() { @@ -64,32 +60,30 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { public void createControl(Composite parent) { Font font = parent.getFont(); - + Composite comp = new Composite(parent, SWT.NONE); setControl(comp); - // PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), - // IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB); +// PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB); GridLayout topLayout = new GridLayout(); topLayout.verticalSpacing = 0; comp.setLayout(topLayout); comp.setFont(font); - + createProjectEditor(comp); createVerticalSpacer(comp, 1); createMainTypeEditor(comp); createVerticalSpacer(comp, 1); createInterpreterEditor(comp); } - + /** * Creates the widgets for specifying a main type. * - * @param parent - * the parent composite + * @param parent the parent composite */ private void createProjectEditor(Composite parent) { - Font font = parent.getFont(); - Group group = new Group(parent, SWT.NONE); + Font font= parent.getFont(); + Group group= new Group(parent, SWT.NONE); group.setText("Project:"); GridData gd = new GridData(GridData.FILL_HORIZONTAL); group.setLayoutData(gd); @@ -99,26 +93,25 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { group.setFont(font); projectSelector = new PHPProjectSelector(group); - projectSelector - .setBrowseDialogMessage("Choose the project containing the application entry point:"); + projectSelector.setBrowseDialogMessage("Choose the project containing the application entry point:"); projectSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); projectSelector.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent evt) { updateLaunchConfigurationDialog(); } }); - } + } + /** * Creates the widgets for specifying a php file. * - * @param parent - * the parent composite + * @param parent the parent composite */ private void createMainTypeEditor(Composite parent) { - Font font = parent.getFont(); - Group mainGroup = new Group(parent, SWT.NONE); - mainGroup.setText("File: "); + Font font= parent.getFont(); + Group mainGroup= new Group(parent, SWT.NONE); + mainGroup.setText("File: "); GridData gd = new GridData(GridData.FILL_HORIZONTAL); mainGroup.setLayoutData(gd); GridLayout layout = new GridLayout(); @@ -127,8 +120,7 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { mainGroup.setFont(font); fileSelector = new PHPFileSelector(mainGroup, projectSelector); - fileSelector - .setBrowseDialogMessage("Choose the PHP file that represents the application entry point:"); + fileSelector.setBrowseDialogMessage("Choose the PHP file that represents the application entry point:"); fileSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fileSelector.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent evt) { @@ -136,26 +128,25 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { } }); } - + /** * Creates the widgets for specifying debug settings. * - * @param parent - * the parent composite + * @param parent the parent composite */ private void createInterpreterEditor(Composite parent) { - Font font = parent.getFont(); - Group interpreterGroup = new Group(parent, SWT.NONE); - interpreterGroup.setText("Interpreter: "); + Font font= parent.getFont(); + Group interpreterGroup= new Group(parent, SWT.NONE); + interpreterGroup.setText("Interpreter: "); GridData gd = new GridData(GridData.FILL_HORIZONTAL); interpreterGroup.setLayoutData(gd); GridLayout layout = new GridLayout(); layout.numColumns = 2; interpreterGroup.setLayout(layout); interpreterGroup.setFont(font); - - fInterpreterText = new Text(interpreterGroup, SWT.SINGLE | SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); + + fInterpreterText= new Text(interpreterGroup, SWT.SINGLE | SWT.BORDER); + gd= new GridData(GridData.FILL_HORIZONTAL); fInterpreterText.setLayoutData(gd); fInterpreterText.setFont(font); fInterpreterText.addModifyListener(new ModifyListener() { @@ -164,28 +155,27 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { } }); - fInterpreterButton = createPushButton(interpreterGroup, "Browse..", - null); + + fInterpreterButton= createPushButton(interpreterGroup,"Browse..", null); fInterpreterButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { handleBrowseSellected(event); } }); - - fUseDefaultInterpreterButton = new Button(interpreterGroup, SWT.CHECK); + + fUseDefaultInterpreterButton = new Button(interpreterGroup,SWT.CHECK); fUseDefaultInterpreterButton.setText("Use default interpreter"); gd = new GridData(GridData.FILL_HORIZONTAL); fUseDefaultInterpreterButton.setLayoutData(gd); fUseDefaultInterpreterButton.setFont(font); - fUseDefaultInterpreterButton - .addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - handleDefaultSellected(event); - } - }); + fUseDefaultInterpreterButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + handleDefaultSellected(event); + } + }); } - + /** * Set the appropriate enabled state for the appletviewqer text widget. */ @@ -198,7 +188,7 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { fInterpreterButton.setEnabled(true); } } - + /** * Returns whether the default appletviewer is to be used */ @@ -206,27 +196,28 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { return fUseDefaultInterpreterButton.getSelection(); } + + protected void handleDefaultSellected(SelectionEvent event) { setInterpreterTextEnabledState(); updateLaunchConfigurationDialog(); - // if (isDefaultInterpreter()) { - // fInterpreterText.setText("default Interpreter"); - // } +// if (isDefaultInterpreter()) { +// fInterpreterText.setText("default Interpreter"); +// } } protected void handleBrowseSellected(SelectionEvent event) { - FileDialog dlg = new FileDialog(getShell(), SWT.OPEN); - String fileName = dlg.open(); - if (fileName != null) { + FileDialog dlg=new FileDialog(getShell(),SWT.OPEN); + String fileName=dlg.open(); + if (fileName!=null) { fInterpreterText.setText(fileName); updateLaunchConfigurationDialog(); } } protected IProject getContext() { - IWorkbenchPage page = XDebugCorePlugin.getDefault().getWorkbench() - .getActiveWorkbenchWindow().getActivePage(); + IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page != null) { ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { @@ -248,33 +239,30 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { } return null; } + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { IProject project = getContext(); if (project != null) - configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, - project.getName()); + configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project.getName()); } + public void initializeFrom(ILaunchConfiguration configuration) { try { - String project = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_PROJECT, (String) null); + String project = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null); if (project != null) { projectSelector.setSelectionText(project); } - String file = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_FILE, (String) null); + String file = configuration.getAttribute(IXDebugConstants.ATTR_PHP_FILE, (String)null); if (file != null) { fileSelector.setSelectionText(file); } - - String interpreterFile = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_INTERPRETER, (String) null); - if (interpreterFile != null) + + String interpreterFile=configuration.getAttribute(IXDebugConstants.ATTR_PHP_INTERPRETER, (String) null); + if(interpreterFile!=null) fInterpreterText.setText(interpreterFile); - boolean selection = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, true); + boolean selection=configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, true); fUseDefaultInterpreterButton.setSelection(selection); setInterpreterTextEnabledState(); @@ -291,41 +279,36 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project); IFile file = fileSelector.getSelection(); - configuration.setAttribute(IXDebugConstants.ATTR_PHP_FILE, - file == null ? "" : file.getProjectRelativePath().toString()); - configuration.setAttribute( - IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, - this.fUseDefaultInterpreterButton.getSelection()); - configuration.setAttribute(IXDebugConstants.ATTR_PHP_INTERPRETER, - this.fInterpreterText.getText()); + configuration.setAttribute(IXDebugConstants.ATTR_PHP_FILE, file == null ? "" : file.getProjectRelativePath() + .toString()); + configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, this.fUseDefaultInterpreterButton.getSelection()); + configuration.setAttribute(IXDebugConstants.ATTR_PHP_INTERPRETER, this.fInterpreterText.getText()); } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration) */ public boolean isValid(ILaunchConfiguration launchConfig) { setErrorMessage(null); - String projectName = projectSelector.getSelectionText().trim(); - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( - projectName); + String projectName=projectSelector.getSelectionText().trim(); + IProject project=ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (!project.exists()) { setErrorMessage("Project does not exist"); return false; } - String fileName = fileSelector.getSelectionText().trim(); - if (fileName.equals("")) { - setErrorMessage("No file selected."); - return false; - } - IFile file = project.getFile(fileName); - if (!file.exists()) { + String fileString=fileSelector.getSelectionText().trim(); + if (!"".equals(fileString)) { + IFile file=project.getFile(fileSelector.getSelectionText().trim()); + if (!file.exists()) { + setErrorMessage("File does not exist"); + return false; + } + } else { setErrorMessage("File does not exist"); return false; } - if (!fUseDefaultInterpreterButton.getSelection()) { + if (!fUseDefaultInterpreterButton.getSelection()) { File exe = new File(fInterpreterText.getText()); System.out.println(exe.toString()); if (!exe.exists()) { @@ -335,11 +318,11 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab { } return true; } - + public Image getImage() { return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE); } - + public String getName() { return "Main"; } diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPPathMapTab.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPPathMapTab.java new file mode 100644 index 0000000..0992e5d --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPPathMapTab.java @@ -0,0 +1,476 @@ +package net.sourceforge.phpeclipse.xdebug.ui.php.launching; + +import java.text.MessageFormat; +//import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +//import java.util.Map; +import java.util.Vector; + +import net.sourceforge.phpeclipse.xdebug.core.PathMapItem; +import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; +import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; +import net.sourceforge.phpeclipse.xdebug.ui.EditPathMapDialog; +/*import net.sourceforge.phpeclipse.xdebug.ui.EnvironmentVariable; +import net.sourceforge.phpeclipse.xdebug.ui.MultipleInputDialog; +import net.sourceforge.phpeclipse.xdebug.ui.php.launching.PHPEnvironmentTab.EnvironmentVariableContentProvider; +import net.sourceforge.phpeclipse.xdebug.ui.php.launching.PHPEnvironmentTab.EnvironmentVariableLabelProvider; +*/ +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +//import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ColumnLayoutData; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +//import org.eclipse.jface.viewers.ViewerSorter; +//import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +public class PHPPathMapTab extends AbstractLaunchConfigurationTab { + protected TableViewer fPathMapTable; + protected Button fAddButton; + protected Button envAddCGIButton; + protected Button fEditButton; + protected Button fRemoveButton; + protected Button fUpButton; + protected Button fDownButton; + + + protected String[] fPathMapTableColumnHeaders = { "Local", "Remote" }; + + protected ColumnLayoutData[] fPathMapTableColumnLayouts = { + new ColumnWeightData(50), new ColumnWeightData(50) }; + + protected static final String P_REMOTE = "remote"; //$NON-NLS-1$ + protected static final String P_LOCAL = "local"; //$NON-NLS-1$ + protected static String[] fPathMapTableColumnProperties = { P_REMOTE, P_LOCAL }; + + + /** + * Content provider for the environment table + */ + protected class PathMapContentProvider implements IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + PathMapItem[] elements = new PathMapItem[0]; + ILaunchConfiguration config = (ILaunchConfiguration) inputElement; + List l; + try { + l = config.getAttribute(IXDebugConstants.ATTR_PHP_PATHMAP, (List) null); + } catch (CoreException e) { + XDebugCorePlugin.log(new Status(IStatus.ERROR, + XDebugCorePlugin.PLUGIN_ID, IStatus.ERROR, + "Error reading configuration", e)); //$NON-NLS-1$ + return elements; + } + if (l != null && !l.isEmpty()) { + elements = new PathMapItem[l.size()]; + for (int i = 0; i < l.size(); i++) { + elements[i] = new PathMapItem((String) l.get(i)); + } + } + + return elements; + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + + /** + * Label provider for the environment table + */ + public class PathMapItemLabelProvider extends LabelProvider + implements ITableLabelProvider { + public String getColumnText(Object element, int columnIndex) { + String result = null; + if (element != null) { + PathMapItem var = (PathMapItem) element; + switch (columnIndex) { + case 0: // local + result = var.getLocalPath().toOSString(); + break; + case 1: // remote + result = var.getRemotePath().toString(); + break; + } + } + return result; + } + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + } + + + public void createControl(Composite parent) { + // Create main composite + Composite mainComposite = new Composite(parent, SWT.NONE); + setControl(mainComposite); + // WorkbenchHelp.setHelp(getControl(), + // IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + mainComposite.setLayout(layout); + mainComposite.setLayoutData(gridData); + mainComposite.setFont(parent.getFont()); + + createPathMapTable(mainComposite); + createTableButtons(mainComposite); + + Dialog.applyDialogFont(mainComposite); + } + + /** + * Creates the add/edit/remove buttons for the environment table + * + * @param parent + * the composite in which the buttons should be created + */ + protected void createTableButtons(Composite parent) { + // Create button composite + Composite buttonComposite = new Composite(parent, SWT.NONE); + GridLayout glayout = new GridLayout(); + glayout.marginHeight = 0; + glayout.marginWidth = 0; + glayout.numColumns = 1; + GridData gdata = new GridData(GridData.VERTICAL_ALIGN_BEGINNING + | GridData.HORIZONTAL_ALIGN_END); + buttonComposite.setLayout(glayout); + buttonComposite.setLayoutData(gdata); + buttonComposite.setFont(parent.getFont()); + + createVerticalSpacer(buttonComposite, 1); + // Create buttons + fAddButton = createPushButton(buttonComposite, "New", null); + fAddButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + handleAddButtonSelected(); + } + }); + + fEditButton = createPushButton(buttonComposite, "Edit", null); + fEditButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + handleEditButtonSelected(); + } + }); + fEditButton.setEnabled(false); + + fRemoveButton = createPushButton(buttonComposite, "Remove", null); + fRemoveButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + handleRemoveButtonSelected(); + } + }); + fRemoveButton.setEnabled(false); + + fUpButton = createPushButton(buttonComposite, "Up", null); + fUpButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + handleUpButtonSelected(); + } + }); + fUpButton.setEnabled(false); + + fDownButton = createPushButton(buttonComposite, "Down", null); + fDownButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + handleDownButtonSelected(); + } + }); + fDownButton.setEnabled(false); + } + + + /** + * Creates and configures the table that displayed the key/value pairs that + * comprise the environment. + * + * @param parent + * the composite in which the table should be created + */ + protected void createPathMapTable(Composite parent) { + Font font = parent.getFont(); + // Create table composite + Composite tableComposite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 1; + GridData gridData = new GridData(GridData.FILL_BOTH); + gridData.heightHint = 150; + tableComposite.setLayout(layout); + tableComposite.setLayoutData(gridData); + tableComposite.setFont(font); + // Create label + Label label = new Label(tableComposite, SWT.NONE); + label.setFont(font); + label.setText("&Map remote path to local path"); + // Create table + fPathMapTable = new TableViewer(tableComposite, SWT.BORDER + | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); + Table table = fPathMapTable.getTable(); + TableLayout tableLayout = new TableLayout(); + table.setLayout(tableLayout); + table.setHeaderVisible(true); + table.setFont(font); + gridData = new GridData(GridData.FILL_BOTH); + fPathMapTable.getControl().setLayoutData(gridData); + fPathMapTable.setContentProvider(new PathMapContentProvider()); + fPathMapTable.setLabelProvider(new PathMapItemLabelProvider()); + fPathMapTable.setColumnProperties(fPathMapTableColumnProperties); + fPathMapTable.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + handleTableSelectionChanged(event); + } + }); + fPathMapTable.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + if (!fPathMapTable.getSelection().isEmpty()) { + handleEditButtonSelected(); + } + } + }); + // Create columns + for (int i = 0; i < fPathMapTableColumnHeaders.length; i++) { + tableLayout.addColumnData(fPathMapTableColumnLayouts[i]); + TableColumn tc = new TableColumn(table, SWT.NONE, i); + tc.setResizable(fPathMapTableColumnLayouts[i].resizable); + tc.setText(fPathMapTableColumnHeaders[i]); + } + } + + /** + * Responds to a selection changed event in the environment table + * @param event the selection change event + */ + protected void handleTableSelectionChanged(SelectionChangedEvent event) { + int size = ((IStructuredSelection)event.getSelection()).size(); + int idx = fPathMapTable.getTable().getSelectionIndex(); + int count = fPathMapTable.getTable().getItemCount(); + if (size==1) { + fEditButton.setEnabled(idx>0); + fUpButton.setEnabled(idx>0); + fDownButton.setEnabled((idx>=0)&&(idx 0); + } + + /** + * Creates an editor for the value of the selected environment variable. + */ + private void handleUpButtonSelected() { + IStructuredSelection sel = (IStructuredSelection) fPathMapTable.getSelection(); + PathMapItem mapItem = (PathMapItem) sel.getFirstElement(); + boolean found=false; + if (mapItem == null) { + return; + } + IPath local = mapItem.getLocalPath(); + TableItem[] items = fPathMapTable.getTable().getItems(); + int i; + for (i = 0; i < items.length; i++) { + PathMapItem item = (PathMapItem) items[i].getData(); + if (item.getLocalPath().equals(local)) { + found=true; + break; + } + } + if ((i>0) && found) { + fPathMapTable.getControl().setRedraw(false); + fPathMapTable.remove(mapItem); + fPathMapTable.insert(mapItem,i-1); + fPathMapTable.getControl().setRedraw(true); + fPathMapTable.setSelection(new StructuredSelection(mapItem),true); + updateLaunchConfigurationDialog(); + } + } + + private void handleDownButtonSelected() { + IStructuredSelection sel = (IStructuredSelection) fPathMapTable.getSelection(); + PathMapItem mapItem = (PathMapItem) sel.getFirstElement(); + boolean found=false; + if (mapItem == null) { + return; + } + IPath local = mapItem.getLocalPath(); + TableItem[] items = fPathMapTable.getTable().getItems(); + int i; + for (i = 0; i < items.length; i++) { + PathMapItem item = (PathMapItem) items[i].getData(); + if (item.getLocalPath().equals(local)) { + found=true; + break; + } + } + + if ((i 0 && strremote.length() > 0) { + addVariable(new PathMapItem(strlocal,strremote)); + } + } + + /** + * Removes the selected environment variable from the table. + */ + private void handleRemoveButtonSelected() { + IStructuredSelection sel = (IStructuredSelection) fPathMapTable.getSelection(); + fPathMapTable.getControl().setRedraw(false); + for (Iterator i = sel.iterator(); i.hasNext();) { + PathMapItem item = (PathMapItem) i.next(); + fPathMapTable.remove(item); + } + fPathMapTable.getControl().setRedraw(true); + updateLaunchConfigurationDialog(); + } + + /** + * Attempts to add the given variable. Returns whether the variable was + * added or not (as when the user answers not to overwrite an existing + * variable). + * + * @param variable the variable to add + * @return whether the variable was added + */ + protected boolean addVariable(PathMapItem mapItem) { + IPath local = mapItem.getLocalPath(); + TableItem[] items = fPathMapTable.getTable().getItems(); + for (int i = 0; i < items.length; i++) { + PathMapItem item = (PathMapItem) items[i].getData(); + if (item.getLocalPath().equals(local)) { + boolean overWrite = MessageDialog.openQuestion(getShell(),"Overwrite variable?", + MessageFormat.format("A local path named {0} already exists. Overwrite?",new String[] { local.toString() })); + if (!overWrite) { + return false; + } + fPathMapTable.remove(item); + break; + } + } + fPathMapTable.add(mapItem); + updateLaunchConfigurationDialog(); + return true; + } + + + + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + // TODO Auto-generated method stub + + } + + public void initializeFrom(ILaunchConfiguration configuration) { + fPathMapTable.setInput(configuration); + } + + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + // Convert the table's items into a List so that this can be saved in the + // configuration's attributes. + TableItem[] items = fPathMapTable.getTable().getItems(); + List vec = new Vector(items.length); + for (int i = 0; i < items.length; i++) { + PathMapItem item = (PathMapItem) items[i].getData(); + vec.add(item.getStringData()); + } + if (vec.size() == 0) { + configuration.setAttribute(IXDebugConstants.ATTR_PHP_PATHMAP, (List) null); + } else { + configuration.setAttribute(IXDebugConstants.ATTR_PHP_PATHMAP, vec); + } + } + + public String getName() { + return "Pathmap"; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPRemoteDebug.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPRemoteDebug.java new file mode 100644 index 0000000..d63052f --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPRemoteDebug.java @@ -0,0 +1,222 @@ +package net.sourceforge.phpeclipse.xdebug.ui.php.launching; + +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import net.sourceforge.phpdt.internal.ui.util.PHPProjectSelector; +//import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; +import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants; +import net.sourceforge.phpeclipse.xdebug.ui.EditPathMapDialog; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +//import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +//import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +//import org.eclipse.swt.events.MouseAdapter; +//import org.eclipse.swt.events.MouseEvent; +//import org.eclipse.swt.events.SelectionAdapter; +//import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +//import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +//import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +//import org.eclipse.swt.widgets.Table; +//import org.eclipse.swt.widgets.TableColumn; +//import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; + +public class PHPRemoteDebug extends AbstractLaunchConfigurationTab { + + private PHPProjectSelector projectSelector; + private Text fIdeIDText; + private Text fRemoteLocationText; + + public void createControl(Composite parent) { + Font font = parent.getFont(); + + Composite comp = new Composite(parent, SWT.NONE); + setControl(comp); +// PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB); + GridLayout topLayout = new GridLayout(); + topLayout.verticalSpacing = 0; + comp.setLayout(topLayout); + comp.setFont(font); + + createProjectEditor(comp); + createVerticalSpacer(comp, 1); + createIdeIDEditor(comp); + + } + + /** + * Creates the widgets for specifying a main type. + * + * @param parent the parent composite + */ + private void createProjectEditor(Composite parent) { + Font font= parent.getFont(); + Group group= new Group(parent, SWT.NONE); + group.setText("Project:"); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + group.setLayoutData(gd); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + group.setLayout(layout); + group.setFont(font); + + projectSelector = new PHPProjectSelector(group); + projectSelector.setBrowseDialogMessage("Choose the project containing the application entry point:"); + projectSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + projectSelector.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent evt) { + updateLaunchConfigurationDialog(); + } + }); + + Label remoteLabel= new Label(group,SWT.NONE); + remoteLabel.setText("Remote Location:"); + + fRemoteLocationText = new Text(group,SWT.SINGLE | SWT.BORDER); + gd= new GridData(GridData.FILL_HORIZONTAL); + fRemoteLocationText.setLayoutData(gd); + fRemoteLocationText.setFont(font); + fRemoteLocationText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent evt) { + updateLaunchConfigurationDialog(); + } + }); + } + + private void createIdeIDEditor(Composite parent) { + Font font= parent.getFont(); + Group group= new Group(parent, SWT.NONE); + group.setText("Ide Identification String :"); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + group.setLayoutData(gd); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + group.setLayout(layout); + group.setFont(font); + + + fIdeIDText = new Text(group, SWT.SINGLE | SWT.BORDER); + gd= new GridData(GridData.FILL_HORIZONTAL); + fIdeIDText.setLayoutData(gd); + fIdeIDText.setFont(font); + fIdeIDText.setTextLimit(48); + fIdeIDText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent evt) { + updateLaunchConfigurationDialog(); + } + }); + + } + + + + protected IProject getContext() { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + //IWorkbenchPage page= XDebugCorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if (page != null) { + ISelection selection = page.getSelection(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + if (!ss.isEmpty()) { + Object obj = ss.getFirstElement(); + if (obj instanceof IResource) + return ((IResource) obj).getProject(); + } + } + IEditorPart part = page.getActiveEditor(); + if (part != null) { + IEditorInput input = part.getEditorInput(); + IResource file = (IResource) input.getAdapter(IResource.class); + if (file != null) { + return file.getProject(); + } + } + } + return null; + } + + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + IProject project = getContext(); + if (project != null) + configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project.getName()); + } + + public void initializeFrom(ILaunchConfiguration configuration) { + try { + String project = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null); + if (project != null) { + projectSelector.setSelectionText(project); + } + String ideID = configuration.getAttribute(IXDebugConstants.ATTR_PHP_IDE_ID, "testID"); + fIdeIDText.setText(ideID); + + String remoteLocation=configuration.getAttribute(IXDebugConstants.ATTR_PHP_REMOTE_LOCATION, ""); + fRemoteLocationText.setText(remoteLocation); + + } catch (CoreException e) { + setErrorMessage(e.getMessage()); + } + + + + } + + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + String project = projectSelector.getSelectionText().trim(); + configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project); + String ideID = fIdeIDText.getText().trim(); + configuration.setAttribute(IXDebugConstants.ATTR_PHP_IDE_ID, ideID); + String remoteLocation = fRemoteLocationText.getText().trim(); + configuration.setAttribute(IXDebugConstants.ATTR_PHP_REMOTE_LOCATION, remoteLocation); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration) + */ + public boolean isValid(ILaunchConfiguration launchConfig) { + setErrorMessage(null); + String projectName=projectSelector.getSelectionText().trim(); + IProject project=ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + if (!project.exists()) { + setErrorMessage("Project does not exist"); + return false; + } + String ideID=fIdeIDText.getText(); + if (ideID.indexOf(' ')>0) { + setErrorMessage("No spaces in Identification String allowed"); + return false; + } + return true; + } + + public Image getImage() { + return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE); + } + + public String getName() { + return "Main"; + } + + +} diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPRemoteTabGroup.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPRemoteTabGroup.java new file mode 100644 index 0000000..4187802 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPRemoteTabGroup.java @@ -0,0 +1,21 @@ +package net.sourceforge.phpeclipse.xdebug.ui.php.launching; + +import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; +import org.eclipse.debug.ui.CommonTab; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.debug.ui.ILaunchConfigurationTab; +import org.eclipse.debug.ui.sourcelookup.SourceLookupTab; + +public class PHPRemoteTabGroup extends AbstractLaunchConfigurationTabGroup { + + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + setTabs(new ILaunchConfigurationTab[] { + new PHPRemoteDebug(), + new PHPPathMapTab(), + new SourceLookupTab(), + new CommonTab() + }); + + } + +} diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPTabGroup.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPTabGroup.java index 7f2c6e4..72a06e1 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPTabGroup.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/PHPTabGroup.java @@ -8,9 +8,14 @@ import org.eclipse.debug.ui.sourcelookup.SourceLookupTab; public class PHPTabGroup extends AbstractLaunchConfigurationTabGroup { + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { - setTabs(new ILaunchConfigurationTab[] { new PHPMainTab(), - new XDebugTab(), new SourceLookupTab(), - new PHPEnvironmentTab(), new CommonTab() }); + setTabs(new ILaunchConfigurationTab[] { + new PHPMainTab(), +// new XDebugTab(), + new SourceLookupTab(), + new PHPEnvironmentTab(), + new CommonTab() + }); } } diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/XDebugTab.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/XDebugTab.java index e3ed6ac..70dd943 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/XDebugTab.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/launching/XDebugTab.java @@ -23,9 +23,7 @@ import org.eclipse.swt.widgets.Text; public class XDebugTab extends AbstractLaunchConfigurationTab { private Label fPortLabel; - private Button fUseDefaultPortButton; - private Text fPortText; public XDebugTab() { @@ -34,11 +32,10 @@ public class XDebugTab extends AbstractLaunchConfigurationTab { public void createControl(Composite parent) { Font font = parent.getFont(); - + Composite comp = new Composite(parent, SWT.NONE); setControl(comp); - // PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), - // IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB); +// PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB); GridLayout topLayout = new GridLayout(); topLayout.verticalSpacing = 0; comp.setLayout(topLayout); @@ -46,26 +43,27 @@ public class XDebugTab extends AbstractLaunchConfigurationTab { createDebugPortEditor(comp); } - + private void createDebugPortEditor(Composite parent) { - Font font = parent.getFont(); - Group debugGroup = new Group(parent, SWT.NONE); - debugGroup.setText("Debug: "); + Font font= parent.getFont(); + Group debugGroup= new Group(parent, SWT.NONE); + debugGroup.setText("Debug: "); GridData gd = new GridData(GridData.FILL_HORIZONTAL); debugGroup.setLayoutData(gd); GridLayout layout = new GridLayout(); layout.numColumns = 2; debugGroup.setLayout(layout); debugGroup.setFont(font); - + fPortLabel = new Label(debugGroup, SWT.NONE); fPortLabel.setText("&DebugPort:"); - // gd = new GridData(GridData.BEGINNING); - // fPortLabel.setLayoutData(gd); +// gd = new GridData(GridData.BEGINNING); +// fPortLabel.setLayoutData(gd); fPortLabel.setFont(font); + fPortText = new Text(debugGroup, SWT.SINGLE | SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); + gd= new GridData(GridData.FILL_HORIZONTAL); fPortText.setLayoutData(gd); fPortText.setFont(font); fPortText.addModifyListener(new ModifyListener() { @@ -74,7 +72,9 @@ public class XDebugTab extends AbstractLaunchConfigurationTab { } }); - fUseDefaultPortButton = new Button(debugGroup, SWT.CHECK); + + + fUseDefaultPortButton = new Button(debugGroup,SWT.CHECK); fUseDefaultPortButton.setText("Use default interpreter"); gd = new GridData(GridData.FILL_HORIZONTAL); fUseDefaultPortButton.setLayoutData(gd); @@ -85,7 +85,7 @@ public class XDebugTab extends AbstractLaunchConfigurationTab { } }); } - + /** * Set the appropriate enabled state for the appletviewqer text widget. */ @@ -98,7 +98,7 @@ public class XDebugTab extends AbstractLaunchConfigurationTab { fPortLabel.setEnabled(true); } } - + /** * Returns whether the default appletviewer is to be used */ @@ -106,11 +106,13 @@ public class XDebugTab extends AbstractLaunchConfigurationTab { return fUseDefaultPortButton.getSelection(); } + protected void handleDefaultSellected(SelectionEvent event) { setDebugportEnabledState(); updateLaunchConfigurationDialog(); } + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { // TODO Auto-generated method stub @@ -118,42 +120,36 @@ public class XDebugTab extends AbstractLaunchConfigurationTab { public void initializeFrom(ILaunchConfiguration configuration) { try { - String portText = "" - + configuration.getAttribute( - IXDebugConstants.ATTR_PHP_DEBUGPORT, 9000); + String portText=""+configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEBUGPORT, 9000); fPortText.setText(portText); - boolean selection = configuration.getAttribute( - IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT, true); + boolean selection=configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT, true); fUseDefaultPortButton.setSelection(selection); setDebugportEnabledState(); } catch (CoreException e) { setErrorMessage(e.getMessage()); } + } public void performApply(ILaunchConfigurationWorkingCopy configuration) { - configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT, - this.fUseDefaultPortButton.getSelection()); + configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT, this.fUseDefaultPortButton.getSelection()); try { - configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEBUGPORT, - Integer.parseInt(this.fPortText.getText().trim())); + configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEBUGPORT, Integer.parseInt(this.fPortText.getText().trim())); } catch (NumberFormatException nfe) { } } - - /* - * (non-Javadoc) - * + + /* (non-Javadoc) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration) */ public boolean isValid(ILaunchConfiguration launchConfig) { setErrorMessage(null); try { Integer.parseInt(fPortText.getText().trim()); - } catch (NumberFormatException nfe) { - setErrorMessage("Debugport is not a valid integer"); + } catch(NumberFormatException nfe) { + setErrorMessage("Debugport is not a valid integer"); return false; } return true; diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/model/PHPBreakpointAdapterFactory.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/model/PHPBreakpointAdapterFactory.java index 7defbc5..1124273 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/model/PHPBreakpointAdapterFactory.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/model/PHPBreakpointAdapterFactory.java @@ -13,7 +13,7 @@ public class PHPBreakpointAdapterFactory implements IAdapterFactory { } public Class[] getAdapterList() { - return new Class[] { IToggleBreakpointsTarget.class }; + return new Class[]{IToggleBreakpointsTarget.class}; } } diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/model/PHPLineBreakpointAdapter.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/model/PHPLineBreakpointAdapter.java index 0138aee..a7e6cb9 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/model/PHPLineBreakpointAdapter.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/php/model/PHPLineBreakpointAdapter.java @@ -18,30 +18,26 @@ public class PHPLineBreakpointAdapter implements IToggleBreakpointsTarget { public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { - IEditorPart editorPart = (IEditorPart) part; + IEditorPart editorPart = (IEditorPart)part; - IResource resource = (IResource) editorPart.getEditorInput() - .getAdapter(IResource.class); + IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class); ITextSelection textSelection = (ITextSelection) selection; - int lineNumber = textSelection.getStartLine() + 1; - IBreakpoint[] breakpoints = DebugPlugin.getDefault() - .getBreakpointManager().getBreakpoints( - IXDebugConstants.ID_PHP_DEBUG_MODEL); + int lineNumber = textSelection.getStartLine()+1; + IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IXDebugConstants.ID_PHP_DEBUG_MODEL); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (resource.equals(breakpoint.getMarker().getResource())) { - if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber)) { - // remove + if (((ILineBreakpoint)breakpoint).getLineNumber() == (lineNumber )) { + // remove breakpoint.delete(); return; } } } - // create line breakpoint (doc line numbers start at 0) - XDebugLineBreakpoint lineBreakpoint = new XDebugLineBreakpoint( - resource, lineNumber); - // DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint); - + // create line breakpoint (doc line numbers start at 0) + XDebugLineBreakpoint lineBreakpoint = new XDebugLineBreakpoint(resource, lineNumber); + DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint); + } public boolean canToggleLineBreakpoints(IWorkbenchPart part, diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/preference/XDebugPreferencePage.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/preference/XDebugPreferencePage.java index 50435bf..dfec826 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/preference/XDebugPreferencePage.java +++ b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/preference/XDebugPreferencePage.java @@ -11,25 +11,24 @@ import org.eclipse.jface.preference.IntegerFieldEditor; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; + public class XDebugPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { /* Preference page for the default XDebug-Settings */ + + private IntegerFieldEditor debugPort; public XDebugPreferencePage() { super(FieldEditorPreferencePage.GRID); // Set the preference store for the preference page. - IPreferenceStore store = XDebugCorePlugin.getDefault() - .getPreferenceStore(); - store.setDefault(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE, - IXDebugPreferenceConstants.DEFAULT_DEBUGPORT); - // get the default form the externalToolsPlugin - String interpreter = ExternalToolsPlugin.getDefault() - .getPreferenceStore().getString( - ExternalToolsPlugin.PHP_RUN_PREF); - store.setDefault(IXDebugPreferenceConstants.PHP_INTERPRETER_PREFERENCE, - interpreter); + IPreferenceStore store = + XDebugCorePlugin.getDefault().getPreferenceStore(); + store.setDefault(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE,IXDebugPreferenceConstants.DEFAULT_DEBUGPORT); + // get the default form the externalToolsPlugin + String interpreter=ExternalToolsPlugin.getDefault().getPreferenceStore().getString(ExternalToolsPlugin.PHP_RUN_PREF); + store.setDefault(IXDebugPreferenceConstants.PHP_INTERPRETER_PREFERENCE,interpreter); setPreferenceStore(store); } @@ -38,19 +37,24 @@ public class XDebugPreferencePage extends FieldEditorPreferencePage implements } protected void createFieldEditors() { - IntegerFieldEditor debugPort = new IntegerFieldEditor( - IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE, "&Debugport:", - getFieldEditorParent(), 5); - debugPort.setValidRange(1025, 65535); + debugPort = new IntegerFieldEditor(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE, "&Debugport:", getFieldEditorParent(),5); + debugPort.setValidRange(1025,65535); + debugPort.setErrorMessage("Debugport must be between 1024 and 65536"); addField(debugPort); - - FileFieldEditor phpInterpreter = new FileFieldEditor( - IXDebugPreferenceConstants.PHP_INTERPRETER_PREFERENCE, - "PHP &Interpreter:", true, getFieldEditorParent()); - phpInterpreter.setErrorMessage("File not found"); + + FileFieldEditor phpInterpreter = new FileFieldEditor(IXDebugPreferenceConstants.PHP_INTERPRETER_PREFERENCE, "PHP &Interpreter:",true,getFieldEditorParent()); + phpInterpreter.setErrorMessage("File not found"); addField(phpInterpreter); - + + } + + public void performApply() { + super.performApply(); + XDebugCorePlugin.getDefault().setProxyPort(debugPort.getIntValue()); } + + + } -- 1.7.1