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