本文整理了Java中org.apache.tools.ant.taskdefs.Execute
类的一些代码示例,展示了Execute
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Execute
类的具体详情如下:
包路径:org.apache.tools.ant.taskdefs.Execute
类名称:Execute
[英]Runs an external program.
[中]运行外部程序。
代码示例来源:origin: apache/groovy
private void runForked(String[] commandLine) {
final Execute executor = new Execute();
executor.setAntRun(getProject());
executor.setWorkingDirectory(getProject().getBaseDir());
executor.setCommandline(commandLine);
try {
executor.execute();
} catch (final IOException ioe) {
throw new BuildException("Error running forked groovyc.", ioe);
}
final int returnCode = executor.getExitValue();
if (returnCode != 0) {
taskSuccess = false;
if (errorProperty != null) {
getProject().setNewProperty(errorProperty, "true");
}
if (failOnError) {
throw new BuildException("Forked groovyc returned error code: " + returnCode);
} else {
log.error("Forked groovyc returned error code: " + returnCode);
}
}
}
代码示例来源:origin: org.apache.ant/ant
Execute exe = new Execute(getExecuteStreamHandler(), null);
exe.setAntRun(getProject());
if (dest == null) {
dest = getProject().getBaseDir();
exe.setWorkingDirectory(dest);
exe.setCommandline(toExecute.getCommandline());
exe.setEnvironment(env.getVariables());
int retCode = exe.execute();
log("retCode=" + retCode, Project.MSG_DEBUG);
if (failOnError && Execute.isFailure(retCode)) {
throw new BuildException(
String.format("cvs exited with error code %s%nCommand line was [%s]",
retCode, actualCommandLine), getLocation());
throw new BuildException(e, getLocation());
throw(e);
Throwable t = e.getCause();
if (t == null) {
t = e;
代码示例来源:origin: org.apache.ant/ant
cmdl.setClassname(javaCommand.getExecutable());
for (String arg : javaCommand.getArguments()) {
cmdl.createArgument().setValue(arg);
= new Execute(redirector.createHandler(),
timeout == null
? null
: new ExecuteWatchdog(timeout));
exe.setAntRun(pc.getProject());
if (Os.isFamily("openvms")) {
setupCommandLineForVMS(exe, cmdl.getCommandline());
} else {
exe.setCommandline(cmdl.getCommandline());
int rc = exe.execute();
redirector.complete();
return rc;
} catch (IOException e) {
throw new BuildException(e);
} finally {
timedOut = exe.killedProcess();
代码示例来源:origin: org.apache.ant/ant
/**
* 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());
}
代码示例来源:origin: kaaproject/kaa
private static void executeCommand(File workingDir, String... command) throws IOException {
Execute exec = new Execute();
if (workingDir == null) {
String homeDir = System.getProperty("user.home");
if (homeDir != null) {
workingDir = new File(homeDir);
}
}
if (workingDir != null) {
exec.setWorkingDirectory(workingDir);
}
exec.setCommandline(command);
exec.execute();
if (exec.isFailure()) {
throw new RuntimeException("Process returned bad exit value: " + exec.getExitValue());
}
}
代码示例来源:origin: org.glassfish.metro/webservices-tools
/**
* Executes the given classname with the given arguments in a separate VM.
*/
private int run(String[] command) throws BuildException {
LogStreamHandler logstr = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);
Execute exe = new Execute(logstr);
exe.setAntRun(project);
exe.setCommandline(command);
try {
int rc = exe.execute();
if (exe.killedProcess()) {
log("Timeout: killed the sub-process", Project.MSG_WARN);
}
return rc;
} catch (IOException e) {
throw new BuildException(e, location);
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-antext
if (srcJar == null) throw new BuildException(Bundle.getMessage("ERR_MissingAttr", "srcJar")); // NO I18N
if (destJar == null) throw new BuildException(Bundle.getMessage("ERR_MissingAttr", "destJar")); // NO I18N
if (destJar.exists() && srcJar.lastModified() <= destJar.lastModified())
final String libsObfsClassPath = getProject().getProperty(MessageFormat.format(LIBS_OBFUSCATOR_CLASSPATH_PROPERTY_NAME, new Object[] { obfs.toLowerCase() }));
if (libsObfsClassPath != null)
jointClassPaths = joinPaths(jointClassPaths, new Path(getProject(), libsObfsClassPath).list());
throw new BuildException(Bundle.getMessage("ERR_NoObfuscator")); // NO I18N
final String old = obfuscatorType;
obfuscatorType = foundObfuscators.get(0);
if (obfuscatorType != null)
final String p = getProject().getProperty(MessageFormat.format(LIBS_OBFUSCATOR_CLASSPATH_PROPERTY_NAME, new Object[] { obfuscatorType.toLowerCase() })); // NO I18N
if (p != null)
createObfuscatorClassPath().add(new Path(getProject(), p));
try
final Execute exec = new Execute(new PumpStreamHandler(System.out, System.out)); //to avoid red colored text in obfuscator output
exec.setAntRun(getProject());
exec.setVMLauncher(true);
exec.setCommandline(commands);
final int i = exec.execute();
if (i != 0)
代码示例来源:origin: org.apache.ant/ant
Commandline toExecute = (Commandline) cmd.clone();
toExecute.setExecutable(PATCH);
toExecute.createArgument().setFile(originalFile);
Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
Project.MSG_WARN),
null);
exe.setCommandline(toExecute.getCommandline());
exe.setWorkingDirectory(getProject().getBaseDir());
} else {
if (!directory.isDirectory()) {
throw new BuildException(directory + " is not a directory.",
getLocation());
exe.setWorkingDirectory(directory);
log(toExecute.describeCommand(), Project.MSG_VERBOSE);
try {
int returncode = exe.execute();
if (Execute.isFailure(returncode)) {
String msg = "'" + PATCH + "' failed with exit code "
+ returncode;
if (failOnError) {
throw new BuildException(msg);
代码示例来源:origin: org.testng/testng
Execute execute= new Execute(new TestNGLogSH(this, Project.MSG_INFO, Project.MSG_WARN, (m_verbose == null || m_verbose < 5)),
watchdog);
execute.setCommandline(cmd.getCommandline());
execute.setAntRun(getProject());
if(m_workingDir != null) {
if(m_workingDir.exists() && m_workingDir.isDirectory()) {
execute.setWorkingDirectory(m_workingDir);
execute.setEnvironment(environment);
retVal= execute.execute();
throw new BuildException("Process fork failed.", e, getLocation());
代码示例来源:origin: org.apache.ant/ant
Execute execTask = new Execute(this);
Project project = getTask().getProject();
execTask.setAntRun(project);
execTask.setWorkingDirectory(project.getBaseDir());
Commandline commandline = new Commandline();
commandline.setExecutable(JAVA2IIOP);
commandline.createArgument().setValue("-VBJdebug");
commandline.createArgument().setValue("-VBJclasspath");
commandline.createArgument().setPath(getCombinedClasspath());
commandline.createArgument().setValue("-list_files");
log("Calling java2iiop", Project.MSG_VERBOSE);
log(commandline.describeCommand(), Project.MSG_DEBUG);
execTask.setCommandline(commandline.getCommandline());
int result = execTask.execute();
if (Execute.isFailure(result)) {
throw new BuildException(
"Failed executing java2iiop (ret code is " + result + ")",
getTask().getLocation());
throw new BuildException(e, getTask().getLocation());
代码示例来源:origin: org.apache.ant/ant
if (Commandline.toString(args).length() > COMMAND_LINE_LIMIT
&& firstFileName >= 0) {
try {
throw new BuildException("Error creating temporary file",
e, location);
final Execute exe = new Execute(
new LogStreamHandler(attributes,
Project.MSG_INFO,
Project.MSG_WARN));
exe.setVMLauncher(true);
exe.setAntRun(project);
exe.setWorkingDirectory(project.getBaseDir());
exe.setCommandline(commandArray);
exe.execute();
return exe.getExitValue();
} catch (final IOException e) {
throw new BuildException("Error running " + args[0]
+ " compiler", e, location);
代码示例来源:origin: randomizedtesting/randomizedtesting
slaveInfo.slaveCommandLine, Project.MSG_VERBOSE);
final Execute execute = new Execute();
execute.setCommandline(commandline.getCommandline());
execute.setVMLauncher(true);
execute.setWorkingDirectory(cwd.toFile());
execute.setStreamHandler(streamHandler);
execute.setNewenvironment(newEnvironment);
if (env.getVariables() != null)
execute.setEnvironment(env.getVariables());
log("Starting JVM J" + slaveInfo.id, Project.MSG_DEBUG);
execute.execute();
return execute;
} catch (IOException e) {
throw new BuildException("Could not start the child process. Run ant with -verbose to get" +
" the execution details.", e);
代码示例来源:origin: org.fitnesse/fitnesse
private int executeRunnerClassAsForked() throws BuildException {
CommandlineJava cmd = initializeJavaCommand();
Execute execute = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN));
String[] commandLine = cmd.getCommandline();
log("Executing: " + StringUtils.join(Arrays.asList(commandLine), " "));
execute.setCommandline(commandLine);
execute.setNewenvironment(false);
execute.setAntRun(getProject());
log(cmd.describeCommand(), Project.MSG_VERBOSE);
int retVal;
try {
retVal = execute.execute();
}
catch (IOException e) {
throw new BuildException("Process fork failed.", e, getLocation());
}
return retVal;
}
代码示例来源:origin: org.apache.ant/ant
.setValue("-" + name + ":" + value.toString()));
throw new BuildException("Invalid target: %s", targetFile);
cmdl.createArgument() .setValue("-" + OUTPUT_FILE + ":"
+ outputFile.replace('\\', '/'));
cmdl.createArgument().setValue(targetFile.getAbsolutePath());
new Execute(new LogStreamHandler(this,
Project.MSG_INFO,
Project.MSG_INFO),
null);
log(cmdl.describeCommand(), Project.MSG_VERBOSE);
process.setCommandline(cmdl.getCommandline());
if (process.execute() != 0) {
throw new BuildException("JJDoc failed.");
throw new BuildException("Failed to launch JJDoc", e);
代码示例来源:origin: org.apache.ant/ant
/**
* A utility method that runs an external command. Writes the output and
* error streams of the command to the project log.
*
* @param task The task that the command is part of. Used for logging
* @param cmdline The command to execute.
* @throws BuildException if the command does not exit successfully.
*/
public static void runCommand(Task task, String... cmdline)
throws BuildException {
try {
task.log(Commandline.describeCommand(cmdline),
Project.MSG_VERBOSE);
Execute exe = new Execute(
new LogStreamHandler(task, Project.MSG_INFO, Project.MSG_ERR));
exe.setAntRun(task.getProject());
exe.setCommandline(cmdline);
int retval = exe.execute();
if (isFailure(retval)) {
throw new BuildException(cmdline[0]
+ " failed with return code " + retval, task.getLocation());
}
} catch (IOException exc) {
throw new BuildException("Could not launch " + cmdline[0] + ": "
+ exc, task.getLocation());
}
}
代码示例来源:origin: org.apache.ant/ant
toExecute.createArgument().setValue("-breakiterator");
tmpList.delete();
throw new BuildException("Error creating temporary file",
e, getLocation());
} finally {
toExecute.createArgument().setValue("@" + packageList);
log(toExecute.describeCommand(), Project.MSG_VERBOSE);
final Execute exe = new Execute(new PumpStreamHandler(out, err));
exe.setAntRun(getProject());
exe.setWorkingDirectory(null);
try {
exe.setCommandline(toExecute.getCommandline());
final int ret = exe.execute();
if (ret != 0 && failOnError) {
throw new BuildException("Javadoc returned " + ret,
getLocation());
throw new BuildException("Javadoc issued warnings.",
getLocation());
代码示例来源:origin: org.apache.ant/ant-junit
cmd = (CommandlineJava) getCommandline().clone();
} catch (final CloneNotSupportedException e) {
throw new BuildException("This shouldn't happen", e, getLocation());
cmd.createArgument().setValue(Constants.TESTSFILE + casesFile);
final Execute execute = new Execute(
new JUnitLogStreamHandler(
this,
Project.MSG_WARN),
watchdog);
execute.setCommandline(cmd.getCommandline());
execute.setAntRun(getProject());
if (dir != null) {
execute.setWorkingDirectory(dir);
execute.setNewenvironment(newEnvironment);
execute.setEnvironment(environment);
boolean success = false;
try {
result.exitCode = execute.execute();
success = true;
} catch (final IOException e) {
throw new BuildException("Process fork failed.", e, getLocation());
} finally {
String vmCrashString = "unknown";
代码示例来源:origin: org.apache.ant/ant
/**
* 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);
}
代码示例来源:origin: randomizedtesting/randomizedtesting
commandline.setClassname(SlaveMainSafe.class.getName());
if (slave.slaves == 1) {
commandline.createArgument().setValue(SlaveMain.OPTION_FREQUENT_FLUSH);
commandline.createArgument().setValue(SlaveMain.OPTION_EVENTSFILE);
commandline.createArgument().setFile(eventFile.toFile());
log("Forked JVM J" + slave.id + " finished with exit code: " + execute.getExitValue(), Project.MSG_DEBUG);
if (execute.isFailure()) {
final int exitStatus = execute.getExitValue();
switch (exitStatus) {
case SlaveMain.ERR_NO_JUNIT:
throw new BuildException("Forked JVM's classpath must include a junit4 JAR.");
case SlaveMain.ERR_OLD_JUNIT:
throw new BuildException("Forked JVM's classpath must use JUnit 4.10 or newer.");
default:
Closeables.close(sysout, false);
throw new BuildException(message.toString());
代码示例来源:origin: org.apache.ant/ant
/**
* 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());
}
}
内容来源于网络,如有侵权,请联系作者删除!