use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class NewMappings method removeRedundantMappings.
// todo area for optimization
private void removeRedundantMappings() {
final LocalFileSystem lfs = LocalFileSystem.getInstance();
final AllVcsesI allVcses = AllVcses.getInstance(myProject);
for (Iterator<String> iterator = myVcsToPaths.keySet().iterator(); iterator.hasNext(); ) {
final String vcsName = iterator.next();
final Collection<VcsDirectoryMapping> mappings = myVcsToPaths.get(vcsName);
final List<Pair<VirtualFile, VcsDirectoryMapping>> objects = ObjectsConvertor.convert(mappings, new Convertor<VcsDirectoryMapping, Pair<VirtualFile, VcsDirectoryMapping>>() {
public Pair<VirtualFile, VcsDirectoryMapping> convert(final VcsDirectoryMapping dm) {
VirtualFile vf = lfs.findFileByPath(dm.getDirectory());
if (vf == null) {
vf = lfs.refreshAndFindFileByPath(dm.getDirectory());
}
return vf == null ? null : Pair.create(vf, dm);
}
}, ObjectsConvertor.NOT_NULL);
final List<Pair<VirtualFile, VcsDirectoryMapping>> filteredFiles;
// todo static
final Convertor<Pair<VirtualFile, VcsDirectoryMapping>, VirtualFile> fileConvertor = new Convertor<Pair<VirtualFile, VcsDirectoryMapping>, VirtualFile>() {
public VirtualFile convert(Pair<VirtualFile, VcsDirectoryMapping> o) {
return o.getFirst();
}
};
if (StringUtil.isEmptyOrSpaces(vcsName)) {
filteredFiles = AbstractVcs.filterUniqueRootsDefault(objects, fileConvertor);
} else {
final AbstractVcs<?> vcs = allVcses.getByName(vcsName);
if (vcs == null) {
VcsBalloonProblemNotifier.showOverChangesView(myProject, "VCS plugin not found for mapping to : '" + vcsName + "'", MessageType.ERROR);
continue;
}
filteredFiles = vcs.filterUniqueRoots(objects, fileConvertor);
}
final List<VcsDirectoryMapping> filteredMappings = ObjectsConvertor.convert(filteredFiles, new Convertor<Pair<VirtualFile, VcsDirectoryMapping>, VcsDirectoryMapping>() {
public VcsDirectoryMapping convert(final Pair<VirtualFile, VcsDirectoryMapping> o) {
return o.getSecond();
}
});
// to calculate what had been removed
mappings.removeAll(filteredMappings);
if (filteredMappings.isEmpty()) {
iterator.remove();
} else {
mappings.clear();
mappings.addAll(filteredMappings);
}
}
sortedMappingsByMap();
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class RefreshSessionImpl method scan.
public void scan() {
List<VirtualFile> workQueue = myWorkQueue;
myWorkQueue = new ArrayList<>();
boolean haveEventsToFire = myFinishRunnable != null || !myEvents.isEmpty();
if (!workQueue.isEmpty()) {
LocalFileSystem fs = LocalFileSystem.getInstance();
if (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 (!myIsRecursive && !myIsAsync) {
// always scan when non-recursive AND synchronous - needed e.g. when refreshing project files on open
nvf.markDirty();
}
RefreshWorker worker = new RefreshWorker(nvf, myIsRecursive);
myWorker = worker;
worker.scan();
haveEventsToFire |= myEvents.addAll(worker.getEvents());
}
count++;
if (LOG.isTraceEnabled())
LOG.trace("events=" + myEvents.size());
} while (!myCancelled && myIsRecursive && count < 3 && workQueue.stream().anyMatch(f -> ((NewVirtualFile) f).isDirty()));
if (t != 0) {
t = System.currentTimeMillis() - t;
LOG.trace((myCancelled ? "cancelled, " : "done, ") + t + " ms, events " + myEvents);
}
}
myWorker = null;
myHaveEventsToFire = haveEventsToFire;
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class VfsImplUtil method checkSubscription.
private static void checkSubscription() {
if (ourSubscribed.getAndSet(true))
return;
Application app = ApplicationManager.getApplication();
app.getMessageBus().connect(app).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
InvalidationState state = null;
synchronized (ourLock) {
for (VFileEvent event : events) {
if (!(event.getFileSystem() instanceof LocalFileSystem))
continue;
// created file should not invalidate + getFile is costly
if (event instanceof VFileCreateEvent)
continue;
if (event instanceof VFilePropertyChangeEvent && !VirtualFile.PROP_NAME.equals(((VFilePropertyChangeEvent) event).getPropertyName())) {
continue;
}
String path = event.getPath();
if (event instanceof VFilePropertyChangeEvent) {
path = ((VFilePropertyChangeEvent) event).getOldPath();
} else if (event instanceof VFileMoveEvent) {
path = ((VFileMoveEvent) event).getOldPath();
}
VirtualFile file = event.getFile();
if (file == null || !file.isDirectory()) {
state = InvalidationState.invalidate(state, path);
} else {
Collection<String> affectedPaths = ourDominatorsMap.get(path);
if (affectedPaths != null) {
// defensive copying; original may be updated on invalidation
affectedPaths = ContainerUtil.newArrayList(affectedPaths);
for (String affectedPath : affectedPaths) {
state = InvalidationState.invalidate(state, affectedPath);
}
}
}
}
}
if (state != null)
state.scheduleRefresh();
}
});
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class WinPathChooserDialog 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 MacFileSaverDialog method fileToVirtualFile.
private static VirtualFile fileToVirtualFile(File file) {
final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
final String vfsPath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
return localFileSystem.refreshAndFindFileByPath(vfsPath);
}
Aggregations