From d91fdceaa60b70502667049c3156197ab14908f0 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 11 Apr 2002 14:58:00 +0000 Subject: [PATCH] may alter value of dir during execute. Cosmetics. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272378 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/ExecuteJava.java | 1 + .../org/apache/tools/ant/taskdefs/Java.java | 61 ++++++++++++------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java index 2fdcfbaf0..04e1384ab 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java @@ -73,6 +73,7 @@ import java.io.PrintStream; * * @author thomas.haas@softwired-inc.com * @author Stefan Bodewig + * @since Ant 1.2 */ public class ExecuteJava implements Runnable, TimeoutObserver { diff --git a/src/main/org/apache/tools/ant/taskdefs/Java.java b/src/main/org/apache/tools/ant/taskdefs/Java.java index 437249e1b..8b0811fa6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Java.java +++ b/src/main/org/apache/tools/ant/taskdefs/Java.java @@ -72,12 +72,15 @@ import java.io.IOException; import java.util.Vector; /** - * This task acts as a loader for java applications but allows to use the same JVM - * for the called application thus resulting in much faster operation. + * This task acts as a loader for java applications but allows to use + * the same JVM for the called application thus resulting in much + * faster operation. * * @author Stefano Mazzocchi stefano@apache.org * @author Stefan Bodewig * + * @since Ant 1.1 + * * @ant.task category="java" */ public class Java extends Task { @@ -97,14 +100,19 @@ public class Java extends Task { * Do the execution. */ public void execute() throws BuildException { - int err = -1; + File savedDir = dir; - if ((err = executeJava()) != 0) { - if (failOnError) { - throw new BuildException("Java returned: "+err, location); - } else { - log("Java Result: " + err, Project.MSG_ERR); + int err = -1; + try { + if ((err = executeJava()) != 0) { + if (failOnError) { + throw new BuildException("Java returned: "+err, location); + } else { + log("Java Result: " + err, Project.MSG_ERR); + } } + } finally { + dir = savedDir; } } @@ -200,7 +208,8 @@ public class Java extends Task { */ public void setJar(File jarfile) throws BuildException { if ( cmdl.getClassname() != null ){ - throw new BuildException("Cannot use 'jar' and 'classname' attributes in same command."); + throw new BuildException("Cannot use 'jar' and 'classname' " + + "attributes in same command."); } cmdl.setJar(jarfile.getAbsolutePath()); } @@ -210,7 +219,8 @@ public class Java extends Task { */ public void setClassname(String s) throws BuildException { if ( cmdl.getJar() != null ){ - throw new BuildException("Cannot use 'jar' and 'classname' attributes in same command"); + throw new BuildException("Cannot use 'jar' and 'classname' " + + "attributes in same command"); } cmdl.setClassname(s); } @@ -307,7 +317,7 @@ public class Java extends Task { * *

Will be ignored if we are not forking a new VM. * - * @since 1.32, Ant 1.5 + * @since Ant 1.5 */ public void addEnv(Environment.Variable var) { env.addVariable(var); @@ -318,7 +328,7 @@ public class Java extends Task { * *

Will be ignored if we are not forking a new VM. * - * @since 1.32, Ant 1.5 + * @since Ant 1.5 */ public void setNewenvironment(boolean newenv) { newEnvironment = newenv; @@ -327,7 +337,7 @@ public class Java extends Task { /** * Shall we append to an existing file? * - * @since 1.36, Ant 1.5 + * @since Ant 1.5 */ public void setAppend(boolean append) { this.append = append; @@ -336,26 +346,34 @@ public class Java extends Task { /** * Timeout in milliseconds after which the process will be killed. * - * @since 1.37, Ant 1.5 + * @since Ant 1.5 */ public void setTimeout(Long value) { timeout = value; } + /** + * Pass output sent to System.out to specified output file. + * + * @since Ant 1.5 + */ protected void handleOutput(String line) { if (outStream != null) { outStream.println(line); - } - else { + } else { super.handleOutput(line); } } + /** + * Pass output sent to System.err to specified output file. + * + * @since Ant 1.5 + */ protected void handleErrorOutput(String line) { if (outStream != null) { outStream.println(line); - } - else { + } else { super.handleErrorOutput(line); } } @@ -412,7 +430,8 @@ public class Java extends Task { if (dir == null) { dir = project.getBaseDir(); } else if (!dir.exists() || !dir.isDirectory()) { - throw new BuildException(dir.getAbsolutePath()+" is not a valid directory", + throw new BuildException(dir.getAbsolutePath() + +" is not a valid directory", location); } @@ -470,11 +489,11 @@ public class Java extends Task { /** * Create the Watchdog to kill a runaway process. * - * @since 1.37, Ant 1.5 + * @since Ant 1.5 */ protected ExecuteWatchdog createWatchdog() throws BuildException { if (timeout == null) { - return null; + return null; } return new ExecuteWatchdog(timeout.longValue()); }