git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274714 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,7 +1,7 @@ | |||
| /* | |||
| * 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. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| @@ -55,9 +55,11 @@ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| /** | |||
| * Renames a file. | |||
| @@ -115,15 +117,15 @@ public class Rename extends Task { | |||
| 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 " + | |||
| dest); | |||
| dest, e, getLocation()); | |||
| } | |||
| } | |||
| } | |||
| @@ -445,14 +445,7 @@ public class Replace extends MatchingTask { | |||
| // otherwise, delete the new one | |||
| if (changes) { | |||
| ++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; | |||
| } | |||
| } catch (IOException ioe) { | |||
| @@ -400,13 +400,13 @@ public class Zip extends MatchingTask { | |||
| fileUtils.getParentFile(zipFile)); | |||
| try { | |||
| if (!zipFile.renameTo(renamedFile)) { | |||
| throw new BuildException("Unable to rename old file " | |||
| + "to temporary file"); | |||
| } | |||
| fileUtils.rename(zipFile, renamedFile); | |||
| } catch (SecurityException e) { | |||
| throw new BuildException("Not allowed to rename old 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 (!renamedFile.renameTo(zipFile)) { | |||
| try { | |||
| fileUtils.rename(renamedFile, zipFile); | |||
| } catch (IOException e) { | |||
| msg += " (and I couldn't rename the temporary file " + | |||
| renamedFile.getName() + " back)"; | |||
| } | |||
| @@ -437,15 +437,13 @@ public class ReplaceRegExp extends Task { | |||
| w = null; | |||
| 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 " | |||
| + temp, getLocation()); | |||
| } | |||
| temp = null; | |||
| } | |||
| } finally { | |||
| try { | |||
| @@ -680,7 +680,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { | |||
| * actual bean changes without changing the the method signatures then | |||
| * 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 | |||
| * 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 | |||
| * 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 | |||
| @@ -864,9 +864,10 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { | |||
| } 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; | |||
| } | |||
| } | |||
| @@ -70,6 +70,7 @@ import org.apache.tools.ant.types.Commandline; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| import org.apache.tools.ant.types.Environment; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| /** | |||
| * 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 | |||
| * 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 | |||
| * 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 | |||
| * 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 | |||
| @@ -871,9 +872,11 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { | |||
| } 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; | |||
| } | |||
| } | |||
| @@ -428,11 +428,13 @@ public class Symlink extends Task { | |||
| FileUtils fu = FileUtils.newFileUtils(); | |||
| File temp = fu.createTempFile("symlink",".tmp", parentDir); | |||
| try { | |||
| if (!canfil.renameTo(temp)) { | |||
| try { | |||
| fu.rename(canfil, temp); | |||
| } catch (IOException e) { | |||
| throw new IOException("Couldn't rename resource when " + | |||
| "attempting to delete " + linkfil); | |||
| } | |||
| // delete the (now) broken link | |||
| if(!linkfil.delete()) { | |||
| throw new IOException("Couldn't delete symlink: " + linkfil + | |||
| @@ -441,7 +443,9 @@ public class Symlink extends Task { | |||
| } | |||
| } finally { | |||
| // 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 + | |||
| " its original name: " + canstr + | |||
| "\n THE RESOURCE'S NAME ON DISK HAS " + | |||