use of com.intellij.execution.runners.ExecutionEnvironment in project intellij-plugins by JetBrains.
the class KarmaCoverageProgramRunner method listenForCoverageFile.
private static void listenForCoverageFile(@NotNull ExecutionEnvironment env, @NotNull KarmaServer server) throws ExecutionException {
KarmaRunConfiguration runConfiguration = (KarmaRunConfiguration) env.getRunProfile();
CoverageEnabledConfiguration coverageEnabledConfiguration = CoverageEnabledConfiguration.getOrCreate(runConfiguration);
CoverageHelper.resetCoverageSuit(runConfiguration);
String coverageFilePath = coverageEnabledConfiguration.getCoverageFilePath();
if (coverageFilePath != null) {
KarmaCoveragePeer coveragePeer = server.getCoveragePeer();
Objects.requireNonNull(coveragePeer);
coveragePeer.startCoverageSession(new KarmaCoverageSession() {
@Override
public void onCoverageSessionFinished(@Nullable File lcovFile) {
LOG.info("Processing karma coverage file: " + lcovFile);
UIUtil.invokeLaterIfNeeded(() -> {
Project project = env.getProject();
if (project.isDisposed())
return;
if (lcovFile != null) {
processLcovInfoFile(lcovFile, coverageFilePath, env, server, runConfiguration);
} else {
int response = Messages.showYesNoDialog(project, "Cannot find karma test coverage report - lcov.info", "Missing Karma Coverage Report", "Select lcov.info", "Cancel", Messages.getWarningIcon());
if (response == Messages.YES) {
FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFileDescriptor(), project, null, null, file -> {
File selected = file != null ? VfsUtilCore.virtualToIoFile(file) : null;
if (selected != null) {
processLcovInfoFile(selected, coverageFilePath, env, server, runConfiguration);
}
});
}
}
});
}
});
}
}
use of com.intellij.execution.runners.ExecutionEnvironment in project buck by facebook.
the class TestExecutionState method attachDebugger.
private void attachDebugger(String title, String port) {
final RemoteConnection remoteConnection = new RemoteConnection(/* useSockets */
true, "localhost", port, /* serverMode */
false);
final RemoteStateState state = new RemoteStateState(mProject, remoteConnection);
final String name = title + " debugger (" + port + ")";
final ConfigurationFactory cfgFactory = ConfigurationTypeUtil.findConfigurationType("Remote").getConfigurationFactories()[0];
RunnerAndConfigurationSettings runSettings = RunManager.getInstance(mProject).createRunConfiguration(name, cfgFactory);
final Executor debugExecutor = DefaultDebugExecutor.getDebugExecutorInstance();
final ExecutionEnvironment env = new ExecutionEnvironmentBuilder(mProject, debugExecutor).runProfile(runSettings.getConfiguration()).build();
final int pollTimeout = 3000;
final DebugEnvironment environment = new DefaultDebugEnvironment(env, state, remoteConnection, pollTimeout);
ApplicationManager.getApplication().invokeLater(() -> {
try {
final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(mProject).attachVirtualMachine(environment);
if (debuggerSession == null) {
return;
}
XDebuggerManager.getInstance(mProject).startSessionAndShowTab(name, null, new XDebugProcessStarter() {
@Override
@NotNull
public XDebugProcess start(@NotNull XDebugSession session) {
return JavaDebugProcess.create(session, debuggerSession);
}
});
} catch (ExecutionException e) {
LOG.error("failed to attach to debugger on port " + port + " with polling timeout " + pollTimeout);
}
});
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij-leiningen-plugin by derkork.
the class LeiningenRunConfigurationType method runConfiguration.
public static void runConfiguration(Project project, LeiningenRunnerParameters params, DataContext context) {
RunnerAndConfigurationSettings configSettings = createRunnerAndConfigurationSettings(params, project);
ProgramRunner runner = RunnerRegistry.getInstance().findRunnerById(DefaultRunExecutor.EXECUTOR_ID);
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, configSettings, project);
try {
runner.execute(env, new ProgramRunner.Callback() {
public void processStarted(RunContentDescriptor runContentDescriptor) {
final ProcessHandler runContentDescriptorProcessHandler = runContentDescriptor.getProcessHandler();
if (runContentDescriptorProcessHandler != null) {
runContentDescriptorProcessHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
LocalFileSystem.getInstance().refreshWithoutFileWatcher(true);
}
});
}
}
});
} catch (ExecutionException e) {
}
}
use of com.intellij.execution.runners.ExecutionEnvironment in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoBeforeRunTaskProvider method executeTask.
@Override
public boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, GoCommandBeforeRunTask task) {
Semaphore done = new Semaphore();
Ref<Boolean> result = Ref.create(false);
GoRunConfigurationBase goRunConfiguration = (GoRunConfigurationBase) configuration;
Module module = goRunConfiguration.getConfigurationModule().getModule();
Project project = configuration.getProject();
String workingDirectory = goRunConfiguration.getWorkingDirectory();
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
if (StringUtil.isEmpty(task.getCommand()))
return;
if (project == null || project.isDisposed())
return;
GoSdkService sdkService = GoSdkService.getInstance(project);
if (!sdkService.isGoModule(module))
return;
done.down();
GoExecutor.in(module).withParameterString(task.getCommand()).withWorkDirectory(workingDirectory).showOutputOnError().showNotifications(false, true).withPresentableName("Executing `" + task + "`").withProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
done.up();
result.set(event.getExitCode() == 0);
}
}).executeWithProgress(false, result1 -> VirtualFileManager.getInstance().asyncRefresh(null));
}
});
done.waitFor();
return result.get();
}
use of com.intellij.execution.runners.ExecutionEnvironment in project android by JetBrains.
the class ConnectJavaDebuggerTask method launchDebugger.
@Override
public ProcessHandler launchDebugger(@NotNull LaunchInfo currentLaunchInfo, @NotNull final Client client, @NotNull ProcessHandlerLaunchStatus launchStatus, @NotNull ProcessHandlerConsolePrinter printer) {
String debugPort = Integer.toString(client.getDebuggerListenPort());
final int pid = client.getClientData().getPid();
Logger.getInstance(ConnectJavaDebuggerTask.class).info(String.format(Locale.US, "Attempting to connect debugger to port %1$s [client %2$d]", debugPort, pid));
// detach old process handler
RunContentDescriptor descriptor = currentLaunchInfo.env.getContentToReuse();
// reach here before the EDT gets around to creating the descriptor?
assert descriptor != null : "ConnectJavaDebuggerTask expects an existing descriptor that will be reused";
final ProcessHandler processHandler = descriptor.getProcessHandler();
assert processHandler != null;
// create a new process handler
RemoteConnection connection = new RemoteConnection(true, "localhost", debugPort, false);
final AndroidRemoteDebugProcessHandler debugProcessHandler = new AndroidRemoteDebugProcessHandler(myProject, myMonitorRemoteProcess);
// switch the launch status and console printers to point to the new process handler
// this is required, esp. for AndroidTestListener which holds a reference to the launch status and printers, and those should
// be updated to point to the new process handlers, otherwise test results will not be forwarded appropriately
launchStatus.setProcessHandler(debugProcessHandler);
printer.setProcessHandler(debugProcessHandler);
// detach after the launch status has been updated to point to the new process handler
processHandler.detachProcess();
AndroidDebugState debugState = new AndroidDebugState(myProject, debugProcessHandler, connection, currentLaunchInfo.consoleProvider);
RunContentDescriptor debugDescriptor;
try {
// @formatter:off
ExecutionEnvironment debugEnv = new ExecutionEnvironmentBuilder(currentLaunchInfo.env).executor(currentLaunchInfo.executor).runner(currentLaunchInfo.runner).contentToReuse(descriptor).build();
debugDescriptor = DebuggerPanelsManager.getInstance(myProject).attachVirtualMachine(debugEnv, debugState, connection, false);
// @formatter:on
} catch (ExecutionException e) {
processHandler.notifyTextAvailable("ExecutionException: " + e.getMessage() + '.', STDERR);
return null;
}
if (debugDescriptor == null) {
processHandler.notifyTextAvailable("Unable to connect debugger to Android application", STDERR);
return null;
}
// re-run the collected text from the old process handler to the new
// TODO: is there a race between messages received once the debugger has been connected, and these messages that are printed out?
final AndroidProcessText oldText = AndroidProcessText.get(processHandler);
if (oldText != null) {
oldText.printTo(debugProcessHandler);
}
RunProfile runProfile = currentLaunchInfo.env.getRunProfile();
int uniqueId = runProfile instanceof RunConfigurationBase ? ((RunConfigurationBase) runProfile).getUniqueID() : -1;
AndroidSessionInfo value = new AndroidSessionInfo(debugProcessHandler, debugDescriptor, uniqueId, currentLaunchInfo.executor.getId(), InstantRunUtils.isInstantRunEnabled(currentLaunchInfo.env));
debugProcessHandler.putUserData(AndroidSessionInfo.KEY, value);
debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEBUG_CLIENT, client);
debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEVICE_API_LEVEL, client.getDevice().getVersion());
final String pkgName = client.getClientData().getClientDescription();
final IDevice device = client.getDevice();
// kill the process when the debugger is stopped
debugProcessHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
debugProcessHandler.removeProcessListener(this);
Client currentClient = device.getClient(pkgName);
if (currentClient != null && currentClient.getClientData().getPid() != pid) {
// a new process has been launched for the same package name, we aren't interested in killing this
return;
}
Logger.getInstance(ConnectJavaDebuggerTask.class).info("Debugger terminating, so terminating process: " + pkgName);
// Note: client.kill() doesn't work when the debugger is attached, we explicitly stop by package id..
try {
device.executeShellCommand("am force-stop " + pkgName, new NullOutputReceiver());
} catch (Exception e) {
// don't care..
}
}
});
return debugProcessHandler;
}
Aggregations