From bee14ad0d4e23d3c2423f905a86bb130525a3590 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 14 Nov 2008 15:12:26 +0000 Subject: [PATCH] allow chmod, chgrp, chown and attribute to be used outside of their native environment. PR 7624 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@714025 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 6 ++++++ docs/manual/CoreTasks/chmod.html | 18 ++++++++++++++++++ docs/manual/CoreTasks/conditions.html | 2 +- docs/manual/OptionalTasks/attrib.html | 19 +++++++++++++++++++ docs/manual/OptionalTasks/chgrp.html | 19 +++++++++++++++++++ docs/manual/OptionalTasks/chown.html | 19 +++++++++++++++++++ .../org/apache/tools/ant/taskdefs/Chmod.java | 3 ++- .../apache/tools/ant/taskdefs/ExecTask.java | 17 ++++++++++++++++- .../optional/unix/AbstractAccessTask.java | 3 ++- .../ant/taskdefs/optional/windows/Attrib.java | 5 +++-- 10 files changed, 105 insertions(+), 6 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 6e41b0519..ad3aef203 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -528,6 +528,12 @@ Other changes: or the number of symlinks was too big) will be removed. Bugzilla Report 36658. + * the os and osfamily attributes of , , and + can now be used to run the commands on operating systems + other than their "native" environment, i.e. non-Unix or non-Windows + operating systems repsectively. + Bugzilla Report 7624. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/docs/manual/CoreTasks/chmod.html b/docs/manual/CoreTasks/chmod.html index 64fa55a39..7e965cbf7 100644 --- a/docs/manual/CoreTasks/chmod.html +++ b/docs/manual/CoreTasks/chmod.html @@ -57,6 +57,12 @@ little. POSIX recommends command line length limits of at least 4096 characters, this may give you an approximation for the number you could use as initial value for these experiments.

+

By default this task won't do anything unless it detects it is + running on a Unix system. If you know for sure that you have a + "chmod" executable on your PATH that is command line compatible with + the Unix command, you can use the task's os attribute and set its + value to your current os.

+

Parameters

@@ -132,6 +138,18 @@ could use as initial value for these experiments.

Defaults to false. Since Ant 1.6. + + + + + + + + + +
No
oslist of Operating Systems on which the command may be + executed.No
osfamilyOS family as used in + the <os> condition.No - defaults to "unix"

Examples

diff --git a/docs/manual/CoreTasks/conditions.html b/docs/manual/CoreTasks/conditions.html
index 665f67e45..be15dcc64 100644
--- a/docs/manual/CoreTasks/conditions.html
+++ b/docs/manual/CoreTasks/conditions.html
@@ -87,7 +87,7 @@ href="uptodate.html">Uptodate task, all attributes and nested
 elements of that task are supported, the property and value attributes
 are redundant and will be ignored.

-

os

+

os

Test whether the current operating system is of a given type. Each defined attribute is tested and the result is true only if all the tests succeed. diff --git a/docs/manual/OptionalTasks/attrib.html b/docs/manual/OptionalTasks/attrib.html index 41d22e595..1b72aac1b 100644 --- a/docs/manual/OptionalTasks/attrib.html +++ b/docs/manual/OptionalTasks/attrib.html @@ -51,6 +51,12 @@ maxparallel attribute of this task to a non-zero value. The number to use highly depends on the length of your file names (the depth of your directory tree), so you'll have to experiment a little.

+

By default this task won't do anything unless it detects it is + running on a Windows system. If you know for sure that you have a + "attrib" executable on your PATH that is command line compatible with + the Windows command, you can use the task's os attribute and set its + value to your current os.

+

Parameters

@@ -111,6 +117,19 @@ directory tree), so you'll have to experiment a little.

unlimited. Defaults to unlimited. Since Ant 1.6. + + + + + + + + + +
No
oslist of Operating Systems on which the command may be + executed.No
osfamilyOS family as used in + the <os> + condition.No - defaults to "windows"

Examples

diff --git a/docs/manual/OptionalTasks/chgrp.html b/docs/manual/OptionalTasks/chgrp.html index 35052ed6e..6c2993c2c 100644 --- a/docs/manual/OptionalTasks/chgrp.html +++ b/docs/manual/OptionalTasks/chgrp.html @@ -54,6 +54,12 @@ little. POSIX recommends command line length limits of at least 4096 characters, this may give you an approximation for the number you could use as initial value for these experiments.

