diff --git a/platform/lang-impl/src/com/intellij/execution/filters/TextConsoleBuilderImpl.java b/platform/lang-impl/src/com/intellij/execution/filters/TextConsoleBuilderImpl.java index 30b49a45d29a..773e5201278a 100644 --- a/platform/lang-impl/src/com/intellij/execution/filters/TextConsoleBuilderImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/filters/TextConsoleBuilderImpl.java @@ -62,4 +62,19 @@ public class TextConsoleBuilderImpl extends TextConsoleBuilder { myViewer = isViewer; } + protected Project getProject() { + return myProject; + } + + protected GlobalSearchScope getScope() { + return myScope; + } + + protected ArrayList getFilters() { + return myFilters; + } + + protected boolean isViewer() { + return myViewer; + } } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleState.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleState.java index ef19d65e6da9..d1fe83536f95 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleState.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleState.java @@ -16,28 +16,15 @@ package com.intellij.execution.impl; -import com.intellij.execution.process.ProcessAdapter; -import com.intellij.execution.process.ProcessEvent; import com.intellij.execution.process.ProcessHandler; -import com.intellij.execution.ui.ConsoleViewContentType; -import com.intellij.execution.ExecutionBundle; -import com.intellij.openapi.util.Key; +import org.jetbrains.annotations.NotNull; import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; public abstract class ConsoleState { - public static final ConsoleState NOT_STARTED = new ConsoleState(){ - public ConsoleState attachTo(final ConsoleViewImpl console, final ProcessHandler processHandler) { - return new RunningState(console, processHandler); - } - }; - - public ConsoleState dispose() { - return NOT_STARTED; - } + public abstract ConsoleState attachTo(ConsoleViewImpl console, ProcessHandler processHandler); + @NotNull + public abstract ConsoleState dispose(); public boolean isFinished() { return false; @@ -49,50 +36,17 @@ public abstract class ConsoleState { public void sendUserInput(final String input) throws IOException {} - public abstract ConsoleState attachTo(ConsoleViewImpl console, ProcessHandler processHandler); - - private static class RunningState extends ConsoleState { - private final ConsoleViewImpl myConsole; - private final ProcessAdapter myProcessListener = new ProcessAdapter() { - public void onTextAvailable(final ProcessEvent event, final Key outputType) { - myConsole.print(event.getText(), ConsoleViewContentType.getConsoleViewType(outputType)); - } - }; - private final ProcessHandler myProcessHandler; - private final Writer myUserInputWriter; - - public RunningState(final ConsoleViewImpl console, final ProcessHandler processHandler) { - myConsole = console; - myProcessHandler = processHandler; - processHandler.addProcessListener(myProcessListener); - final OutputStream processInput = myProcessHandler.getProcessInput(); - myUserInputWriter = processInput != null ? new OutputStreamWriter(processInput) : null; - } - + public abstract static class NotStartedStated extends ConsoleState { + @NotNull + @Override public ConsoleState dispose() { - if (myProcessHandler != null) { - myProcessHandler.removeProcessListener(myProcessListener); - } - return NOT_STARTED; + // not disposable + return this; } - public boolean isFinished() { - return myProcessHandler == null || myProcessHandler.isProcessTerminated(); - } - - public boolean isRunning() { - return myProcessHandler != null && !myProcessHandler.isProcessTerminated(); - } - - public void sendUserInput(final String input) throws IOException { - if (myUserInputWriter == null) - throw new IOException(ExecutionBundle.message("no.user.process.input.error.message")); - myUserInputWriter.write(input); - myUserInputWriter.flush(); - } - - public ConsoleState attachTo(final ConsoleViewImpl console, final ProcessHandler processHandler) { - return dispose().attachTo(console, processHandler); + @Override + public String toString() { + return "Not started state"; } } } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index c7527036d028..91b44e999751 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -147,7 +147,8 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo private final DisposedPsiManagerCheck myPsiDisposedCheck; private final boolean isViewer; - private ConsoleState myState = ConsoleState.NOT_STARTED; + private ConsoleState myState; + private Computable myStateForUpdate; private static int getCycleBufferSize() { @@ -366,8 +367,20 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo } public ConsoleViewImpl(final Project project, GlobalSearchScope searchScope, boolean viewer, FileType fileType) { + this(project, searchScope, viewer, fileType, + new ConsoleState.NotStartedStated() { + @Override + public ConsoleState attachTo(ConsoleViewImpl console, ProcessHandler processHandler) { + return new ConsoleViewRunningState(console, processHandler, this, true, true); + } + }); + } + + protected ConsoleViewImpl(final Project project, GlobalSearchScope searchScope, boolean viewer, FileType fileType, + @NotNull final ConsoleState initialState) { super(new BorderLayout()); isViewer = viewer; + myState = initialState; myPsiDisposedCheck = new DisposedPsiManagerCheck(project); myProject = project; myFileType = fileType; @@ -1061,7 +1074,10 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo } }); - setEditorUpActions(editor); + if (!isViewer) { + setEditorUpActions(editor); + } + return editor; } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewRunningState.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewRunningState.java new file mode 100644 index 000000000000..59773c09ce9f --- /dev/null +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewRunningState.java @@ -0,0 +1,98 @@ +/* + * Copyright 2000-2011 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.impl; + +import com.intellij.execution.ExecutionBundle; +import com.intellij.execution.process.ProcessAdapter; +import com.intellij.execution.process.ProcessEvent; +import com.intellij.execution.process.ProcessHandler; +import com.intellij.execution.ui.ConsoleViewContentType; +import com.intellij.openapi.util.Key; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; + + +public class ConsoleViewRunningState extends ConsoleState { + private final ConsoleViewImpl myConsole; + private final ProcessHandler myProcessHandler; + private final ConsoleState myFinishedStated; + private final Writer myUserInputWriter; + + private final ProcessAdapter myProcessListener = new ProcessAdapter() { + public void onTextAvailable(final ProcessEvent event, final Key outputType) { + myConsole.print(event.getText(), ConsoleViewContentType.getConsoleViewType(outputType)); + } + }; + + public ConsoleViewRunningState(final ConsoleViewImpl console, final ProcessHandler processHandler, + final ConsoleState finishedStated, + final boolean attachToStdOut, + final boolean attachToStdIn) { + + myConsole = console; + myProcessHandler = processHandler; + myFinishedStated = finishedStated; + + // attach to process stdout + if (attachToStdOut) { + processHandler.addProcessListener(myProcessListener); + } + + // attach to process stdin + if (attachToStdIn) { + final OutputStream processInput = myProcessHandler.getProcessInput(); + myUserInputWriter = processInput != null ? new OutputStreamWriter(processInput) : null; + } else { + myUserInputWriter = null; + } + } + + @NotNull + public ConsoleState dispose() { + if (myProcessHandler != null) { + myProcessHandler.removeProcessListener(myProcessListener); + } + return myFinishedStated; + } + + public boolean isFinished() { + return myProcessHandler == null || myProcessHandler.isProcessTerminated(); + } + + public boolean isRunning() { + return myProcessHandler != null && !myProcessHandler.isProcessTerminated(); + } + + public void sendUserInput(final String input) throws IOException { + if (myUserInputWriter == null) + throw new IOException(ExecutionBundle.message("no.user.process.input.error.message")); + myUserInputWriter.write(input); + myUserInputWriter.flush(); + } + + public ConsoleState attachTo(final ConsoleViewImpl console, final ProcessHandler processHandler) { + return dispose().attachTo(console, processHandler); + } + + @Override + public String toString() { + return "Running state"; + } +} 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 fa6ec89e36a5..926310c5741c 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestRunnerConnectionUtil.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/SMTestRunnerConnectionUtil.java @@ -92,6 +92,7 @@ public class SMTestRunnerConnectionUtil { @Override public void attachToProcess(final ProcessHandler processHandler) { // attach listeners + super.attachToProcess(processHandler); attachEventsProcessors(consoleProperties, getResultsViewer(), getResultsViewer().getStatisticsPane(), processHandler, testFrameworkName); @@ -177,9 +178,9 @@ public class SMTestRunnerConnectionUtil { final ProcessHandler processHandler, @NotNull final String testFrameworkName) { //build messages consumer - final OutputToGeneralTestEventsConverter outputConsumer = consoleProperties instanceof SMCustomMessagesParsing ? - ((SMCustomMessagesParsing)consoleProperties).createTestEventsConverter(testFrameworkName) : - new OutputToGeneralTestEventsConverter(testFrameworkName); + final OutputToGeneralTestEventsConverter outputConsumer = consoleProperties instanceof SMCustomMessagesParsing + ? ((SMCustomMessagesParsing)consoleProperties).createTestEventsConverter(testFrameworkName) + : new OutputToGeneralTestEventsConverter(testFrameworkName); //events processor final GeneralToSMTRunnerEventsConvertor eventsProcessor = new GeneralToSMTRunnerEventsConvertor(resultsViewer.getTestsRootNode(), diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerConsoleView.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerConsoleView.java index 4e9265bf7ed5..8312b0f3b88a 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerConsoleView.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTRunnerConsoleView.java @@ -112,6 +112,7 @@ public class SMTRunnerConsoleView extends BaseTestsOutputConsoleView { } public void attachToProcess(final ProcessHandler processHandler) { + super.attachToProcess(processHandler); if (processHandler == null) { return; } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java index ad68caf50dee..52e6351a2ad9 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java @@ -132,6 +132,20 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp public abstract RuntimeConfiguration getConfiguration(); + /** + * 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 + * 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. + * + * @return False for view-only mode and true for stdin support. + */ + public boolean isEditable() { + return false; + } + protected ExecutionConsole getConsole() { return myConsole; } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/ui/BaseTestsOutputConsoleView.java b/platform/testRunner/src/com/intellij/execution/testframework/ui/BaseTestsOutputConsoleView.java index 97f92c7351f1..c2b8f7600c05 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/ui/BaseTestsOutputConsoleView.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/ui/BaseTestsOutputConsoleView.java @@ -10,14 +10,14 @@ * 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 + * See the Lice the specific language governing permissions and * limitations under the License. */ package com.intellij.execution.testframework.ui; import com.intellij.execution.filters.Filter; import com.intellij.execution.filters.HyperlinkInfo; -import com.intellij.execution.filters.TextConsoleBuilderFactory; +import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.testframework.*; import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ConsoleViewContentType; @@ -37,7 +37,10 @@ public abstract class BaseTestsOutputConsoleView implements ConsoleView, Observa public BaseTestsOutputConsoleView(final TestConsoleProperties properties, final AbstractTestProxy unboundOutputRoot) { myProperties = properties; - myConsole = TextConsoleBuilderFactory.getInstance().createBuilder(properties.getProject(), myProperties.getScope()).getConsole(); + + myConsole = new TestsConsoleBuilderImpl(properties.getProject(), + myProperties.getScope(), + !properties.isEditable()).getConsole(); myPrinter = new TestsOutputConsolePrinter(myConsole, properties, unboundOutputRoot); myProperties.setConsole(this); @@ -53,6 +56,10 @@ public abstract class BaseTestsOutputConsoleView implements ConsoleView, Observa protected abstract TestResultsPanel createTestResultsPanel(); + public void attachToProcess(final ProcessHandler processHandler) { + myConsole.attachToProcess(processHandler); + } + public void print(final String s, final ConsoleViewContentType contentType) { printNew(new Printable() { public void printOn(final Printer printer) { diff --git a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsConsoleBuilderImpl.java b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsConsoleBuilderImpl.java new file mode 100644 index 000000000000..024aa639e199 --- /dev/null +++ b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsConsoleBuilderImpl.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2011 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.ui; + +import com.intellij.execution.filters.TextConsoleBuilderImpl; +import com.intellij.execution.ui.ConsoleView; +import com.intellij.openapi.project.Project; +import com.intellij.psi.search.GlobalSearchScope; + +/** + * @author Roman.Chernyatchik + */ +public class TestsConsoleBuilderImpl extends TextConsoleBuilderImpl { + public TestsConsoleBuilderImpl(final Project project, + final GlobalSearchScope scope, + boolean isViewer) { + super(project, scope); + setViewer(isViewer); + } + + @Override + protected ConsoleView createConsole() { + return new TestsConsoleViewImpl(getProject(), getScope(), isViewer(), null); + } +} diff --git a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsConsoleViewImpl.java b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsConsoleViewImpl.java new file mode 100644 index 000000000000..bdc2771d0063 --- /dev/null +++ b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsConsoleViewImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2011 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.ui; + +import com.intellij.execution.impl.ConsoleState; +import com.intellij.execution.impl.ConsoleViewImpl; +import com.intellij.execution.impl.ConsoleViewRunningState; +import com.intellij.execution.process.ProcessHandler; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.project.Project; +import com.intellij.psi.search.GlobalSearchScope; + +/** + * @author Roman.Chernyatchik + */ +public class TestsConsoleViewImpl extends ConsoleViewImpl { + + public TestsConsoleViewImpl(final Project project, + final GlobalSearchScope searchScope, + final boolean viewer, + final FileType fileType) { + super(project, searchScope, viewer, fileType, + new ConsoleState.NotStartedStated() { + @Override + public ConsoleState attachTo(ConsoleViewImpl console, ProcessHandler processHandler) { + return new ConsoleViewRunningState(console, processHandler, this, false, !viewer); + } + }); + } +} diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/JUnitTreeConsoleView.java b/plugins/junit/src/com/intellij/execution/junit2/ui/JUnitTreeConsoleView.java index 656cc5c1b221..567aafbc5397 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/JUnitTreeConsoleView.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/JUnitTreeConsoleView.java @@ -18,7 +18,6 @@ package com.intellij.execution.junit2.ui; import com.intellij.execution.configurations.ConfigurationPerRunnerSettings; import com.intellij.execution.configurations.RunnerSettings; -import com.intellij.execution.junit2.TestProxy; import com.intellij.execution.junit2.ui.model.JUnitRunningModel; import com.intellij.execution.junit2.ui.model.TreeCollapser; import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties; @@ -53,6 +52,7 @@ public class JUnitTreeConsoleView extends BaseTestsOutputConsoleView { } public void attachToProcess(final ProcessHandler processHandler) { + super.attachToProcess(processHandler); myConsolePanel.onProcessStarted(processHandler); } diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java index 20b58ee7f3ac..ec08cbfcc025 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java @@ -25,8 +25,6 @@ package com.theoryinpractice.testng.ui; import com.intellij.execution.Executor; import com.intellij.execution.configurations.ConfigurationPerRunnerSettings; import com.intellij.execution.configurations.RunnerSettings; -import com.intellij.execution.process.ProcessHandler; -import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.execution.testframework.TestTreeView; import com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView; import com.intellij.execution.testframework.ui.TestResultsPanel; @@ -124,9 +122,6 @@ public class TestNGConsoleView extends BaseTestsOutputConsoleView { } } - public void attachToProcess(ProcessHandler processHandler) { - } - public TestProxy getCurrentTest() { return currentTest; }