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);
}
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));
}
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;
}
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());
}
}
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);
}
Aggregations