You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ceki Gulcu <cg...@urbanet.ch> on 2000/12/28 01:07:36 UTC

Two consequtive ifs


Hello,

Sorry if this question has been already asked before. I have a target that 
depends on the existence of JNDI and JMS libraries, as in:

<project name="log4j" default="compile" basedir="." >
	<target name="init">
		<tstamp />
		<property name="srcdir" value="." />
		<property name="classes" value="classes" />
		<property name="stem" value="org/apache/log4j" />
		<property name="build.compiler" value="jikes"/>	
		<property name="version" value="1.0"/>
	
                 <available classname="javax.jms.Message"
  	                   property="jms-present"/>

                 <available classname="javax.naming.Context"
  	                   property="jndi-present"/>
         </target>

    ... removed stuff

             <target name="compile.jms" depends="init" if="jms-present">
             <echo message="Really compiling JMS dependent code." />
	    <javac
		   srcdir="${srcdir}"
		   destdir="${classes}"
		   includes="${stem}/net/JMS*.java"
		   classpath="${classpath}"/>
	</target>
</project>

However, since ANT does not allow two consecutive if attributes, I can only 
check for the presence of JMS. How can I check for the presence of JNDI and 
execute the "compile.jms" target only if both JMS and JNDI are present? 
Thanks in advance for your help, Ceki


Re: Two consequtive ifs

Posted by Ceki Gulcu <cg...@urbanet.ch>.
Thanks for the info. Happy new year, Ceki

At 16:11 29.12.2000 -0500, you wrote:
>It would be nice for the 'if' logic to support compound conditionals:
>
>if="(condition1 and condition2) or condition3 and not condition4"
>
>Probably should get rid of the "unless" attribute altogether....
>
>etc.
>
>However, that is not currently the case.
>
>So, unfortunately, you are left with having to do things in a weird
>non-intuitive chained way, and you can't rely on having checked
>the variables in a one time, init step.  This is because there is
>no conditional flow control, other than <available> and <uptodate>.
>
><target name="do_the_work" depends="check_jms_after_checking_jndi" 
>if="jms-and-jndi-present">
>....
></target>
>
><target name="check_jms_after_checking_jndi" depends="check_jndi" 
>if="jndi-present">
>
>                   <available classname="javax.jms.Message"
>                       property="jms-and-jndi-present"/>
></target>
>
><target name="check_jndi">
>                   <available classname="javax.naming.Context"
>                       property="jndi-present"/>
></target>
>
>Jason
>
>----- Original Message -----
>From: "Ceki Gulcu" <cg...@urbanet.ch>
>To: <an...@jakarta.apache.org>
>Sent: Wednesday, December 27, 2000 7:07 PM
>Subject: Two consequtive ifs
>
>
> >
> >
> > Hello,
> >
> > Sorry if this question has been already asked before. I have a target that
> > depends on the existence of JNDI and JMS libraries, as in:
> >
> > <project name="log4j" default="compile" basedir="." >
> > <target name="init">
> > <tstamp />
> > <property name="srcdir" value="." />
> > <property name="classes" value="classes" />
> > <property name="stem" value="org/apache/log4j" />
> > <property name="build.compiler" value="jikes"/>
> > <property name="version" value="1.0"/>
> >
> >                  <available classname="javax.jms.Message"
> >                      property="jms-present"/>
> >
> >                  <available classname="javax.naming.Context"
> >                      property="jndi-present"/>
> >          </target>
> >
> >     ... removed stuff
> >
> >              <target name="compile.jms" depends="init" if="jms-present">
> >              <echo message="Really compiling JMS dependent code." />
> >     <javac
> >    srcdir="${srcdir}"
> >    destdir="${classes}"
> >    includes="${stem}/net/JMS*.java"
> >    classpath="${classpath}"/>
> > </target>
> > </project>
> >
> > However, since ANT does not allow two consecutive if attributes, I can 
> only
> > check for the presence of JMS. How can I check for the presence of JNDI 
> and
> > execute the "compile.jms" target only if both JMS and JNDI are present?
> > Thanks in advance for your help, Ceki
> >


Re: Two consequtive ifs

Posted by Jason Rosenberg <ja...@squaretrade.com>.
It would be nice for the 'if' logic to support compound conditionals:

