• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does ant know what to avoid doing?

 
paul wheaton
Trailboss
Pie
Posts: 21752
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must be having a brain fog day.
I'm trying to wrap my head around the idea of how ant knows when to avoid doing work that doesn't need to be done. I think compiling java is straightforward, but what about other stuff.
Suppose I have a directory tree full of *.xxx files. And another directory tree full of *.yyy files.
Suppose I have /src/animals/cows/bessie.xxx that has a timestamp later than /dest/animals/cows/bessie.yyy. But /src/animals/cows/gertrude.xxx has a timestamp earlier than /dest/animals/cows/gertrude.yyy. Because of this, I need to run "mash /src/animals/cows/bessie.xxx -dest /dest/animals/cows/" but not run mash for gertrude.
What ant script would do that?
 
paul wheaton
Trailboss
Pie
Posts: 21752
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To expand on my question a bit, take a look at the jar tag.
Does it just call the JDK jar stuff, or does it first figure out if it needs to do a jar at all?
 
Lewin Chan
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
Having never inspected the ant source, this won't be a definitive answer.
For any operation where there is a destination file (and source files), if the destination file is considered more recent than any of the source files, then that the operaion won't then take place.
For instance,

You may find in this instance that the jar never actually contains the files from classes2.
L
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It fully depends on how the specific task is implemented.
The jar task, for example, does try to examine wether the jar needs to be updated, but only uses time stamps for this - so if the jar file is newer than the file you want to add, it won't get added even if it isn't yet contained in the jar. Bug 10755 is about this problem - a workaround is to manipulate the time stamps using the touch task.
If a task doesn't support conditional execution, you can use the uptodate task to set a property and conditionally execute a target.
Did that help?
 
paul wheaton
Trailboss
Pie
Posts: 21752
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.
That's the answer I was hoping for: jar is not just simply called. Ant looks at the timestamps of files to see if the whole jar thing can be skipped.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic