Browse Source

Add includesfile and excludesfile attributes to MatchingTask.

This adds the ability to keep the patterns for inclusion/exclusion
separate from the buildfile - increasing the readability in some
difficult cases.

The code is based on the patch submitted by Aaron on 2000/05/24 with
some modifications.

Submitted by:	Aaron Knauf <AaronK@geniesystems.com>
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267703 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
3dd76dec2e
2 changed files with 250 additions and 31 deletions
  1. +176
    -25
      docs/index.html
  2. +74
    -6
      src/main/org/apache/tools/ant/taskdefs/MatchingTask.java

+ 176
- 25
docs/index.html View File

@@ -375,6 +375,10 @@ time:</p>
</ul>
<p>When both inclusion and exclusion are used, only files/directories that match
the include patterns, and don't match the exclude patterns are used.</p>
<p>Patterns can be specified inside the buildfile via task attributes or
nested elements and via external files. Each line of the external file
is taken as pattern that is added to the list of include or exclude
patterns.</p>
<h3>Patterns</h3>
<p>As described earlier, patterns are used for the inclusion and exclusion.
These patterns look very much like the patterns used in DOS and UNIX:</p>
@@ -617,9 +621,9 @@ UNIX system.</p>
<h3>Description</h3>
<p>Copies a directory tree from the source to the destination.</p>
<p>It is possible to refine the set of files that are being copied. This can be
done with the <i>includes</i>, <i>excludes</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> attribute is used to specify
done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
the files you want to have excluded. This is also done with patterns. And
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
@@ -660,12 +664,24 @@ this attribute has been replaced by the <i>excludes</i> attribute.</p>
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">comma separated list of patterns of files that must be
excluded. No files (except default excludes) are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">indicates whether default excludes should be used or not
@@ -806,9 +822,9 @@ repository pointed to by the cvsRoot attribute, and stores the files in &quot;${
<p>Deletes either a single file or
all files in a specified directory and its sub-directories.</p>
<p>It is possible to refine the set of files that are being deleted. This can be
done with the <i>includes</i>, <i>excludes</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> attribute you specify the files you want to
have included in the deletion process by using patterns. The <i>exclude</i> attribute is used to specify
done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
have included in the deletion process by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
the files you want to have excluded from the deletion process. This is also done with patterns. And
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
@@ -838,12 +854,24 @@ relative to the <i>dir</i> directory.</p>
and any sub-directories are deleted when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">Comma separated list of patterns of files that must be
excluded from the deletion list. No files (except default excludes) are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">Indicates whether default excludes should be used or not
@@ -1012,7 +1040,16 @@ with <i>2000.</i></p>
<h2><a name="fixcrlf">FixCRLF</a></h2>
<h3>Description</h3>
<p>Adjusts a text file to local.</p>
<p>The <i>basedir</i> attribute is the reference directory from where to jar.</p>
<p>It is possible to refine the set of files that are being adjusted. This can be
done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
the files you want to have excluded. This is also done with patterns. And
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
href="#directorybasedtasks">directory based tasks</a>, on how the
inclusion/exclusion of files works, and how to write patterns. The patterns are
relative to the <i>src</i> directory.</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
@@ -1037,12 +1074,24 @@ with <i>2000.</i></p>
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">comma separated list of patterns of files that must be
excluded. No files (except default excludes) are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">indicates whether default excludes should be used or not
@@ -1246,9 +1295,9 @@ subdir is a directory).</p>
<p>Jars a set of files.</p>
<p>The <i>basedir</i> attribute is the reference directory from where to jar.</p>
<p>It is possible to refine the set of files that are being jarred. This can be
done with the <i>includes</i>, <i>excludes</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> attribute is used to specify
done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
the files you want to have excluded. This is also done with patterns. And
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
@@ -1308,12 +1357,24 @@ attribute are just names, they do not contain any path information!</p>
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">comma separated list of patterns of files that must be
excluded. No files (except default excludes) are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">indicates whether default excludes should be used or not
@@ -1427,9 +1488,9 @@ classpath.</p>
<p>The directory structure of the source tree should follow the package
hierarchy.</p>
<p>It is possible to refine the set of files that are being compiled/copied.
This can be done with the <i>includes</i>, <i>excludes</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> attribute is used to specify
This can be done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
the files you want to have excluded. This is also done with patterns. And
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
@@ -1469,12 +1530,24 @@ relative to the <i>srcdir</i> directory.</p>
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">comma separated list of patterns of files that must be
excluded. No files (except default excludes) are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">indicates whether default excludes should be used or not
@@ -2165,9 +2238,9 @@ compiled files will be stored in the directory <code>${build}/classes</code>.</p
<p>Creates a tar archive.</p>
<p>The <i>basedir</i> attribute is the reference directory from where to tar.</p>
<p>It is possible to refine the set of files that are being tarred. This can be
done with the <i>includes</i>, <i>excludes</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> attribute is used to specify
done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
the files you want to have excluded. This is also done with patterns. And
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
@@ -2210,12 +2283,24 @@ task to come up with a .tar.gz package.</p>
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">comma separated list of patterns of files that must be
excluded. No files (except default excludes) are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">indicates whether default excludes should be used or not
@@ -2294,9 +2379,9 @@ initialization target.</p>
<p>This is useful for building views of XML based documentation,
or in generating code.</p>
<p>It is possible to refine the set of files that are being copied. This can be
done with the <i>includes</i>, <i>excludes</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> attribute is used to specify
done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
the files you want to have excluded. This is also done with patterns. And
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
@@ -2340,6 +2425,36 @@ Defaults to xslp or xalan (in that order), if one is found in your
class path</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">includes</td>
<td valign="top">comma separated list of patterns of files that must be
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">comma separated list of patterns of files that must be
excluded. No files (except default excludes) are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">indicates whether default excludes should be used or not
(&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
</table>
<h3>Examples</h3>
<blockquote>
@@ -2385,9 +2500,9 @@ carried from tarfile.</p>
<p>Creates a zipfile.</p>
<p>The <i>basedir</i> attribute is the reference directory from where to zip.</p>
<p>It is possible to refine the set of files that are being zipped. This can be
done with the <i>includes</i>, <i>excludes</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> attribute is used to specify
done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
the files you want to have excluded. This is also done with patterns. And
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
@@ -2447,12 +2562,24 @@ attribute are just names, they do not contain any path information!</p>
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">comma separated list of patterns of files that must be
excluded. No files (except default excludes) are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">indicates whether default excludes should be used or not
@@ -2590,10 +2717,10 @@ specific directory via parameters</p>
<p>The directory structure of the source tree should follow the package
hierarchy.</p>
<p>It is possible to refine the set of files that are being compiled/copied.
This can be done with the <i>includes</i>, <i>excludes</i> and
<i>defaultexcludes</i> attributes. With the <i>includes</i> attribute you
This can be done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and
<i>defaultexcludes</i> attributes. With the <i>includes</i> or <i>includesfile</i> attribute you
specify the files you want to have included by using patterns. The
<i>exclude</i> attribute is used to specify the files you want to have
<i>exclude</i> or <i>excludesfile</i> attribute is used to specify the files you want to have
excluded. This is also done with patterns. And finally with the
<i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
@@ -2680,6 +2807,12 @@ patterns are relative to the <i>srcDir</i> directory.</p>
omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">explicit</td>
<td valign="top">Whether variables must be declared explicitly
@@ -2698,6 +2831,12 @@ patterns are relative to the <i>srcDir</i> directory.</p>
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">java</td>
<td valign="top">Whether the generated java code is produced</td>
@@ -2854,6 +2993,12 @@ patterns are relative to the <i>srcDir</i> directory.</p>
omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">fromExtention</td>
<td valign="top">The string that files must end in to be renamed</td>
@@ -2865,6 +3010,12 @@ patterns are relative to the <i>srcDir</i> directory.</p>
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">replace</td>
<td valign="top">Whether the file being renamed to should be


+ 74
- 6
src/main/org/apache/tools/ant/taskdefs/MatchingTask.java View File

@@ -107,18 +107,14 @@ public abstract class MatchingTask extends Task {
* add a name entry on the include list
*/
public NameEntry createInclude() {
NameEntry result = new NameEntry();
includeList.addElement(result);
return result;
return addPatternToList(includeList);
}
/**
* add a name entry on the exclude list
*/
public NameEntry createExclude() {
NameEntry result = new NameEntry();
excludeList.addElement(result);
return result;
return addPatternToList(excludeList);
}

/**
@@ -239,4 +235,76 @@ public abstract class MatchingTask extends Task {
ds.scan();
return ds;
}

/**
* add a name entry to the given list
*/
private NameEntry addPatternToList(Vector list) {
NameEntry result = new NameEntry();
list.addElement(result);
return result;
}

/**
* Reads path matching patterns from a file and adds them to the
* includes or excludes list (as appropriate).
*/
private void readPatterns(File patternfile, Vector patternlist) {

try {
// Get a FileReader
BufferedReader patternReader =
new BufferedReader(new FileReader(patternfile));
// Create one NameEntry in the appropriate pattern list for each
// line in the file.
String line = patternReader.readLine();
while (line != null) {
if (line.length() > 0) {
addPatternToList(patternlist).setName(line);
}
line = patternReader.readLine();
}
} catch(IOException ioe) {
project.log("An error occured while reading from pattern file: "
+ patternfile, Project.MSG_ERR);
}
}

/**
* Sets the name of the file containing the includes patterns.
*
* @param includesfile A string containing the filename to fetch
* the include patterns from.
*/
public void setIncludesfile(String includesfile) {
if (includesfile != null && includesfile.length() > 0) {
File incl = project.resolveFile(includesfile);
if (!incl.exists()) {
project.log("Includesfile "+includesfile+" not found.",
Project.MSG_ERR);
} else {
readPatterns(incl, includeList);
}
}
}

/**
* Sets the name of the file containing the includes patterns.
*
* @param excludesfile A string containing the filename to fetch
* the include patterns from.
*/
public void setExcludesfile(String excludesfile) {
if (excludesfile != null && excludesfile.length() > 0) {
File excl = project.resolveFile(excludesfile);
if (!excl.exists()) {
project.log("Excludesfile "+excludesfile+" not found.",
Project.MSG_ERR);
} else {
readPatterns(excl, excludeList);
}
}
}

}

Loading…
Cancel
Save