You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Steve Roy <sr...@mac.com> on 2006/01/07 03:24:43 UTC

Perform tasks conditionally

Hello,

I have been using Ant for about a year but I still feel like I am a 
newbie, and maybe this explains my question, but you tell me.

I have a script where I compile the sources for my project and jar it 
all up. This works well but I'm looking at adding an optimization where 
the Jar task would be skipped if no source file had to be recompiled. 
How could I do that?

I looked at the Condition task, but that didn't light up anything in my 
mind. I'm guessing that I need to find out from the Javac task how many 
files had to be compiled, but how would I do that?

Steve

-- 
Steve Roy <sr...@mac.com>
<http://homepage.mac.com/sroy>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Perform tasks conditionally

Posted by glenn opdycke-hansen <gl...@gmail.com>.
I would look at uptodate
http://ant.apache.org/manual/CoreTasks/uptodate.html

That would test file timestamps and set a property.
I am not sure what you want to do.

--glenn

On 1/6/06, Steve Roy <sr...@mac.com> wrote:
> Hello,
>
> I have been using Ant for about a year but I still feel like I am a
> newbie, and maybe this explains my question, but you tell me.
>
> I have a script where I compile the sources for my project and jar it
> all up. This works well but I'm looking at adding an optimization where
> the Jar task would be skipped if no source file had to be recompiled.
> How could I do that?
>
> I looked at the Condition task, but that didn't light up anything in my
> mind. I'm guessing that I need to find out from the Javac task how many
> files had to be compiled, but how would I do that?
>
> Steve
>
> --
> Steve Roy <sr...@mac.com>
> <http://homepage.mac.com/sroy>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Perform tasks conditionally

Posted by Clifton Craig <cc...@gbg.com>.
Steve,

The jar task compares the timestamps of all the files you wish to jar to the 
preexisting complete jar (if it had been run before) and will not execute if 
none of them are later than the timestamp of the existing jar. Working 
backwards from there you have the javac task which compares the timestamps of 
all the source files with their corresponding class files and skips the ones 
that it doesn't need to compile. The end result is if you touch any source 
file it will trigger a recompile which will trigger a re-jarring. In fact all 
(most?) of ant's tasks are designed this way with optimization for 
incremental builds. My take is that you have changed some default of the 
javac task that could be always recompiling your source or maybe you-re using 
some force attribute on your jar task? Could it be that maybe you're using a 
copy task (copying configs to the output folder) with a force attribute which 
would also trigger a rejarring as the copied files would appear newer than 
the jar? Maybe you're just getting confused by the build logs which log the 
jar task even when it skips operation? Careful starting out new as I was in 
the same ship a couple years ago and had the same problem. I can't remember 
how but I think I was dumping my class output somewhere special and telling 
the javac task to use something different for figuring out what to compile. 
The heart of the problem was that I was forcing something where I didn't 
understand the default behaviour and caused a whole lot of problems down he 
line when I had to maintain it.
-- 
Clifton C. Craig, Software Engineer
Intelligent Computer Systems -  A Division of GBG
ccc@icsaward.com
ccraig@gbg.com

On Friday 06 January 2006 9:24 pm, Steve Roy wrote:
> Hello,
>
> I have been using Ant for about a year but I still feel like I am a
> newbie, and maybe this explains my question, but you tell me.
>
> I have a script where I compile the sources for my project and jar it
> all up. This works well but I'm looking at adding an optimization where
> the Jar task would be skipped if no source file had to be recompiled.
> How could I do that?
>
> I looked at the Condition task, but that didn't light up anything in my
> mind. I'm guessing that I need to find out from the Javac task how many
> files had to be compiled, but how would I do that?
>
> Steve


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Perform tasks conditionally

Posted by Dominique Devienne <dd...@gmail.com>.
On 1/6/06, Jeffrey E Care <ca...@us.ibm.com> wrote:
> The jar task already figures this out for you.

Indeed it does. If Jar runs anyway, it could be because you generate a
manifest dynamically, with a date or version number that changes on
every build, forcing jar to always run. Otherwise <jar> is a "smart"
task, which only rebuilds the jar if it notices files have changed.
--DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Perform tasks conditionally

Posted by Jeffrey E Care <ca...@us.ibm.com>.
The jar task already figures this out for you.

-- 
Jeffrey E. Care (carej@us.ibm.com)
WebSphere v7 Release Engineer
WebSphere Build Tooling Lead (Project Mantis)


Steve Roy <sr...@mac.com> wrote on 01/06/2006 09:24:43 PM:

> Hello,
> 
> I have been using Ant for about a year but I still feel like I am a 
> newbie, and maybe this explains my question, but you tell me.
> 
> I have a script where I compile the sources for my project and jar it 
> all up. This works well but I'm looking at adding an optimization where 
> the Jar task would be skipped if no source file had to be recompiled. 
> How could I do that?
> 
> I looked at the Condition task, but that didn't light up anything in my 
> mind. I'm guessing that I need to find out from the Javac task how many 
> files had to be compiled, but how would I do that?
> 
> Steve
> 
> -- 
> Steve Roy <sr...@mac.com>
> <http://homepage.mac.com/sroy>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>