1 package com
.intellij
.execution
.testframework
.sm
;
3 import com
.intellij
.execution
.ExecutionException
;
4 import com
.intellij
.execution
.configurations
.CommandLineState
;
5 import com
.intellij
.execution
.configurations
.ConfigurationPerRunnerSettings
;
6 import com
.intellij
.execution
.configurations
.RunnerSettings
;
7 import com
.intellij
.execution
.configurations
.RuntimeConfiguration
;
8 import com
.intellij
.execution
.process
.ProcessAdapter
;
9 import com
.intellij
.execution
.process
.ProcessEvent
;
10 import com
.intellij
.execution
.process
.ProcessHandler
;
11 import com
.intellij
.execution
.testframework
.TestConsoleProperties
;
12 import com
.intellij
.execution
.testframework
.sm
.runner
.GeneralToSMTRunnerEventsConvertor
;
13 import com
.intellij
.execution
.testframework
.sm
.runner
.OutputToGeneralTestEventsConverter
;
14 import com
.intellij
.execution
.testframework
.sm
.runner
.SMTRunnerConsoleProperties
;
15 import com
.intellij
.execution
.testframework
.sm
.runner
.ui
.SMTRunnerConsoleView
;
16 import com
.intellij
.execution
.testframework
.sm
.runner
.ui
.SMTRunnerNotificationsHandler
;
17 import com
.intellij
.execution
.testframework
.sm
.runner
.ui
.SMTRunnerUIActionsHandler
;
18 import com
.intellij
.execution
.testframework
.sm
.runner
.ui
.SMTestRunnerResultsForm
;
19 import com
.intellij
.execution
.testframework
.sm
.runner
.ui
.statistics
.StatisticsPanel
;
20 import com
.intellij
.execution
.testframework
.ui
.BaseTestsOutputConsoleView
;
21 import com
.intellij
.execution
.ui
.ConsoleView
;
22 import com
.intellij
.openapi
.util
.Disposer
;
23 import com
.intellij
.openapi
.util
.Key
;
24 import org
.jetbrains
.annotations
.NotNull
;
25 import org
.jetbrains
.annotations
.Nullable
;
28 * @author Roman Chernyatchik
30 public class SMTestRunnerConnectionUtil
{
31 private SMTestRunnerConnectionUtil() {
32 // Do nothing. Utility class.
36 * Creates Test Runner console component with test tree, console, statistics tabs
37 * and attaches it to given Process handler.
39 * You can use this method in run configuration's CommandLineState. You should
40 * just override "execute" method of your custom command line state and return
41 * test runner's console.
43 * @param processHandler Process handler
44 * @param consoleProperties Console properties for test console actions
45 * @return Console view
46 * @throws ExecutionException If IDEA cannot execute process this Exception will
47 * be catched and shown in error message box
49 public static BaseTestsOutputConsoleView
attachRunner(@NotNull final ProcessHandler processHandler
,
50 @NotNull final TestConsoleProperties consoleProperties
,
51 final RunnerSettings runnerSettings
,
52 final ConfigurationPerRunnerSettings configurationSettings
,
53 final String splitterPropertyName
) throws ExecutionException
{
56 final SMTRunnerConsoleView testRunnerConsole
= new SMTRunnerConsoleView(consoleProperties
, runnerSettings
, configurationSettings
, splitterPropertyName
);
57 testRunnerConsole
.initUI();
58 final SMTestRunnerResultsForm resultsViewer
= testRunnerConsole
.getResultsViewer();
61 attachEventsProcessors(consoleProperties
, resultsViewer
, resultsViewer
.getStatisticsPane(), processHandler
);
62 testRunnerConsole
.attachToProcess(processHandler
);
64 return testRunnerConsole
;
68 * Creates Test Runner console component with test tree, console, statistics tabs
69 * and attaches it to given Process handler.
71 * You can use this method in run configuration's CommandLineState. You should
72 * just override "execute" method of your custom command line state and return
73 * test runner's console.
77 * public class MyCommandLineState extends CommandLineState {
82 * public ExecutionResult execute(@NotNull final Executor executor,
83 * @NotNull final ProgramRunner runner) throws ExecutionException {
85 * final ProcessHandler processHandler = startProcess();
86 * final AbstractRubyRunConfiguration runConfiguration = getConfig();
87 * final Project project = runConfiguration.getProject();
89 * final ConsoleView console =
90 * SMTestRunnerConnectionUtil.attachRunner(project, processHandler, this, runConfiguration,
91 * "MY_TESTRUNNER_SPLITTER_SETTINGS");
93 * return new DefaultExecutionResult(console, processHandler,
94 * createActions(console, processHandler));
99 * @param processHandler Process handler
100 * @param commandLineState Command line state
101 * @param config User run configuration settings
102 * @param splitterPropertyName This property will be used for storing splitter position.
103 * @return Console view
104 * @throws ExecutionException If IDEA cannot execute process this Exception will
105 * be catched and shown in error message box
107 public static ConsoleView
attachRunner(@NotNull final ProcessHandler processHandler
,
108 @NotNull final CommandLineState commandLineState
,
109 @NotNull final RuntimeConfiguration config
,
110 @Nullable final String splitterPropertyName
) throws ExecutionException
{
111 final TestConsoleProperties consoleProperties
= new SMTRunnerConsoleProperties(config
);
113 return attachRunner(processHandler
, consoleProperties
,
114 commandLineState
.getRunnerSettings(), commandLineState
.getConfigurationSettings(), splitterPropertyName
);
117 private static ProcessHandler
attachEventsProcessors(@NotNull final TestConsoleProperties consoleProperties
,
118 final SMTestRunnerResultsForm resultsViewer
,
119 final StatisticsPanel statisticsPane
,
120 final ProcessHandler processHandler
)
121 throws ExecutionException
{
123 //build messages consumer
124 final OutputToGeneralTestEventsConverter outputConsumer
= new OutputToGeneralTestEventsConverter();
127 final GeneralToSMTRunnerEventsConvertor eventsProcessor
= new GeneralToSMTRunnerEventsConvertor(resultsViewer
.getTestsRootNode());
130 final SMTRunnerUIActionsHandler uiActionsHandler
= new SMTRunnerUIActionsHandler(consoleProperties
);
132 final SMTRunnerNotificationsHandler notifierHandler
= new SMTRunnerNotificationsHandler(consoleProperties
);
134 // subscribe on events
136 // subscribes event processor on output consumer events
137 outputConsumer
.setProcessor(eventsProcessor
);
138 // subscribes result viewer on event processor
139 eventsProcessor
.addEventsListener(resultsViewer
);
140 // subscribes test runner's actions on results viewer events
141 resultsViewer
.addEventsListener(uiActionsHandler
);
142 // subscribes statistics tab viewer on event processor
143 eventsProcessor
.addEventsListener(statisticsPane
.createTestEventsListener());
144 // subscribes test runner's notification balloons on results viewer events
145 eventsProcessor
.addEventsListener(notifierHandler
);
147 processHandler
.addProcessListener(new ProcessAdapter() {
149 public void processTerminated(final ProcessEvent event
) {
150 Disposer
.dispose(eventsProcessor
);
151 Disposer
.dispose(outputConsumer
);
155 public void startNotified(final ProcessEvent event
) {
156 eventsProcessor
.onStartTesting();
160 public void processWillTerminate(ProcessEvent event
, boolean willBeDestroyed
) {
161 outputConsumer
.flushBufferBeforeTerminating();
162 eventsProcessor
.onFinishTesting();
166 public void onTextAvailable(final ProcessEvent event
, final Key outputType
) {
167 outputConsumer
.process(event
.getText(), outputType
);
170 return processHandler
;