Search in sources :

Example 1 with RunMode

use of io.flutter.run.common.RunMode in project flutter-intellij by flutter.

the class TestLaunchState method startProcess.

@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
    final RunMode mode = RunMode.fromEnv(getEnvironment());
    final FlutterCommandStartResult result = fields.run(getEnvironment().getProject(), mode);
    switch(result.status) {
        case OK:
            assert result.processHandler != null;
            processHandler = result.processHandler;
            return result.processHandler;
        case EXCEPTION:
            assert result.exception != null;
            throw new ExecutionException(FlutterBundle.message("flutter.command.exception.message" + result.exception.getMessage()));
        default:
            throw new ExecutionException("Unexpected state");
    }
}
Also used : RunMode(io.flutter.run.common.RunMode) FlutterCommandStartResult(io.flutter.sdk.FlutterCommandStartResult) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with RunMode

use of io.flutter.run.common.RunMode in project flutter-intellij by flutter.

the class SdkAttachConfig method getState.

@NotNull
@Override
public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
    try {
        checkRunnable(env.getProject());
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
    final SdkFields launchFields = getFields();
    final MainFile mainFile = MainFile.verify(launchFields.getFilePath(), env.getProject()).get();
    final Project project = env.getProject();
    final RunMode mode = RunMode.fromEnv(env);
    final Module module = ModuleUtilCore.findModuleForFile(mainFile.getFile(), env.getProject());
    final LaunchState.CreateAppCallback createAppCallback = (@Nullable FlutterDevice device) -> {
        if (device == null)
            return null;
        final GeneralCommandLine command = getCommand(env, device);
        final FlutterApp app = FlutterApp.start(env, project, module, mode, device, command, StringUtil.capitalize(mode.mode()) + "App", "StopApp");
        // Stop the app if the Flutter SDK changes.
        final FlutterSdkManager.Listener sdkListener = new FlutterSdkManager.Listener() {

            @Override
            public void flutterSdkRemoved() {
                app.shutdownAsync();
            }
        };
        FlutterSdkManager.getInstance(project).addListener(sdkListener);
        Disposer.register(project, () -> FlutterSdkManager.getInstance(project).removeListener(sdkListener));
        return app;
    };
    final LaunchState launcher = new AttachState(env, mainFile.getAppDir(), mainFile.getFile(), this, createAppCallback);
    addConsoleFilters(launcher, env, mainFile, module);
    return launcher;
}
Also used : FlutterApp(io.flutter.run.daemon.FlutterApp) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) Project(com.intellij.openapi.project.Project) FlutterSdkManager(io.flutter.sdk.FlutterSdkManager) RunMode(io.flutter.run.common.RunMode) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Module(com.intellij.openapi.module.Module) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with RunMode

use of io.flutter.run.common.RunMode in project flutter-intellij by flutter.

the class SdkRunConfig method getState.

