Emacs and Antmod

Author: Arjen Wiersma

This document explains how one can utilize Antmod with GNU Emacs (XEmacs is untested).

Required files

You will need:

  • The "antmod.el" file available in your Antmod distribution (${ANTMOD_HOME}/resources/emacs/antmod.el)
  • Working JDEE with all of it's prerequisites.

Put your antmod.el into your elisp (~/.elisp) directory.

The software is tested on GNU Emacs 21.3.1 with JDE 2.3.4 and antmod CVS.

Setting up the systems

Setting up GNU Emacs

In order to utilize antmod you will need to configure your Emacs to load it for you, or you need to load it manually with M-x load-file.

;; Assuming you installed JDE per instructions...
(setq load-path (cons "~/.elisp) load-path))
(require 'antmod)

Setting up Antmod

To setup antmod you will need to create an ~/.antmodrc file with the following contents (adjusted to your environment of course).

antmod.checkoutdir=/home/johndoe/chkout
antmod.repositories.default=scm:svn:http://svnserver/

Using antmod in Emacs

Getting the release descriptors

In order to actually check out a release from SVN you will need a list of release descriptors. These are normally handled by antmod transparently, however to support the word completion features in Emacs we need to pre-fetch them.

Run M-x antmod-update-release-list to fetch the release descriptor list.

Checking out a release

Now that you have a list of release descriptors; we can check out a release for editing. When you run M-x antmod-co-release you will be prompted for the name of a release, this input is limited to the releases that Emacs can find in your antmod-releases directory (the antmod.descriptor.xml.localdir entry in your .antmodrc).

After entering a release name Emacs will ask you what version you want to check out. This list is also limited to the versions for which a release descriptor is available.

Setting up your editing environment

Emacs is setup up very general when it comes to the JDEE. In order to be usefull in the JDEE you need to perform several customizations. Luckily the structure that antmod adheres is standardized for us, so we can automagically create these customization files.

Run M-x antmod-make-jdee-project-files to create these files. Whenever you check out a new release, or add jars to your current release you will need to rebuild the JDEE project files.

You are now ready to edit your files.

Compiling your files

The normal jde-ant-build command will build the specific module you are working in for you, however compiling the complete release proved to be tedious.

The M-x antmod-build-release command provides the logic necessary to compile an entire release and is the suggested way to build your release. It actually uses the dist target to build the release and create all necessary distribution files.

Cleaning up

Just as with compiling of a complete release there is a function for cleaning a release M-x antmod-clean-release. The normal jde-ant functions allow you to do it on a module basis, so no support has been built in for that.

Installing a release

Emacs allows you to invoke the installation procedure that invokes the "ant deploy" functionality in the release's build file from within your editing facility using M-x antmod-install-release.

Specialized editing facilities

Emacs is capable of doing so much more then editing, several functions exist to make your live in Emacs with Java even easier.

Keyword completion

In order to speed up editing you can utilize the keyword completion service in Emacs. By invoking M-x jde-complete-in-line, default bound to C-c C-v ., or M-x jde-complete-minibuf which is unbound by default.

These commands start the Beanshell to examine classes for completion possibilities, thus providing the same possibilities as a modern IDE.

Finding unused functions

By invoking M-x antmod-make-xref-db you can create a cross reference database for your release. This database allows you to do several very cool things; one of them being the ability to find unused functions.

When visiting a java file in your project you can run *M-x jde-xref-list-uncalled-functions* and the cross reference database will tell you what functions and variables are unused.

note: when using reflection you will not be able to detect unused functions as well as the top level functions in a webservice will also always be uncalled.

Display a call tree

To get insight into where a certain function gets used you can create a call tree based on the cross referencing database. By calling *M-x jde-xref-display-call-tree* within a function you will see where this function is called from.

An Example:

[-] void org.antmod.server.soap.utils.Attribute.Attribute(boolean,String,int,int,String[])
 | [+] void org.antmod.server.soap.scm.maps.ChangeRequest.validate()
 | [-] void org.antmod.server.soap.scm.maps.AutorisationData.validate()
 |  ` [-] HashSet org.antmod.server.soap.scm.DataValidator.validate(AutorisationData,String)
 |     ` [+] void org.antmod.server.soap.scm.maps.ScmSignupData.validate()
 | [+] void org.antmod.server.soap.UserAccountData.validate()
 | [+] void org.antmod.server.soap.TrackingData.validate()
 | [+] void org.antmod.server.soap.TrackingData.validate()
 | [+] void org.antmod.server.soap.DiscountData.validate()
 | [+] void org.antmod.server.soap.DiscountData.validate()
 | [+] void org.antmod.server.soap.DiscountData.validate()
 | [+] void org.antmod.server.soap.ContactData.validate()
 ` [+] void org.antmod.server.soap.BillingData.validate()

As you can see, the Attribute constructor Attribute(boolean,String,int,int,String[]) is called from AutorisationData.validate() which in turn is called from DataValidator.validate(AutorisationData,String) which is called from ScmSignupData.validate()... etc.

Troubleshooting

Lots of things can go wrong of course...

Antmod configuration

In order to verify that Emacs has fully understood your antmod configuration you can see the internal structure of antmod.el's rendition of the properties. Before running this command please switch to your scratch buffer since it will print to the current location of your cursor.

Run M-x antmod-dump-config to see all the settings for antmod, variables expanded.