Search in sources :

Example 6 with ExecutionConsole

use of com.intellij.execution.ui.ExecutionConsole in project intellij-plugins by JetBrains.

the class FlexBaseRunner method launchDebugProcess.

protected RunContentDescriptor launchDebugProcess(final Module module, final FlexBuildConfiguration bc, final BCBasedRunnerParameters params, final ExecutionEnvironment env) throws ExecutionException {
    final XDebugSession debugSession = XDebuggerManager.getInstance(module.getProject()).startSession(env, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) throws ExecutionException {
            try {
                if (params instanceof FlexUnitRunnerParameters) {
                    return new FlexDebugProcess(session, bc, params) {

                        @NotNull
                        @Override
                        public ExecutionConsole createConsole() {
                            try {
                                return createFlexUnitRunnerConsole(session.getProject(), env, getProcessHandler());
                            } catch (ExecutionException e) {
                                Logger.getInstance(FlexBaseRunner.class.getName()).error(e);
                            }
                            return super.createConsole();
                        }
                    };
                }
                return new FlexDebugProcess(session, bc, params);
            } catch (IOException e) {
                iosStopForwardTcpPortIfNeeded(bc, params);
                throw new ExecutionException(e.getMessage(), e);
            }
        }
    });
    debugSession.addSessionListener(new XDebugSessionListener() {

        @Override
        public void sessionStopped() {
            iosStopForwardTcpPortIfNeeded(bc, params);
        }
    });
    return debugSession.getRunContentDescriptor();
}
Also used : FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) FlexDebugProcess(com.intellij.lang.javascript.flex.debug.FlexDebugProcess) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ExecutionConsole

use of com.intellij.execution.ui.ExecutionConsole in project intellij-plugins by JetBrains.

the class FlexUnitExecutionTest method doTest.

