You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by jpyork <jp...@hotmail.com> on 2008/01/23 21:50:16 UTC

Checking a property with ant

I have tried a few things today and still can't figure this out.  I have a
properties file with a setting of say test=successful and I want ant to
check the property test to make sure it is set to successful before going
on.  How do I do this?
-- 
View this message in context: http://www.nabble.com/Checking-a-property-with-ant-tp15051347p15051347.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


AW: Checking a property with ant

Posted by Knuplesch, Jürgen <Ju...@icongmbh.de>.
Alternativly use if-Task of antcontrib to do it in one step. 


-- 
Jürgen Knuplesch                    www.icongmbh.de
icon Systemhaus GmbH                Tel. +49 711 806098-275
Sophienstraße 40                    
D-70178 Stuttgart                   Fax. +49 711 806098-299

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121 
-----Ursprüngliche Nachricht-----
Von: Barry Andreasen [mailto:barry.andreasen@sentillion.com] 
Gesendet: Donnerstag, 24. Januar 2008 10:45
An: user@ant.apache.org
Betreff: RE: Checking a property with ant

This is a 2 step process.  First you need to also create a conditional property based on the value of the property test.  Then you can use that conditional property in target elements to conditionalize their execution.  For instance
 
Step 1:
<condition name="conditionOK">
    <equals arg1="${test}" arg2="successful"
</condition>
 
Step 2:
<target name="conditional_target" if=conditionOK>
   ... your target elements
</target>
 
________________________________

From: jpyork [mailto:jp_york@hotmail.com]
Sent: Wed 1/23/2008 15:50
To: user@ant.apache.org
Subject: Checking a property with ant




I have tried a few things today and still can't figure this out.  I have a properties file with a setting of say test=successful and I want ant to check the property test to make sure it is set to successful before going on.  How do I do this?
--
View this message in context: http://www.nabble.com/Checking-a-property-with-ant-tp15051347p15051347.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
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: Checking a property with ant

Posted by Barry Andreasen <ba...@sentillion.com>.
This is a 2 step process.  First you need to also create a conditional property based on the value of the property test.  Then you can use that conditional property in target elements to conditionalize their execution.  For instance
 
Step 1:
<condition name="conditionOK">
    <equals arg1="${test}" arg2="successful"
</condition>
 
Step 2:
<target name="conditional_target" if=conditionOK>
   ... your target elements
</target>
 
________________________________

From: jpyork [mailto:jp_york@hotmail.com]
Sent: Wed 1/23/2008 15:50
To: user@ant.apache.org
Subject: Checking a property with ant




I have tried a few things today and still can't figure this out.  I have a
properties file with a setting of say test=successful and I want ant to
check the property test to make sure it is set to successful before going
on.  How do I do this?
--
View this message in context: http://www.nabble.com/Checking-a-property-with-ant-tp15051347p15051347.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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





AW: Checking a property with ant

Posted by Ja...@rzf.fin-nrw.de.
>     <condition property="buildfailed">
> 		<equals arg1="${buildresults}" arg2="failed"/> 
> 	</condition>

Translation:

if ( buildresults == "failed" ) {
    buildfailed = true;
}
 
// otherwise 'buildfailed' is not set


> 	<target name="buildresults" unless="buildfailed">
> 			<fail message="Check deploy script for error" />
> 	</target>


public target buildresults() {
	// unless clause
	if ( buildfailed != null ) {
		return;
	}
	fail("Check deploy script for error");
}



Jan

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


Re: Checking a property with ant

Posted by Gilbert Rebhan <an...@schillbaer.de>.
>         <condition property="buildfailed">
> 		<equals arg1="${buildresults}" arg2="failed"/> 
> 	</condition>
> 	
> 	<target name="buildresults" unless="buildfailed">
> 			<fail message="Check deploy script for error" />
> 	</target>
> 
> If I am understanding this correctly then, the above should reference the
> buildresults property that is held in a property file and if it is set to
> failed...the script should fail.  The issue is that when the buildresults is
> set to successful, the build still fails.  
> 
> Anyone see what I am doing wrong?

