From 003b013e23a3ddefa411b4340f52f43df5ea0870 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sun, 25 Jun 2000 11:45:19 +0000 Subject: [PATCH] Make a matching task This is based on the concept in the patch submitted by Charles Tewksbury although the implementation details are a little different. Submitted by: Charles Tewksbury git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267699 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/Replace.java | 65 +++++++++++++++---- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Replace.java b/src/main/org/apache/tools/ant/taskdefs/Replace.java index 7d59898e8..ae9a1fc8c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Replace.java +++ b/src/main/org/apache/tools/ant/taskdefs/Replace.java @@ -60,36 +60,65 @@ import java.util.*; /** * Replaces all the occurrences of the given string token with the given - * string value of the indicated file. + * string value of the indicated files. * * @author Stefano Mazzocchi stefano@apache.org */ -public class Replace extends Task { +public class Replace extends MatchingTask { private File src = null; - private File dest = null; private String token = null; private String value = ""; + + private File dir = null; /** * Do the execution. */ public void execute() throws BuildException { - project.log("Replacing " + token + " --> " + value); + if (token == null) { + throw new BuildException("replace token must not be null"); + } + + if (src == null && dir == null) { + throw new BuildException("Either the file or the dir attribute must be specified"); + } - if (src == null || token == null ) { - project.log("File and token must not be null"); - return; + project.log("Replacing " + token + " --> " + value); + + if (src != null) { + processFile(src); } - if (dest == null) { - throw new BuildException("Error creating temp file."); + if (dir != null) { + DirectoryScanner ds = super.getDirectoryScanner(dir); + String[] srcs = ds.getIncludedFiles(); + + for(int i=0; i