Exploring
Exploring

Reputation: 3359

Ant local property creation from a propertyfile

I am aware since Ant 1.8, local property can be used to the current scope.

For my case, I need to load properties from a propertyfile and I need these properties to be local. For example, my properties file:

param1=value1
param2=value2
param3=value3
.
.
paramN=valueN

I want to load this property file on each target and want to keep those properties local to that target.

How I can achieve it?

Upvotes: 1

Views: 447

Answers (2)

Rebse
Rebse

Reputation: 10377

As Local Task only works for single properties, you may extend it to work for a bunch of properties loaded from a propertyfile. The Antelope project (some of Antelope Ant tasks are now part of antcontrib, but the planned merge has never been finished..) has a similar task called unset which takes a single property, but also a propertyfile - check it's source for inspiration (sources are included in the release zip). Alternatively use the Antelope unset task (it has no dependencies to other Antelope classes) like that to create a scope :

<target name="foo">
<!-- loaded when target starts.. -->
<property file="foo.properties"/>
...
<!-- ..destroyed when target ends -->
<unset file="foo.properties/>
</target>

Upvotes: 0

opatry
opatry

Reputation: 151

If you didn't know all property and/or doesn't want to enumerate all of them with <local/> for each, the only solution I see is to use a nested <antcall/> inside your target to do the properties loading and keep them in this local ant context (once the ant call has been done, all properties created inside it are lost, you can't get them from ant call caller).

Upvotes: 1

Related Questions