your condition is right, you check whether your
${buildresults} property (set in a property file or
otherwise) has the value "failed" and if yes the
property ${buildfailed} is set.

but =

<target name="buildresults" unless="buildfailed">

means = run that target unless your ${buildfailed} property
is set, regardless what value it holds

so you need to use =
<target name="buildresults" if="buildfailed">

instead.

Regards, Gilbert



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


Re: Checking a property with ant

Posted by jpyork <jp...@hotmail.com>.
	This is what I have:


        <condition property="buildfailed">
		<equals arg1="${buildresults}" arg2="failed"/> 
	</condition>
	
	<target name="buildresults" unless="buildfailed">
			<fail message="Check deploy script for error" />
	</target>

If I am understanding this correctly then, the above should reference the
buildresults property that is held in a property file and if it is set to
failed...the script should fail.  The issue is that when the buildresults is
set to successful, the build still fails.  

Anyone see what I am doing wrong?






jpyork wrote:
> 
> I have tried a few things today and still can't figure this out.  I have a
> properties file with a setting of say test=successful and I want ant to
> check the property test to make sure it is set to successful before going
> on.  How do I do this?
> 

-- 
View this message in context: http://www.nabble.com/Checking-a-property-with-ant-tp15051347p15095025.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: AW: Checking a property with ant

Posted by Gilbert Rebhan <an...@schillbaer.de>.

Jan.Materne@rzf.fin-nrw.de schrieb:
> But dont forget: <target if|unless> checks whether a property with
> the given name is set/not-set.

therefore in my example the property thats' used
afterwards with target if|unless is set via
condition + equals ... ;-)

> <property name="foo" value="true"/>
> <target name="foo" unless="foo">
>     <echo>I will be executed</echo>
> </target>
> 
> <property name="bar" value="false"/>
> <target name="bar" if="bar">
>     <echo>I will be executed</echo>
> </target>

so afterwards you're able to react if| unless
that property is set after your gusto

Regards, Gilbert

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


Re: AW: Checking a property with ant

Posted by vvitayau <va...@gmail.com>.
I got failure when
                command="find . -maxdepth 1 -name ${reporting.db}.\*\.001 |
wc -l"/>

... the trick is why doesn't 0 -eq 0 is when it has EOL so adding pipe xargs
echo -n resolved this bug

hope this helps test your condition.

    <target name="db2-test">
        <sshexec host="${reporting.host}" trust="true"
username="${reporting.user}" password="${reporting.password}"
                outputproperty="reporting.backup.count" failonerror="true"
                command="find . -maxdepth 1 -name ${reporting.db}.\*\.001 |
wc -l | xargs echo -n"/>

        <condition property="missing.backup">
            <equals arg1="${reporting.backup.count}"    arg2="0"/>
        </condition>
    </target>

    <target name="testdb" depends="db2-test" unless="missing.backup">
        ...
    </target>

-- 
View this message in context: http://ant.1045680.n5.nabble.com/Checking-a-property-with-ant-tp1350385p3242389.html
Sent from the Ant - Users mailing list archive at Nabble.com.

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


AW: Checking a property with ant

Posted by Ja...@rzf.fin-nrw.de.
> <target name="whatever" if="allOK">
> <target name="whatever" unless="allOK">

But dont forget: <target if|unless> checks whether a property with
the given name is set/not-set.

<property name="foo" value="true"/>
<target name="foo" unless="foo">
    <echo>I will be executed</echo>
</target>

<property name="bar" value="false"/>
<target name="bar" if="bar">
    <echo>I will be executed</echo>
</target>



Jan

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


Re: Checking a property with ant

Posted by Gilbert Rebhan <an...@schillbaer.de>.
> I have tried a few things today and still can't figure this out.  I have a
> properties file with a setting of say test=successful and I want ant to
> check the property test to make sure it is set to successful before going
> on.  How do I do this?


see manual <condition>, f.e. =

<condition property="allOK">
  <equals arg1="${test}" arg2="successful"/>
</condition>

and later on =

<target name="whatever" if="allOK">
...
</target>

or the other way around

<target name="whatever" unless="allOK">
...
</target>


Regards, Gilbert

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