@NotNull
@Override
public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
    final SdkFields launchFields = fields.copy();
    try {
        launchFields.checkRunnable(env.getProject());
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
    final MainFile mainFile = MainFile.verify(launchFields.getFilePath(), env.getProject()).get();
    final Project project = env.getProject();
    final RunMode mode = RunMode.fromEnv(env);
    final Module module = ModuleUtilCore.findModuleForFile(mainFile.getFile(), env.getProject());
    final LaunchState.CreateAppCallback createAppCallback = (@Nullable FlutterDevice device) -> {
        if (device == null)
            return null;
        final GeneralCommandLine command = getCommand(env, device);
        // Workaround for https://github.com/flutter/flutter/issues/16766
        // TODO(jacobr): remove once flutter tool incremental building works
        // properly with --track-widget-creation.
        final Path buildPath = command.getWorkDirectory().toPath().resolve("build");
        final Path cachedParametersPath = buildPath.resolve("last_build_run.json");
        final String[] parametersToTrack = { "--preview-dart-2", "--track-widget-creation" };
        final JsonArray jsonArray = new JsonArray();
        for (String parameter : command.getParametersList().getList()) {
            for (String allowedParameter : parametersToTrack) {
                if (parameter.startsWith(allowedParameter)) {
                    jsonArray.add(new JsonPrimitive(parameter));
                    break;
                }
            }
        }
        final String json = new Gson().toJson(jsonArray);
        String existingJson = null;
        if (Files.exists(cachedParametersPath)) {
            try {
                existingJson = new String(Files.readAllBytes(cachedParametersPath), StandardCharsets.UTF_8);
            } catch (IOException e) {
                FlutterUtils.warn(LOG, "Unable to get existing json from " + cachedParametersPath);
            }
        }
        if (!StringUtil.equals(json, existingJson)) {
            // to the underlying Flutter build rules.
            try {
                if (Files.exists(buildPath)) {
                    if (Files.isDirectory(buildPath)) {
                        Files.walkFileTree(buildPath, new RecursiveDeleter("*.{fingerprint,dill}"));
                    }
                } else {
                    Files.createDirectory(buildPath);
                }
                Files.write(cachedParametersPath, json.getBytes(StandardCharsets.UTF_8));
            } catch (IOException e) {
                FlutterUtils.warn(LOG, e);
            }
        }
        final FlutterApp app = FlutterApp.start(env, project, module, mode, device, command, StringUtil.capitalize(mode.mode()) + "App", "StopApp");
        // Stop the app if the Flutter SDK changes.
        final FlutterSdkManager.Listener sdkListener = new FlutterSdkManager.Listener() {

            @Override
            public void flutterSdkRemoved() {
                app.shutdownAsync();
            }
        };
        FlutterSdkManager.getInstance(project).addListener(sdkListener);
        Disposer.register(project, () -> FlutterSdkManager.getInstance(project).removeListener(sdkListener));
        return app;
    };
    final LaunchState launcher = new LaunchState(env, mainFile.getAppDir(), mainFile.getFile(), this, createAppCallback);
    addConsoleFilters(launcher, env, mainFile, module);
    return launcher;
}
Also used : FlutterApp(io.flutter.run.daemon.FlutterApp) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) JsonPrimitive(com.google.gson.JsonPrimitive) Gson(com.google.gson.Gson) IOException(java.io.IOException) JsonArray(com.google.gson.JsonArray) Project(com.intellij.openapi.project.Project) FlutterSdkManager(io.flutter.sdk.FlutterSdkManager) RunMode(io.flutter.run.common.RunMode) ExecutionException(com.intellij.execution.ExecutionException) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with RunMode

use of io.flutter.run.common.RunMode in project flutter-intellij by flutter.

the class SdkRunConfig method getCommand.

@NotNull
@Override
public GeneralCommandLine getCommand(@NotNull ExecutionEnvironment env, @NotNull FlutterDevice device) throws ExecutionException {
    final SdkFields launchFields = fields.copy();
    final Project project = env.getProject();
    final RunMode mode = RunMode.fromEnv(env);
    final boolean initialFirstRun = firstRun;
    firstRun = false;
    return fields.createFlutterSdkRunCommand(project, mode, FlutterLaunchMode.fromEnv(env), device, initialFirstRun);
}
Also used : Project(com.intellij.openapi.project.Project) RunMode(io.flutter.run.common.RunMode) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with RunMode

use of io.flutter.run.common.RunMode in project flutter-intellij by flutter.

the class BazelRunConfig method getCommand.

@NotNull
@Override
public GeneralCommandLine getCommand(ExecutionEnvironment env, @NotNull FlutterDevice device) throws ExecutionException {
    final BazelFields launchFields = fields.copy();
    final RunMode mode = RunMode.fromEnv(env);
    return launchFields.getLaunchCommand(env.getProject(), device, mode);
}
Also used : RunMode(io.flutter.run.common.RunMode) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RunMode (io.flutter.run.common.RunMode)6 NotNull (org.jetbrains.annotations.NotNull)6 ExecutionException (com.intellij.execution.ExecutionException)4 Module (com.intellij.openapi.module.Module)3 Project (com.intellij.openapi.project.Project)3 RefactoringElementListener (com.intellij.refactoring.listeners.RefactoringElementListener)2 FlutterApp (io.flutter.run.daemon.FlutterApp)2 FlutterSdkManager (io.flutter.sdk.FlutterSdkManager)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Workspace (io.flutter.bazel.Workspace)1 FlutterDevice (io.flutter.run.FlutterDevice)1 LaunchState (io.flutter.run.LaunchState)1 FlutterCommandStartResult (io.flutter.sdk.FlutterCommandStartResult)1 IOException (java.io.IOException)1