use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.
the class DebuggerTestCase method attachVM.
protected DebuggerSession attachVM(final RemoteConnection remoteConnection, final boolean pollConnection) throws InvocationTargetException, InterruptedException {
final RemoteState remoteState = new RemoteStateState(myProject, remoteConnection);
final DebuggerSession[] debuggerSession = new DebuggerSession[1];
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
try {
debuggerSession[0] = attachVirtualMachine(remoteState, new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()).runProfile(new MockConfiguration()).build(), remoteConnection, pollConnection);
} catch (ExecutionException e) {
fail(e.getMessage());
}
}
});
debuggerSession[0].getProcess().getProcessHandler().addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
print(event.getText(), outputType);
}
});
return debuggerSession[0];
}
use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.
the class DebuggerTestCase method createLocalProcess.
protected DebuggerSession createLocalProcess(int transport, final JavaParameters javaParameters) throws ExecutionException, InterruptedException, InvocationTargetException {
createBreakpoints(javaParameters.getMainClass());
final DebuggerSession[] debuggerSession = new DebuggerSession[] { null };
DebuggerSettings.getInstance().DEBUGGER_TRANSPORT = transport;
GenericDebuggerRunnerSettings debuggerRunnerSettings = new GenericDebuggerRunnerSettings();
debuggerRunnerSettings.LOCAL = true;
debuggerRunnerSettings.setDebugPort(String.valueOf(DEFAULT_ADDRESS));
ExecutionEnvironment environment = new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()).runnerSettings(debuggerRunnerSettings).runProfile(new MockConfiguration()).build();
final JavaCommandLineState javaCommandLineState = new JavaCommandLineState(environment) {
@Override
protected JavaParameters createJavaParameters() {
return javaParameters;
}
@Override
protected GeneralCommandLine createCommandLine() throws ExecutionException {
return getJavaParameters().toCommandLine();
}
};
final RemoteConnection debugParameters = DebuggerManagerImpl.createDebugParameters(javaCommandLineState.getJavaParameters(), debuggerRunnerSettings, true);
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
try {
debuggerSession[0] = attachVirtualMachine(javaCommandLineState, javaCommandLineState.getEnvironment(), debugParameters, false);
} catch (ExecutionException e) {
fail(e.getMessage());
}
}
});
final ProcessHandler processHandler = debuggerSession[0].getProcess().getProcessHandler();
debuggerSession[0].getProcess().addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
print(event.getText(), outputType);
}
});
DebugProcessImpl process = (DebugProcessImpl) DebuggerManagerEx.getInstanceEx(myProject).getDebugProcess(processHandler);
assertNotNull(process);
return debuggerSession[0];
}
use of com.intellij.execution.process.ProcessEvent 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.ProcessEvent in project intellij-community by JetBrains.
the class PyConsoleTask method runTestOn.
@Override
public void runTestOn(final String sdkHome) throws Exception {
final Project project = getProject();
final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.EMPTY_SDK);
setProcessCanTerminate(false);
PydevConsoleRunner consoleRunner = new PydevConsoleRunnerImpl(project, sdk, PyConsoleType.PYTHON, myFixture.getTempDirPath(), Maps.newHashMap(), PyConsoleOptions.getInstance(project).getPythonConsoleSettings(), (s) -> {
});
before();
myConsoleInitSemaphore = new Semaphore(0);
consoleRunner.addConsoleListener(new PydevConsoleRunnerImpl.ConsoleListener() {
@Override
public void handleConsoleInitialized(LanguageConsoleView consoleView) {
myConsoleInitSemaphore.release();
}
});
consoleRunner.run();
waitFor(myConsoleInitSemaphore);
myCommandSemaphore = new Semaphore(1);
myConsoleView = consoleRunner.getConsoleView();
myProcessHandler = consoleRunner.getProcessHandler();
myExecuteHandler = consoleRunner.getConsoleExecuteActionHandler();
myCommunication = consoleRunner.getPydevConsoleCommunication();
myCommunication.addCommunicationListener(new ConsoleCommunicationListener() {
@Override
public void commandExecuted(boolean more) {
myCommandSemaphore.release();
}
@Override
public void inputRequested() {
}
});
myProcessHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
if (event.getExitCode() != 0 && !myProcessCanTerminate) {
Assert.fail("Process terminated unexpectedly\n" + output());
}
}
});
OutputPrinter myOutputPrinter = null;
if (shouldPrintOutput) {
myOutputPrinter = new OutputPrinter();
myOutputPrinter.start();
}
waitForOutput("PyDev console");
try {
testing();
after();
} finally {
setProcessCanTerminate(true);
if (myOutputPrinter != null) {
myOutputPrinter.stop();
}
disposeConsole();
}
}
use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.
the class PyUnitTestTask method runConfiguration.
/**
* Run configuration.
*
* @param settings settings (if have any, null otherwise)
* @param config configuration to run
* @throws Exception
*/
protected void runConfiguration(@Nullable final RunnerAndConfigurationSettings settings, @NotNull final RunConfiguration config) throws Exception {
final ExecutionEnvironment environment;
if (settings == null) {
environment = ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), config).build();
} else {
environment = ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), settings).build();
}
//noinspection ConstantConditions
Assert.assertTrue(environment.getRunner().canRun(DefaultRunExecutor.EXECUTOR_ID, config));
before();
final com.intellij.util.concurrency.Semaphore s = new com.intellij.util.concurrency.Semaphore();
s.down();
myOutput = new StringBuilder();
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
try {
environment.getRunner().execute(environment, new ProgramRunner.Callback() {
@Override
public void processStarted(RunContentDescriptor descriptor) {
myDescriptor = descriptor;
myProcessHandler = myDescriptor.getProcessHandler();
myProcessHandler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
myOutput.append(event.getText());
}
});
myConsoleView = (SMTRunnerConsoleView) descriptor.getExecutionConsole();
myTestProxy = myConsoleView.getResultsViewer().getTestsRootNode();
myConsoleView.getResultsViewer().addEventsListener(new TestResultsViewer.SMEventsAdapter() {
@Override
public void onTestingFinished(TestResultsViewer sender) {
s.up();
}
});
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
Assert.assertTrue(s.waitFor(getTestTimeout()));
XDebuggerTestUtil.waitForSwing();
assertFinished();
Assert.assertTrue(output(), allTestsCount() > 0);
after();
disposeProcess(myProcessHandler);
}
Aggregations