Search in sources :

Example 16 with PubRoot

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

the class OpenInXcodeAction method openFile.

private static void openFile(@NotNull VirtualFile file) {
    final Project project = ProjectUtil.guessProjectForFile(file);
    final FlutterSdk sdk = project != null ? FlutterSdk.getFlutterSdk(project) : null;
    if (sdk == null) {
        FlutterSdkAction.showMissingSdkDialog(project);
        return;
    }
    final PubRoot pubRoot = PubRoot.forFile(file);
    if (pubRoot == null) {
        FlutterMessages.showError("Error Opening Xcode", "Unable to run `flutter build` (no pub root found)");
        return;
    }
    // Trigger an iOS build if necessary.
    if (!hasBeenBuilt(pubRoot)) {
        final ProgressHelper progressHelper = new ProgressHelper(project);
        progressHelper.start("Building for iOS");
        sdk.flutterBuild(pubRoot, "ios", "--debug").start(null, new ProcessAdapter() {

            @Override
            public void processTerminated(@NotNull ProcessEvent event) {
                progressHelper.done();
                if (event.getExitCode() != 0) {
                    FlutterMessages.showError("Error Opening Xcode", "`flutter build` returned: " + event.getExitCode());
                    return;
                }
                openWithXcode(file.getPath());
            }
        });
    } else {
        openWithXcode(file.getPath());
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProgressHelper(io.flutter.utils.ProgressHelper) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) FlutterSdk(io.flutter.sdk.FlutterSdk) PubRoot(io.flutter.pub.PubRoot)

Example 17 with PubRoot

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

the class FlutterReloadManager method shouldBlockReload.

private static boolean shouldBlockReload(@NotNull DartServerData.DartError error, @NotNull Project project, @Nullable Module module) {
    // Only block on errors.
    if (!error.getSeverity().equals(AnalysisErrorSeverity.ERROR))
        return false;
    final File file = new File(error.getAnalysisErrorFileSD());
    final VirtualFile virtualFile = VfsUtil.findFileByIoFile(file, false);
    if (virtualFile != null) {
        final List<PubRoot> roots = module == null ? PubRoots.forProject(project) : PubRoots.forModule(module);
        for (PubRoot root : roots) {
            // Skip errors in test files.
            final String relativePath = root.getRelativePath(virtualFile);
            if (relativePath != null && relativePath.startsWith("test/"))
                return false;
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PubRoot(io.flutter.pub.PubRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Example 18 with PubRoot

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

the class SdkFields method createFlutterSdkRunCommand.

/**
 * Create a command to run 'flutter run --machine'.
 */
public GeneralCommandLine createFlutterSdkRunCommand(@NotNull Project project, @Nullable FlutterDevice device, @NotNull RunMode mode) throws ExecutionException {
    final MainFile main = MainFile.verify(filePath, project).get();
    final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
    if (flutterSdk == null) {
        throw new ExecutionException(FlutterBundle.message("flutter.sdk.is.not.configured"));
    }
    final PubRoot root = PubRoot.forDirectory(main.getAppDir());
    if (root == null) {
        throw new ExecutionException("Entrypoint isn't within a Flutter pub root");
    }
    String[] args = additionalArgs == null ? new String[] {} : additionalArgs.split(" ");
    if (buildFlavor != null) {
        args = ArrayUtil.append(args, "--flavor=" + buildFlavor);
    }
    final FlutterCommand command = flutterSdk.flutterRun(root, main.getFile(), device, mode, args);
    return command.createGeneralCommandLine(project);
}
Also used : FlutterCommand(io.flutter.sdk.FlutterCommand) FlutterSdk(io.flutter.sdk.FlutterSdk) PubRoot(io.flutter.pub.PubRoot) ExecutionException(com.intellij.execution.ExecutionException)

Example 19 with PubRoot

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

the class InspectorPanel method isCreatedByLocalProject.

boolean isCreatedByLocalProject(DiagnosticsNode node) {
    if (node.isCreatedByLocalProject()) {
        return true;
    }
    // TODO(jacobr): remove the following code once the
    // `setPubRootDirectories` method has been in two revs of the Flutter Alpha
    // channel. The feature is expected to have landed in the Flutter dev
    // chanel on March 2, 2018.
    final InspectorSourceLocation location = node.getCreationLocation();
    if (location == null) {
        return false;
    }
    final VirtualFile file = location.getFile();
    if (file == null) {
        return false;
    }
    final String filePath = file.getCanonicalPath();
    if (filePath != null) {
        for (PubRoot root : getFlutterApp().getPubRoots()) {
            final String canonicalPath = root.getRoot().getCanonicalPath();
            if (canonicalPath != null && filePath.startsWith(canonicalPath)) {
                return true;
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PubRoot(io.flutter.pub.PubRoot)

Example 20 with PubRoot

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

the class FlutterSdkUtil method guessFlutterSdkFromPackagesFile.

/**
 * Parse any .packages file and infer the location of the Flutter SDK from that.
 */
@Nullable
public static String guessFlutterSdkFromPackagesFile(@NotNull Module module) {
    final PubRoot pubRoot = PubRoot.forModuleWithRefresh(module);
    if (pubRoot == null) {
        return null;
    }
    final VirtualFile packagesFile = pubRoot.getPackages();
    if (packagesFile == null) {
        return null;
    }
    // parse it
    try {
        final String contents = new String(packagesFile.contentsToByteArray(true));
        return parseFlutterSdkPath(contents);
    } catch (IOException e) {
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PubRoot(io.flutter.pub.PubRoot) IOException(java.io.IOException) 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