diff --git a/docs/manual/CoreTasks/property.html b/docs/manual/CoreTasks/property.html index 5a934e819..3552315ff 100644 --- a/docs/manual/CoreTasks/property.html +++ b/docs/manual/CoreTasks/property.html @@ -147,7 +147,7 @@ Two of the values are shown being echoed.


-

Copyright © 2001 Apache Software Foundation. All rights +

Copyright © 2001-2002 Apache Software Foundation. All rights Reserved.

diff --git a/src/main/org/apache/tools/ant/taskdefs/Copy.java b/src/main/org/apache/tools/ant/taskdefs/Copy.java index 1640d5fb6..47efb956d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copy.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copy.java @@ -88,6 +88,8 @@ import java.util.Enumeration; * @author Stefan Bodewig * @author Michael McCallum * @author Magesh Umasankar + * + * @version $Revision$ */ public class Copy extends Task { protected File file = null; // the source file @@ -109,6 +111,7 @@ public class Copy extends Task { protected Mapper mapperElement = null; private Vector filterSets = new Vector(); private FileUtils fileUtils; + private String encoding = null; public Copy() { fileUtils = FileUtils.newFileUtils(); @@ -163,6 +166,16 @@ public class Copy extends Task { preserveLastModified = preserve; } + /** + * Whether to give the copied files the same last modified time as + * the original files. + * + * @since 1.32, Ant 1.5 + */ + public boolean getPreserveLastModified() { + return preserveLastModified; + } + /** * Get the filtersets being applied to this operation. * @@ -234,6 +247,24 @@ public class Copy extends Task { return mapperElement; } + /** + * Sets the character encoding + * + * @since 1.32, Ant 1.5 + */ + public void setEncoding (String encoding) { + this.encoding = encoding; + } + + /** + * @return the character encoding, null if not set. + * + * @since 1.32, Ant 1.5 + */ + public String getEncoding() { + return encoding; + } + /** * Performs the copy operation. */ @@ -422,7 +453,8 @@ public class Copy extends Task { executionFilters.addFilterSet((FilterSet)filterEnum.nextElement()); } fileUtils.copyFile(fromFile, toFile, executionFilters, - forceOverwrite, preserveLastModified); + forceOverwrite, preserveLastModified, + encoding); } catch (IOException ioe) { String msg = "Failed to copy " + fromFile + " to " + toFile + " due to " + ioe.getMessage(); diff --git a/src/main/org/apache/tools/ant/taskdefs/Move.java b/src/main/org/apache/tools/ant/taskdefs/Move.java index 76d95bb50..acadd1742 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Move.java +++ b/src/main/org/apache/tools/ant/taskdefs/Move.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -81,6 +81,8 @@ import java.util.Enumeration; * * @author Glenn McAllister glennm@ca.ibm.com * @author Magesh Umasankar + * + * @version $Revision$ */ public class Move extends Copy { @@ -155,7 +157,9 @@ public class Move extends Copy { executionFilters.addFilterSet((FilterSet)filterEnum.nextElement()); } getFileUtils().copyFile(f, d, executionFilters, - forceOverwrite); + forceOverwrite, + getPreserveLastModified(), + getEncoding()); f = new File(fromFile); if (!f.delete()) { diff --git a/src/main/org/apache/tools/ant/taskdefs/Property.java b/src/main/org/apache/tools/ant/taskdefs/Property.java index d8fde8506..551404d4e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Property.java +++ b/src/main/org/apache/tools/ant/taskdefs/Property.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java index d0baf302a..4eaf7c64d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index 3b70a37a5..7da78bad1 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -64,6 +64,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.lang.reflect.Method; import java.text.DecimalFormat; @@ -140,7 +142,7 @@ public class FileUtils { overwrite, false); } - /** + /** * Convienence method to copy a file from a source to a * destination specifying if token filtering must be used, if * source files may overwrite newer destination files and the @@ -156,6 +158,25 @@ public class FileUtils { overwrite, preserveLastModified); } + /** + * Convienence method to copy a file from a source to a + * destination specifying if token filtering must be used, if + * source files may overwrite newer destination files and the + * last modified time of destFile file should be made equal + * to the last modified time of sourceFile. + * + * @throws IOException + * + * @since 1.14, Ant 1.5 + */ + public void copyFile(String sourceFile, String destFile, + FilterSetCollection filters, boolean overwrite, + boolean preserveLastModified, String encoding) + throws IOException { + copyFile(new File(sourceFile), new File(destFile), filters, + overwrite, preserveLastModified, encoding); + } + /** * Convienence method to copy a file from a source to a destination. * No filtering is performed. @@ -201,6 +222,26 @@ public class FileUtils { public void copyFile(File sourceFile, File destFile, FilterSetCollection filters, boolean overwrite, boolean preserveLastModified) throws IOException { + copyFile(sourceFile, destFile, filters, overwrite, + preserveLastModified, null); + } + + /** + * Convienence method to copy a file from a source to a + * destination specifying if token filtering must be used, if + * source files may overwrite newer destination files, the last + * modified time of destFile file should be made + * equal to the last modified time of sourceFile and + * which character encoding to assume. + * + * @throws IOException + * + * @since 1.14, Ant 1.5 + */ + public void copyFile(File sourceFile, File destFile, + FilterSetCollection filters, boolean overwrite, + boolean preserveLastModified, String encoding) + throws IOException { if (overwrite || !destFile.exists() || destFile.lastModified() < sourceFile.lastModified()) { @@ -217,8 +258,16 @@ public class FileUtils { } if (filters != null && filters.hasFilters()) { - BufferedReader in = new BufferedReader(new FileReader(sourceFile)); - BufferedWriter out = new BufferedWriter(new FileWriter(destFile)); + BufferedReader in = null; + BufferedWriter out = null; + + if (encoding == null) { + in = new BufferedReader(new FileReader(sourceFile)); + out = new BufferedWriter(new FileWriter(destFile)); + } else { + in = new BufferedReader(new InputStreamReader(new FileInputStream(sourceFile), encoding)); + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destFile), encoding)); + } int length; String newline = null; diff --git a/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java b/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java index f0b497463..55a22a726 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without