Browse Source

Add append attributes to <exec>, <java> and <sql>

PR: 3234, part of 5299


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272234 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
6258074cd0
7 changed files with 60 additions and 4 deletions
  1. +3
    -0
      WHATSNEW
  2. +6
    -0
      docs/manual/CoreTasks/exec.html
  3. +6
    -0
      docs/manual/CoreTasks/java.html
  4. +6
    -0
      docs/manual/CoreTasks/sql.html
  5. +11
    -1
      src/main/org/apache/tools/ant/taskdefs/ExecTask.java
  6. +14
    -2
      src/main/org/apache/tools/ant/taskdefs/Java.java
  7. +14
    -1
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 3
- 0
WHATSNEW View File

@@ -275,6 +275,9 @@ Other changes:
* <uptodate> now has a 'srcfile' attribute to allow specifying a * <uptodate> now has a 'srcfile' attribute to allow specifying a
full-path filename. full-path filename.


* <exec>, <sql> and <java> now support append attributes to allow
appending the output to an existing file.

Changes from Ant 1.4 to Ant 1.4.1 Changes from Ant 1.4 to Ant 1.4.1
=========================================== ===========================================




+ 6
- 0
docs/manual/CoreTasks/exec.html View File

@@ -50,6 +50,12 @@ systems.</p>
redirected.</td> redirected.</td>
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>
</tr> </tr>
<tr>
<td valign="top">append</td>
<td valign="top">whether output should be appended to or overwrite
an existing file. Defaults to false.</td>
<td align="center" valign="top">No</td>
</tr>
<tr> <tr>
<td valign="top">outputproperty</td> <td valign="top">outputproperty</td>
<td valign="top">the name of a property in which the output of the <td valign="top">the name of a property in which the output of the


+ 6
- 0
docs/manual/CoreTasks/java.html View File

@@ -94,6 +94,12 @@ JVM.
<td valign="top">Name of a file to write the output to.</td> <td valign="top">Name of a file to write the output to.</td>
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>
</tr> </tr>
<tr>
<td valign="top">append</td>
<td valign="top">whether output should be appended to or overwrite
an existing file. Defaults to false.</td>
<td align="center" valign="top">No</td>
</tr>
<tr> <tr>
<td valign="top">newenvironment</td> <td valign="top">newenvironment</td>
<td valign="top">Do not propagate old environment when new <td valign="top">Do not propagate old environment when new


+ 6
- 0
docs/manual/CoreTasks/sql.html View File

@@ -88,6 +88,12 @@ and <b>abort</b> execution and transaction and fail task.</p>
<td width="78%" valign="top">Output file for result sets (defaults to System.out)</td> <td width="78%" valign="top">Output file for result sets (defaults to System.out)</td>
<td width="10%" valign="top">No (print to System.out by default)</td> <td width="10%" valign="top">No (print to System.out by default)</td>
</tr> </tr>
<tr>
<td valign="top">append</td>
<td valign="top">whether output should be appended to or overwrite
an existing file. Defaults to false.</td>
<td align="center" valign="top">No</td>
</tr>
<tr> <tr>
<td width="12%" valign="top">classpath</td> <td width="12%" valign="top">classpath</td>
<td width="78%" valign="top">Classpath used to load driver</td> <td width="78%" valign="top">Classpath used to load driver</td>


+ 11
- 1
src/main/org/apache/tools/ant/taskdefs/ExecTask.java View File

@@ -96,6 +96,7 @@ public class ExecTask extends Task {
private String outputprop; private String outputprop;
private String resultProperty; private String resultProperty;
private boolean failIfExecFails=true; private boolean failIfExecFails=true;
private boolean append = false;


/** Controls whether the VM (1.3 and above) is used to execute the command */ /** Controls whether the VM (1.3 and above) is used to execute the command */
private boolean vmLauncher = true; private boolean vmLauncher = true;
@@ -208,6 +209,15 @@ public class ExecTask extends Task {
failIfExecFails=flag; failIfExecFails=flag;
} }
/**
* Shall we append to an existing file?
*
* @since 1.30, Ant 1.5
*/
public void setAppend(boolean append) {
this.append = append;
}

