Search in sources :

Example 61 with ExecutionEnvironment

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);
}
Also used : JsonObject(com.google.gson.JsonObject) Event(org.dartlang.vm.service.element.Event) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlutterInitializer(io.flutter.FlutterInitializer) THashMap(gnu.trove.THashMap) FlutterLaunchMode(io.flutter.run.FlutterLaunchMode) com.intellij.xdebugger(com.intellij.xdebugger) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) WindowListener(java.awt.event.WindowListener) Disposer(com.intellij.openapi.util.Disposer) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) ExecutionResult(com.intellij.execution.ExecutionResult) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Logger(com.intellij.openapi.diagnostic.Logger) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) XSuspendContext(com.intellij.xdebugger.frame.XSuspendContext) DartDebuggerEditorsProvider(com.jetbrains.lang.dart.ide.runner.base.DartDebuggerEditorsProvider) ObservatoryConnector(io.flutter.ObservatoryConnector) WindowManager(com.intellij.openapi.wm.WindowManager) FlutterBundle(io.flutter.FlutterBundle) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) WindowEvent(java.awt.event.WindowEvent) StandardCharsets(java.nio.charset.StandardCharsets) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TimeoutUtil(com.intellij.util.TimeoutUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VMConsumer(org.dartlang.vm.service.consumer.VMConsumer) NotNull(org.jetbrains.annotations.NotNull) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) DartVmServiceEvaluator(io.flutter.vmService.frame.DartVmServiceEvaluator) java.util(java.util) DartVmServiceSuspendContext(io.flutter.vmService.frame.DartVmServiceSuspendContext) DartVmServiceStackFrame(io.flutter.vmService.frame.DartVmServiceStackFrame) CompletableFuture(java.util.concurrent.CompletableFuture) org.dartlang.vm.service.element(org.dartlang.vm.service.element) XDebuggerEditorsProvider(com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider) DartPopFrameAction(com.jetbrains.lang.dart.ide.runner.actions.DartPopFrameAction) GetObjectConsumer(org.dartlang.vm.service.consumer.GetObjectConsumer) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) ProjectUtil(com.intellij.ide.impl.ProjectUtil) Project(com.intellij.openapi.project.Project) FlutterUtils(io.flutter.FlutterUtils) Logging(org.dartlang.vm.service.logging.Logging) VmService(org.dartlang.vm.service.VmService) IOException(java.io.IOException) XBreakpointHandler(com.intellij.xdebugger.breakpoints.XBreakpointHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) java.awt(java.awt) Pair(com.intellij.openapi.util.Pair) BitUtil(com.intellij.util.BitUtil) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) javax.swing(javax.swing) FlutterLaunchMode(io.flutter.run.FlutterLaunchMode) VMConsumer(org.dartlang.vm.service.consumer.VMConsumer) Event(org.dartlang.vm.service.element.Event) WindowEvent(java.awt.event.WindowEvent)

Example 62 with ExecutionEnvironment

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);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) SdkRunConfig(io.flutter.run.SdkRunConfig) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) SdkAttachConfig(io.flutter.run.SdkAttachConfig)

Example 63 with ExecutionEnvironment

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);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Executor(com.intellij.execution.Executor) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) SdkRunConfig(io.flutter.run.SdkRunConfig) ArrayList(java.util.ArrayList) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) SdkFields(io.flutter.run.SdkFields) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder)

Aggregations

ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)63 ProcessHandler (com.intellij.execution.process.ProcessHandler)17 Project (com.intellij.openapi.project.Project)16 ExecutionException (com.intellij.execution.ExecutionException)15 NotNull (org.jetbrains.annotations.NotNull)14 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)13 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)13 Nullable (org.jetbrains.annotations.Nullable)13 Executor (com.intellij.execution.Executor)12 ProcessEvent (com.intellij.execution.process.ProcessEvent)12 ProgramRunner (com.intellij.execution.runners.ProgramRunner)12 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)11 RunProfile (com.intellij.execution.configurations.RunProfile)10 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)10 Key (com.intellij.openapi.util.Key)10 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)8 IOException (java.io.IOException)8 Module (com.intellij.openapi.module.Module)7 Ref (com.intellij.openapi.util.Ref)7 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)6