Browse Source

Several changes:

1)  restructured Project and Task: copyFile should be a project
method rather than a task method for good OO patterns. Well,
actually they should be target-granular but we'll see.

2)  patched all the necessary files to make the above work

3)  removed some unused methods (setAttributes())

4)  added the Filter task that addes token filtering capabilities
to all the copyFile operations. This works more or less as a
superstructure to Replace and KeySubst but automatically and
inherited by all the tasks that use copyFile() methods.

5)  indicated KeySubst as deprecated

6) updated docs to reflect this new behavior

NOTE: behavior is _totally_ back compatible if you don't
specify any <filter> tag.

NOTE2: nothing is carved in stone. If you don't like something
you're welcome to propose fixes.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267604 13f79535-47bb-0310-9956-ffa450edef68
master
Stefano Mazzocchi 25 years ago
parent
commit
ae16bb711b
15 changed files with 474 additions and 263 deletions
  1. +63
    -11
      docs/index.html
  2. +160
    -30
      src/main/org/apache/tools/ant/Project.java
  3. +1
    -0
      src/main/org/apache/tools/ant/ProjectHelper.java
  4. +2
    -8
      src/main/org/apache/tools/ant/Target.java
  5. +5
    -57
      src/main/org/apache/tools/ant/Task.java
  6. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/Copydir.java
  7. +17
    -17
      src/main/org/apache/tools/ant/taskdefs/Copyfile.java
  8. +81
    -0
      src/main/org/apache/tools/ant/taskdefs/Filter.java
  9. +127
    -124
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  10. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/Java.java
  11. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  12. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  13. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/KeySubst.java
  14. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/Rmic.java
  15. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/defaults.properties

+ 63
- 11
docs/index.html View File

