Hello,
I have completed, the first stage, of the modifications to jde-ant.el
which allows a user to select the invocation style, either script or
via Java. I have added appropriate comments to the jde-ant.el file to
indicate the changes. I will repeat here:
added 3 custom variables
jde-ant-class
indicates which java class to invoke
default value is org.apache.tools.ant.Main
jde-ant-classpath
List of jar files needed to run ant.
This needs to be set to include the 3 ant jar files
and the tools.jar from Sun.
I have chosen to use this instead of using the global
classpath as the jar files used to invoke ant is not
necessarily needed to compile the classes. I think, IMHO,
this makes it cleaner.
jde-ant-invocation-style
Used to determine how to invoke jde-ant, the default how
Jason would like to see it.
Added 1 defun
jde-ant-build-classpath
This defun creates the classpath from the list of jars in
jde-ant-classpath.
To Do:
Add one more customer var to indicate the home directory of Ant.
Thereby, automatically creating the required classpath to include
the 3 ant jar files and the tools.jar from Sun. This allows the
user to include the additional jar files they need to run ant
and not worry about the required jars.
If I have made a error please let me know.
Douglas WF Acheson
P.S. If you can come up with better wording for the
jde-ant-invocation-style I would be very much appreciated.
--- [EMAIL PROTECTED] wrote:
>
> Douglas
>
> What if, instead of using the custom string variable jde-ant-program,
> a new
> custom variable jde-ant-invocation-style is a choice between invoking
> a
> specific script or invoking a function that generates the appropriate
> Ant
> command. Perhaps something like:
>
> Jde Ant Invocation Style: [Hide]
>
> (*) Use program or script
> Script/Program : __________________________________________
>
> ( ) Invoke function
> Function : ________________________________________________
>
>
> This way, jde-ant is flexible enough to do the things you want. When
> jde-ant-build is called, the invocation style variable will be
> checked, and
> the ant command will be built accordingly...
> A standard function could be created to invoke the jvm defined by
> 'jde-run-java-vm' using the classpath defined by
> 'jde-global-classpath'/'jde-run-option-classpath' and the Ant main
> class.
>
> Thoughts?
>
> Jason
>
>
>
>
>
>
>
> Douglas WF
>
> Acheson To:
> [EMAIL PROTECTED]
>
> <[EMAIL PROTECTED] cc:
>
> om> Subject: Re: jde-ant
>
>
>
> 07/19/01
>
> 02:00 PM
>
>
>
>
>
>
>
>
>
> Hello,
>
> I understand your position about running ant. Would it be possible
> to allow changes so that you can use it either way? They way you
> have
> outlined below, via the ant batch/shell script, and invoking a JVM to
> run ant.
>
> Allowing jde-ant to be invoked via a JVM directly allows more
> flexible within Emacs. Using this model allows changes to be
> controlled within Emacs and not in the batch/shell script.
> Therefore,
> change need to occur within the environment of the project and not to
> the batch/shell script.
>
> I have made the necessary changes to jde-ant.el to invoke the JVM.
> It was not hard, and very little changes required.
>
> I was thinking have a boolean switch (jde-ant-use-jvm) that is
> checked to see how to invoke ant. This allows users to invoke it the
> way you intended or to allow customization totally in Emacs.
>
> I believe this is a natural evolution in jde-ant. I have no
> hesitation to provide my services to make the changes and help
> maintain
> those changes.
>
> What do you think? Is it viable?
>
>
> Douglas WF Acheson
>
> --- [EMAIL PROTECTED] wrote:
> >
> > Douglas
> >
> > Invoking the jvm from jde-ant is something that has been discussed
> > and
> > considered. However, my main objection is that Ant is a
> > cross-platform
> > project build tool that has no (and should have no) dependencies on
> > Emacs
> > or JDE. Developers need to be able to provide clear build
> > instructions to
> > the CM/build teams. Simpler instructions are better. Typically
> (or,
> > at
> > least, in my experience) a shell script is used to hide some of the
> > complexity of passing arguments to java/Ant. Most teams probably
> > just use
> > the default shell scripts that are provided with Ant (I do :).
> >
> > I don't want to seem stubborn/bull-headed/pedantic, but my
> > inclination is
> > to keep jde-ant simple, but convenient, as far as invoking Ant
> > builds.
> > Once you have jde-ant invoking Ant through the vm, you introduce
> all
> > kinds
> > of additional complexity--what VM to use?, should one use Beanshell
> > to do
> > the invocation?, where are the required .jar files (ant.jar,
> > xerces.jar...)? etc.--that I think is desirable to avoid.
> >
> > In your case, I think the best options are:
> > 1) put your custom tasks in a jar and add it to the ANT_HOME/lib
> > directory, or
> > 2) set your CLASSPATH environment variable to include the
> > appropriate
> > items
> > 3) edit the ant(.bat) shell script to include your classpath
> > config,
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Douglas WF
> >
> > Acheson To:
> > [EMAIL PROTECTED]
> >
> > <[EMAIL PROTECTED] cc: [EMAIL PROTECTED]
> >
> > om> Subject: Re: jde-ant
> >
> >
> >
> > 07/18/01
> >
> > 02:23 PM
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Jason,
> >
> > I think I finally understand :-) The jde-ant calls the ant.bat
> > script. Why not just have the jde-build-ant-command invoke the jvm
> > using the Ant.class. This way the call to ant is total
> customizable,
> > I
> > believe. In addition, all you have to to is change custom
> variables
> > and do not worry about the bat/sh file.
> >
> > Douglas WF Acheson
> >
> > --- Douglas WF Acheson <[EMAIL PROTECTED]> wrote:
> > > Thanks for the reply Jason,
> > >
> > > I do not mean to be a pain in the ass.
> > >
> > > Option #1, IMO, will not work as the custom variable jde-ant-args
> > is
> > > used to pass args to ant. I need to modify the classpath for the
> > JVM
> > > that runs ant.
> > >
> > > Option #2, totally agree, too much work.
> > >
> > > Option #3, IMO, is the chicken and egg problem. Need to find the
> > > class
> > > before using the class.
> > >
> > > Currently I get a class not found error when running ant as the
> JVM
> > > class loader cannot find my classes.
> > >
> > > I need to do the following:
>
=== message truncated ===
=====
Douglas WF Acheson
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
;; jde-ant.el --- Use Apache Ant to build your JDE projects
;;
;; Author: Jason Stell | [EMAIL PROTECTED]
;; Created: 19 Oct 2000
;; Version 1.3 19 June 2001
;;
;; This file is not part of Emacs
;; This program 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.
;; This program 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 this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;; Commentary:
;; This file defines jde-ant-build and some helper functions.
;; jde-ant-build uses the specified ant program/shell script to
;; execute a specified build file (in the project root).
;;
;;
;; Installation:
;; -- Make sure this file is accessible via your emacs load-path
;; -- Add the following to your .emacs
;; (require 'jde-ant)
;; -- Customize the ant variables, which can be found in the
;; jde-project group
;; -- Optionally create a keybinding for jde-ant-build
;;
;;
;; To do:
;; -- allow interactive ant target/argument specification.
;; {DONE - version 1.1}
;;
;; -- consider using jde-run-java-vm to execute Ant instead of
;; requiring a shell script.
;;
;;
;; Notes:
;; -- The JDE (Java Development Environment for Emacs) can be
;; downloaded at http://sunsite.auc.dk/jde/
;;
;; -- Apache Ant is a Java & XML build system that can be downloaded
;; at http://jakarta.apache.org/ant/
;;
;; Version History:
;;
;; -- Version 1.3 (19 June 2001)
;; : Addition of jde-ant-projecthelp to display list of targets for
;; the current buildfile.
;; -- Version 1.2 (4 June 2001)
;; : Addition of jde-ant-read-buildfile option to prompt for the buildfile
;; name -- contributed by Rob Shaw <[EMAIL PROTECTED]>
;; : Various Bug fixes contributed by Rob Shaw <[EMAIL PROTECTED]>
;; - The setting of the system property in a format other
;; than -Dname=value had the side effect of negating the -emacs
;; command line argument.
;; - The setting of the current directory to the location of the
;; JDE project file is now taking place when
;; jde-ant-enable-find is nil.
;; - The ant target is now the last thing to be appended to
;; ant command to avoid any possible confusion for ANT
;; as to what is the desired target.
;; -- Version 1.2b2 (25 May 2001)
;; : Fix to properly use the -find <buildfile> Ant switch--contributed
;; by Rob Shaw <[EMAIL PROTECTED]>.
;; -- Version 1.2b1 (23 May 2001)
;; : Added jde-ant-enable-find custom flag to use the -find switch
;; available in Ant. This overrides the requirement for a JDE
;; project file
;; : Fixed minor bug missing whitespace before -buildfile switch
;; when building the ant compile command
;; -- Version 1.1 (20 October 2000)
;; : Added interactive prompts (optional, based on customizable
;; toggles) for Ant target and additional args. Removed the
;; jde-ant-target custom variable, since this is really
;; represented by the default target in the build file.
;; : The -f switch seems to be causing problems. Removed it from
;; the default jde-ant-args.
;; : Basic changes to the way the ant command is assembled.
;;
;; -- Version 1.0 (19 October 2000)
;; Initial Version
(require 'compile)
(require 'jde)
(defcustom jde-ant-program "ant"
"*Specifies name of ant program/script."
:group 'jde-project
:type 'string)
(defcustom jde-ant-args "-emacs"
"*Specifies arguments to be passed to make program."
:group 'jde-project
:type 'string)
(defcustom jde-ant-buildfile "build.xml"
"*Specifies the default buildfile to use."
:group 'jde-project
:type 'string)
(defcustom jde-ant-read-buildfile nil
"*Specify whether to prompt for a buildfile. If non-nil, the
jde-ant-build command prompts you for an ant buildfile."
:group 'jde-project
:type 'boolean)
(defcustom jde-ant-read-target nil
"*Specify whether to prompt for a build target. If non-nil, the
jde-ant-build command prompts you for an ant target."
:group 'jde-project
:type 'boolean)
(defvar jde-ant-interactive-target ""
"Target to use for the build in place of the default target.")
(defvar jde-ant-interactive-target-arg-history nil
"History of targets entered in the minibuffer.")
(defcustom jde-ant-read-args nil
"*Specify whether to prompt for additional arguments to pass to ant. If non-nil, the
jde-ant-build command prompts you for the additional arguments."
:group 'jde-project
:type 'boolean)
(defvar jde-ant-interactive-args ""
"Additional arguments for the ant command.")
(defvar jde-ant-interactive-args-arg-history nil
"History of targets entered in the minibuffer.")
(defcustom jde-ant-enable-find nil
"*Specify whether the -find option should be specified in Ant. If non-nil, Ant
will search up the directory hierarchy from the current directory for the build
definition file. Also note that, if non-nil, this will relax the requirement for
an explicit jde project file."
:group 'jde-project
:type 'boolean)
;;; The next three custom variables and defun added by Douglas WF Acheson to
;;; allow a user to select how ant is invoked, either by script or via Java
(defcustom jde-ant-class "org.apache.tools.ant.Main"
"*Specifies class to invoke for Ant."
:group 'jde-project
:type 'string
)
(defcustom jde-ant-invocation-style (list "Script")
"*Specifies how to invoke ant. Ant can be invoked in one of two ways.
The first is via the ant script/program that comes with ant.
The second if via java; here you specify which class to start.
usually org.apache.tools.ant.Main. Using this method you must specify
the four required jar files (ant.jar, jaxp.jar, parser.jar, tools.jar
from Sun) in the jde-ant-classpath.
Script -- invokes ant using the jde-ant-build-function
Java -- invokes ant via the class defined in jde-ant-class"
:group 'jde-project
:type '(list
(radio-button-choice
(const "Script")
(const "Java")
)
)
)
(defcustom jde-ant-classpath nil
"*Specifies classpath used to invoke ant. This must include the three (3)
ant jar files ant.jar jaxp.jar and parser.jar and the tools.jar file from
the JDK."
:group 'jde-project
:type '(repeat (file :tag "Path"))
)
(defun jde-ant-build-classpath ()
"Constructs the classpath used to invoke ant."
(interactive)
(if (boundp 'jde-ant-classpath)
; then
(concat "-classpath " (jde-build-classpath jde-ant-classpath))
; else
""
) ; end if
)
;;; end of Douglas WF Acheson mod
;;; Modification to next defun by Douglas WF Acheson to allow how the ant
;;; command is invoked
(defun jde-build-ant-command (target more-args)
"Constructs the java ant command."
(let (ant-command)
(if (string= (car jde-ant-invocation-style) "Script")
; then
(setq ant-command (concat jde-ant-program " -Dbuffer=" buffer-file-name " "))
; else
(setq ant-command
(concat "java " (jde-ant-build-classpath) " " jde-ant-class " -Dbuffer="
buffer-file-name " "))
)
(if (not jde-ant-enable-find)
(if (not (string= jde-ant-buildfile ""))
(setq ant-command (concat ant-command " -buildfile " jde-ant-buildfile "
"))))
(if (not (string= jde-ant-args ""))
(setq ant-command (concat ant-command jde-ant-args " ")))
(if (not (string= more-args ""))
(setq ant-command (concat ant-command more-args " ")))
(if jde-ant-enable-find
(setq ant-command (concat ant-command " -find " jde-ant-buildfile " ")))
(if (not (string= target ""))
(setq ant-command (concat ant-command target " ")))
ant-command))
;;;###autoload
(defun jde-ant-build ()
"Build the current project using Ant."
(interactive)
(if jde-ant-read-buildfile
(setq jde-ant-buildfile
(read-from-minibuffer
"Buildfile: "
jde-ant-buildfile
nil nil
'(jde-ant-buildfile-arg-history . 1))))
(if jde-ant-read-target
(setq jde-ant-interactive-target
(read-from-minibuffer
"Target to build: "
jde-ant-interactive-target
nil nil
'(jde-ant-interactive-target-arg-history . 1))))
(if jde-ant-read-args
(setq jde-ant-interactive-args
(read-from-minibuffer
"Additional build args: "
jde-ant-interactive-args
nil nil
'(jde-ant-interactive-args-arg-history . 1))))
(let ((compile-command (jde-build-ant-command jde-ant-interactive-target
jde-ant-interactive-args)))
(when compile-command
;; Force save-some-buffers to use the minibuffer
;; to query user about whether to save modified buffers.
;; Otherwise, when user invokes the command from
;; menu, save-some-buffers tries to popup a menu
;; which seems not to be supported--at least on
;; the PC.
; (if (eq system-type 'windows-nt)
; (let ((temp (if (boundp 'last-nonmenu-event)
; last-nonmen-event
; t
; )
; )) ; (let ((temp last-nonmenu-event))
;; The next line makes emacs think that the command
;; was invoked from the minibuffer, even when it
;; is actually invoked from the menu-bar.
; (setq last-nonmenu-event t)
; (save-some-buffers (not compilation-ask-about-save) nil)
; (setq last-nonmenu-event temp))
; (save-some-buffers (not compilation-ask-about-save) nil))
(message "%s" compile-command)
(if (not jde-ant-enable-find)
(let ((default-directory (jde-find-project-file default-directory)))
(compile-internal compile-command "No more errors")))
(if jde-ant-enable-find
(compile-internal compile-command "No more errors"))
)))
;;;###autoload
(defun jde-ant-projecthelp ()
"Display Ant project help for the current project.
This will execute the Ant program with the `-projecthelp'
switch to output available targets with their descriptions
for the current buildfile. This function uses the same
rules as `jde-ant-build' for finding the buildfile."
(interactive)
(if jde-ant-read-buildfile
(setq jde-ant-buildfile
(read-from-minibuffer
"Buildfile: "
jde-ant-buildfile
nil nil
'(jde-ant-buildfile-arg-history . 1))))
(let ((projecthelp-command (jde-build-ant-command nil " -projecthelp")))
(when projecthelp-command
(message "%s" projecthelp-command)
(if (not jde-ant-enable-find)
(let ((default-directory (jde-find-project-file default-directory)))
(shell-command projecthelp-command "*Ant Project Help*"))
(shell-command projecthelp-command "*Ant Project Help*")))))
(provide 'jde-ant)
;; End of jde-ant.el