From ae16bb711b331f6c8a20ee1298cf171de43266f7 Mon Sep 17 00:00:00 2001
From: Stefano Mazzocchi by Version 1.0.5 - 2000/02/12 Version 1.0.6 - 2000/02/13 If there is a property called "builddir" with the value
"build", then this could be used in an attribute like this: "${builddir}/classes".
This is resolved as "build/classes". A project can have a set of tokens that will be automatically expanded if
+found when a file is copied. These might be set in the buildfile
+by the filter task. If no filter task is specified, all
+file copying works normally and the files are not modified during the copy in
+any way. Otherwise, if a filter is set, the files will be filtered and
+each occurrency of the specified token will be replaced. Since this can be a very harmful behavior, the tokens in the files must
+be of the form @token@ where token is the token name that is set
+in the filter task. This token syntax matches the syntax of other build systems
+that perform such filtering and remains sufficiently orthogonal to most
+programming and scripting languages, as well with documentation systems. Note: in case a token with the format @token@ if found in a file but no
+filter is associated with that token, no changes take place. So, no escaping
+method is present, but as long as you choose appropriate names for your tokens,
+this should not cause problems.
-
-
Table of Contents
@@ -296,6 +298,22 @@ task attributes. This is done by placing the property name between
Token Filters
+Examples
<project name="foo" default="dist" basedir=".">
@@ -303,6 +321,8 @@ This is resolved as "build/classes".
Sets a token filter for this project. Token filters are used by all tasks +that perform file copying operations through the Project commodity methods.
+Note: the token string must not contain the separators chars (@).
+| Attribute | +Description | +Required | +
| token | +the token string without @ | +Yes | +
| value | +the string that should be put to replace the token when the + file is copied | +Yes | +
<filter token="year" value="2000" />
+ <copydir src="${src.dir}" dest="${dest.dir}"/>
+will copy recursively all the files from the src.dir directory into +the dest.dir directory replacing all the occurencies of the string @year@ +with 2000.
+Gets a file from an URL. When the verbose option is "on", this task @@ -957,7 +1009,7 @@ archive with http/ftp.
Removes carriage return and eof characters from the shell scripts. Tabs and -spaces are left as is. +spaces are left as is.
<fixcrlf srcdir="${src}"
cr="add"
includes="**/*.bat"
/>
Ensures that there are carriage return characters prior to evey line feed. -Tabs and spaces are left as is. +Tabs and spaces are left as is. EOF characters are left alone if run on DOS systems, and are removed if run on Unix systems.
<fixcrlf srcdir="${src}"
@@ -1007,7 +1059,7 @@ DOS systems, and are removed if run on Unix systems.
includes="**/Makefile"
/>
Adds or removes CR characters to match local OS conventions, and -converts spaces to tabs when appropriate. EOF characters are left alone if +converts spaces to tabs when appropriate. EOF characters are left alone if run on DOS systems, and are removed if run on Unix systems. Many versions of make require tabs prior to commands.
<fixcrlf srcdir="${src}"
diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java
index bdf5716d1..5f446093d 100644
--- a/src/main/org/apache/tools/ant/Project.java
+++ b/src/main/org/apache/tools/ant/Project.java
@@ -89,6 +89,9 @@ public class Project {
public static final String JAVA_1_2 = "1.2";
public static final String JAVA_1_3 = "1.3";
+ public static final String TOKEN_START = "@";
+ public static final String TOKEN_END = "@";
+
private String name;
private PrintStream out;
private int msgOutputLevel = MSG_INFO;
@@ -98,6 +101,8 @@ public class Project {
private String defaultTarget;
private Hashtable taskClassDefinitions = new Hashtable();
private Hashtable targets = new Hashtable();
+ private Hashtable filters = new Hashtable();
+ private boolean filtering = false;
private File baseDir;
public Project(PrintStream out, int msgOutputLevel) {
@@ -114,9 +119,10 @@ public class Project {
InputStream in = this.getClass().getResourceAsStream(defs);
props.load(in);
in.close();
+
Enumeration enum = props.propertyNames();
while (enum.hasMoreElements()) {
- String key = (String)enum.nextElement();
+ String key = (String) enum.nextElement();
String value = props.getProperty(key);
try {
Class taskClass = Class.forName(value);
@@ -127,10 +133,11 @@ public class Project {
}
Properties systemP = System.getProperties();
- Enumeration e=systemP.keys();
+ Enumeration e = systemP.keys();
while (e.hasMoreElements()) {
- String n=(String) e.nextElement();
- properties.put(n, systemP.get(n));
+ String name = (String) e.nextElement();
+ String value = (String) systemP.get(name);
+ this.setProperty(name, value);
}
} catch (IOException ioe) {
String msg = "Can't load default task list";
@@ -142,11 +149,11 @@ public class Project {
public PrintStream getOutput() {
return this.out;
}
-
+
public int getOutputLevel() {
return this.msgOutputLevel;
}
-
+
public void log(String msg) {
log(msg, MSG_INFO);
}
@@ -167,13 +174,13 @@ public class Project {
// command line properties take precedence
if (null != userProperties.get(name))
return;
- log("Setting project property: " + name + " to " +
+ log("Setting project property: " + name + " -> " +
value, MSG_VERBOSE);
properties.put(name, value);
}
public void setUserProperty(String name, String value) {
- log("Setting project property: " + name + " to " +
+ log("Setting project property: " + name + " -> " +
value, MSG_VERBOSE);
userProperties.put(name, value);
properties.put(name, value);
@@ -211,6 +218,18 @@ public class Project {
return name;
}
+ public void addFilter(String token, String value) {
+ if (token == null) return;
+ log("Setting token to filter: " + token + " -> "
+ + value, MSG_VERBOSE);
+ this.filters.put(token, value);
+ this.filtering = true;
+ }
+
+ public Hashtable getFilters() {
+ return filters;
+ }
+
// match basedir attribute in xml
public void setBasedir(String baseD) throws BuildException {
try {
@@ -330,28 +349,29 @@ public class Project {
public void addOrReplaceTarget(String targetName, Target target) {
String msg = " +Target: " + targetName;
log(msg, MSG_VERBOSE);
+ target.setProject(this);
targets.put(targetName, target);
}
public Task createTask(String taskType) throws BuildException {
Class c = (Class)taskClassDefinitions.get(taskType);
-
+
// XXX
// check for nulls, other sanity
try {
Object o=c.newInstance();
- Task task = null;
- if( o instanceof Task ) {
- task=(Task)o;
- } else {
- // "Generic" Bean - use the setter pattern
- // and an Adapter
- TaskAdapter taskA=new TaskAdapter();
- taskA.setProxy( o );
- task=taskA;
- }
- task.setProject(this);
+ Task task = null;
+ if( o instanceof Task ) {
+ task=(Task)o;
+ } else {
+ // "Generic" Bean - use the setter pattern
+ // and an Adapter
+ TaskAdapter taskA=new TaskAdapter();
+ taskA.setProxy( o );
+ task=taskA;
+ }
+ task.setProject(this);
String msg = " +Task: " + taskType;
log (msg, MSG_VERBOSE);
return task;
@@ -359,7 +379,7 @@ public class Project {
String msg = "Could not create task of type: "
+ taskType + " due to " + e;
throw new BuildException(msg);
- }
+ }
}
public void executeTarget(String targetName) throws BuildException {
@@ -455,9 +475,8 @@ public class Project {
@returns translated string or empty string if to_process is null or empty
@author Jon S. Stevens jon@clearink.com
*/
- public static String translatePath(String to_process) {
- if ( to_process == null || to_process.length() == 0 )
- return "";
+ public String translatePath(String to_process) {
+ if ( to_process == null || to_process.length() == 0 ) return "";
StringBuffer bs = new StringBuffer(to_process.length() + 50);
StringCharacterIterator sci = new StringCharacterIterator(to_process);
@@ -485,14 +504,126 @@ public class Project {
return(bs.toString());
}
- // returns the boolean equivalent of a string, which is considered true
- // if either "on", "true", or "yes" is found, case insensitiveness.
+ /**
+ * Convienence method to copy a file from a source to a destination
+ * using token filtering.
+ *
+ * @throws IOException
+ */
+ public void copyFile(String sourceFile, String destFile)
+ throws IOException
+ {
+ copyFile(new File(sourceFile), new File(destFile));
+ }
+
+ /**
+ * Convienence method to copy a file from a source to a destination
+ * specifying if token filtering must be used.
+ *
+ * @throws IOException
+ */
+ public void copyFile(File sourceFile, File destFile)
+ throws IOException
+ {
+
+ if (destFile.lastModified() < sourceFile.lastModified()) {
+ log("Copy: " + sourceFile.getAbsolutePath() + " > "
+ + destFile.getAbsolutePath(), MSG_VERBOSE);
+
+ // ensure that parent dir of dest file exists!
+ // not using getParentFile method to stay 1.1 compat
+ File parent = new File(destFile.getParent());
+ if (!parent.exists()) {
+ parent.mkdirs();
+ }
+
+ if (filtering) {
+ BufferedReader in = new BufferedReader(new FileReader(sourceFile));
+ BufferedWriter out = new BufferedWriter(new FileWriter(destFile));
+
+ int length;
+ String newline = null;
+ String line = in.readLine();
+ while (line != null) {
+ if (line.length() == 0) {
+ out.newLine();
+ } else {
+ newline = replace(line, filters);
+ out.write(newline);
+ out.newLine();
+ }
+ line = in.readLine();
+ }
+
+ out.close();
+ in.close();
+ } else {
+ FileInputStream in = new FileInputStream(sourceFile);
+ FileOutputStream out = new FileOutputStream(destFile);
+
+ byte[] buffer = new byte[8 * 1024];
+ int count = 0;
+ do {
+ out.write(buffer, 0, count);
+ count = in.read(buffer, 0, buffer.length);
+ } while (count != -1);
+
+ in.close();
+ out.close();
+ }
+ }
+ }
+
+ /**
+ * Does replacement on the given string using the given token table.
+ *
+ * @returns the string with the token replaced.
+ */
+ private String replace(String s, Hashtable tokens) {
+ int index = s.indexOf(TOKEN_START);
+
+ if (index > -1) {
+ try {
+ StringBuffer b = new StringBuffer();
+ int i = 0;
+ String token = null;
+ String value = null;
+
+ do {
+ token = s.substring(index + TOKEN_START.length(), s.indexOf(TOKEN_END, index + TOKEN_START.length() + 1));
+ b.append(s.substring(i, index));
+ if (tokens.containsKey(token)) {
+ value = (String) tokens.get(token);
+ log("Replacing: " + TOKEN_START + token + TOKEN_END + " -> " + value, MSG_VERBOSE);
+ b.append(value);
+ } else {
+ b.append(TOKEN_START);
+ b.append(token);
+ b.append(TOKEN_END);
+ }
+ i = index + TOKEN_START.length() + token.length() + TOKEN_END.length();
+ } while ((index = s.indexOf(TOKEN_START, i)) > -1);
+
+ b.append(s.substring(i));
+ return b.toString();
+ } catch (StringIndexOutOfBoundsException e) {
+ return s;
+ }
+ } else {
+ return s;
+ }
+ }
+
+ /**
+ * returns the boolean equivalent of a string, which is considered true
+ * if either "on", "true", or "yes" is found, ignoring case.
+ */
public static boolean toBoolean(String s) {
- return (s.equalsIgnoreCase("on") ||
- s.equalsIgnoreCase("true") ||
+ return (s.equalsIgnoreCase("on") ||
+ s.equalsIgnoreCase("true") ||
s.equalsIgnoreCase("yes"));
}
-
+
// Given a string defining a target name, and a Hashtable
// containing the "name to Target" mapping, pick out the
// Target and execute it.
@@ -507,7 +638,6 @@ public class Project {
t.execute();
}
-
/**
* Topologically sort a set of Targets.
* @param root is the (String) name of the root Target. The sort is
diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java
index 355257a87..f660e3a86 100644
--- a/src/main/org/apache/tools/ant/ProjectHelper.java
+++ b/src/main/org/apache/tools/ant/ProjectHelper.java
@@ -227,6 +227,7 @@ public class ProjectHelper {
NamedNodeMap nodeMap = element.getAttributes();
configureTask(project, task, nodeMap);
task.init();
+ task.setTarget(target);
target.addTask(task);
}
}
diff --git a/src/main/org/apache/tools/ant/Target.java b/src/main/org/apache/tools/ant/Target.java
index 9c48d1be6..f38259b25 100644
--- a/src/main/org/apache/tools/ant/Target.java
+++ b/src/main/org/apache/tools/ant/Target.java
@@ -88,12 +88,6 @@ public class Target {
}
}
- public void setAttribute(String name, Object value) {
- if (value instanceof Task) {
- addTask((Task) value);
- }
- }
-
public void setName(String name) {
this.name = name;
}
@@ -115,11 +109,11 @@ public class Target {
}
public void setCondition(String property) {
- this.condition = property;
+ this.condition = (property == null) ? "" : property;
}
public void execute() throws BuildException {
- if ((this.condition != null) || (this.condition.equals("")) || (project.getProperty(this.condition) != null)) {
+ if (("".equals(this.condition)) || (project.getProperty(this.condition) != null)) {
Enumeration enum = tasks.elements();
while (enum.hasMoreElements()) {
Task task = (Task) enum.nextElement();
diff --git a/src/main/org/apache/tools/ant/Task.java b/src/main/org/apache/tools/ant/Task.java
index e59b3e301..68433bcbe 100644
--- a/src/main/org/apache/tools/ant/Task.java
+++ b/src/main/org/apache/tools/ant/Task.java
@@ -54,14 +54,10 @@
package org.apache.tools.ant;
-import java.io.*;
-import java.util.*;
-
/**
* Base class for all tasks.
- *
- * @author duncan@x180.com
*/
+
public abstract class Task {
protected Project project = null;
@@ -80,16 +76,12 @@ public abstract class Task {
}
/**
- * Sets a task attribute.
+ * Sets the target object of this task.
*
- * @param name the attribute name
- * @param value the attribute value
+ * @param target Target in whose scope this task belongs.
*/
- public void setAttribute(String name, Object value) {
- if (name.equals("target")) {
- this.target = (Target) value;
- this.project = this.target.getProject();
- }
+ public void setTarget(Target target) {
+ this.target = target;
}
/**
@@ -106,49 +98,5 @@ public abstract class Task {
*/
public void execute() throws BuildException {};
- /**
- * Convienence method to copy a file from a source to a destination
- *
- * @throws IOException
- */
- protected void copyFile(String sourceFile, String destFile)
- throws IOException
- {
- copyFile(new File(sourceFile), new File(destFile));
- }
-
- /**
- * Convienence method to copy a file from a source to a destination.
- *
- * @throws IOException
- */
- protected void copyFile(File sourceFile, File destFile) throws IOException {
-
- if (destFile.lastModified() < sourceFile.lastModified()) {
- project.log("Copy: " + sourceFile.getAbsolutePath() + " > "
- + destFile.getAbsolutePath(), project.MSG_VERBOSE);
-
- // ensure that parent dir of dest file exists!
- // not using getParentFile method to stay 1.1 compat
- File parent = new File(destFile.getParent());
- if (!parent.exists()) {
- parent.mkdirs();
- }
-
- // open up streams and copy using a decent buffer
- FileInputStream in = new FileInputStream(sourceFile);
- FileOutputStream out = new FileOutputStream(destFile);
-
- byte[] buffer = new byte[8 * 1024];
- int count = 0;
- do {
- out.write(buffer, 0, count);
- count = in.read(buffer, 0, buffer.length);
- } while (count != -1);
-
- in.close();
- out.close();
- }
- }
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/Copydir.java b/src/main/org/apache/tools/ant/taskdefs/Copydir.java
index 029ad5a01..f5fdf8834 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Copydir.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Copydir.java
@@ -97,10 +97,10 @@ public class Copydir extends MatchingTask {
+ destDir.getAbsolutePath());
Enumeration enum = filecopyList.keys();
while (enum.hasMoreElements()) {
- String fromFile = (String)enum.nextElement();
- String toFile = (String)filecopyList.get(fromFile);
+ String fromFile = (String) enum.nextElement();
+ String toFile = (String) filecopyList.get(fromFile);
try {
- copyFile(fromFile, toFile);
+ project.copyFile(fromFile, toFile);
} catch (IOException ioe) {
String msg = "Failed to copy " + fromFile + " to " + toFile
+ " due to " + ioe.getMessage();
diff --git a/src/main/org/apache/tools/ant/taskdefs/Copyfile.java b/src/main/org/apache/tools/ant/taskdefs/Copyfile.java
index fa78d8f0b..bfa93070b 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Copyfile.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Copyfile.java
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -9,7 +9,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -17,15 +17,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
@@ -60,7 +60,7 @@ import java.io.*;
import java.util.*;
/**
- *
+ * Copies a file.
*
* @author duncan@x180.com
*/
@@ -71,22 +71,22 @@ public class Copyfile extends Task {
public File destFile;
public void setSrc(String src) {
- srcFile = project.resolveFile(src);
+ srcFile = project.resolveFile(src);
}
public void setDest(String dest) {
- destFile = project.resolveFile(dest);
+ destFile = project.resolveFile(dest);
}
public void execute() throws BuildException {
- if (srcFile.lastModified() > destFile.lastModified()) {
- try {
- copyFile(srcFile, destFile);
- } catch (IOException ioe) {
- String msg = "Error copying file: " + srcFile.getAbsolutePath()
- + " due to " + ioe.getMessage();
- throw new BuildException(msg);
- }
- }
+ if (srcFile.lastModified() > destFile.lastModified()) {
+ try {
+ project.copyFile(srcFile, destFile);
+ } catch (IOException ioe) {
+ String msg = "Error copying file: " + srcFile.getAbsolutePath()
+ + " due to " + ioe.getMessage();
+ throw new BuildException(msg);
+ }
+ }
}
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/Filter.java b/src/main/org/apache/tools/ant/taskdefs/Filter.java
new file mode 100644
index 000000000..35e4847f6
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/Filter.java
@@ -0,0 +1,81 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+package org.apache.tools.ant.taskdefs;
+
+import org.apache.tools.ant.*;
+
+/**
+ * This task set a token filter that is used by the file copy methods
+ * of the project to do token substitution.
+ *
+ * @author Stefano Mazzocchi stefano@apache.org
+ */
+public class Filter extends Task {
+
+ private String token;
+ private String value;
+
+ public void setToken(String token) {
+ this.token = token;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public void init() throws BuildException {
+ project.addFilter(token, value);
+ }
+}
diff --git a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
index 41b47e9a3..0b16038f8 100644
--- a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
+++ b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
@@ -60,8 +60,8 @@ import java.util.*;
import java.text.*;
/**
- * Task to convert text source files to local OS formatting conventions, as
- * well as repair text files damaged by misconfigured or misguided editors or
+ * Task to convert text source files to local OS formatting conventions, as
+ * well as repair text files damaged by misconfigured or misguided editors or
* file transfer programs.
*
* This task can take the following arguments:
@@ -210,16 +210,16 @@ public class FixCRLF extends MatchingTask {
if (!srcDir.exists()) {
throw new BuildException("srcdir does not exist!");
}
- if (!srcDir.isDirectory()) {
+ if (!srcDir.isDirectory()) {
throw new BuildException("srcdir is not a directory!");
}
if (destDir != null) {
if (!destDir.exists()) {
- throw new BuildException("destdir does not exist!");
+ throw new BuildException("destdir does not exist!");
+ }
+ if (!destDir.isDirectory()) {
+ throw new BuildException("destdir is not a directory!");
}
- if (!destDir.isDirectory()) {
- throw new BuildException("destdir is not a directory!");
- }
}
// log options used
@@ -231,134 +231,137 @@ public class FixCRLF extends MatchingTask {
DirectoryScanner ds = super.getDirectoryScanner(srcDir);
String[] files = ds.getIncludedFiles();
-try {
-
- for (int i = 0; i < files.length; i++) {
- File srcFile = new File(srcDir, files[i]);
-
- // read the contents of the file
- int count = (int)srcFile.length();
- byte indata[] = new byte[count];
- try {
- FileInputStream inStream = new FileInputStream(srcFile);
- inStream.read(indata);
- inStream.close();
- } catch (IOException e) {
- throw new BuildException(e);
- }
- // count the number of cr, lf, and tab characters
- int cr = 0;
- int lf = 0;
- int tab = 0;
+ try {
+ for (int i = 0; i < files.length; i++) {
+ File srcFile = new File(srcDir, files[i]);
+
+ // read the contents of the file
+ int count = (int)srcFile.length();
+ byte indata[] = new byte[count];
+ try {
+ FileInputStream inStream = new FileInputStream(srcFile);
+ inStream.read(indata);
+ inStream.close();
+ } catch (IOException e) {
+ throw new BuildException(e);
+ }
- for (int k=0; k0) && (indata[count-1] == 0x1A));
-
- // log stats (before fixes)
- project.log(srcFile + ": size=" + count + " cr=" + cr +
- " lf=" + lf + " tab=" + tab + " eof=" + eof,
- "fixcrlf", project.MSG_VERBOSE);
-
- // determine the output buffer size (slightly pessimisticly)
- int outsize = count;
- if (addcr != 0) outsize-=cr;
- if (addcr == +1) outsize+=lf;
- if (addtab == -1) outsize+=tab*7;
- if (ctrlz == +1) outsize+=1;
-
- // copy the data
- byte outdata[] = new byte[outsize];
- int o = 0; // output offset
- int line = o; // beginning of line
- int col = 0; // desired column
-
- for (int k=0; k0) && (indata[count-1] == 0x1A));
+
+ // log stats (before fixes)
+ project.log(srcFile + ": size=" + count + " cr=" + cr +
+ " lf=" + lf + " tab=" + tab + " eof=" + eof,
+ "fixcrlf", project.MSG_VERBOSE);
+
+ // determine the output buffer size (slightly pessimisticly)
+ int outsize = count;
+ if (addcr != 0) outsize-=cr;
+ if (addcr == +1) outsize+=lf;
+ if (addtab == -1) outsize+=tab*7;
+ if (ctrlz == +1) outsize+=1;
+
+ // copy the data
+ byte outdata[] = new byte[outsize];
+ int o = 0; // output offset
+ int line = o; // beginning of line
+ int col = 0; // desired column
+
+ for (int k=0; k0 && o+10 && o+12 && outdata[o-1]==0x0A && outdata[o-2]==0x1A) o--;
- if (o>1 && outdata[o-1]==0x1A) o--;
- }
+ // add or remove an eof character as required
+ if (ctrlz == +1) {
+ if (outdata[o-1]!=0x1A) outdata[o++]=0x1A;
+ } else if (ctrlz == -1) {
+ if (o>2 && outdata[o-1]==0x0A && outdata[o-2]==0x1A) o--;
+ if (o>1 && outdata[o-1]==0x1A) o--;
+ }
- // output the data
- try {
- File destFile = srcFile;
- if (destDir != null) destFile = new File(destDir, files[i]);
- FileOutputStream outStream = new FileOutputStream(destFile);
- outStream.write(outdata,0,o);
- outStream.close();
- } catch (IOException e) {
- throw new BuildException(e);
- }
+ // output the data
+ try {
+ File destFile = srcFile;
+ if (destDir != null) destFile = new File(destDir, files[i]);
+ FileOutputStream outStream = new FileOutputStream(destFile);
+ outStream.write(outdata,0,o);
+ outStream.close();
+ } catch (IOException e) {
+ throw new BuildException(e);
+ }
- } /* end for */
-} catch (Exception e) {e.printStackTrace(); throw new BuildException(e); }
+ } /* end for */
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new BuildException(e);
+ }
}
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/Java.java b/src/main/org/apache/tools/ant/taskdefs/Java.java
index 220765a92..37b18ecfc 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Java.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Java.java
@@ -62,7 +62,7 @@ import java.util.*;
* This task acts as a loader for java applications but allows to use the same JVM
* for the called application thus resulting in much faster operation.
*
- * @author Stefano Mazzocchi stefano@apache.org
+ * @author Stefano Mazzocchi stefano@apache.org
*/
public class Java extends Exec {
@@ -87,7 +87,7 @@ public class Java extends Exec {
StringBuffer b = new StringBuffer();
b.append("java ");
if (classpath != null) {
- b.append("-cp ");
+ b.append("-classpath ");
b.append(classpath);
b.append(" ");
}
@@ -114,7 +114,7 @@ public class Java extends Exec {
* Set the classpath to be used for this compilation.
*/
public void setClasspath(String s) {
- this.classpath = Project.translatePath(s);
+ this.classpath = project.translatePath(s);
}
/**
diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java
index da2d8440f..9e5038e30 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Javac.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java
@@ -118,7 +118,7 @@ public class Javac extends MatchingTask {
* Set the classpath to be used for this compilation.
*/
public void setClasspath(String classpath) {
- compileClasspath = Project.translatePath(classpath);
+ compileClasspath = project.translatePath(classpath);
}
/**
@@ -126,7 +126,7 @@ public class Javac extends MatchingTask {
* against.
*/
public void setBootclasspath(String bootclasspath) {
- this.bootclasspath = Project.translatePath(bootclasspath);
+ this.bootclasspath = project.translatePath(bootclasspath);
}
/**
@@ -134,7 +134,7 @@ public class Javac extends MatchingTask {
* compilation.
*/
public void setExtdirs(String extdirs) {
- this.extdirs = Project.translatePath(extdirs);
+ this.extdirs = project.translatePath(extdirs);
}
/**
@@ -228,7 +228,7 @@ public class Javac extends MatchingTask {
String fromFile = (String)enum.nextElement();
String toFile = (String)filecopyList.get(fromFile);
try {
- copyFile(fromFile, toFile);
+ project.copyFile(fromFile, toFile);
} catch (IOException ioe) {
String msg = "Failed to copy " + fromFile + " to " + toFile
+ " due to " + ioe.getMessage();
diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
index 60b5955e7..47ec0f81a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
@@ -160,10 +160,10 @@ public class Javadoc extends Exec {
old = Project.toBoolean(src);
}
public void setClasspath(String src) {
- classpath = Project.translatePath(src);
+ classpath = project.translatePath(src);
}
public void setBootclasspath(String src) {
- bootclasspath = Project.translatePath(src);
+ bootclasspath = project.translatePath(src);
}
public void setExtdirs(String src) {
extdirs = src;
diff --git a/src/main/org/apache/tools/ant/taskdefs/KeySubst.java b/src/main/org/apache/tools/ant/taskdefs/KeySubst.java
index 6ed03e99b..cf98dec77 100644
--- a/src/main/org/apache/tools/ant/taskdefs/KeySubst.java
+++ b/src/main/org/apache/tools/ant/taskdefs/KeySubst.java
@@ -76,6 +76,7 @@ public class KeySubst extends Task {
Do the execution.
*/
public void execute() throws BuildException {
+ project.log("!! KeySubst is deprecated. Use Filter + CopyDir instead. !!");
project.log("Performing Substitions");
if ( source == null || dest == null ) {
project.log("Source and destinations must not be null");
diff --git a/src/main/org/apache/tools/ant/taskdefs/Rmic.java b/src/main/org/apache/tools/ant/taskdefs/Rmic.java
index 8e17fea8d..a9558dcdb 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Rmic.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Rmic.java
@@ -103,7 +103,7 @@ public class Rmic extends Task {
* Set the classpath to be used for this compilation.
*/
public void setClasspath(String classpath) {
- compileClasspath = Project.translatePath(classpath);
+ compileClasspath = project.translatePath(classpath);
}
public void execute() throws BuildException {
@@ -144,7 +144,7 @@ public class Rmic extends Task {
File oldStubFile = new File(baseFile, stubFileName);
File newStubFile = new File(sourceBaseFile, stubFileName);
try {
- copyFile(oldStubFile, newStubFile);
+ project.copyFile(oldStubFile, newStubFile);
oldStubFile.delete();
} catch (IOException ioe) {
String msg = "Failed to copy " + oldStubFile + " to " +
@@ -156,7 +156,7 @@ public class Rmic extends Task {
File oldSkelFile = new File(baseFile, skelFileName);
File newSkelFile = new File(sourceBaseFile, skelFileName);
try {
- copyFile(oldSkelFile, newSkelFile);
+ project.copyFile(oldSkelFile, newSkelFile);
oldSkelFile.delete();
} catch (IOException ioe) {
String msg = "Failed to copy " + oldSkelFile + " to " +
diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties
index 66e2bc65d..055feb169 100644
--- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties
+++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties
@@ -13,7 +13,6 @@ get=org.apache.tools.ant.taskdefs.Get
expand=org.apache.tools.ant.taskdefs.Expand
echo=org.apache.tools.ant.taskdefs.Echo
javadoc=org.apache.tools.ant.taskdefs.Javadoc
-keysubst=org.apache.tools.ant.taskdefs.KeySubst
zip=org.apache.tools.ant.taskdefs.Zip
gzip=org.apache.tools.ant.taskdefs.GZip
replace=org.apache.tools.ant.taskdefs.Replace
@@ -25,7 +24,9 @@ ant=org.apache.tools.ant.taskdefs.Ant
exec=org.apache.tools.ant.taskdefs.Exec
tar=org.apache.tools.ant.taskdefs.Tar
available=org.apache.tools.ant.taskdefs.Available
+filter=org.apache.tools.ant.taskdefs.Filter
fixcrlf=org.apache.tools.ant.taskdefs.FixCRLF
# deprecated ant tasks (kept for back compatibility)
javadoc2=org.apache.tools.ant.taskdefs.Javadoc
+keysubst=org.apache.tools.ant.taskdefs.KeySubst