Search in sources :

Example 1 with SdkFields

use of io.flutter.run.SdkFields in project flutter-intellij by flutter.

the class FlutterModuleUtils method autoCreateRunConfig.

/**
 * Creates a Flutter run configuration if none exists.
 */
public static void autoCreateRunConfig(@NotNull Project project, @NotNull PubRoot root) {
    assert ApplicationManager.getApplication().isReadAccessAllowed();
    if (project.isDisposed())
        return;
    VirtualFile main = root.getLibMain();
    if (main == null || !main.exists()) {
        // Check for example main.dart in plugins
        main = root.getExampleLibMain();
        if (main == null || !main.exists()) {
            return;
        }
    }
    final FlutterRunConfigurationType configType = FlutterRunConfigurationType.getInstance();
    final RunManager runManager = RunManager.getInstance(project);
    if (!runManager.getConfigurationsList(configType).isEmpty()) {
        // Don't create a run config if one already exists.
        return;
    }
    final RunnerAndConfigurationSettings settings = runManager.createConfiguration(project.getName(), configType.getFactory());
    final SdkRunConfig config = (SdkRunConfig) settings.getConfiguration();
    // Set config name.
    config.setName("main.dart");
    // Set fields.
    final SdkFields fields = new SdkFields();
    fields.setFilePath(main.getPath());
    config.setFields(fields);
    runManager.addConfiguration(settings);
    runManager.setSelectedConfiguration(settings);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SdkRunConfig(io.flutter.run.SdkRunConfig) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) SdkFields(io.flutter.run.SdkFields) RunManager(com.intellij.execution.RunManager) FlutterRunConfigurationType(io.flutter.run.FlutterRunConfigurationType)

Example 2 with SdkFields

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

RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 SdkFields (io.flutter.run.SdkFields)2 SdkRunConfig (io.flutter.run.SdkRunConfig)2 Executor (com.intellij.execution.Executor)1 RunManager (com.intellij.execution.RunManager)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FlutterRunConfigurationType (io.flutter.run.FlutterRunConfigurationType)1 ArrayList (java.util.ArrayList)1