Gus
Gus

Reputation: 251

Iterating through a properties file in Ant

So I need to write an Ant script that iterates through a properties file and uses the keys from that file to pull values from a few other properties files (using the same key).

I haven't been able to find any examples remotely similar to what I'm trying to accomplish. Is this something thats plausible with Ant? I know its rather old. I've never used Maven but I believe our platform would be able to support that if this isn't possible in Ant

Upvotes: 0

Views: 381

Answers (1)

F.Rosado
F.Rosado

Reputation: 507

Using the <script> command you can execute arbirary java/javascript code and do not supported code. For your case, perhaps some similar to :

<scriptdef name="iterateprops" language="javascript">
    <attribute name="src" />
    <![CDATA[
       importClass(java.util.Properties);
       importClass(java.io.FileInputStream);
       var src = attributes.get("src");
       var properties = new Properties();
       properties.load(new FileInputStream(src));
       var names = properties.propertyNames();
       while(names.hasMoreElements()) {
           println (names.nextElement());
       }

    ]]>
</scriptdef>

An later use it:

<iterateprops src="file.properties" />

Upvotes: 1

Related Questions