Browse Source

Make use of FileUtils in a uniform way via the getFileUtils method and a static final reference in the using files.

Also removed unused/* imports along the way.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277295 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 20 years ago
parent
commit
257dadeaf0
93 changed files with 579 additions and 531 deletions
  1. +2
    -2
      src/main/org/apache/tools/ant/AntClassLoader.java
  2. +4
    -4
      src/main/org/apache/tools/ant/DirectoryScanner.java
  3. +4
    -2
      src/main/org/apache/tools/ant/Location.java
  4. +21
    -22
      src/main/org/apache/tools/ant/Project.java
  5. +8
    -8
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  6. +10
    -9
      src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
  7. +3
    -4
      src/main/org/apache/tools/ant/loader/AntClassLoader2.java
  8. +5
    -3
      src/main/org/apache/tools/ant/taskdefs/Ant.java
  9. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/Available.java
  10. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/BuildNumber.java
  11. +2
    -4
      src/main/org/apache/tools/ant/taskdefs/Concat.java
  12. +3
    -2
      src/main/org/apache/tools/ant/taskdefs/DependSet.java
  13. +4
    -3
      src/main/org/apache/tools/ant/taskdefs/Ear.java
  14. +5
    -4
      src/main/org/apache/tools/ant/taskdefs/ExecTask.java
  15. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/Execute.java
  16. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/Expand.java
  17. +6
    -6
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  18. +5
    -3
      src/main/org/apache/tools/ant/taskdefs/Get.java
  19. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/ImportTask.java
  20. +5
    -4
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  21. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/Length.java
  22. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/Rename.java
  23. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/Replace.java
  24. +5
    -5
      src/main/org/apache/tools/ant/taskdefs/Rmic.java
  25. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/SignJar.java
  26. +4
    -3
      src/main/org/apache/tools/ant/taskdefs/TempFile.java
  27. +4
    -5
      src/main/org/apache/tools/ant/taskdefs/Touch.java
  28. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/War.java
  29. +6
    -6
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  30. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/XmlProperty.java
  31. +7
    -7
      src/main/org/apache/tools/ant/taskdefs/Zip.java
  32. +4
    -3
      src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  33. +7
    -6
      src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java
  34. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/condition/IsFileSelected.java
  35. +8
    -7
      src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
  36. +3
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java
  37. +5
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
  38. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
  39. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
  40. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ildasm.java
  41. +3
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/ImportTypelib.java
  42. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java
  43. +7
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/WsdlToDotnet.java
  44. +6
    -6
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
  45. +4
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
  46. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
  47. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  48. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java
  49. +6
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  50. +9
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovBase.java
  51. +9
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
  52. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/repository/Library.java
  53. +7
    -7
      src/main/org/apache/tools/ant/types/XMLCatalog.java
  54. +4
    -2
      src/main/org/apache/tools/ant/types/selectors/DateSelector.java
  55. +3
    -3
      src/main/org/apache/tools/ant/types/selectors/DifferentSelector.java
  56. +5
    -1
      src/main/org/apache/tools/ant/types/selectors/MappingSelector.java
  57. +9
    -6
      src/main/org/apache/tools/ant/util/FileUtils.java
  58. +3
    -3
      src/main/org/apache/tools/ant/util/JAXPUtils.java
  59. +4
    -5
      src/main/org/apache/tools/ant/util/JavaEnvUtils.java
  60. +6
    -3
      src/main/org/apache/tools/ant/util/LoaderUtils.java
  61. +5
    -3
      src/main/org/apache/tools/ant/util/ResourceUtils.java
  62. +6
    -7
      src/main/org/apache/tools/ant/util/SourceFileScanner.java
  63. +5
    -3
      src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java
  64. +3
    -3
      src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java
  65. +4
    -3
      src/testcases/org/apache/tools/ant/filters/EscapeUnicodeTest.java
  66. +14
    -23
      src/testcases/org/apache/tools/ant/filters/HeadTailTest.java
  67. +4
    -3
      src/testcases/org/apache/tools/ant/filters/LineContainsTest.java
  68. +4
    -3
      src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java
  69. +4
    -3
      src/testcases/org/apache/tools/ant/filters/StripJavaCommentsTest.java
  70. +6
    -4
      src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java
  71. +6
    -4
      src/testcases/org/apache/tools/ant/taskdefs/BZip2Test.java
  72. +1
    -6
      src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java
  73. +5
    -3
      src/testcases/org/apache/tools/ant/taskdefs/ConcatTest.java
  74. +7
    -8
      src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java
  75. +7
    -5
      src/testcases/org/apache/tools/ant/taskdefs/ExecTaskTest.java
  76. +6
    -6
      src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java
  77. +6
    -5
      src/testcases/org/apache/tools/ant/taskdefs/InitializeClassTest.java
  78. +5
    -4
      src/testcases/org/apache/tools/ant/taskdefs/JarTest.java
  79. +12
    -6
      src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java
  80. +6
    -6
      src/testcases/org/apache/tools/ant/taskdefs/MoveTest.java
  81. +5
    -5
      src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
  82. +8
    -9
      src/testcases/org/apache/tools/ant/taskdefs/RecorderTest.java
  83. +5
    -2
      src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java
  84. +10
    -13
      src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java
  85. +5
    -3
      src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java
  86. +3
    -3
      src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
  87. +4
    -2
      src/testcases/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java
  88. +5
    -3
      src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
  89. +5
    -10
      src/testcases/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java
  90. +3
    -3
      src/testcases/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReportTest.java
  91. +5
    -4
      src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
  92. +105
    -104
      src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
  93. +8
    -7
      src/testcases/org/apache/tools/ant/util/JavaEnvUtilsTest.java

+ 2
- 2
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -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


+ 4
- 4
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -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;



+ 4
- 2
src/main/org/apache/tools/ant/Location.java View File

@@ -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;
}


+ 21
- 22
src/main/org/apache/tools/ant/Project.java View File

@@ -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);
}



+ 8
- 8
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -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));
}
}


+ 10
- 9
src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java View File

@@ -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.</p>
*/
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",


