Author: bodewig
Date: Mon Aug 24 14:09:35 2009
New Revision: 807228
URL: http://svn.apache.org/viewvc?rev=807228&view=rev
Log:
errorproperty and warningproperty for <sql>. Submitted by Andrew Stevens. PR
38807
Modified:
ant/core/trunk/CONTRIBUTORS
ant/core/trunk/WHATSNEW
ant/core/trunk/contributors.xml
ant/core/trunk/docs/manual/CoreTasks/sql.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
Modified: ant/core/trunk/CONTRIBUTORS
URL:
http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=807228&r1=807227&r2=807228&view=diff
==============================================================================
Binary files - no diff available.
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=807228&r1=807227&r2=807228&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Aug 24 14:09:35 2009
@@ -897,6 +897,10 @@
* A new <resourceexists> condition can check whether resources exists.
+ * <sql> 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
=============================================
Modified: ant/core/trunk/contributors.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=807228&r1=807227&r2=807228&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Mon Aug 24 14:09:35 2009
@@ -67,6 +67,10 @@
<last>Everitt</last>
</name>
<name>
+ <first>Andrew</first>
+ <last>Stevens</last>
+ </name>
+ <name>
<first>Andrey</first>
<last>Urazov</last>
</name>
Modified: ant/core/trunk/docs/manual/CoreTasks/sql.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/sql.html?rev=807228&r1=807227&r2=807228&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/sql.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/sql.html Mon Aug 24 14:09:35 2009
@@ -256,6 +256,18 @@
ever occurs)</td>
</tr>
+<tr>
+ <td valign="top">errorproperty</td>
+ <td valign="top">The name of a property to set in the event of an
+ error. <em>Since Ant 1.8.0</em></td>
+ <td align="center" valign="top">No</td>
+</tr>
+<tr>
+ <td valign="top">warningproperty</td>
+ <td valign="top">The name of a property to set in the event of an
+ warning. <em>Since Ant 1.8.0</em></td>
+ <td align="center" valign="top">No</td>
+</tr>
</table>
<h3>Parameters specified as nested elements</h3>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java?rev=807228&r1=807227&r2=807228&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java Mon Aug
24 14:09:35 2009
@@ -251,6 +251,18 @@
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
* @param srcFile the file containing the SQL command.
@@ -522,6 +534,28 @@
}
/**
+ * 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 @@
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 @@
if (!onError.equals("continue")) {
throw e;
}
+ setErrorProperty();
} finally {
if (resultSet != null) {
try {
@@ -1059,5 +1096,22 @@
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");
+ }
}
}