+

By default this task won't do anything unless it detects it is + running on a Unix system. If you know for sure that you have a + "chgrp" executable on your PATH that is command line compatible with + the Unix command, you can use the task's os attribute and set its + value to your current os.

+

Parameters

@@ -105,6 +111,19 @@ could use as initial value for these experiments.

Defaults to false. + + + + + + + + + +
No
oslist of Operating Systems on which the command may be + executed.No
osfamilyOS family as used in + the <os> + condition.No - defaults to "unix"

Examples

diff --git a/docs/manual/OptionalTasks/chown.html b/docs/manual/OptionalTasks/chown.html index 21c556385..4714fa442 100644 --- a/docs/manual/OptionalTasks/chown.html +++ b/docs/manual/OptionalTasks/chown.html @@ -54,6 +54,12 @@ little. POSIX recommends command line length limits of at least 4096 characters, this may give you an approximation for the number you could use as initial value for these experiments.

+

By default this task won't do anything unless it detects it is + running on a Unix system. If you know for sure that you have a + "chown" executable on your PATH that is command line compatible with + the Unix command, you can use the task's os attribute and set its + value to your current os.

+

Parameters

@@ -104,6 +110,19 @@ could use as initial value for these experiments.

Defaults to false. + + + + + + + + + +
No
oslist of Operating Systems on which the command may be + executed.No
osfamilyOS family as used in + the <os> + condition.No - defaults to "unix"

Examples

diff --git a/src/main/org/apache/tools/ant/taskdefs/Chmod.java b/src/main/org/apache/tools/ant/taskdefs/Chmod.java index a9154677d..0c8ac376a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Chmod.java +++ b/src/main/org/apache/tools/ant/taskdefs/Chmod.java @@ -254,6 +254,7 @@ public class Chmod extends ExecuteOn { * @return true if the os is valid. */ protected boolean isValidOs() { - return Os.isFamily(Os.FAMILY_UNIX) && super.isValidOs(); + return getOs() == null && getOsFamily() == null + ? Os.isFamily(Os.FAMILY_UNIX) : super.isValidOs(); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java index dcddb5e49..3e54f2cd8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java @@ -154,6 +154,14 @@ public class ExecTask extends Task { this.os = os; } + /** + * List of operating systems on which the command may be executed. + * @since Ant 1.8.0 + */ + public final String getOs() { + return os; + } + /** * Sets a command line. * @param cmdl command line. @@ -396,6 +404,13 @@ public class ExecTask extends Task { this.osFamily = osFamily.toLowerCase(Locale.US); } + /** + * Restrict this execution to a single OS Family + * @since Ant 1.8.0 + */ + public final String getOsFamily() { + return osFamily; + } /** * The method attempts to figure out where the executable is so that we can feed @@ -545,7 +560,7 @@ public class ExecTask extends Task { */ protected boolean isValidOs() { //hand osfamily off to Os class, if set - if (osFamily != null && !Os.isOs(osFamily, null, null, null)) { + if (osFamily != null && !Os.isFamily(osFamily)) { return false; } //the Exec OS check is different from Os.isOs(), which diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/unix/AbstractAccessTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/unix/AbstractAccessTask.java index 2293cf450..40b8e8a2f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/unix/AbstractAccessTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/unix/AbstractAccessTask.java @@ -104,6 +104,7 @@ public abstract class AbstractAccessTask * use the superclasses' test (user set). */ protected boolean isValidOs() { - return Os.isFamily("unix") && super.isValidOs(); + return getOs() == null && getOsFamily() == null + ? Os.isFamily(Os.FAMILY_UNIX) : super.isValidOs(); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/windows/Attrib.java b/src/main/org/apache/tools/ant/taskdefs/optional/windows/Attrib.java index 5dc338fa0..2bf37b3b8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/windows/Attrib.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/windows/Attrib.java @@ -172,11 +172,12 @@ public class Attrib extends ExecuteOn { /** * Check if the os is valid. - * Always include windows + * Defauls is to allow windows * @return true if the os is valid. */ protected boolean isValidOs() { - return Os.isFamily("windows") && super.isValidOs(); + return getOs() == null && getOsFamily() == null ? + Os.isFamily(Os.WINDOWS) : super.isValidOs(); } private static String getSignString(boolean attr) {