Browse Source

Use the new FileUtils#rename method

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274714 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
b498a4535a
7 changed files with 41 additions and 38 deletions
  1. +10
    -8
      src/main/org/apache/tools/ant/taskdefs/Rename.java
  2. +1
    -8
      src/main/org/apache/tools/ant/taskdefs/Replace.java
  3. +7
    -5
      src/main/org/apache/tools/ant/taskdefs/Zip.java
  4. +4
    -6
      src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
  5. +5
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
  6. +7
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
  7. +7
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java

+ 10
- 8
src/main/org/apache/tools/ant/taskdefs/Rename.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -55,9 +55,11 @@
package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;


import java.io.File; import java.io.File;
import java.io.IOException;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.util.FileUtils;


/** /**
* Renames a file. * Renames a file.
@@ -115,15 +117,15 @@ public class Rename extends Task {
throw new BuildException("src attribute is required", getLocation()); throw new BuildException("src attribute is required", getLocation());
} }


if (replace && dest.exists()) {
if (!dest.delete()) {
throw new BuildException("Unable to remove existing file " +
dest);
}
if (!replace && dest.exists()) {
throw new BuildException(dest + " already exists.");
} }
if (!src.renameTo(dest)) {

try {
FileUtils.newFileUtils().rename(src, dest);
} catch (IOException e) {
throw new BuildException("Unable to rename " + src + " to " + throw new BuildException("Unable to rename " + src + " to " +
dest);
dest, e, getLocation());
} }
} }
} }

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

@@ -445,14 +445,7 @@ public class Replace extends MatchingTask {
// otherwise, delete the new one // otherwise, delete the new one
if (changes) { if (changes) {
++fileCount; ++fileCount;
if (!src.delete()) {
throw new BuildException("Couldn't delete " + src,
getLocation());
}
if (!temp.renameTo(src)) {
throw new BuildException("Couldn't rename temporary file "
+ temp, getLocation());
}
fileUtils.rename(temp, src);
temp = null; temp = null;
} }
} catch (IOException ioe) { } catch (IOException ioe) {


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

@@ -400,13 +400,13 @@ public class Zip extends MatchingTask {
fileUtils.getParentFile(zipFile)); fileUtils.getParentFile(zipFile));


try { try {
if (!zipFile.renameTo(renamedFile)) {
throw new BuildException("Unable to rename old file "
+ "to temporary file");
}
fileUtils.rename(zipFile, renamedFile);
} catch (SecurityException e) { } catch (SecurityException e) {
throw new BuildException("Not allowed to rename old file " throw new BuildException("Not allowed to rename old file "
+ "to temporary file"); + "to temporary file");
} catch (IOException e) {
throw new BuildException("Unable to rename old file "
+ "to temporary file");
} }
} }


@@ -498,7 +498,9 @@ public class Zip extends MatchingTask {
} }


if (doUpdate && renamedFile != null) { if (doUpdate && renamedFile != null) {
if (!renamedFile.renameTo(zipFile)) {
try {
fileUtils.rename(renamedFile, zipFile);
} catch (IOException e) {
msg += " (and I couldn't rename the temporary file " + msg += " (and I couldn't rename the temporary file " +
renamedFile.getName() + " back)"; renamedFile.getName() + " back)";
} }


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

@@ -437,15 +437,13 @@ public class ReplaceRegExp extends Task {
w = null; w = null;


if (changes) { if (changes) {
if (!f.delete()) {
throw new BuildException("Couldn't delete " + f,
getLocation());
}
if (!temp.renameTo(f)) {
try {
fileUtils.rename(temp, f);
temp = null;
} catch (IOException e) {
throw new BuildException("Couldn't rename temporary file " throw new BuildException("Couldn't rename temporary file "
+ temp, getLocation()); + temp, getLocation());
} }
temp = null;
} }
} finally { } finally {
try { try {


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

@@ -680,7 +680,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
* actual bean changes without changing the the method signatures then * actual bean changes without changing the the method signatures then
* only the bean classfile needs to be updated and the rest of the * only the bean classfile needs to be updated and the rest of the
* weblogic jar file can remain the same. If the Interfaces, ie. the * weblogic jar file can remain the same. If the Interfaces, ie. the
* method signatures change or if the xml deployment dicriptors changed,
* method signatures change or if the xml deployment descriptors changed,
* the whole jar needs to be rebuilt with ejbc. This is not strictly true * the whole jar needs to be rebuilt with ejbc. This is not strictly true
* for the xml files. If the JNDI name changes then the jar doesnt have to * for the xml files. If the JNDI name changes then the jar doesnt have to
* be rebuild, but if the resources references change then it does. At * be rebuild, but if the resources references change then it does. At
@@ -864,9 +864,10 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
} catch (IOException closeException) { } catch (IOException closeException) {
} }


weblogicJarFile.delete();
newWLJarFile.renameTo(weblogicJarFile);
if (!weblogicJarFile.exists()) {
try {
fileUtils.rename(newWLJarFile, weblogicJarFile);
} catch (IOException renameException) {
log(renameException.getMessage(), Project.MSG_WARN);
rebuild = true; rebuild = true;
} }
} }


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

@@ -70,6 +70,7 @@ import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Environment; import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils;


/** /**
* Websphere deployment tool that augments the ejbjar task. * Websphere deployment tool that augments the ejbjar task.
@@ -693,7 +694,7 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool {
* If the actual bean changes without changing the the method signatures * If the actual bean changes without changing the the method signatures
* then only the bean classfile needs to be updated and the rest of the * then only the bean classfile needs to be updated and the rest of the
* websphere jar file can remain the same. If the Interfaces, ie. the * websphere jar file can remain the same. If the Interfaces, ie. the
* method signatures change or if the xml deployment dicriptors changed,
* method signatures change or if the xml deployment descriptors changed,
* the whole jar needs to be rebuilt with ejbdeploy. This is not strictly * the whole jar needs to be rebuilt with ejbdeploy. This is not strictly
* true for the xml files. If the JNDI name changes then the jar doesnt * true for the xml files. If the JNDI name changes then the jar doesnt
* have to be rebuild, but if the resources references change then it * have to be rebuild, but if the resources references change then it
@@ -871,9 +872,11 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool {
} catch (IOException closeException) { } catch (IOException closeException) {
} }


websphereJarFile.delete();
newwasJarFile.renameTo(websphereJarFile);
if (!websphereJarFile.exists()) {
try {
FileUtils.newFileUtils().rename(newwasJarFile,
websphereJarFile);
} catch (IOException renameException) {
log(renameException.getMessage(), Project.MSG_WARN);
rebuild = true; rebuild = true;
} }
} }


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

@@ -428,11 +428,13 @@ public class Symlink extends Task {
FileUtils fu = FileUtils.newFileUtils(); FileUtils fu = FileUtils.newFileUtils();
File temp = fu.createTempFile("symlink",".tmp", parentDir); File temp = fu.createTempFile("symlink",".tmp", parentDir);
try { try {
if (!canfil.renameTo(temp)) {
try {
fu.rename(canfil, temp);
} catch (IOException e) {
throw new IOException("Couldn't rename resource when " + throw new IOException("Couldn't rename resource when " +
"attempting to delete " + linkfil); "attempting to delete " + linkfil);
} }
// delete the (now) broken link // delete the (now) broken link
if(!linkfil.delete()) { if(!linkfil.delete()) {
throw new IOException("Couldn't delete symlink: " + linkfil + throw new IOException("Couldn't delete symlink: " + linkfil +
@@ -441,7 +443,9 @@ public class Symlink extends Task {
} }
} finally { } finally {
// return the resource to its original name. // return the resource to its original name.
if (!temp.renameTo(canfil)) {
try {
fu.rename(temp, canfil);
} catch (IOException e) {
throw new IOException("Couldn't return resource " + temp + throw new IOException("Couldn't return resource " + temp +
" its original name: " + canstr + " its original name: " + canstr +
"\n THE RESOURCE'S NAME ON DISK HAS " + "\n THE RESOURCE'S NAME ON DISK HAS " +


Loading…
Cancel
Save