Search in sources :

Example 11 with FlutterSdk

use of io.flutter.sdk.FlutterSdk in project flutter-intellij by flutter.

the class DeviceDaemon method chooseCommand.

/**
 * Returns the appropriate command to start the device daemon, if any.
 * <p>
 * A null means the device daemon should be shut down.
 */
@Nullable
static Command chooseCommand(@NotNull final Project project) {
    if (!usesFlutter(project)) {
        return null;
    }
    final String androidHome = IntelliJAndroidSdk.chooseAndroidHome(project, false);
    // See if the Bazel workspace provides a script.
    final Workspace workspace = WorkspaceCache.getInstance(project).getNow();
    if (workspace != null) {
        final String script = workspace.getDaemonScript();
        if (script != null) {
            return new Command(workspace.getRoot().getPath(), script, ImmutableList.of(), androidHome);
        }
    }
    // Otherwise, use the Flutter SDK.
    final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
    if (sdk == null) {
        return null;
    }
    try {
        final String path = FlutterSdkUtil.pathToFlutterTool(sdk.getHomePath());
        return new Command(sdk.getHomePath(), path, ImmutableList.of("daemon"), androidHome);
    } catch (ExecutionException e) {
        LOG.warn("Unable to calculate command to watch Flutter devices", e);
        return null;
    }
}
Also used : FlutterSdk(io.flutter.sdk.FlutterSdk) ExecutionException(com.intellij.execution.ExecutionException) Workspace(io.flutter.bazel.Workspace) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with FlutterSdk

use of io.flutter.sdk.FlutterSdk in project flutter-intellij by flutter.

the class DebugTestRunner method canRun.

@Override
public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
    if (!DefaultDebugExecutor.EXECUTOR_ID.equals(executorId) || !(profile instanceof TestConfig)) {
        return false;
    }
    final FlutterSdk sdk = FlutterSdk.getFlutterSdk(((TestConfig) profile).getProject());
    if (sdk == null || !sdk.getVersion().flutterTestSupportsMachineMode()) {
        return false;
    }
    final TestConfig config = (TestConfig) profile;
    return config.getFields().getScope() != TestFields.Scope.DIRECTORY;
}
Also used : FlutterSdk(io.flutter.sdk.FlutterSdk)

Example 13 with FlutterSdk

use of io.flutter.sdk.FlutterSdk in project flutter-intellij by flutter.

the class FlutterModuleBuilder method commitModule.

@Nullable
@Override
public Module commitModule(@NotNull Project project, @Nullable ModifiableModuleModel model) {
    final String basePath = getModuleFileDirectory();
    if (basePath == null) {
        Messages.showErrorDialog("Module path not set", "Internal Error");
        return null;
    }
    final VirtualFile baseDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(basePath);
    if (baseDir == null) {
        Messages.showErrorDialog("Unable to determine Flutter project directory", "Internal Error");
        return null;
    }
    final FlutterSdk sdk = getFlutterSdk();
    if (sdk == null) {
        Messages.showErrorDialog("Flutter SDK not found", "Error");
        return null;
    }
    final OutputListener listener = new OutputListener();
    final PubRoot root = runFlutterCreateWithProgress(baseDir, sdk, project, listener, getAdditionalSettings());
    if (root == null) {
        final String stderr = listener.getOutput().getStderr();
        final String msg = stderr.isEmpty() ? "Flutter create command was unsuccessful" : stderr;
        final int code = FlutterMessages.showDialog(project, msg, "Project Creation Error", new String[] { "Run Flutter Doctor", "Cancel" }, 0);
        if (code == 0) {
            new FlutterDoctorAction().startCommand(project, sdk, null);
        }
        return null;
    }
    FlutterSdkUtil.updateKnownSdkPaths(sdk.getHomePath());
    // Create the Flutter module. This indirectly calls setupRootModule, etc.
    final Module flutter = super.commitModule(project, model);
    if (flutter == null) {
        return null;
    }
    FlutterModuleUtils.autoShowMain(project, root);
    addAndroidModule(project, model, basePath, flutter.getName());
    return flutter;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlutterDoctorAction(io.flutter.actions.FlutterDoctorAction) FlutterSdk(io.flutter.sdk.FlutterSdk) PubRoot(io.flutter.pub.PubRoot) OutputListener(com.intellij.execution.OutputListener) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with FlutterSdk

use of io.flutter.sdk.FlutterSdk in project flutter-intellij by flutter.

the class FlutterSmallIDEProjectGenerator method generateProject.

public static void generateProject(@NotNull Project project, @NotNull VirtualFile baseDir, @NotNull String flutterSdkPath, @NotNull Module module, @NotNull FlutterCreateAdditionalSettings settings) {
    final FlutterSdk sdk = FlutterSdk.forPath(flutterSdkPath);
    if (sdk == null) {
        FlutterMessages.showError("Error creating project", flutterSdkPath + " is not a valid Flutter SDK");
        return;
    }
    FlutterUtils.disableGradleProjectMigrationNotification(project);
    // Run "flutter create".
    final OutputListener listener = new OutputListener();
    final PubRoot root = sdk.createFiles(baseDir, module, listener, settings);
    if (root == null) {
        final String stderr = listener.getOutput().getStderr();
        final String msg = stderr.isEmpty() ? "Flutter create command was unsuccessful" : stderr;
        FlutterMessages.showError("Error creating project", msg);
        return;
    }
    final Runnable runnable = () -> applyDartModule(sdk, project, module, root);
    try {
        TransactionGuard.getInstance().submitTransactionAndWait(runnable);
    } catch (ProcessCanceledException e) {
        LOG.error(e);
    }
}
Also used : FlutterSdk(io.flutter.sdk.FlutterSdk) PubRoot(io.flutter.pub.PubRoot) OutputListener(com.intellij.execution.OutputListener) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 15 with FlutterSdk

use of io.flutter.sdk.FlutterSdk in project flutter-intellij by flutter.

the class SdkConfigurationNotificationProvider method createNotificationPanel.

@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull final FileEditor fileEditor) {
    // If this is a Bazel configured Flutter project, exit immediately, neither of the notifications should be shown for this project type.
    if (FlutterModuleUtils.isFlutterBazelProject(project))
        return null;
    if (file.getFileType() != DartFileType.INSTANCE)
        return null;
    final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile == null || psiFile.getLanguage() != DartLanguage.INSTANCE)
        return null;
    final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
    if (module == null || !FlutterModuleUtils.isFlutterModule(module))
        return null;
    final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
    if (flutterSdk == null) {
        return createNoFlutterSdkPanel(project);
    } else if (!flutterSdk.getVersion().isMinRecommendedSupported()) {
        return createOutOfDateFlutterSdkPanel(flutterSdk);
    }
    return null;
}
Also used : FlutterSdk(io.flutter.sdk.FlutterSdk) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Aggregations

FlutterSdk (io.flutter.sdk.FlutterSdk)15 PubRoot (io.flutter.pub.PubRoot)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 ExecutionException (com.intellij.execution.ExecutionException)4 Project (com.intellij.openapi.project.Project)4 Nullable (org.jetbrains.annotations.Nullable)3 OutputListener (com.intellij.execution.OutputListener)2 Module (com.intellij.openapi.module.Module)2 Workspace (io.flutter.bazel.Workspace)2 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 ScratchRootType (com.intellij.ide.scratch.ScratchRootType)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)1 IdeaLoggingEvent (com.intellij.openapi.diagnostic.IdeaLoggingEvent)1 SubmittedReportInfo (com.intellij.openapi.diagnostic.SubmittedReportInfo)1 PluginId (com.intellij.openapi.extensions.PluginId)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1