ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Juergen Hermann" ...@web.de>
Subject Re: properties file read programatically
Date Thu, 21 Jul 2005 21:25:59 GMT
On Thu, 21 Jul 2005 22:48:38 +0200, javier muguruza wrote:

>I haven't found anything in the list about that...is it possible to
>use ant programatically to read a property file and at the same time
>performing the property substitution like ant does? I would like to
>reuse my build.properties for my own code.

Of course it is´(after all, Ant itself is just a program, too). The 
following prints "{baz=bar, foo=bar}". Since everyone can read Python, it 
should be no problem to convert this to Java (well, it will get a little 
longer ;).


from java.io import File
from org.apache.tools.ant import Project
from org.apache.tools.ant.taskdefs import Property

out = open('test.properties', 'w')
out.write("""
foo=bar
baz=${foo}
""")
out.close()

prj = Project()

p = Property()
p.setProject(prj)
p.init()
f = File('test.properties')
p.setFile(f)
p.execute()

print prj.getProperties()


Ciao, Jürgen



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message