ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: [Ant]Read buid.xml file in memory
Date Thu, 12 Feb 2015 05:43:07 GMT
On 2015-02-11, Jackie Xiao wrote:

> Is it possible for Ant to read build files from memory?

Yes, but it takes some effort.  The entry point for this would be a
custom ProjectHelper implementation[1].

Note that there are several parts in Ant that assume there is some sort
of File that defines the build - or at least a "base directory" so
relative paths can get resolved.  This means you will still need to set
the basedir of the Project instance you create.

My first instinct was to subclass Ant's own ProjectHelper2[2] but it
isn't really subclass friendly.  You'd need to override the three arg
parse method to set the InputSource from a stream reading from memory
(or a CipherInputStream wrapping the FileInputStream ;-).

Unfortunately the machinery of ProjectHelper2 relies on AntXMLContext
knowing the buildfile and you don't get hold of the context inside the
three arg parse method as there is no accessor for it in RootHandler.
There are ways that require knowledge of ProjectHelper2's internals.

One thing making things even more complex is that Ant itself loads some
antlibs when starting and uses the same ProjectHelper - these should be
read from the "real" URLs.

I ended up with a simple proof of concept, but wouldn't want to use
something like this in production.  You may want to open an enhancement
request for making ProjectHelper2 more sub-class friendly for your real
use case (wrapping the input stream).





To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message