Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 18274 invoked from network); 2 May 2002 14:59:58 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 2 May 2002 14:59:58 -0000 Received: (qmail 20248 invoked by uid 97); 2 May 2002 14:59:56 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@nagoya.betaversion.org Received: (qmail 20192 invoked by alias); 2 May 2002 14:59:55 -0000 Delivered-To: jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 20176 invoked by uid 97); 2 May 2002 14:59:55 -0000 Mailing-List: contact ant-dev-help@jakarta.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 ant-dev@jakarta.apache.org Received: (qmail 20148 invoked by uid 98); 2 May 2002 14:59:54 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Content-Class: urn:content-classes:message From: To: Subject: [PATCH] 'outputproperty attribute' for Java Task (with correct diff file) Date: Thu, 2 May 2002 16:00:39 +0100 Message-ID: <11b7d01c1f1ea$1f3b5d30$7735bcc3@blueyonder.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_11B7E_01C1F1F2.80FFC530" X-Mailer: Microsoft CDO for Windows 2000 Thread-Index: AcHx6h87Xcd/zl3SEdaQvQCQJ9GOQA== X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_11B7E_01C1F1F2.80FFC530 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I found this useful when passing information between java calls.=20 The outputproperty is used in the same way as Exec, but for Java. = Currently only implemented for calls when the fork attribute is set to = true.=20 Dennis Adams=20 =20 ------=_NextPart_000_11B7E_01C1F1F2.80FFC530 Content-Type: text/plain; name="outputPropertyForJava.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="outputPropertyForJava.txt" --- org\apache\tools\ant\taskdefs\Java.java.orig Thu Oct 11 23:58:28 = 2001 +++ org\apache\tools\ant\taskdefs\Java.java Thu May 2 14:44:19 2002 @@ -72,14 +72,16 @@ * @author Stefan = Bodewig */ public class Java extends Task { - + private static String lSep =3D = System.getProperty("line.separator"); private CommandlineJava cmdl =3D new CommandlineJava(); private boolean fork =3D false; private File dir =3D null; private File out; private PrintStream outStream =3D null; private boolean failOnError =3D false; - =20 + private String outputprop;=20 + private ByteArrayOutputStream baos;=20 + /** * Do the execution. */ @@ -251,6 +253,14 @@ } =20 /** + * Property name whose value should be set to the output of + * the process + */ + public void setOutputproperty(String outputprop) { + this.outputprop =3D outputprop; + } + + /** * -mx or -Xmx depending on VM version */ public void setMaxmemory(String max){ @@ -313,13 +323,16 @@ FileOutputStream fos =3D null; try { Execute exe =3D null; - if (out =3D=3D null) { - exe =3D new Execute(new LogStreamHandler(this, = Project.MSG_INFO, - = Project.MSG_WARN),=20 - null); + if (out !=3D null) { + fos =3D new FileOutputStream(out); + exe =3D new Execute(new PumpStreamHandler(fos), null); + } else if (outputprop !=3D null) {=20 + baos =3D new ByteArrayOutputStream(); + exe =3D new Execute(new PumpStreamHandler(baos), null); } else { - fos =3D new FileOutputStream(out); - exe =3D new Execute(new PumpStreamHandler(fos), null); + exe =3D new Execute(new LogStreamHandler(this, = Project.MSG_INFO, + = Project.MSG_WARN),=20 + null); =20 } =20 exe.setAntRun(project); @@ -335,7 +348,27 @@ =20 exe.setCommandline(command); try { - return exe.execute(); + int rVal =3D exe.execute(); + + if (baos !=3D null)=20 + { + BufferedReader in =3D new BufferedReader(new = StringReader(baos.toString())); + String line =3D null; + StringBuffer val =3D new StringBuffer(); + while ((line =3D in.readLine()) !=3D null)=20 + { + if (val.length() !=3D 0)=20 + { + val.append(lSep); + } + val.append(line); + }=20 + + + project.setProperty(outputprop,val.toString()); + } + =20 + return rVal; } catch (IOException e) { throw new BuildException(e, location); } ------=_NextPart_000_11B7E_01C1F1F2.80FFC530 Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: For additional commands, e-mail: ------=_NextPart_000_11B7E_01C1F1F2.80FFC530--