ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gleb Frank <fr...@KSL.Stanford.EDU>
Subject File dependency (make rule?) task definition
Date Thu, 17 Feb 2000 13:22:14 GMT
Here is a task definition that might be useful to people that have
non-Java modules in their projects.

While Ant's javac task compiles files only when needed, and several other
built-in tasks only execute when actually necessary, this is not the case
with some of the other tasks; in particular, exec. That means that if you
have non-java targets in your project, you often are forced to rebuild
them every time. Which is a pain, especially if a lot of stuff depends on
them and therefore has to be rebuilt as well.

Hence the attached task definition. It's roughly equivalent to a make rule
(remember make?). It compares a list of targets (dependent files) and a
list of sources (primary files) and executes a subtask whenever
any of the sources is newer than any of the targets. 

Attributes:

tgts: a list of dependent files.
sources: a list of primary files. 
subtask: an Ant target that gets executed when tgts need updating.
delim (optional): the string containing delimiter characters for lists in
tgts and sources. Default value: ",".

Example of usage:
<project name="foo" default="parser" basedir=".">

  <target name="init">
    <taskdef name="filedep"
class="org.apache.tools.ant.taskdefs.FileDependency"/>
  </target>  

  <target name="parser">
    <filedep tgts="Parser.java;ParserTokenTypes.java;Lexer.java"
         sources="Parser.g" 
         delim=";"
         subtask="antlr"/>

  <target name="antlr">
    <exec dir="${basedir}" command="java antlr.Tool Parser.g"/>
  </target>  
</project>

(And in case you're curious, the Java class in this particular example
can't be called using the java task, because the damn thing calls
System.exit().)

Hopefully, this can make the transition from "make" easier for some
people.

Gleb

Mime
View raw message