The Artima Developer Community
Sponsored Link

Java Answers Forum
File Dependencies with Ant

3 replies on 1 page. Most recent reply: Apr 17, 2002 8:48 AM by Bill Venners

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

File Dependencies with Ant Posted: Apr 7, 2002 3:10 PM
Reply to this message Reply
Advertisement
I am trying to convert most of my makefiles to ant build files, and I am a bit stumped as how to do file dependencies. In one of my makefiles I have this:

Page.java: page.dtd page.xjs
java -jar $(xjcjar) page.dtd page.xjs

Basically, the Page.java file is generated by JAXB from the page.dtd DTD and page.xjs directive file. I don't want Page.java regenerated unless it is older than either page.dtd or page.xjs.

In my ant build script, I've made a target called pageparser, which correctly runs JAXB and generates my parser (which includes Page.java):

<target name="pageparser" depends="prepare">
<java jar="${xjcjar}" fork="true">
<arg line="${pagedtd} page.xjs" />
</java>
</target>

Trouble is I'm not sure how to get this target to be built only if Page.java is older than either page.dtd or page.xjs. I fear I need to use an if attribute in the target, something like this:

<target name="pageparser" if="parseroutofdate"
depends="prepare">

This would work if I somehow was able to set a property conditionally, which I also can't figure out how to do. It also seems a very convoluted way to do file dependencies.

I did discover the dependset task, and added this to my prepare target. I think this will delete Page.java if it is older than either page.dtd or page.xjs:

<dependset>
<srcfilelist
dir="$ tddir "
files="page.dtd" />
<srcfilelist
dir="."
files="page.xjs" />
<targetfilelist
dir="."
files="Page.java" />
</dependset>

The trouble here is that I don't really need to delete the Page.java file, just regenerate it by running the pageparser target.

Any ideas?


Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: File Dependencies with Ant Posted: Apr 8, 2002 6:41 AM
Reply to this message Reply
Hi Bill,

I suppose you have read this ?
http://jakarta.apache.org/ant/manual/index.html
More spcifically this one :
http://jakarta.apache.org/ant/manual/CoreTasks/dependset.html

Even on big project I usually delete all the targets & keep the dependency list very small !

Thomas,
tsmets @ lautre . net

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: File Dependencies with Ant Posted: Apr 8, 2002 11:48 AM
Reply to this message Reply
> Hi Bill,
>
> I suppose you have read this ?
> http://jakarta.apache.org/ant/manual/index.html
> More spcifically this one :
> http://jakarta.apache.org/ant/manual/CoreTasks/depends
> t.html
>
Yes, I've gone through the entire manual and coded up a DependSet task to delete Page.java (included in my original post). The trouble with DependSet is it just deletes the files. I'm still left with no way to conditionally run JAXB to generate them.

This document is good:

http://jakarta.apache.org/ant/ant_in_anger.html

It mentions that:

Some of the features of make, specifically inference rules and dependency checking are not included in ant. That's because they are 'different' ways of doing a build. Make requires you to state dependencies and the build steps, ant wants you to state tasks and the order between them, the tasks themselves can do depedency checking or not. A full java build using Jikes is so fast that dependency checking is relatively moot, while many of the other tasks (but not all), compare the timestamp of the source file with that of the destination file before acting.

> Even on big project I usually delete all the targets
> & keep the dependency list very small !
>
Yeah, but my particular situation is that the jar file being built by this one line in my makefile is used to generate every page on this website (including the one you're looking at). So whenever that jar file changes, I have to rebuild my entire website. It is not workable to just say I'll rebuild the entire website every time I do anything, because there are over 12,000 pages.

The Ant in Anger doc makes it clear that it is up to the tasks to do their own dependency checking, and my problem is that JAXB doesn't do any dependency checking. So what I think I need is a task like DependSet that, instead of deleting the target files if any are older than any source files, it runs a different task to regenerate the target files. I'm surprised no one has run across this before, but I don't see such a task anywhere. I may end up taking DependSet and hacking it until it does the thing I need. If anyone knows of such a task already in existence, please post its whereabouts here.

Thanks.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: File Dependencies with Ant Posted: Apr 17, 2002 8:48 AM
Reply to this message Reply
> The Ant in Anger doc makes it clear that it is up to
> the tasks to do their own dependency checking, and my
> problem is that JAXB doesn't do any dependency
> checking. So what I think I need is a task like
> DependSet that, instead of deleting the target files
> if any are older than any source files, it runs a
> different task to regenerate the target files. I'm
> surprised no one has run across this before, but I
> don't see such a task anywhere. I may end up taking
> DependSet and hacking it until it does the thing I
> need. If anyone knows of such a task already in
> existence, please post its whereabouts here.
>
Turns out the needed task was already written and part of the core set of ant tasks. It is called UpToDate. UpToDate sets a property if target files are at a later date than source files. I can use that to conditionally run any other task by making execution of those tasks dependent on properties set by UpDoDate.

Flat View: This topic has 3 replies on 1 page
Topic: client/server Previous Topic   Next Topic Topic: inner classes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use