Search in sources :

Example 1 with DevToolsService

use of io.flutter.run.daemon.DevToolsService in project flutter-intellij by flutter.

the class BazelFields method getLaunchCommand.

/**
 * Returns the command to use to launch the Flutter app. (Via running the Bazel target.)
 */
GeneralCommandLine getLaunchCommand(@NotNull Project project, @Nullable FlutterDevice device, @NotNull RunMode mode) throws ExecutionException {
    try {
        checkRunnable(project);
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
    final Workspace workspace = getWorkspace(project);
    final String launchingScript = getRunScriptFromWorkspace(project);
    // already checked
    assert launchingScript != null;
    // if the workspace is null, then so is the launching script, therefore this was already checked.
    assert workspace != null;
    final String target = getTarget();
    // already checked
    assert target != null;
    final String additionalArgs = getAdditionalArgs();
    final GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(workspace.getRoot().getPath());
    commandLine.setCharset(StandardCharsets.UTF_8);
    commandLine.setExePath(FileUtil.toSystemDependentName(launchingScript));
    final String inputBazelArgs = StringUtil.notNullize(bazelArgs);
    if (!inputBazelArgs.isEmpty()) {
        commandLine.addParameter(String.format("--bazel-options=%s", inputBazelArgs));
    }
    // Potentially add the flag related to build mode.
    if (enableReleaseMode) {
        commandLine.addParameter("--release");
    } else if (mode.equals(PROFILE)) {
        commandLine.addParameter("--profile");
    }
    // Tell the flutter command-line tools that we want a machine interface on stdio.
    commandLine.addParameter("--machine");
    // Pause the app at startup in order to set breakpoints.
    if (!enableReleaseMode && mode == DEBUG) {
        commandLine.addParameter("--start-paused");
    }
    // User specified additional target arguments.
    final CommandLineTokenizer additionalArgsTokenizer = new CommandLineTokenizer(StringUtil.notNullize(additionalArgs));
    while (additionalArgsTokenizer.hasMoreTokens()) {
        commandLine.addParameter(additionalArgsTokenizer.nextToken());
    }
    final String enableBazelHotRestartParam = "--enable-google3-hot-reload";
    final String disableBazelHotRestartParam = "--no-enable-google3-hot-reload";
    final boolean hasEnabledArg = StringUtil.notNullize(additionalArgs).contains(enableBazelHotRestartParam);
    final boolean hasDisabledArg = StringUtil.notNullize(additionalArgs).contains(disableBazelHotRestartParam);
    if (!FlutterSettings.getInstance().isEnableBazelHotRestart() && hasDisabledArg) {
        final Notification notification = new Notification(FlutterMessages.FLUTTER_NOTIFICATION_GROUP_ID, "Google3-specific hot restart is disabled by default", "You can now remove this flag from your configuration's additional args: " + disableBazelHotRestartParam, NotificationType.INFORMATION);
        Notifications.Bus.notify(notification, project);
    } else if (FlutterSettings.getInstance().isEnableBazelHotRestart() && !hasEnabledArg && !hasDisabledArg) {
        commandLine.addParameter(enableBazelHotRestartParam);
    }
    // Send in the deviceId.
    if (device != null) {
        commandLine.addParameter("-d");
        commandLine.addParameter(device.deviceId());
    }
    try {
        final ProgressManager progress = ProgressManager.getInstance();
        final CompletableFuture<DevToolsInstance> devToolsFuture = new CompletableFuture<>();
        progress.runProcessWithProgressSynchronously(() -> {
            progress.getProgressIndicator().setIndeterminate(true);
            try {
                final DevToolsService service = this.devToolsService == null ? DevToolsService.getInstance(project) : this.devToolsService;
                devToolsFuture.complete(service.getDevToolsInstance().get(30, TimeUnit.SECONDS));
            } catch (Exception e) {
                LOG.error(e);
            }
        }, "Starting DevTools", false, project);
        final DevToolsInstance instance = devToolsFuture.get();
        commandLine.addParameter("--devtools-server-address=http://" + instance.host + ":" + instance.port);
    } catch (Exception e) {
        LOG.error(e);
    }
    commandLine.addParameter(target);
    return commandLine;
}
Also used : Notification(com.intellij.notification.Notification) ExecutionException(com.intellij.execution.ExecutionException) InvalidDataException(com.intellij.openapi.util.InvalidDataException) CompletableFuture(java.util.concurrent.CompletableFuture) DevToolsService(io.flutter.run.daemon.DevToolsService) ProgressManager(com.intellij.openapi.progress.ProgressManager) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) DevToolsInstance(io.flutter.run.daemon.DevToolsInstance) ExecutionException(com.intellij.execution.ExecutionException) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) Workspace(io.flutter.bazel.Workspace) CommandLineTokenizer(com.intellij.execution.configurations.CommandLineTokenizer)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)1 CommandLineTokenizer (com.intellij.execution.configurations.CommandLineTokenizer)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 Notification (com.intellij.notification.Notification)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 InvalidDataException (com.intellij.openapi.util.InvalidDataException)1 Workspace (io.flutter.bazel.Workspace)1 DevToolsInstance (io.flutter.run.daemon.DevToolsInstance)1 DevToolsService (io.flutter.run.daemon.DevToolsService)1 CompletableFuture (java.util.concurrent.CompletableFuture)1