diff --git a/src/main/org/apache/tools/ant/taskdefs/DependSet.java b/src/main/org/apache/tools/ant/taskdefs/DependSet.java index 16da47966..689300476 100644 --- a/src/main/org/apache/tools/ant/taskdefs/DependSet.java +++ b/src/main/org/apache/tools/ant/taskdefs/DependSet.java @@ -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 @@ -179,6 +179,8 @@ public class DependSet extends MatchingTask { // 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 @@ public class DependSet extends MatchingTask { 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 @@ public class DependSet extends MatchingTask { 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) ); + } } }