|
|
@@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
* Copyright 2000,2002,2004 The Apache Software Foundation |
|
|
|
* Copyright 2000,2002,2004-2005 The Apache Software Foundation |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
@@ -47,6 +47,10 @@ public class Exec extends Task { |
|
|
|
protected PrintWriter fos = null; |
|
|
|
private boolean failOnError = false; |
|
|
|
|
|
|
|
/** |
|
|
|
* Constructor for Exec. |
|
|
|
* Prints a warning message to std error. |
|
|
|
*/ |
|
|
|
public Exec() { |
|
|
|
System.err.println("As of Ant 1.2 released in October 2000, " |
|
|
|
+ "the Exec class"); |
|
|
@@ -55,10 +59,20 @@ public class Exec extends Task { |
|
|
|
System.err.println("Don\'t use it!"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Execute the task. |
|
|
|
* @throws BuildException on error |
|
|
|
*/ |
|
|
|
public void execute() throws BuildException { |
|
|
|
run(command); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Execute the command. |
|
|
|
* @param command the command to exec |
|
|
|
* @return the exit value of the command |
|
|
|
* @throws BuildException on error |
|
|
|
*/ |
|
|
|
protected int run(String command) throws BuildException { |
|
|
|
|
|
|
|
int err = -1; // assume the worst |
|
|
@@ -152,26 +166,53 @@ public class Exec extends Task { |
|
|
|
return err; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Set the directory. |
|
|
|
* @param d a <code>String</code> value |
|
|
|
*/ |
|
|
|
public void setDir(String d) { |
|
|
|
this.dir = getProject().resolveFile(d); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Set the Operating System that this exec is to run in. |
|
|
|
* @param os a <code>String</code> value |
|
|
|
*/ |
|
|
|
public void setOs(String os) { |
|
|
|
this.os = os; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Set the command to exec. |
|
|
|
* @param command a <code>String</code> value |
|
|
|
*/ |
|
|
|
public void setCommand(String command) { |
|
|
|
this.command = command; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Set the output filename. |
|
|
|
* @param out a <code>String</code> value |
|
|
|
*/ |
|
|
|
public void setOutput(String out) { |
|
|
|
this.out = out; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Set the failOnError attribute. |
|
|
|
* Default is false. |
|
|
|
* @param fail a <code>boolean</code> value |
|
|
|
*/ |
|
|
|
public void setFailonerror(boolean fail) { |
|
|
|
failOnError = fail; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Log an output message. |
|
|
|
* @param line the line to putput |
|
|
|
* @param messageLevel the level of logging - ignored |
|
|
|
* if output is going to a file |
|
|
|
*/ |
|
|
|
protected void outputLog(String line, int messageLevel) { |
|
|
|
if (fos == null) { |
|
|
|
log(line, messageLevel); |
|
|
@@ -180,6 +221,9 @@ public class Exec extends Task { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Close output. |
|
|
|
*/ |
|
|
|
protected void logFlush() { |
|
|
|
if (fos != null) { |
|
|
|
fos.close(); |
|
|
@@ -192,7 +236,7 @@ public class Exec extends Task { |
|
|
|
private BufferedReader din; |
|
|
|
private int messageLevel; |
|
|
|
private boolean endOfStream = false; |
|
|
|
private int SLEEP_TIME = 5; |
|
|
|
private static final int SLEEP_TIME = 5; |
|
|
|
|
|
|
|
public StreamPumper(InputStream is, int messageLevel) { |
|
|
|
this.din = new BufferedReader(new InputStreamReader(is)); |
|
|
|