diff --git a/WHATSNEW b/WHATSNEW
index a1c5f5c71..6dd302b79 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -300,7 +300,8 @@ Other changes:
to destination strings.
* Add the echoxml task. This will echo nested XML to a file, with
- the normal processor instruction. UTF-8 encoding only.
+ the normal processor instruction. UTF-8 encoding only; no-namespace
+ support.
* Try to make subprojects of custom Project subclasses instances of the
same type. Bugzilla report 17901.
@@ -325,9 +326,10 @@ Other changes:
* now accepts nested FileNameMappers e.g. .
Bugzilla report 37604.
-
* New task loadresource that accompanies loadfile for non file resources.
+* now supports an encoding when saving to a file
+
Changes from Ant 1.6.4 to Ant 1.6.5
===================================
diff --git a/docs/manual/CoreTasks/echo.html b/docs/manual/CoreTasks/echo.html
index c2a516a28..553dd975f 100644
--- a/docs/manual/CoreTasks/echo.html
+++ b/docs/manual/CoreTasks/echo.html
@@ -50,6 +50,11 @@ ignored
One of "error", "warning", "info", "verbose", "debug" (decreasing order)
No - default is "warning". |
+
+ encoding |
+ encoding to use, default is ""; the local system encoding. |
+ No |
+
Examples
diff --git a/src/etc/testcases/taskdefs/echo.xml b/src/etc/testcases/taskdefs/echo.xml
index 7898104f2..4c35c3678 100644
--- a/src/etc/testcases/taskdefs/echo.xml
+++ b/src/etc/testcases/taskdefs/echo.xml
@@ -2,6 +2,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -20,4 +30,55 @@
+
+
+
+
+
+
+
+
+
+
+ Did not find @{expected} in @{actual}
+
+
+
+
+
+ Simple text
+
+
+
+
+
+
+ Simple text
+ Appended
+
+
+
+
+
+
+ Simple text
+
+
+
+
+
+
+ ${char}
+
+
+
+
+
+
+ ${char}
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/org/apache/tools/ant/taskdefs/Checksum.java b/src/main/org/apache/tools/ant/taskdefs/Checksum.java
index 35edb60c2..529cc6bfa 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Checksum.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Checksum.java
@@ -444,6 +444,14 @@ public class Checksum extends MatchingTask implements Condition {
if (todir != null) {
// A separate directory was explicitly declared
String path = (String) relativeFilePaths.get(file);
+ if(path==null) {
+ //bug 37386. this should not occur, but it has, once.
+ throw new BuildException("Internal error: " +
+ "relativeFilePaths could not match file"+
+ file+
+ "\n" +
+ "please file a bug report on this");
+ }
directory = new File(todir, path).getParentFile();
// Create the directory, as it might not exist.
directory.mkdirs();
diff --git a/src/main/org/apache/tools/ant/taskdefs/Echo.java b/src/main/org/apache/tools/ant/taskdefs/Echo.java
index e8f608d8d..ebbc3f2ec 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Echo.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Echo.java
@@ -20,6 +20,10 @@ package org.apache.tools.ant.taskdefs;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.Writer;
+import java.io.BufferedWriter;
+import java.io.OutputStreamWriter;
+import java.io.FileOutputStream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@@ -37,6 +41,8 @@ public class Echo extends Task {
protected String message = ""; // required
protected File file = null;
protected boolean append = false;
+ /** encoding; set to null or empty means 'default' */
+ private String encoding = "";
// by default, messages are always displayed
protected int logLevel = Project.MSG_WARN;
@@ -50,9 +56,16 @@ public class Echo extends Task {
if (file == null) {
log(message, logLevel);
} else {
- FileWriter out = null;
+ Writer out = null;
try {
- out = new FileWriter(file.getAbsolutePath(), append);
+ String filename = file.getAbsolutePath();
+ if(encoding==null || encoding.length()==0) {
+ out = new FileWriter(filename, append);
+ } else {
+ out = new BufferedWriter(
+ new OutputStreamWriter(
+ new FileOutputStream(filename, append),encoding));
+ }
out.write(message, 0, message.length());
} catch (IOException ioe) {
throw new BuildException(ioe, getLocation());
@@ -114,6 +127,15 @@ public class Echo extends Task {
logLevel = echoLevel.getLevel();
}
+ /**
+ * Declare the encoding to use when outputting to a file;
+ * Use "" for the platform's default encoding.
+ * @param encoding
+ */
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
/**
* The enumerated values for the level attribute.
*/
diff --git a/src/main/org/apache/tools/ant/taskdefs/EchoXML.java b/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
index 68830d429..5530116b4 100755
--- a/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
+++ b/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
@@ -24,12 +24,22 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.XMLFragment;
import org.apache.tools.ant.util.DOMElementWriter;
+import org.apache.tools.ant.util.FileUtils;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
/**
* Echo XML.
+ * Notice how this is a ProjectComponent and not a task, which means that certain
+ * well-known task operations (such as {@link org.apache.tools.ant.Task#getLocation()}) do not work.
+ *
+ * Other limitations
+ *
+ * - Currently no XMLNS support
+ * - Processing Instructions get ignored
+ * - Encoding is always UTF-8
+ *
* @since Ant 1.7
*/
public class EchoXML extends XMLFragment {
@@ -60,8 +70,8 @@ public class EchoXML extends XMLFragment {
*/
public void execute() {
DOMElementWriter writer = new DOMElementWriter(!append);
+ OutputStream os = null;
try {
- OutputStream os = null;
if (file != null) {
os = new FileOutputStream(file.getAbsolutePath(), append);
} else {
@@ -72,8 +82,12 @@ public class EchoXML extends XMLFragment {
throw new BuildException(ERROR_NO_XML);
}
writer.write((Element) n, os);
+ } catch (BuildException e) {
+ throw e;
} catch (Exception e) {
throw new BuildException(e);
+ } finally {
+ FileUtils.close(os);
}
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/EchoTest.java b/src/testcases/org/apache/tools/ant/taskdefs/EchoTest.java
index 82d39d4f2..4ec2cd2a8 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/EchoTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/EchoTest.java
@@ -50,4 +50,23 @@ public class EchoTest extends BuildFileTest {
" message\n"+
" ");
}
-}
+
+ public void testFile() throws Exception {
+ executeTarget("testFile");
+ }
+
+ public void testAppend() throws Exception {
+ executeTarget("testAppend");
+ }
+
+ public void testEmptyEncoding() throws Exception {
+ executeTarget("testEmptyEncoding");
+ }
+
+ public void testUTF16Encoding() throws Exception {
+ executeTarget("testUTF16Encoding");
+ }
+ public void testUTF8Encoding() throws Exception {
+ executeTarget("testUTF8Encoding");
+ }
+}
\ No newline at end of file