Search in sources :

Example 6 with PubRoot

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

the class TestConfigProducer method setupForDirectory.

private boolean setupForDirectory(TestConfig config, PsiDirectory dir) {
    final PubRoot root = PubRoot.forDescendant(dir.getVirtualFile(), dir.getProject());
    if (root == null)
        return false;
    if (!root.hasTests(dir.getVirtualFile()))
        return false;
    config.setFields(TestFields.forDir(dir.getVirtualFile().getPath()));
    config.setGeneratedName();
    return true;
}
Also used : PubRoot(io.flutter.pub.PubRoot)

Example 7 with PubRoot

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

the class RenderThread method setFile.

/**
 * Set a new file, with or without outline.
 */
public void setFile(@Nullable VirtualFile file, @Nullable FlutterOutline fileOutline, @Nullable String instrumentedCode) {
    myFile = file;
    myFileOutline = fileOutline;
    myInstrumentedCode = instrumentedCode;
    myPackages = null;
    final PubRoot pubRoot = PubRoot.forFile(file);
    if (pubRoot != null) {
        myPackages = pubRoot.getPackages();
    }
    myWidgetOutline = null;
}
Also used : PubRoot(io.flutter.pub.PubRoot)

Example 8 with PubRoot

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

the class FlutterInitializer method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    // Convert all modules of deprecated type FlutterModuleType.
    if (FlutterModuleUtils.convertFromDeprecatedModuleType(project)) {
        // If any modules were converted over, create a notification
        FlutterMessages.showInfo(FlutterBundle.message("flutter.initializer.module.converted.title"), "Converted from '" + FlutterModuleUtils.DEPRECATED_FLUTTER_MODULE_TYPE_ID + "' to '" + FlutterModuleUtils.getModuleTypeIDForFlutter() + "'.");
    }
    // Disable the 'Migrate Project to Gradle' notification.
    FlutterUtils.disableGradleProjectMigrationNotification(project);
    // Start watching for devices.
    DeviceService.getInstance(project);
    // Start watching for Flutter debug active events.
    FlutterViewFactory.init(project);
    // If the project declares a Flutter dependency, do some extra initialization.
    final PubRoot root = PubRoot.singleForProjectWithRefresh(project);
    if (root != null && root.declaresFlutter()) {
        // Set Android SDK.
        if (root.hasAndroidModule(project)) {
            ensureAndroidSdk(project);
        }
        // Setup a default run configuration for 'main.dart' (if it's not there already and the file exists).
        FlutterModuleUtils.autoCreateRunConfig(project, root);
        // Ensure a run config is selected and ready to go.
        FlutterModuleUtils.ensureRunConfigSelected(project);
        // If there are no open editors, show main.
        final FileEditorManager editorManager = FileEditorManager.getInstance(project);
        if (editorManager.getOpenFiles().length == 0) {
            FlutterModuleUtils.autoShowMain(project, root);
        }
    }
    FlutterRunNotifications.init(project);
    // Watch save actions for reload on save.
    FlutterReloadManager.init(project);
    // Watch save actions for format on save.
    FlutterSaveActionsManager.init(project);
    // Start watching for project structure and .packages file changes.
    final FlutterPluginsLibraryManager libraryManager = new FlutterPluginsLibraryManager(project);
    libraryManager.startWatching();
    // Initialize the analytics notification group.
    NotificationsConfiguration.getNotificationsConfiguration().register(Analytics.GROUP_DISPLAY_ID, NotificationDisplayType.STICKY_BALLOON, false);
    // Initialize analytics.
    final PropertiesComponent properties = PropertiesComponent.getInstance();
    if (!properties.getBoolean(analyticsToastShown)) {
        properties.setValue(analyticsToastShown, true);
        final Notification notification = new Notification(Analytics.GROUP_DISPLAY_ID, "Welcome to Flutter!", FlutterBundle.message("flutter.analytics.notification.content"), NotificationType.INFORMATION, (notification1, event) -> {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if ("url".equals(event.getDescription())) {
                    BrowserUtil.browse("https://www.google.com/policies/privacy/");
                }
            }
        });
        notification.addAction(new AnAction("Sounds good!") {

            @Override
            public void actionPerformed(AnActionEvent event) {
                notification.expire();
                final Analytics analytics = getAnalytics();
                // We only track for flutter projects.
                if (FlutterModuleUtils.usesFlutter(project)) {
                    ToolWindowTracker.track(project, analytics);
                }
            }
        });
        notification.addAction(new AnAction("No thanks") {

            @Override
            public void actionPerformed(AnActionEvent event) {
                notification.expire();
                setCanReportAnalytics(false);
            }
        });
        Notifications.Bus.notify(notification);
    } else {
        // We only track for flutter projects.
        if (FlutterModuleUtils.usesFlutter(project)) {
            ToolWindowTracker.track(project, getAnalytics());
        }
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PubRoot(io.flutter.pub.PubRoot) FlutterPluginsLibraryManager(io.flutter.sdk.FlutterPluginsLibraryManager) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) AnAction(com.intellij.openapi.actionSystem.AnAction) Analytics(io.flutter.analytics.Analytics)

Example 9 with PubRoot

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

the class FlutterDependencyInspection method checkFile.

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
    if (!isOnTheFly)
        return null;
    if (!(psiFile instanceof DartFile))
        return null;
    if (DartPlugin.isPubActionInProgress())
        return null;
    final VirtualFile file = FlutterUtils.getRealVirtualFile(psiFile);
    if (file == null || !file.isInLocalFileSystem())
        return null;
    final Project project = psiFile.getProject();
    if (!ProjectRootManager.getInstance(project).getFileIndex().isInContent(file))
        return null;
    final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
    final Module module = ModuleUtilCore.findModuleForFile(file, project);
    if (!FlutterModuleUtils.isFlutterModule(module))
        return null;
    final PubRoot root = PubRoot.forPsiFile(psiFile);
    if (root == null || myIgnoredPubspecPaths.contains(root.getPubspec().getPath()))
        return null;
    if (root.getPackages() == null) {
        return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("packages.get.never.done"));
    }
    if (!root.hasUpToDatePackages()) {
        return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("pubspec.edited"));
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartFile(com.jetbrains.lang.dart.psi.DartFile) FlutterSdk(io.flutter.sdk.FlutterSdk) PubRoot(io.flutter.pub.PubRoot) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with PubRoot

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

the class FlutterModuleBuilder method runFlutterCreateWithProgress.

/**
 * Runs flutter create without showing a console, but with an indeterminate progress dialog.
 * <p>
 * Returns the PubRoot if successful.
 */
@Nullable
private static PubRoot runFlutterCreateWithProgress(@NotNull VirtualFile baseDir, @NotNull FlutterSdk sdk, @NotNull Project project, @Nullable ProcessListener processListener, @Nullable FlutterCreateAdditionalSettings additionalSettings) {
    final ProgressManager progress = ProgressManager.getInstance();
    final AtomicReference<PubRoot> result = new AtomicReference<>(null);
    FlutterUtils.disableGradleProjectMigrationNotification(project);
    progress.runProcessWithProgressSynchronously(() -> {
        progress.getProgressIndicator().setIndeterminate(true);
        result.set(sdk.createFiles(baseDir, null, processListener, additionalSettings));
    }, "Creating Flutter Project", false, project);
    return result.get();
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) PubRoot(io.flutter.pub.PubRoot) AtomicReference(java.util.concurrent.atomic.AtomicReference) Nullable(org.jetbrains.annotations.Nullable)

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