Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Ant can get a value read from a file into a property value?

The file looks like:

a1,b1
a2,b2
...

I know the value "a2". How to get the value "b2" into a property value.

I know how to select line which contains "a2" by:

<linecontains>
  <contains value="a2"/>
</linecontains>

But I do not know how to set a property value to "b2". I am at your disposal for more other information.

like image 339
pindare Avatar asked May 05 '09 08:05

pindare


People also ask

How do I use Ant properties file?

It allows you to reuse the same build file, with different property settings for different execution environment. For example, build properties file can be maintained separately for DEV, TEST, and PROD environments. It is useful, when you do not know the values for a property (in a particular environment) up-front.

How do I override property value in Ant?

Ant Properties are set once and then can never be overridden. That's why setting any property on the command line via a -Dproperty=value will always override anything you've set in the file; the property is set and then nothing can override it. This way: Anything set at the command line takes precedence over build.

How do you set an Ant property?

The property value is immutable, once the value is set you cannot change it. To set a property to a specific value you use Name/value assignment. To set a property to a location you use Name/location assignment. To use the properties surround them with ${}.


1 Answers

The following does the trick for me:

<loadfile srcfile="data" property="result">
     <filterchain>
           <linecontains>
                <contains value="a2"/>
           </linecontains>
           <tokenfilter>
                <replacestring from="a2," to=""/>
           </tokenfilter>
    </filterchain>
</loadfile>
<echo message="${result}"/>

As you pointed out, first the line the the 'a2' will be selected. The tokenfilter then replaces a2 and the colon with nothing. Hope that helps.

like image 154
Mnementh Avatar answered Sep 17 '22 18:09

Mnementh