@@ -11,12 +11,14 @@
<p>by</p>
<!-- Names are in alphabetical order, on last name -->
<ul>
<li>James Duncan Davison (<a href="mailto:(duncan@x180.com">duncan@x180.com</a>)</li>
<li>Arnout J. Kuiper (<a href="mailto:(ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>)</li>
<li>Stefano Mazzocchi (<a href="mailto:(stefano@apache.org">stefano@apache.org</a>)</li>
<li>Sam Ruby (<a href="mailto:(rubys@us.ibm.com">rubys@us.ibm.com</a>)</li>
<li>James Duncan Davison (<a href="mailto:duncan@x180.com">duncan@x180.com</a>)</li>
<li>Arnout J. Kuiper (<a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>)</li>
<li>Stefano Mazzocchi (<a href="mailto:stefano@apache.org">stefano@apache.org</a>)</li>
<li>Sam Ruby (<a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>)</li>
</ul>
<p>Version 1.0.5 - 2000/02/12</p>

<p>Version 1.0.6 - 2000/02/13</p>

<hr>
<h2>Table of Contents</h2>
<ul>
@@ -296,6 +298,22 @@ task attributes. This is done by placing the property name between
<p>If there is a property called &quot;builddir&quot; with the value
&quot;build&quot;, then this could be used in an attribute like this: &quot;${builddir}/classes&quot;.
This is resolved as &quot;build/classes&quot;.</p>
<h3>Token Filters</h3>
<p>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 <a href="#filter">filter task</a>. 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 <i>filtered</i> and
each occurrency of the specified token will be replaced.</p>
<p>Since this can be a very harmful behavior, the tokens in the files <b>must</b>
be of the form<i> @token@</i> where <i>token</i> 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.</p>
<p>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.</p>
<h3>Examples</h3>
<blockquote>
<pre>&lt;project name=&quot;foo&quot; default=&quot;dist&quot; basedir=&quot;.&quot;&gt;
@@ -303,6 +321,8 @@ This is resolved as &quot;build/classes&quot;.</p>
&lt;tstamp/&gt;
&lt;property name=&quot;build&quot; value=&quot;build&quot; /&gt;
&lt;property name=&quot;dist&quot; value=&quot;dist&quot; /&gt;
&lt;filter token=&quot;version&quot; value=&quot;1.0.3&quot; /&gt;
&lt;filter token=&quot;year&quot; value=&quot;2000&quot; /&gt;
&lt;/target&gt;

&lt;target name=&quot;prepare&quot; depends=&quot;init&quot;&gt;
@@ -429,6 +449,7 @@ but excludes all &quot;*.gif&quot; files from the copy.</p>
<li><a href="#echo">Echo</a></li>
<li><a href="#exec">Exec</a></li>
<li><a href="#expand">Expand</a></li>
<li><a href="#filter">Filter</a></li>
<li><a href="#get">Get</a></li>
<li><a href="#gzip">GZip</a></li>
<li><a href="#fixcrlf">FixCRLF</a></li>
@@ -842,6 +863,37 @@ systems.</p>
/&gt;</code></p>
</blockquote>
<hr>
<h2><a name="filter">Filter</a></h2>
<h3>Description</h3>
<p>Sets a token filter for this project. Token filters are used by all tasks
that perform file copying operations through the Project commodity methods.</p>
<p>Note: the token string must not contain the separators chars (@).</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">token</td>
<td valign="top">the token string without @</td>
<td align="center" valign="top">Yes</td>
</tr>
<tr>
<td valign="top">value</td>
<td valign="top">the string that should be put to replace the token when the
file is copied</td>
<td align="center" valign="top">Yes</td>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;filter token=&quot;year&quot; value=&quot;2000&quot; /&gt;
&lt;copydir src=&quot;${src.dir}&quot; dest=&quot;${dest.dir}&quot;/&gt;</pre>
<p>will copy recursively all the files from the <i>src.dir</i> directory into
the <i>dest.dir</i> directory replacing all the occurencies of the string <i>@year@</i>
with <i>2000.</i></p>
<hr>
<h2><a name="get">Get</a></h2>
<h3>Description</h3>
<p>Gets a file from an URL. When the verbose option is &quot;on&quot;, this task
@@ -957,7 +1009,7 @@ archive with http/ftp.</p>
</tr>
<tr>
<td valign="top">tab</td>
<td valign="top">Specifies how tab characters are to be handled. Valid
<td valign="top">Specifies how tab characters are to be handled. Valid
values for this property are:
<ul>
<li>add: convert sequences of spaces which span a tab stop to tabs
@@ -973,10 +1025,10 @@ archive with http/ftp.</p>
</tr>
<tr>
<td valign="top">eof</td>
<td valign="top">Specifies how DOS end of file (control-Z) characters are
<td valign="top">Specifies how DOS end of file (control-Z) characters are
to be handled. Valid values for this property are:
<ul>
<li>add: ensure that there is an EOF character at the end of the file
<li>add: ensure that there is an EOF character at the end of the file
<li>asis: leave EOF characters alone
<li>remove: remove any EOF character found at the end
</ul>
@@ -993,13 +1045,13 @@ archive with http/ftp.</p>
includes=&quot;**/*.sh&quot;
/&gt;</pre>
<p>Removes carriage return and eof characters from the shell scripts. Tabs and
spaces are left as is.
spaces are left as is.
<pre> &lt;fixcrlf srcdir=&quot;${src}&quot;
cr="add"
includes=&quot;**/*.bat&quot;
/&gt;</pre>
<p>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.</p>
<pre> &lt;fixcrlf srcdir=&quot;${src}&quot;
@@ -1007,7 +1059,7 @@ DOS systems, and are removed if run on Unix systems.</p>
includes=&quot;**/Makefile&quot;
/&gt;</pre>
<p>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.</p>
<pre> &lt;fixcrlf srcdir=&quot;${src}&quot;


+ 160
- 30
src/main/org/apache/tools/ant/Project.java View File

@@ -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 <a href="mailto:jon@clearink.com">jon@clearink.com</a>
*/
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


+ 1
- 0
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -227,6 +227,7 @@ public class ProjectHelper {
NamedNodeMap nodeMap = element.getAttributes();
configureTask(project, task, nodeMap);
task.init();
task.setTarget(target);
target.addTask(task);
}
}


