ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Checksum.java
Date Wed, 10 Apr 2002 14:30:05 GMT
bodewig     02/04/10 07:30:05

  Modified:    src/main/org/apache/tools/ant/taskdefs Checksum.java
  Log:
  Make sure <checksum> resets its internal state (bug 7552 audit), don't
  trust File.length(), make sure <checksum> doesn't break the property
  immutability rules.
  
  Revision  Changes    Path
  1.19      +28 -21    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Checksum.java
  
  Index: Checksum.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Checksum.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Checksum.java	10 Apr 2002 00:19:54 -0000	1.18
  +++ Checksum.java	10 Apr 2002 14:30:04 -0000	1.19
  @@ -78,6 +78,8 @@
    *
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    *
  + * @since Ant 1.5
  + *
    * @ant.task category="control"
    */
   public class Checksum extends MatchingTask implements Condition {
  @@ -216,6 +218,7 @@
        * Validate attributes and get down to business.
        */
       private boolean validateAndExecute() throws BuildException {
  +        String savedFileExt = fileext;
   
           if (file == null && filesets.size() == 0) {
               throw new BuildException(
  @@ -265,13 +268,6 @@
                   "ForceOverwrite cannot be used when conditions are being used.");
           }
   
  -        if (fileext == null) {
  -            fileext = "." + algorithm;
  -        } else if (fileext.trim().length() == 0) {
  -            throw new BuildException(
  -                "File extension when specified must not be an empty string");
  -        }
  -
           messageDigest = null;
           if (provider != null) {
               try {
  @@ -294,20 +290,32 @@
                   location);
           }
   
  -        addToIncludeFileMap(file);
  +        if (fileext == null) {
  +            fileext = "." + algorithm;
  +        } else if (fileext.trim().length() == 0) {
  +            throw new BuildException(
  +                "File extension when specified must not be an empty string");
  +        }
   
  -        int sizeofFileSet = filesets.size();
  -        for (int i = 0; i < sizeofFileSet; i++) {
  -            FileSet fs = (FileSet) filesets.elementAt(i);
  -            DirectoryScanner ds = fs.getDirectoryScanner(project);
  -            String[] srcFiles = ds.getIncludedFiles();
  -            for (int j = 0; j < srcFiles.length; j++) {
  -                File src = new File(fs.getDir(project), srcFiles[j]);
  -                addToIncludeFileMap(src);
  +        try {
  +            addToIncludeFileMap(file);
  +            
  +            int sizeofFileSet = filesets.size();
  +            for (int i = 0; i < sizeofFileSet; i++) {
  +                FileSet fs = (FileSet) filesets.elementAt(i);
  +                DirectoryScanner ds = fs.getDirectoryScanner(project);
  +                String[] srcFiles = ds.getIncludedFiles();
  +                for (int j = 0; j < srcFiles.length; j++) {
  +                    File src = new File(fs.getDir(project), srcFiles[j]);
  +                    addToIncludeFileMap(src);
  +                }
               }
  -        }
   
  -        return generateChecksums();
  +            return generateChecksums();
  +        } finally {
  +            fileext = savedFileExt;
  +            includeFileMap.clear();
  +        }
       }
   
       /**
  @@ -379,13 +387,12 @@
                       if (isCondition) {
                           checksumMatches = checksum.equals(property);
                       } else {
  -                        project.setProperty(prop, checksum);
  +                        project.setNewProperty(prop, checksum);
                       }
                   } else if (destination instanceof java.io.File) {
                       if (isCondition) {
                           File existingFile = (File) destination;
  -                        if (existingFile.exists() &&
  -                            existingFile.length() == checksum.length()) {
  +                        if (existingFile.exists()) {
                               fis = new FileInputStream(existingFile);
                               InputStreamReader isr = new InputStreamReader(fis);
                               BufferedReader br = new BufferedReader(isr);
  
  
  

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


Mime
View raw message