本文整理汇总了Java中org.eclipse.che.api.core.util.ProcessUtil类的典型用法代码示例。如果您正苦于以下问题:Java ProcessUtil类的具体用法?Java ProcessUtil怎么用?Java ProcessUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProcessUtil类属于org.eclipse.che.api.core.util包,在下文中一共展示了ProcessUtil类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeCommand
import org.eclipse.che.api.core.util.ProcessUtil; //导入依赖的package包/类
@VisibleForTesting
void executeCommand(
String[] commandLine,
int timeout,
String address,
String workspaceId,
Set<Integer> successResponseCodes)
throws TimeoutException, IOException, InterruptedException {
final ListLineConsumer outputConsumer = new ListLineConsumer();
Process process = ProcessUtil.executeAndWait(commandLine, timeout, SECONDS, outputConsumer);
if (!successResponseCodes.contains(process.exitValue())) {
LOG.error(
"Error occurred during backup/restore of workspace '{}' on node '{}' : {}",
workspaceId,
address,
outputConsumer.getText());
throw new IOException("Synchronization process failed. Exit code " + process.exitValue());
}
}
示例2: execute
import org.eclipse.che.api.core.util.ProcessUtil; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
public void execute(CommandLineBuilder builder, File workDir, File outputLog, final LineConsumer consumer) throws IOException, InterruptedException {
String command = builder.build();
if (StringUtils.isEmpty(command)) {
throw new IllegalStateException("Command cannot be empty");
}
Process process = new ProcessBuilder(builder.buildCommandLine().toShellCommand())
.redirectInput(outputLog)
.redirectErrorStream(true)
.directory(workDir).start();
try {
result = process.waitFor();
isFinished = true;
} catch (InterruptedException e) {
ProcessUtil.kill(process);
throw e;
}
}
示例3: execute
import org.eclipse.che.api.core.util.ProcessUtil; //导入依赖的package包/类
@VisibleForTesting
void execute(String[] commandLine, int timeout)
throws TimeoutException, IOException, InterruptedException {
final ListLineConsumer outputConsumer = new ListLineConsumer();
Process process = ProcessUtil.executeAndWait(commandLine, timeout, SECONDS, outputConsumer);
if (process.exitValue() != 0) {
LOG.error(outputConsumer.getText());
throw new IOException("Process failed. Exit code " + process.exitValue());
}
}
示例4: readMavenVersionInformation
import org.eclipse.che.api.core.util.ProcessUtil; //导入依赖的package包/类
private static void readMavenVersionInformation(LineConsumer cmdOutput) throws IOException {
final CommandLine commandLine = new CommandLine(getMavenExecCommand()).add("-version");
final ProcessBuilder processBuilder =
new ProcessBuilder().command(commandLine.toShellCommand()).redirectErrorStream(true);
final Process process = processBuilder.start();
ProcessUtil.process(process, cmdOutput, LineConsumer.DEV_NULL);
}
示例5: execute
import org.eclipse.che.api.core.util.ProcessUtil; //导入依赖的package包/类
public void execute(String[] commandLine, File workDir)
throws TimeoutException, IOException, InterruptedException {
ProcessBuilder pb =
new ProcessBuilder(commandLine).redirectErrorStream(true).directory(workDir);
eventService.publish(
new ComposerOutputImpl(String.join(" ", commandLine), ComposerOutput.State.START));
LineConsumer lineConsumer =
new AbstractLineConsumer() {
@Override
public void writeLine(String line) throws IOException {
eventService.publish(new ComposerOutputImpl(line, ComposerOutput.State.IN_PROGRESS));
}
};
// process will be stopped after timeout
Watchdog watcher = new Watchdog(10, TimeUnit.MINUTES);
try {
final Process process = pb.start();
final ValueHolder<Boolean> isTimeoutExceeded = new ValueHolder<>(false);
watcher.start(
() -> {
isTimeoutExceeded.set(true);
ProcessUtil.kill(process);
});
// consume logs until process ends
ProcessUtil.process(process, lineConsumer);
process.waitFor();
eventService.publish(new ComposerOutputImpl("Done", ComposerOutput.State.DONE));
if (isTimeoutExceeded.get()) {
LOG.error("Command time expired : command-line " + Arrays.toString(commandLine));
eventService.publish(
new ComposerOutputImpl(
"Installing dependencies time expired", ComposerOutput.State.ERROR));
throw new TimeoutException();
} else if (process.exitValue() != 0) {
LOG.error("Command failed : command-line " + Arrays.toString(commandLine));
eventService.publish(new ComposerOutputImpl("Error occurred", ComposerOutput.State.ERROR));
throw new IOException(
"Process failed. Exit code "
+ process.exitValue()
+ " command-line : "
+ Arrays.toString(commandLine));
}
} finally {
watcher.stop();
}
}
示例6: execute
import org.eclipse.che.api.core.util.ProcessUtil; //导入依赖的package包/类
/**
* Execute maven archetype command
*
* @param commandLine command to execution e.g. mvn archetype:generate
* -DarchetypeGroupId=<archetype-groupId> -DarchetypeArtifactId=<archetype-artifactId>
* -DarchetypeVersion=<archetype-version> -DgroupId=<my.groupid> -DartifactId=<my-artifactId>
* @param workDir folder where command will execute in common use root dir of workspace
* @throws TimeoutException
* @throws IOException
* @throws InterruptedException
*/
private void execute(String[] commandLine, File workDir)
throws TimeoutException, IOException, InterruptedException {
ProcessBuilder pb =
new ProcessBuilder(commandLine).redirectErrorStream(true).directory(workDir);
eventService.publish(
new ArchetypeOutputImpl("Start Project generation", ArchetypeOutput.State.START));
LineConsumer lineConsumer =
new AbstractLineConsumer() {
@Override
public void writeLine(String line) throws IOException {
eventService.publish(new ArchetypeOutputImpl(line, ArchetypeOutput.State.IN_PROGRESS));
}
};
// process will be stopped after timeout
Watchdog watcher = new Watchdog(60, TimeUnit.SECONDS);
try {
final Process process = pb.start();
final ValueHolder<Boolean> isTimeoutExceeded = new ValueHolder<>(false);
watcher.start(
() -> {
isTimeoutExceeded.set(true);
ProcessUtil.kill(process);
});
// consume logs until process ends
ProcessUtil.process(process, lineConsumer);
process.waitFor();
eventService.publish(new ArchetypeOutputImpl("Done", DONE));
if (isTimeoutExceeded.get()) {
LOG.error("Generation project time expired : command-line " + Arrays.toString(commandLine));
eventService.publish(new ArchetypeOutputImpl("Generation project time expired", ERROR));
throw new TimeoutException();
} else if (process.exitValue() != 0) {
LOG.error("Generation project fail : command-line " + Arrays.toString(commandLine));
eventService.publish(new ArchetypeOutputImpl("Generation project occurs error", ERROR));
throw new IOException(
"Process failed. Exit code "
+ process.exitValue()
+ " command-line : "
+ Arrays.toString(commandLine));
}
} finally {
watcher.stop();
}
}
示例7: suspend
import org.eclipse.che.api.core.util.ProcessUtil; //导入依赖的package包/类
public Location suspend(final String file, boolean isRemoteConnection)
throws IOException, InterruptedException, DebuggerException {
if (pid < 0) {
throw new DebuggerException("Gdb process not found.");
}
if (isRemoteConnection) {
Runtime.getRuntime().exec("kill -SIGINT " + pid).waitFor();
sendCommand("signal SIGSTOP ");
} else {
final List<String> outputs = new ArrayList<>();
final ProcessBuilder processBuilder =
new ProcessBuilder().command("ps", "-o", "pid,cmd", "--ppid", String.valueOf(pid));
final Process process = processBuilder.start();
LineConsumer stdout =
new AbstractLineConsumer() {
@Override
public void writeLine(String line) throws IOException {
outputs.add(line);
}
};
ProcessUtil.process(process, stdout);
int processId = -1;
for (String output : outputs) {
try {
final ProcessInfo processInfo = ProcessInfo.parse(output);
if (file.equals(processInfo.getProcessName())) {
processId = processInfo.getProcessId();
}
} catch (Exception e) {
// we can't get info about current process, but we are trying to get info about another
// processes
}
}
if (processId == -1) {
throw new DebuggerException(format("Process %s not found.", file));
}
Runtime.getRuntime().exec("kill -SIGINT " + processId).waitFor();
}
final GdbOutput gdbOutput = sendCommand("backtrace");
final GdbBacktrace backtrace = GdbBacktrace.parse(gdbOutput);
final Map<Integer, Location> frames = backtrace.getFrames();
if (frames.containsKey(0)) {
return frames.get(0);
}
throw new DebuggerException("Unable recognize current location for debugger session. ");
}