Search in sources :

Example 36 with LocalFileSystem

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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 37 with LocalFileSystem

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);
}
Also used : LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem)

Example 38 with LocalFileSystem

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with LocalFileSystem

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);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) FileWatcher(com.intellij.openapi.vfs.impl.local.FileWatcher) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) LocalFileSystemImpl(com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl) SmartList(com.intellij.util.SmartList)

Example 40 with LocalFileSystem

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;
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)58 VirtualFile (com.intellij.openapi.vfs.VirtualFile)52 File (java.io.File)27 Nullable (org.jetbrains.annotations.Nullable)9 NotNull (org.jetbrains.annotations.NotNull)8 IOException (java.io.IOException)6 Project (com.intellij.openapi.project.Project)5 Change (com.intellij.openapi.vcs.changes.Change)5 Test (org.junit.Test)5 Module (com.intellij.openapi.module.Module)4 Application (com.intellij.openapi.application.Application)3 Library (com.intellij.openapi.roots.libraries.Library)3 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 PsiFile (com.intellij.psi.PsiFile)3 Notification (com.intellij.notification.Notification)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)2