bodewig 01/08/06 07:10:43
Modified: src/main/org/apache/tools/ant Project.java
src/main/org/apache/tools/ant/taskdefs Copy.java Move.java
Touch.java
Added: src/main/org/apache/tools/ant/util FileUtils.java
Removed: src/main/org/apache/tools/ant FileUtils.java
Log:
Move FileUtils into util package.
Revision Changes Path
1.70 +13 -9 jakarta-ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- Project.java 2001/08/05 11:06:53 1.69
+++ Project.java 2001/08/06 14:10:42 1.70
@@ -59,6 +59,7 @@
import java.text.*;
import org.apache.tools.ant.types.FilterSet;
+import org.apache.tools.ant.util.FileUtils;
/**
* Central representation of an Ant project. This class defines a
@@ -140,7 +141,10 @@
}
}
+ private FileUtils fileUtils;
+
public Project() {
+ fileUtils = FileUtils.getFileUtils();
}
/**
@@ -690,7 +694,7 @@
* @deprecated
*/
public void copyFile(String sourceFile, String destFile) throws
IOException {
- FileUtils.copyFile(sourceFile, destFile);
+ fileUtils.copyFile(sourceFile, destFile);
}
/**
@@ -703,7 +707,7 @@
*/
public void copyFile(String sourceFile, String destFile, boolean
filtering)
throws IOException {
- FileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null);
+ fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null);
}
/**
@@ -717,7 +721,7 @@
*/
public void copyFile(String sourceFile, String destFile, boolean
filtering,
boolean overwrite) throws IOException {
- FileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null, overwrite);
+ fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null, overwrite);
}
/**
@@ -734,7 +738,7 @@
public void copyFile(String sourceFile, String destFile, boolean
filtering,
boolean overwrite, boolean preserveLastModified)
throws IOException {
- FileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null,
+ fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null,
overwrite, preserveLastModified);
}
@@ -747,7 +751,7 @@
* @deprecated
*/
public void copyFile(File sourceFile, File destFile) throws IOException {
- FileUtils.copyFile(sourceFile, destFile);
+ fileUtils.copyFile(sourceFile, destFile);
}
/**
@@ -760,7 +764,7 @@
*/
public void copyFile(File sourceFile, File destFile, boolean filtering)
throws IOException {
- FileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null);
+ fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null);
}
/**
@@ -774,7 +778,7 @@
*/
public void copyFile(File sourceFile, File destFile, boolean filtering,
boolean overwrite) throws IOException {
- FileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null, overwrite);
+ fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null, overwrite);
}
/**
@@ -791,7 +795,7 @@
public void copyFile(File sourceFile, File destFile, boolean filtering,
boolean overwrite, boolean preserveLastModified)
throws IOException {
- FileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null,
+ fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet
: null,
overwrite, preserveLastModified);
}
@@ -806,7 +810,7 @@
+ " in JDK 1.1", Project.MSG_WARN);
return;
}
- FileUtils.setFileLastModified(file, time);
+ fileUtils.setFileLastModified(file, time);
log("Setting modification time for " + file, MSG_VERBOSE);
}
1.18 +8 -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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Copy.java 2001/08/04 14:37:40 1.17
+++ Copy.java 2001/08/06 14:10:43 1.18
@@ -93,7 +93,14 @@
protected Mapper mapperElement = null;
private Vector filterSets = new Vector();
+ private FileUtils fileUtils;
+ public Copy() {
+ fileUtils = FileUtils.getFileUtils();
+ }
+
+ protected FileUtils getFileUtils() {return fileUtils;}
+
/**
* Sets a single source file to copy.
*/
@@ -365,7 +372,7 @@
for (Enumeration filterEnum = filterSets.elements();
filterEnum.hasMoreElements();) {
executionFilterSet.addFilterSet((FilterSet)filterEnum.nextElement());
}
- FileUtils.copyFile(fromFile, toFile, executionFilterSet,
+ fileUtils.copyFile(fromFile, toFile, executionFilterSet,
forceOverwrite, preserveLastModified);
} catch (IOException ioe) {
String msg = "Failed to copy " + fromFile + " to " +
toFile
1.6 +2 -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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Move.java 2001/08/04 14:37:40 1.5
+++ Move.java 2001/08/06 14:10:43 1.6
@@ -108,8 +108,8 @@
for (Enumeration filterEnum =
getFilterSets().elements(); filterEnum.hasMoreElements();) {
executionFilterSet.addFilterSet((FilterSet)filterEnum.nextElement());
}
- FileUtils.copyFile(fromFile, toFile, executionFilterSet,
- forceOverwrite);
+ getFileUtils().copyFile(fromFile, toFile,
executionFilterSet,
+ forceOverwrite);
File f = new File(fromFile);
if (!f.delete()) {
1.9 +7 -2
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Touch.java
Index: Touch.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Touch.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Touch.java 2001/03/29 10:08:55 1.8
+++ Touch.java 2001/08/06 14:10:43 1.9
@@ -89,7 +89,12 @@
private long millis = -1;
private String dateTime;
private Vector filesets = new Vector();
+ private FileUtils fileUtils;
+ public Touch() {
+ fileUtils = FileUtils.getFileUtils();
+ }
+
/**
* Sets a single source file to touch. If the file does not exist
* an empty file will be created.
@@ -204,9 +209,9 @@
}
if (millis < 0) {
- project.setFileLastModified(file, System.currentTimeMillis());
+ fileUtils.setFileLastModified(file, System.currentTimeMillis());
} else {
- project.setFileLastModified(file, millis);
+ fileUtils.setFileLastModified(file, millis);
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java
Index: FileUtils.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.util;
import java.io.*;
import java.lang.reflect.Method;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FilterSet;
/**
* Central representation of an Ant project. This class defines a
* Ant project with all of it's targets and tasks. It also provides
* the mechanism to kick off a build using a particular target name.
* <p>
* This class also encapsulates methods which allow Files to be refered
* to using abstract path names which are translated to native system
* file paths at runtime as well as defining various project properties.
*
* @author [EMAIL PROTECTED]
* @author <a href="mailto:[EMAIL PROTECTED]">Conor MacNeill</a>
*/
public class FileUtils {
private static Object lockReflection = new Object();
private static java.lang.reflect.Method setLastModified = null;
/**
* Factory method.
*/
public static FileUtils getFileUtils() {
return new FileUtils();
}
/**
* Empty constructor.
*/
protected FileUtils() {}
/**
* Convienence method to copy a file from a source to a destination.
* No filtering is performed.
*
* @throws IOException
*/
public void copyFile(String sourceFile, String destFile) throws
IOException {
copyFile(new File(sourceFile), new File(destFile), null, false,
false);
}
/**
* Convienence method to copy a file from a source to a destination
* specifying if token filtering must be used.
*
* @throws IOException
*/
public void copyFile(String sourceFile, String destFile, FilterSet
filterSet)
throws IOException
{
copyFile(new File(sourceFile), new File(destFile), filterSet, false,
false);
}
/**
* Convienence method to copy a file from a source to a
* destination specifying if token filtering must be used and if
* source files may overwrite newer destination files.
*
* @throws IOException
*/
public void copyFile(String sourceFile, String destFile, FilterSet
filterSet,
boolean overwrite) throws IOException {
copyFile(new File(sourceFile), new File(destFile), filterSet,
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
* last modified time of <code>destFile</code> file should be made equal
* to the last modified time of <code>sourceFile</code>.
*
* @throws IOException
*/
public void copyFile(String sourceFile, String destFile, FilterSet
filterSet,
boolean overwrite, boolean preserveLastModified)
throws IOException {
copyFile(new File(sourceFile), new File(destFile), filterSet,
overwrite, preserveLastModified);
}
/**
* Convienence method to copy a file from a source to a destination.
* No filtering is performed.
*
* @throws IOException
*/
public void copyFile(File sourceFile, File destFile) throws IOException {
copyFile(sourceFile, destFile, null, false, false);
}
/**
* Convienence method to copy a file from a source to a destination
* specifying if token filtering must be used.
*
* @throws IOException
*/
public void copyFile(File sourceFile, File destFile, FilterSet filterSet)
throws IOException {
copyFile(sourceFile, destFile, filterSet, false, false);
}
/**
* Convienence method to copy a file from a source to a
* destination specifying if token filtering must be used and if
* source files may overwrite newer destination files.
*
* @throws IOException
*/
public void copyFile(File sourceFile, File destFile, FilterSet filterSet,
boolean overwrite) throws IOException {
copyFile(sourceFile, destFile, filterSet, 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
* last modified time of <code>destFile</code> file should be made equal
* to the last modified time of <code>sourceFile</code>.
*
* @throws IOException
*/
public void copyFile(File sourceFile, File destFile, FilterSet filterSet,
boolean overwrite, boolean preserveLastModified)
throws IOException {
if (overwrite || !destFile.exists() ||
destFile.lastModified() < sourceFile.lastModified()) {
if (destFile.exists() && destFile.isFile()) {
destFile.delete();
}
// ensure that parent dir of dest file exists!
// not using getParentFile method to stay 1.1 compat
File parent = new File(destFile.getParent());
if (!parent.exists()) {
parent.mkdirs();
}
if (filterSet != null && filterSet.hasFilters()) {
BufferedReader in = new BufferedReader(new
FileReader(sourceFile));
BufferedWriter out = new BufferedWriter(new
FileWriter(destFile));
int length;
String newline = null;
String line = in.readLine();
while (line != null) {
if (line.length() == 0) {
out.newLine();
} else {
newline = filterSet.replaceTokens(line);
out.write(newline);
out.newLine();
}
line = in.readLine();
}
out.close();
in.close();
} else {
FileInputStream in = new FileInputStream(sourceFile);
FileOutputStream out = new FileOutputStream(destFile);
byte[] buffer = new byte[8 * 1024];
int count = 0;
do {
out.write(buffer, 0, count);
count = in.read(buffer, 0, buffer.length);
} while (count != -1);
in.close();
out.close();
}
if (preserveLastModified) {
setFileLastModified(destFile, sourceFile.lastModified());
}
}
}
/**
* see whether we have a setLastModified method in File and return it.
*/
protected final Method getSetLastModified() {
if (Project.getJavaVersion() == Project.JAVA_1_1) {
return null;
}
if (setLastModified == null) {
synchronized (lockReflection) {
if (setLastModified == null) {
try {
setLastModified =
java.io.File.class.getMethod("setLastModified",
new Class[]
{Long.TYPE});
} catch (NoSuchMethodException nse) {
throw new BuildException("File.setlastModified not in
JDK > 1.1?",
nse);
}
}
}
}
return setLastModified;
}
/**
* Calls File.setLastModified(long time) in a Java 1.1 compatible way.
*/
public void setFileLastModified(File file, long time) throws
BuildException {
if (Project.getJavaVersion() == Project.JAVA_1_1) {
return;
}
Long[] times = new Long[1];
if (time < 0) {
times[0] = new Long(System.currentTimeMillis());
} else {
times[0] = new Long(time);
}
try {
getSetLastModified().invoke(file, times);
} catch (java.lang.reflect.InvocationTargetException ite) {
Throwable nested = ite.getTargetException();
throw new BuildException("Exception setting the modification time
"
+ "of " + file, nested);
} catch (Throwable other) {
throw new BuildException("Exception setting the modification time
"
+ "of " + file, other);
}
}
}