use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.
the class JrtFileSystemImpl method checkSubscription.
private void checkSubscription() {
if (mySubscribed.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) {
Set<VirtualFile> toRefresh = null;
for (VFileEvent event : events) {
if (event.getFileSystem() instanceof LocalFileSystem && event instanceof VFileContentChangeEvent) {
VirtualFile file = event.getFile();
if (file != null && "release".equals(file.getName())) {
String homePath = file.getParent().getPath();
ArchiveHandler handler = myHandlers.remove(homePath);
if (handler != null) {
handler.dispose();
VirtualFile root = findFileByPath(composeRootPath(homePath));
if (root != null) {
((NewVirtualFile) root).markDirtyRecursively();
if (toRefresh == null)
toRefresh = ContainerUtil.newHashSet();
toRefresh.add(root);
}
}
}
}
}
if (toRefresh != null) {
boolean async = !ApplicationManager.getApplication().isUnitTestMode();
RefreshQueue.getInstance().refresh(async, true, null, toRefresh);
}
}
});
}
use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.
the class RefreshWorker method checkCancelled.
private void checkCancelled(@NotNull NewVirtualFile stopAt) {
if (myCancelled || ourCancellingCondition != null && ourCancellingCondition.fun(stopAt)) {
if (LOG.isTraceEnabled())
LOG.trace("cancelled at: " + stopAt);
forceMarkDirty(stopAt);
while (!myRefreshQueue.isEmpty()) {
NewVirtualFile next = myRefreshQueue.pullFirst().first;
forceMarkDirty(next);
}
throw new RefreshCancelledException();
}
}
use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.
the class PersistentFsTest method checkMustCreateRootWithCanonicalPath.
private void checkMustCreateRootWithCanonicalPath(String jarName) throws IOException {
File tmp = createTempDirectory();
File x = new File(tmp, jarName);
assertTrue(x.createNewFile());
JarFileSystem jfs = JarFileSystem.getInstance();
String path = x.getPath() + "/../" + x.getName() + JarFileSystem.JAR_SEPARATOR;
NewVirtualFile root = myFs.findRoot(path, jfs);
assertFalse(root.getPath(), root.getPath().contains("../"));
assertFalse(root.getPath(), root.getPath().contains("/.."));
}
use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.
the class RemoveBomAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(e.getDataContext());
if (files == null) {
return;
}
List<VirtualFile> filesToProcess = getFilesWithBom(files, true);
for (VirtualFile virtualFile : filesToProcess) {
byte[] bom = virtualFile.getBOM();
assert bom != null;
if (virtualFile instanceof NewVirtualFile) {
virtualFile.setBOM(null);
NewVirtualFile file = (NewVirtualFile) virtualFile;
try {
byte[] bytes = file.contentsToByteArray();
byte[] contentWithStrippedBom = new byte[bytes.length - bom.length];
System.arraycopy(bytes, bom.length, contentWithStrippedBom, 0, contentWithStrippedBom.length);
WriteAction.run(() -> file.setBinaryContent(contentWithStrippedBom));
} catch (IOException ex) {
LOG.warn("Unexpected exception occurred on attempt to remove BOM from file " + file, ex);
}
}
}
}
use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.
the class FileListeningTest method buildDBFileStructure.
private static StringBuilder buildDBFileStructure(@NotNull VirtualFile from, int level, @NotNull StringBuilder builder) {
List<VirtualFile> children = ContainerUtil.newArrayList(((NewVirtualFile) from).getCachedChildren());
Collections.sort(children, (o1, o2) -> o1.getName().compareTo(o2.getName()));
for (VirtualFile eachChild : children) {
builder.append(StringUtil.repeat(" ", level)).append(eachChild.getName()).append("\n");
buildDBFileStructure(eachChild, level + 1, builder);
}
return builder;
}
Aggregations