diff --git a/WHATSNEW b/WHATSNEW index 914a89466..4a16b9708 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -334,20 +334,25 @@ Other changes: * now accepts nested FileNameMappers e.g. . Bugzilla report 37604. -* New task loadresource that accompanies loadfile for non file resources. +* New task that accompanies for non file resources. * now supports an encoding when saving to a file. * new GreedyInputHandler added. -* add textfile attribute to the filesmatch condition. +* add textfile attribute to the condition. When true, the text + contents of the two files are compared, ignoring line ending differences. -* new resourcesmatch condition. +* new condition. * added the onmissingfiltersfile attribute to filterset. Bugzilla report 19845. * added the inline handler element to the input task. +* supports property expansion if you set the expandProperties attribute. By default + it does not expand properties, something we dare not change for fear of breaking complex + SQL operations in existing files. + Changes from Ant 1.6.4 to Ant 1.6.5 =================================== diff --git a/docs/manual/CoreTasks/sql.html b/docs/manual/CoreTasks/sql.html index cd4a5373e..962b08738 100644 --- a/docs/manual/CoreTasks/sql.html +++ b/docs/manual/CoreTasks/sql.html @@ -146,10 +146,17 @@ and abort execution and transaction and fail task.

object will perform escape substitution.
See Statement's - API docs for details. since Ant 1.6. + API docs for details. . No (default=true) + + expandproperties + Set to true to turn on property expansion in + nested SQL, inline in the task or nested transactions. Since Ant 1.7. + No (default=false) + +

Parameters specified as nested elements

@@ -220,7 +227,8 @@ truncate table some_other_table;

Connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the two SQL statements - inserting data into some_table and truncating some_other_table

+ inserting data into some_table and truncating some_other_table. Ant Properties + in the nested text will not be expanded.

Note that you may want to enclose your statements in <![CDATA[ ... ]]> sections so you don't @@ -239,6 +247,23 @@ update some_table set column1 = column1 + 1 where column2 < 42; ]]></sql> +The following command turns property expansion in nested text on (it is off purely for backwards +compatibility), then creates a new user in the HSQLDB database using Ant properties. + +

<sql
+    driver="org.hsqldb.jdbcDriver";
+    url="jdbc:hsqldb:file:${database.dir}"
+    userid="sa"
+    password=""
+    expandProperties="true"
+    >
+  <transaction>
+    CREATE USER ${newuser} PASSWORD ${newpassword}
+  </transaction>
+</sql>
+
+ +

The following connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the SQL statements contained within the files data1.sql, data2.sql and data3.sql and then executes the truncate diff --git a/docs/manual/api/index.html b/docs/manual/api/index.html index b8ea4e2ac..622c7e0c7 100644 --- a/docs/manual/api/index.html +++ b/docs/manual/api/index.html @@ -1,12 +1,37 @@ - - - - -Apache Ant API - - -Redirecting to Apache Ant API ... - - - + + + + + + +Apache Ant API + + + + + + + + + + + +<H2> +Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. +<BR> +Link to<A HREF="overview-summary.html">Non-frame version.</A> + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java b/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java index c400674c1..490ffcffe 100644 --- a/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java @@ -300,7 +300,7 @@ public abstract class JDBCTask extends Task { */ protected Connection getConnection() throws BuildException { if (userId == null) { - throw new BuildException("User Id attribute must be set!", getLocation()); + throw new BuildException("UserId attribute must be set!", getLocation()); } if (password == null) { throw new BuildException("Password attribute must be set!", getLocation()); @@ -378,14 +378,17 @@ public abstract class JDBCTask extends Task { } catch (ClassNotFoundException e) { throw new BuildException( "Class Not Found: JDBC driver " + driver + " could not be loaded", + e, getLocation()); } catch (IllegalAccessException e) { throw new BuildException( "Illegal Access: JDBC driver " + driver + " could not be loaded", + e, getLocation()); } catch (InstantiationException e) { throw new BuildException( "Instantiation Exception: JDBC driver " + driver + " could not be loaded", + e, getLocation()); } return driverInstance; diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index 385ab6191..10168a338 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -180,6 +180,14 @@ public class SQLExec extends JDBCTask { */ private boolean escapeProcessing = true; + /** + * should properties be expanded in text? + * false for backwards compatibility + * + * @since Ant 1.7 + */ + private boolean expandProperties = false; + /** * Set the name of the SQL file to be run. * Required unless statements are enclosed in the build file @@ -189,12 +197,35 @@ public class SQLExec extends JDBCTask { this.srcFile = srcFile; } + /** + * Enable property expansion inside nested text + * + * @param expandProperties + * @since Ant 1.7 + */ + public void setExpandProperties(boolean expandProperties) { + this.expandProperties = expandProperties; + } + + /** + * is property expansion inside inline text enabled? + * + * @return true if properties are to be expanded. + * @since Ant 1.7 + */ + public boolean getExpandProperties() { + return expandProperties; + } + /** * Set an inline SQL command to execute. - * NB: Properties are not expanded in this text. - * @param sql a inline string containing the SQL command. + * NB: Properties are not expanded in this text unless {@link #expandProperties} + * is set. + * @param sql an inline string containing the SQL command. */ public void addText(String sql) { + //there is no need to expand properties here as that happens when Transaction.addText is + //called; to do so here would be an error. this.sqlCommand += sql; } @@ -209,7 +240,7 @@ public class SQLExec extends JDBCTask { /** * Adds a collection of resources (nested element). - * @param set a collection of resources containing SQL commands, + * @param rc a collection of resources containing SQL commands, * each resource is run in a separate transaction. * @since Ant 1.7 */ @@ -664,11 +695,15 @@ public class SQLExec extends JDBCTask { * @param src the source file */ public void setSrc(File src) { - setSrcResource(new FileResource(src)); + //there are places (in this file, and perhaps elsewhere, where it is assumed + //that null is an acceptable parameter. + if(src!=null) { + setSrcResource(new FileResource(src)); + } } /** - * Set the source file attribute. + * Set the source resource attribute. * @param src the source file * @since Ant 1.7 */ @@ -684,7 +719,12 @@ public class SQLExec extends JDBCTask { * @param sql the inline text */ public void addText(String sql) { - this.tSqlCommand += sql; + if (sql != null) { + if (getExpandProperties()) { + sql = getProject().replaceProperties(sql); + } + this.tSqlCommand += sql; + } } /** diff --git a/src/main/org/apache/tools/ant/types/resources/FileResource.java b/src/main/org/apache/tools/ant/types/resources/FileResource.java index acbbfa333..1a1eb4004 100755 --- a/src/main/org/apache/tools/ant/types/resources/FileResource.java +++ b/src/main/org/apache/tools/ant/types/resources/FileResource.java @@ -277,8 +277,14 @@ public class FileResource extends Resource implements Touchable { * @return this FileResource formatted as a String. */ public String toString() { - return isReference() ? getCheckedRef().toString() - : FILE_UTILS.normalize(file.getAbsolutePath()).getAbsolutePath(); + if(isReference()) { + return getCheckedRef().toString(); + } + if(file==null) { + return "(unbound file resource)"; + } + String absolutePath = file.getAbsolutePath(); + return FILE_UTILS.normalize(absolutePath).getAbsolutePath(); } /**