+ 2
- 8
src/main/org/apache/tools/ant/Target.java View File

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


+ 5
- 57
src/main/org/apache/tools/ant/Task.java View File

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


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/Copydir.java View File

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


+ 17
- 17
src/main/org/apache/tools/ant/taskdefs/Copyfile.java View File

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

+ 81
- 0
src/main/org/apache/tools/ant/taskdefs/Filter.java View File

@@ -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
* <http://www.apache.org/>.
*/

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 <a href="mailto:stefano@apache.org">stefano@apache.org</a>
*/
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);
}
}

+ 127
- 124
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -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.
* <p>
* 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; k<count; k++) {
byte c = indata[k];
if (c == '\r') cr++;
if (c == '\n') lf++;
if (c == '\t') tab++;
}
// count the number of cr, lf, and tab characters
int cr = 0;
int lf = 0;
int tab = 0;

// check for trailing eof
boolean eof = ((count>0) && (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; k<count; k++) {
switch (indata[k]) {
case ' ':
// advance column
if (addtab == 0) outdata[o++]=(byte)' ';
col++;
break;

case '\t':
if (addtab == 0) {
// treat like any other character
outdata[o++]=(byte)'\t';
col++;
} else {
// advance column to next tab stop
col = (col|7)+1;
}
break;

case '\r':
if (addcr == 0) {
// treat like any other character
outdata[o++]=(byte)'\r';
for (int k=0; k<count; k++) {
byte c = indata[k];
if (c == '\r') cr++;
if (c == '\n') lf++;
if (c == '\t') tab++;
}

// check for trailing eof
boolean eof = ((count>0) && (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; k<count; k++) {
switch (indata[k]) {
case ' ':
// advance column
if (addtab == 0) outdata[o++]=(byte)' ';
col++;
}
break;

case '\n':
// start a new line (optional CR followed by LF)
if (addcr == +1) outdata[o++]=(byte)'\r';
outdata[o++]=(byte)'\n';
line=o;
col=0;
break;

default:
// add tabs if two or more spaces are required
if (addtab>0 && o+1<line+col) {
// determine logical column
int diff=o-line;

// add tabs until this column would be passed
// note: the start of line is adjusted to match
while ((diff|7)<col) {
break;

case '\t':
if (addtab == 0) {
// treat like any other character
outdata[o++]=(byte)'\t';
line-=7-(diff&7);
diff=o-line;
col++;
} else {
// advance column to next tab stop
col = (col|7)+1;
}
break;

case '\r':
if (addcr == 0) {
// treat like any other character
outdata[o++]=(byte)'\r';
col++;
}
break;

case '\n':
// start a new line (optional CR followed by LF)
if (addcr == +1) outdata[o++]=(byte)'\r';
outdata[o++]=(byte)'\n';
line=o;
col=0;
break;

default:
// add tabs if two or more spaces are required
if (addtab>0 && o+1<line+col) {
// determine logical column
int diff=o-line;

// add tabs until this column would be passed
// note: the start of line is adjusted to match
while ((diff|7)<col) {
outdata[o++]=(byte)'\t';
line-=7-(diff&7);
diff=o-line;
};
};
};

// space out to desired column
while (o<line+col) outdata[o++]=(byte)' ';
// space out to desired column
while (o<line+col) outdata[o++]=(byte)' ';

// append desired character
outdata[o++]=indata[k];
col++;
// append desired character
outdata[o++]=indata[k];
col++;
}
}
}

// 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--;
}
// 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);
}
}
}

+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/Java.java View File

@@ -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 <a href="mailto:stefano@pache.org">stefano@apache.org</a>
* @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
*/
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);
}
/**


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

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


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

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


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

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


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/Rmic.java View File

@@ -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 " +


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/defaults.properties View File

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

Loading…
Cancel
Save