Browse Source

<sql> "output" attribute now supports any Resource in addition to a file.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@677383 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 17 years ago
parent
commit
37820a5018
3 changed files with 30 additions and 7 deletions
  1. +2
    -0
      WHATSNEW
  2. +4
    -1
      docs/manual/CoreTasks/sql.html
  3. +24
    -6
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 2
- 0
WHATSNEW View File

@@ -190,6 +190,8 @@ Other changes:


* <echo> supports an "output" Resource attribute as an alternative to "file". * <echo> supports an "output" Resource attribute as an alternative to "file".


* <sql> "output" attribute now supports any Resource in addition to a file.

Changes from Ant 1.7.0 TO Ant 1.7.1 Changes from Ant 1.7.0 TO Ant 1.7.1
============================================= =============================================




+ 4
- 1
docs/manual/CoreTasks/sql.html View File

@@ -117,7 +117,10 @@ and <b>abort</b> execution and transaction and fail task.</p>
</tr> </tr>
<tr> <tr>
<td width="12%" valign="top">output</td> <td width="12%" valign="top">output</td>
<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)
<b>Since Ant 1.8</b> can specify any Resource that supports output (see
<a href="../develop.html#set-magic">note</a>).
</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> <tr>


+ 24
- 6
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -25,10 +25,12 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.FileProvider;
import org.apache.tools.ant.types.resources.FileResource; import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.Union; import org.apache.tools.ant.types.resources.Union;


import java.io.File; import java.io.File;
import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -153,10 +155,9 @@ public class SQLExec extends JDBCTask {
private boolean showtrailers = true; private boolean showtrailers = true;


/** /**
* Results Output file.
* Results Output Resource.
*/ */
private File output = null;

private Resource output = null;


/** /**
* Action to perform if an error is found * Action to perform if an error is found
@@ -392,6 +393,15 @@ public class SQLExec extends JDBCTask {
* @param output the output file to use for logging messages. * @param output the output file to use for logging messages.
*/ */
public void setOutput(File output) { public void setOutput(File output) {
setOutput(new FileResource(getProject(), output));
}

/**
* Set the output Resource;
* optional, defaults to the Ant log.
* @param output the output Resource to store results.
*/
public void setOutput(Resource output) {
this.output = output; this.output = output;
} }


@@ -556,9 +566,17 @@ public class SQLExec extends JDBCTask {
PrintStream out = System.out; PrintStream out = System.out;
try { try {
if (output != null) { if (output != null) {
log("Opening PrintStream to output file " + output, Project.MSG_VERBOSE);
out = new PrintStream(new BufferedOutputStream(
new FileOutputStream(output.getAbsolutePath(), append)));
log("Opening PrintStream to output Resource " + output, Project.MSG_VERBOSE);
OutputStream os;
if (output instanceof FileProvider) {
os = new FileOutputStream(((FileProvider) output).getFile(), append);
} else {
os = output.getOutputStream();
if (append) {
log("Ignoring append=true for non-file resource " + output, Project.MSG_WARN);
}
}
out = new PrintStream(new BufferedOutputStream(os));
} }


// Process all transactions // Process all transactions


Loading…
Cancel
Save