diff --git a/WHATSNEW b/WHATSNEW
index 2caaec44c..125b042c0 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -23,6 +23,9 @@ Other changes:
* New file selectors
See the setpermissions task for a + platform independent alternative.
+Attribute | +Description | +Required | +
permissions | +The permissions to set as comma separated list of + names + of PosixFilePermission + values. | +No | +
mode | +The permissions to set as tradional Unix + three-digit octal number. | +No | +
failonerror | +Whether to stop the build if setting permissions + fails. | +No, defaults to true | +
Resource +Collections are used to select groups of resources.
+++<setpermissions mode="755"> + <file file="${dist}/start.sh"/> +</setpermissions> +
makes the "start.sh" file readable and executable for + anyone and in addition writable by the owner.
+++<setpermissions permissions="OWNER_READ,OWNER_WRITE,OWNER_EXECUTE,OTHERS_READ,OTHERS_EXECUTE,GROUP_READ,GROUP_EXECUTE"> + <file file="${dist}/start.sh"/> +</setpermissions> +
makes the "start.sh" file readable and executable for + anyone and in addition writable by the owner.
+ + diff --git a/manual/tasklist.html b/manual/tasklist.html index 003ba7591..b57c85136 100644 --- a/manual/tasklist.html +++ b/manual/tasklist.html @@ -147,6 +147,7 @@Changes the permissions of a collection of resources.
Synchronize two directory trees.
This task provides a subset of {@link Chmod}'s and {@link + * org.apache.tools.ant.taskdefs.optional.windows.Attrib}'s abilities + * in a platform independent way.
+ * + * @since Ant 1.10.0 + */ +public class SetPermissions extends Task { + private final SetString
value
+ */
+ public void setMode(String octalString) {
+ int mode = Integer.parseInt(octalString, 8);
+ permissions.addAll(PermissionUtils.permissionsFromMode(mode));
+ }
+
+ /**
+ * Set whether to fail when errors are encountered. If false, note errors
+ * to the output but keep going. Default is true.
+ * @param failonerror true or false.
+ */
+ public void setFailOnError(final boolean failonerror) {
+ this.failonerror = failonerror;
+ }
+
+ /**
+ * Adds a collection of resources to set permissions on.
+ * @param rc a resource collection
+ */
+ public void add(ResourceCollection rc) {
+ if (resources == null) {
+ resources = new Resources();
+ }
+ resources.add(rc);
+ }
+
+ public void execute() {
+ if (resources == null) {
+ throw new BuildException("At least one resource-collection is required");
+ }
+ for (Resource r : resources) {
+ try {
+ PermissionUtils.setPermissions(r, permissions);
+ } catch (IOException ioe) {
+ String msg = "Failed to set permissions on " + r + " due to "
+ + ioe.getMessage();
+ if (failonerror) {
+ throw new BuildException(msg, ioe);
+ } else {
+ log("Warning: " + msg, Project.MSG_ERR);
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties
index e1022fb83..06507a369 100644
--- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties
+++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties
@@ -91,6 +91,7 @@ replace=org.apache.tools.ant.taskdefs.Replace
resourcecount=org.apache.tools.ant.taskdefs.ResourceCount
retry=org.apache.tools.ant.taskdefs.Retry
rmic=org.apache.tools.ant.taskdefs.Rmic
+setpermissions=org.apache.tools.ant.taskdefs.SetPermissions
sequential=org.apache.tools.ant.taskdefs.Sequential
signjar=org.apache.tools.ant.taskdefs.SignJar
sleep=org.apache.tools.ant.taskdefs.Sleep
diff --git a/src/tests/antunit/taskdefs/setpermissions-test.xml b/src/tests/antunit/taskdefs/setpermissions-test.xml
new file mode 100644
index 000000000..61f771ccc
--- /dev/null
+++ b/src/tests/antunit/taskdefs/setpermissions-test.xml
@@ -0,0 +1,67 @@
+
+
+