/** /**
* Do the work. * Do the work.
*/ */
@@ -342,7 +352,7 @@ public class ExecTask extends Task {
protected ExecuteStreamHandler createHandler() throws BuildException { protected ExecuteStreamHandler createHandler() throws BuildException {
if(out!=null) { if(out!=null) {
try { try {
fos = new FileOutputStream(out);
fos = new FileOutputStream(out.getAbsolutePath(), append);
log("Output redirected to " + out, Project.MSG_VERBOSE); log("Output redirected to " + out, Project.MSG_VERBOSE);
return new PumpStreamHandler(fos); return new PumpStreamHandler(fos);
} catch (FileNotFoundException fne) { } catch (FileNotFoundException fne) {


+ 14
- 2
src/main/org/apache/tools/ant/taskdefs/Java.java View File

@@ -90,6 +90,7 @@ public class Java extends Task {
private File out; private File out;
private PrintStream outStream = null; private PrintStream outStream = null;
private boolean failOnError = false; private boolean failOnError = false;
private boolean append = false;
/** /**
* Do the execution. * Do the execution.
@@ -299,6 +300,15 @@ public class Java extends Task {
newEnvironment = newenv; newEnvironment = newenv;
} }


/**
* Shall we append to an existing file?
*
* @since 1.36, Ant 1.5
*/
public void setAppend(boolean append) {
this.append = append;
}

protected void handleOutput(String line) { protected void handleOutput(String line) {
if (outStream != null) { if (outStream != null) {
outStream.println(line); outStream.println(line);
@@ -328,7 +338,9 @@ public class Java extends Task {
exe.setSystemProperties(command.getSystemProperties()); exe.setSystemProperties(command.getSystemProperties());
if (out != null) { if (out != null) {
try { try {
outStream = new PrintStream(new FileOutputStream(out));
outStream =
new PrintStream(new FileOutputStream(out.getAbsolutePath(),
append));
exe.execute(project); exe.execute(project);
} catch (IOException io) { } catch (IOException io) {
throw new BuildException(io, location); throw new BuildException(io, location);
@@ -356,7 +368,7 @@ public class Java extends Task {
Project.MSG_WARN), Project.MSG_WARN),
null); null);
} else { } else {
fos = new FileOutputStream(out);
fos = new FileOutputStream(out.getAbsolutePath(), append);
exe = new Execute(new PumpStreamHandler(fos), null); exe = new Execute(new PumpStreamHandler(fos), null);
} }


+ 14
- 1
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -227,6 +227,10 @@ public class SQLExec extends Task {
*/ */
private String encoding = null; private String encoding = null;


/**
* Append to an existing file or overwrite it?
*/
private boolean append = false;


public void setCaching(boolean value){ public void setCaching(boolean value){
caching = value; caching = value;
@@ -377,6 +381,15 @@ public class SQLExec extends Task {
this.output = output; this.output = output;
} }


/**
* Shall we append to an existing file?
*
* @since 1.36, Ant 1.5
*/
public void setAppend(boolean append) {
this.append = append;
}

/** /**
* Set the rdbms required * Set the rdbms required
*/ */
@@ -510,7 +523,7 @@ public class SQLExec extends Task {
try { try {
if (output != null) { if (output != null) {
log("Opening PrintStream to output file " + output, Project.MSG_VERBOSE); log("Opening PrintStream to output file " + output, Project.MSG_VERBOSE);
out = new PrintStream(new BufferedOutputStream(new FileOutputStream(output)));
out = new PrintStream(new BufferedOutputStream(new FileOutputStream(output.getAbsolutePath(), append)));
} }
// Process all transactions // Process all transactions


Loading…
Cancel
Save