Browse Source

Added logging to SourceFileScanner.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268192 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
3b1f2fca74
3 changed files with 50 additions and 6 deletions
  1. +2
    -0
      WHATSNEW
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  3. +47
    -5
      src/main/org/apache/tools/ant/util/SourceFileScanner.java

+ 2
- 0
WHATSNEW View File

@@ -28,6 +28,8 @@ Other changes:
* <cab> can work on non-Windows platforms with the help of libcabinet.
See http://trill.cis.fordham.edu/~barbacha/cabinet_library/.

* <FTP> now supports passive mode.

Fixed bugs:
-----------



+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -266,7 +266,7 @@ public class Copy extends Task {
if (forceOverwrite) {
toCopy = names;
} else {
SourceFileScanner ds = new SourceFileScanner();
SourceFileScanner ds = new SourceFileScanner(this);
toCopy = ds.restrict(names, fromDir, toDir, mapper);
}


+ 47
- 5
src/main/org/apache/tools/ant/util/SourceFileScanner.java View File

@@ -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);


Loading…
Cancel
Save