import-bot (20211) [Avatar] Offline
#1
[Originally posted by kwutzke]

Hi!

How do print conditional info to the screen with <echo>?

I check a few things within tasks, mostly using the following:

<property name="local.bootstrap.class">
value="$org.apache.catalina.startup.Bootstrap"/>
<property name="local.bootstrap.jar.file">
location="${env.CATALINA_HOME}/bin/bootstrap.jar"/>

<target name="check-bootstrap-local" description="Checks Tomcat bootstrap.">

<available property="local.bootstrap.jar" file="${local.bootstrap.jar.file}"/>
<fail unless="local.bootstrap.jar" message="Local Tomcat bootstrap jar file<br /> '${local.bootstrap.jar.file}' *not* found!"/>
<echo message="Local Tomcat bootstrap jar file found at<br /> '${local.bootstrap.jar.file}'."/>

<available property="local.bootstrap" classname="${tomcat.bootstrap.class}">
<classpath refid="local.bootstrap.classpath"/>
</available>
<fail unless="local.bootstrap" message="Local Tomcat bootstrap class<br /> '${tomcat.bootstrap.class}' *not* found in ${local.bootstrap.jar.file}!"/>
<echo message="Local Tomcat class '${tomcat.bootstrap.class}' found in<br /> ${local.bootstrap.jar.file}."/>
</target>

This basically works OK, if the task is supposed to fail on some condition. On
fail the fail message is printed, otherwise it runs on to the echo and
continues.

But how do I simply print to the console for non-failing task, e.g. a task
that determines, whether the local Tomcat server is running or not? Both
conditions are basically non-critical, if the server is already running, then
let's celebrate, if not, run a task to start it up. Anyway, I would like to
print some info to the screen!

Conditional echos here:

<target name="check-reach-local" description="Try to reach local Tomcat.">
<waitfor timeoutproperty="local.unreachable" maxwait="5" maxwaitunit="second">
<socket server="${local.server}" port="${local.port}"/>
</waitfor>
<!-- ***print info on server status*** -->
<!-- if running print "Tomcat is running." -->
<!-- if not running print "Tomcat is not running! Starting up server." -->
</target>

On page 255, you wrote resorting to <if> >then> <else> tasks with the contrib
project is not the best solution... So ,how do I do this in plain Ant style,
*without* having to create dozens of conditional echo tasks...

Is it possible?

Karsten
import-bot (20211) [Avatar] Offline
#2
Re: Conditional echos
[Originally posted by steve_l]

You have conditional <targets> instead. Turn to P77 to see these.
import-bot (20211) [Avatar] Offline
#3
Re: Conditional echos
[Originally posted by kwutzke]

> This issue is being actively discussed at this very moment on the Ant user
> list. Please take this disucssion there. Adding if/unless to echo is fine
> with me.
>

Pheeeew!

> Keep in mind that this forum is to discuss our book and any errata or
> questions about it, not to make Ant feature requests! smilie

OK! smilie
Karsten
import-bot (20211) [Avatar] Offline
#4
Re: Conditional echos
[Originally posted by kwutzke]

> You have conditional <targets> instead. Turn to P77 to see these.

Yes, I know. But it's very complicated to introduce targets just to print
something. The <fail> task has been extended with the if/unless feature
recently, why not put it in <echo>, too? Both tasks are pretty similar, so it
would be an argument for the Ant developers to introduce it for <echo>. I'd
even say, they should implement it for all tasks, not necessarily targets
though.

Karsten
import-bot (20211) [Avatar] Offline
#5
Re: Conditional echos
[Originally posted by ehatcher]

This issue is being actively discussed at this very moment on the Ant user
list. Please take this disucssion there. Adding if/unless to echo is fine
with me.

Keep in mind that this forum is to discuss our book and any errata or
questions about it, not to make Ant feature requests! smilie