private AbstractTestProxy doTest(boolean debugNotRun, FlexUnitRunnerParameters.Scope testScope, String testClassOrPackage, @Nullable String testMethod, @Nullable String projectRoot, @Nullable FlexUnitRunnerParameters.OutputLogLevel outputLogLevel, String... files) throws Exception {
    configureByFiles(projectRoot, files);
    final Ref<IXMLElement> expected = new Ref<>();
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> {
        try {
            Collection<IXMLElement> collection = JSTestUtils.extractXml(myEditor.getDocument(), "testResults");
            assertEquals("Invalid expected structure", 1, collection.size());
            expected.set(collection.iterator().next());
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }));
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> FlexTestUtils.modifyBuildConfiguration(myModule, configuration -> configuration.setTargetPlatform(myTargetPlatform))));
    final RunnerAndConfigurationSettings runnerAndConfigurationSettings = RunManager.getInstance(myProject).createRunConfiguration("test", FlexUnitRunConfigurationType.getFactory());
    final FlexUnitRunConfiguration flexUnitRunConfig = (FlexUnitRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
    final FlexUnitRunnerParameters params = flexUnitRunConfig.getRunnerParameters();
    params.setModuleName(myModule.getName());
    params.setBCName(FlexBuildConfigurationManager.getInstance(myModule).getBuildConfigurations()[0].getName());
    params.setOutputLogLevel(outputLogLevel);
    params.setScope(testScope);
    switch(testScope) {
        case Class:
            params.setClassName(testClassOrPackage);
            break;
        case Method:
            params.setClassName(testClassOrPackage);
            params.setMethodName(testMethod);
            break;
        case Package:
            params.setPackageName(testClassOrPackage);
            break;
        default:
            fail("Unknown scope: " + testScope);
    }
    flexUnitRunConfig.checkConfiguration();
    final ProgramRunner runner = new FlexUnitTestRunner();
    final Executor executor = debugNotRun ? DefaultDebugExecutor.getDebugExecutorInstance() : DefaultRunExecutor.getRunExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, runnerAndConfigurationSettings, getProject());
    final Semaphore compilation = new Semaphore();
    compilation.down();
    final Semaphore execution = new Semaphore();
    execution.down();
    final Semaphore startup = new Semaphore();
    final ProcessListener listener = new ProcessListener() {

        @Override
        public void startNotified(ProcessEvent event) {
            startup.up();
        }

        @Override
        public void processTerminated(ProcessEvent event) {
            execution.up();
        }

        @Override
        public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
        }

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            System.out.println("FlexUnit: " + event.getText());
        }
    };
    final Ref<ExecutionConsole> executionConsole = new Ref<>();
    ApplicationManager.getApplication().invokeLater(() -> {
        try {
            runner.execute(env, new ProgramRunner.Callback() {

                @Override
                public void processStarted(RunContentDescriptor descriptor) {
                    compilation.up();
                    startup.down();
                    descriptor.getProcessHandler().addProcessListener(listener);
                    executionConsole.set(descriptor.getExecutionConsole());
                }
            });
        } catch (Throwable t) {
            t.printStackTrace();
            fail(t.getMessage());
            compilation.up();
            startup.up();
            execution.up();
        }
    });
    if (!compilation.waitFor(COMPILATION_TIMEOUT * 1000)) {
        fail("Compilation did not succeed in " + COMPILATION_TIMEOUT + " seconds. There was an error or it took too long\n" + FlexCompilerHandler.getInstance(myProject).getLastCompilationMessages());
    }
    if (!startup.waitFor(STARTUP_TIMEOUT * 1000)) {
        fail("Process was not started in " + STARTUP_TIMEOUT + " seconds");
    }
    if (!execution.waitFor(EXECUTION_TIMEOUT * 1000)) {
        fail("Execution did not finish in " + EXECUTION_TIMEOUT + " seconds");
    }
    // give tests tree some time to stabilize
    Thread.sleep(200);
    final AbstractTestProxy testRoot = ((SMTRunnerConsoleView) executionConsole.get()).getResultsViewer().getRoot();
    checkResults(expected.get(), testRoot);
    if (outputLogLevel == null) {
        checkOutput(testRoot, outputLogLevel);
    }
    return testRoot;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) TargetPlatform(com.intellij.flex.model.bc.TargetPlatform) ServerSocket(java.net.ServerSocket) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) FlexCompilerHandler(com.intellij.lang.javascript.flex.build.FlexCompilerHandler) Semaphore(com.intellij.util.concurrency.Semaphore) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Map(java.util.Map) TestStateInfo(com.intellij.execution.testframework.sm.runner.states.TestStateInfo) FlexUnitRunConfigurationType(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfigurationType) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Collection(java.util.Collection) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable) Printable(com.intellij.execution.testframework.Printable) ProcessListener(com.intellij.execution.process.ProcessListener) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ProcessEvent(com.intellij.execution.process.ProcessEvent) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) Ref(com.intellij.openapi.util.Ref) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) CodeInsightTestCase(com.intellij.codeInsight.CodeInsightTestCase) WriteAction(com.intellij.openapi.application.WriteAction) JSTestOption(com.intellij.lang.javascript.JSTestOption) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) FlexUnitLibs(com.intellij.flex.util.FlexUnitLibs) HashMap(java.util.HashMap) CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension) IXMLElement(net.n3.nanoxml.IXMLElement) SocketTimeoutException(java.net.SocketTimeoutException) RunManager(com.intellij.execution.RunManager) ModuleType(com.intellij.openapi.module.ModuleType) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) ThrowableRunnable(com.intellij.util.ThrowableRunnable) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ProgramRunner(com.intellij.execution.runners.ProgramRunner) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) Key(com.intellij.openapi.util.Key) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) IOException(java.io.IOException) Executor(com.intellij.execution.Executor) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) JSTestUtils(com.intellij.lang.javascript.JSTestUtils) Printer(com.intellij.execution.testframework.Printer) FlexCompilerProjectConfiguration(com.intellij.lang.javascript.flex.build.FlexCompilerProjectConfiguration) Assert(org.junit.Assert) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Semaphore(com.intellij.util.concurrency.Semaphore) IXMLElement(net.n3.nanoxml.IXMLElement) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) Ref(com.intellij.openapi.util.Ref) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Key(com.intellij.openapi.util.Key)

Example 8 with ExecutionConsole

use of com.intellij.execution.ui.ExecutionConsole in project intellij-community by JetBrains.

the class DefaultJavaProgramRunner method addDefaultActions.

private static void addDefaultActions(@NotNull RunContentBuilder contentBuilder, @NotNull ExecutionResult executionResult) {
    final ExecutionConsole executionConsole = executionResult.getExecutionConsole();
    final JComponent consoleComponent = executionConsole != null ? executionConsole.getComponent() : null;
    final ControlBreakAction controlBreakAction = new ControlBreakAction(executionResult.getProcessHandler());
    if (consoleComponent != null) {
        controlBreakAction.registerCustomShortcutSet(controlBreakAction.getShortcutSet(), consoleComponent);
        final ProcessHandler processHandler = executionResult.getProcessHandler();
        assert processHandler != null : executionResult;
        processHandler.addProcessListener(new ProcessAdapter() {

            @Override
            public void processTerminated(final ProcessEvent event) {
                processHandler.removeProcessListener(this);
                controlBreakAction.unregisterCustomShortcutSet(consoleComponent);
            }
        });
    }
    contentBuilder.addAction(controlBreakAction);
    contentBuilder.addAction(new SoftExitAction(executionResult.getProcessHandler()));
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) CapturingProcessAdapter(com.intellij.execution.process.CapturingProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole)

