You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Rebhan, Gilbert" <Gi...@huk-coburg.de> on 2007/04/26 11:28:23 UTC
RE: Verifying if a property is present in a property file
Hi,
or solution via script, i.e.
<project name="bla" default="main" basedir=".">
<!-- // Properties -->
<echo file="y:/props.txt">
key = value
key.1 = value1
bind.i.address = foobar
</echo>
<!-- Properties // -->
<target name="depends">
<script language="ruby">
<![CDATA[
pattern = /bind\.ip\.address/
str = File.read("Y:/props.txt")
$project.setProperty "ok-address-config", "true" if str.match(pattern)
]]>
</script>
<!-- or
<script language="ruby">
<![CDATA[
File.open("Y:/props.txt", "r").each do |line|
$project.setProperty "ok-address-config", "true" if line =~ /bind\.ip\.address/
end
]]>
</script>
-->
</target>
<target name="merge" if="ok-address-config">
<echo>Condition checked > OK ! > proceed ...</echo>
</target>
<target name="main" depends="depends,merge"/>
</project>
Regards, Gilbert
-----Original Message-----
From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
Sent: Thursday, April 26, 2007 10:53 AM
To: user@ant.apache.org
Subject: AW: Verifying if a property is present in a property file
The easiest way is loading the property file ...
<property file="" prefix="tmp"/>
<target name="merge" if="tmp.TheMagicProperty">
...
</target>
Alternatively you could search for the string "TheMagicProperty=" in the file ...
Jan
>-----Ursprüngliche Nachricht-----
>Von: Tim Culhane [mailto:tim.culhane@criticalpath.net]
>Gesendet: Donnerstag, 26. April 2007 10:28
>An: user@ant.apache.org
>Betreff: Verifying if a property is present in a property file
>
>Hi,
>
>I am writing a target which merges property values from the
>property file
>into another file which is then used when building my application. The
>target should only get executed if the specific property is
>present in the
>property file.
>
>The target which does the merging is dependant on another target, named
>merge-check, which should verify that the required property is
>present in
>the property file. Merge-check should set an internal property, named
>something like merge-check-ok, if the property is present.
>In the target doing the merge, we can then check the property
>merge-check-ok
>using the if clause.
>
>However, I don't know how to check the property file for a specific
>property. I've tried using a condition, and using the
>loadproperties and
>filterchain as in the bwlow example:
>
>
> <target name="config-address-check" depends="config-merge-check"
> if="ok-merge-config">
> <condition property="ok-address-config">
> <loadproperties srcfile="build.properties">
> <filterchain>
> <linecontains>
> <contains value="bind.ip.address"/>
> </linecontains>
> </filterchain>
> </loadproperties>
> </condition>
> </target>
>
>But the condition task does not support loadproperties.
>
>Can anybody tell me how I can verify if a property exists, and
>hence let the
>script know of this?
>
>Thanks,
>
>Tim
>
>-------------------------
>Tim Culhane,
>Critical Path Ireland,
>42-47 Lower Mount Street,
>Dublin 2.
>Direct line: 353-1-2415107
>phone: 353-1-2415000
>
>Tim.culhane@criticalpath.net
>http://www.criticalpath.net
>
>Critical Path
>a global leader in digital communications
>------------------------
>
>
>
>
>---------------------------------------------------------------------
>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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: Verifying if a property is present in a property file
Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
<!-- or if you prefer oneliners even shorter...
<script language="ruby"><![CDATA[
$project.setProperty "ok-address-config", "true" if File.read("Y:/props.txt").match(/bind\.ip\.address/)
]]></script>
-->
Gilbert
-----Original Message-----
From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de]
Sent: Thursday, April 26, 2007 11:28 AM
To: Ant Users List
Subject: RE: Verifying if a property is present in a property file
Hi,
or solution via script, i.e.
<project name="bla" default="main" basedir=".">
<!-- // Properties -->
<echo file="y:/props.txt">
key = value
key.1 = value1
bind.i.address = foobar
</echo>
<!-- Properties // -->
<target name="depends">
<script language="ruby">
<![CDATA[
pattern = /bind\.ip\.address/
str = File.read("Y:/props.txt")
$project.setProperty "ok-address-config", "true" if str.match(pattern)
]]>
</script>
<!-- or
<script language="ruby">
<![CDATA[
File.open("Y:/props.txt", "r").each do |line|
$project.setProperty "ok-address-config", "true" if line =~ /bind\.ip\.address/
end
]]>
</script>
-->
</target>
<target name="merge" if="ok-address-config">
<echo>Condition checked > OK ! > proceed ...</echo>
</target>
<target name="main" depends="depends,merge"/>
</project>
Regards, Gilbert
-----Original Message-----
From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
Sent: Thursday, April 26, 2007 10:53 AM
To: user@ant.apache.org
Subject: AW: Verifying if a property is present in a property file
The easiest way is loading the property file ...
<property file="" prefix="tmp"/>
<target name="merge" if="tmp.TheMagicProperty">
...
</target>
Alternatively you could search for the string "TheMagicProperty=" in the file ...
Jan
>-----Ursprüngliche Nachricht-----
>Von: Tim Culhane [mailto:tim.culhane@criticalpath.net]
>Gesendet: Donnerstag, 26. April 2007 10:28
>An: user@ant.apache.org
>Betreff: Verifying if a property is present in a property file
>
>Hi,
>
>I am writing a target which merges property values from the
>property file
>into another file which is then used when building my application. The
>target should only get executed if the specific property is
>present in the
>property file.
>
>The target which does the merging is dependant on another target, named
>merge-check, which should verify that the required property is
>present in
>the property file. Merge-check should set an internal property, named
>something like merge-check-ok, if the property is present.
>In the target doing the merge, we can then check the property
>merge-check-ok
>using the if clause.
>
>However, I don't know how to check the property file for a specific
>property. I've tried using a condition, and using the
>loadproperties and
>filterchain as in the bwlow example:
>
>
> <target name="config-address-check" depends="config-merge-check"
> if="ok-merge-config">
> <condition property="ok-address-config">
> <loadproperties srcfile="build.properties">
> <filterchain>
> <linecontains>
> <contains value="bind.ip.address"/>
> </linecontains>
> </filterchain>
> </loadproperties>
> </condition>
> </target>
>
>But the condition task does not support loadproperties.
>
>Can anybody tell me how I can verify if a property exists, and
>hence let the
>script know of this?
>
>Thanks,
>
>Tim
>
>-------------------------
>Tim Culhane,
>Critical Path Ireland,
>42-47 Lower Mount Street,
>Dublin 2.
>Direct line: 353-1-2415107
>phone: 353-1-2415000
>
>Tim.culhane@criticalpath.net
>http://www.criticalpath.net
>
>Critical Path
>a global leader in digital communications
>------------------------
>
>
>
>
>---------------------------------------------------------------------
>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
---------------------------------------------------------------------
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