Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Ekaterina Tuzova
2011-03-24 20:29:02 +03:00
12 changed files with 254 additions and 72 deletions
@@ -62,4 +62,19 @@ public class TextConsoleBuilderImpl extends TextConsoleBuilder {
myViewer = isViewer;
}
protected Project getProject() {
return myProject;
}
protected GlobalSearchScope getScope() {
return myScope;
}
protected ArrayList<Filter> getFilters() {
return myFilters;
}
protected boolean isViewer() {
return myViewer;
}
}
@@ -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";
}
}
}
@@ -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<ModalityState> 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;
}
@@ -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";
}
}
@@ -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(),
@@ -112,6 +112,7 @@ public class SMTRunnerConsoleView extends BaseTestsOutputConsoleView {
}
public void attachToProcess(final ProcessHandler processHandler) {
super.attachToProcess(processHandler);
if (processHandler == null) {
return;
}
@@ -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;
}
@@ -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) {
@@ -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);
}
}
@@ -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);
}
});
}
}
@@ -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);
}
@@ -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;
}