Hi,

I recently completed this package that leverages on the Emacs Java Development
Environment (JDE) configuration options to launch JSwat (a really good open source Java
debugger).

I later realized that JDE already supports the configuration of debuggers other than
JDEbug and jdb; the problem is that JSwat requires some parameters to be in a special
format (e.g. no ending slashes in directory names used in the sourcepath, something
required by JDE but that creates problems for JSwat; and usage of Windows style path
notation) which required further transformations. This package takes care of that.

In the long run I believe the best path is to add hooks to JDE to do those
transformations (or to make JSwat more flexible with parameters passed to it from the
command-line) and use the JDE jde-db-debugger option "other". In the mean time, this
package has been quite helpful.

Enjoy,
        Nascif

PS: If anybody has been succesful using jde-db-debugger to start JSwat under Windows,
please send me a cheat sheet :-) For example, to which JDE variable should I add the
JSwat jar file?


===File d:/emacs/dev/jswat.el===============================
;;; jswat.el
;; $Revision: 0.01 $ 

;; Author: Nascif A. Abousalh Neto <[EMAIL PROTECTED]>
;; Maintainer: Nascif A. Abousalh Neto
;; Keywords: java, debugging, tools
;; Time-stamp: <2001-11-21 14:45:17 nascif>

;; Copyright (C) 1997, 1998, 2000, 2001 Nascif A. Abousalh Neto

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

; Note: This library implements an Emacs interface to JSwat
; (http://www.bluemarsh.com/java/jswat/), based heavily on the JDEE
; (http://jdee.sunsite.dk/rootpage.html) configuration. The idea is to save time by
; re-using the configuration of one tool (JDEE debugger) to use another similar one
; (JSwat). The target audience is designers that have JDEE
; installed and configured, but want to play with a different debugger.
;
; Usage: (assuming JSwat and JDEE are already installed and configured): 
; 1) Add this library to a directory visible from your load-path
; 2) Add to your .emacs (after the lines that enable JDEE) the line
;       (require 'jswat)
; 3) Customize the variable "jswat-jar" to point to the path of your JSwat jar file
; 4) Your probably don't have to do that, but you may need (in future versions of
;    JSwat) to customize "jswat-main-class" to reflect changes in the JSwat main class
;    name
; 5) After loading a Java file (with an associated JDEE project file), 
;    just call it interactively:
;       M-x jswat 
;
; Problems:
; - Not tested on *nix, only on Windows;
; - Probably won't work with paths that contain a space.
; - Uses JDE 2.2.8 variables that have been deprecated in 2.2.9 (easy to fix)
;

(require 'jde)

(defgroup jswat nil
  "JSwat Options"
  :group 'tools
  :prefix "jswat-")

(defcustom jswat-jar "d:/bin/jswat-1.4.6/jswat-20011112.jar"
  "Path to JSwat jar file"
  :group 'jswat
  :type 'file)

(defcustom jswat-main-class "com.bluemarsh.jswat.Main"
  "Main class used to launch JSwat"
  :group 'jswat
  :type 'string)

(defun jswat ()
  "Invokes JSwat using the setup derived from the current JDE session.
   Assumes that Emacs is configured to use a Unix-like (e.g. bash) shell"
  (interactive)
  ;; Java interpreter
  (let* ((buffer (get-buffer-create "*JSwat*"))
         (java-vm (if (eq system-type 'windows-nt)
                    jde-run-java-vm-w
                  jde-run-java-vm))
        (jpda-jar (if jde-bug-vm-includes-jpda-p                      
                      (expand-file-name 
                       "lib/tools.jar"
                       (jde-normalize-path 'jde-bug-jdk-directory))
                    (expand-file-name 
                     "lib/jpda.jar" (jde-normalize-path
                                     'jde-bug-jpda-directory))))
        (jswat-classpath (list jpda-jar jswat-jar))
        (proj-classpath  (mapcar 'jswat-remove-last-slash (if jde-db-option-classpath
                                                            jde-db-option-classpath
                                                            jde-global-classpath)))
        (proj-sourcepath (mapcar 'jswat-remove-last-slash jde-db-source-directories))
        )
    (set-buffer buffer)
    (erase-buffer)
    ;; Insert vm call
    (setq command java-vm)
    ;;Insert jswat classpath
    (setq command (concat command " "
                          (jde-build-classpath-arg 'jswat-classpath)))
    ;; Insert sourcepath
    (if proj-sourcepath
        (setq command (concat command " -Djava.source.path="
                              (jswat-replace-path-separator 
                               (jde-build-classpath proj-sourcepath)))))
    ;; Insert JSwat main class
    (setq command (concat command " " jswat-main-class))

    ;;Insert classic VM toggle for the debugee VM
    (if jde-db-option-vm-args
        (setq command (concat command " "
                              (mapconcat (lambda (vm-arg) vm-arg)
                                           jde-db-option-vm-args
                                           " "))))

    ;; Insert application classpath
    (if proj-classpath
        (setq command (concat command " -classpath "
                              (jswat-replace-path-separator 
                               (jde-build-classpath proj-classpath)))))
    ;; Insert debugee vm  arguments
    (if (not (null jde-db-option-properties))
        (setq command (concat command " " 
                              (mapconcat (lambda (prop-name-value) 
                                           (concat "-D" (car prop-name-value) "=" (cdr 
prop-name-value)))
                                         jde-db-option-properties
                                         " "))))
    ;; Insert application main class and application arguments
    (if (not (string= jde-run-application-class ""))
        (setq command (concat command " " jde-run-application-class " "
                              (mapconcat (lambda (path) path)
                                         jde-db-option-application-args
                                         " "))))
    ;; insert complete command in JSwat buffer for debugging
    (insert command "\n")
    ;; change to the application runtime directory
    (cd (jde-normalize-path jde-run-working-directory))
    ;; build assynch command and launch JSwat
    (setq form (nconc (list 'start-process "jswat-process" buffer)
                      (split-string command " ")))
    (eval form)))

(defun jswat-replace-path-separator (string)
  "replace path separators to match the OS style
   TODO: make more generic, current does only Unix->Windows"
  (if (eq system-type 'windows-nt)
      (jswat-replace-chars-in-string string ?/ ?\\)
    string))

;;; From Steve Kemp's small functions
(defun jswat-replace-chars-in-string (string from to)
  "Replace characters in STRING from FROM to TO."
  (let ((string (substring string 0))   ;Copy string.
        (len (length string))
        (idx 0))
    ;; Replace all occurrences of FROM with TO.
    (while (< idx len)
      (when (= (aref string idx) from)
        (aset string idx to))
      (setq idx (1+ idx)))
    string))

(defun jswat-remove-last-slash (path)
  "Remove last slash from path if present"
  (let ((len (length path)))
    (if (> len 0)
        (let ((last (1- len)))
          (if (or (= (aref path last) ?\\)
                  (= (aref path last) ?/))
              (substring path 0 last)
            path))
      path)))

(provide 'jswat)

;; jswat.el ends here
============================================================



Reply via email to