Search in sources :

Example 1 with PubRoot

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

the class OpenInAndroidStudioAction method findProjectFile.

// A plugin contains an example app, which needs to be opened when the native Android is to be edited.
// In the case of an app that contains a plugin the flutter_app/flutter_plugin/example/android should be opened when
// 'Open in Android Studio' is requested.
protected static VirtualFile findProjectFile(@Nullable AnActionEvent e) {
    if (e != null) {
        final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
        if (file != null && file.exists()) {
            // We have a selection. Check if it is within a plugin.
            final Project project = e.getProject();
            assert (project != null);
            final VirtualFile projectDir = project.getBaseDir();
            for (PubRoot root : PubRoots.forProject(project)) {
                if (root.isFlutterPlugin()) {
                    VirtualFile rootFile = root.getRoot();
                    VirtualFile aFile = file;
                    while (aFile != null) {
                        if (aFile.equals(rootFile)) {
                            // We know a plugin resource is selected. Find the example app for it.
                            for (VirtualFile child : rootFile.getChildren()) {
                                if (isExampleWithAndroidWithApp(child)) {
                                    return child.findChild("android");
                                }
                            }
                        }
                        if (aFile.equals(projectDir)) {
                            aFile = null;
                        } else {
                            aFile = aFile.getParent();
                        }
                    }
                }
            }
            if (isProjectFileName(file.getName())) {
                return getProjectForFile(file);
            }
            // Return null if this is an ios folder.
            if (FlutterExternalIdeActionGroup.isWithinIOsDirectory(file, project)) {
                return null;
            }
        }
        final Project project = e.getProject();
        if (project != null) {
            return getProjectForFile(findStudioProjectFile(project));
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PubRoot(io.flutter.pub.PubRoot)

Example 2 with PubRoot

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

the class InspectorPanel method setActivate.

void setActivate(boolean enabled) {
    if (!enabled) {
        onIsolateStopped();
        isActive = false;
        return;
    }
    if (isActive) {
        // Already activated.
        return;
    }
    isActive = true;
    assert (getInspectorService() != null);
    getInspectorService().addClient(this);
    final ArrayList<String> rootDirectories = new ArrayList<>();
    for (PubRoot root : getFlutterApp().getPubRoots()) {
        rootDirectories.add(root.getRoot().getCanonicalPath());
    }
    getInspectorService().setPubRootDirectories(rootDirectories);
    getInspectorService().isWidgetTreeReady().thenAccept((Boolean ready) -> {
        if (ready) {
            recomputeTreeRoot();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) PubRoot(io.flutter.pub.PubRoot)

Example 3 with PubRoot

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

the class TestFields method getSuggestedName.

/**
 * Generates a name for these test settings, if they are valid.
 */
@NotNull
public String getSuggestedName(@NotNull Project project, @NotNull String defaultName) {
    switch(getScope()) {
        case NAME:
            final String name = getTestName();
            if (name == null)
                return defaultName;
            return name;
        case FILE:
            final VirtualFile file = getFileOrDir();
            if (file == null)
                return defaultName;
            return "tests in " + file.getName();
        case DIRECTORY:
            final String relativePath = getRelativePath(project);
            if (relativePath != null)
                return "tests in " + relativePath;
            // check if it's the pub root itself.
            final PubRoot root = getPubRoot(project);
            if (root != null && root.getRoot().equals(getFileOrDir())) {
                return "all tests in " + root.getRoot().getName();
            }
    }
    return defaultName;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PubRoot(io.flutter.pub.PubRoot) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PubRoot

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

the class TestFields method run.

/**
 * Starts running the tests.
 */
ProcessHandler run(@NotNull Project project, @NotNull RunMode mode) throws ExecutionException {
    final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
    if (sdk == null) {
        throw new ExecutionException("The Flutter SDK is not configured");
    }
    final VirtualFile fileOrDir = getFileOrDir();
    if (fileOrDir == null) {
        throw new ExecutionException("File or directory not found");
    }
    final String testName = getTestName();
    final PubRoot root = getPubRoot(project);
    if (root == null) {
        throw new ExecutionException("Test file isn't within a Flutter pub root");
    }
    return sdk.flutterTest(root, fileOrDir, testName, mode).startProcess(project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlutterSdk(io.flutter.sdk.FlutterSdk) PubRoot(io.flutter.pub.PubRoot) ExecutionException(com.intellij.execution.ExecutionException)

Example 5 with PubRoot

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

the class TestLaunchState method create.

static TestLaunchState create(@NotNull ExecutionEnvironment env, @NotNull TestConfig config) throws ExecutionException {
    final TestFields fields = config.getFields();
    try {
        fields.checkRunnable(env.getProject());
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
    final VirtualFile fileOrDir = fields.getFileOrDir();
    assert (fileOrDir != null);
    final PubRoot pubRoot = fields.getPubRoot(env.getProject());
    assert (pubRoot != null);
    final FlutterSdk sdk = FlutterSdk.getFlutterSdk(env.getProject());
    assert (sdk != null);
    final boolean testConsoleEnabled = sdk.getVersion().flutterTestSupportsMachineMode();
    final TestLaunchState launcher = new TestLaunchState(env, config, fileOrDir, pubRoot, testConsoleEnabled);
    DaemonConsoleView.install(launcher, env, pubRoot.getRoot());
    return launcher;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlutterSdk(io.flutter.sdk.FlutterSdk) PubRoot(io.flutter.pub.PubRoot) ExecutionException(com.intellij.execution.ExecutionException) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

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