Search in sources :

Example 6 with FlutterSdk

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

the class FlutterProjectStep method updateSdkField.

private void updateSdkField(JTextComponent sdkEditor) {
    FlutterSdk current = FlutterSdk.forPath(sdkEditor.getText());
    Color color = sdkBackgroundColor;
    if (current == null) {
        if (ColorUtil.isDark(sdkBackgroundColor)) {
            color = ColorUtil.darker(JBColor.YELLOW, 5);
        } else {
            color = ColorUtil.desaturate(JBColor.YELLOW, 15);
        }
    }
    sdkEditor.setBackground(color);
}
Also used : FlutterSdk(io.flutter.sdk.FlutterSdk)

Example 7 with FlutterSdk

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

the class FlutterErrorReportSubmitter method submitAsync.

@SuppressWarnings("deprecation")
@Override
public void submitAsync(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo, @NotNull Component parentComponent, @NotNull Consumer<SubmittedReportInfo> consumer) {
    if (events.length == 0) {
        consumer.consume(new SubmittedReportInfo(null, null, SubmittedReportInfo.SubmissionStatus.FAILED));
        return;
    }
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
    Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        project = ProjectManager.getInstance().getDefaultProject();
    }
    final StringBuilder builder = new StringBuilder();
    builder.append("Please file this bug report at https://github.com/flutter/flutter-intellij/issues/new.\n");
    builder.append("\n");
    builder.append("---\n");
    builder.append("\n");
    builder.append("## What happened\n");
    builder.append("\n");
    if (additionalInfo != null) {
        builder.append(additionalInfo.trim()).append("\n");
    } else {
        builder.append("(please describe what you were doing when this exception occurred)\n");
    }
    builder.append("\n");
    builder.append("## Version information\n");
    builder.append("\n");
    // IntelliJ version
    final ApplicationInfo info = ApplicationInfo.getInstance();
    builder.append(info.getVersionName()).append(" `").append(info.getFullVersion()).append("`");
    final PluginId pid = FlutterUtils.getPluginId();
    final IdeaPluginDescriptor flutterPlugin = PluginManager.getPlugin(pid);
    // noinspection ConstantConditions
    builder.append(" • Flutter plugin `").append(pid.getIdString()).append(' ').append(flutterPlugin.getVersion()).append("`");
    final IdeaPluginDescriptor dartPlugin = PluginManager.getPlugin(PluginId.getId("Dart"));
    if (dartPlugin != null) {
        // noinspection ConstantConditions
        builder.append(" • Dart plugin `").append(dartPlugin.getVersion()).append("`");
    }
    builder.append("\n\n");
    final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
    if (sdk == null) {
        builder.append("No Flutter sdk configured.\n");
    } else {
        final String flutterVersion = getFlutterVersion(sdk);
        if (flutterVersion != null) {
            builder.append(flutterVersion.trim()).append("\n");
        } else {
            builder.append("Error getting Flutter sdk information.\n");
        }
    }
    builder.append("\n");
    for (IdeaLoggingEvent event : events) {
        builder.append("## Exception\n");
        builder.append("\n");
        builder.append(event.getMessage()).append("\n");
        builder.append("\n");
        if (event.getThrowable() != null) {
            builder.append("```\n");
            builder.append(event.getThrowableText().trim()).append("\n");
            builder.append("```\n");
            builder.append("\n");
            FlutterInitializer.getAnalytics().sendException(event.getThrowable(), false);
        }
    }
    final String text = builder.toString().trim() + "\n";
    // Create scratch file.
    final ScratchRootType scratchRoot = ScratchRootType.getInstance();
    final VirtualFile file = scratchRoot.createScratchFile(project, "bug-report.md", Language.ANY, text);
    if (file != null) {
        // Open the file.
        new OpenFileDescriptor(project, file).navigate(true);
    } else {
        consumer.consume(new SubmittedReportInfo(null, null, SubmittedReportInfo.SubmissionStatus.FAILED));
    }
    consumer.consume(new SubmittedReportInfo(null, "", SubmittedReportInfo.SubmissionStatus.NEW_ISSUE));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) IdeaLoggingEvent(com.intellij.openapi.diagnostic.IdeaLoggingEvent) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) FlutterSdk(io.flutter.sdk.FlutterSdk) ScratchRootType(com.intellij.ide.scratch.ScratchRootType) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) SubmittedReportInfo(com.intellij.openapi.diagnostic.SubmittedReportInfo)

Example 8 with FlutterSdk

use of io.flutter.sdk.FlutterSdk 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 9 with FlutterSdk

use of io.flutter.sdk.FlutterSdk 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 10 with FlutterSdk

use of io.flutter.sdk.FlutterSdk 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)

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