bodewig 02/02/25 03:03:40
Modified: docs/manual/CoreTasks property.html
src/main/org/apache/tools/ant/taskdefs Copy.java Move.java
Property.java
src/main/org/apache/tools/ant/taskdefs/optional/ide
VAJWorkspaceScanner.java
src/main/org/apache/tools/ant/util FileUtils.java
src/testcases/org/apache/tools/ant/taskdefs
PropertyTest.java
Log:
Add encoding attribute to copy/move so that filtered operations work
on encodings different than the platform's default as well.
PR: Christopher Taylor <[EMAIL PROTECTED]>
some year 2002 fixes.
Revision Changes Path
1.10 +1 -1 jakarta-ant/docs/manual/CoreTasks/property.html
Index: property.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/property.html,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- property.html 24 Feb 2002 04:18:56 -0000 1.9
+++ property.html 25 Feb 2002 11:03:39 -0000 1.10
@@ -147,7 +147,7 @@
</p>
<hr>
-<p align="center">Copyright © 2001 Apache Software Foundation. All
rights
+<p align="center">Copyright © 2001-2002 Apache Software Foundation. All
rights
Reserved.</p>
</body>
</html>
1.32 +33 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java
Index: Copy.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Copy.java 5 Feb 2002 08:08:10 -0000 1.31
+++ Copy.java 25 Feb 2002 11:03:40 -0000 1.32
@@ -88,6 +88,8 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @author <A href="[EMAIL PROTECTED]">Michael McCallum</A>
* @author <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
+ *
+ * @version $Revision: 1.32 $
*/
public class Copy extends Task {
protected File file = null; // the source file
@@ -109,6 +111,7 @@
protected Mapper mapperElement = null;
private Vector filterSets = new Vector();
private FileUtils fileUtils;
+ private String encoding = null;
public Copy() {
fileUtils = FileUtils.newFileUtils();
@@ -164,6 +167,16 @@
}
/**
+ * 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.
*
* @return a vector of FilterSet objects
@@ -235,6 +248,24 @@
}
/**
+ * Sets the character encoding
+ *
+ * @since 1.32, Ant 1.5
+ */
+ public void setEncoding (String encoding) {
+ this.encoding = encoding;
+ }
+
+ /**
+ * @return the character encoding, <code>null</code> if not set.
+ *
+ * @since 1.32, Ant 1.5
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
* Performs the copy operation.
*/
public void execute() throws BuildException {
@@ -422,7 +453,8 @@
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();
1.16 +6 -2
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Move.java
Index: Move.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Move.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Move.java 25 Jan 2002 16:15:44 -0000 1.15
+++ Move.java 25 Feb 2002 11:03:40 -0000 1.16
@@ -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 @@
*
* @author Glenn McAllister <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
+ *
+ * @version $Revision: 1.16 $
*/
public class Move extends Copy {
@@ -155,7 +157,9 @@
executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
}
getFileUtils().copyFile(f, d, executionFilters,
- forceOverwrite);
+ forceOverwrite,
+
getPreserveLastModified(),
+ getEncoding());
f = new File(fromFile);
if (!f.delete()) {
1.45 +1 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java
Index: Property.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- Property.java 23 Feb 2002 20:42:14 -0000 1.44
+++ Property.java 25 Feb 2002 11:03:40 -0000 1.45
@@ -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
1.8 +1 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java
Index: VAJWorkspaceScanner.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- VAJWorkspaceScanner.java 25 Feb 2002 08:27:26 -0000 1.7
+++ VAJWorkspaceScanner.java 25 Feb 2002 11:03:40 -0000 1.8
@@ -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
1.14 +53 -4
jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java
Index: FileUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- FileUtils.java 29 Jan 2002 17:12:20 -0000 1.13
+++ FileUtils.java 25 Feb 2002 11:03:40 -0000 1.14
@@ -64,6 +64,8 @@
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;
@@ -85,7 +87,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Conor MacNeill</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
*
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
public class FileUtils {
@@ -140,7 +142,7 @@
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
@@ -157,6 +159,25 @@
}
/**
+ * 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 <code>destFile</code> file should be made equal
+ * to the last modified time of <code>sourceFile</code>.
+ *
+ * @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 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 <code>destFile</code> file should be made
+ * equal to the last modified time of <code>sourceFile</code> 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 @@
}
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;
1.7 +1 -1
jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
Index: PropertyTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PropertyTest.java 23 Feb 2002 20:42:14 -0000 1.6
+++ PropertyTest.java 25 Feb 2002 11:03:40 -0000 1.7
@@ -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
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>