How to load variables from XML properties file?

I am currently loading properties from an XML file in Ant. However, I would like to complete the current ant task inside the for loop when loading a new XML properties file for the same set of properties each time.

I am aware of the existence of the ant -contrib var task, which allows me to override properties. However, I'm not sure how to combine this with loading properties from an XML file. First, I thought about iterating over all the properties, and then set them to new values ​​using the propertyregex task. Unfortunately, when I started writing code for this, I realized that I did not know how to actually load property values, since they could not overwrite previously set properties. (Well, they can use the var task, but this cannot be used to load from an XML file, as far as I can tell.)

Any ideas? What I'm perfectly looking for is a task that will be called something like

<xmlvars file="myxmlpropertyfile.xml"/> 

which will function just like

 <xmlproperty file="myxmlpropertyfile.xml"/> 

except that it overwrites the variables.

+4
source share
2 answers

One of the things you can do with the <xmlproperty> task is to prefix each property with a specific value. Why not just use your parameter name as a prefix?

Otherwise, you could use the <echoproperties> task to undo all the properties, and then perform the next iteration of your <for> task.

Something like this, but this is not verified:

  <for param="my.directory"> <fileset dir="${some.directory}"/> <sequential> <xmlproperty file="@{my.directory}/myxmlpropertyfile.xml" prefix="foo-fighters"/> <blah, blah, blah/> <for param="reset.var"> <echoproperty prefix=foo-fighters"/> <sequential> <var name="@{reset.var}" unset="true"/> </sequential> </for> </sequential> </for> 

Basically, you use an external <for> loop to cycle through your directories and use <xmlproperty> to set property names. <blah blah blah/> means doing what you want. Then, before proceeding to the next iteration of the external <for> loop, you will create an internal <for> loop that will disable all the variables that you previously set in the <xmlproperty> task.

The trick uses a variable prefix that ensures variable names are easy to find. So foo-fighters .

+2
source

It looks like I can accomplish this using the unset var var attribute. Will report ...

0
source

Source: https://habr.com/ru/post/1434095/


All Articles