use of com.intellij.execution.process.OSProcessHandler in project intellij-community by JetBrains.
the class MavenRunConfiguration method getState.
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
JavaCommandLineState state = new JavaCommandLineState(env) {
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
return MavenRunConfiguration.this.createJavaParameters(env.getProject());
}
@NotNull
@Override
public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
DefaultExecutionResult res = (DefaultExecutionResult) super.execute(executor, runner);
if (executor.getId().equals(ToolWindowId.RUN) && MavenResumeAction.isApplicable(env.getProject(), getJavaParameters(), MavenRunConfiguration.this)) {
MavenResumeAction resumeAction = new MavenResumeAction(res.getProcessHandler(), runner, env);
res.setRestartActions(resumeAction);
}
return res;
}
@NotNull
@Override
protected OSProcessHandler startProcess() throws ExecutionException {
OSProcessHandler result = super.startProcess();
result.setShouldDestroyProcessRecursively(true);
result.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
updateProjectsFolders();
}
});
return result;
}
};
state.setConsoleBuilder(MavenConsoleImpl.createConsoleBuilder(getProject()));
return state;
}
use of com.intellij.execution.process.OSProcessHandler in project intellij-community by JetBrains.
the class JavaScratchConfiguration method getState.
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
final JavaCommandLineState state = new JavaApplicationCommandLineState<JavaScratchConfiguration>(this, env) {
@Override
protected void setupJavaParameters(JavaParameters params) throws ExecutionException {
super.setupJavaParameters(params);
final File scrachesOutput = JavaScratchCompilationSupport.getScratchOutputDirectory(getProject());
if (scrachesOutput != null) {
params.getClassPath().addFirst(FileUtil.toCanonicalPath(scrachesOutput.getAbsolutePath()).replace('/', File.separatorChar));
}
}
@NotNull
@Override
protected OSProcessHandler startProcess() throws ExecutionException {
final OSProcessHandler handler = super.startProcess();
if (getRunnerSettings() instanceof DebuggingRunnerData) {
final VirtualFile vFile = getConfiguration().getScratchVirtualFile();
if (vFile != null) {
DebuggerManager.getInstance(getProject()).addDebugProcessListener(handler, new DebugProcessListener() {
@Override
public void processAttached(DebugProcess process) {
if (vFile.isValid()) {
process.appendPositionManager(new JavaScratchPositionManager((DebugProcessImpl) process, vFile));
}
process.removeDebugProcessListener(this);
}
});
}
}
return handler;
}
};
state.setConsoleBuilder(TextConsoleBuilderFactory.getInstance().createBuilder(getProject(), getConfigurationModule().getSearchScope()));
return state;
}
use of com.intellij.execution.process.OSProcessHandler in project intellij-community by JetBrains.
the class JavaCommandLineStateUtil method startProcess.
@NotNull
public static OSProcessHandler startProcess(@NotNull GeneralCommandLine commandLine, boolean ansiColoring) throws ExecutionException {
ProcessHandlerFactory factory = ProcessHandlerFactory.getInstance();
OSProcessHandler processHandler = ansiColoring ? factory.createColoredProcessHandler(commandLine) : factory.createProcessHandler(commandLine);
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
use of com.intellij.execution.process.OSProcessHandler in project kotlin by JetBrains.
the class RunUtils method run.
private static RunResult run(final RunSettings settings) {
System.out.println("RUN COMMAND: " + settings);
final StringBuilder stdOut = new StringBuilder();
final StringBuilder stdErr = new StringBuilder();
OSProcessHandler handler;
try {
handler = new OSProcessHandler(settings.commandLine.createProcess(), settings.commandLine.getCommandLineString(), Charsets.UTF_8);
if (settings.input != null) {
handler.getProcessInput().write(settings.input.getBytes());
}
close(handler.getProcessInput());
} catch (ExecutionException e) {
return new RunResult(false, getStackTrace(e));
} catch (IOException e) {
return new RunResult(false, getStackTrace(e));
}
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
System.out.println("TERMINATED: " + settings.commandLine);
super.processTerminated(event);
}
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String str = event.getText();
if (outputType == ProcessOutputTypes.STDOUT || outputType == ProcessOutputTypes.SYSTEM) {
appendToContent(stdOut, str);
} else if (outputType == ProcessOutputTypes.STDERR) {
appendToContent(stdErr, str);
}
}
private synchronized void appendToContent(StringBuilder content, String line) {
if (settings.printOutputAtAppearance) {
System.out.println(getPrefixString() + StringUtil.trimTrailing(line));
System.out.flush();
} else {
content.append(getPrefixString());
content.append(StringUtil.trimTrailing(line));
content.append("\n");
}
}
private String getPrefixString() {
return (settings.outputPrefix != null) ? settings.outputPrefix + " " : "";
}
});
handler.startNotify();
if (settings.waitForEnd) {
String timeoutAsString = System.getenv("kotlin.tests.android.timeout");
if (timeoutAsString == null) {
timeoutAsString = "30";
System.err.println("Default value for timeout used: timeout = 30 min. You can change it using 'kotlin.tests.android.timeout' environment variable");
}
int timeout;
try {
timeout = Integer.parseInt(timeoutAsString);
} catch (NumberFormatException e) {
timeout = 30;
System.err.println("Timeout system property should be a number");
}
handler.waitFor(timeout * 60 * 1000);
if (!handler.isProcessTerminated()) {
System.out.println("Output before handler.isProcessTerminated() " + settings.commandLine);
System.out.println(stdOut);
System.err.println(stdErr);
return new RunResult(false, "Timeout exception: execution was terminated after ~20 min.");
}
} else {
handler.waitFor();
}
int exitCode = handler.getProcess().exitValue();
if (exitCode != 0) {
return new RunResult(false, builderToString(stdOut) + builderToString(stdErr));
} else {
String output = builderToString(stdOut) + builderToString(stdErr);
if (OutputUtils.isBuildFailed(output)) {
return new RunResult(false, output);
}
if (!settings.commandLine.getCommandLineString().contains("install")) {
System.out.print(output);
}
return new RunResult(true, output);
}
}
use of com.intellij.execution.process.OSProcessHandler in project kotlin by JetBrains.
the class KotlinIntegrationTestBase method runProcess.
private static int runProcess(GeneralCommandLine commandLine, StringBuilder executionLog) throws ExecutionException {
OSProcessHandler handler = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
StringBuilder outContent = new StringBuilder();
StringBuilder errContent = new StringBuilder();
handler.addProcessListener(new OutputListener(outContent, errContent));
handler.startNotify();
handler.waitFor();
int exitCode = handler.getProcess().exitValue();
appendIfNotEmpty(executionLog, "OUT:\n", outContent.toString());
appendIfNotEmpty(executionLog, "\nERR:\n", errContent.toString());
executionLog.append("\nReturn code: ").append(exitCode).append("\n");
return exitCode;
}
Aggregations