Search in sources :

Example 46 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 47 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)

Example 48 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class ConfigFileFactoryImpl method createFileFromTemplate.

@Nullable
private VirtualFile createFileFromTemplate(@Nullable final Project project, String url, final String templateName, final boolean forceNew) {
    final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    final File file = new File(VfsUtilCore.urlToPath(url));
    VirtualFile existingFile = fileSystem.refreshAndFindFileByIoFile(file);
    if (existingFile != null) {
        existingFile.refresh(false, false);
        if (!existingFile.isValid()) {
            existingFile = null;
        }
    }
    if (existingFile != null && !forceNew) {
        return existingFile;
    }
    try {
        String text = getText(templateName, project);
        final VirtualFile childData;
        if (existingFile == null || existingFile.isDirectory()) {
            final VirtualFile virtualFile;
            if (!FileUtil.createParentDirs(file) || (virtualFile = fileSystem.refreshAndFindFileByIoFile(file.getParentFile())) == null) {
                throw new IOException(IdeBundle.message("error.message.unable.to.create.file", file.getPath()));
            }
            childData = virtualFile.createChildData(this, file.getName());
        } else {
            childData = existingFile;
        }
        VfsUtil.saveText(childData, text);
        return childData;
    } catch (final IOException e) {
        LOG.info(e);
        ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(IdeBundle.message("message.text.error.creating.deployment.descriptor", e.getLocalizedMessage()), IdeBundle.message("message.text.creating.deployment.descriptor")));
    }
    return null;
}
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) Nullable(org.jetbrains.annotations.Nullable)

Example 49 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class SvnBranchConfigurationManager method resolveAllBranchPoints.

@NotNull
private Set<Pair<VirtualFile, SvnBranchConfigurationNew>> resolveAllBranchPoints() {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    final UrlSerializationHelper helper = new UrlSerializationHelper(SvnVcs.getInstance(myProject));
    final Set<Pair<VirtualFile, SvnBranchConfigurationNew>> branchPointsToLoad = ContainerUtil.newHashSet();
    for (Map.Entry<String, SvnBranchConfiguration> entry : myConfigurationBean.myConfigurationMap.entrySet()) {
        final SvnBranchConfiguration configuration = entry.getValue();
        final VirtualFile root = lfs.refreshAndFindFileByIoFile(new File(entry.getKey()));
        if (root == null) {
            LOG.info("root not found: " + entry.getKey());
            continue;
        }
        final SvnBranchConfiguration configToConvert;
        if ((!myConfigurationBean.mySupportsUserInfoFilter) || configuration.isUserinfoInUrl()) {
            configToConvert = helper.afterDeserialization(entry.getKey(), configuration);
        } else {
            configToConvert = configuration;
        }
        final SvnBranchConfigurationNew newConfig = new SvnBranchConfigurationNew();
        newConfig.setTrunkUrl(configToConvert.getTrunkUrl());
        newConfig.setUserinfoInUrl(configToConvert.isUserinfoInUrl());
        for (String branchUrl : configToConvert.getBranchUrls()) {
            List<SvnBranchItem> stored = getStored(branchUrl);
            if (stored != null && !stored.isEmpty()) {
                newConfig.addBranches(branchUrl, new InfoStorage<>(stored, InfoReliability.setByUser));
            } else {
                branchPointsToLoad.add(Pair.create(root, newConfig));
                newConfig.addBranches(branchUrl, new InfoStorage<>(new ArrayList<>(), InfoReliability.empty));
            }
        }
        myBunch.updateForRoot(root, new InfoStorage<>(newConfig, InfoReliability.setByUser), false);
    }
    return branchPointsToLoad;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class HgUtil method convertToLocalVirtualFile.

/**
   * Convert {@link VcsVirtualFile} to the {@link LocalFileSystem local} Virtual File.
   *
   * TODO
   * It is a workaround for the following problem: VcsVirtualFiles returned from the {@link FileHistoryPanelImpl} contain the current path
   * of the file, not the path that was in certain revision. This has to be fixed by making {@link HgFileRevision} implement
   * {@link VcsFileRevisionEx}.
   */
@Nullable
public static VirtualFile convertToLocalVirtualFile(@Nullable VirtualFile file) {
    if (!(file instanceof AbstractVcsVirtualFile)) {
        return file;
    }
    LocalFileSystem lfs = LocalFileSystem.getInstance();
    VirtualFile resultFile = lfs.findFileByPath(file.getPath());
    if (resultFile == null) {
        resultFile = lfs.refreshAndFindFileByPath(file.getPath());
    }
    return resultFile;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 File (java.io.File)32 Nullable (org.jetbrains.annotations.Nullable)10 NotNull (org.jetbrains.annotations.NotNull)8 IOException (java.io.IOException)7 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 Library (com.intellij.openapi.roots.libraries.Library)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 PsiFile (com.intellij.psi.PsiFile)4 Application (com.intellij.openapi.application.Application)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 Notification (com.intellij.notification.Notification)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)2