use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.
the class FlexUnitExecutionTest method doTest.
private AbstractTestProxy doTest(boolean debugNotRun, FlexUnitRunnerParameters.Scope testScope, String testClassOrPackage, @Nullable String testMethod, @Nullable String projectRoot, @Nullable FlexUnitRunnerParameters.OutputLogLevel outputLogLevel, String... files) throws Exception {
configureByFiles(projectRoot, files);
final Ref<IXMLElement> expected = new Ref<>();
UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> {
try {
Collection<IXMLElement> collection = JSTestUtils.extractXml(myEditor.getDocument(), "testResults");
assertEquals("Invalid expected structure", 1, collection.size());
expected.set(collection.iterator().next());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}));
UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> FlexTestUtils.modifyBuildConfiguration(myModule, configuration -> configuration.setTargetPlatform(myTargetPlatform))));
final RunnerAndConfigurationSettings runnerAndConfigurationSettings = RunManager.getInstance(myProject).createRunConfiguration("test", FlexUnitRunConfigurationType.getFactory());
final FlexUnitRunConfiguration flexUnitRunConfig = (FlexUnitRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
final FlexUnitRunnerParameters params = flexUnitRunConfig.getRunnerParameters();
params.setModuleName(myModule.getName());
params.setBCName(FlexBuildConfigurationManager.getInstance(myModule).getBuildConfigurations()[0].getName());
params.setOutputLogLevel(outputLogLevel);
params.setScope(testScope);
switch(testScope) {
case Class:
params.setClassName(testClassOrPackage);
break;
case Method:
params.setClassName(testClassOrPackage);
params.setMethodName(testMethod);
break;
case Package:
params.setPackageName(testClassOrPackage);
break;
default:
fail("Unknown scope: " + testScope);
}
flexUnitRunConfig.checkConfiguration();
final ProgramRunner runner = new FlexUnitTestRunner();
final Executor executor = debugNotRun ? DefaultDebugExecutor.getDebugExecutorInstance() : DefaultRunExecutor.getRunExecutorInstance();
final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, runnerAndConfigurationSettings, getProject());
final Semaphore compilation = new Semaphore();
compilation.down();
final Semaphore execution = new Semaphore();
execution.down();
final Semaphore startup = new Semaphore();
final ProcessListener listener = new ProcessListener() {
@Override
public void startNotified(ProcessEvent event) {
startup.up();
}
@Override
public void processTerminated(ProcessEvent event) {
execution.up();
}
@Override
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
}
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
System.out.println("FlexUnit: " + event.getText());
}
};
final Ref<ExecutionConsole> executionConsole = new Ref<>();
ApplicationManager.getApplication().invokeLater(() -> {
try {
runner.execute(env, new ProgramRunner.Callback() {
@Override
public void processStarted(RunContentDescriptor descriptor) {
compilation.up();
startup.down();
descriptor.getProcessHandler().addProcessListener(listener);
executionConsole.set(descriptor.getExecutionConsole());
}
});
} catch (Throwable t) {
t.printStackTrace();
fail(t.getMessage());
compilation.up();
startup.up();
execution.up();
}
});
if (!compilation.waitFor(COMPILATION_TIMEOUT * 1000)) {
fail("Compilation did not succeed in " + COMPILATION_TIMEOUT + " seconds. There was an error or it took too long\n" + FlexCompilerHandler.getInstance(myProject).getLastCompilationMessages());
}
if (!startup.waitFor(STARTUP_TIMEOUT * 1000)) {
fail("Process was not started in " + STARTUP_TIMEOUT + " seconds");
}
if (!execution.waitFor(EXECUTION_TIMEOUT * 1000)) {
fail("Execution did not finish in " + EXECUTION_TIMEOUT + " seconds");
}
// give tests tree some time to stabilize
Thread.sleep(200);
final AbstractTestProxy testRoot = ((SMTRunnerConsoleView) executionConsole.get()).getResultsViewer().getRoot();
checkResults(expected.get(), testRoot);
if (outputLogLevel == null) {
checkOutput(testRoot, outputLogLevel);
}
return testRoot;
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.
the class FlexUnitTestRunner method execute.
@Override
public void execute(@NotNull final ExecutionEnvironment env, @Nullable final Callback callback) throws ExecutionException {
final Project project = env.getProject();
final RunProfileState state = env.getState();
if (state == null) {
return;
}
Runnable startRunnable = () -> {
try {
if (project.isDisposed())
return;
final RunContentDescriptor descriptor = doExecute(state, env);
if (callback != null)
callback.processStarted(descriptor);
if (descriptor != null) {
ExecutionManager.getInstance(project).getContentManager().showRunContent(env.getExecutor(), descriptor);
final ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler != null)
processHandler.startNotify();
}
} catch (ExecutionException e) {
ExecutionUtil.handleExecutionError(env, e);
}
};
ExecutionManager.getInstance(project).compileAndRun(startRunnable, env, state, null);
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.
the class DartCoverageProgramRunner method doExecute.
@Nullable
@Override
protected RunContentDescriptor doExecute(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
final DartCommandLineRunConfiguration runConfiguration = (DartCommandLineRunConfiguration) env.getRunProfile();
final DartSdk sdk = DartSdk.getDartSdk(runConfiguration.getProject());
if (sdk == null) {
throw new ExecutionException(DartBundle.message("dart.sdk.is.not.configured"));
}
final String dartPubPath = DartSdkUtil.getPubPath(sdk);
final RunContentDescriptor result = DefaultProgramRunnerKt.executeState(state, env, this);
if (result == null) {
return null;
}
if (!myCoveragePackageActivated && !activateCoverage(runConfiguration.getProject(), dartPubPath)) {
throw new ExecutionException("Cannot activate pub package 'coverage'.");
}
final ProcessHandler dartAppProcessHandler = result.getProcessHandler();
if (dartAppProcessHandler != null) {
((DartCommandLineRunningState) state).addObservatoryUrlConsumer(observatoryUrl -> startCollectingCoverage(env, dartAppProcessHandler, observatoryUrl));
}
return result;
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.
the class KarmaDebugProgramRunner method execute.
@NotNull
@Override
protected Promise<RunContentDescriptor> execute(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult = state.execute(environment.getExecutor(), this);
if (executionResult == null) {
return Promise.resolve(null);
}
KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
if (consoleView == null) {
return Promise.resolve(KarmaUtil.createDefaultDescriptor(executionResult, environment));
}
KarmaServer karmaServer = consoleView.getKarmaExecutionSession().getKarmaServer();
if (karmaServer.areBrowsersReady()) {
KarmaDebugBrowserSelector browserSelector = new KarmaDebugBrowserSelector(karmaServer.getCapturedBrowsers(), environment, consoleView);
DebuggableWebBrowser debuggableWebBrowser = browserSelector.selectDebugEngine();
if (debuggableWebBrowser == null) {
return Promises.resolvedPromise(KarmaUtil.createDefaultDescriptor(executionResult, environment));
}
return KarmaKt.prepareKarmaDebugger(environment.getProject(), debuggableWebBrowser, () -> createDescriptor(environment, executionResult, consoleView, karmaServer, debuggableWebBrowser));
} else {
RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, environment);
karmaServer.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
return Promises.resolvedPromise(descriptor);
}
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.
the class KarmaCoverageProgramRunner method doExecute.
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult = state.execute(env.getExecutor(), this);
if (executionResult == null) {
return null;
}
RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, env);
KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
if (consoleView == null) {
return descriptor;
}
KarmaServer server = consoleView.getKarmaExecutionSession().getKarmaServer();
if (server.areBrowsersReady()) {
listenForCoverageFile(env, server);
} else {
server.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
}
return descriptor;
}
Aggregations