Search in sources :

Example 1 with WriteAction

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();
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) WriteAction(com.intellij.openapi.application.WriteAction) AbstractPythonRunConfigurationParams(com.jetbrains.python.run.AbstractPythonRunConfigurationParams) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with WriteAction

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;
    }
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) ExecutionResult(com.intellij.execution.ExecutionResult) ExecutionResult(com.intellij.execution.ExecutionResult) Result(com.intellij.openapi.application.Result)

Example 3 with WriteAction

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);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PyDebugRunner(com.jetbrains.python.debugger.PyDebugRunner) Semaphore(java.util.concurrent.Semaphore) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) PyDebugProcess(com.jetbrains.python.debugger.PyDebugProcess) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) PythonCommandLineState(com.jetbrains.python.run.PythonCommandLineState) WriteAction(com.intellij.openapi.application.WriteAction) ProcessEvent(com.intellij.execution.process.ProcessEvent) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) RunProfile(com.intellij.execution.configurations.RunProfile) Project(com.intellij.openapi.project.Project) Key(com.intellij.openapi.util.Key)

Example 4 with WriteAction

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();
}
Also used : IdeaTestFixtureFactory(com.intellij.testFramework.fixtures.IdeaTestFixtureFactory) WriteAction(com.intellij.openapi.application.WriteAction) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 5 with WriteAction

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;
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)85 WriteAction (com.intellij.openapi.application.WriteAction)85 NotNull (org.jetbrains.annotations.NotNull)38 VirtualFile (com.intellij.openapi.vfs.VirtualFile)37 File (java.io.File)20 IOException (java.io.IOException)16 Module (com.intellij.openapi.module.Module)10 PsiFile (com.intellij.psi.PsiFile)7 Sdk (com.intellij.openapi.projectRoots.Sdk)5 RunResult (com.intellij.openapi.application.RunResult)4 Document (com.intellij.openapi.editor.Document)4 Project (com.intellij.openapi.project.Project)4 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)4 Library (com.intellij.openapi.roots.libraries.Library)4 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)4 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 FacetManager (com.intellij.facet.FacetManager)2 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)2