diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java
index 6622a850e..6b86d49ba 100644
--- a/src/main/org/apache/tools/ant/AntClassLoader.java
+++ b/src/main/org/apache/tools/ant/AntClassLoader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ import org.apache.tools.ant.util.LoaderUtils;
*/
public class AntClassLoader extends ClassLoader implements SubBuildListener {
- private static final FileUtils FILE_UTILS = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* An enumeration of all resources of a given name found within the
diff --git a/src/main/org/apache/tools/ant/DirectoryScanner.java b/src/main/org/apache/tools/ant/DirectoryScanner.java
index 9dd3c7b60..cf0789d5b 100644
--- a/src/main/org/apache/tools/ant/DirectoryScanner.java
+++ b/src/main/org/apache/tools/ant/DirectoryScanner.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -165,6 +165,9 @@ public class DirectoryScanner
"**/.DS_Store"
};
+ /** Helper. */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* Patterns which should be excluded by default.
*
@@ -241,9 +244,6 @@ public class DirectoryScanner
*/
private boolean followSymlinks = true;
- /** Helper. */
- private static final FileUtils FILE_UTILS = FileUtils.newFileUtils();
-
/** Whether or not everything tested so far has been included. */
protected boolean everythingIncluded = true;
diff --git a/src/main/org/apache/tools/ant/Location.java b/src/main/org/apache/tools/ant/Location.java
index 6b1a6ea80..d0036a3bc 100644
--- a/src/main/org/apache/tools/ant/Location.java
+++ b/src/main/org/apache/tools/ant/Location.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000,2002-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +39,8 @@ public class Location implements Serializable {
/** Location to use when one is needed but no information is available */
public static final Location UNKNOWN_LOCATION = new Location();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* Creates an "unknown" location.
*/
@@ -84,7 +86,7 @@ public class Location implements Serializable {
*/
public Location(String fileName, int lineNumber, int columnNumber) {
if (fileName != null && fileName.startsWith("file:")) {
- this.fileName = FileUtils.newFileUtils().fromURI(fileName);
+ this.fileName = FILE_UTILS.fromURI(fileName);
} else {
this.fileName = fileName;
}
diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java
index 326793391..680603e0b 100644
--- a/src/main/org/apache/tools/ant/Project.java
+++ b/src/main/org/apache/tools/ant/Project.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -123,6 +123,9 @@ public class Project {
/** Default filter end token. */
public static final String TOKEN_END = FilterSet.DEFAULT_TOKEN_END;
+ /** Instance of a utility class to use for file operations. */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/** Name of this project. */
private String name;
/** Description for this project (if any). */
@@ -185,6 +188,11 @@ public class Project {
*/
private boolean keepGoingMode = false;
+ /**
+ * Flag which catches Listeners which try to use System.out or System.err
+ */
+ private boolean loggingMessage = false;
+
/**
* Sets the input handler
*
@@ -227,19 +235,10 @@ public class Project {
return inputHandler;
}
- /** Instance of a utility class to use for file operations. */
- private FileUtils fileUtils;
-
- /**
- * Flag which catches Listeners which try to use System.out or System.err
- */
- private boolean loggingMessage = false;
-
/**
* Creates a new Ant project.
*/
public Project() {
- fileUtils = FileUtils.newFileUtils();
inputHandler = new DefaultInputHandler();
}
@@ -731,7 +730,7 @@ public class Project {
* isn't a directory
*/
public void setBaseDir(File baseDir) throws BuildException {
- baseDir = fileUtils.normalize(baseDir.getAbsolutePath());
+ baseDir = FILE_UTILS.normalize(baseDir.getAbsolutePath());
if (!baseDir.exists()) {
throw new BuildException("Basedir " + baseDir.getAbsolutePath()
+ " does not exist");
@@ -1300,7 +1299,7 @@ public class Project {
* @deprecated
*/
public File resolveFile(String fileName, File rootDir) {
- return fileUtils.resolveFile(rootDir, fileName);
+ return FILE_UTILS.resolveFile(rootDir, fileName);
}
/**
@@ -1316,7 +1315,7 @@ public class Project {
*
*/
public File resolveFile(String fileName) {
- return fileUtils.resolveFile(baseDir, fileName);
+ return FILE_UTILS.resolveFile(baseDir, fileName);
}
/**
@@ -1370,7 +1369,7 @@ public class Project {
*/
public void copyFile(String sourceFile, String destFile)
throws IOException {
- fileUtils.copyFile(sourceFile, destFile);
+ FILE_UTILS.copyFile(sourceFile, destFile);
}
/**
@@ -1390,7 +1389,7 @@ public class Project {
*/
public void copyFile(String sourceFile, String destFile, boolean filtering)
throws IOException {
- fileUtils.copyFile(sourceFile, destFile,
+ FILE_UTILS.copyFile(sourceFile, destFile,
filtering ? globalFilters : null);
}
@@ -1414,7 +1413,7 @@ public class Project {
*/
public void copyFile(String sourceFile, String destFile, boolean filtering,
boolean overwrite) throws IOException {
- fileUtils.copyFile(sourceFile, destFile,
+ FILE_UTILS.copyFile(sourceFile, destFile,
filtering ? globalFilters : null, overwrite);
}
@@ -1444,7 +1443,7 @@ public class Project {
public void copyFile(String sourceFile, String destFile, boolean filtering,
boolean overwrite, boolean preserveLastModified)
throws IOException {
- fileUtils.copyFile(sourceFile, destFile,
+ FILE_UTILS.copyFile(sourceFile, destFile,
filtering ? globalFilters : null, overwrite, preserveLastModified);
}
@@ -1462,7 +1461,7 @@ public class Project {
* @deprecated
*/
public void copyFile(File sourceFile, File destFile) throws IOException {
- fileUtils.copyFile(sourceFile, destFile);
+ FILE_UTILS.copyFile(sourceFile, destFile);
}
/**
@@ -1482,7 +1481,7 @@ public class Project {
*/
public void copyFile(File sourceFile, File destFile, boolean filtering)
throws IOException {
- fileUtils.copyFile(sourceFile, destFile,
+ FILE_UTILS.copyFile(sourceFile, destFile,
filtering ? globalFilters : null);
}
@@ -1506,7 +1505,7 @@ public class Project {
*/
public void copyFile(File sourceFile, File destFile, boolean filtering,
boolean overwrite) throws IOException {
- fileUtils.copyFile(sourceFile, destFile,
+ FILE_UTILS.copyFile(sourceFile, destFile,
filtering ? globalFilters : null, overwrite);
}
@@ -1536,7 +1535,7 @@ public class Project {
public void copyFile(File sourceFile, File destFile, boolean filtering,
boolean overwrite, boolean preserveLastModified)
throws IOException {
- fileUtils.copyFile(sourceFile, destFile,
+ FILE_UTILS.copyFile(sourceFile, destFile,
filtering ? globalFilters : null, overwrite, preserveLastModified);
}
@@ -1557,7 +1556,7 @@ public class Project {
*/
public void setFileLastModified(File file, long time)
throws BuildException {
- fileUtils.setFileLastModified(file, time);
+ FILE_UTILS.setFileLastModified(file, time);
log("Setting modification time for " + file, MSG_VERBOSE);
}
diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
index c0c79fafe..fb5ee5cc9 100644
--- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
+++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ public class ProjectHelper2 extends ProjectHelper {
/**
* helper for path -> URI and URI -> path conversions.
*/
- private static FileUtils fu = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* Parse an unknown element from a url
@@ -157,7 +157,7 @@ public class ProjectHelper2 extends ProjectHelper {
if (source instanceof File) {
buildFile = (File) source;
- buildFile = fu.normalize(buildFile.getAbsolutePath());
+ buildFile = FILE_UTILS.normalize(buildFile.getAbsolutePath());
context.setBuildFile(buildFile);
buildFileName = buildFile.toString();
// } else if (source instanceof InputStream ) {
@@ -188,7 +188,7 @@ public class ProjectHelper2 extends ProjectHelper {
String uri = null;
if (buildFile != null) {
- uri = fu.toURI(buildFile.getAbsolutePath());
+ uri = FILE_UTILS.toURI(buildFile.getAbsolutePath());
inputStream = new FileInputStream(buildFile);
} else {
inputStream = url.openStream();
@@ -415,16 +415,16 @@ public class ProjectHelper2 extends ProjectHelper {
+ systemId, Project.MSG_VERBOSE);
if (systemId.startsWith("file:")) {
- String path = fu.fromURI(systemId);
+ String path = FILE_UTILS.fromURI(systemId);
File file = new File(path);
if (!file.isAbsolute()) {
- file = fu.resolveFile(context.getBuildFileParent(), path);
+ file = FILE_UTILS.resolveFile(context.getBuildFileParent(), path);
}
try {
InputSource inputSource =
new InputSource(new FileInputStream(file));
- inputSource.setSystemId(fu.toURI(file.getAbsolutePath()));
+ inputSource.setSystemId(FILE_UTILS.toURI(file.getAbsolutePath()));
return inputSource;
} catch (FileNotFoundException fne) {
context.getProject().log(file.getAbsolutePath()
@@ -695,7 +695,7 @@ public class ProjectHelper2 extends ProjectHelper {
if ((new File(baseDir)).isAbsolute()) {
project.setBasedir(baseDir);
} else {
- project.setBaseDir(fu.resolveFile(
+ project.setBaseDir(FILE_UTILS.resolveFile(
context.getBuildFileParent(), baseDir));
}
}
diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
index 730418d37..19cc2fac4 100644
--- a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
+++ b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,6 +51,11 @@ import org.xml.sax.helpers.XMLReaderAdapter;
*/
public class ProjectHelperImpl extends ProjectHelper {
+ /**
+ * helper for path -> URI and URI -> path conversions.
+ */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* SAX 1 style parser used to parse the given file. This may
* in fact be a SAX 2 XMLReader wrapped in an XMLReaderAdapter.
@@ -78,10 +83,6 @@ public class ProjectHelperImpl extends ProjectHelper {
* been placed outside of targets.
*/
private Target implicitTarget = new Target();
- /**
- * helper for path -> URI and URI -> path conversions.
- */
- private static FileUtils fu = FileUtils.newFileUtils();
/**
* default constructor
@@ -119,7 +120,7 @@ public class ProjectHelperImpl extends ProjectHelper {
}
- String uri = fu.toURI(bFile.getAbsolutePath());
+ String uri = FILE_UTILS.toURI(bFile.getAbsolutePath());
inputStream = new FileInputStream(bFile);
inputSource = new InputSource(inputStream);
inputSource.setSystemId(uri);
@@ -296,15 +297,15 @@ public class ProjectHelperImpl extends ProjectHelper {
helperImpl.project.log("resolving systemId: " + systemId, Project.MSG_VERBOSE);
if (systemId.startsWith("file:")) {
- String path = fu.fromURI(systemId);
+ String path = FILE_UTILS.fromURI(systemId);
File file = new File(path);
if (!file.isAbsolute()) {
- file = fu.resolveFile(helperImpl.buildFileParent, path);
+ file = FILE_UTILS.resolveFile(helperImpl.buildFileParent, path);
}
try {
InputSource inputSource = new InputSource(new FileInputStream(file));
- inputSource.setSystemId(fu.toURI(file.getAbsolutePath()));
+ inputSource.setSystemId(FILE_UTILS.toURI(file.getAbsolutePath()));
return inputSource;
} catch (FileNotFoundException fne) {
helperImpl.project.log(file.getAbsolutePath() + " could not be found",
diff --git a/src/main/org/apache/tools/ant/loader/AntClassLoader2.java b/src/main/org/apache/tools/ant/loader/AntClassLoader2.java
index 2a7e9120a..30951f84a 100644
--- a/src/main/org/apache/tools/ant/loader/AntClassLoader2.java
+++ b/src/main/org/apache/tools/ant/loader/AntClassLoader2.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class AntClassLoader2 extends AntClassLoader {
/** Instance of a utility class to use for file operations. */
- private FileUtils fileUtils;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/** Static map of jar file/time to manifiest class-path entries */
private static Map pathMap = Collections.synchronizedMap(new HashMap());
@@ -53,7 +53,6 @@ public class AntClassLoader2 extends AntClassLoader {
* Constructor
*/
public AntClassLoader2() {
- fileUtils = FileUtils.newFileUtils();
}
/**
@@ -279,7 +278,7 @@ public class AntClassLoader2 extends AntClassLoader {
}
if (!"".equals(classpath)) {
- URL baseURL = fileUtils.getFileURL(pathComponent);
+ URL baseURL = FILE_UTILS.getFileURL(pathComponent);
StringTokenizer st = new StringTokenizer(classpath);
while (st.hasMoreTokens()) {
String classpathElement = st.nextToken();
diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java
index e594969dc..f98594f64 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Ant.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,6 +67,8 @@ public class Ant extends Task {
/** Target Executor */
private static final Executor EXECUTOR = new SingleCheckExecutor();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/** the basedir where is executed the build file */
private File dir = null;
@@ -164,7 +166,7 @@ public class Ant extends Task {
if (output != null) {
File outfile = null;
if (dir != null) {
- outfile = FileUtils.newFileUtils().resolveFile(dir, output);
+ outfile = FILE_UTILS.resolveFile(dir, output);
} else {
outfile = getProject().resolveFile(output);
}
@@ -305,7 +307,7 @@ public class Ant extends Task {
antFile = "build.xml";
}
- File file = FileUtils.newFileUtils().resolveFile(dir, antFile);
+ File file = FILE_UTILS.resolveFile(dir, antFile);
antFile = file.getAbsolutePath();
log("calling target(s) "
diff --git a/src/main/org/apache/tools/ant/taskdefs/Available.java b/src/main/org/apache/tools/ant/taskdefs/Available.java
index d6849494f..02a77dc17 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Available.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Available.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@ import org.apache.tools.ant.util.StringUtils;
* @ant.task category="control"
*/
public class Available extends Task implements Condition {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private String property;
private String classname;
@@ -143,8 +144,7 @@ public class Available extends Task implements Condition {
* @param file the name of the file which is required.
*/
public void setFile(File file) {
- this.file = FileUtils.newFileUtils()
- .removeLeadingPath(getProject().getBaseDir(), file);
+ this.file = FILE_UTILS.removeLeadingPath(getProject().getBaseDir(), file);
}
/**
diff --git a/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java b/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java
index d4e9c2dad..46f8c110e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java
+++ b/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +48,8 @@ public class BuildNumber
/** The default filename to use if no file specified. */
private static final String DEFAULT_FILENAME = DEFAULT_PROPERTY_NAME;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/** The File in which the build number is stored. */
private File myFile;
@@ -177,7 +179,7 @@ public class BuildNumber
if (!myFile.exists()) {
try {
- FileUtils.newFileUtils().createNewFile(myFile);
+ FILE_UTILS.createNewFile(myFile);
} catch (final IOException ioe) {
final String message =
myFile + " doesn't exist and new file can't be created.";
diff --git a/src/main/org/apache/tools/ant/taskdefs/Concat.java b/src/main/org/apache/tools/ant/taskdefs/Concat.java
index 7a0d1ce9b..0133b8aad 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Concat.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Concat.java
@@ -68,6 +68,7 @@ public class Concat extends Task {
// The size of buffers to be used
private static final int BUFFER_SIZE = 8192;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
// Attributes.
/**
@@ -125,9 +126,6 @@ public class Concat extends Task {
/** internal variable - used to collect the source files from sources */
private Vector sourceFiles = new Vector();
- /** 1.1 utilities and copy utilities */
- private static FileUtils fileUtils = FileUtils.newFileUtils();
-
// Attribute setters.
/**
@@ -465,7 +463,7 @@ public class Concat extends Task {
continue;
}
if (destinationFile != null
- && fileUtils.fileNameEquals(destinationFile, file)) {
+ && FILE_UTILS.fileNameEquals(destinationFile, file)) {
throw new BuildException("Input file \""
+ file + "\" "
+ "is the same as the output file.");
diff --git a/src/main/org/apache/tools/ant/taskdefs/DependSet.java b/src/main/org/apache/tools/ant/taskdefs/DependSet.java
index ce5b26705..0bfc84de7 100644
--- a/src/main/org/apache/tools/ant/taskdefs/DependSet.java
+++ b/src/main/org/apache/tools/ant/taskdefs/DependSet.java
@@ -24,7 +24,6 @@ import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.types.FileList;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.util.FileUtils;
@@ -78,6 +77,8 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class DependSet extends MatchingTask {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private Vector sourceFileSets = new Vector();
private Vector sourceFileLists = new Vector();
private Vector targetFileSets = new Vector();
@@ -138,7 +139,7 @@ public class DependSet extends MatchingTask {
We have to munge the time to allow for the filesystem time
granularity.
*/
- now += FileUtils.getFileUtils().getFileTimestampGranularity();
+ now += FILE_UTILS.getFileTimestampGranularity();
//
// Grab all the target files specified via filesets
diff --git a/src/main/org/apache/tools/ant/taskdefs/Ear.java b/src/main/org/apache/tools/ant/taskdefs/Ear.java
index 34b4830ee..4c256db86 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Ear.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Ear.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,10 +32,11 @@ import org.apache.tools.zip.ZipOutputStream;
* @ant.task category="packaging"
*/
public class Ear extends Jar {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private File deploymentDescriptor;
private boolean descriptorAdded;
- private static final FileUtils fu = FileUtils.newFileUtils();
+
/**
* Create an Ear task.
@@ -108,7 +109,7 @@ public class Ear extends Jar {
// element.
if (vPath.equalsIgnoreCase("META-INF/application.xml")) {
if (deploymentDescriptor == null
- || !fu.fileNameEquals(deploymentDescriptor, file)
+ || !FILE_UTILS.fileNameEquals(deploymentDescriptor, file)
|| descriptorAdded) {
log("Warning: selected " + archiveType
+ " files include a META-INF/application.xml which will"
diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java
index bbe3bd5bd..f617bedb6 100644
--- a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +39,8 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class ExecTask extends Task {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private String os;
private File dir;
@@ -392,10 +394,9 @@ public class ExecTask extends Task {
return executableFile.getAbsolutePath();
}
- FileUtils fileUtils = FileUtils.newFileUtils();
// now try to resolve against the dir if given
if (dir != null) {
- executableFile = fileUtils.resolveFile(dir, exec);
+ executableFile = FILE_UTILS.resolveFile(dir, exec);
if (executableFile.exists()) {
return executableFile.getAbsolutePath();
}
@@ -430,7 +431,7 @@ public class ExecTask extends Task {
if (p != null) {
String[] dirs = p.list();
for (int i = 0; i < dirs.length; i++) {
- executableFile = fileUtils.resolveFile(new File(dirs[i]),
+ executableFile = FILE_UTILS.resolveFile(new File(dirs[i]),
exec);
if (executableFile.exists()) {
return executableFile.getAbsolutePath();
diff --git a/src/main/org/apache/tools/ant/taskdefs/Execute.java b/src/main/org/apache/tools/ant/taskdefs/Execute.java
index 0db527784..3fa0d61e9 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Execute.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Execute.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,6 +49,8 @@ public class Execute {
/** Invalid exit code. **/
public static final int INVALID = Integer.MAX_VALUE;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private String[] cmdl = null;
private String[] env = null;
private int exitValue = INVALID;
@@ -1152,7 +1154,7 @@ public class Execute {
*/
private File createCommandFile(String[] cmd, String[] env)
throws IOException {
- File script = FileUtils.newFileUtils().createTempFile("ANT", ".COM", null);
+ File script = FILE_UTILS.createTempFile("ANT", ".COM", null);
//TODO: bind the longevity of the file to the exe
script.deleteOnExit();
PrintWriter out = null;
diff --git a/src/main/org/apache/tools/ant/taskdefs/Expand.java b/src/main/org/apache/tools/ant/taskdefs/Expand.java
index a2c6a3f1c..6a99a455c 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Expand.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Expand.java
@@ -63,6 +63,8 @@ public class Expand extends Task {
private String encoding = "UTF8";
/** Error message when more that one mapper is defined */
public static final String ERROR_MULTIPLE_MAPPERS = "Cannot define more than one mapper";
+
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* Do the work.
@@ -88,14 +90,12 @@ public class Expand extends Task {
throw new BuildException("Dest must be a directory.", getLocation());
}
- FileUtils fileUtils = FileUtils.newFileUtils();
-
if (source != null) {
if (source.isDirectory()) {
throw new BuildException("Src must not be a directory."
+ " Use nested filesets instead.", getLocation());
} else {
- expandFile(fileUtils, source, dest);
+ expandFile(FILE_UTILS, source, dest);
}
}
if (filesets.size() > 0) {
@@ -107,7 +107,7 @@ public class Expand extends Task {
String[] files = ds.getIncludedFiles();
for (int i = 0; i < files.length; ++i) {
File file = new File(fromDir, files[i]);
- expandFile(fileUtils, file, dest);
+ expandFile(FILE_UTILS, file, dest);
}
}
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
index c9077f444..c25dbc722 100644
--- a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
+++ b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -106,6 +106,8 @@ public class FixCRLF extends MatchingTask {
private static final char CTRLZ = '\u001A';
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private int tablength = 8;
private String spaces = " ";
private StringBuffer linebuf = new StringBuffer(1024);
@@ -120,8 +122,6 @@ public class FixCRLF extends MatchingTask {
private File srcDir;
private File destDir = null;
- private FileUtils fileUtils = FileUtils.newFileUtils();
-
/**
* Encoding to assume for the files
*/
@@ -373,7 +373,7 @@ public class FixCRLF extends MatchingTask {
try {
// Set up the output Writer
try {
- tmpFile = fileUtils.createTempFile("fixcrlf", "", null);
+ tmpFile = FILE_UTILS.createTempFile("fixcrlf", "", null);
tmpFile.deleteOnExit();
Writer writer = (encoding == null) ? new FileWriter(tmpFile)
: new OutputStreamWriter(new FileOutputStream(tmpFile),
@@ -527,7 +527,7 @@ public class FixCRLF extends MatchingTask {
if (destFile.exists()) {
// Compare the destination with the temp file
log("destFile exists", Project.MSG_DEBUG);
- if (!fileUtils.contentEquals(destFile, tmpFile)) {
+ if (!FILE_UTILS.contentEquals(destFile, tmpFile)) {
log(destFile + " is being written", Project.MSG_DEBUG);
} else {
log(destFile + " is not written, as the contents "
@@ -537,7 +537,7 @@ public class FixCRLF extends MatchingTask {
}
if (destIsWrong) {
- fileUtils.rename(tmpFile, destFile);
+ FILE_UTILS.rename(tmpFile, destFile);
tmpFile = null;
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java
index 9508c9336..e0c1ef721 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Get.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Get.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,6 +43,9 @@ import java.util.Date;
* @ant.task category="network"
*/
public class Get extends Task {
+
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private URL source; // required
private File dest; // required
private boolean verbose = false;
@@ -243,8 +246,7 @@ public class Get extends Task {
: ""), logLevel);
}
if (remoteTimestamp != 0) {
- FileUtils.newFileUtils()
- .setFileLastModified(dest, remoteTimestamp);
+ FILE_UTILS.setFileLastModified(dest, remoteTimestamp);
}
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/ImportTask.java b/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
index 59c6f6807..356c491db 100644
--- a/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
@@ -54,7 +54,7 @@ import java.util.Vector;
public class ImportTask extends Task {
private String file;
private boolean optional;
- private static final FileUtils FILE_UTILS = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* sets the optional attribute
diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
index bf9e416df..68e445c03 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -344,6 +344,8 @@ public class Javadoc extends Task {
}
}
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/** The command line built to execute Javadoc. */
private Commandline cmd = new Commandline();
@@ -427,7 +429,6 @@ public class Javadoc extends Task {
private Html footer = null;
private Html bottom = null;
private boolean useExternalFile = false;
- private FileUtils fileUtils = FileUtils.newFileUtils();
private String source = null;
private boolean linksource = false;
private boolean breakiterator = false;
@@ -1709,7 +1710,7 @@ public class Javadoc extends Task {
if (packageListFile.exists()) {
try {
String packageListURL =
- fileUtils.getFileURL(packageListLocation)
+ FILE_UTILS.getFileURL(packageListLocation)
.toExternalForm();
toExecute.createArgument()
.setValue("-linkoffline");
@@ -1858,7 +1859,7 @@ public class Javadoc extends Task {
*/
if (useExternalFile) {
if (tmpList == null) {
- tmpList = fileUtils.createTempFile("javadoc", "", null);
+ tmpList = FILE_UTILS.createTempFile("javadoc", "", null);
tmpList.deleteOnExit();
toExecute.createArgument()
.setValue("@" + tmpList.getAbsolutePath());
diff --git a/src/main/org/apache/tools/ant/taskdefs/Length.java b/src/main/org/apache/tools/ant/taskdefs/Length.java
index ceec0f06b..59b86d319 100755
--- a/src/main/org/apache/tools/ant/taskdefs/Length.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Length.java
@@ -21,7 +21,6 @@ import java.io.File;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
import java.util.Vector;
import java.util.HashSet;
import java.util.Iterator;
@@ -30,7 +29,6 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.dispatch.Dispatchable;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.util.FileUtils;
@@ -45,6 +43,7 @@ public class Length extends Task {
private static final String ALL = "all";
private static final String EACH = "each";
private static final String STRING = "string";
+
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private String property;
diff --git a/src/main/org/apache/tools/ant/taskdefs/Rename.java b/src/main/org/apache/tools/ant/taskdefs/Rename.java
index c4383efe4..d7c2585f5 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Rename.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Rename.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,8 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class Rename extends Task {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private File src;
private File dest;
private boolean replace = true;
@@ -83,7 +85,7 @@ public class Rename extends Task {
}
try {
- FileUtils.newFileUtils().rename(src, dest);
+ FILE_UTILS.rename(src, dest);
} catch (IOException e) {
throw new BuildException("Unable to rename " + src + " to "
+ dest, e, getLocation());
diff --git a/src/main/org/apache/tools/ant/taskdefs/Replace.java b/src/main/org/apache/tools/ant/taskdefs/Replace.java
index 514dc9b4d..3d56ae842 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Replace.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Replace.java
@@ -52,6 +52,8 @@ import org.apache.tools.ant.util.StringUtils;
*/
public class Replace extends MatchingTask {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private File src = null;
private NestedString token = null;
private NestedString value = new NestedString();
@@ -70,8 +72,6 @@ public class Replace extends MatchingTask {
/** The encoding used to read and write files - if null, uses default */
private String encoding = null;
- private FileUtils fileUtils = FileUtils.newFileUtils();
-
/**
* An inline string to use as the replacement text.
*/
@@ -587,7 +587,7 @@ public class Replace extends MatchingTask {
try {
in = new FileInput(src);
- temp = fileUtils.createTempFile("rep", ".tmp",
+ temp = FILE_UTILS.createTempFile("rep", ".tmp",
src.getParentFile());
out = new FileOutput(temp);
@@ -613,7 +613,7 @@ public class Replace extends MatchingTask {
boolean changes = (replaceCount != repCountStart);
if (changes) {
- fileUtils.rename(temp, src);
+ FILE_UTILS.rename(temp, src);
temp = null;
}
} catch (IOException ioe) {
diff --git a/src/main/org/apache/tools/ant/taskdefs/Rmic.java b/src/main/org/apache/tools/ant/taskdefs/Rmic.java
index e15a05d0c..cebb29bfd 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Rmic.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Rmic.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,8 +104,6 @@ public class Rmic extends MatchingTask {
private ClassLoader loader = null;
- private FileUtils fileUtils = FileUtils.newFileUtils();
-
private FacadeTaskHelper facade;
/** unable to verify message */
public static final String ERROR_UNABLE_TO_VERIFY_CLASS = "Unable to verify class ";
@@ -122,6 +120,8 @@ public class Rmic extends MatchingTask {
/** base attribute not set message */
public static final String ERROR_BASE_NOT_SET = "base attribute must be set!";
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* Constructor for Rmic.
*/
@@ -607,11 +607,11 @@ public class Rmic extends MatchingTask {
File newFile = new File(sourceBaseFile, sourceFileName);
try {
if (filtering) {
- fileUtils.copyFile(oldFile, newFile,
+ FILE_UTILS.copyFile(oldFile, newFile,
new FilterSetCollection(getProject()
.getGlobalFilterSet()));
} else {
- fileUtils.copyFile(oldFile, newFile);
+ FILE_UTILS.copyFile(oldFile, newFile);
}
oldFile.delete();
} catch (IOException ioe) {
diff --git a/src/main/org/apache/tools/ant/taskdefs/SignJar.java b/src/main/org/apache/tools/ant/taskdefs/SignJar.java
index ca3d87ddd..1b75dddb9 100644
--- a/src/main/org/apache/tools/ant/taskdefs/SignJar.java
+++ b/src/main/org/apache/tools/ant/taskdefs/SignJar.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,6 +40,8 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class SignJar extends Task {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* The name of the jar file.
*/
@@ -351,7 +353,7 @@ public class SignJar extends Task {
if (jarFile.equals(signedjarFile)) {
return false;
}
- if (FileUtils.newFileUtils().isUpToDate(jarFile, signedjarFile)) {
+ if (FILE_UTILS.isUpToDate(jarFile, signedjarFile)) {
return true;
}
} else {
diff --git a/src/main/org/apache/tools/ant/taskdefs/TempFile.java b/src/main/org/apache/tools/ant/taskdefs/TempFile.java
index 31afc3568..7d5f9bc55 100644
--- a/src/main/org/apache/tools/ant/taskdefs/TempFile.java
+++ b/src/main/org/apache/tools/ant/taskdefs/TempFile.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,6 +40,8 @@ import org.apache.tools.ant.util.FileUtils;
public class TempFile extends Task {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* Name of property to set.
*/
@@ -115,8 +117,7 @@ public class TempFile extends Task {
if (destDir == null) {
destDir = getProject().resolveFile(".");
}
- FileUtils utils = FileUtils.newFileUtils();
- File tfile = utils.createTempFile(prefix, suffix, destDir);
+ File tfile = FILE_UTILS.createTempFile(prefix, suffix, destDir);
getProject().setNewProperty(property, tfile.toString());
}
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/Touch.java b/src/main/org/apache/tools/ant/taskdefs/Touch.java
index dc964d065..a1925fb5e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Touch.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Touch.java
@@ -72,13 +72,13 @@ public class Touch extends Task {
DateFormat.MEDIUM, Locale.US);
}
};
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private File file;
private long millis = -1;
private String dateTime;
private Vector filesets = new Vector();
private Vector filelists = new Vector();
- private FileUtils fileUtils;
private boolean dateTimeConfigured;
private boolean mkdirs;
private boolean verbose = true;
@@ -89,7 +89,6 @@ public class Touch extends Task {
* Construct a new Touch
task.
*/
public Touch() {
- fileUtils = FileUtils.newFileUtils();
}
/**
@@ -315,7 +314,7 @@ public class Touch extends Task {
}
private void touch(File fromDir, String filename, long defaultTimestamp) {
- File f = fileUtils.resolveFile(fromDir, filename);
+ File f = FILE_UTILS.resolveFile(fromDir, filename);
if (fileNameMapper == null) {
touch(f, defaultTimestamp);
} else {
@@ -334,7 +333,7 @@ public class Touch extends Task {
log("Creating " + file,
((verbose) ? Project.MSG_INFO : Project.MSG_VERBOSE));
try {
- fileUtils.createNewFile(file, mkdirs);
+ FILE_UTILS.createNewFile(file, mkdirs);
} catch (IOException ioe) {
throw new BuildException("Could not create " + file, ioe,
getLocation());
@@ -344,7 +343,7 @@ public class Touch extends Task {
throw new BuildException("Can not change modification date of "
+ "read-only file " + file);
}
- fileUtils.setFileLastModified(file, modTime);
+ FILE_UTILS.setFileLastModified(file, modTime);
}
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/War.java b/src/main/org/apache/tools/ant/taskdefs/War.java
index a32f9d05c..c64503635 100644
--- a/src/main/org/apache/tools/ant/taskdefs/War.java
+++ b/src/main/org/apache/tools/ant/taskdefs/War.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ public class War extends Jar {
*/
private boolean descriptorAdded;
- private static final FileUtils fu = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
public War() {
super();
@@ -146,7 +146,7 @@ public class War extends Jar {
// by the "webxml" attribute and in a element.
if (vPath.equalsIgnoreCase("WEB-INF/web.xml")) {
if (deploymentDescriptor == null
- || !fu.fileNameEquals(deploymentDescriptor, file)
+ || !FILE_UTILS.fileNameEquals(deploymentDescriptor, file)
|| descriptorAdded) {
log("Warning: selected " + archiveType
+ " files include a WEB-INF/web.xml which will be ignored "
diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
index 985124c40..4949b34d5 100644
--- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
+++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,9 +82,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
/** force output of target files even if they already exist */
private boolean force = false;
- /** Utilities used for file operations */
- private FileUtils fileUtils;
-
/** XSL output properties to be used */
private Vector outputProperties = new Vector();
@@ -103,6 +100,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
private static final String XALAN_LIAISON_CLASS =
"org.apache.tools.ant.taskdefs.optional.XalanLiaison";
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* Whether to style all files in the included directories as well.
*
@@ -145,7 +145,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Creates a new XSLTProcess Task.
*/
public XSLTProcess() {
- fileUtils = FileUtils.newFileUtils();
+
} //-- XSLTProcess
/**
@@ -221,7 +221,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
File stylesheet = getProject().resolveFile(xslFile);
if (!stylesheet.exists()) {
- stylesheet = fileUtils.resolveFile(baseDir, xslFile);
+ stylesheet = FILE_UTILS.resolveFile(baseDir, xslFile);
/*
* shouldn't throw out deprecation warnings before we know,
* the wrong version has been used.
diff --git a/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java b/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java
index 285b4025f..2b87d693e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java
+++ b/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -179,7 +179,6 @@ public class XmlProperty extends org.apache.tools.ant.Task {
private boolean semanticAttributes = false;
private boolean includeSemanticAttribute = false;
private File rootDirectory = null;
- private FileUtils fileUtils = FileUtils.newFileUtils();
private Hashtable addedAttributes = new Hashtable();
private XMLCatalog xmlCatalog = new XMLCatalog();
@@ -192,6 +191,7 @@ public class XmlProperty extends org.apache.tools.ant.Task {
private static final String[] ATTRIBUTES = new String[] {
ID, REF_ID, LOCATION, VALUE, PATH, PATHID
};
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* Constructor.
@@ -686,7 +686,7 @@ public class XmlProperty extends org.apache.tools.ant.Task {
if (rootDirectory == null) {
return getProject().resolveFile(fileName);
}
- return fileUtils.resolveFile(rootDirectory, fileName);
+ return FILE_UTILS.resolveFile(rootDirectory, fileName);
}
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/Zip.java b/src/main/org/apache/tools/ant/taskdefs/Zip.java
index 649ff35b7..9a2664300 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Zip.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Zip.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,7 +84,7 @@ public class Zip extends MatchingTask {
protected boolean doubleFilePass = false;
protected boolean skipWriting = false;
- private static FileUtils fileUtils = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* true when we are adding new files into the Zip file, as opposed
@@ -406,12 +406,12 @@ public class Zip extends MatchingTask {
if (doUpdate) {
renamedFile =
- fileUtils.createTempFile("zip", ".tmp",
+ FILE_UTILS.createTempFile("zip", ".tmp",
zipFile.getParentFile());
renamedFile.deleteOnExit();
try {
- fileUtils.rename(zipFile, renamedFile);
+ FILE_UTILS.rename(zipFile, renamedFile);
} catch (SecurityException e) {
throw new BuildException(
"Not allowed to rename old file ("
@@ -528,7 +528,7 @@ public class Zip extends MatchingTask {
if (doUpdate && renamedFile != null) {
try {
- fileUtils.rename(renamedFile, zipFile);
+ FILE_UTILS.rename(renamedFile, zipFile);
} catch (IOException e) {
msg += " (and I couldn't rename the temporary file "
+ renamedFile.getName() + " back)";
@@ -641,7 +641,7 @@ public class Zip extends MatchingTask {
}
if (!resources[i].isDirectory() && dealingWithFiles) {
- File f = fileUtils.resolveFile(base,
+ File f = FILE_UTILS.resolveFile(base,
resources[i].getName());
zipFile(f, zOut, prefix + name, fileMode);
} else if (!resources[i].isDirectory()) {
@@ -827,7 +827,7 @@ public class Zip extends MatchingTask {
for (int j = 0; j < initialResources[i].length; j++) {
File resourceAsFile =
- fileUtils.resolveFile(base,
+ FILE_UTILS.resolveFile(base,
initialResources[i][j].getName());
if (resourceAsFile.equals(zipFile)) {
throw new BuildException("A zip file cannot include "
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
index 3f84ba880..23ce0a0e3 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,6 +41,8 @@ import org.apache.tools.ant.taskdefs.condition.Os;
*/
public abstract class DefaultCompilerAdapter implements CompilerAdapter {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/* jdg - TODO - all these attributes are currently protected, but they
* should probably be private in the near future.
*/
@@ -69,7 +71,6 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
protected static final String lSep = System.getProperty("line.separator");
protected Javac attributes;
- private FileUtils fileUtils = FileUtils.newFileUtils();
/**
* Set the Javac instance which contains the configured compilation
@@ -408,7 +409,7 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
&& firstFileName >= 0) {
PrintWriter out = null;
try {
- tmpFile = fileUtils.createTempFile(
+ tmpFile = FILE_UTILS.createTempFile(
"files", "", getJavac().getTempdir());
tmpFile.deleteOnExit();
out = new PrintWriter(new FileWriter(tmpFile));
diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java b/src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java
index a87ed0a3b..7af373fb2 100644
--- a/src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java
+++ b/src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,14 +32,15 @@ import org.apache.tools.ant.util.FileUtils;
public class FilesMatch implements Condition {
/**
- * files to compare
+ * Helper that provides the file comparison method.
*/
- private File file1, file2;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
- * Helper that provides the file comparison method.
+ * files to compare
*/
- private FileUtils fu = FileUtils.newFileUtils();
+ private File file1, file2;
+
/**
* Sets the File1 attribute
@@ -78,7 +79,7 @@ public class FilesMatch implements Condition {
//#now match the files
boolean matches = false;
try {
- matches = fu.contentEquals(file1, file2);
+ matches = FILE_UTILS.contentEquals(file1, file2);
} catch (IOException ioe) {
throw new BuildException("when comparing files: "
+ ioe.getMessage(), ioe);
diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/IsFileSelected.java b/src/main/org/apache/tools/ant/taskdefs/condition/IsFileSelected.java
index 35787a742..afef0f191 100644
--- a/src/main/org/apache/tools/ant/taskdefs/condition/IsFileSelected.java
+++ b/src/main/org/apache/tools/ant/taskdefs/condition/IsFileSelected.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation
+ * Copyright 2004-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,9 @@ import org.apache.tools.ant.types.selectors.AbstractSelectorContainer;
* This is a condition that checks to see if a file passes an embedded selector.
*/
public class IsFileSelected extends AbstractSelectorContainer implements Condition {
- private static final FileUtils FILE_UTILS = FileUtils.newFileUtils();
+
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private File file;
private File baseDir;
diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
index 09511924e..abbac68a6 100644
--- a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
+++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,6 +65,12 @@ import org.apache.tools.ant.util.FileUtils;
* @ant.task name="cvstagdiff"
*/
public class CvsTagDiff extends AbstractCvsTask {
+
+ /**
+ * Used to create the temp file for cvs log
+ */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* Token to identify the word file in the rdiff log
*/
@@ -122,11 +128,6 @@ public class CvsTagDiff extends AbstractCvsTask {
*/
private File mydestfile;
- /**
- * Used to create the temp file for cvs log
- */
- private FileUtils myfileUtils = FileUtils.newFileUtils();
-
/**
* The package/module to analyze.
* @param p the name of the package to analyse
@@ -215,7 +216,7 @@ public class CvsTagDiff extends AbstractCvsTask {
setCommand("");
File tmpFile = null;
try {
- tmpFile = myfileUtils.createTempFile("cvstagdiff", ".log", null);
+ tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null);
tmpFile.deleteOnExit();
setOutput(tmpFile);
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java b/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java
index 7e65d7aa8..f39c90143 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,12 +84,11 @@ public class ANTLR extends Task {
/** Instance of a utility class to use for file operations. */
- private FileUtils fileUtils;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
public ANTLR() {
commandline.setVm(JavaEnvUtils.getJreExecutable("java"));
commandline.setClassname("antlr.Tool");
- fileUtils = FileUtils.newFileUtils();
}
/**
@@ -120,7 +119,7 @@ public class ANTLR extends Task {
} else {
sg = superGrammar;
}
- setGlib(fileUtils.resolveFile(getProject().getBaseDir(), sg));
+ setGlib(FILE_UTILS.resolveFile(getProject().getBaseDir(), sg));
}
/**
* Sets an optional super grammar file
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
index f088cc620..ab00d4f81 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ public class Cab extends MatchingTask {
protected String archiveType = "cab";
- private FileUtils fileUtils = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* The name/location of where to create the .cab file.
@@ -138,7 +138,7 @@ public class Cab extends MatchingTask {
boolean upToDate = true;
for (int i = 0; i < files.size() && upToDate; i++) {
String file = files.elementAt(i).toString();
- if (fileUtils.resolveFile(baseDir, file).lastModified()
+ if (FILE_UTILS.resolveFile(baseDir, file).lastModified()
> cabFile.lastModified()) {
upToDate = false;
}
@@ -152,7 +152,7 @@ public class Cab extends MatchingTask {
*/
protected File createListFile(Vector files)
throws IOException {
- File listFile = fileUtils.createTempFile("ant", "", null);
+ File listFile = FILE_UTILS.createTempFile("ant", "", null);
listFile.deleteOnExit();
PrintWriter writer = new PrintWriter(new FileOutputStream(listFile));
@@ -283,7 +283,7 @@ public class Cab extends MatchingTask {
exec.setDir(baseDir);
if (!doVerbose) {
- outFile = fileUtils.createTempFile("ant", "", null);
+ outFile = FILE_UTILS.createTempFile("ant", "", null);
outFile.deleteOnExit();
exec.setOutput(outFile);
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
index f9c108399..57c9a6dd5 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -120,7 +120,7 @@ public class ReplaceRegExp extends Task {
private RegularExpression regex;
private Substitution subs;
- private FileUtils fileUtils = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* Encoding to assume for the files
@@ -321,7 +321,7 @@ public class ReplaceRegExp extends Task {
*/
protected void doReplace(File f, int options)
throws IOException {
- File temp = fileUtils.createTempFile("replace", ".txt", null);
+ File temp = FILE_UTILS.createTempFile("replace", ".txt", null);
temp.deleteOnExit();
Reader r = null;
@@ -445,7 +445,7 @@ public class ReplaceRegExp extends Task {
if (changes) {
log("File has changed; saving the updated file", Project.MSG_VERBOSE);
try {
- fileUtils.rename(temp, f);
+ FILE_UTILS.rename(temp, f);
temp = null;
} catch (IOException e) {
throw new BuildException("Couldn't rename temporary file "
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
index ced5af8c8..bdf57de24 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ public class XMLValidateTask extends Task {
/**
* helper for path -> URI and URI -> path conversions.
*/
- private static final FileUtils FILE_UTILS = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
protected static final String INIT_FAILED_MSG =
"Could not start xml validation: ";
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ildasm.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ildasm.java
index 8d1257deb..0aad2abbb 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ildasm.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ildasm.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,6 +58,8 @@ import java.io.File;
*/
public class Ildasm extends Task {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* source file (mandatory)
*/
@@ -328,7 +330,7 @@ public class Ildasm extends Task {
}
long sourceTime = sourceFile.lastModified();
long destTime = destFile.lastModified();
- if (sourceTime > (destTime + FileUtils.newFileUtils().getFileTimestampGranularity())) {
+ if (sourceTime > (destTime + FILE_UTILS.getFileTimestampGranularity())) {
log("Source file is newer than the dest file: a rebuild is required",
Project.MSG_VERBOSE);
return true;
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/ImportTypelib.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/ImportTypelib.java
index 912b79570..e31cb55bd 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/ImportTypelib.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/ImportTypelib.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ import java.io.File;
*/
public class ImportTypelib extends Task {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* input file; precedes options
@@ -166,7 +167,7 @@ public class ImportTypelib extends Task {
}
long sourceTime = srcFile.lastModified();
long destTime = destFile.lastModified();
- if (sourceTime > (destTime + FileUtils.newFileUtils().getFileTimestampGranularity())) {
+ if (sourceTime > (destTime + FILE_UTILS.getFileTimestampGranularity())) {
log("Source file is newer than the dest file: a rebuild is required",
Project.MSG_VERBOSE);
return true;
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java
index 6c48a23f2..f93b293d6 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@ import java.io.IOException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.BufferedOutputStream;
-import java.io.FileNotFoundException;
import java.util.Hashtable;
import org.apache.tools.ant.BuildException;
@@ -56,6 +55,8 @@ import org.apache.tools.ant.types.Commandline;
public class NetCommand {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* owner project
*/
@@ -326,9 +327,8 @@ public class NetCommand {
//and set @tmpfile as the command -then we remember to delete the tempfile
//afterwards
FileOutputStream fos = null;
- FileUtils fileUtils = FileUtils.newFileUtils();
- temporaryCommandFile = fileUtils.createTempFile("cmd", ".txt", null);
+ temporaryCommandFile = FILE_UTILS.createTempFile("cmd", ".txt", null);
owner.log("Using response file" + temporaryCommandFile, Project.MSG_VERBOSE);
try {
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/WsdlToDotnet.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/WsdlToDotnet.java
index 47bede134..9c6c2e9b5 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/WsdlToDotnet.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/WsdlToDotnet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.apache.tools.ant.taskdefs.optional.dotnet;
import java.io.File;
import java.util.Vector;
import java.util.Iterator;
-import java.net.URL;
import java.net.MalformedURLException;
import org.apache.tools.ant.BuildException;
@@ -52,6 +51,11 @@ import org.apache.tools.ant.util.FileUtils;
public class WsdlToDotnet extends Task {
+ /**
+ * used for timestamp checking
+ */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* name of output file (required)
*/
@@ -124,11 +128,6 @@ public class WsdlToDotnet extends Task {
*/
public static final String ERROR_NO_DEST_FILE = "destination file must be specified";
- /**
- * used for timestamp checking
- */
- private FileUtils fileutils = FileUtils.newFileUtils();
-
/**
* Name of the file to generate. Required
* @param destFile filename
@@ -346,7 +345,7 @@ public class WsdlToDotnet extends Task {
if (destLastModified == -1) {
return true;
}
- return !fileutils.isUpToDate(schema.getTimestamp(), destLastModified);
+ return !FILE_UTILS.isUpToDate(schema.getTimestamp(), destLastModified);
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
index b5c48aafa..f459b6ebb 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -86,6 +86,9 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
protected static final String COMPILER_EJB11 = "weblogic.ejbc";
protected static final String COMPILER_EJB20 = "weblogic.ejbc20";
+ /** File utilities instance for copying jars */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/** Instance variable that stores the suffix for the weblogic jarfile. */
private String jarSuffix = ".jar";
@@ -136,9 +139,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
*/
private Integer jvmDebugLevel = null;
- /** File utilities instance for copying jars */
- private FileUtils fileUtils = FileUtils.newFileUtils();
-
private File outputDir;
/**
@@ -498,7 +498,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
if (noEJBC) {
try {
- fileUtils.copyFile(sourceJar, destJar);
+ FILE_UTILS.copyFile(sourceJar, destJar);
if (!keepgenerated) {
sourceJar.delete();
}
@@ -840,7 +840,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
}
try {
- fileUtils.rename(newWLJarFile, weblogicJarFile);
+ FILE_UTILS.rename(newWLJarFile, weblogicJarFile);
} catch (IOException renameException) {
log(renameException.getMessage(), Project.MSG_WARN);
rebuild = true;
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
index 9476d48a5..728493bd3 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,6 +84,8 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool {
protected static final String WAS_CMP_MAP = "Map.mapxmi";
protected static final String WAS_CMP_SCHEMA = "Schema.dbxmi";
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/** Instance variable that stores the suffix for the websphere jarfile. */
private String jarSuffix = ".jar";
@@ -840,8 +842,7 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool {
}
try {
- FileUtils.newFileUtils().rename(newwasJarFile,
- websphereJarFile);
+ FILE_UTILS.rename(newwasJarFile, websphereJarFile);
} catch (IOException renameException) {
log(renameException.getMessage(), Project.MSG_WARN);
rebuild = true;
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
index 0f83f3b26..e353bf164 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -145,7 +145,7 @@ public class Translate extends MatchingTask {
* Used to resolve file names.
*/
- private FileUtils fileUtils = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* Last Modified Timestamp of resource bundle file being used.
@@ -499,7 +499,7 @@ public class Translate extends MatchingTask {
String[] srcFiles = ds.getIncludedFiles();
for (int j = 0; j < srcFiles.length; j++) {
try {
- File dest = fileUtils.resolveFile(toDir, srcFiles[j]);
+ File dest = FILE_UTILS.resolveFile(toDir, srcFiles[j]);
//Make sure parent dirs exist, else, create them.
try {
File destDir = new File(dest.getParent());
@@ -512,7 +512,7 @@ public class Translate extends MatchingTask {
Project.MSG_DEBUG);
}
destLastModified = dest.lastModified();
- File src = fileUtils.resolveFile(ds.getBasedir(), srcFiles[j]);
+ File src = FILE_UTILS.resolveFile(ds.getBasedir(), srcFiles[j]);
srcLastModified = src.lastModified();
//Check to see if dest file has to be recreated
boolean needsWork = forceOverwrite
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
index b9d4fc303..72424ced1 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -151,6 +151,8 @@ public class JUnitTask extends Task {
private static final int STRING_BUFFER_SIZE = 128;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* If true, force ant to re-classload all classes for each JUnit TestCase
*
@@ -925,7 +927,7 @@ public class JUnitTask extends Task {
*/
private File createTempPropertiesFile(String prefix) {
File propsFile =
- FileUtils.newFileUtils().createTempFile(prefix, ".properties",
+ FILE_UTILS.createTempFile(prefix, ".properties",
tmpDir != null ? tmpDir : getProject().getBaseDir());
propsFile.deleteOnExit();
return propsFile;
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java
index a5d63f99d..f5e26e961 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,6 +46,8 @@ import org.apache.tools.ant.util.JavaEnvUtils;
*/
public abstract class AbstractMetamataTask extends Task {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* The user classpath to be provided. It matches the -classpath of the
* command line. The classpath must includes both the .class and the
@@ -282,7 +284,7 @@ public abstract class AbstractMetamataTask extends Task {
}
protected final File createTmpFile() {
- File tmpFile = FileUtils.newFileUtils()
+ File tmpFile = FILE_UTILS
.createTempFile("metamata", ".tmp", getProject().getBaseDir());
tmpFile.deleteOnExit();
return tmpFile;
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
index 2a87f1e77..297a43bf7 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,6 +84,8 @@ public class FTP
/** Default port for FTP */
public static final int DEFAULT_FTP_PORT = 21;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private String remotedir;
private String server;
private String userid;
@@ -107,7 +109,6 @@ public class FTP
private boolean preserveLastModified = false;
private String chmod = null;
private String umask = null;
- private FileUtils fileUtils = FileUtils.newFileUtils();
protected static final String[] ACTION_STRS = {
"sending",
@@ -1487,7 +1488,7 @@ public class FTP
File tempFile = findFileName(ftp);
try {
// create a local temporary file
- fileUtils.createNewFile(tempFile);
+ FILE_UTILS.createNewFile(tempFile);
long localTimeStamp = tempFile.lastModified();
BufferedInputStream instream = new BufferedInputStream(new FileInputStream(tempFile));
ftp.storeFile(tempFile.getName(), instream);
@@ -1518,7 +1519,7 @@ public class FTP
FTPFile [] theFiles = null;
final int maxIterations = 1000;
for (int counter = 1; counter < maxIterations; counter++) {
- File localFile = fileUtils.createTempFile("ant" + Integer.toString(counter), ".tmp",
+ File localFile = FILE_UTILS.createTempFile("ant" + Integer.toString(counter), ".tmp",
null);
String fileName = localFile.getName();
boolean found = false;
@@ -1809,7 +1810,7 @@ public class FTP
outstream = null;
FTPFile[] remote = ftp.listFiles(resolveFile(filename));
if (remote.length > 0) {
- fileUtils.setFileLastModified(file,
+ FILE_UTILS.setFileLastModified(file,
remote[0].getTimestamp()
.getTime().getTime());
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovBase.java b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovBase.java
index a758c13c8..8642e8740 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovBase.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovBase.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ import org.apache.tools.ant.util.FileUtils;
*/
public abstract class CovBase extends Task {
private File home;
- private static FileUtils fu = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private boolean isJProbe4 = false;
private static boolean isDos = Os.isFamily("dos");
@@ -48,11 +48,11 @@ public abstract class CovBase extends Task {
protected File findCoverageJar() {
File loc = null;
if (isJProbe4) {
- loc = fu.resolveFile(home, "lib/coverage.jar");
+ loc = FILE_UTILS.resolveFile(home, "lib/coverage.jar");
} else {
- loc = fu.resolveFile(home, "coverage/coverage.jar");
+ loc = FILE_UTILS.resolveFile(home, "coverage/coverage.jar");
if (!loc.canRead()) {
- File newLoc = fu.resolveFile(home, "lib/coverage.jar");
+ File newLoc = FILE_UTILS.resolveFile(home, "lib/coverage.jar");
if (newLoc.canRead()) {
isJProbe4 = true;
loc = newLoc;
@@ -70,11 +70,11 @@ public abstract class CovBase extends Task {
File loc = null;
if (isJProbe4) {
- loc = fu.resolveFile(home, "bin/" + relativePath);
+ loc = FILE_UTILS.resolveFile(home, "bin/" + relativePath);
} else {
- loc = fu.resolveFile(home, relativePath);
+ loc = FILE_UTILS.resolveFile(home, relativePath);
if (!loc.canRead()) {
- File newLoc = fu.resolveFile(home, "bin/" + relativePath);
+ File newLoc = FILE_UTILS.resolveFile(home, "bin/" + relativePath);
if (newLoc.canRead()) {
isJProbe4 = true;
loc = newLoc;
@@ -85,7 +85,7 @@ public abstract class CovBase extends Task {
}
protected File createTempFile(String prefix) {
- return fu.createTempFile(prefix, ".tmp", null);
+ return FILE_UTILS.createTempFile(prefix, ".tmp", null);
}
protected String getParamFileArgument() {
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
index 055cb3402..72d642efa 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -118,6 +118,8 @@ public class Symlink extends Task {
private boolean overwrite;
private boolean failonerror;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/** Initialize the task. */
public void init() throws BuildException {
@@ -163,10 +165,9 @@ public class Symlink extends Task {
// handle the case where the link exists
// and points to a directory (bug 25181)
try {
- FileUtils fu = FileUtils.newFileUtils();
File test = new File(link);
File testRes = new File(resource);
- if (!fu.isSymbolicLink(test.getParentFile(),
+ if (!FILE_UTILS.isSymbolicLink(test.getParentFile(),
test.getName())) {
doLink(resource, link);
} else {
@@ -396,12 +397,12 @@ public class Symlink extends Task {
// rename the resource, thus breaking the link
String parentStr = canfil.getParent();
File parentDir = new File(parentStr);
- FileUtils fu = FileUtils.newFileUtils();
- File temp = fu.createTempFile("symlink", ".tmp", parentDir);
+
+ File temp = FILE_UTILS.createTempFile("symlink", ".tmp", parentDir);
temp.deleteOnExit();
try {
try {
- fu.rename(canfil, temp);
+ FILE_UTILS.rename(canfil, temp);
} catch (IOException e) {
throw new IOException("Couldn't rename resource when "
+ "attempting to delete " + linkfil);
@@ -416,7 +417,7 @@ public class Symlink extends Task {
} finally {
// return the resource to its original name.
try {
- fu.rename(temp, canfil);
+ FILE_UTILS.rename(temp, canfil);
} catch (IOException e) {
throw new IOException("Couldn't return resource " + temp
+ " to its original name: " + canstr
@@ -626,7 +627,6 @@ public class Symlink extends Task {
File parentNext, next;
String nameParentNext;
- FileUtils fu = FileUtils.newFileUtils();
Vector removals = new Vector();
while (enumLinks.hasMoreElements()) {
next = (File) enumLinks.nextElement();
@@ -634,7 +634,7 @@ public class Symlink extends Task {
parentNext = new File(nameParentNext);
try {
- if (!fu.isSymbolicLink(parentNext, next.getName())) {
+ if (!FILE_UTILS.isSymbolicLink(parentNext, next.getName())) {
removals.addElement(next);
}
} catch (IOException ioe) {
diff --git a/src/main/org/apache/tools/ant/taskdefs/repository/Library.java b/src/main/org/apache/tools/ant/taskdefs/repository/Library.java
index e125f082f..1e3cf7ad8 100644
--- a/src/main/org/apache/tools/ant/taskdefs/repository/Library.java
+++ b/src/main/org/apache/tools/ant/taskdefs/repository/Library.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation
+ * Copyright 2004-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ public class Library implements EnabledLibraryElement {
*/
private boolean enabled = true;
- private static FileUtils FILE_UTILS = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* turn policy on/off
diff --git a/src/main/org/apache/tools/ant/types/XMLCatalog.java b/src/main/org/apache/tools/ant/types/XMLCatalog.java
index 282d0d049..54b0b05e9 100644
--- a/src/main/org/apache/tools/ant/types/XMLCatalog.java
+++ b/src/main/org/apache/tools/ant/types/XMLCatalog.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -120,7 +120,7 @@ public class XMLCatalog extends DataType
implements Cloneable, EntityResolver, URIResolver {
/** helper for some File.toURL connversions */
- private static FileUtils fileUtils = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
//-- Fields ----------------------------------------------------------------
@@ -453,7 +453,7 @@ public class XMLCatalog extends DataType
URL baseURL = null;
try {
if (base == null) {
- baseURL = fileUtils.getFileURL(getProject().getBaseDir());
+ baseURL = FILE_UTILS.getFileURL(getProject().getBaseDir());
} else {
baseURL = new URL(base);
}
@@ -649,7 +649,7 @@ public class XMLCatalog extends DataType
baseURL = matchingEntry.getBase();
} else {
try {
- baseURL = fileUtils.getFileURL(getProject().getBaseDir());
+ baseURL = FILE_UTILS.getFileURL(getProject().getBaseDir());
} catch (MalformedURLException ex) {
throw new BuildException("Project basedir cannot be converted to a URL");
}
@@ -667,7 +667,7 @@ public class XMLCatalog extends DataType
log("uri : '"
+ uri + "' matches a readable file", Project.MSG_DEBUG);
try {
- url = fileUtils.getFileURL(testFile);
+ url = FILE_UTILS.getFileURL(testFile);
} catch (MalformedURLException ex1) {
throw new BuildException("could not find an URL for :" + testFile.getAbsolutePath());
}
@@ -679,7 +679,7 @@ public class XMLCatalog extends DataType
}
if (url != null) {
- String fileName = fileUtils.fromURI(url.toString());
+ String fileName = FILE_UTILS.fromURI(url.toString());
if (fileName != null) {
log("fileName " + fileName, Project.MSG_DEBUG);
File resFile = new File(fileName);
@@ -756,7 +756,7 @@ public class XMLCatalog extends DataType
baseURL = matchingEntry.getBase();
} else {
try {
- baseURL = fileUtils.getFileURL(getProject().getBaseDir());
+ baseURL = FILE_UTILS.getFileURL(getProject().getBaseDir());
} catch (MalformedURLException ex) {
throw new BuildException("Project basedir cannot be converted to a URL");
}
diff --git a/src/main/org/apache/tools/ant/types/selectors/DateSelector.java b/src/main/org/apache/tools/ant/types/selectors/DateSelector.java
index 8a65d91d6..8f8e8daad 100644
--- a/src/main/org/apache/tools/ant/types/selectors/DateSelector.java
+++ b/src/main/org/apache/tools/ant/types/selectors/DateSelector.java
@@ -24,7 +24,6 @@ import java.text.ParseException;
import java.util.Locale;
import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.util.FileUtils;
@@ -36,6 +35,9 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class DateSelector extends BaseExtendSelector {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private long millis = -1;
private String dateTime = null;
private boolean includeDirs = false;
@@ -60,7 +62,7 @@ public class DateSelector extends BaseExtendSelector {
*
*/
public DateSelector() {
- granularity = FileUtils.getFileUtils().getFileTimestampGranularity();
+ granularity = FILE_UTILS.getFileTimestampGranularity();
}
/**
diff --git a/src/main/org/apache/tools/ant/types/selectors/DifferentSelector.java b/src/main/org/apache/tools/ant/types/selectors/DifferentSelector.java
index c1a76acc7..93b47cfb5 100644
--- a/src/main/org/apache/tools/ant/types/selectors/DifferentSelector.java
+++ b/src/main/org/apache/tools/ant/types/selectors/DifferentSelector.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ import java.io.IOException;
*/
public class DifferentSelector extends MappingSelector {
- private FileUtils fileUtils = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private boolean ignoreFileTimes = true;
private boolean ignoreContents = false;
@@ -101,7 +101,7 @@ public class DifferentSelector extends MappingSelector {
if (!ignoreContents) {
//here do a bulk comparison
try {
- return !fileUtils.contentEquals(srcfile, destfile);
+ return !FILE_UTILS.contentEquals(srcfile, destfile);
} catch (IOException e) {
throw new BuildException("while comparing " + srcfile + " and "
+ destfile, e);
diff --git a/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java b/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java
index 15eb0453f..9421ab55d 100644
--- a/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java
+++ b/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java
@@ -30,6 +30,10 @@ import java.io.File;
* selector
*/
public abstract class MappingSelector extends BaseSelector {
+
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
protected File targetdir = null;
protected Mapper mapperElement = null;
protected FileNameMapper map = null;
@@ -40,7 +44,7 @@ public abstract class MappingSelector extends BaseSelector {
*
*/
public MappingSelector() {
- granularity = (int) FileUtils.getFileUtils().getFileTimestampGranularity();
+ granularity = (int) FILE_UTILS.getFileTimestampGranularity();
}
diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java
index caf162903..e5bc151c5 100644
--- a/src/main/org/apache/tools/ant/util/FileUtils.java
+++ b/src/main/org/apache/tools/ant/util/FileUtils.java
@@ -58,14 +58,16 @@ import org.apache.tools.ant.launch.Locator;
*/
public class FileUtils {
-
+
private static final FileUtils PRIMARY_INSTANCE = new FileUtils();
-
+
//get some non-crypto-grade randomness from various places.
private static Random rand = new Random(System.currentTimeMillis()
+ Runtime.getRuntime().freeMemory());
private static boolean onNetWare = Os.isFamily("netware");
+
+ private static final int BUF_SIZE = 8192;
// for toURI
private static boolean[] isSpecial = new boolean[256];
@@ -119,6 +121,7 @@ public class FileUtils {
* Method to retrieve The FileUtils, which is shared by all users of this
* method.
* @return an instance of FileUtils.
+ * @since Ant 1.7
*/
public static FileUtils getFileUtils() {
return PRIMARY_INSTANCE;
@@ -555,7 +558,7 @@ public class FileUtils {
if (filterChainsAvailable) {
ChainReaderHelper crh = new ChainReaderHelper();
- crh.setBufferSize(8192);
+ crh.setBufferSize(BUF_SIZE);
crh.setPrimaryReader(in);
crh.setFilterChains(filterChains);
crh.setProject(project);
@@ -612,14 +615,14 @@ public class FileUtils {
if (filterChainsAvailable) {
ChainReaderHelper crh = new ChainReaderHelper();
- crh.setBufferSize(8192);
+ crh.setBufferSize(BUF_SIZE);
crh.setPrimaryReader(in);
crh.setFilterChains(filterChains);
crh.setProject(project);
Reader rdr = crh.getAssembledReader();
in = new BufferedReader(rdr);
}
- char[] buffer = new char[1024 * 8];
+ char[] buffer = new char[BUF_SIZE];
while (true) {
int nRead = in.read(buffer, 0, buffer.length);
if (nRead == -1) {
@@ -1052,7 +1055,7 @@ public class FileUtils {
* reader.
*/
public static final String readFully(Reader rdr) throws IOException {
- return readFully(rdr, 8192);
+ return readFully(rdr, BUF_SIZE);
}
/**
diff --git a/src/main/org/apache/tools/ant/util/JAXPUtils.java b/src/main/org/apache/tools/ant/util/JAXPUtils.java
index 8ac0dcb41..369b7e9cc 100644
--- a/src/main/org/apache/tools/ant/util/JAXPUtils.java
+++ b/src/main/org/apache/tools/ant/util/JAXPUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ public class JAXPUtils {
*
* @since Ant 1.6
*/
- private static final FileUtils fu = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
* Parser factory to use to create parsers.
@@ -175,7 +175,7 @@ public class JAXPUtils {
* @since Ant 1.5.2
*/
public static String getSystemId(File file) {
- return fu.toURI(file.getAbsolutePath());
+ return FILE_UTILS.toURI(file.getAbsolutePath());
}
/**
diff --git a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java
index 8bddb3f69..d4be68715 100644
--- a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java
+++ b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ public class JavaEnvUtils {
private static final String javaHome = System.getProperty("java.home");
/** FileUtils instance for path normalization */
- private static final FileUtils fileUtils = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/** Version of currently running VM. */
private static String javaVersion;
@@ -250,7 +250,7 @@ public class JavaEnvUtils {
* @return null if the executable cannot be found.
*/
private static File findInDir(String dirName, String commandName) {
- File dir = fileUtils.normalize(dirName);
+ File dir = FILE_UTILS.normalize(dirName);
File executable = null;
if (dir.exists()) {
executable = new File(dir, addExtension(commandName));
@@ -371,8 +371,7 @@ public class JavaEnvUtils {
*/
public static File createVmsJavaOptionFile(String[] cmd)
throws IOException {
- File script = FileUtils.newFileUtils()
- .createTempFile("ANT", ".JAVA_OPTS", null);
+ File script = FILE_UTILS.createTempFile("ANT", ".JAVA_OPTS", null);
PrintWriter out = null;
try {
out = new PrintWriter(new BufferedWriter(new FileWriter(script)));
diff --git a/src/main/org/apache/tools/ant/util/LoaderUtils.java b/src/main/org/apache/tools/ant/util/LoaderUtils.java
index 057681710..28a559cf4 100644
--- a/src/main/org/apache/tools/ant/util/LoaderUtils.java
+++ b/src/main/org/apache/tools/ant/util/LoaderUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,10 @@ import org.apache.tools.ant.launch.Locator;
*
*/
public class LoaderUtils {
+
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* Set the context classloader
*
@@ -67,9 +71,8 @@ public class LoaderUtils {
*/
private static File normalizeSource(File source) {
if (source != null) {
- FileUtils fileUtils = FileUtils.newFileUtils();
try {
- source = fileUtils.normalize(source.getAbsolutePath());
+ source = FILE_UTILS.normalize(source.getAbsolutePath());
} catch (BuildException e) {
// relative path
}
diff --git a/src/main/org/apache/tools/ant/util/ResourceUtils.java b/src/main/org/apache/tools/ant/util/ResourceUtils.java
index ad721df43..b23e907d6 100644
--- a/src/main/org/apache/tools/ant/util/ResourceUtils.java
+++ b/src/main/org/apache/tools/ant/util/ResourceUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,9 @@ import java.util.Vector;
*/
public class ResourceUtils {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* tells which source files should be reprocessed based on the
* last modification date of target files
@@ -51,8 +54,7 @@ public class ResourceUtils {
FileNameMapper mapper,
ResourceFactory targets) {
return selectOutOfDateSources(logTo, source, mapper, targets,
- FileUtils.newFileUtils()
- .getFileTimestampGranularity());
+ FILE_UTILS.getFileTimestampGranularity());
}
/**
diff --git a/src/main/org/apache/tools/ant/util/SourceFileScanner.java b/src/main/org/apache/tools/ant/util/SourceFileScanner.java
index 59f390e5b..ebf45a12a 100644
--- a/src/main/org/apache/tools/ant/util/SourceFileScanner.java
+++ b/src/main/org/apache/tools/ant/util/SourceFileScanner.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ public class SourceFileScanner implements ResourceFactory {
protected Task task;
- private FileUtils fileUtils;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private File destDir; // base directory of the fileset
/**
@@ -44,7 +44,6 @@ public class SourceFileScanner implements ResourceFactory {
*/
public SourceFileScanner(Task task) {
this.task = task;
- fileUtils = FileUtils.newFileUtils();
}
/**
@@ -61,7 +60,7 @@ public class SourceFileScanner implements ResourceFactory {
public String[] restrict(String[] files, File srcDir, File destDir,
FileNameMapper mapper) {
return restrict(files, srcDir, destDir, mapper,
- fileUtils.getFileTimestampGranularity());
+ FILE_UTILS.getFileTimestampGranularity());
}
/**
@@ -85,7 +84,7 @@ public class SourceFileScanner implements ResourceFactory {
this.destDir = destDir;
Vector v = new Vector();
for (int i = 0; i < files.length; i++) {
- File src = fileUtils.resolveFile(srcDir, files[i]);
+ File src = FILE_UTILS.resolveFile(srcDir, files[i]);
v.addElement(new Resource(files[i], src.exists(),
src.lastModified(), src.isDirectory()));
}
@@ -112,7 +111,7 @@ public class SourceFileScanner implements ResourceFactory {
public File[] restrictAsFiles(String[] files, File srcDir, File destDir,
FileNameMapper mapper) {
return restrictAsFiles(files, srcDir, destDir, mapper,
- fileUtils.getFileTimestampGranularity());
+ FILE_UTILS.getFileTimestampGranularity());
}
/**
@@ -140,7 +139,7 @@ public class SourceFileScanner implements ResourceFactory {
* @since Ant 1.5.2
*/
public Resource getResource(String name) {
- File src = fileUtils.resolveFile(destDir, name);
+ File src = FILE_UTILS.resolveFile(destDir, name);
return new Resource(name, src.exists(), src.lastModified(),
src.isDirectory());
}
diff --git a/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java b/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java
index 722ffb2a0..86f58d1d5 100644
--- a/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java
+++ b/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation
+ * Copyright 2004-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@ import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import junit.framework.TestCase;
-import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils;
@@ -37,6 +36,9 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class AntClassLoaderDelegationTest extends TestCase {
+ /** Instance of a utility class to use for file operations. */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private Project p;
public AntClassLoaderDelegationTest(String name) {
@@ -64,7 +66,7 @@ public class AntClassLoaderDelegationTest extends TestCase {
// An AntClassLoader which is supposed to delegate to the parent and then to the disk path:
ClassLoader acl = new AntClassLoader(parent, p, path, true);
// The intended result URLs:
- URL urlFromPath = new URL(FileUtils.newFileUtils().toURI(buildTestcases) + TEST_RESOURCE);
+ URL urlFromPath = new URL(FILE_UTILS.toURI(buildTestcases) + TEST_RESOURCE);
URL urlFromParent = new URL("http://ant.apache.org/" + TEST_RESOURCE);
assertEquals("correct resources (regular delegation order)",
Arrays.asList(new URL[] {urlFromParent, urlFromPath}),
diff --git a/src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java b/src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java
index 1e365635d..c7cd74392 100644
--- a/src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java
+++ b/src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class ConcatFilterTest extends BuildFileTest {
- private static FileUtils fu = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private static final String lSep =
Os.isFamily("mac") ? "\r" : System.getProperty("line.separator");
@@ -82,7 +82,7 @@ public class ConcatFilterTest extends BuildFileTest {
executeTarget("testFilterReaderNoArgs");
File expected = getProject().resolveFile("input/concatfilter.test");
File result = getProject().resolveFile("result/concat.FilterReaderNoArgs.test");
- assertTrue("testFilterReaderNoArgs: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testFilterReaderNoArgs: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
public void testFilterReaderBefore() {
diff --git a/src/testcases/org/apache/tools/ant/filters/EscapeUnicodeTest.java b/src/testcases/org/apache/tools/ant/filters/EscapeUnicodeTest.java
index 3d22b6528..63535e1ee 100644
--- a/src/testcases/org/apache/tools/ant/filters/EscapeUnicodeTest.java
+++ b/src/testcases/org/apache/tools/ant/filters/EscapeUnicodeTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@ import org.apache.tools.ant.util.FileUtils;
/**
*/
public class EscapeUnicodeTest extends BuildFileTest {
+
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
public EscapeUnicodeTest(String name) {
super(name);
@@ -43,8 +45,7 @@ public class EscapeUnicodeTest extends BuildFileTest {
executeTarget("testEscapeUnicode");
File expected = getProject().resolveFile("expected/escapeunicode.test");
File result = getProject().resolveFile("result/escapeunicode.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue(fu.contentEquals(expected, result));
+ assertTrue(FILE_UTILS.contentEquals(expected, result));
}
}
diff --git a/src/testcases/org/apache/tools/ant/filters/HeadTailTest.java b/src/testcases/org/apache/tools/ant/filters/HeadTailTest.java
index 4980c85e3..c7ffbbf96 100644
--- a/src/testcases/org/apache/tools/ant/filters/HeadTailTest.java
+++ b/src/testcases/org/apache/tools/ant/filters/HeadTailTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,8 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class HeadTailTest extends BuildFileTest {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public HeadTailTest(String name) {
super(name);
}
@@ -46,32 +48,28 @@ public class HeadTailTest extends BuildFileTest {
executeTarget("testHead");
File expected = getProject().resolveFile("expected/head-tail.head.test");
File result = getProject().resolveFile("result/head-tail.head.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("testHead: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testHead: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
public void testHeadLines() throws IOException {
executeTarget("testHeadLines");
File expected = getProject().resolveFile("expected/head-tail.headLines.test");
File result = getProject().resolveFile("result/head-tail.headLines.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("testHeadLines: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testHeadLines: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
public void testHeadSkip() throws IOException {
executeTarget("testHeadSkip");
File expected = getProject().resolveFile("expected/head-tail.headSkip.test");
File result = getProject().resolveFile("result/head-tail.headSkip.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("testHeadSkip: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testHeadSkip: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
public void testHeadLinesSkip() throws IOException {
executeTarget("testHeadLinesSkip");
File expected = getProject().resolveFile("expected/head-tail.headLinesSkip.test");
File result = getProject().resolveFile("result/head-tail.headLinesSkip.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("testHeadLinesSkip: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testHeadLinesSkip: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
public void testFilterReaderHeadLinesSkip() throws IOException {
@@ -80,41 +78,36 @@ public class HeadTailTest extends BuildFileTest {
"expected/head-tail.headLinesSkip.test");
File result = getProject().resolveFile(
"result/head-tail.filterReaderHeadLinesSkip.test");
- FileUtils fu = FileUtils.newFileUtils();
assertTrue("testFilterReaderHeadLinesSkip: Result not like expected",
- fu.contentEquals(expected, result));
+ FILE_UTILS.contentEquals(expected, result));
}
public void testTail() throws IOException {
executeTarget("testTail");
File expected = getProject().resolveFile("expected/head-tail.tail.test");
File result = getProject().resolveFile("result/head-tail.tail.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("testTail: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testTail: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
public void testTailLines() throws IOException {
executeTarget("testTailLines");
File expected = getProject().resolveFile("expected/head-tail.tailLines.test");
File result = getProject().resolveFile("result/head-tail.tailLines.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("testTailLines: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testTailLines: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
public void testTailSkip() throws IOException {
executeTarget("testTailSkip");
File expected = getProject().resolveFile("expected/head-tail.tailSkip.test");
File result = getProject().resolveFile("result/head-tail.tailSkip.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("testTailSkip: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testTailSkip: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
public void testTailLinesSkip() throws IOException {
executeTarget("testTailLinesSkip");
File expected = getProject().resolveFile("expected/head-tail.tailLinesSkip.test");
File result = getProject().resolveFile("result/head-tail.tailLinesSkip.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("testTailLinesSkip: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testTailLinesSkip: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
public void testFilterReaderTailLinesSkip() throws IOException {
@@ -123,17 +116,15 @@ public class HeadTailTest extends BuildFileTest {
"expected/head-tail.tailLinesSkip.test");
File result = getProject().resolveFile(
"result/head-tail.filterReaderTailLinesSkip.test");
- FileUtils fu = FileUtils.newFileUtils();
assertTrue("testFilterReaderTailLinesSkip: Result not like expected",
- fu.contentEquals(expected, result));
+ FILE_UTILS.contentEquals(expected, result));
}
public void testHeadTail() throws IOException {
executeTarget("testHeadTail");
File expected = getProject().resolveFile("expected/head-tail.headtail.test");
File result = getProject().resolveFile("result/head-tail.headtail.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("testHeadTail: Result not like expected", fu.contentEquals(expected, result));
+ assertTrue("testHeadTail: Result not like expected", FILE_UTILS.contentEquals(expected, result));
}
}
diff --git a/src/testcases/org/apache/tools/ant/filters/LineContainsTest.java b/src/testcases/org/apache/tools/ant/filters/LineContainsTest.java
index 7151ecd3b..e9e052f2d 100644
--- a/src/testcases/org/apache/tools/ant/filters/LineContainsTest.java
+++ b/src/testcases/org/apache/tools/ant/filters/LineContainsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,8 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class LineContainsTest extends BuildFileTest {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public LineContainsTest(String name) {
super(name);
}
@@ -43,8 +45,7 @@ public class LineContainsTest extends BuildFileTest {
executeTarget("testLineContains");
File expected = getProject().resolveFile("expected/linecontains.test");
File result = getProject().resolveFile("result/linecontains.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue(fu.contentEquals(expected, result));
+ assertTrue(FILE_UTILS.contentEquals(expected, result));
}
}
diff --git a/src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java b/src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java
index 6ef0f395a..2d00922af 100644
--- a/src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java
+++ b/src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@ import org.apache.tools.ant.util.FileUtils;
/**
*/
public class ReplaceTokensTest extends BuildFileTest {
+
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
public ReplaceTokensTest(String name) {
super(name);
@@ -43,8 +45,7 @@ public class ReplaceTokensTest extends BuildFileTest {
executeTarget("testReplaceTokens");
File expected = getProject().resolveFile("expected/replacetokens.test");
File result = getProject().resolveFile("result/replacetokens.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue(fu.contentEquals(expected, result));
+ assertTrue(FILE_UTILS.contentEquals(expected, result));
}
}
diff --git a/src/testcases/org/apache/tools/ant/filters/StripJavaCommentsTest.java b/src/testcases/org/apache/tools/ant/filters/StripJavaCommentsTest.java
index 90453b21e..a298acdec 100644
--- a/src/testcases/org/apache/tools/ant/filters/StripJavaCommentsTest.java
+++ b/src/testcases/org/apache/tools/ant/filters/StripJavaCommentsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@ import org.apache.tools.ant.util.FileUtils;
/**
*/
public class StripJavaCommentsTest extends BuildFileTest {
+
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
public StripJavaCommentsTest(String name) {
super(name);
@@ -43,8 +45,7 @@ public class StripJavaCommentsTest extends BuildFileTest {
executeTarget("testStripJavaComments");
File expected = getProject().resolveFile("expected/stripjavacomments.test");
File result = getProject().resolveFile("result/stripjavacomments.test");
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue(fu.contentEquals(expected, result));
+ assertTrue(FILE_UTILS.contentEquals(expected, result));
}
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java b/src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java
index f44416993..676599953 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,9 @@ import java.io.IOException;
*/
public class BUnzip2Test extends BuildFileTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public BUnzip2Test(String name) {
super(name);
}
@@ -40,11 +43,10 @@ public class BUnzip2Test extends BuildFileTest {
executeTarget("cleanup");
}
- public void testRealTest() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
+ public void testRealTest() throws IOException {
executeTarget("realTest");
assertTrue("File content mismatch after bunzip2",
- fileUtils.contentEquals(project.resolveFile("expected/asf-logo-huge.tar"),
+ FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar"),
project.resolveFile("asf-logo-huge.tar")));
}
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/BZip2Test.java b/src/testcases/org/apache/tools/ant/taskdefs/BZip2Test.java
index a1e00c341..35c4c5950 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/BZip2Test.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/BZip2Test.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,9 @@ import java.io.IOException;
*/
public class BZip2Test extends BuildFileTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public BZip2Test(String name) {
super(name);
}
@@ -40,11 +43,10 @@ public class BZip2Test extends BuildFileTest {
executeTarget("cleanup");
}
- public void testRealTest() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
+ public void testRealTest() throws IOException {
executeTarget("realTest");
assertTrue("File content mismatch",
- fileUtils.contentEquals(project.resolveFile("expected/asf-logo-huge.tar.bz2"),
+ FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar.bz2"),
project.resolveFile("asf-logo-huge.tar.bz2")));
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java
index 5069aa4d7..2128930f2 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001,2003-2004 The Apache Software Foundation
+ * Copyright 2001,2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.BuildFileTest;
-import org.apache.tools.ant.util.FileUtils;
import java.io.IOException;
import java.io.File;
@@ -41,22 +40,18 @@ public class ChecksumTest extends BuildFileTest {
}
public void testCreateMd5() throws IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("createMd5");
}
public void testCreateMD5SUMformat() throws IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("createMD5SUMformat");
}
public void testCreateSVFformat() throws IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("createSVFformat");
}
public void testCreatePattern() throws IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("createPattern");
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ConcatTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ConcatTest.java
index 940c6d19a..562b4d5aa 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/ConcatTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/ConcatTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,6 +43,9 @@ public class ConcatTest
*/
private static final String tempFile2 = "concat.tmp.2";
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
/**
* Required constructor.
*/
@@ -268,9 +271,8 @@ public class ConcatTest
public void testTranscoding() throws IOException {
executeTarget("testTranscoding");
- FileUtils fileUtils = FileUtils.newFileUtils();
File f1 = getProject().resolveFile("copy/expected/utf-8");
File f2 = getProject().resolveFile("concat.utf8");
- assertTrue(fileUtils.contentEquals(f1, f2));
+ assertTrue(FILE_UTILS.contentEquals(f1, f2));
}
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java b/src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java
index 82be6cfc7..553737b46 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.BuildFileTest;
-import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import java.io.File;
@@ -30,6 +29,9 @@ import java.io.IOException;
*/
public class CopyTest extends BuildFileTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public CopyTest(String name) {
super(name);
}
@@ -100,20 +102,18 @@ public class CopyTest extends BuildFileTest {
public void testFilterSet() throws IOException {
executeTarget("testFilterSet");
- FileUtils fileUtils = FileUtils.newFileUtils();
File tmp = new File(getProjectDir(), "copy.filterset.tmp");
File check = new File(getProjectDir(), "expected/copy.filterset.filtered");
assertTrue(tmp.exists());
- assertTrue(fileUtils.contentEquals(tmp, check));
+ assertTrue(FILE_UTILS.contentEquals(tmp, check));
}
public void testFilterChain() throws IOException {
executeTarget("testFilterChain");
- FileUtils fileUtils = FileUtils.newFileUtils();
File tmp = new File(getProjectDir(), "copy.filterchain.tmp");
File check = new File(getProjectDir(), "expected/copy.filterset.filtered");
assertTrue(tmp.exists());
- assertTrue(fileUtils.contentEquals(tmp, check));
+ assertTrue(FILE_UTILS.contentEquals(tmp, check));
}
public void testSingleFileFileset() {
@@ -125,10 +125,9 @@ public class CopyTest extends BuildFileTest {
public void testTranscoding() throws IOException {
executeTarget("testTranscoding");
- FileUtils fileUtils = FileUtils.newFileUtils();
File f1 = getProject().resolveFile("copy/expected/utf-8");
File f2 = getProject().resolveFile("copytest1.tmp");
- assertTrue(fileUtils.contentEquals(f1, f2));
+ assertTrue(FILE_UTILS.contentEquals(f1, f2));
}
public void testMissingFileIgnore() {
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ExecTaskTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ExecTaskTest.java
index f117c86c7..c351b5b84 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/ExecTaskTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/ExecTaskTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation.
+ * Copyright 2003-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import org.apache.tools.ant.util.FileUtils;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-import java.io.OutputStream;
import java.util.GregorianCalendar;
import junit.framework.ComparisonFailure;
@@ -39,6 +38,10 @@ public class ExecTaskTest extends BuildFileTest {
private static final int MAX_BUILD_TIME = 4000;
private static final int SECURITY_MARGIN = 2000; // wait 2 second extras
// the test failed with 100 ms of margin on cvs.apache.org on August 1st, 2003
+
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private File logFile;
private MonitoredBuild myBuild = null;
volatile private boolean buildFinished = false;
@@ -316,7 +319,7 @@ public class ExecTaskTest extends BuildFileTest {
return;
}
assertTrue("error with transcoding",
- FileUtils.newFileUtils().contentEquals(
+ FILE_UTILS.contentEquals(
getProject().resolveFile("expected/utf-8"),
getProject().resolveFile("redirector.out")));
}
@@ -343,8 +346,7 @@ public class ExecTaskTest extends BuildFileTest {
return;
}
myBuild = new MonitoredBuild(new File(System.getProperty("root"), BUILD_FILE), "spawn");
- FileUtils fileutils = FileUtils.newFileUtils();
- logFile = fileutils.createTempFile("spawn","log", project.getBaseDir());
+ logFile = FILE_UTILS.createTempFile("spawn","log", project.getBaseDir());
// this is guaranteed by FileUtils#createTempFile
assertTrue("log file not existing", !logFile.exists());
// make the spawned process run 4 seconds
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java b/src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java
index a3e05a3af..498856ca1 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2001,2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
*/
package org.apache.tools.ant.taskdefs;
-import java.io.File;
import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.util.FileUtils;
@@ -25,6 +24,9 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class GUnzipTest extends BuildFileTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public GUnzipTest(String name) {
super(name);
}
@@ -46,16 +48,14 @@ public class GUnzipTest extends BuildFileTest {
}
public void testRealTest() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("realTest");
- assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
+ assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
public void testTestGzipTask() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("testGzipTask");
- assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
+ assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/InitializeClassTest.java b/src/testcases/org/apache/tools/ant/taskdefs/InitializeClassTest.java
index 2857ccf70..414c939a6 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/InitializeClassTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/InitializeClassTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002,2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
-import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.util.FileUtils;
@@ -31,7 +30,10 @@ import org.apache.tools.ant.util.FileUtils;
*
*/
public class InitializeClassTest extends BuildFileTest {
-
+
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private File f1 = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/forkedout");
private File f2 = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/unforkedout");
@@ -51,8 +53,7 @@ public class InitializeClassTest extends BuildFileTest {
project.executeTarget("unforked");
System.setOut(ps);
newps.close();
- FileUtils fu = FileUtils.newFileUtils();
- assertTrue("Forked - non-forked mismatch", fu.contentEquals(f1, f2));
+ assertTrue("Forked - non-forked mismatch", FILE_UTILS.contentEquals(f1, f2));
}
public void tearDown() {
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java b/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java
index ef0da75fc..99c19f291 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,18 +24,19 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
-import java.util.Date;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.tools.ant.BuildFileTest;
-import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.util.FileUtils;
/**
*/
public class JarTest extends BuildFileTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private static String tempJar = "tmp.jar";
private static String tempDir = "jartmp/";
private Reader r1, r2;
@@ -125,7 +126,7 @@ public class JarTest extends BuildFileTest {
private void testRecreate(String firstTarget, String secondTarget) {
executeTarget(firstTarget);
long sleeptime = 3000
- + FileUtils.newFileUtils().getFileTimestampGranularity();
+ + FILE_UTILS.getFileTimestampGranularity();
try {
Thread.sleep(sleeptime);
} catch (InterruptedException e) {
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java b/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java
index 3e05919e9..8bbcaff2e 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,13 @@
package org.apache.tools.ant.taskdefs;
-import junit.framework.*;
-import java.io.*;
-import org.apache.tools.ant.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.TeeOutputStream;
@@ -33,6 +37,9 @@ public class JavaTest extends BuildFileTest {
// this time was OK on a Win NT machine and on nagoya
private static final int SECURITY_MARGIN = 2000;
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
private boolean runFatalTests=false;
public JavaTest(String name) {
@@ -167,8 +174,7 @@ public class JavaTest extends BuildFileTest {
}
public void testSpawn() {
- FileUtils fileutils = FileUtils.newFileUtils();
- File logFile = fileutils.createTempFile("spawn","log", project.getBaseDir());
+ File logFile = FILE_UTILS.createTempFile("spawn","log", project.getBaseDir());
// this is guaranteed by FileUtils#createTempFile
assertTrue("log file not existing", !logFile.exists());
project.setProperty("logFile", logFile.getAbsolutePath());
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/MoveTest.java b/src/testcases/org/apache/tools/ant/taskdefs/MoveTest.java
index a21976f4f..1c4c657da 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/MoveTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/MoveTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.BuildFileTest;
-import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileUtils;
import java.io.File;
import java.io.IOException;
@@ -29,6 +28,9 @@ import java.io.IOException;
*/
public class MoveTest extends BuildFileTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public MoveTest(String name) {
super(name);
}
@@ -43,20 +45,18 @@ public class MoveTest extends BuildFileTest {
public void testFilterSet() throws IOException {
executeTarget("testFilterSet");
- FileUtils fileUtils = FileUtils.newFileUtils();
File tmp = new File(getProjectDir(), "move.filterset.tmp");
File check = new File(getProjectDir(), "expected/copy.filterset.filtered");
assertTrue(tmp.exists());
- assertTrue(fileUtils.contentEquals(tmp, check));
+ assertTrue(FILE_UTILS.contentEquals(tmp, check));
}
public void testFilterChain() throws IOException {
executeTarget("testFilterChain");
- FileUtils fileUtils = FileUtils.newFileUtils();
File tmp = new File(getProjectDir(), "move.filterchain.tmp");
File check = new File(getProjectDir(), "expected/copy.filterset.filtered");
assertTrue(tmp.exists());
- assertTrue(fileUtils.contentEquals(tmp, check));
+ assertTrue(FILE_UTILS.contentEquals(tmp, check));
}
/** Bugzilla Report 11732 */
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java b/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
index a328a0732..69d7c13c6 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,6 @@
package org.apache.tools.ant.taskdefs;
-import java.net.URL;
-import java.io.File;
-
import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.FileUtils;
@@ -28,6 +25,9 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class PropertyTest extends BuildFileTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public PropertyTest(String name) {
super(name);
}
@@ -64,7 +64,7 @@ public class PropertyTest extends BuildFileTest {
public void test5() {
String baseDir = getProject().getProperty("basedir");
try {
- String uri = FileUtils.newFileUtils().toURI(
+ String uri = FILE_UTILS.toURI(
baseDir + "/property3.properties");
getProject().setNewProperty(
"test5.url", uri);
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/RecorderTest.java b/src/testcases/org/apache/tools/ant/taskdefs/RecorderTest.java
index c0296ed23..adf05e453 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/RecorderTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/RecorderTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation
+ * Copyright 2004-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,9 @@ public class RecorderTest extends BuildFileTest {
private static final String REC_DIR = "recorder-out";
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public RecorderTest(String name) {
super(name);
}
@@ -43,9 +46,8 @@ public class RecorderTest extends BuildFileTest {
}
public void testNoAppend() throws IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("noappend");
- assertTrue(fileUtils
+ assertTrue(FILE_UTILS
.contentEquals(project.resolveFile(REC_DIR
+ "rectest1.result"),
project.resolveFile(REC_DIR
@@ -53,9 +55,8 @@ public class RecorderTest extends BuildFileTest {
}
public void testAppend() throws IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("append");
- assertTrue(fileUtils
+ assertTrue(FILE_UTILS
.contentEquals(project.resolveFile(REC_DIR
+ "rectest2.result"),
project.resolveFile(REC_DIR
@@ -63,9 +64,8 @@ public class RecorderTest extends BuildFileTest {
}
public void testRestart() throws IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("restart");
- assertTrue(fileUtils
+ assertTrue(FILE_UTILS
.contentEquals(project.resolveFile(REC_DIR
+ "rectest3.result"),
project.resolveFile(REC_DIR
@@ -73,9 +73,8 @@ public class RecorderTest extends BuildFileTest {
}
public void testDeleteRestart() throws IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("deleterestart");
- assertTrue(fileUtils
+ assertTrue(FILE_UTILS
.contentEquals(project.resolveFile(REC_DIR
+ "rectest4.result"),
project.resolveFile(REC_DIR
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java b/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java
index 034071d70..9b0908de9 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,9 @@ public class TouchTest extends BuildFileTest {
private static String TOUCH_FILE = "src/etc/testcases/taskdefs/touchtest";
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public TouchTest(String name) {
super(name);
}
@@ -155,7 +158,7 @@ public class TouchTest extends BuildFileTest {
* @param time
*/
public void assertTimesNearlyMatch(long timestamp,long time) {
- long granularity= FileUtils.newFileUtils().getFileTimestampGranularity();
+ long granularity= FILE_UTILS.getFileTimestampGranularity();
assertTimesNearlyMatch(timestamp, time, granularity);
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java b/src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java
index f3203585b..68fc4bb9d 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,9 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class UntarTest extends BuildFileTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public UntarTest(String name) {
super(name);
}
@@ -37,44 +40,38 @@ public class UntarTest extends BuildFileTest {
}
public void testRealTest() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("realTest");
- assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
+ assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
public void testRealGzipTest() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("realGzipTest");
- assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
+ assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
public void testRealBzip2Test() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("realBzip2Test");
- assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
+ assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
public void testTestTarTask() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("testTarTask");
- assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
+ assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
public void testTestGzipTarTask() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("testGzipTarTask");
- assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
+ assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
public void testTestBzip2TarTask() throws java.io.IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
executeTarget("testBzip2TarTask");
- assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
+ assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java b/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java
index 9b7010f42..e09c2f768 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2001,2003-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,9 @@ import java.io.IOException;
*/
public class UnzipTest extends BuildFileTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public UnzipTest(String name) {
super(name);
}
@@ -60,8 +63,7 @@ public class UnzipTest extends BuildFileTest {
* @throws IOException
*/
private void assertLogoUncorrupted() throws IOException {
- FileUtils fileUtils = FileUtils.newFileUtils();
- assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
+ assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
project.resolveFile("asf-logo.gif")));
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java b/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
index 631d9465a..ba431ecf4 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ import org.apache.tools.ant.util.FileUtils;
/**
*/
public class XmlPropertyTest extends BuildFileTest {
- private static FileUtils fileUtils = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
public XmlPropertyTest(String name) {
super(name);
@@ -125,7 +125,7 @@ public class XmlPropertyTest extends BuildFileTest {
if ( localRoot ) {
workingDir = inputFile.getParentFile();
} else {
- workingDir = fileUtils.resolveFile(new File("."), ".");
+ workingDir = FILE_UTILS.resolveFile(new File("."), ".");
}
try {
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java
index a9914b2b5..2bd4daeab 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001,2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,8 @@ import org.w3c.dom.Document;
*/
public abstract class AbstractXSLTLiaisonTest extends TestCase {
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
protected XSLTLiaison liaison;
protected AbstractXSLTLiaisonTest(String name){
@@ -54,7 +56,7 @@ public abstract class AbstractXSLTLiaisonTest extends TestCase {
if (url == null){
throw new FileNotFoundException("Unable to load '" + name + "' from classpath");
}
- return new File(FileUtils.newFileUtils().fromURI(url.toExternalForm()));
+ return new File(FILE_UTILS.fromURI(url.toExternalForm()));
}
/** keep it simple stupid */
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
index 171623718..fd34c9961 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,8 @@ import java.io.IOException;
*/
public class ReplaceRegExpTest extends BuildFileTest {
private static final String PROJECT_PATH = "src/etc/testcases/taskdefs/optional";
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public ReplaceRegExpTest(String name) {
super(name);
}
@@ -87,7 +89,7 @@ public class ReplaceRegExpTest extends BuildFileTest {
public void testDontAddNewline1() throws IOException {
executeTarget("testDontAddNewline1");
assertTrue("Files match",
- FileUtils.newFileUtils()
+ FILE_UTILS
.contentEquals(new File(System.getProperty("root"), PROJECT_PATH + "/test.properties"),
new File(System.getProperty("root"), PROJECT_PATH + "/replaceregexp2.result.properties")));
}
@@ -95,7 +97,7 @@ public class ReplaceRegExpTest extends BuildFileTest {
public void testDontAddNewline2() throws IOException {
executeTarget("testDontAddNewline2");
assertTrue("Files match",
- FileUtils.newFileUtils()
+ FILE_UTILS
.contentEquals(new File(System.getProperty("root"), PROJECT_PATH + "/test.properties"),
new File(System.getProperty("root"), PROJECT_PATH + "/replaceregexp2.result.properties")));
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java
index 7036ca9b0..1e8e98c69 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,16 +19,9 @@ package org.apache.tools.ant.taskdefs.optional.image;
import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.util.FileUtils;
-import org.apache.tools.ant.taskdefs.condition.Os;
-import java.io.IOException;
import java.io.File;
-import java.io.InputStream;
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.BufferedReader;
-import java.util.Properties;
+
/**
* Tests the Image task.
@@ -41,6 +34,8 @@ public class ImageTest extends BuildFileTest {
"src/etc/testcases/taskdefs/optional/image/";
private final static String LARGEIMAGE = "largeimage.jpg";
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public ImageTest(String name) {
super(name);
}
@@ -73,7 +68,7 @@ public class ImageTest extends BuildFileTest {
File f = createRelativeFile("/dest/" + LARGEIMAGE);
long lastModified = f.lastModified();
try {
- Thread.sleep(FileUtils.newFileUtils()
+ Thread.sleep(FILE_UTILS
.getFileTimestampGranularity());
}
catch (InterruptedException e) {}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReportTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReportTest.java
index 519d80b0a..4691057d2 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReportTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReportTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001,2003-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ import org.w3c.dom.NodeList;
*/
public class XMLReportTest extends TestCase {
/** helper for some File/URL connversions */
- private static FileUtils fileUtils = FileUtils.newFileUtils();
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
public XMLReportTest(String s) {
super(s);
@@ -49,7 +49,7 @@ public class XMLReportTest extends TestCase {
if (url == null) {
throw new FileNotFoundException("Unable to load '" + name + "' from classpath");
}
- return new File(fileUtils.fromURI(url.toString()));
+ return new File(FILE_UTILS.fromURI(url.toString()));
}
public void testCreateDocument() throws Exception {
diff --git a/src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java b/src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
index afb09cfdd..cec781c63 100644
--- a/src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
+++ b/src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ package org.apache.tools.ant.types.selectors;
// Java
import java.io.File;
-import java.io.FileWriter;
import java.util.Comparator;
import java.util.Iterator;
import java.text.RuleBasedCollator;
@@ -38,6 +37,7 @@ import org.apache.tools.ant.BuildEvent;
// The classes to test
import org.apache.tools.ant.types.selectors.modifiedselector.*;
+import org.apache.tools.ant.util.FileUtils;
/**
@@ -48,6 +48,8 @@ import org.apache.tools.ant.types.selectors.modifiedselector.*;
*/
public class ModifiedSelectorTest extends BaseSelectorTest {
+ /** Utilities used for file operations */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
// ===================== attributes =====================
@@ -388,8 +390,7 @@ public class ModifiedSelectorTest extends BaseSelectorTest {
* configure() method of ModifiedSelector. This testcase tests that.
*/
public void testCreatePropertiesCacheViaCustomSelector() {
- File cachefile = org.apache.tools.ant.util.FileUtils.newFileUtils()
- .createTempFile("tmp-cache-", ".properties", null);
+ File cachefile = FILE_UTILS.createTempFile("tmp-cache-", ".properties", null);
try {
// initialize test environment (called "bed")
makeBed();
diff --git a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
index ad55d416d..6f71455d0 100644
--- a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
+++ b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation
+ * Copyright 2001-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,9 @@
package org.apache.tools.ant.util;
-import java.io.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import junit.framework.TestCase;
@@ -30,7 +32,7 @@ import org.apache.tools.ant.taskdefs.condition.Os;
*/
public class FileUtilsTest extends TestCase {
- private FileUtils fu;
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private File removeThis;
private String root;
@@ -39,7 +41,6 @@ public class FileUtilsTest extends TestCase {
}
public void setUp() {
- fu = FileUtils.newFileUtils();
// Windows adds the drive letter in uppercase, unless you run Cygwin
root = new File(File.separator).getAbsolutePath().toUpperCase();
}
@@ -79,7 +80,7 @@ public class FileUtilsTest extends TestCase {
fail(ie.getMessage());
}
- fu.setFileLastModified(removeThis, -1);
+ FILE_UTILS.setFileLastModified(removeThis, -1);
long secondModTime = removeThis.lastModified();
assertTrue(secondModTime > modTime);
@@ -88,7 +89,7 @@ public class FileUtilsTest extends TestCase {
// in a previous version, the date of the file was set to 123456
// milliseconds since 01.01.1970
// it did not work on a computer running JDK 1.4.1_02 + Windows 2000
- fu.setFileLastModified(removeThis, secondModTime + millisperday);
+ FILE_UTILS.setFileLastModified(removeThis, secondModTime + millisperday);
long thirdModTime = removeThis.lastModified();
/*
* I would love to compare this with 123456, but depending on
@@ -104,30 +105,30 @@ public class FileUtilsTest extends TestCase {
* Start with simple absolute file names.
*/
assertEquals(File.separator,
- fu.resolveFile(null, "/").getPath());
+ FILE_UTILS.resolveFile(null, "/").getPath());
assertEquals(File.separator,
- fu.resolveFile(null, "\\").getPath());
+ FILE_UTILS.resolveFile(null, "\\").getPath());
/*
* throw in drive letters
*/
String driveSpec = "C:";
assertEquals(driveSpec + "\\",
- fu.resolveFile(null, driveSpec + "/").getPath());
+ FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
assertEquals(driveSpec + "\\",
- fu.resolveFile(null, driveSpec + "\\").getPath());
+ FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
String driveSpecLower = "c:";
assertEquals(driveSpec + "\\",
- fu.resolveFile(null, driveSpecLower + "/").getPath());
+ FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(driveSpec + "\\",
- fu.resolveFile(null, driveSpecLower + "\\").getPath());
+ FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
/*
* promised to eliminate consecutive slashes after drive letter.
*/
assertEquals(driveSpec + "\\",
- fu.resolveFile(null, driveSpec + "/////").getPath());
+ FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath());
assertEquals(driveSpec + "\\",
- fu.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
+ FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
if (Os.isFamily("netware")) {
/*
@@ -135,45 +136,45 @@ public class FileUtilsTest extends TestCase {
*/
driveSpec = "SYS:";
assertEquals(driveSpec,
- fu.resolveFile(null, driveSpec + "/").getPath());
+ FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
assertEquals(driveSpec,
- fu.resolveFile(null, driveSpec + "\\").getPath());
+ FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
driveSpecLower = "sys:";
assertEquals(driveSpec,
- fu.resolveFile(null, driveSpecLower + "/").getPath());
+ FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(driveSpec,
- fu.resolveFile(null, driveSpecLower + "\\").getPath());
+ FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
/*
* promised to eliminate consecutive slashes after drive letter.
*/
assertEquals(driveSpec,
- fu.resolveFile(null, driveSpec + "/////").getPath());
+ FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath());
assertEquals(driveSpec,
- fu.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
+ FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
}
/*
* Now test some relative file name magic.
*/
assertEquals(localize("/1/2/3/4"),
- fu.resolveFile(new File(localize("/1/2/3")), "4").getPath());
+ FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "4").getPath());
assertEquals(localize("/1/2/3/4"),
- fu.resolveFile(new File(localize("/1/2/3")), "./4").getPath());
+ FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "./4").getPath());
assertEquals(localize("/1/2/3/4"),
- fu.resolveFile(new File(localize("/1/2/3")), ".\\4").getPath());
+ FILE_UTILS.resolveFile(new File(localize("/1/2/3")), ".\\4").getPath());
assertEquals(localize("/1/2/3/4"),
- fu.resolveFile(new File(localize("/1/2/3")), "./.\\4").getPath());
+ FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "./.\\4").getPath());
assertEquals(localize("/1/2/3/4"),
- fu.resolveFile(new File(localize("/1/2/3")), "../3/4").getPath());
+ FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "../3/4").getPath());
assertEquals(localize("/1/2/3/4"),
- fu.resolveFile(new File(localize("/1/2/3")), "..\\3\\4").getPath());
+ FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "..\\3\\4").getPath());
assertEquals(localize("/1/2/3/4"),
- fu.resolveFile(new File(localize("/1/2/3")), "../../5/.././2/./3/6/../4").getPath());
+ FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "../../5/.././2/./3/6/../4").getPath());
assertEquals(localize("/1/2/3/4"),
- fu.resolveFile(new File(localize("/1/2/3")), "..\\../5/..\\./2/./3/6\\../4").getPath());
+ FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "..\\../5/..\\./2/./3/6\\../4").getPath());
try {
- fu.resolveFile(new File(localize("/1")), "../../b");
+ FILE_UTILS.resolveFile(new File(localize("/1")), "../../b");
fail("successfully crawled beyond the filesystem root");
} catch (BuildException e) {
// Expected Exception caught
@@ -186,32 +187,32 @@ public class FileUtilsTest extends TestCase {
* Start with simple absolute file names.
*/
assertEquals(File.separator,
- fu.normalize("/").getPath());
+ FILE_UTILS.normalize("/").getPath());
assertEquals(File.separator,
- fu.normalize("\\").getPath());
+ FILE_UTILS.normalize("\\").getPath());
/*
* throw in drive letters
*/
String driveSpec = "C:";
assertEquals(driveSpec,
- fu.normalize(driveSpec).getPath());
+ FILE_UTILS.normalize(driveSpec).getPath());
assertEquals(driveSpec + "\\",
- fu.normalize(driveSpec + "/").getPath());
+ FILE_UTILS.normalize(driveSpec + "/").getPath());
assertEquals(driveSpec + "\\",
- fu.normalize(driveSpec + "\\").getPath());
+ FILE_UTILS.normalize(driveSpec + "\\").getPath());
String driveSpecLower = "c:";
assertEquals(driveSpec + "\\",
- fu.normalize(driveSpecLower + "/").getPath());
+ FILE_UTILS.normalize(driveSpecLower + "/").getPath());
assertEquals(driveSpec + "\\",
- fu.normalize(driveSpecLower + "\\").getPath());
+ FILE_UTILS.normalize(driveSpecLower + "\\").getPath());
/*
* promised to eliminate consecutive slashes after drive letter.
*/
assertEquals(driveSpec + "\\",
- fu.normalize(driveSpec + "/////").getPath());
+ FILE_UTILS.normalize(driveSpec + "/////").getPath());
assertEquals(driveSpec + "\\",
- fu.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
+ FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
if (Os.isFamily("netware")) {
/*
@@ -219,58 +220,58 @@ public class FileUtilsTest extends TestCase {
*/
driveSpec = "SYS:";
assertEquals(driveSpec,
- fu.normalize(driveSpec).getPath());
+ FILE_UTILS.normalize(driveSpec).getPath());
assertEquals(driveSpec,
- fu.normalize(driveSpec + "/").getPath());
+ FILE_UTILS.normalize(driveSpec + "/").getPath());
assertEquals(driveSpec,
- fu.normalize(driveSpec + "\\").getPath());
+ FILE_UTILS.normalize(driveSpec + "\\").getPath());
driveSpecLower = "sys:";
assertEquals(driveSpec,
- fu.normalize(driveSpecLower).getPath());
+ FILE_UTILS.normalize(driveSpecLower).getPath());
assertEquals(driveSpec,
- fu.normalize(driveSpecLower + "/").getPath());
+ FILE_UTILS.normalize(driveSpecLower + "/").getPath());
assertEquals(driveSpec,
- fu.normalize(driveSpecLower + "\\").getPath());
+ FILE_UTILS.normalize(driveSpecLower + "\\").getPath());
assertEquals(driveSpec + "\\junk",
- fu.normalize(driveSpecLower + "\\junk").getPath());
+ FILE_UTILS.normalize(driveSpecLower + "\\junk").getPath());
/*
* promised to eliminate consecutive slashes after drive letter.
*/
assertEquals(driveSpec,
- fu.normalize(driveSpec + "/////").getPath());
+ FILE_UTILS.normalize(driveSpec + "/////").getPath());
assertEquals(driveSpec,
- fu.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
+ FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
}
/*
* Now test some relative file name magic.
*/
assertEquals(localize("/1/2/3/4"),
- fu.normalize(localize("/1/2/3/4")).getPath());
+ FILE_UTILS.normalize(localize("/1/2/3/4")).getPath());
assertEquals(localize("/1/2/3/4"),
- fu.normalize(localize("/1/2/3/./4")).getPath());
+ FILE_UTILS.normalize(localize("/1/2/3/./4")).getPath());
assertEquals(localize("/1/2/3/4"),
- fu.normalize(localize("/1/2/3/.\\4")).getPath());
+ FILE_UTILS.normalize(localize("/1/2/3/.\\4")).getPath());
assertEquals(localize("/1/2/3/4"),
- fu.normalize(localize("/1/2/3/./.\\4")).getPath());
+ FILE_UTILS.normalize(localize("/1/2/3/./.\\4")).getPath());
assertEquals(localize("/1/2/3/4"),
- fu.normalize(localize("/1/2/3/../3/4")).getPath());
+ FILE_UTILS.normalize(localize("/1/2/3/../3/4")).getPath());
assertEquals(localize("/1/2/3/4"),
- fu.normalize(localize("/1/2/3/..\\3\\4")).getPath());
+ FILE_UTILS.normalize(localize("/1/2/3/..\\3\\4")).getPath());
assertEquals(localize("/1/2/3/4"),
- fu.normalize(localize("/1/2/3/../../5/.././2/./3/6/../4")).getPath());
+ FILE_UTILS.normalize(localize("/1/2/3/../../5/.././2/./3/6/../4")).getPath());
assertEquals(localize("/1/2/3/4"),
- fu.normalize(localize("/1/2/3/..\\../5/..\\./2/./3/6\\../4")).getPath());
+ FILE_UTILS.normalize(localize("/1/2/3/..\\../5/..\\./2/./3/6\\../4")).getPath());
try {
- fu.normalize("foo");
+ FILE_UTILS.normalize("foo");
fail("foo is not an absolute path");
} catch (BuildException e) {
// Expected exception caught
}
try {
- fu.normalize(localize("/1/../../b"));
+ FILE_UTILS.normalize(localize("/1/../../b"));
fail("successfully crawled beyond the filesystem root");
} catch (BuildException e) {
// Expected exception caught
@@ -282,13 +283,13 @@ public class FileUtilsTest extends TestCase {
*/
public void testNullArgs() {
try {
- fu.normalize(null);
+ FILE_UTILS.normalize(null);
fail("successfully normalized a null-file");
} catch (NullPointerException npe) {
// Expected exception caught
}
- File f = fu.resolveFile(null, "a");
+ File f = FILE_UTILS.resolveFile(null, "a");
assertEquals(f, new File("a"));
}
@@ -297,7 +298,7 @@ public class FileUtilsTest extends TestCase {
*/
public void testCreateTempFile() {
File parent = new File((new File("/tmp")).getAbsolutePath());
- File tmp1 = fu.createTempFile("pre", ".suf", parent);
+ File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", parent);
assertTrue("new file", !tmp1.exists());
String name = tmp1.getName();
@@ -307,12 +308,12 @@ public class FileUtilsTest extends TestCase {
parent.getAbsolutePath(),
tmp1.getParent());
- File tmp2 = fu.createTempFile("pre", ".suf", parent);
+ File tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent);
assertTrue("files are different",
!tmp1.getAbsolutePath().equals(tmp2.getAbsolutePath()));
// null parent dir
- File tmp3 = fu.createTempFile("pre", ".suf", null);
+ File tmp3 = FILE_UTILS.createTempFile("pre", ".suf", null);
String tmploc = System.getProperty("java.io.tmpdir");
assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(),
tmp3.getAbsolutePath());
@@ -322,17 +323,17 @@ public class FileUtilsTest extends TestCase {
* Test contentEquals
*/
public void testContentEquals() throws IOException {
- assertTrue("Non existing files", fu.contentEquals(new File(System.getProperty("root"), "foo"),
+ assertTrue("Non existing files", FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"),
new File(System.getProperty("root"), "bar")));
assertTrue("One exists, the other one doesn\'t",
- !fu.contentEquals(new File(System.getProperty("root"), "foo"), new File(System.getProperty("root"), "build.xml")));
+ !FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"), new File(System.getProperty("root"), "build.xml")));
assertTrue("Don\'t compare directories",
- !fu.contentEquals(new File(System.getProperty("root"), "src"), new File(System.getProperty("root"), "src")));
+ !FILE_UTILS.contentEquals(new File(System.getProperty("root"), "src"), new File(System.getProperty("root"), "src")));
assertTrue("File equals itself",
- fu.contentEquals(new File(System.getProperty("root"), "build.xml"),
+ FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"),
new File(System.getProperty("root"), "build.xml")));
assertTrue("Files are different",
- !fu.contentEquals(new File(System.getProperty("root"), "build.xml"),
+ !FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"),
new File(System.getProperty("root"), "docs.xml")));
}
@@ -342,7 +343,7 @@ public class FileUtilsTest extends TestCase {
public void testCreateNewFile() throws IOException {
removeThis = new File("dummy");
assertTrue(!removeThis.exists());
- fu.createNewFile(removeThis);
+ FILE_UTILS.createNewFile(removeThis);
assertTrue(removeThis.exists());
}
@@ -350,43 +351,43 @@ public class FileUtilsTest extends TestCase {
* Test removeLeadingPath.
*/
public void testRemoveLeadingPath() {
- assertEquals("bar", fu.removeLeadingPath(new File("/foo"),
+ assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("/foo"),
new File("/foo/bar")));
- assertEquals("bar", fu.removeLeadingPath(new File("/foo/"),
+ assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("/foo/"),
new File("/foo/bar")));
- assertEquals("bar", fu.removeLeadingPath(new File("\\foo"),
+ assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("\\foo"),
new File("\\foo\\bar")));
- assertEquals("bar", fu.removeLeadingPath(new File("\\foo\\"),
+ assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("\\foo\\"),
new File("\\foo\\bar")));
- assertEquals("bar", fu.removeLeadingPath(new File("c:/foo"),
+ assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:/foo"),
new File("c:/foo/bar")));
- assertEquals("bar", fu.removeLeadingPath(new File("c:/foo/"),
+ assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:/foo/"),
new File("c:/foo/bar")));
- assertEquals("bar", fu.removeLeadingPath(new File("c:\\foo"),
+ assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo"),
new File("c:\\foo\\bar")));
- assertEquals("bar", fu.removeLeadingPath(new File("c:\\foo\\"),
+ assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo\\"),
new File("c:\\foo\\bar")));
- assertEqualsIgnoreDriveCase(fu.normalize("/bar").getAbsolutePath(),
- fu.removeLeadingPath(new File("/foo"), new File("/bar")));
- assertEqualsIgnoreDriveCase(fu.normalize("/foobar").getAbsolutePath(),
- fu.removeLeadingPath(new File("/foo"), new File("/foobar")));
+ assertEqualsIgnoreDriveCase(FILE_UTILS.normalize("/bar").getAbsolutePath(),
+ FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/bar")));
+ assertEqualsIgnoreDriveCase(FILE_UTILS.normalize("/foobar").getAbsolutePath(),
+ FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/foobar")));
// bugzilla report 19979
- assertEquals("", fu.removeLeadingPath(new File("/foo/bar"),
+ assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"),
new File("/foo/bar")));
- assertEquals("", fu.removeLeadingPath(new File("/foo/bar"),
+ assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"),
new File("/foo/bar/")));
- assertEquals("", fu.removeLeadingPath(new File("/foo/bar/"),
+ assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar/"),
new File("/foo/bar/")));
- assertEquals("", fu.removeLeadingPath(new File("/foo/bar/"),
+ assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar/"),
new File("/foo/bar")));
String expected = "foo/bar".replace('\\', File.separatorChar)
.replace('/', File.separatorChar);
- assertEquals(expected, fu.removeLeadingPath(new File("/"),
+ assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("/"),
new File("/foo/bar")));
- assertEquals(expected, fu.removeLeadingPath(new File("c:/"),
+ assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("c:/"),
new File("c:/foo/bar")));
- assertEquals(expected, fu.removeLeadingPath(new File("c:\\"),
+ assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("c:\\"),
new File("c:\\foo\\bar")));
}
@@ -403,24 +404,24 @@ public class FileUtilsTest extends TestCase {
dosRoot = "";
}
if (Os.isFamily("dos")) {
- assertEquals("file:///C:/foo", fu.toURI("c:\\foo"));
+ assertEquals("file:///C:/foo", FILE_UTILS.toURI("c:\\foo"));
}
if (Os.isFamily("netware")) {
- assertEquals("file:///SYS:/foo", fu.toURI("sys:\\foo"));
+ assertEquals("file:///SYS:/foo", FILE_UTILS.toURI("sys:\\foo"));
}
- assertEquals("file:///" + dosRoot + "foo", fu.toURI("/foo"));
+ assertEquals("file:///" + dosRoot + "foo", FILE_UTILS.toURI("/foo"));
/* May fail if the directory ${user.dir}/foo/ exists
* (and anyway is the tested behavior actually desirable?):
assertEquals("file:./foo", fu.toURI("./foo"));
*/
- assertEquals("file:///" + dosRoot + "foo", fu.toURI("\\foo"));
+ assertEquals("file:///" + dosRoot + "foo", FILE_UTILS.toURI("\\foo"));
/* See above:
assertEquals("file:./foo", fu.toURI(".\\foo"));
*/
- assertEquals("file:///" + dosRoot + "foo%20bar", fu.toURI("/foo bar"));
- assertEquals("file:///" + dosRoot + "foo%20bar", fu.toURI("\\foo bar"));
- assertEquals("file:///" + dosRoot + "foo%23bar", fu.toURI("/foo#bar"));
- assertEquals("file:///" + dosRoot + "foo%23bar", fu.toURI("\\foo#bar"));
+ assertEquals("file:///" + dosRoot + "foo%20bar", FILE_UTILS.toURI("/foo bar"));
+ assertEquals("file:///" + dosRoot + "foo%20bar", FILE_UTILS.toURI("\\foo bar"));
+ assertEquals("file:///" + dosRoot + "foo%23bar", FILE_UTILS.toURI("/foo#bar"));
+ assertEquals("file:///" + dosRoot + "foo%23bar", FILE_UTILS.toURI("\\foo#bar"));
}
/**
@@ -428,16 +429,16 @@ public class FileUtilsTest extends TestCase {
*/
public void testFromURI() {
if (Os.isFamily("netware")) {
- assertEqualsIgnoreDriveCase("SYS:\\foo", fu.fromURI("file:///sys:/foo"));
+ assertEqualsIgnoreDriveCase("SYS:\\foo", FILE_UTILS.fromURI("file:///sys:/foo"));
}
if (Os.isFamily("dos")) {
- assertEqualsIgnoreDriveCase("C:\\foo", fu.fromURI("file:///c:/foo"));
+ assertEqualsIgnoreDriveCase("C:\\foo", FILE_UTILS.fromURI("file:///c:/foo"));
}
- assertEqualsIgnoreDriveCase(localize("/foo"), fu.fromURI("file:///foo"));
+ assertEqualsIgnoreDriveCase(localize("/foo"), FILE_UTILS.fromURI("file:///foo"));
assertEquals("." + File.separator + "foo",
- fu.fromURI("file:./foo"));
- assertEqualsIgnoreDriveCase(localize("/foo bar"), fu.fromURI("file:///foo%20bar"));
- assertEqualsIgnoreDriveCase(localize("/foo#bar"), fu.fromURI("file:///foo%23bar"));
+ FILE_UTILS.fromURI("file:./foo"));
+ assertEqualsIgnoreDriveCase(localize("/foo bar"), FILE_UTILS.fromURI("file:///foo%20bar"));
+ assertEqualsIgnoreDriveCase(localize("/foo#bar"), FILE_UTILS.fromURI("file:///foo%23bar"));
}
public void testModificationTests() {
@@ -453,13 +454,13 @@ public class FileUtilsTest extends TestCase {
//check that older is up to date with a newer dest
assertTrue("older source files are up to date",
- fu.isUpToDate(firstTime,secondTime));
+ FILE_UTILS.isUpToDate(firstTime,secondTime));
//check that older is up to date with a newer dest
assertFalse("newer source files are no up to date",
- fu.isUpToDate(secondTime, firstTime));
+ FILE_UTILS.isUpToDate(secondTime, firstTime));
assertTrue("-1 dest timestamp implies nonexistence",
- !fu.isUpToDate(firstTime,-1L));
+ !FILE_UTILS.isUpToDate(firstTime,-1L));
}
/**
diff --git a/src/testcases/org/apache/tools/ant/util/JavaEnvUtilsTest.java b/src/testcases/org/apache/tools/ant/util/JavaEnvUtilsTest.java
index 3f69ea7fd..f80a9b0b4 100644
--- a/src/testcases/org/apache/tools/ant/util/JavaEnvUtilsTest.java
+++ b/src/testcases/org/apache/tools/ant/util/JavaEnvUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002,2004 The Apache Software Foundation
+ * Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,9 @@ import org.apache.tools.ant.taskdefs.condition.Os;
*
*/
public class JavaEnvUtilsTest extends TestCase {
+
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
public JavaEnvUtilsTest(String s) {
super(s);
}
@@ -43,9 +46,8 @@ public class JavaEnvUtilsTest extends TestCase {
public void testGetExecutableWindows() {
if (Os.isFamily("windows")) {
- FileUtils fileUtils = FileUtils.newFileUtils();
String javaHome =
- fileUtils.normalize(System.getProperty("java.home"))
+ FILE_UTILS.normalize(System.getProperty("java.home"))
.getAbsolutePath();
String j = JavaEnvUtils.getJreExecutable("java");
@@ -64,7 +66,7 @@ public class JavaEnvUtilsTest extends TestCase {
try {
assertTrue(j+" is absolute", (new File(j)).isAbsolute());
String javaHomeParent =
- fileUtils.normalize(javaHome+"/..").getAbsolutePath();
+ FILE_UTILS.normalize(javaHome+"/..").getAbsolutePath();
assertTrue(j+" is normalized and in the JDK dir",
j.startsWith(javaHomeParent));
@@ -89,9 +91,8 @@ public class JavaEnvUtilsTest extends TestCase {
public void testGetExecutableMostPlatforms() {
if (!Os.isName("netware") && !Os.isFamily("windows")) {
- FileUtils fileUtils = FileUtils.newFileUtils();
String javaHome =
- fileUtils.normalize(System.getProperty("java.home"))
+ FILE_UTILS.normalize(System.getProperty("java.home"))
.getAbsolutePath();
// could still be OS/2
@@ -112,7 +113,7 @@ public class JavaEnvUtilsTest extends TestCase {
assertTrue(j+" is absolute", (new File(j)).isAbsolute());
String javaHomeParent =
- fileUtils.normalize(javaHome+"/..").getAbsolutePath();
+ FILE_UTILS.normalize(javaHome+"/..").getAbsolutePath();
assertTrue(j+" is normalized and in the JDK dir",
j.startsWith(javaHomeParent));