You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/07/11 12:59:48 UTC
svn commit: r675917 - in /ant/core/trunk: WHATSNEW
docs/manual/CoreTasks/sql.html
src/main/org/apache/tools/ant/taskdefs/JDBCTask.java
src/main/org/apache/tools/ant/taskdefs/SQLExec.java
Author: bodewig
Date: Fri Jul 11 03:59:48 2008
New Revision: 675917
URL: http://svn.apache.org/viewvc?rev=675917&view=rev
Log:
Allow ant to continue even if <sql> fails to connect to the database. PR 36712.
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/CoreTasks/sql.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=675917&r1=675916&r2=675917&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jul 11 03:59:48 2008
@@ -132,6 +132,11 @@
instances when overriding other methods like runStatements.
Bugzilla Report 27178.
+ * <sql> has a new failOnConnectionError attribute that can be used to
+ keep a build going even if the task failed to connect to the
+ database.
+ Bugzilla Report 36712.
+
Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================
Modified: ant/core/trunk/docs/manual/CoreTasks/sql.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/sql.html?rev=675917&r1=675916&r2=675917&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/sql.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/sql.html Fri Jul 11 03:59:48 2008
@@ -195,6 +195,13 @@
<td width="10%" valign="top">No, default <em>false</em></td>
</tr>
+<tr>
+ <td width="12%" valign="top">failOnConnectionError</td>
+ <td width="78%" valign="top">If false, will only print a warning
+ message and not execute any statement if the task fails to connect
+ to the database. <em>Since Ant 1.8.0</em>.</td>
+ <td width="10%" valign="top">No, default <em>true</em></td>
+</tr>
</table>
<h3>Parameters specified as nested elements</h3>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java?rev=675917&r1=675916&r2=675917&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java Fri Jul 11 03:59:48 2008
@@ -143,6 +143,12 @@
private String version = null;
/**
+ * whether the task fails when ant fails to connect to the database.
+ * @since Ant 1.8.0
+ */
+ private boolean failOnConnectionError = true;
+
+ /**
* Sets the classpath for loading the driver.
* @param classpath The classpath to set
*/
@@ -232,6 +238,15 @@
}
/**
+ * whether the task should cause the build to fail if it cannot
+ * connect to the database.
+ * @since Ant 1.8.0
+ */
+ public void setFailOnConnectionError(boolean b) {
+ failOnConnectionError = b;
+ }
+
+ /**
* Verify we are connected to the correct RDBMS
* @param conn the jdbc connection
* @return true if we are connected to the correct RDBMS
@@ -296,7 +311,8 @@
*
* The calling method is responsible for closing the connection.
*
- * @return Connection the newly created connection.
+ * @return Connection the newly created connection or null if the
+ * connection failed and failOnConnectionError is false.
* @throws BuildException if the UserId/Password/Url is not set or there
* is no suitable driver or the driver fails to load.
*/
@@ -326,7 +342,13 @@
conn.setAutoCommit(autocommit);
return conn;
} catch (SQLException e) {
- throw new BuildException(e, getLocation());
+ // failed to connect
+ if (!failOnConnectionError) {
+ log("Failed to connect: " + e.getMessage(), Project.MSG_WARN);
+ return null;
+ } else {
+ throw new BuildException(e, getLocation());
+ }
}
}
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=675917&r1=675916&r2=675917&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 Fri Jul 11 03:59:48 2008
@@ -159,7 +159,7 @@
/**
* Action to perform if an error is found
- **/
+ */
private String onError = "abort";
/**