/** * Set the working dir of the new process. * @param exe executable. * @throws BuildException if the dir doesn't exist. */ private void setupWorkingDir(Execute exe) { if (dir == null) { dir = getProject().getBaseDir(); } else if (!dir.isDirectory()) { throw new BuildException(dir.getAbsolutePath() + " is not a valid directory", getLocation()); } exe.setWorkingDirectory(dir); }
/** * Executes the given classname with the given arguments in a separate VM. * @param command String[] of command-line arguments. */ private void spawn(String[] command) throws BuildException { Execute exe = new Execute(); setupExecutable(exe, command); try { exe.spawn(); } catch (IOException e) { throw new BuildException(e, getLocation()); } }
/** * Executes the given source-file or classname with the given arguments in a separate VM. * @param command String[] of command-line arguments. */ private int fork(String[] command) throws BuildException { Execute exe = new Execute(redirector.createHandler(), createWatchdog()); setupExecutable(exe, command); try { int rc = exe.execute(); redirector.complete(); if (exe.killedProcess()) { throw new BuildException(TIMEOUT_MESSAGE); } return rc; } catch (IOException e) { throw new BuildException(e, getLocation()); } }
if (e.getLocation() == null && getLocation() != null) { e.setLocation(getLocation()); } catch (Throwable t) { if (failOnError) { throw new BuildException(t, getLocation());
/** * Do the execution. * @throws BuildException if failOnError is set to true and the application * returns a nonzero result code. */ @Override public void execute() throws BuildException { File savedDir = dir; Permissions savedPermissions = perm; int err = -1; try { checkConfiguration(); err = executeJava(); if (err != 0) { if (failOnError) { throw new ExitStatusException("Java returned: " + err, err, getLocation()); } else { log("Java Result: " + err, Project.MSG_ERR); } } maybeSetResultPropertyValue(err); } finally { dir = savedDir; perm = savedPermissions; } }