From 23fa1f8ee7f295d7ec507107f4a2873a7a2ee283 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Thu, 14 Jun 2012 18:26:46 +0400 Subject: [PATCH] custom Printer per SMTestProxy instance and its children --- .../sm/SMTestRunnerConnectionUtil.java | 15 +++++++--- ...eralIdBasedToSMTRunnerEventsConvertor.java | 15 ++++++++++ .../sm/runner/GeneralTestEventsProcessor.java | 2 ++ .../GeneralToSMTRunnerEventsConvertor.java | 4 +++ .../testframework/sm/runner/SMTestProxy.java | 26 ++++++++++++++-- .../sm/runner/TestProxyPrinterProvider.java | 30 +++++++++++++++++++ .../runner/events/BaseStartedNodeEvent.java | 28 ++++++++++++++++- .../sm/runner/events/TestStartedEvent.java | 10 +++++-- .../runner/events/TestSuiteStartedEvent.java | 10 +++++-- ...MockGeneralTestEventsProcessorAdapter.java | 4 +++ 10 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 platform/smRunner/src/com/intellij/execution/testframework/sm/runner/TestProxyPrinterProvider.java diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestRunnerConnectionUtil.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestRunnerConnectionUtil.java index 7c1567c9c435..2fe057da6a9b 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestRunnerConnectionUtil.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestRunnerConnectionUtil.java @@ -90,7 +90,8 @@ public class SMTestRunnerConnectionUtil { runnerSettings, configurationSettings, new CompositeTestLocationProvider(locator), - false); + false, + null); } public static SMTRunnerConsoleView createConsoleWithCustomLocator(@NotNull final String testFrameworkName, @@ -98,7 +99,8 @@ public class SMTestRunnerConnectionUtil { final RunnerSettings runnerSettings, final ConfigurationPerRunnerSettings configurationSettings, @Nullable final TestLocationProvider locator, - final boolean idBasedTreeConstruction) { + final boolean idBasedTreeConstruction, + @Nullable final TestProxyPrinterProvider printerProvider) { // Console final String splitterPropertyName = testFrameworkName + ".Splitter.Proportion"; final SMTRunnerConsoleView console = @@ -109,7 +111,8 @@ public class SMTestRunnerConnectionUtil { super.attachToProcess(processHandler); attachEventsProcessors(consoleProperties, getResultsViewer(), getResultsViewer().getStatisticsPane(), - processHandler, testFrameworkName, locator, idBasedTreeConstruction); + processHandler, testFrameworkName, locator, idBasedTreeConstruction, + printerProvider); } }; console.setHelpId("reference.runToolWindow.testResultsTab"); @@ -213,7 +216,8 @@ public class SMTestRunnerConnectionUtil { final ProcessHandler processHandler, @NotNull final String testFrameworkName, @Nullable final TestLocationProvider locator, - boolean idBasedTreeConstruction) { + boolean idBasedTreeConstruction, + @Nullable TestProxyPrinterProvider printerProvider) { //build messages consumer final OutputToGeneralTestEventsConverter outputConsumer; if (consoleProperties instanceof SMCustomMessagesParsing) { @@ -233,6 +237,9 @@ public class SMTestRunnerConnectionUtil { if (locator != null) { eventsProcessor.setLocator(locator); } + if (printerProvider != null) { + eventsProcessor.setPrinterProvider(printerProvider); + } // ui actions final SMTRunnerUIActionsHandler uiActionsHandler = new SMTRunnerUIActionsHandler(consoleProperties); diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java index 88ce640ae88f..6c9e4153429f 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java @@ -18,6 +18,7 @@ package com.intellij.execution.testframework.sm.runner; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.intellij.execution.process.ProcessOutputTypes; +import com.intellij.execution.testframework.Printer; import com.intellij.execution.testframework.sm.SMRunnerUtil; import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil; import com.intellij.execution.testframework.sm.runner.events.*; @@ -48,6 +49,7 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor implements GeneralTestEven private final String myTestFrameworkName; private boolean myIsTestingFinished = false; private TestLocationProvider myLocator = null; + private TestProxyPrinterProvider myTestProxyPrinterProvider = null; public GeneralIdBasedToSMTRunnerEventsConvertor(@NotNull SMTestProxy.SMRootTestProxy testsRootProxy, @NotNull String testFrameworkName) { @@ -112,6 +114,11 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor implements GeneralTestEven }); } + @Override + public void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider) { + myTestProxyPrinterProvider = printerProvider; + } + public void onTestStarted(@NotNull final TestStartedEvent testStartedEvent) { SMRunnerUtil.addToInvokeLater(new Runnable() { public void run() { @@ -145,6 +152,14 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor implements GeneralTestEven } SMTestProxy childProxy = new SMTestProxy(startedNodeEvent.getName(), suite, startedNodeEvent.getLocationUrl(), true); + TestProxyPrinterProvider printerProvider = myTestProxyPrinterProvider; + String nodeType = startedNodeEvent.getNodeType(); + if (printerProvider != null && nodeType != null) { + Printer printer = printerProvider.getPrinterByType(nodeType, startedNodeEvent.getNodeArgs()); + if (printer != null) { + childProxy.setPreferredPrinter(printer); + } + } childNode = new Node(startedNodeEvent.getId(), parentNode, childProxy); myNodeByIdMap.put(nodeId, childNode); myRunningNodes.add(childNode); diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java index 62f9564789df..98f62d10ff1a 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java @@ -74,4 +74,6 @@ public interface GeneralTestEventsProcessor extends Disposable { void addEventsListener(@NotNull SMTRunnerEventsListener viewer); void onFinishTesting(); + + void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider); } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java index 2e38c07d0594..4f6d1357283e 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java @@ -113,6 +113,10 @@ public class GeneralToSMTRunnerEventsConvertor implements GeneralTestEventsProce }); } + @Override + public void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider) { + } + public void onTestStarted(@NotNull final TestStartedEvent testStartedEvent) { SMRunnerUtil.addToInvokeLater(new Runnable() { public void run() { diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java index edc1b91d5391..c8833bd7de58 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java @@ -60,6 +60,7 @@ public class SMTestProxy extends AbstractTestProxy { private boolean myIsEmpty = true; TestLocationProvider myLocator = null; private final boolean myPreservePresentableName; + private Printer myPreferredPrinter = null; public SMTestProxy(final String testName, final boolean isSuite, @Nullable final String locationUrl) { @@ -79,6 +80,10 @@ public class SMTestProxy extends AbstractTestProxy { myLocator = locator; } + public void setPreferredPrinter(@NotNull Printer preferredPrinter) { + myPreferredPrinter = preferredPrinter; + } + public boolean isInProgress() { //final SMTestProxy parent = getParent(); @@ -172,8 +177,24 @@ public class SMTestProxy extends AbstractTestProxy { // if parent is being printed then all childs output // should be also send to the same printer child.setPrinter(myPrinter); + if (myPreferredPrinter != null && child.myPreferredPrinter == null) { + child.setPreferredPrinter(myPreferredPrinter); + } } + @Nullable + private Printer getRightPrinter(@Nullable Printer printer) { + if (myPreferredPrinter != null && printer != null) { + return myPreferredPrinter; + } + return printer; + } + + public void setPrinter(Printer printer) { + super.setPrinter(getRightPrinter(printer)); + } + + public String getName() { return myName; } @@ -397,13 +418,14 @@ public class SMTestProxy extends AbstractTestProxy { * @param printer Printer */ public void printOn(final Printer printer) { - super.printOn(printer); + final Printer rightPrinter = getRightPrinter(printer); + super.printOn(rightPrinter); invokeInAlarm(new Runnable() { @Override public void run() { //Tests State, that provide and formats additional output - myState.printOn(printer); + myState.printOn(rightPrinter); } }); } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/TestProxyPrinterProvider.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/TestProxyPrinterProvider.java new file mode 100644 index 000000000000..7ce468d5d1f5 --- /dev/null +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/TestProxyPrinterProvider.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.testframework.sm.runner; + +import com.intellij.execution.testframework.Printer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Sergey Simonchik + */ +public interface TestProxyPrinterProvider { + + @Nullable + Printer getPrinterByType(@NotNull String nodeType, @Nullable String arguments); + +} diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/BaseStartedNodeEvent.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/BaseStartedNodeEvent.java index 9182d4619b8d..8d597ecbd439 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/BaseStartedNodeEvent.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/BaseStartedNodeEvent.java @@ -26,14 +26,20 @@ public abstract class BaseStartedNodeEvent extends TreeNodeEvent { private final int myParentId; private final String myLocationUrl; + private final String myNodeType; + private final String myNodeArgs; protected BaseStartedNodeEvent(@NotNull String name, int id, int parentId, - @Nullable final String locationUrl) { + @Nullable final String locationUrl, + @Nullable String nodeType, + @Nullable String nodeArgs) { super(name, id); myParentId = parentId; myLocationUrl = locationUrl; + myNodeType = nodeType; + myNodeArgs = nodeArgs; validate(); } @@ -58,6 +64,16 @@ public abstract class BaseStartedNodeEvent extends TreeNodeEvent { return myLocationUrl; } + @Nullable + public String getNodeType() { + return myNodeType; + } + + @Nullable + public String getNodeArgs() { + return myNodeArgs; + } + @Override protected void appendToStringInfo(@NotNull StringBuilder buf) { append(buf, "parentId", myParentId); @@ -68,4 +84,14 @@ public abstract class BaseStartedNodeEvent extends TreeNodeEvent { return TreeNodeEvent.getIntAttribute(message, "parentNodeId"); } + @Nullable + public static String getNodeType(@NotNull MessageWithAttributes message) { + return message.getAttributes().get("nodeType"); + } + + @Nullable + public static String getNodeArgs(@NotNull MessageWithAttributes message) { + return message.getAttributes().get("nodeArgs"); + } + } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestStartedEvent.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestStartedEvent.java index 05ba2638e401..c1e15f87f012 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestStartedEvent.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestStartedEvent.java @@ -26,11 +26,15 @@ public class TestStartedEvent extends BaseStartedNodeEvent { public TestStartedEvent(@NotNull TestStarted testStarted, @Nullable String locationUrl) { - super(testStarted.getTestName(), TreeNodeEvent.getNodeId(testStarted), - getParentNodeId(testStarted), locationUrl); + super(testStarted.getTestName(), + TreeNodeEvent.getNodeId(testStarted), + getParentNodeId(testStarted), + locationUrl, + BaseStartedNodeEvent.getNodeType(testStarted), + BaseStartedNodeEvent.getNodeArgs(testStarted)); } public TestStartedEvent(@NotNull String name, @Nullable String locationUrl) { - super(name, -1, -1, locationUrl); + super(name, -1, -1, locationUrl, null, null); } } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestSuiteStartedEvent.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestSuiteStartedEvent.java index 4c761e7471a1..89b279e7a905 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestSuiteStartedEvent.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestSuiteStartedEvent.java @@ -26,12 +26,16 @@ public class TestSuiteStartedEvent extends BaseStartedNodeEvent { public TestSuiteStartedEvent(@NotNull TestSuiteStarted suiteStarted, @Nullable String locationUrl) { - super(suiteStarted.getSuiteName(), TreeNodeEvent.getNodeId(suiteStarted), - getParentNodeId(suiteStarted), locationUrl); + super(suiteStarted.getSuiteName(), + TreeNodeEvent.getNodeId(suiteStarted), + getParentNodeId(suiteStarted), + locationUrl, + BaseStartedNodeEvent.getNodeType(suiteStarted), + BaseStartedNodeEvent.getNodeArgs(suiteStarted)); } public TestSuiteStartedEvent(@NotNull String name, @Nullable String locationUrl) { - super(name, -1, -1, locationUrl); + super(name, -1, -1, locationUrl, null, null); } } diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/MockGeneralTestEventsProcessorAdapter.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/MockGeneralTestEventsProcessorAdapter.java index 822e4e11520b..c4177badf2b7 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/MockGeneralTestEventsProcessorAdapter.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/MockGeneralTestEventsProcessorAdapter.java @@ -100,6 +100,10 @@ public class MockGeneralTestEventsProcessorAdapter implements GeneralTestEventsP public void onFinishTesting() { } + @Override + public void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider) { + } + @Override public void dispose() { myOutputBuffer.setLength(0);