GradleTestsExecutionConsole (@NotNull Project project, @NotNull ExternalSystemTask task, @Nullable ExecutionEnvironment env, @Nullable ProcessHandler processHandler) { if (env == null) return null; RunConfiguration configuration; SMTRunnerConsoleProperties consoleProperties = null; RunnerAndConfigurationSettings settings = env.getRunnerAndConfigurationSettings(); if (settings == null) { RunProfile runProfile = env.getRunProfile(); if (runProfile instanceof AbstractImportTestsAction.ImportRunProfile) { configuration = ((AbstractImportTestsAction.ImportRunProfile)runProfile).getInitialConfiguration(); if (configuration instanceof SMRunnerConsolePropertiesProvider) { consoleProperties = ((SMRunnerConsolePropertiesProvider)configuration).createTestConsoleProperties(DefaultRunExecutor.getRunExecutorInstance()); } } else { return null; } } else { configuration = settings.getConfiguration(); } if (!(configuration instanceof ExternalSystemRunConfiguration externalSystemRunConfiguration)) return null; if (consoleProperties == null) { consoleProperties = new GradleConsoleProperties(externalSystemRunConfiguration, env.getExecutor()); } String testFrameworkName = externalSystemRunConfiguration.getSettings().getExternalSystemId().getReadableName(); String splitterPropertyName = SMTestRunnerConnectionUtil.getSplitterPropertyName(testFrameworkName); GradleTestsExecutionConsole consoleView = new GradleTestsExecutionConsole(project, task.getId(), consoleProperties, splitterPropertyName); SMTestRunnerConnectionUtil.initConsoleView(consoleView, testFrameworkName); SMTestRunnerResultsForm resultsViewer = consoleView.getResultsViewer(); final TestTreeView testTreeView = resultsViewer.getTreeView(); if (testTreeView != null) { TestTreeRenderer originalRenderer = ObjectUtils.tryCast(testTreeView.getCellRenderer(), TestTreeRenderer.class); if (originalRenderer != null) { originalRenderer.setAdditionalRootFormatter(new SMRootTestProxyFormatter() { @Override public void format(@NotNull SMTestProxy.SMRootTestProxy testProxy, @NotNull TestTreeRenderer renderer) { if (!testProxy.isInProgress() && testProxy.isEmptySuite()) { renderer.clear(); renderer.append(GradleBundle.message( "gradle.test.runner.ui.tests.tree.presentation.labels.no.tests.were.found"), SimpleTextAttributes.REGULAR_ATTRIBUTES ); } } }); } } SMTestProxy.SMRootTestProxy testsRootNode = resultsViewer.getTestsRootNode(); testsRootNode.setExecutionId(env.getExecutionId()); testsRootNode.setSuiteStarted(); consoleView.getEventPublisher().onTestingStarted(testsRootNode); if (processHandler != null) { processHandler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(@NotNull ProcessEvent event) { if (testsRootNode.isInProgress()) { ApplicationManager.getApplication().invokeLater(() -> { if (event.getExitCode() == 1) { testsRootNode.setTestFailed("", null, false); } else { testsRootNode.setFinished(); } resultsViewer.onBeforeTestingFinished(testsRootNode); resultsViewer.onTestingFinished(testsRootNode); }); } } }); } if (task instanceof ExternalSystemExecuteTaskTask) { consoleView.addMessageFilter(new ReRunTaskFilter((ExternalSystemExecuteTaskTask)task, env)); } Disposable disposable = Disposer.newDisposable(consoleView, "Gradle test runner build event listener disposable"); BuildViewManager buildViewManager = project.getService(BuildViewManager.class); project.getService(ExternalSystemRunConfigurationViewManager.class).addListener(new BuildProgressListener() { @Override public void onEvent(@NotNull Object buildId, @NotNull BuildEvent event) { if (buildId != task.getId()) return; if (event instanceof FinishBuildEvent) { Disposer.dispose(disposable); } else if (event instanceof StartBuildEvent) { // override start build event to use different execution console, toolbar actions etc. BuildDescriptor buildDescriptor = ((StartBuildEvent)event).getBuildDescriptor(); DefaultBuildDescriptor defaultBuildDescriptor = new DefaultBuildDescriptor(buildDescriptor.getId(), buildDescriptor.getTitle(), buildDescriptor.getWorkingDir(), buildDescriptor.getStartTime()); // do not open Build tw for any error messages as it can be tests failure events defaultBuildDescriptor.setActivateToolWindowWhenFailed(false); event = new StartBuildEventImpl(defaultBuildDescriptor, event.getMessage()); } buildViewManager.onEvent(buildId, event); if (event instanceof StartEvent) { ProgressBuildEventImpl progressBuildEvent = new ProgressBuildEventImpl(event.getId(), event.getParentId(), event.getEventTime(), event.getMessage(), -1, -1, ""); progressBuildEvent.setHint("- " + GradleBundle.message("gradle.test.runner.build.tw.link.title")); buildViewManager.onEvent(buildId, progressBuildEvent); } maybeOpenBuildToolWindow(event, project, testsRootNode); } }, disposable); return consoleView; }