Java Code Examples for com.intellij.openapi.vfs.LocalFileSystem#getInstance()
The following examples show how to use
com.intellij.openapi.vfs.LocalFileSystem#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TFSDiffProvider.java From azure-devops-intellij with MIT License | 6 votes |
@Override public Map<VirtualFile, VcsRevisionNumber> getCurrentRevisions(Iterable<VirtualFile> files) { final ServerContext context = TFSVcs.getInstance(project).getServerContext(true); final List<String> filePaths = ContainerUtil.newArrayList(); for (VirtualFile file : files) { String filePath = file.getPath(); filePaths.add(filePath); } TfvcClient client = TfvcClient.getInstance(project); final LocalFileSystem fs = LocalFileSystem.getInstance(); final Map<VirtualFile, VcsRevisionNumber> revisionMap = ContainerUtil.newHashMap(); client.getLocalItemsInfo(context, filePaths, info -> { final String itemPath = info.getLocalItem(); final VirtualFile virtualFile = fs.findFileByPath(itemPath); if (virtualFile == null) { logger.error("VirtualFile not found for item " + itemPath); return; } revisionMap.put(virtualFile, createRevision(info, itemPath)); }); return revisionMap; }
Example 2
Source File: FileContent.java From consulo with Apache License 2.0 | 6 votes |
public static FileContent createFromTempFile(Project project, String name, String ext, @Nonnull 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"); }
Example 3
Source File: FilePathImpl.java From consulo with Apache License 2.0 | 6 votes |
public static FilePath createOn(String s) { File ioFile = new File(s); final LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); VirtualFile virtualFile = localFileSystem.findFileByIoFile(ioFile); if (virtualFile != null) { return new FilePathImpl(virtualFile); } else { VirtualFile virtualFileParent = localFileSystem.findFileByIoFile(ioFile.getParentFile()); if (virtualFileParent != null) { return new FilePathImpl(virtualFileParent, ioFile.getName(), false); } else { return null; } } }
Example 4
Source File: ProjectImporterCheckoutListener.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean processCheckedOutDirectory(Project project, File directory) { final File[] files = directory.listFiles(); if (files != null) { final LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); for (File file : files) { if (file.isDirectory()) continue; final VirtualFile virtualFile = localFileSystem.findFileByIoFile(file); if (virtualFile != null) { final ProjectOpenProcessor openProcessor = ProjectOpenProcessors.getInstance().findProcessor(file); if (openProcessor != null) { int rc = Messages.showYesNoDialog(project, VcsBundle .message("checkout.open.project.prompt", files[0].getPath()), VcsBundle.message("checkout.title"), Messages.getQuestionIcon()); if (rc == Messages.YES) { ProjectUtil.openAsync(virtualFile.getPath(), project, false, UIAccess.current()); } return true; } } } } return false; }
Example 5
Source File: PlatformTestCase.java From consulo with Apache License 2.0 | 6 votes |
public static void cleanupApplicationCaches(Project project) { if (project != null && !project.isDisposed()) { UndoManagerImpl globalInstance = (UndoManagerImpl)UndoManager.getGlobalInstance(); if (globalInstance != null) { globalInstance.dropHistoryInTests(); } ((UndoManagerImpl)UndoManager.getInstance(project)).dropHistoryInTests(); ((PsiManagerEx)PsiManager.getInstance(project)).getFileManager().cleanupForNextTest(); } LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl)LocalFileSystem.getInstance(); if (localFileSystem != null) { localFileSystem.cleanupForNextTest(); } LocalHistory.getInstance().cleanupForNextTest(); }
Example 6
Source File: LocalFilesystemModificationHandler.java From saros with GNU General Public License v2.0 | 6 votes |
/** * Instantiates a LocalFilesystemModificationHandler object. The handler, including the held * filesystem listener, is enabled by default. * * @see #initialize() * @see #dispose() */ public LocalFilesystemModificationHandler( Project project, EditorManager editorManager, ISarosSession session, FileReplacementInProgressObservable fileReplacementInProgressObservable, AnnotationManager annotationManager, LocalEditorHandler localEditorHandler) { this.project = project; this.editorManager = editorManager; this.session = session; this.fileReplacementInProgressObservable = fileReplacementInProgressObservable; this.annotationManager = annotationManager; this.localEditorHandler = localEditorHandler; this.enabled = false; this.disposed = false; this.localFileSystem = LocalFileSystem.getInstance(); }
Example 7
Source File: CSharpCreateFromTemplateHandler.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nullable @RequiredReadAction public static Module findModuleByPsiDirectory(final PsiDirectory directory) { LightVirtualFile l = new LightVirtualFile("test.cs", CSharpFileType.INSTANCE, "") { @Override public VirtualFile getParent() { return directory.getVirtualFile(); } @Nonnull @Override public VirtualFileSystem getFileSystem() { return LocalFileSystem.getInstance(); } }; return CreateFileFromTemplateAction.ModuleResolver.EP_NAME.composite().resolveModule(directory, CSharpFileType.INSTANCE); }
Example 8
Source File: SyncProjectDialog.java From p4ic4idea with Apache License 2.0 | 6 votes |
@Nullable public VirtualFile getDirectory() { if (directoryField == null) { return null; } String text = directoryField.getText(); if (text == null || text.trim().isEmpty()) { return null; } final File parent = new File(text); LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile file = lfs.findFileByIoFile(parent); if (file == null) { file = lfs.refreshAndFindFileByIoFile(parent); } return file; }
Example 9
Source File: ProjectStoreImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void setProjectFilePathNoUI(@Nonnull final String filePath) { final StateStorageManager stateStorageManager = getStateStorageManager(); final LocalFileSystem fs = LocalFileSystem.getInstance(); final File file = new File(filePath); final File dirStore = file.isDirectory() ? new File(file, Project.DIRECTORY_STORE_FOLDER) : new File(file.getParentFile(), Project.DIRECTORY_STORE_FOLDER); String defaultFilePath = new File(dirStore, "misc.xml").getPath(); // deprecated stateStorageManager.addMacro(StoragePathMacros.PROJECT_FILE, defaultFilePath); stateStorageManager.addMacro(StoragePathMacros.DEFAULT_FILE, defaultFilePath); final File ws = new File(dirStore, "workspace.xml"); stateStorageManager.addMacro(StoragePathMacros.WORKSPACE_FILE, ws.getPath()); stateStorageManager.addMacro(StoragePathMacros.PROJECT_CONFIG_DIR, dirStore.getPath()); VfsUtil.markDirtyAndRefresh(false, true, true, fs.refreshAndFindFileByIoFile(dirStore)); myPresentableUrl = null; }
Example 10
Source File: FileExperimentLoader.java From intellij with Apache License 2.0 | 5 votes |
private void doInitialize() { LocalFileSystem fileSystem = LocalFileSystem.getInstance(); fileSystem.addRootToWatch(file.getPath(), /* watchRecursively= */ false); // We need to look up the file in the VFS or else we don't receive events about it. This works // even if the returned VirtualFile is null (because the experiments file doesn't exist yet). fileSystem.findFileByIoFile(file); ApplicationManager.getApplication() .getMessageBus() .connect() .subscribe(VirtualFileManager.VFS_CHANGES, new RefreshExperimentsListener()); }
Example 11
Source File: RemoteRevisionsNumbersCache.java From consulo with Apache License 2.0 | 5 votes |
RemoteRevisionsNumbersCache(final Project project) { myProject = project; myLock = new Object(); myData = new HashMap<>(); myRefreshingQueues = Collections.synchronizedMap(new HashMap<VcsRoot, LazyRefreshingSelfQueue<String>>()); myLatestRevisionsMap = new HashMap<>(); myLfs = LocalFileSystem.getInstance(); myVcsManager = ProjectLevelVcsManager.getInstance(project); myVcsConfiguration = VcsConfiguration.getInstance(project); }
Example 12
Source File: CompilerUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void refreshIODirectories(@Nonnull final Collection<File> files) { final LocalFileSystem lfs = LocalFileSystem.getInstance(); final List<VirtualFile> filesToRefresh = new ArrayList<VirtualFile>(); for (File file : files) { final VirtualFile virtualFile = lfs.refreshAndFindFileByIoFile(file); if (virtualFile != null) { filesToRefresh.add(virtualFile); } } if (!filesToRefresh.isEmpty()) { RefreshQueue.getInstance().refresh(false, true, null, filesToRefresh); } }
Example 13
Source File: ScratchFileServiceImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public Collection<VirtualFile> additionalRoots(Project project) { Set<VirtualFile> result = ContainerUtil.newLinkedHashSet(); LocalFileSystem fileSystem = LocalFileSystem.getInstance(); ScratchFileService app = ScratchFileService.getInstance(); for (RootType r : RootType.getAllRootTypes()) { ContainerUtil.addIfNotNull(result, fileSystem.findFileByPath(app.getRootPath(r))); } return result; }
Example 14
Source File: AndroidModuleLibraryManager.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void fileChanged(@NotNull final Project project, @NotNull final VirtualFile file) { if (!BUILD_FILE_NAME.equals(file.getName())) { return; } if (LocalFileSystem.getInstance() != file.getFileSystem() && !ApplicationManager.getApplication().isUnitTestMode()) { return; } if (!VfsUtilCore.isAncestor(project.getBaseDir(), file, true)) { return; } getInstance(project).scheduleUpdate(); }
Example 15
Source File: FileBasedTest.java From consulo with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { final TestFixtureBuilder<IdeaProjectTestFixture> testFixtureBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(); myProjectFixture = testFixtureBuilder.getFixture(); myProjectFixture.setUp(); myProject = myProjectFixture.getProject(); myLocalFileSystem = LocalFileSystem.getInstance(); }
Example 16
Source File: FileGroupingProjectNode.java From consulo with Apache License 2.0 | 5 votes |
public FileGroupingProjectNode(Project project, File file, ViewSettings viewSettings) { super(project, file, viewSettings); final LocalFileSystem lfs = LocalFileSystem.getInstance(); myVirtualFile = lfs.findFileByIoFile(file); if (myVirtualFile == null) { myVirtualFile = lfs.refreshAndFindFileByIoFile(file); } }
Example 17
Source File: VirtualFileSystemProviderImpl.java From intellij with Apache License 2.0 | 4 votes |
@Override public LocalFileSystem getSystem() { return LocalFileSystem.getInstance(); }
Example 18
Source File: Unity3dPackageOrderEntry.java From consulo-unity3d with Apache License 2.0 | 4 votes |
@Nonnull @Override @RequiredReadAction public VirtualFile[] getFiles(@Nonnull OrderRootType rootType) { List<VirtualFile> files = new ArrayList<>(); if(rootType == BinariesOrderRootType.getInstance() || rootType == SourcesOrderRootType.getInstance()) { LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); // moved to project files String projectPackageCache = getProjectPackageCache(); VirtualFile localFile = localFileSystem.findFileByIoFile(new File(projectPackageCache, myNameWithVersion)); addDotNetModulesInsideLibrary(files, localFile); if(files.isEmpty()) { Unity3dPackageWatcher watcher = Unity3dPackageWatcher.getInstance(); for(String path : watcher.getPackageDirPaths()) { VirtualFile file = localFileSystem.findFileByIoFile(new File(path, myNameWithVersion)); addDotNetModulesInsideLibrary(files, file); } } } if(files.isEmpty()) { Sdk sdk = getSdk(); if(sdk != null) { VirtualFile homeDirectory = sdk.getHomeDirectory(); if(homeDirectory != null) { VirtualFile builtInDirectory = homeDirectory.findFileByRelativePath(getBuiltInPackagesRelativePath()); if(builtInDirectory != null) { VirtualFile packageDirectory = builtInDirectory.findChild(getPackageName()); ContainerUtil.addIfNotNull(files, packageDirectory); } } } } return VfsUtilCore.toVirtualFileArray(files); }
Example 19
Source File: RefreshSessionImpl.java From consulo with Apache License 2.0 | 4 votes |
void scan() { List<VirtualFile> workQueue = myWorkQueue; myWorkQueue = new ArrayList<>(); boolean forceRefresh = !myIsRecursive && !myIsAsync; // shallow sync refresh (e.g. project config files on open) if (!workQueue.isEmpty()) { LocalFileSystem fs = LocalFileSystem.getInstance(); if (!forceRefresh && fs instanceof LocalFileSystemImpl) { ((LocalFileSystemImpl)fs).markSuspiciousFilesDirty(workQueue); } long t = 0; if (LOG.isTraceEnabled()) { LOG.trace("scanning " + workQueue); t = System.currentTimeMillis(); } int count = 0; refresh: do { if (LOG.isTraceEnabled()) LOG.trace("try=" + count); for (VirtualFile file : workQueue) { if (myCancelled) break refresh; NewVirtualFile nvf = (NewVirtualFile)file; if (forceRefresh) { nvf.markDirty(); } else if (!nvf.isDirty()) { continue; } RefreshWorker worker = new RefreshWorker(nvf, myIsRecursive); myWorker = worker; worker.scan(); myEvents.addAll(worker.getEvents()); } count++; if (LOG.isTraceEnabled()) LOG.trace("events=" + myEvents.size()); } while (!myCancelled && myIsRecursive && count < 3 && ContainerUtil.exists(workQueue, f -> ((NewVirtualFile)f).isDirty())); if (t != 0) { t = System.currentTimeMillis() - t; LOG.trace((myCancelled ? "cancelled, " : "done, ") + t + " ms, events " + myEvents); } } myWorker = null; }
Example 20
Source File: StartupManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
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()) { //ProjectFsStatsCollector.watchedRoots(myProject, -1); return; } myApplication.executeOnPooledThread(() -> { 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(); int pctNonWatched = 0; 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); pctNonWatched = (int)(100.0 * nonWatched.size() / roots.length); } } //ProjectFsStatsCollector.watchedRoots(myProject, pctNonWatched); }); }