ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/unix Symlink.java
Date Wed, 25 Jun 2003 11:52:48 GMT
bodewig     2003/06/25 04:52:48

  Modified:    src/main/org/apache/tools/ant/taskdefs Rename.java
                        Replace.java Zip.java
               src/main/org/apache/tools/ant/taskdefs/optional
                        ReplaceRegExp.java
               src/main/org/apache/tools/ant/taskdefs/optional/ejb
                        WeblogicDeploymentTool.java
                        WebsphereDeploymentTool.java
               src/main/org/apache/tools/ant/taskdefs/optional/unix
                        Symlink.java
  Log:
  Use the new FileUtils#rename method
  
  Revision  Changes    Path
  1.14      +10 -8     ant/src/main/org/apache/tools/ant/taskdefs/Rename.java
  
  Index: Rename.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Rename.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Rename.java	10 Feb 2003 14:13:36 -0000	1.13
  +++ Rename.java	25 Jun 2003 11:52:46 -0000	1.14
  @@ -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 @@
               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());
           }
       }
   }
  
  
  
  1.40      +1 -8      ant/src/main/org/apache/tools/ant/taskdefs/Replace.java
  
  Index: Replace.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Replace.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- Replace.java	24 Apr 2003 09:27:02 -0000	1.39
  +++ Replace.java	25 Jun 2003 11:52:46 -0000	1.40
  @@ -445,14 +445,7 @@
               // 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) {
  
  
  
  1.107     +7 -5      ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
  
  Index: Zip.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
  retrieving revision 1.106
  retrieving revision 1.107
  diff -u -r1.106 -r1.107
  --- Zip.java	2 May 2003 14:50:10 -0000	1.106
  +++ Zip.java	25 Jun 2003 11:52:46 -0000	1.107
  @@ -400,13 +400,13 @@
                                                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 @@
               }
   
               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)";
                   }
  
  
  
  1.21      +4 -6      ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
  
  Index: ReplaceRegExp.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ReplaceRegExp.java	24 Apr 2003 09:27:02 -0000	1.20
  +++ ReplaceRegExp.java	25 Jun 2003 11:52:47 -0000	1.21
  @@ -437,15 +437,13 @@
               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 {
  
  
  
  1.49      +5 -4      ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
  
  Index: WeblogicDeploymentTool.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- WeblogicDeploymentTool.java	16 Feb 2003 01:46:20 -0000	1.48
  +++ WeblogicDeploymentTool.java	25 Jun 2003 11:52:47 -0000	1.49
  @@ -680,7 +680,7 @@
        * 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 @@
                   } 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;
                   }
               }
  
  
  
  1.21      +7 -4      ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
  
  Index: WebsphereDeploymentTool.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- WebsphereDeploymentTool.java	18 Apr 2003 23:40:25 -0000	1.20
  +++ WebsphereDeploymentTool.java	25 Jun 2003 11:52:47 -0000	1.21
  @@ -70,6 +70,7 @@
   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 @@
        * 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 @@
                   } 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;
                   }
               }
  
  
  
  1.7       +8 -4      ant/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
  
  Index: Symlink.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Symlink.java	22 Apr 2003 07:35:16 -0000	1.6
  +++ Symlink.java	25 Jun 2003 11:52:47 -0000	1.7
  @@ -428,11 +428,13 @@
           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 @@
               }
           } 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 " +
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message