Return-Path: X-Original-To: apmail-ant-user-archive@www.apache.org Delivered-To: apmail-ant-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 57F3A17BAE for ; Thu, 12 Feb 2015 05:43:20 +0000 (UTC) Received: (qmail 81193 invoked by uid 500); 12 Feb 2015 05:43:19 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 81141 invoked by uid 500); 12 Feb 2015 05:43:19 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 81130 invoked by uid 99); 12 Feb 2015 05:43:19 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Feb 2015 05:43:19 +0000 Received: from samaflost.de (v35516.1blu.de [178.254.33.213]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 3F9561A0320 for ; Thu, 12 Feb 2015 05:43:19 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by samaflost.de (Postfix) with ESMTP id 43AD6588E353 for ; Thu, 12 Feb 2015 06:43:16 +0100 (CET) Received: from samaflost.de ([127.0.0.1]) by localhost (v35516.1blu.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8Ael803QO3ol for ; Thu, 12 Feb 2015 06:43:08 +0100 (CET) Received: by samaflost.de (Postfix, from userid 1000) id EDC92588E352; Thu, 12 Feb 2015 06:43:07 +0100 (CET) From: Stefan Bodewig To: user@ant.apache.org Subject: Re: [Ant]Read buid.xml file in memory References: <1bae3e6601e44580a90ed9d5aa5c2d7a@shmbx02.ebaotech.com> Date: Thu, 12 Feb 2015 06:43:07 +0100 In-Reply-To: <1bae3e6601e44580a90ed9d5aa5c2d7a@shmbx02.ebaotech.com> (Jackie Xiao's message of "Wed, 11 Feb 2015 16:07:11 +0000") Message-ID: <87mw4jd6s4.fsf@v35516.1blu.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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). Stefan [1] http://ant.apache.org/manual/projecthelper.html [2] https://git-wip-us.apache.org/repos/asf?p=ant.git;a=blob;f=src/main/org/apache/tools/ant/helper/ProjectHelper2.java;h=67e1decb9f01d7496a11b0745359d61b5c2694b8;hb=HEAD [3] https://gist.github.com/bodewig/7909d63fc887b908a56a --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org