|
|
@@ -54,6 +54,9 @@ |
|
|
|
|
|
|
|
package org.apache.tools.ant.util; |
|
|
|
|
|
|
|
import org.apache.tools.ant.Project; |
|
|
|
import org.apache.tools.ant.Task; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.Vector; |
|
|
|
|
|
|
@@ -69,6 +72,15 @@ import java.util.Vector; |
|
|
|
*/ |
|
|
|
public class SourceFileScanner { |
|
|
|
|
|
|
|
protected Task task; |
|
|
|
|
|
|
|
/** |
|
|
|
* @param task The task we should log messages through |
|
|
|
*/ |
|
|
|
public SourceFileScanner(Task task) { |
|
|
|
this.task = task; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Restrict the given set of files to those that are newer than |
|
|
|
* their corresponding target files. |
|
|
@@ -81,24 +93,54 @@ public class SourceFileScanner { |
|
|
|
*/ |
|
|
|
public String[] restrict(String[] files, File srcDir, File destDir, |
|
|
|
FileNameMapper mapper) { |
|
|
|
|
|
|
|
long now = (new java.util.Date()).getTime(); |
|
|
|
StringBuffer targetList = new StringBuffer(); |
|
|
|
|
|
|
|
Vector v = new Vector(); |
|
|
|
for (int i=0; i< files.length; i++) { |
|
|
|
|
|
|
|
String[] targets = mapper.mapFileName(files[i]); |
|
|
|
if (targets == null || targets.length == 0) { |
|
|
|
task.log(files[i]+" skipped - don\'t know how to handle it", |
|
|
|
Project.MSG_VERBOSE); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
File src = new File(srcDir, files[i]); |
|
|
|
for (int j=0; j<targets.length; j++) { |
|
|
|
File dest = new File(destDir, targets[j]); |
|
|
|
if (!dest.exists() || |
|
|
|
src.lastModified() > dest.lastModified()) { |
|
|
|
if (src.lastModified() > now) { |
|
|
|
task.log("Warning: "+files[i]+" modified in the future.", |
|
|
|
Project.MSG_WARN); |
|
|
|
} |
|
|
|
|
|
|
|
boolean added = false; |
|
|
|
targetList.setLength(0); |
|
|
|
for (int j=0; !added && j<targets.length; j++) { |
|
|
|
File dest = new File(destDir, targets[j]); |
|
|
|
if (!dest.exists()) { |
|
|
|
task.log(files[i]+" added as "+dest.getAbsolutePath()+" doesn\'t exist.", |
|
|
|
Project.MSG_VERBOSE); |
|
|
|
v.addElement(files[i]); |
|
|
|
break; |
|
|
|
added = true; |
|
|
|
} else if (src.lastModified() > dest.lastModified()) { |
|
|
|
task.log(files[i]+" added as "+dest.getAbsolutePath()+" is outdated.", |
|
|
|
Project.MSG_VERBOSE); |
|
|
|
v.addElement(files[i]); |
|
|
|
added = true; |
|
|
|
} else { |
|
|
|
if (targetList.length() > 0) { |
|
|
|
targetList.append(", "); |
|
|
|
} |
|
|
|
targetList.append(dest.getAbsolutePath()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!added) { |
|
|
|
task.log(files[i]+" omitted as "+targetList.toString() |
|
|
|
+ (targets.length == 1 ? " is" : " are ") |
|
|
|
+ " up to date.", Project.MSG_VERBOSE); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
String[] result = new String[v.size()]; |
|
|
|
v.copyInto(result); |
|
|
|