+ 3
- 4
src/main/org/apache/tools/ant/loader/AntClassLoader2.java View File

@@ -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();


+ 5
- 3
src/main/org/apache/tools/ant/taskdefs/Ant.java View File

@@ -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) "


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/Available.java View File

@@ -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);
}

/**


+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/BuildNumber.java View File

@@ -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.";


+ 2
- 4
src/main/org/apache/tools/ant/taskdefs/Concat.java View File

@@ -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.");


+ 3
- 2
src/main/org/apache/tools/ant/taskdefs/DependSet.java View File

@@ -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


+ 4
- 3
src/main/org/apache/tools/ant/taskdefs/Ear.java View File

@@ -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 {
// <fileset> 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"


+ 5
- 4
src/main/org/apache/tools/ant/taskdefs/ExecTask.java View File

@@ -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();


+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -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;


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/Expand.java View File

@@ -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);
}
}
}


+ 6
- 6
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -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;
}



+ 5
- 3
src/main/org/apache/tools/ant/taskdefs/Get.java View File

@@ -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);
}
}



+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/ImportTask.java View File

@@ -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


+ 5
- 4
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -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());


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/Length.java View File

@@ -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;


+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/Rename.java View File

@@ -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());


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/Replace.java View File

@@ -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) {


+ 5
- 5
src/main/org/apache/tools/ant/taskdefs/Rmic.java View File

@@ -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) {


+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/SignJar.java View File

@@ -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 {


+ 4
- 3
src/main/org/apache/tools/ant/taskdefs/TempFile.java View File

@@ -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());
}
}

+ 4
- 5
src/main/org/apache/tools/ant/taskdefs/Touch.java View File

@@ -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 <code>Touch</code> 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);
}

}

+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/War.java View File

@@ -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 <fileset> 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 "


+ 6
- 6
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -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.


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/XmlProperty.java View File

@@ -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);
}

}

+ 7
- 7
src/main/org/apache/tools/ant/taskdefs/Zip.java View File

@@ -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 "


+ 4
- 3
src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -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));


+ 7
- 6
src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java View File

@@ -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);


+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/condition/IsFileSelected.java View File

@@ -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;



+ 8
- 7
src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java View File

@@ -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);



+ 3
- 4
src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java View File

@@ -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


+ 5
- 5
src/main/org/apache/tools/ant/taskdefs/optional/Cab.java View File

@@ -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);
}


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java View File

@@ -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 "


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java View File

@@ -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: ";


+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ildasm.java View File

@@ -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;


+ 3
- 2
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/ImportTypelib.java View File

@@ -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;


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java View File

@@ -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 {


+ 7
- 8
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/WsdlToDotnet.java View File

@@ -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);
}




+ 6
- 6
src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java View File

@@ -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;


+ 4
- 3
src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java View File

@@ -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;


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java View File

@@ -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


+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -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;


+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java View File

@@ -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 <tt>.class</tt> 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;


+ 6
- 5
src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java View File

@@ -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());
}


+ 9
- 9
src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovBase.java View File

@@ -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() {


+ 9
- 9
src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java View File

@@ -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) {


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/repository/Library.java View File

@@ -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


+ 7
- 7
src/main/org/apache/tools/ant/types/XMLCatalog.java View File

@@ -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");
}


+ 4
- 2
src/main/org/apache/tools/ant/types/selectors/DateSelector.java View File

@@ -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();
}

/**


+ 3
- 3
src/main/org/apache/tools/ant/types/selectors/DifferentSelector.java View File

@@ -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);


+ 5
- 1
src/main/org/apache/tools/ant/types/selectors/MappingSelector.java View File

@@ -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();
}




+ 9
- 6
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -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);
}

/**


+ 3
- 3
src/main/org/apache/tools/ant/util/JAXPUtils.java View File

@@ -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());
}

/**


+ 4
- 5
src/main/org/apache/tools/ant/util/JavaEnvUtils.java View File

@@ -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)));


+ 6
- 3
src/main/org/apache/tools/ant/util/LoaderUtils.java View File

@@ -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
}


+ 5
- 3
src/main/org/apache/tools/ant/util/ResourceUtils.java View File

@@ -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());
}

/**


+ 6
- 7
src/main/org/apache/tools/ant/util/SourceFileScanner.java View File

@@ -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());
}


+ 5
- 3
src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java View File

@@ -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}),


+ 3
- 3
src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java View File

@@ -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() {


+ 4
- 3
src/testcases/org/apache/tools/ant/filters/EscapeUnicodeTest.java View File

@@ -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));
}

}

+ 14
- 23
src/testcases/org/apache/tools/ant/filters/HeadTailTest.java View File

@@ -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));
}

}

+ 4
- 3
src/testcases/org/apache/tools/ant/filters/LineContainsTest.java View File

@@ -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));
}

}

+ 4
- 3
src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java View File

@@ -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));
}

}

+ 4
- 3
src/testcases/org/apache/tools/ant/filters/StripJavaCommentsTest.java View File

@@ -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));
}

}

+ 6
- 4
src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java View File

@@ -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")));
}
}

+ 6
- 4
src/testcases/org/apache/tools/ant/taskdefs/BZip2Test.java View File

@@ -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")));
}



+ 1
- 6
src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java View File

@@ -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");
}



+ 5
- 3
src/testcases/org/apache/tools/ant/taskdefs/ConcatTest.java View File

@@ -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));
}
}

+ 7
- 8
src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java View File

@@ -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() {


+ 7
- 5
src/testcases/org/apache/tools/ant/taskdefs/ExecTaskTest.java View File

@@ -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


+ 6
- 6
src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java View File

@@ -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")));
}



+ 6
- 5
src/testcases/org/apache/tools/ant/taskdefs/InitializeClassTest.java View File

@@ -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() {


+ 5
- 4
src/testcases/org/apache/tools/ant/taskdefs/JarTest.java View File

@@ -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) {


+ 12
- 6
src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java View File

@@ -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());


+ 6
- 6
src/testcases/org/apache/tools/ant/taskdefs/MoveTest.java View File

@@ -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 */


+ 5
- 5
src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java View File

@@ -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);


+ 8
- 9
src/testcases/org/apache/tools/ant/taskdefs/RecorderTest.java View File

@@ -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


+ 5
- 2
src/testcases/org/apache/tools/ant/taskdefs/TouchTest.java View File

@@ -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);
}



+ 10
- 13
src/testcases/org/apache/tools/ant/taskdefs/UntarTest.java View File

@@ -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")));
}



+ 5
- 3
src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java View File

@@ -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")));
}



+ 3
- 3
src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java View File

@@ -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 {


+ 4
- 2
src/testcases/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java View File

@@ -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 */


+ 5
- 3
src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java View File

@@ -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")));
}


+ 5
- 10
src/testcases/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java View File

@@ -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) {}


+ 3
- 3
src/testcases/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReportTest.java View File

@@ -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 {


+ 5
- 4
src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java View File

@@ -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();


+ 105
- 104
src/testcases/org/apache/tools/ant/util/FileUtilsTest.java View File

@@ -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));
}

/**


+ 8
- 7
src/testcases/org/apache/tools/ant/util/JavaEnvUtilsTest.java View File

@@ -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));



Loading…
Cancel
Save