*************************************
* *
* DB/C Newsletter *
* October 2003 *
* *
*************************************
News and Comments
The software patent steamroller chugs on. The EU has just voted to
allow most software patents, similar to what the United States allows.
Many trivial software patents have been and will continue to be granted.
The effect of this will be to further big corporation hegemony over
software progress which will surely slow the pace of innovation in the
computer industry. The software patent problem is real and will affect
us all. I urge you to make your position on this issue known to your
colleagues and politicians.
This month's newsletter is about Ant, a useful tool that is part of
the standard Eclipse distribution. Ant's uses are many and varied. The
article will give you an overview of Ant's capabilities.
I'm sure that readers of dbctalk would be interested in hearing about
how you use Ant or any other tools with Eclipse/DDT, so if you have any
such stories, please share them with us at dbctalk.
don.wills@dbcsoftware.com
******************************************************************************
Ant
Ant is a build tool that was created by James Duncan Davidson. Ant
is free software that is available from the Apache Software Foundation.
Apache released version 1.1 of Ant in July 2000. Version 1.5.4 is the
current version.
A build tool is a program that reads a file containing instructions,
and then interprets and executes those instructions. Build tools are
generally used to compile and link programs into test or distribution
form. The 'make' utility found in UNIX is probably the most widely
used build tool.
These features set Ant apart from other build tools:
Ant is written in Java.
Ant uses XML files as input.
Ant is easily customizable.
Ant's input files, typically called buildfiles, are XML formatted
text files. Here is a very simple Ant buildfile that deletes all files
with the extensions of .tmp and .wrk:
There is always exactly one 'project' element within a buildfile.
There must be one or more 'target' elements within the 'project' element.
There may be any number of task elements within each 'target' element.
In the example, 'delete' is a task element. The 'default' attribute
in the project element specifies the default target to be interpreted
and executed. The default target can be overridden in the Ant start-up
command line or initialization parameters.
There are dozens of built-in Ant tasks. In addition to built-in
Ant tasks, it is easy to provide custom Ant tasks. Custom Ant tasks are
just Java classes that are subclasses of the 'org.apache.tools.ant.Task'
abstract class. Whether you write them yourself or obtain third-party
custom Ant tasks, you make custom Ant tasks available by including their
classes in the Java class path.
The book titled "Ant The Definitive Guide" by Jesse Tilly and Eric
M. Burke and published by O'Reilly is an excellent tutorial and reference
for Ant. The book provides a complete description of all built-in tasks,
as well as all other aspects of Ant.
Ant is integrated into Eclipse. Files with the '.xml' extension
cause the 'Run Ant...' menu option to be available in the Package Explorer
context menu (the right-click menu). This one of several ways that Ant
buildfiles can be run from Eclipse.
Another way to cause an Ant buildfile to be run is to run the
External Tools. This can be done from either the Run main menu item,
or from toolbar button with the little red suitcase and running person.
To cause the build file to run whenever the Eclipse 'build' happens,
add the buildfile to the list of External Tools Builders in the project
properties. Whenever a 'build' occurs (either automatically when a Save
happens or as a result of choosing 'Rebuild' from the Project item on
the main menu), your buildfile will also be run.
The rest of this article describes a more complex example of an
Ant buildfile and how it is used in Eclipse/DDT. This example can be
downloaded from the Sample Code at www.dbcsoftware.com. It is titled
"Sample Ant Buildfile". The example consists of these two files:
a buildfile named 'build.xml' and a DB/C DX source program named
'twolang.prg'. They are also shown in the text below.
The purpose of the sample buildfile is to compile all DB/C DX
source programs in a project twice - once for English and a second
time for French. Source programs are assumed to end with the '.prg'
extension. English object files will end with '.dbe' and French
object files will end with '.dbf'.
Here is 'twolang.prg':
%ifdef EN
msg init "Hello World"
%endif
%ifdef FR
msg init "Allo Monde"
%endif
display *es, msg, *w3
shutdown
Here is 'build.xml':
Compiles all files that look like *.prg in the src subdirectory under the
project into two files named *.dbe and *.dbf in the dbc subdirectory
There are two targets in this buildfile: 'clean' and 'compile'. The
'compile' target is the default. The base directory is '.' which means the
project directory. The 'description' element is for documentation and
information purpose only.
Global properties are specified by the 'property' elements. They are
property/value pairs that are immutable; once set, the value cannot be
changed. Properties can be specified on the Ant command line, effectively
overriding the definitions in the buildfile.
The 'fileset' and 'mapper' elements define groups of files that will
be used by the 'apply' task to create command lines for compilation.
Targets may be defined in any order. Eclipse allow you to specify
which targets are run and in what order. There is also a 'depends'
attribute which can be used in a 'target' element to cause another target
to be run (our example doesn't use 'depends'). Our first target is named
'clean'; it deletes all '.dbe' and '.dbf' files from the dbc subdirectory.
The 'compile' target does the compilation. It has two tasks - one for each
language. The 'apply' task is a built-in Ant task the runs an executable
program outside of Java. In our example, it runs the compiler.
Ant is a very useful tool that you should consider adding to your
personal software toolbox. Have fun!
******************************************************************************
DB/C DX Class Schedule
Class: DB/C DX Fundamentals
Date: December, 2003
Location: Oak Brook, Illinois
For information, send email to admin@dbcsoftware.com.
******************************************************************************
Subscribing to the DB/C Newsletter
If you don't already have the DB/C Newsletter delivered to your email
address and would like to have it emailed to you monthly, just send an
email message to 'dbcnews-subscribe@dbcsoftware.com'. The newsletter will
be delivered to the email address from which the message was sent.