diff --git a/CONTRIBUTORS b/CONTRIBUTORS index ce7bc179b..b06e78f22 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -10,6 +10,7 @@ Alison Winters Andreas Ames Andreas Mross Andrew Everitt +Andrew Stevens Andrey Urazov Andy Wood Anil K. Vijendran diff --git a/WHATSNEW b/WHATSNEW index 0792772e4..c31886b8e 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -897,6 +897,10 @@ Other changes: * A new condition can check whether resources exists. + * has two new attributes errorproperty and warningproperty that + can be set if an error/warning occurs. + Bugzilla Report 38807. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/contributors.xml b/contributors.xml index eda08884f..dc8fde697 100644 --- a/contributors.xml +++ b/contributors.xml @@ -66,6 +66,10 @@ Andrew Everitt + + Andrew + Stevens + Andrey Urazov diff --git a/docs/manual/CoreTasks/sql.html b/docs/manual/CoreTasks/sql.html index 923fea326..091c9f18e 100644 --- a/docs/manual/CoreTasks/sql.html +++ b/docs/manual/CoreTasks/sql.html @@ -256,6 +256,18 @@ and abort execution and transaction and fail task.

ever occurs) + + errorproperty + The name of a property to set in the event of an + error. Since Ant 1.8.0 + No + + + warningproperty + The name of a property to set in the event of an + warning. Since Ant 1.8.0 + No +

Parameters specified as nested elements

diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index 3445d483a..9166e355f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -250,6 +250,18 @@ public class SQLExec extends JDBCTask { */ private boolean treatWarningsAsErrors = false; + /** + * The name of the property to set in the event of an error + * @since Ant 1.8.0 + */ + private String errorProperty = null; + + /** + * The name of the property to set in the event of a warning + * @since Ant 1.8.0 + */ + private String warningProperty = null; + /** * Set the name of the SQL file to be run. * Required unless statements are enclosed in the build file @@ -521,6 +533,28 @@ public class SQLExec extends JDBCTask { csvQuoteChar = s; } + /** + * Property to set to "true" if a statement throws an error. + * + * @param errorProperty the name of the property to set in the + * event of an error. + * @since Ant 1.8.0 + */ + public void setErrorProperty(String errorProperty) { + this.errorProperty = errorProperty; + } + + /** + * Property to set to "true" if a statement produces a warning. + * + * @param warningProperty the name of the property to set in the + * event of a warning. + * @since Ant 1.8.0 + */ + public void setWarningProperty(String warningProperty) { + this.warningProperty = warningProperty; + } + /** * Load the sql file and then execute it * @throws BuildException on error. @@ -614,11 +648,13 @@ public class SQLExec extends JDBCTask { if (onError.equals("abort")) { throw new BuildException(e, getLocation()); } + setErrorProperty(); } catch (SQLException e) { closeQuietly(); if (onError.equals("abort")) { throw new BuildException(e, getLocation()); } + setErrorProperty(); } finally { try { if (getStatement() != null) { @@ -758,6 +794,7 @@ public class SQLExec extends JDBCTask { if (!onError.equals("continue")) { throw e; } + setErrorProperty(); } finally { if (resultSet != null) { try { @@ -1059,5 +1096,22 @@ public class SQLExec extends JDBCTask { if (treatWarningsAsErrors && initialWarning != null) { throw initialWarning; } + if (initialWarning != null) { + setWarningProperty(); + } + } + + protected final void setErrorProperty() { + setProperty(errorProperty); + } + + protected final void setWarningProperty() { + setProperty(warningProperty); + } + + private void setProperty(String name) { + if (name != null) { + getProject().setNewProperty(name, "true"); + } } }