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 DependSet.java
Date Wed, 20 Feb 2002 16:32:21 GMT
bodewig     02/02/20 08:32:21

  Modified:    src/main/org/apache/tools/ant/taskdefs DependSet.java
  Log:
  optimize dependset by not comparing each target with each source but
  only the oldest target.
  
  Submitted by:	mrezaei@starpoint.com
  
  I've also swapped the order of handling sourcefilesets and
  sourcefilelists as filelists are a lot less expensive than filesets.
  
  Revision  Changes    Path
  1.8       +52 -45    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/DependSet.java
  
  Index: DependSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/DependSet.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DependSet.java	22 Nov 2001 08:40:38 -0000	1.7
  +++ DependSet.java	20 Feb 2002 16:32:21 -0000	1.8
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -108,7 +108,7 @@
    * </li></ul>
    * 
    * @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
  - * @version $Revision: 1.7 $ $Date: 2001/11/22 08:40:38 $
  + * @version $Revision: 1.8 $ $Date: 2002/02/20 16:32:21 $
    */
   public class DependSet extends MatchingTask {
   
  @@ -179,6 +179,8 @@
           // Grab all the target files specified via filesets
           //
           Vector  allTargets         = new Vector();
  +        long oldestTargetTime = 0;
  +        File oldestTarget = null;
           Enumeration enumTargetSets = targetFileSets.elements();
           while (enumTargetSets.hasMoreElements()) {
                    
  @@ -195,6 +197,12 @@
                    log("Warning: "+targetFiles[i]+" modified in the future.", 
                        Project.MSG_WARN);
                 }
  +
  +              if (oldestTarget == null ||
  +                  dest.lastModified() < oldestTargetTime) {
  +                  oldestTargetTime = dest.lastModified();
  +                  oldestTarget = dest;
  +              }
              }
           }
   
  @@ -223,81 +231,80 @@
                    log("Warning: "+targetFiles[i]+" modified in the future.", 
                        Project.MSG_WARN);
                 }
  +              if (oldestTarget == null ||
  +                  dest.lastModified() < oldestTargetTime) {
  +                  oldestTargetTime = dest.lastModified();
  +                  oldestTarget = dest;
  +              }
              }
           }
  +        if (oldestTarget != null) {
  +            log(oldestTarget + " is oldest target file", Project.MSG_VERBOSE);
  +        } else { 
  +            // no target files, then we cannot remove any target files and
  +            // skip the following tests right away
  +            upToDate = false;
  +        }
   
           //
  -        // Check targets vs source files specified via filesets
  +        // Check targets vs source files specified via filelists
           //
           if (upToDate) {
  -           Enumeration enumSourceSets = sourceFileSets.elements();
  -           while (upToDate && enumSourceSets.hasMoreElements()) {
  +           Enumeration enumSourceLists = sourceFileLists.elements();
  +           while (upToDate && enumSourceLists.hasMoreElements()) {
             
  -              FileSet sourceFS          = (FileSet) enumSourceSets.nextElement();
  -              DirectoryScanner sourceDS = sourceFS.getDirectoryScanner(project);
  -              String[] sourceFiles      = sourceDS.getIncludedFiles();
  +              FileList sourceFL         = (FileList) enumSourceLists.nextElement();
  +              String[] sourceFiles      = sourceFL.getFiles(project);
   
  -              for (int i=0; upToDate && i < sourceFiles.length; i++) {
  -                 File src = new File(sourceFS.getDir(project), sourceFiles[i]);
  +              int i = 0;
  +              do {
  +                 File src = new File(sourceFL.getDir(project), sourceFiles[i]);
   
                    if (src.lastModified() > now) {
                       log("Warning: "+sourceFiles[i]+" modified in the future.", 
                           Project.MSG_WARN);
                    }
   
  -                 Enumeration enumTargets = allTargets.elements();
  -                 while (upToDate && enumTargets.hasMoreElements()) {
  -                 
  -                    File dest = (File)enumTargets.nextElement();
  -                    if (src.lastModified() > dest.lastModified()) {
  -                       log(dest.getPath() + " is out of date with respect to " +
  -                                sourceFiles[i], Project.MSG_VERBOSE);
  -                       upToDate = false;
  +                 if (!src.exists()) {
  +                    log(sourceFiles[i]+ " does not exist.", Project.MSG_VERBOSE);
  +                    upToDate = false;
  +                    break;
  +                 }
   
  -                    }
  +                 if (src.lastModified() > oldestTargetTime) {
  +                    upToDate = false;
  +                    log(oldestTarget + " is out of date with respect to " +
  +                        sourceFiles[i], Project.MSG_VERBOSE);
                    }
  -              }
  +              } while (upToDate && (++i < sourceFiles.length) );
              }
           }
   
           //
  -        // Check targets vs source files specified via filelists
  +        // Check targets vs source files specified via filesets
           //
           if (upToDate) {
  -           Enumeration enumSourceLists = sourceFileLists.elements();
  -           while (upToDate && enumSourceLists.hasMoreElements()) {
  +           Enumeration enumSourceSets = sourceFileSets.elements();
  +           while (upToDate && enumSourceSets.hasMoreElements()) {
             
  -              FileList sourceFL         = (FileList) enumSourceLists.nextElement();
  -              String[] sourceFiles      = sourceFL.getFiles(project);
  +              FileSet sourceFS          = (FileSet) enumSourceSets.nextElement();
  +              DirectoryScanner sourceDS = sourceFS.getDirectoryScanner(project);
  +              String[] sourceFiles      = sourceDS.getIncludedFiles();
   
  -              int i = 0;
  -              do {
  -                 File src = new File(sourceFL.getDir(project), sourceFiles[i]);
  +              for (int i=0; upToDate && i < sourceFiles.length; i++) {
  +                 File src = new File(sourceFS.getDir(project), sourceFiles[i]);
   
                    if (src.lastModified() > now) {
                       log("Warning: "+sourceFiles[i]+" modified in the future.", 
                           Project.MSG_WARN);
                    }
   
  -                 if (!src.exists()) {
  -                    log(sourceFiles[i]+ " does not exist.", Project.MSG_VERBOSE);
  +                 if (src.lastModified() > oldestTargetTime) {
                       upToDate = false;
  -                    break;
  +                    log(oldestTarget + " is out of date with respect to " +
  +                        sourceFiles[i], Project.MSG_VERBOSE);
                    }
  -
  -                 Enumeration enumTargets = allTargets.elements();
  -                 while (upToDate && enumTargets.hasMoreElements()) {
  -                 
  -                    File dest = (File)enumTargets.nextElement();
  -                    
  -                    if (src.lastModified() > dest.lastModified()) {
  -                       log(dest.getPath() + " is out of date with respect to " +
  -                                sourceFiles[i], Project.MSG_VERBOSE);
  -                       upToDate = false;
  -
  -                    }
  -                 }
  -              } while (upToDate && (++i < sourceFiles.length) );
  +              }
              }
           }
   
  
  
  

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