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