unite junit and testng runnable state; extract SM runner

This commit is contained in:
Anna Kozlova
2015-04-07 11:25:49 +02:00
parent 91ec19c613
commit e619ef5cef
12 changed files with 219 additions and 202 deletions
+2 -2
View File
@@ -16,11 +16,11 @@
<orderEntry type="module" module-name="compiler-openapi" />
<orderEntry type="module" module-name="java-impl" />
<orderEntry type="module" module-name="java-indexing-api" />
<orderEntry type="module" module-name="smRunner" />
</component>
<component name="copyright">
<Base>
<setting name="state" value="1" />
</Base>
</component>
</module>
</module>
@@ -0,0 +1,78 @@
/*
* Copyright 2000-2015 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;
import com.intellij.execution.*;
import com.intellij.execution.configurations.JavaCommandLineState;
import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.execution.configurations.RunnerSettings;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.execution.testframework.TestFrameworkRunningModel;
import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction;
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil;
import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties;
import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Getter;
import com.intellij.util.PathUtil;
import jetbrains.buildServer.messages.serviceMessages.ServiceMessageTypes;
import org.jetbrains.annotations.NotNull;
public abstract class JavaTestFrameworkRunnableState extends JavaCommandLineState {
public JavaTestFrameworkRunnableState(ExecutionEnvironment environment) {
super(environment);
}
@NotNull protected abstract String getFrameworkName();
@NotNull protected abstract String getVMParameter();
@NotNull protected abstract AbstractRerunFailedTestsAction createRerunFailedTestsAction(TestConsoleProperties testConsoleProperties, ConsoleView consoleView);
protected ExecutionResult startSMRunner(Executor executor,
OSProcessHandler handler,
RunConfigurationBase configuration,
ExecutionEnvironment environment) throws ExecutionException {
getJavaParameters().getVMParametersList().add(getVMParameter());
getJavaParameters().getClassPath().add(PathUtil.getJarPathForClass(ServiceMessageTypes.class));
final RunnerSettings runnerSettings = getRunnerSettings();
TestConsoleProperties testConsoleProperties = new SMTRunnerConsoleProperties(configuration, getFrameworkName(), executor);
testConsoleProperties.setIfUndefined(TestConsoleProperties.HIDE_PASSED_TESTS, false);
final ConsoleView consoleView = SMTestRunnerConnectionUtil.createConsoleWithCustomLocator(getFrameworkName(), testConsoleProperties, environment, null);
Disposer.register(configuration.getProject(), consoleView);
consoleView.attachToProcess(handler);
AbstractRerunFailedTestsAction rerunFailedTestsAction = createRerunFailedTestsAction(testConsoleProperties, consoleView);
rerunFailedTestsAction.setModelProvider(new Getter<TestFrameworkRunningModel>() {
@Override
public TestFrameworkRunningModel get() {
return ((SMTRunnerConsoleView)consoleView).getResultsViewer();
}
});
final DefaultExecutionResult result = new DefaultExecutionResult(consoleView, handler);
result.setRestartActions(rerunFailedTestsAction);
JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(configuration, handler, runnerSettings);
return result;
}
}
@@ -17,6 +17,7 @@ package com.intellij.execution.testframework;
import com.intellij.execution.CantRunException;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
@@ -48,7 +49,7 @@ public abstract class SearchForTestsTask extends Task.Backgroundable {
}
protected abstract void search() throws CantRunException;
protected abstract void search() throws ExecutionException;
protected abstract void onFound();
public void ensureFinished() {
@@ -77,14 +78,14 @@ public abstract class SearchForTestsTask extends Task.Backgroundable {
public void run(@NotNull ProgressIndicator indicator) {
try {
mySocket = myServerSocket.accept();
final CantRunException[] ex = new CantRunException[1];
final ExecutionException[] ex = new ExecutionException[1];
DumbService.getInstance(getProject()).repeatUntilPassesInSmartMode(new Runnable() {
@Override
public void run() {
try {
search();
}
catch (CantRunException e) {
catch (ExecutionException e) {
ex[0] = e;
}
}
@@ -104,7 +105,7 @@ public abstract class SearchForTestsTask extends Task.Backgroundable {
}
}
protected void logCantRunException(CantRunException e) throws CantRunException {
protected void logCantRunException(ExecutionException e) throws ExecutionException {
throw e;
}
@@ -51,7 +51,7 @@ public abstract class JavaCommandLineState extends CommandLineState implements J
protected abstract JavaParameters createJavaParameters() throws ExecutionException;
protected GeneralCommandLine createCommandLine() throws ExecutionException {
@SuppressWarnings("deprecation") Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
final Project project = getEnvironment().getProject();
return CommandLineBuilder.createFromJavaParameters(getJavaParameters(), project, true);
}