Browse Source

Added a type attribute to <execon> and <chmod>. It can take the values

"file", "dir" and "both" and deteremines, whether the task should work
on plain files only (the default), directories only or both.
Suggested by:	Peter Donald <donaldp@mad.scientist.com>,
                Kitching Simon <Simon.Kitching@orange.ch>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267969 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
982db474ca
2 changed files with 50 additions and 7 deletions
  1. +20
    -4
      docs/index.html
  2. +30
    -3
      src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java

+ 20
- 4
docs/index.html View File

@@ -1059,6 +1059,14 @@ elements.</p>
<code>chmod</code> command. Defaults to true.</td> <code>chmod</code> command. Defaults to true.</td>
<td valign="top" align="center">No</td> <td valign="top" align="center">No</td>
</tr> </tr>
<tr>
<td valign="top">type</td>
<td valign="top">One of <em>file</em>, <em>dir</em> or
<em>both</em>. If set to <em>file</em>, only the permissions of
plain files are going to be changed. If set to <em>dir</em>, only
the directories are considered.</td>
<td align="center" valign="top">No, default is <em>file</em></td>
</tr>
</table> </table>
<h3>Examples</h3> <h3>Examples</h3>
<blockquote> <blockquote>
@@ -1548,10 +1556,10 @@ system command.</p>
<p>Executes a system command. When the <i>os</i> attribute is specified, then <p>Executes a system command. When the <i>os</i> attribute is specified, then
the command is only executed when Ant is run on one of the specified operating the command is only executed when Ant is run on one of the specified operating
systems.</p> systems.</p>
<p>The files of a number of <a href="#fileset">FileSet</a>s are passed
as arguments to the system command. At least one nested
<code>&lt;fileset&gt;</code> or <code>&lt;filesetref&gt;</code> is
required.</p>
<p>The files and/or directories of a number of <a
href="#fileset">FileSet</a>s are passed as arguments to the system
command. At least one nested <code>&lt;fileset&gt;</code> or
<code>&lt;filesetref&gt;</code> is required.</p>
<h3>Parameters</h3> <h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0"> <table border="1" cellpadding="2" cellspacing="0">
<tr> <tr>
@@ -1601,6 +1609,14 @@ required.</p>
once for every file.</td> once for every file.</td>
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>
</tr> </tr>
<tr>
<td valign="top">type</td>
<td valign="top">One of <em>file</em>, <em>dir</em> or
<em>both</em>. If set to <em>file</em>, only the names of plain
files will be sent to the command. If set to <em>dir</em>, only
the names of directories are considered.</td>
<td align="center" valign="top">No, default is <em>file</em></td>
</tr>
</table> </table>
<h3>Parameters specified as nested elements</h3> <h3>Parameters specified as nested elements</h3>
<h4>fileset and filesetref</h4> <h4>fileset and filesetref</h4>


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

@@ -71,6 +71,7 @@ public class ExecuteOn extends ExecTask {


protected Vector filesets = new Vector(); protected Vector filesets = new Vector();
private boolean parallel = false; private boolean parallel = false;
protected String type = "file";


/** /**
* Adds a set of files (nested fileset attribute). * Adds a set of files (nested fileset attribute).
@@ -93,6 +94,13 @@ public class ExecuteOn extends ExecTask {
this.parallel = parallel; this.parallel = parallel;
} }


/**
* Shall the command work only on files, directories or both?
*/
public void setType(FileDirBoth type) {
this.type = type.getValue();
}

protected void checkConfiguration() { protected void checkConfiguration() {
super.checkConfiguration(); super.checkConfiguration();
if (filesets.size() == 0) { if (filesets.size() == 0) {
@@ -122,9 +130,18 @@ public class ExecuteOn extends ExecTask {
} }
DirectoryScanner ds = fs.getDirectoryScanner(project); DirectoryScanner ds = fs.getDirectoryScanner(project);
String[] s = ds.getIncludedFiles();
for (int j=0; j<s.length; j++) {
v.addElement(new File(fs.getDir(), s[j]).getAbsolutePath());
if (!"dir".equals(type)) {
String[] s = ds.getIncludedFiles();
for (int j=0; j<s.length; j++) {
v.addElement(new File(fs.getDir(), s[j]).getAbsolutePath());
}
}

if (!"file".equals(type)) {
String[] s = ds.getIncludedDirectories();
for (int j=0; j<s.length; j++) {
v.addElement(new File(fs.getDir(), s[j]).getAbsolutePath());
}
} }
} }


@@ -173,4 +190,14 @@ public class ExecuteOn extends ExecTask {
} }
} }


/**
* Enumerated attribute with the values "file", "dir" and "both"
* for the type attribute.
*/
public static class FileDirBoth extends EnumeratedAttribute {
public String[] getValues() {
return new String[] {"file", "dir", "both"};
}
}

} }

Loading…
Cancel
Save