Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 38194 invoked from network); 13 Feb 2004 04:54:55 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 13 Feb 2004 04:54:55 -0000 Received: (qmail 42107 invoked by uid 500); 13 Feb 2004 04:54:33 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 42066 invoked by uid 500); 13 Feb 2004 04:54:33 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 42050 invoked from network); 13 Feb 2004 04:54:32 -0000 Received: from unknown (HELO out002.verizon.net) (206.46.170.141) by daedalus.apache.org with SMTP; 13 Feb 2004 04:54:32 -0000 Received: from PAULHOME ([4.13.99.26]) by out002.verizon.net (InterMail vM.5.01.06.06 201-253-122-130-106-20030910) with ESMTP id <20040213045442.IDJX23576.out002.verizon.net@PAULHOME> for ; Thu, 12 Feb 2004 22:54:42 -0600 Message-ID: <005001c3f1ee$09f35bc0$1a630d04@PAULHOME> From: "Paul F. Williams" To: Subject: notes on embedding ANT Date: Thu, 12 Feb 2004 22:58:36 -0600 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Authentication-Info: Submitted using SMTP AUTH at out002.verizon.net from [4.13.99.26] at Thu, 12 Feb 2004 22:54:42 -0600 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I'm an ANT newbie. Please forgive any newbie offenses. I want to use ANT's task engine in my own app. I don't want to invoke it from a command line. I don't want to run individual tasks myself. I want to use the ANT engine internally to process an XML script. Maybe there is an established way to use ANT this way, but I found none. This script is in the META-INF directory of a JAR file. I don't want to extract the file to a temporary file and feed it to ANT. Instead, I would like to convert the script's ZipEntry to an InputStream and pass the stream to ANT. My current solution installs a project helper remarkably like the current ProjectHelper2 class. The main difference is that my parse() method is more friendly to InputStreams. My app's main method points ANT to my helper class via the system properties. I have an ANT engine wrapper much like Main.runBuild() that duplicates the logic to run ANT. It uses an InputStream instead of a File. Everything works. I pull the script as an InputStream and pass it to the wrapper. The wrapper passes the stream to the helper. The helper parses and runs the script. (My next step is to provide my own specialized tasks that I want ANT to resolve without a .) Here are some obstacles I had to overcome: 1) I had to duplicate much of the functionality of the Main.runBuild method. It would be nice if Main.runBuild() were refactored into a generic way to start the ANT engine. Doing so would make it easier for others to embed the engine. 2) Main assumes a File (which is OK), but it would be nice if the code that starts the engine would take an InputStream. 3) ProjectHelper.configureProject takes a File. The actual ProjectHelper.parse method takes an Object. It would be nice if both used Objects. 4) It would be nice if org.apache.tools.ant.helper.ProjectHelper2 were friendly to InputStreams. In fact, all the SAX parser needs is an InputStream (converted into an InputSource). The parser would not need to close the stream; higher level methods would determine when to do so. The existing Main class would send a FileInputStream. Other apps might send their own InputStreams. In short, streams seems like a more flexible design. One potential pitfall I see is ProjectHelper2 line 199: inputSource.setSystemId(uri); If the helper gets an InputStream, it will not have a URI. I did not set the URI, and it worked ok for me, but I don't know all the ramifications. Do these suggestions sound reasonable? If so, how might this pitiful wretch of a newbie contribute? --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org