use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class ConfigurationBasedProcessRunner method createExecutionEnvironment.
@NotNull
private ExecutionEnvironment createExecutionEnvironment(@NotNull final String sdkPath, @NotNull final Project project, @NotNull final String workingDir) throws ExecutionException {
final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration("test", myConfigurationFactory);
final AbstractPythonRunConfigurationParams config = (AbstractPythonRunConfigurationParams) settings.getConfiguration();
assert myExpectedConfigurationType.isInstance(config) : String.format("Expected configuration %s, but got %s", myExpectedConfigurationType, config.getClass());
// Checked by assert
@SuppressWarnings("unchecked") final CONF_T castedConfiguration = (CONF_T) config;
castedConfiguration.setSdkHome(sdkPath);
castedConfiguration.setWorkingDirectory(workingDir);
new WriteAction() {
@Override
protected void run(@NotNull final Result result) throws Throwable {
configurationCreatedAndWillLaunch(castedConfiguration);
RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
}
}.execute();
// Execute
final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
return ExecutionEnvironmentBuilder.create(executor, settings).build();
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class PyBaseDebuggerTask method finishSession.
protected void finishSession() throws InterruptedException {
disposeDebugProcess();
if (mySession != null) {
new WriteAction() {
protected void run(@NotNull Result result) throws Throwable {
mySession.stop();
}
}.execute();
//wait for process termination after session.stop() which is async
waitFor(mySession.getDebugProcess().getProcessHandler());
XDebuggerTestUtil.disposeDebugSession(mySession);
mySession = null;
myDebugProcess = null;
myPausedSemaphore = null;
}
final ExecutionResult result = myExecutionResult;
if (myExecutionResult != null) {
UIUtil.invokeLaterIfNeeded(() -> Disposer.dispose(result.getExecutionConsole()));
myExecutionResult = null;
}
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class PyDebuggerTask method runTestOn.
public void runTestOn(String sdkHome) throws Exception {
final Project project = getProject();
final ConfigurationFactory factory = PythonConfigurationType.getInstance().getConfigurationFactories()[0];
final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration("test", factory);
myRunConfiguration = (PythonRunConfiguration) settings.getConfiguration();
myRunConfiguration.setSdkHome(sdkHome);
myRunConfiguration.setScriptName(getScriptName());
myRunConfiguration.setWorkingDirectory(myFixture.getTempDirPath());
myRunConfiguration.setScriptParameters(getScriptParameters());
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
}
}.execute();
final PyDebugRunner runner = (PyDebugRunner) ProgramRunnerUtil.getRunner(getExecutorId(), settings);
Assert.assertTrue(runner.canRun(getExecutorId(), myRunConfiguration));
final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();
final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, settings, project);
final PythonCommandLineState pyState = (PythonCommandLineState) myRunConfiguration.getState(executor, env);
assert pyState != null;
pyState.setMultiprocessDebug(isMultiprocessDebug());
final ServerSocket serverSocket;
try {
//noinspection SocketOpenedButNotSafelyClosed
serverSocket = new ServerSocket(0);
} catch (IOException e) {
throw new ExecutionException("Failed to find free socket port", e);
}
final int serverLocalPort = serverSocket.getLocalPort();
final RunProfile profile = env.getRunProfile();
//turn off exception breakpoints by default
PythonDebuggerTest.createExceptionBreak(myFixture, false, false, false);
before();
setProcessCanTerminate(false);
myTerminateSemaphore = new Semaphore(0);
new WriteAction<ExecutionResult>() {
@Override
protected void run(@NotNull Result<ExecutionResult> result) throws Throwable {
myExecutionResult = pyState.execute(executor, runner.createCommandLinePatchers(myFixture.getProject(), pyState, profile, serverLocalPort));
mySession = XDebuggerManager.getInstance(getProject()).startSession(env, new XDebugProcessStarter() {
@NotNull
public XDebugProcess start(@NotNull final XDebugSession session) {
myDebugProcess = new PyDebugProcess(session, serverSocket, myExecutionResult.getExecutionConsole(), myExecutionResult.getProcessHandler(), isMultiprocessDebug());
StringBuilder output = new StringBuilder();
myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
output.append(event.getText());
}
@Override
public void processTerminated(ProcessEvent event) {
myTerminateSemaphore.release();
if (event.getExitCode() != 0 && !myProcessCanTerminate) {
Assert.fail("Process terminated unexpectedly\n" + output.toString());
}
}
});
myDebugProcess.getProcessHandler().startNotify();
return myDebugProcess;
}
});
result.setResult(myExecutionResult);
}
}.execute().getResultObject();
OutputPrinter myOutputPrinter = null;
if (shouldPrintOutput) {
myOutputPrinter = new OutputPrinter();
myOutputPrinter.start();
}
myPausedSemaphore = new Semaphore(0);
mySession.addSessionListener(new XDebugSessionListener() {
@Override
public void sessionPaused() {
if (myPausedSemaphore != null) {
myPausedSemaphore.release();
}
}
});
doTest(myOutputPrinter);
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class HighlightingTestBase method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
final IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory();
myTestFixture = createFixture(factory);
myTestFixture.setTestDataPath(getTestDataBasePath() + getTestDataPath());
Class<? extends LocalInspectionTool>[] inspectionClasses = new DefaultInspectionProvider().getInspectionClasses();
if (getName().contains("Inspection")) {
inspectionClasses = ArrayUtil.mergeArrays(inspectionClasses, ApplicationLoader.getInspectionClasses());
}
myTestFixture.setUp();
myTestFixture.enableInspections(inspectionClasses);
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
ResourceUtil.copyFiles(HighlightingTestBase.this);
init();
}
}.execute().throwException();
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class DependenciesImportingTest method testSaveJdkPositionSystemDependency.
public void testSaveJdkPositionSystemDependency() throws Exception {
createProjectPom("<groupId>test</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency>" + " <groupId>test</groupId>" + " <artifactId>systemDep</artifactId>" + " <version>1</version>" + " <scope>system</scope>" + " <systemPath>${java.home}/lib/rt.jar</systemPath>" + " </dependency>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.0</version>" + " </dependency>" + "</dependencies>");
importProject();
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
ModifiableRootModel rootModel = ModuleRootManager.getInstance(getModule("m1")).getModifiableModel();
OrderEntry[] orderEntries = rootModel.getOrderEntries().clone();
assert orderEntries.length == 4;
assert orderEntries[0] instanceof JdkOrderEntry;
assert orderEntries[1] instanceof ModuleSourceOrderEntry;
assert "Maven: test:systemDep:1".equals(((LibraryOrderEntry) orderEntries[2]).getLibraryName());
assert "Maven: junit:junit:4.0".equals(((LibraryOrderEntry) orderEntries[3]).getLibraryName());
rootModel.rearrangeOrderEntries(new OrderEntry[] { orderEntries[2], orderEntries[3], orderEntries[0], orderEntries[1] });
rootModel.commit();
}
}.execute();
resolveDependenciesAndImport();
// JDK position was saved
OrderEntry[] orderEntries = ModuleRootManager.getInstance(getModule("m1")).getOrderEntries();
assert orderEntries.length == 4;
assert "Maven: test:systemDep:1".equals(((LibraryOrderEntry) orderEntries[0]).getLibraryName());
assert "Maven: junit:junit:4.0".equals(((LibraryOrderEntry) orderEntries[1]).getLibraryName());
assert orderEntries[2] instanceof JdkOrderEntry;
assert orderEntries[3] instanceof ModuleSourceOrderEntry;
}
Aggregations