Example 9 with ExecutionConsole

use of com.intellij.execution.ui.ExecutionConsole in project intellij-community by JetBrains.

the class PyExecuteSelectionAction method selectConsole.

private static void selectConsole(@NotNull DataContext dataContext, @NotNull Project project, final Consumer<PyCodeExecutor> consumer, Editor editor) {
    Collection<RunContentDescriptor> consoles = getConsoles(project);
    ExecutionHelper.selectContentDescriptor(dataContext, project, consoles, "Select console to execute in", descriptor -> {
        if (descriptor != null && descriptor.getExecutionConsole() instanceof PyCodeExecutor) {
            ExecutionConsole console = descriptor.getExecutionConsole();
            consumer.consume((PyCodeExecutor) console);
            if (console instanceof PythonDebugLanguageConsoleView) {
                XDebugSession currentSession = XDebuggerManager.getInstance(project).getCurrentSession();
                if (currentSession != null) {
                    ContentManager contentManager = currentSession.getUI().getContentManager();
                    Content content = contentManager.findContent("Console");
                    contentManager.setSelectedContent(content);
                    IdeFocusManager.findInstance().requestFocus(editor.getContentComponent(), true);
                }
            } else {
                PythonConsoleToolWindow consoleToolWindow = PythonConsoleToolWindow.getInstance(project);
                ToolWindow toolWindow = consoleToolWindow != null ? consoleToolWindow.getToolWindow() : null;
                if (toolWindow != null && !toolWindow.isVisible()) {
                    toolWindow.show(null);
                    ContentManager contentManager = toolWindow.getContentManager();
                    Content content = contentManager.findContent(descriptor.getDisplayName());
                    if (content != null) {
                        contentManager.setSelectedContent(content);
                    }
                }
            }
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) ToolWindow(com.intellij.openapi.wm.ToolWindow) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) Content(com.intellij.ui.content.Content) ContentManager(com.intellij.ui.content.ContentManager) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole)

Example 10 with ExecutionConsole

use of com.intellij.execution.ui.ExecutionConsole in project intellij-community by JetBrains.

the class PyEduDebugRunner method createDebugProcess.

@NotNull
@Override
protected PyDebugProcess createDebugProcess(@NotNull XDebugSession session, ServerSocket serverSocket, ExecutionResult result, PythonCommandLineState pyState) {
    ExecutionConsole executionConsole = result.getExecutionConsole();
    ProcessHandler processHandler = result.getProcessHandler();
    boolean isMultiProcess = pyState.isMultiprocessDebug();
    String scriptName = getScriptName(pyState);
    if (scriptName != null) {
        VirtualFile file = VfsUtil.findFileByIoFile(new File(scriptName), true);
        if (file != null) {
            int line = getBreakpointLineNumber(file, session.getProject());
            if (line != NO_LINE) {
                return new PyEduDebugProcess(session, serverSocket, executionConsole, processHandler, isMultiProcess, scriptName, line + 1);
            }
        }
    }
    LOG.info("Failed to create PyEduDebugProcess. PyDebugProcess created instead.");
    return new PyDebugProcess(session, serverSocket, executionConsole, processHandler, isMultiProcess);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PyDebugProcess(com.jetbrains.python.debugger.PyDebugProcess) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ExecutionConsole (com.intellij.execution.ui.ExecutionConsole)13 NotNull (org.jetbrains.annotations.NotNull)6 ProcessHandler (com.intellij.execution.process.ProcessHandler)5 RunnerLayoutUi (com.intellij.execution.ui.RunnerLayoutUi)3 Content (com.intellij.ui.content.Content)3 ProcessEvent (com.intellij.execution.process.ProcessEvent)2 ProgramRunner (com.intellij.execution.runners.ProgramRunner)2 SMTRunnerConsoleView (com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView)2 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)2 FlexUnitRunnerParameters (com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 XDebugTabLayouter (com.intellij.xdebugger.ui.XDebugTabLayouter)2 PythonDebugLanguageConsoleView (com.jetbrains.python.console.PythonDebugLanguageConsoleView)2 File (java.io.File)2 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 CodeInsightTestCase (com.intellij.codeInsight.CodeInsightTestCase)1 InstancesTracker (com.intellij.debugger.memory.component.InstancesTracker)1 MemoryViewDebugProcessData (com.intellij.debugger.memory.component.MemoryViewDebugProcessData)1 ClassesFilteredView (com.intellij.debugger.memory.ui.ClassesFilteredView)1