From a7d840c0943dbc9ad3b5295959354f9e4c46f3f1 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Fri, 25 Mar 2011 16:02:55 +0300 Subject: [PATCH 1/2] Unwrap/remove action should not show implicit 'while' statement in JSP file. --- .../com/intellij/codeInsight/unwrap/JavaWhileUnwrapper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaWhileUnwrapper.java b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaWhileUnwrapper.java index 3910887fb119..4a2b3635c75d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaWhileUnwrapper.java +++ b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaWhileUnwrapper.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.unwrap; import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.psi.*; +import com.intellij.psi.impl.source.tree.java.PsiWhileStatementImpl; import com.intellij.util.IncorrectOperationException; public class JavaWhileUnwrapper extends JavaUnwrapper { @@ -25,7 +26,9 @@ public class JavaWhileUnwrapper extends JavaUnwrapper { } public boolean isApplicableTo(PsiElement e) { - return e instanceof PsiWhileStatement || e instanceof PsiDoWhileStatement; + return e instanceof PsiWhileStatementImpl // Don't use "e instanceof PsiWhileStatement" because JspWhileStatement intanceof PsiWhileStatement, + // but we doesn't support unwrap JspWhileStatement. + || e instanceof PsiDoWhileStatement; } @Override From 3b56ceee59eb878968b85f90fe491ccdbce7d168 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Fri, 25 Mar 2011 16:04:09 +0300 Subject: [PATCH 2/2] smrunner: in editable mode - flush buffer if chunk of text isn't part of a service message --- .../sm/SMCustomMessagesParsing.java | 5 +++- .../sm/SMTestRunnerConnectionUtil.java | 4 +-- .../OutputToGeneralTestEventsConverter.java | 29 +++++++++++++++++-- .../sm/runner/SMTRunnerConsoleProperties.java | 10 ++++--- .../testframework/TestConsoleProperties.java | 6 +++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/SMCustomMessagesParsing.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/SMCustomMessagesParsing.java index 0420bfbbd2d4..aca2118f3404 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/SMCustomMessagesParsing.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/SMCustomMessagesParsing.java @@ -15,13 +15,16 @@ */ package com.intellij.execution.testframework.sm; +import com.intellij.execution.testframework.TestConsoleProperties; import com.intellij.execution.testframework.sm.runner.OutputToGeneralTestEventsConverter; +import org.jetbrains.annotations.NotNull; /** * @author gregsh */ public interface SMCustomMessagesParsing { - OutputToGeneralTestEventsConverter createTestEventsConverter(final String testFrameworkName); + OutputToGeneralTestEventsConverter createTestEventsConverter(@NotNull final String testFrameworkName, + @NotNull final TestConsoleProperties consoleProperties); } 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 926310c5741c..04a0391b79d0 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestRunnerConnectionUtil.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestRunnerConnectionUtil.java @@ -179,8 +179,8 @@ public class SMTestRunnerConnectionUtil { @NotNull final String testFrameworkName) { //build messages consumer final OutputToGeneralTestEventsConverter outputConsumer = consoleProperties instanceof SMCustomMessagesParsing - ? ((SMCustomMessagesParsing)consoleProperties).createTestEventsConverter(testFrameworkName) - : new OutputToGeneralTestEventsConverter(testFrameworkName); + ? ((SMCustomMessagesParsing)consoleProperties).createTestEventsConverter(testFrameworkName, consoleProperties) + : new OutputToGeneralTestEventsConverter(testFrameworkName, consoleProperties); //events processor final GeneralToSMTRunnerEventsConvertor eventsProcessor = new GeneralToSMTRunnerEventsConvertor(resultsViewer.getTestsRootNode(), diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java index 72d25d4ae4ae..2f5a921a296d 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java @@ -16,6 +16,7 @@ package com.intellij.execution.testframework.sm.runner; import com.intellij.execution.process.ProcessOutputTypes; +import com.intellij.execution.testframework.TestConsoleProperties; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; @@ -41,10 +42,13 @@ import static com.intellij.execution.testframework.sm.runner.GeneralToSMTRunnerE */ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer { private static final Logger LOG = Logger.getInstance(OutputToGeneralTestEventsConverter.class.getName()); - + + private static final String TEAMCITY_SERVICE_MESSAGE_PREFIX = "##teamcity["; + private GeneralTestEventsProcessor myProcessor; private final MyServiceMessageVisitor myServiceMessageVisitor; private final String myTestFrameworkName; + private boolean myStdinSupportEnabled; private static class OutputChunk { private final Key myKey; @@ -70,10 +74,12 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer private final List myOutputChunks; - public OutputToGeneralTestEventsConverter(@NotNull final String testFrameworkName) { + public OutputToGeneralTestEventsConverter(@NotNull final String testFrameworkName, + @NotNull final TestConsoleProperties consoleProperties) { myTestFrameworkName = testFrameworkName; myServiceMessageVisitor = new MyServiceMessageVisitor(); myOutputChunks = new ArrayList(); + myStdinSupportEnabled = consoleProperties.isEditable(); } public void setProcessor(final GeneralTestEventsProcessor processor) { @@ -145,9 +151,28 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer if (lastChar == '\n' || lastChar == '\r') { // buffer contains consistent string flushStdOutputBuffer(); + } else { + // test framework may show some promt and ask user for smth. Question may not + // finish with \n or \r thus buffer wont be flushed and user will have to input smth + // before question. And question will became visible with next portion of text. + // Such behaviour is confusing. So + // 1. Let's assume that sevice messages starts with \n if console is editable + // 2. Then we can suggest that each service message will start from new line and buffer should + // be flushed before every service message. Thus if chunks list is empty and output doesn't end + // with \n or \r but starts with ##teamcity then it is a service message and should be buffered otherwise + // we can safely flush buffer. + + // TODO if editable: + if (myStdinSupportEnabled && !isMostLikelyServiceMessagePart(text)) { + flushStdOutputBuffer(); + } } } + protected boolean isMostLikelyServiceMessagePart(@NotNull final String text) { + return text.startsWith(TEAMCITY_SERVICE_MESSAGE_PREFIX); + } + private void processConsistentText(final String text, final Key outputType, boolean tcLikeFakeOutput) { try { final ServiceMessage serviceMessage = parseServiceMessage(text, outputType); diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerConsoleProperties.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerConsoleProperties.java index cab20db48634..bcbd4ba5260f 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerConsoleProperties.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerConsoleProperties.java @@ -20,6 +20,7 @@ import com.intellij.execution.configurations.RuntimeConfiguration; import com.intellij.execution.testframework.TestConsoleProperties; import com.intellij.ide.util.PropertiesComponent; import com.intellij.util.config.Storage; +import org.jetbrains.annotations.NotNull; /** * @author: Roman Chernyatchik @@ -32,11 +33,12 @@ public class SMTRunnerConsoleProperties extends TestConsoleProperties { * @param testFrameworkName Prefix for storage which keeps runner settings. E.g. "RubyTestUnit" * @param executor */ - public SMTRunnerConsoleProperties(final RuntimeConfiguration config, - final String testFrameworkName, - Executor executor) + public SMTRunnerConsoleProperties(@NotNull final RuntimeConfiguration config, + @NotNull final String testFrameworkName, + @NotNull final Executor executor) { - super(new Storage.PropertiesComponentStorage(testFrameworkName + "Support.", PropertiesComponent.getInstance()), config.getProject(), + super(new Storage.PropertiesComponentStorage(testFrameworkName + "Support.", PropertiesComponent.getInstance()), + config.getProject(), executor); myConfiguration = config; } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java index 52e6351a2ad9..57332b78d476 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java @@ -136,10 +136,14 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp * Allows to make console editable and disable/enable input sending in process stdin stream. * Normally tests shouldn't ask anything in stdin so console is view only by default. * - * NB: Process input support feature isn't fully implemented. Input text will be lost after + * NB1: Process input support feature isn't fully implemented. Input text will be lost after * switching to any other test/suite in tests results view. It's highly not recommended to change * default behaviour. Please do it only in critical cases and only if you are sure that you need this feature. * + * + * NB2: If you are using Service Messages based test runner please ensure that before each service message + * (e.g. #teamcity[...]) you always send "\n" to the output stream. + * * @return False for view-only mode and true for stdin support. */ public boolean isEditable() {