use of com.intellij.execution.runners.ExecutionEnvironment in project flutter-intellij by flutter.
the class DartVmServiceDebugProcess method onConnectSucceeded.
private void onConnectSucceeded(VmService vmService) {
final DartVmServiceListener vmServiceListener = new DartVmServiceListener(this, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
final DartVmServiceBreakpointHandler breakpointHandler = (DartVmServiceBreakpointHandler) myBreakpointHandlers[0];
myVmServiceWrapper = new VmServiceWrapper(this, vmService, vmServiceListener, myIsolatesInfo, breakpointHandler);
final ScriptProvider provider = (isolateId, scriptId) -> myVmServiceWrapper.getScriptSync(isolateId, scriptId);
mapper.onConnect(provider, myConnector.getRemoteBaseUrl());
final FlutterLaunchMode launchMode = FlutterLaunchMode.fromEnv(executionEnvironment);
if (launchMode.supportsDebugConnection()) {
myVmServiceWrapper.handleDebuggerConnected();
// TODO(jacobr): the following code is a workaround for issues
// auto-resuming isolates paused at their creation while running in
// debug mode.
// The ideal fix would by to fix VMServiceWrapper so that it checks
// for already running isolates like we do here or to refactor where we
// create our VmServiceWrapper so we can listen for isolate creation soon
// enough that we never miss an isolate creation message.
vmService.getVM(new VMConsumer() {
@Override
public void received(VM vm) {
final ElementList<IsolateRef> isolates = vm.getIsolates();
// to handleDebuggerConnected was made and so
for (IsolateRef isolateRef : isolates) {
vmService.getIsolate(isolateRef.getId(), new VmServiceConsumers.GetIsolateConsumerWrapper() {
public void received(Isolate isolate) {
final Event event = isolate.getPauseEvent();
final EventKind eventKind = event.getKind();
if (eventKind == EventKind.PauseStart) {
ApplicationManager.getApplication().invokeLater(() -> {
// We are assuming it is safe to call handleIsolate multiple times.
myVmServiceWrapper.handleIsolate(isolateRef, true);
});
} else if (eventKind == EventKind.Resume) {
// Currently true if we got here via 'flutter attach'
ApplicationManager.getApplication().invokeLater(() -> {
myVmServiceWrapper.attachIsolate(isolateRef, isolate);
});
}
}
});
}
}
@Override
public void onError(RPCError error) {
FlutterUtils.warn(LOG, error.toString());
}
});
}
vmService.addVmServiceListener(vmServiceListener);
myVmConnected = true;
getSession().rebuildViews();
onVmConnected(vmService);
}
use of com.intellij.execution.runners.ExecutionEnvironment in project flutter-intellij by flutter.
the class AttachDebuggerAction method startCommand.
@Override
public void startCommand(@NotNull Project project, @NotNull FlutterSdk sdk, @Nullable PubRoot root, @NotNull DataContext context) {
// NOTE: When making changes here, consider making similar changes to RunFlutterAction.
FlutterInitializer.sendAnalyticsAction(this);
RunConfiguration configuration = findRunConfig(project);
if (configuration == null) {
final RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project).getSelectedConfiguration();
if (settings == null) {
showSelectConfigDialog();
return;
}
configuration = settings.getConfiguration();
if (!(configuration instanceof SdkRunConfig)) {
if (project.isDefault() || !FlutterSdkUtil.hasFlutterModules(project)) {
return;
}
showSelectConfigDialog();
return;
}
}
final SdkAttachConfig sdkRunConfig = new SdkAttachConfig((SdkRunConfig) configuration);
final Executor executor = RunFlutterAction.getExecutor(ToolWindowId.DEBUG);
if (executor == null) {
return;
}
final ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.create(executor, sdkRunConfig);
final ExecutionEnvironment env = builder.activeTarget().dataContext(context).build();
FlutterLaunchMode.addToEnvironment(env, FlutterLaunchMode.DEBUG);
if (project.getUserData(ATTACH_IS_ACTIVE) == null) {
project.putUserData(ATTACH_IS_ACTIVE, ThreeState.fromBoolean(false));
onAttachTermination(project, (p) -> p.putUserData(ATTACH_IS_ACTIVE, null));
}
ProgramRunnerUtil.executeConfiguration(env, false, true);
}
use of com.intellij.execution.runners.ExecutionEnvironment in project flutter-intellij by flutter.
the class RunFlutterAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
// NOTE: When making changes here, consider making similar changes to ConnectAndroidDebuggerAction.
FlutterInitializer.sendAnalyticsAction(this);
final RunnerAndConfigurationSettings settings = getRunConfigSettings(e);
if (settings == null) {
return;
}
final RunConfiguration configuration = settings.getConfiguration();
if (!(configuration instanceof SdkRunConfig)) {
// Action is disabled; shouldn't happen.
return;
}
final SdkRunConfig sdkRunConfig = (SdkRunConfig) configuration.clone();
final SdkFields fields = sdkRunConfig.getFields();
final String additionalArgs = fields.getAdditionalArgs();
String flavorArg = null;
if (fields.getBuildFlavor() != null) {
flavorArg = "--flavor=" + fields.getBuildFlavor();
}
final List<String> args = new ArrayList<>();
if (additionalArgs != null) {
args.add(additionalArgs);
}
if (flavorArg != null) {
args.add(flavorArg);
}
if (!args.isEmpty()) {
fields.setAdditionalArgs(Joiner.on(" ").join(args));
}
final Executor executor = getExecutor(myExecutorId);
if (executor == null) {
return;
}
final ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.create(executor, sdkRunConfig);
final ExecutionEnvironment env;
try {
env = builder.activeTarget().dataContext(e.getDataContext()).build();
} catch (IllegalStateException ex) {
// the reason why. This adds a bit more diagnostics to the exception to help us determine what's going on.
throw new IllegalStateException(ex.getMessage() + " (" + myExecutorId + "/" + myLaunchMode + "/" + getClass().getSimpleName() + ")");
}
FlutterLaunchMode.addToEnvironment(env, myLaunchMode);
ProgramRunnerUtil.executeConfiguration(env, false, true);
}
Aggregations