use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class FileContent method createFromTempFile.
public static FileContent createFromTempFile(Project project, String name, String ext, @NotNull byte[] content) throws IOException {
File tempFile = FileUtil.createTempFile(name, "." + ext);
if (content.length != 0) {
FileUtil.writeToFile(tempFile, content);
}
tempFile.deleteOnExit();
final LocalFileSystem lfs = LocalFileSystem.getInstance();
VirtualFile file = lfs.findFileByIoFile(tempFile);
if (file == null) {
file = lfs.refreshAndFindFileByIoFile(tempFile);
}
if (file != null) {
return new FileContent(project, file);
}
throw new IOException("Can not create temp file for revision content");
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class MacPathChooserDialog method fileToVirtualFile.
private VirtualFile fileToVirtualFile(File file) {
final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
final String vfsPath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
return localFileSystem.refreshAndFindFileByPath(vfsPath);
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class RefreshVFsSynchronously method findFirstValidVirtualParent.
@Nullable
private static VirtualFile findFirstValidVirtualParent(@Nullable File file) {
LocalFileSystem lfs = LocalFileSystem.getInstance();
VirtualFile vf = null;
while (file != null && (vf == null || !vf.isValid())) {
vf = lfs.findFileByIoFile(file);
file = file.getParentFile();
}
return vf == null || !vf.isValid() ? null : vf;
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class StartupManagerImpl method checkProjectRoots.
private void checkProjectRoots() {
VirtualFile[] roots = ProjectRootManager.getInstance(myProject).getContentRoots();
if (roots.length == 0)
return;
LocalFileSystem fs = LocalFileSystem.getInstance();
if (!(fs instanceof LocalFileSystemImpl))
return;
FileWatcher watcher = ((LocalFileSystemImpl) fs).getFileWatcher();
if (!watcher.isOperational())
return;
PooledThreadExecutor.INSTANCE.submit(() -> {
LOG.debug("FW/roots waiting started");
while (true) {
if (myProject.isDisposed())
return;
if (!watcher.isSettingRoots())
break;
TimeoutUtil.sleep(10);
}
LOG.debug("FW/roots waiting finished");
Collection<String> manualWatchRoots = watcher.getManualWatchRoots();
if (!manualWatchRoots.isEmpty()) {
List<String> nonWatched = new SmartList<>();
for (VirtualFile root : roots) {
if (!(root.getFileSystem() instanceof LocalFileSystem))
continue;
String rootPath = root.getPath();
for (String manualWatchRoot : manualWatchRoots) {
if (FileUtil.isAncestor(manualWatchRoot, rootPath, false)) {
nonWatched.add(rootPath);
}
}
}
if (!nonWatched.isEmpty()) {
String message = ApplicationBundle.message("watcher.non.watchable.project");
watcher.notifyOnFailure(message, null);
LOG.info("unwatched roots: " + nonWatched);
LOG.info("manual watches: " + manualWatchRoots);
}
}
});
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class ChangesUtil method getValidParentUnderReadAction.
@Nullable
private static VirtualFile getValidParentUnderReadAction(@NotNull FilePath filePath) {
return ReadAction.compute(() -> {
VirtualFile result = null;
FilePath parent = filePath;
LocalFileSystem lfs = LocalFileSystem.getInstance();
while (result == null && parent != null) {
result = lfs.findFileByPath(parent.getPath());
parent = parent.getParentPath();
}
return result;
});
}
Aggregations