Search in sources :

Example 26 with PubRoot

use of io.flutter.pub.PubRoot 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 27 with PubRoot

use of io.flutter.pub.PubRoot 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 28 with PubRoot

use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.

the class FlutterProjectOpenProcessor method convertToFlutterProject.

/**
 * Sets up a project that doesn't have any Flutter modules.
 * <p>
 * (It probably wasn't created with "flutter create" and probably didn't have any IntelliJ configuration before.)
 */
private static void convertToFlutterProject(@NotNull Project project) {
    final PubRoot root = PubRoot.singleForProjectWithRefresh(project);
    if (root == null) {
        // Either no pub roots, or more than one.
        return;
    }
    final Module module = root.getModule(project);
    if (module == null) {
        // Shouldn't happen or root would have been null.
        return;
    }
    FlutterModuleUtils.setFlutterModuleAndReload(module, project);
}
Also used : PubRoot(io.flutter.pub.PubRoot) Module(com.intellij.openapi.module.Module)

Example 29 with PubRoot

use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.

the class FlutterProjectOpenProcessor method canOpenProject.

@Override
public boolean canOpenProject(@Nullable VirtualFile file) {
    if (file == null)
        return false;
    ApplicationInfo info = ApplicationInfo.getInstance();
    if (FlutterUtils.isAndroidStudio()) {
        return false;
    }
    final PubRoot root = PubRoot.forDirectory(file);
    return root != null && root.declaresFlutter();
}
Also used : ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) PubRoot(io.flutter.pub.PubRoot)

Aggregations

PubRoot (io.flutter.pub.PubRoot)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 Nullable (org.jetbrains.annotations.Nullable)9 FlutterSdk (io.flutter.sdk.FlutterSdk)7 Project (com.intellij.openapi.project.Project)4 ExecutionException (com.intellij.execution.ExecutionException)3 OutputListener (com.intellij.execution.OutputListener)2 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)2 Module (com.intellij.openapi.module.Module)2 DartFile (com.jetbrains.lang.dart.psi.DartFile)2 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 PsiDirectory (com.intellij.psi.PsiDirectory)1