@@ -21,10 +21,13 @@ import java.io.File;
import java.io.IOException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Enumeration;
import java.util.Vector;
import java.util.Vector;
import java.util.Locale;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Path;
@@ -43,6 +46,7 @@ public class ExecTask extends Task {
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private String os;
private String os;
private String osFamily;
private File dir;
private File dir;
protected boolean failOnError = false;
protected boolean failOnError = false;
@@ -382,6 +386,15 @@ public class ExecTask extends Task {
}
}
/**
* Restrict this execution to a single OS Family
* @param osFamily
*/
public void setOsFamily(String osFamily) {
this.osFamily = osFamily.toLowerCase(Locale.US);
}
/**
/**
* The method attempts to figure out where the executable is so that we can feed
* The method attempts to figure out where the executable is so that we can feed
* the full path. We first try basedir, then the exec dir, and then
* the full path. We first try basedir, then the exec dir, and then
@@ -516,21 +529,33 @@ public class ExecTask extends Task {
* @return boolean.
* @return boolean.
* <ul>
* <ul>
* <li>
* <li>
* <code>true</code> if the os under which Ant is running is
* matches one os in the os attribute
* or if the os attribute is null</li>
* <li><code>true</code> if the os and osfamily attributes are null.</li>
* <li><code>true</code> if osfamily is set, and the os family and must match
* that of the current OS, according to the logic of
* {@link Os#isOs(String, String, String, String)}, and the result of the
* <code>os</code> attribute must also evaluate true.
* </li>
* <li>
* <code>true</code> if os is set, and the system.property os.name
* is found in the os attribute,</li>
* <li><code>false</code> otherwise.</li>
* <li><code>false</code> otherwise.</li>
* </ul>
* </ul>
*/
*/
protected boolean isValidOs() {
protected boolean isValidOs() {
// test if os match
//hand osfamily off to Os class, if set
if(osFamily!=null && !Os.isOs(osFamily,null,null,null)) {
return false;
}
//the Exec OS check is different from Os.isOs(), which
//probes for a specific OS. Instead it searches the os field
//for the current os.name
String myos = System.getProperty("os.name");
String myos = System.getProperty("os.name");
log("Current OS is " + myos, Project.MSG_VERBOSE);
log("Current OS is " + myos, Project.MSG_VERBOSE);
if ((os != null) && (os.indexOf(myos) < 0)) {
if ((os != null) && (os.indexOf(myos) < 0)) {
// this command will be executed only on the specified OS
// this command will be executed only on the specified OS
log("This OS, " + myos
log("This OS, " + myos
+ " was not found in the specified list of valid OSes: " + os,
Project.MSG_VERBOSE);
+ " was not found in the specified list of valid OSes: " + os,
Project.MSG_VERBOSE);
return false;
return false;
}
}
return true;
return true;