Java 类com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl 实例源码

项目:idea-php-typo3-plugin    文件:TYPO3ExtensionUtil.java   
/**
 * Traverses the given directories and returns the first valid
 * extension definition that's applicable.
 *
 * @param directories List of directories to analyze
 */
public static TYPO3ExtensionDefinition findContainingExtension(PsiDirectory[] directories) {
    for (PsiDirectory directory : directories) {
        VirtualDirectoryImpl virtualFile = (VirtualDirectoryImpl) directory.getVirtualFile();

        while (!isExtensionRootDirectory(virtualFile)) {
            if (virtualFile.getParent() == null) {
                return null;
            }

            virtualFile = virtualFile.getParent();
        }

        TYPO3ExtensionDefinition extensionDefinition = ExtensionDefinitionFactory.fromDirectory(virtualFile);
        if (extensionDefinition != null) {
            return extensionDefinition;
        }
    }

    return null;
}
项目:idea-php-typo3-plugin    文件:TYPO3ExtensionUtil.java   
/**
 * Determines if a directory is the top-most directory of an extension.
 * It does so by searching the "ext_emconf.php"
 *
 * @param virtualFile Directory to scan
 * @return true if the current directory is a root directory.
 */
private static boolean isExtensionRootDirectory(VirtualDirectoryImpl virtualFile) {
    VirtualFile[] immediateChildren = virtualFile.getChildren();
    for (VirtualFile file : immediateChildren) {
        if (file.getName().equals("ext_emconf.php")) {
            return true;
        }
    }
    return false;
}
项目:idea-php-typo3-plugin    文件:ExtensionDefinitionFactory.java   
public static TYPO3ExtensionDefinition fromDirectory(VirtualDirectoryImpl virtualDirectory) {
    TYPO3ExtensionDefinition extensionDefinition = null;

    // try finding composer manifest
    VirtualFileSystemEntry composerManifest = virtualDirectory.findChild("composer.json");
    if (composerManifest != null) {
        try {
            extensionDefinition = fromComposerManifest(composerManifest);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return extensionDefinition != null ? extensionDefinition : null;
}
项目:intellij-ce-playground    文件:PlatformTestCase.java   
private static void addSubTree(VirtualFile root, Set<VirtualFile> to) {
  if (root instanceof VirtualDirectoryImpl) {
    for (VirtualFile child : ((VirtualDirectoryImpl)root).getCachedChildren()) {
      if (child instanceof VirtualDirectoryImpl) {
        to.add(child);
        addSubTree(child, to);
      }
    }
  }
}
项目:intellij-ce-playground    文件:LocalFileSystemTest.java   
public void testFileCaseChange() throws Exception {
  if (SystemInfo.isFileSystemCaseSensitive) {
    System.err.println("Ignored: case-insensitive FS required");
    return;
  }

  File top = createTempDirectory(false);
  File file = IoTestUtil.createTestFile(top, "file.txt", "test");

  VirtualFile topDir = myFS.refreshAndFindFileByIoFile(top);
  assertNotNull(topDir);
  VirtualFile sourceFile = myFS.refreshAndFindFileByIoFile(file);
  assertNotNull(sourceFile);

  String newName = StringUtil.capitalize(file.getName());
  FileUtil.rename(file, newName);
  topDir.refresh(false, true);
  assertFalse(((VirtualDirectoryImpl)topDir).allChildrenLoaded());
  assertTrue(sourceFile.isValid());
  assertEquals(newName, sourceFile.getName());

  topDir.getChildren();
  newName = newName.toLowerCase(Locale.ENGLISH);
  FileUtil.rename(file, newName);
  topDir.refresh(false, true);
  assertTrue(((VirtualDirectoryImpl)topDir).allChildrenLoaded());
  assertTrue(sourceFile.isValid());
  assertEquals(newName, sourceFile.getName());
}
项目:intellij-ce-playground    文件:StudyProjectGenerator.java   
public static void openFirstTask(@NotNull final Course course, @NotNull final Project project) {
  LocalFileSystem.getInstance().refresh(false);
  final Lesson firstLesson = StudyUtils.getFirst(course.getLessons());
  final Task firstTask = StudyUtils.getFirst(firstLesson.getTaskList());
  final VirtualFile taskDir = firstTask.getTaskDir(project);
  if (taskDir == null) return;
  final Map<String, TaskFile> taskFiles = firstTask.getTaskFiles();
  VirtualFile activeVirtualFile = null;
  for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
    final String name = entry.getKey();
    final TaskFile taskFile = entry.getValue();
    final VirtualFile virtualFile = ((VirtualDirectoryImpl)taskDir).refreshAndFindChild(name);
    if (virtualFile != null) {
      FileEditorManager.getInstance(project).openFile(virtualFile, true);
      if (!taskFile.getAnswerPlaceholders().isEmpty()) {
        activeVirtualFile = virtualFile;
      }
    }
  }
  if (activeVirtualFile != null) {
    final PsiFile file = PsiManager.getInstance(project).findFile(activeVirtualFile);
    ProjectView.getInstance(project).select(file, activeVirtualFile, true);
    FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
  } else {
    String first = StudyUtils.getFirst(taskFiles.keySet());
    if (first != null) {
      NewVirtualFile firstFile = ((VirtualDirectoryImpl)taskDir).refreshAndFindChild(first);
      if (firstFile != null) {
        FileEditorManager.getInstance(project).openFile(firstFile, true);
      }
    }
  }
}
项目:vue-for-idea    文件:FileUtils.java   
public static List<String> getAllFilesInDirectory(VirtualFile directory, String target, String replacement) {
    List<String> files = new ArrayList<String>();
    VirtualFile[] children = directory.getChildren();
    for (VirtualFile child : children) {
        if (child instanceof VirtualDirectoryImpl) {
            files.addAll(getAllFilesInDirectory(child, target, replacement));
        } else if (child instanceof VirtualFileImpl) {
            files.add(child.getPath().replace(target, replacement));
        }
    }
    return files;
}
项目:tools-idea    文件:PlatformTestCase.java   
private static void addSubTree(VirtualFile root, Set<VirtualFile> to) {
  if (root instanceof VirtualDirectoryImpl) {
    for (VirtualFile child : ((VirtualDirectoryImpl)root).getCachedChildren()) {
      if (child instanceof VirtualDirectoryImpl) {
        to.add(child);
        addSubTree(child, to);
      }
    }
  }
}
项目:tools-idea    文件:LocalFileSystemTest.java   
public void testWindowsHiddenDirectory() throws Exception {
  if (!SystemInfo.isWindows) {
    System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME);
    return;
  }

  File file = new File("C:\\Documents and Settings\\desktop.ini");
  if (!file.exists()) {
    System.err.println(getName() + " skipped: missing " + file);
    return;
  }

  String parent = FileUtil.toSystemIndependentName(file.getParent());
  VirtualDirectoryImpl.allowRootAccess(parent);
  try {
    VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
    assertNotNull(virtualFile);

    NewVirtualFileSystem fs = (NewVirtualFileSystem)virtualFile.getFileSystem();
    FileAttributes attributes = fs.getAttributes(virtualFile);
    assertNotNull(attributes);
    assertEquals(FileAttributes.Type.FILE, attributes.type);
    assertEquals(FileAttributes.HIDDEN, attributes.flags);
  }
  finally {
    VirtualDirectoryImpl.disallowRootAccess(parent);
  }
}
项目:WebStormRequireJsPlugin    文件:FileUtils.java   
public static List<String> getAllFilesInDirectory(VirtualFile directory, String target, String replacement) {
    List<String> files = new ArrayList<String>();
    VirtualFile[] children = directory.getChildren();
    for (VirtualFile child : children) {
        if (child instanceof VirtualDirectoryImpl) {
            files.addAll(getAllFilesInDirectory(child, target, replacement));
        } else if (child instanceof VirtualFileImpl) {
            files.add(child.getPath().replace(target, replacement));
        }
    }
    return files;
}
项目:consulo    文件:PlatformTestCase.java   
private static void addSubTree(VirtualFile root, Set<VirtualFile> to) {
  if (root instanceof VirtualDirectoryImpl) {
    for (VirtualFile child : ((VirtualDirectoryImpl)root).getCachedChildren()) {
      if (child instanceof VirtualDirectoryImpl) {
        to.add(child);
        addSubTree(child, to);
      }
    }
  }
}
项目:consulo    文件:LocalFileSystemTest.java   
public void testFileCaseChange() throws Exception {
  if (SystemInfo.isFileSystemCaseSensitive) {
    System.err.println("Ignored: case-insensitive FS required");
    return;
  }

  File top = createTempDirectory(false);
  File file = IoTestUtil.createTestFile(top, "file.txt", "test");
  File intermediate = new File(top, "_intermediate_");

  VirtualFile topDir = myFS.refreshAndFindFileByIoFile(top);
  assertNotNull(topDir);
  VirtualFile sourceFile = myFS.refreshAndFindFileByIoFile(file);
  assertNotNull(sourceFile);

  String newName = StringUtil.capitalize(file.getName());
  FileUtil.rename(file, intermediate);
  FileUtil.rename(intermediate, new File(top, newName));
  topDir.refresh(false, true);
  assertFalse(((VirtualDirectoryImpl)topDir).allChildrenLoaded());
  assertTrue(sourceFile.isValid());
  assertEquals(newName, sourceFile.getName());

  topDir.getChildren();
  newName = newName.toLowerCase(Locale.ENGLISH);
  FileUtil.rename(file, intermediate);
  FileUtil.rename(intermediate, new File(top, newName));
  topDir.refresh(false, true);
  assertTrue(((VirtualDirectoryImpl)topDir).allChildrenLoaded());
  assertTrue(sourceFile.isValid());
  assertEquals(newName, sourceFile.getName());
}
项目:educational-plugin    文件:StudyUtils.java   
public static void openFirstTask(@NotNull final Course course, @NotNull final Project project) {
  LocalFileSystem.getInstance().refresh(false);
  final Lesson firstLesson = getFirst(course.getLessons());
  if (firstLesson == null) return;
  final Task firstTask = getFirst(firstLesson.getTaskList());
  if (firstTask == null) return;
  final VirtualFile taskDir = firstTask.getTaskDir(project);
  if (taskDir == null) return;
  final Map<String, TaskFile> taskFiles = firstTask.getTaskFiles();
  VirtualFile activeVirtualFile = null;
  for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
    final String relativePath = entry.getKey();
    final TaskFile taskFile = entry.getValue();
    taskDir.refresh(false, true);
    final VirtualFile virtualFile = taskDir.findFileByRelativePath(relativePath);
    if (virtualFile != null) {
      if (!taskFile.getActivePlaceholders().isEmpty()) {
        activeVirtualFile = virtualFile;
      }
    }
  }
  if (activeVirtualFile != null) {
    final PsiFile file = PsiManager.getInstance(project).findFile(activeVirtualFile);
    ProjectView.getInstance(project).select(file, activeVirtualFile, false);
    final FileEditor[] editors = FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
    if (editors.length == 0) {
      return;
    }
    final FileEditor studyEditor = editors[0];
    if (studyEditor instanceof StudyEditor) {
      selectFirstAnswerPlaceholder((StudyEditor)studyEditor, project);
    }
    FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
  }
  else {
    String first = getFirst(taskFiles.keySet());
    if (first != null) {
      NewVirtualFile firstFile = ((VirtualDirectoryImpl)taskDir).refreshAndFindChild(first);
      if (firstFile != null) {
        FileEditorManager.getInstance(project).openFile(firstFile, true);
      }
    }
  }
}
项目:intellij-ce-playground    文件:RefreshWorker.java   
private void processQueue(NewVirtualFileSystem fs, PersistentFS persistence) throws RefreshCancelledException {
  TObjectHashingStrategy<String> strategy = FilePathHashingStrategy.create(fs.isCaseSensitive());

  while (!myRefreshQueue.isEmpty()) {
    Pair<NewVirtualFile, FileAttributes> pair = myRefreshQueue.pullFirst();
    NewVirtualFile file = pair.first;
    boolean fileDirty = file.isDirty();
    debug(LOG, "file=%s dirty=%b", file, fileDirty);
    if (!fileDirty) continue;

    checkCancelled(file);

    FileAttributes attributes = pair.second != null ? pair.second : fs.getAttributes(file);
    if (attributes == null) {
      scheduleDeletion(file);
      continue;
    }

    NewVirtualFile parent = file.getParent();
    if (parent != null && checkAndScheduleFileTypeChange(parent, file, attributes)) {
      // ignore everything else
      file.markClean();
      continue ;
    }

    if (file.isDirectory()) {
      boolean fullSync = ((VirtualDirectoryImpl)file).allChildrenLoaded();
      if (fullSync) {
        fullDirRefresh(fs, persistence, strategy, (VirtualDirectoryImpl)file);
      }
      else {
        partialDirRefresh(fs, strategy, (VirtualDirectoryImpl)file);
      }
    }
    else {
      long currentTimestamp = persistence.getTimeStamp(file);
      long upToDateTimestamp = attributes.lastModified;
      long currentLength = persistence.getLastRecordedLength(file);
      long upToDateLength = attributes.length;

      if (currentTimestamp != upToDateTimestamp || currentLength != upToDateLength) {
        scheduleUpdateContent(file);
      }
    }

    boolean currentWritable = persistence.isWritable(file);
    boolean upToDateWritable = attributes.isWritable();
    if (LOG_ATTRIBUTES.isDebugEnabled()) {
      LOG_ATTRIBUTES.debug("file=" + file + " writable vfs=" + file.isWritable() + " persistence=" + currentWritable + " real=" + upToDateWritable);
    }
    if (currentWritable != upToDateWritable) {
      scheduleAttributeChange(file, VirtualFile.PROP_WRITABLE, currentWritable, upToDateWritable);
    }

    if (SystemInfo.isWindows) {
      boolean currentHidden = file.is(VFileProperty.HIDDEN);
      boolean upToDateHidden = attributes.isHidden();
      if (currentHidden != upToDateHidden) {
        scheduleAttributeChange(file, VirtualFile.PROP_HIDDEN, currentHidden, upToDateHidden);
      }
    }

    if (attributes.isSymLink()) {
      String currentTarget = file.getCanonicalPath();
      String upToDateTarget = fs.resolveSymLink(file);
      String upToDateVfsTarget = upToDateTarget != null ? FileUtil.toSystemIndependentName(upToDateTarget) : null;
      if (!Comparing.equal(currentTarget, upToDateVfsTarget)) {
        scheduleAttributeChange(file, VirtualFile.PROP_SYMLINK_TARGET, currentTarget, upToDateVfsTarget);
      }
    }

    if (myIsRecursive || !file.isDirectory()) {
      file.markClean();
    }
  }
}
项目:tools-idea    文件:PersistentFSImpl.java   
@Nullable
private VirtualFileSystemEntry findFileById(int id, boolean cachedOnly, TIntArrayList visited, int mask) {
  VirtualFileSystemEntry cached = myIdToDirCache.get(id);
  if (cached != null) return cached;

  if (visited != null && (visited.size() >= DEPTH_LIMIT || (mask & id) == id && visited.contains(id))) {
    @NonNls String sb = "Dead loop detected in persistent FS (id=" + id + " cached-only=" + cachedOnly + "):";
    for (int i = 0; i < visited.size(); i++) {
      int _id = visited.get(i);
      sb += "\n  " + _id + " '" + getName(_id) + "' " +
        String.format("%02x", getFileAttributes(_id)) + ' ' + myIdToDirCache.containsKey(_id);
    }
    LOG.error(sb);
    return null;
  }
  if (visited == null) visited = new TIntArrayList(DEPTH_LIMIT);
  visited.add(id);

  int parentId = getParent(id);
  VirtualFileSystemEntry result;
  if (parentId == 0) {
    myRootsLock.readLock().lock();
    try {
      result = myRootsById.get(id);
    }
    finally {
      myRootsLock.readLock().unlock();
    }
  }
  else {
    VirtualFileSystemEntry parentFile = findFileById(parentId, cachedOnly, visited, mask |= id);
    if (parentFile instanceof VirtualDirectoryImpl) {
      result = ((VirtualDirectoryImpl)parentFile).findChildById(id, cachedOnly);
    }
    else {
      result = null;
    }
  }

  if (result != null && result.isDirectory()) {
    VirtualFileSystemEntry old = myIdToDirCache.put(id, result);
    if (old != null) result = old;
  }
  return result;
}
项目:tools-idea    文件:FileWatcherTest.java   
public void testSubst() throws Exception {
  if (!SystemInfo.isWindows) {
    System.err.println("Ignored: Windows required");
    return;
  }

  File targetDir = createTestDir("top");
  File subDir = createTestDir(targetDir, "sub");
  File file = createTestFile(subDir, "test.txt");
  File rootFile = createSubst(targetDir.getAbsolutePath());
  VirtualDirectoryImpl.allowRootAccess(rootFile.getPath());
  VirtualFile vfsRoot = myFileSystem.findFileByIoFile(rootFile);

  try {
    assertNotNull(rootFile.getPath(), vfsRoot);
    File substDir = new File(rootFile, subDir.getName());
    File substFile = new File(substDir, file.getName());
    refresh(targetDir);
    refresh(substDir);

    LocalFileSystem.WatchRequest request = watch(substDir);
    try {
      myAccept = true;
      FileUtil.writeToFile(file, "new content");
      assertEvent(VFileContentChangeEvent.class, substFile.getAbsolutePath());

      LocalFileSystem.WatchRequest request2 = watch(targetDir);
      try {
        myAccept = true;
        FileUtil.delete(file);
        assertEvent(VFileDeleteEvent.class, file.getAbsolutePath(), substFile.getAbsolutePath());
      }
      finally {
        unwatch(request2);
      }

      myAccept = true;
      FileUtil.writeToFile(file, "re-creation");
      assertEvent(VFileCreateEvent.class, substFile.getAbsolutePath());
    }
    finally {
      unwatch(request);
    }
  }
  finally {
    delete(targetDir);
    IoTestUtil.deleteSubst(rootFile.getPath());
    if (vfsRoot != null) {
      ((NewVirtualFile)vfsRoot).markDirty();
      myFileSystem.refresh(false);
    }
    VirtualDirectoryImpl.disallowRootAccess(rootFile.getPath());
  }
}
项目:consulo    文件:RefreshWorker.java   
private void processQueue(NewVirtualFileSystem fs, PersistentFS persistence) throws RefreshCancelledException {
  TObjectHashingStrategy<String> strategy = FilePathHashingStrategy.create(fs.isCaseSensitive());

  while (!myRefreshQueue.isEmpty()) {
    Pair<NewVirtualFile, FileAttributes> pair = myRefreshQueue.pullFirst();
    NewVirtualFile file = pair.first;
    boolean fileDirty = file.isDirty();
    if (LOG.isTraceEnabled()) LOG.trace("file=" + file + " dirty=" + fileDirty);
    if (!fileDirty) continue;

    checkCancelled(file);

    FileAttributes attributes = pair.second != null ? pair.second : fs.getAttributes(file);
    if (attributes == null) {
      scheduleDeletion(file);
      continue;
    }

    NewVirtualFile parent = file.getParent();
    if (parent != null && checkAndScheduleFileTypeChange(parent, file, attributes)) {
      // ignore everything else
      file.markClean();
      continue ;
    }

    if (file.isDirectory()) {
      boolean fullSync = ((VirtualDirectoryImpl)file).allChildrenLoaded();
      if (fullSync) {
        fullDirRefresh(fs, persistence, strategy, (VirtualDirectoryImpl)file);
      }
      else {
        partialDirRefresh(fs, strategy, (VirtualDirectoryImpl)file);
      }
    }
    else {
      long currentTimestamp = persistence.getTimeStamp(file);
      long upToDateTimestamp = attributes.lastModified;
      long currentLength = persistence.getLastRecordedLength(file);
      long upToDateLength = attributes.length;

      if (currentTimestamp != upToDateTimestamp || currentLength != upToDateLength) {
        scheduleUpdateContent(file);
      }
    }

    boolean currentWritable = persistence.isWritable(file);
    boolean upToDateWritable = attributes.isWritable();
    if (LOG_ATTRIBUTES.isDebugEnabled()) {
      LOG_ATTRIBUTES.debug("file=" + file + " writable vfs=" + file.isWritable() + " persistence=" + currentWritable + " real=" + upToDateWritable);
    }
    if (currentWritable != upToDateWritable) {
      scheduleAttributeChange(file, VirtualFile.PROP_WRITABLE, currentWritable, upToDateWritable);
    }

    if (SystemInfo.isWindows) {
      boolean currentHidden = file.is(VFileProperty.HIDDEN);
      boolean upToDateHidden = attributes.isHidden();
      if (currentHidden != upToDateHidden) {
        scheduleAttributeChange(file, VirtualFile.PROP_HIDDEN, currentHidden, upToDateHidden);
      }
    }

    if (attributes.isSymLink()) {
      String currentTarget = file.getCanonicalPath();
      String upToDateTarget = fs.resolveSymLink(file);
      String upToDateVfsTarget = upToDateTarget != null ? FileUtil.toSystemIndependentName(upToDateTarget) : null;
      if (!Comparing.equal(currentTarget, upToDateVfsTarget)) {
        scheduleAttributeChange(file, VirtualFile.PROP_SYMLINK_TARGET, currentTarget, upToDateVfsTarget);
      }
    }

    if (myIsRecursive || !file.isDirectory()) {
      file.markClean();
    }
  }
}