Browse Source

Adding a new non-static method, isFailure() to Execute. As well as simplifying a common operation, it is a foundation for instance specific logic to decide if an execute failed, which could be of use in VMS land.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@405524 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 19 years ago
parent
commit
35a452e2ac
3 changed files with 18 additions and 7 deletions
  1. +13
    -1
      src/main/org/apache/tools/ant/taskdefs/Execute.java
  2. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/rmic/ForkingSunRmic.java
  3. +4
    -4
      src/testcases/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java

+ 13
- 1
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -47,7 +47,9 @@ import org.apache.tools.ant.util.FileUtils;
*/
public class Execute {

/** Invalid exit code. **/
/** Invalid exit code.
* set to {@link Integer#MAX_VALUE}
*/
public static final int INVALID = Integer.MAX_VALUE;

private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
@@ -586,6 +588,16 @@ public class Execute {
? (exitValue % 2 == 0) : (exitValue != 0);
}

/**
* Did this execute return in a failure.
* @see #isFailure(int)
* @return true if and only if the exit code is interpreted as a failure
* @since Ant1.7
*/
public boolean isFailure() {
return isFailure(getExitValue());
}

/**
* Test for an untimely death of the process.
* @return true if a watchdog had to kill the process.


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/rmic/ForkingSunRmic.java View File

@@ -65,9 +65,8 @@ public class ForkingSunRmic extends DefaultRmicAdapter {
exe.setAntRun(project);
exe.setWorkingDirectory(project.getBaseDir());
exe.setCommandline(args);

exe.execute();
return exe.getExitValue() == 0;
return !exe.isFailure();
} catch (IOException exception) {
throw new BuildException("Error running " + SunRmic.RMIC_EXECUTABLE
+ " -maybe it is not on the path", exception);


+ 4
- 4
src/testcases/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java View File

@@ -27,12 +27,12 @@ import java.io.*;
*/
public class ExecuteWatchdogTest extends TestCase {

private final static int TIME_OUT = 5000;
private final static long TIME_OUT = 5000;

private final static String TEST_CLASSPATH = getTestClassPath();

private final static int CLOCK_ERROR=200;
private final static int TIME_OUT_TEST=TIME_OUT-CLOCK_ERROR;
private final static long TIME_OUT_TEST=TIME_OUT-CLOCK_ERROR;

private ExecuteWatchdog watchdog;

@@ -58,7 +58,7 @@ public class ExecuteWatchdogTest extends TestCase {
return classpath;
}

private Process getProcess(int timetorun) throws Exception {
private Process getProcess(long timetorun) throws Exception {
String[] cmdArray = {
JavaEnvUtils.getJreExecutable("java"), "-classpath", TEST_CLASSPATH,
TimeProcess.class.getName(), String.valueOf(timetorun)
@@ -94,7 +94,7 @@ public class ExecuteWatchdogTest extends TestCase {
watchdog.start(process);
int retCode = waitForEnd(process);
assertTrue("process should not have been killed", !watchdog.killedProcess());
assertEquals(0, retCode);
assertFalse(Execute.isFailure(retCode));
}

// test that the watchdog ends the process


Loading…
Cancel
Save