ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From javier muguruza <jmugur...@gmail.com>
Subject Re: properties file read programatically
Date Thu, 21 Jul 2005 22:22:50 GMT
great juergen, thanks.

 I mean I knew it could be done some way or other, I meant if it was
possible very easily. I find it strange that I could not find any
reference to it, in the wiki or something, I guess people would find
it very handy in their configuration files...

javi


On 7/21/05, Juergen Hermann <jh@web.de> wrote:
> 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
> 
>

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


Mime
View raw message