Search in sources :

Example 6 with SdkRunConfig

use of io.flutter.run.SdkRunConfig 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

SdkRunConfig (io.flutter.run.SdkRunConfig)6 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)5 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)2 SdkFields (io.flutter.run.SdkFields)2 Executor (com.intellij.execution.Executor)1 RunManager (com.intellij.execution.RunManager)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FlutterRunConfigurationType (io.flutter.run.FlutterRunConfigurationType)1 SdkAttachConfig (io.flutter.run.SdkAttachConfig)1 ArrayList (java.util.ArrayList)1 Nullable (org.jetbrains.annotations.Nullable)1