if="(condition1 and condition2) or condition3 and not condition4"

Probably should get rid of the "unless" attribute altogether....

etc.

However, that is not currently the case.

So, unfortunately, you are left with having to do things in a weird
non-intuitive chained way, and you can't rely on having checked
the variables in a one time, init step.  This is because there is
no conditional flow control, other than <available> and <uptodate>.

<target name="do_the_work" depends="check_jms_after_checking_jndi" if="jms-and-jndi-present">
....
</target>

<target name="check_jms_after_checking_jndi" depends="check_jndi" if="jndi-present">

                  <available classname="javax.jms.Message"
                      property="jms-and-jndi-present"/>
</target>

<target name="check_jndi">
                  <available classname="javax.naming.Context"
                      property="jndi-present"/>
</target>

Jason

----- Original Message ----- 
From: "Ceki Gulcu" <cg...@urbanet.ch>
To: <an...@jakarta.apache.org>
Sent: Wednesday, December 27, 2000 7:07 PM
Subject: Two consequtive ifs


> 
> 
> Hello,
> 
> Sorry if this question has been already asked before. I have a target that 
> depends on the existence of JNDI and JMS libraries, as in:
> 
> <project name="log4j" default="compile" basedir="." >
> <target name="init">
> <tstamp />
> <property name="srcdir" value="." />
> <property name="classes" value="classes" />
> <property name="stem" value="org/apache/log4j" />
> <property name="build.compiler" value="jikes"/> 
> <property name="version" value="1.0"/>
> 
>                  <available classname="javax.jms.Message"
>                      property="jms-present"/>
> 
>                  <available classname="javax.naming.Context"
>                      property="jndi-present"/>
>          </target>
> 
>     ... removed stuff
> 
>              <target name="compile.jms" depends="init" if="jms-present">
>              <echo message="Really compiling JMS dependent code." />
>     <javac
>    srcdir="${srcdir}"
>    destdir="${classes}"
>    includes="${stem}/net/JMS*.java"
>    classpath="${classpath}"/>
> </target>
> </project>
> 
> However, since ANT does not allow two consecutive if attributes, I can only 
> check for the presence of JMS. How can I check for the presence of JNDI and 
> execute the "compile.jms" target only if both JMS and JNDI are present? 
> Thanks in advance for your help, Ceki
> 


Re: Two consequtive ifs

Posted by Peter Donald <do...@apache.org>.
At 02:46  28/12/00 +0100, Stefan Schmitt wrote:
>From: "Ceki Gulcu" <cg...@urbanet.ch>
>Subject: Two consequtive ifs
>
>Hi
>I do not have a smart solution. It's only a quick hack.
>You can call your compile target from another target like the following
>sample
>
><target name="first" if="firstprop">
>    <antcall target="second"/>
></target>
>
><target name="second" if="secondprop">
>    .....
></target>
>
>
>The target named second is accessed if firstprop and secondprop are set.

Alternatively theres another hack ...

<target name="first" if="firstprop">
    <property name="secondprop" value="true"/>
</target>

<target name="second" if="secondprop" depends="first">
    .....
</target>

Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*


Re: Two consequtive ifs

Posted by Stefan Schmitt <ss...@raleigh.ibm.com>.
From: "Ceki Gulcu" <cg...@urbanet.ch>
Subject: Two consequtive ifs

Hi
I do not have a smart solution. It's only a quick hack.
You can call your compile target from another target like the following
sample

<target name="first" if="firstprop">
    <antcall target="second"/>
</target>

<target name="second" if="secondprop">
    .....
</target>


The target named second is accessed if firstprop and secondprop are set.

Yours
Stefan S


Re: Two consequtive ifs

Posted by Jason Rosenberg <ja...@squaretrade.com>.
----- Original Message ----- 
From: "Ceki Gulcu" <cg...@urbanet.ch>
To: <an...@jakarta.apache.org>
Sent: Wednesday, December 27, 2000 7:07 PM
Subject: Two consequtive ifs


