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");
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations