diff --git a/docs/index.html b/docs/index.html
index d46a634b9..b80d23c62 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -620,8 +620,18 @@ if the org.whatever.Myclass is found in Ant's classpath.
Description
-Changes the permissions of a file. Right now it has efect only under Unix.
+
Changes the permissions of a file or all files inside a specified directory. Right now it has efect only under Unix.
The permissions are also UNIX style, like the argument for the chmod command.
+It is possible to refine the set of files whose permissions are changed. This can be
+done with the includes, includesfile, excludes, excludesfile and defaultexcludes
+attributes. With the includes or includesfile attribute you specify the files you want to
+have included by using patterns. The exclude or excludesfile attribute is used to specify
+the files you want to have excluded. This is also done with patterns. And
+finally with the defaultexcludes attribute, you can specify whether you
+want to use default exclusions or not. See the section on directory based tasks, on how the
+inclusion/exclusion of files works, and how to write patterns. The patterns are
+relative to the dir directory.
Parameters
@@ -629,24 +639,72 @@ The permissions are also UNIX style, like the argument for the chmod command.Description
Required |
+
+ file |
+ the file or single directory of which the permissions
+ must be changed. |
+ exactly one of the two |
+
+
+ dir |
+ the directory which holds the files whose permissions
+ must be changed. |
+
src |
- the file of which the permissions must be changed. |
- Yes |
+ the file or single directory of which the permissions
+ must be changed (deprecated, use file instead). |
+ No |
perm |
the new permissions. |
Yes |
+
+ includes |
+ comma separated list of patterns of files that must be
+ included. All files are included when omitted. |
+ No |
+
+
+ includesfile |
+ the name of a file. Each line of this file is
+ taken to be an include pattern |
+ No |
+
+
+ excludes |
+ comma separated list of patterns of files that must be
+ excluded. No files (except default excludes) are excluded when omitted. |
+ No |
+
+
+ excludesfile |
+ the name of a file. Each line of this file is
+ taken to be an exclude pattern |
+ No |
+
+
+ defaultexcludes |
+ indicates whether default excludes should be used or not
+ ("yes"/"no"). Default excludes are used when omitted. |
+ No |
+
Examples
- <chmod src="${dist}/start.sh" perm="ugo+rx"
+ <chmod file="${dist}/start.sh" perm="ugo+rx"
/>
makes the "start.sh" file readable and executable for anyone on a
UNIX system.
+
+ <chmod dir="${dist}/bin" perm="ugo+rx" includes="**/*.sh" />
+
+
+makes all ".sh" files below ${dist}/bin
+readable and executable for anyone on a UNIX system.
Description
diff --git a/src/main/org/apache/tools/ant/taskdefs/Chmod.java b/src/main/org/apache/tools/ant/taskdefs/Chmod.java
index d092b4e03..5595f9879 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Chmod.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Chmod.java
@@ -60,33 +60,66 @@ import java.io.*;
import java.util.*;
/**
- *
+ * Chmod equivalent for unix-like environments.
*
* @author costin@eng.sun.com
+ * @author Mariusz Nowostawski (Marni) mnowostawski@infoscience.otago.ac.nz
*/
-public class Chmod extends Task {
+public class Chmod extends MatchingTask {
- private File srcFile;
+ private File srcFile; //if we want to chmod a single file or dir
+ private File srcDir; //if we want to chmod a list of files
private String mod;
+ public void setFile(String src) {
+ srcFile = project.resolveFile(src);
+ }
+
+ public void setDir(String src) {
+ srcDir = project.resolveFile(src);
+ }
+
public void setSrc(String src) {
- srcFile = project.resolveFile(src);
+ project.log("The src attribute is deprecated. " +
+ "Please use the file attribute.",
+ Project.MSG_WARN);
+ setFile(src);
}
public void setPerm(String perm) {
- mod=perm;
+ mod=perm;
}
public void execute() throws BuildException {
- try {
- // XXX if OS=unix
- if (System.getProperty("path.separator").equals(":") &&
- !System.getProperty("os.name").startsWith("Mac"))
- Runtime.getRuntime().exec("chmod " + mod + " " + srcFile );
- } catch (IOException ioe) {
- // ignore, but warn
- System.out.println("Error chmod" + ioe.toString() );
- }
+ try {
+ // XXX if OS=unix
+ if (System.getProperty("path.separator").equals(":") &&
+ !System.getProperty("os.name").startsWith("Mac")) {
+
+ if (srcFile != null && srcDir == null) {
+ chmod(srcFile.toString());
+ } else if(srcFile == null && srcDir == null) {
+ project.log("The attribute 'file' or 'dir' needs to be set.", Project.MSG_WARN);
+ throw new BuildException("Required attribute not set in Chmod", location);
+ } else if(srcFile == null && srcDir != null) {
+
+ DirectoryScanner ds = getDirectoryScanner(srcDir);
+ String[] files = ds.getIncludedFiles();
+
+ for (int i = 0; i < files.length; i++) {
+ chmod(files[i]);
+ }
+ }
+ }
+ } catch (IOException ioe) {
+ // ignore, but warn
+ project.log("Error in Chmod " + ioe.toString() , Project.MSG_WARN);
+ }
+ }
+
+
+ private void chmod(String file) throws BuildException, IOException {
+ Runtime.getRuntime().exec("chmod " + mod + " " + file);
}
}