> 
> 
> Hello,
> 
> Sorry if this question has been already asked before. I have a target that 
> depends on the existence of JNDI and JMS libraries, as in:
> 
> <project name="log4j" default="compile" basedir="." >
> <target name="init">
> <tstamp />
> <property name="srcdir" value="." />
> <property name="classes" value="classes" />
> <property name="stem" value="org/apache/log4j" />
> <property name="build.compiler" value="jikes"/> 
> <property name="version" value="1.0"/>
> 
>                  <available classname="javax.jms.Message"
>                      property="jms-present"/>
> 
>                  <available classname="javax.naming.Context"
>                      property="jndi-present"/>
>          </target>
> 
>     ... removed stuff
> 
>              <target name="compile.jms" depends="init" if="jms-present">
>              <echo message="Really compiling JMS dependent code." />
>     <javac
>    srcdir="${srcdir}"
>    destdir="${classes}"
>    includes="${stem}/net/JMS*.java"
>    classpath="${classpath}"/>
> </target>
> </project>
> 
> However, since ANT does not allow two consecutive if attributes, I can only 
> check for the presence of JMS. How can I check for the presence of JNDI and 
> execute the "compile.jms" target only if both JMS and JNDI are present? 
> Thanks in advance for your help, Ceki
> 

It would be nice for the 'if' logic to support compound conditionals:

if="(condition1 and condition2) or condition3 and not condition4"

Probably should get rid of the "unless" attribute altogether....

etc.

However, that is not currently the case.

So, unfortunately, you are left with having to do things in a weird
non-intuitive chained way, and you can't rely on having checked
the variables in a one time, init step.  This is because there is
no conditional flow control, other than <available> and <uptodate>.

<target name="do_the_work" depends="check_jms_after_checking_jndi" if="jms-and-jndi-present">
....
</target>

<target name="check_jms_after_checking_jndi" depends="check_jndi" if="jndi-present">

                  <available classname="javax.jms.Message"
                      property="jms-and-jndi-present"/>
</target>

<target name="check_jndi">
                  <available classname="javax.naming.Context"
                      property="jndi-present"/>
</target>

Jason


















Re: Two consequtive ifs

Posted by Jason Rosenberg <ja...@squaretrade.com>.
----- Original Message ----- 
From: "Ceki Gulcu" <cg...@urbanet.ch>
To: <an...@jakarta.apache.org>
Sent: Wednesday, December 27, 2000 7:07 PM
Subject: Two consequtive ifs


> 
> 
> Hello,
> 
> Sorry if this question has been already asked before. I have a target that 
> depends on the existence of JNDI and JMS libraries, as in:
> 
> <project name="log4j" default="compile" basedir="." >
> <target name="init">
> <tstamp />
> <property name="srcdir" value="." />
> <property name="classes" value="classes" />
> <property name="stem" value="org/apache/log4j" />
> <property name="build.compiler" value="jikes"/> 
> <property name="version" value="1.0"/>
> 
>                  <available classname="javax.jms.Message"
>                      property="jms-present"/>
> 
>                  <available classname="javax.naming.Context"
>                      property="jndi-present"/>
>          </target>
> 
>     ... removed stuff
> 
>              <target name="compile.jms" depends="init" if="jms-present">
>              <echo message="Really compiling JMS dependent code." />
>     <javac
>    srcdir="${srcdir}"
>    destdir="${classes}"
>    includes="${stem}/net/JMS*.java"
>    classpath="${classpath}"/>
> </target>
> </project>
> 
> However, since ANT does not allow two consecutive if attributes, I can only 
> check for the presence of JMS. How can I check for the presence of JNDI and 
> execute the "compile.jms" target only if both JMS and JNDI are present? 
> Thanks in advance for your help, Ceki
> 

It would be nice for the 'if' logic to support compound conditionals:

if="(condition1 and condition2) or condition3 and not condition4"

Probably should get rid of the "unless" attribute altogether....

etc.

However, that is not currently the case.

So, unfortunately, you are left with having to do things in a weird
non-intuitive chained way, and you can't rely on having checked
the variables in a one time, init step.  This is because there is
no conditional flow control, other than <available> and <uptodate>.

<target name="do_the_work" depends="check_jms_after_checking_jndi" if="jms-and-jndi-present">
....
</target>

<target name="check_jms_after_checking_jndi" depends="check_jndi" if="jndi-present">

                  <available classname="javax.jms.Message"
                      property="jms-and-jndi-present"/>
</target>

<target name="check_jndi">
                  <available classname="javax.naming.Context"
                      property="jndi-present"/>
</target>

Jason