com.intellij.openapi.vfs.pointers.VirtualFilePointer Java Examples

The following examples show how to use com.intellij.openapi.vfs.pointers.VirtualFilePointer. 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: VirtualFilePointerManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private synchronized void assertAllPointersDisposed() {
  List<VirtualFilePointer> leaked = new ArrayList<>(dumpAllPointers());
  Collections.sort(leaked, Comparator.comparing(VirtualFilePointer::getUrl));
  for (VirtualFilePointer pointer : leaked) {
    try {
      ((VirtualFilePointerImpl)pointer).getTraceableDisposable().throwDisposalError("Not disposed pointer: " + pointer);
    }
    finally {
      ((VirtualFilePointerImpl)pointer).dispose();
    }
  }

  synchronized (myContainers) {
    if (!myContainers.isEmpty()) {
      VirtualFilePointerContainerImpl container = myContainers.iterator().next();
      container.getTraceableDisposable().throwDisposalError("Not disposed container");
    }
  }
}
 
Example #2
Source File: LibraryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<String> getInvalidRootUrls(@Nonnull OrderRootType type) {
  if (myDisposed) return Collections.emptyList();

  VirtualFilePointerContainer container = myRoots.get(type);
  final List<VirtualFilePointer> pointers = container == null ? Collections.emptyList() : container.getList();
  List<String> invalidPaths = null;
  for (VirtualFilePointer pointer : pointers) {
    if (!pointer.isValid()) {
      if (invalidPaths == null) {
        invalidPaths = new SmartList<>();
      }
      invalidPaths.add(pointer.getUrl());
    }
  }
  return ContainerUtil.notNullize(invalidPaths);
}
 
Example #3
Source File: ContentEntryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private List<ContentFolder> getFolders0(Predicate<ContentFolderTypeProvider> predicate) {
  List<ContentFolder> list = new ArrayList<>(myContentFolders.size());
  for (ContentFolder contentFolder : myContentFolders) {
    if (predicate.apply(contentFolder.getType())) {
      list.add(contentFolder);
    }
  }

  Module module = getModuleRootLayer().getModule();
  if(module.getModuleDirUrl() == null) {
    return list;
  }

  if (predicate.apply(ExcludedContentFolderTypeProvider.getInstance())) {
    for (DirectoryIndexExcludePolicy excludePolicy : DirectoryIndexExcludePolicy.EP_NAME.getExtensions(getRootModel().getProject())) {
      final VirtualFilePointer[] files = excludePolicy.getExcludeRootsForModule(myModuleRootLayer);
      for (VirtualFilePointer file : files) {
        list.add(new LightContentFolderImpl(file, ExcludedContentFolderTypeProvider.getInstance(), this));
      }
    }
  }
  return list;
}
 
Example #4
Source File: LibraryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean removeRoot(@Nonnull String url, @Nonnull OrderRootType rootType) {
  checkDisposed();
  LOG.assertTrue(isWritable());

  final VirtualFilePointerContainer container = myRoots.get(rootType);
  final VirtualFilePointer byUrl = container == null ? null : container.findByUrl(url);
  if (byUrl != null) {
    container.remove(byUrl);
    if (myExcludedRoots != null) {
      for (String excludedRoot : myExcludedRoots.getUrls()) {
        if (!isUnderRoots(excludedRoot)) {
          VirtualFilePointer pointer = myExcludedRoots.findByUrl(excludedRoot);
          if (pointer != null) {
            myExcludedRoots.remove(pointer);
          }
        }
      }
    }
    container.removeJarDirectory(url);
    return true;
  }
  return false;
}
 
Example #5
Source File: ExcludeCompilerOutputPolicy.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public VirtualFilePointer[] getExcludeRootsForModule(@Nonnull final ModuleRootLayer moduleRootLayer) {
  ModuleCompilerPathsManager manager = ModuleCompilerPathsManager.getInstance(moduleRootLayer.getModule());
  List<VirtualFilePointer> result = new ArrayList<VirtualFilePointer>(3);

  if (manager.isInheritedCompilerOutput()) {
    final VirtualFilePointer compilerOutputPointer = CompilerConfiguration.getInstance(myProject).getCompilerOutputPointer();
    for (ContentEntry contentEntry : moduleRootLayer.getContentEntries()) {
      if (compilerOutputPointer.getUrl().contains(contentEntry.getUrl())) {
        result.add(compilerOutputPointer);
      }
    }
  }
  else {
    if (!manager.isExcludeOutput()) {
      return VirtualFilePointer.EMPTY_ARRAY;
    }

    for (ContentFolderTypeProvider contentFolderType : ContentFolderTypeProvider.filter(ContentFolderScopes.productionAndTest())) {
      result.add(manager.getCompilerOutputPointer(contentFolderType));
    }
  }
  return result.isEmpty() ? VirtualFilePointer.EMPTY_ARRAY : result.toArray(new VirtualFilePointer[result.size()]);
}
 
Example #6
Source File: FileTreeNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean acceptFilter(Pair<PackageSetBase, NamedScopesHolder> filter, boolean showOnlyFilteredItems) {
  try {
    VirtualFilePointer filePointer = getFilePointer();
    if (!filePointer.isValid()) {
      return false;
    }
    VirtualFile file = filePointer.getFile();
    if (file != null && file.isValid() && filter.first.contains(file, filter.second)) {
      applyFilter(true);
      return true;
    }
  }
  catch (Throwable e) {
    // TODO: catch and ignore exceptions: see to FilePatternPackageSet
    // sometimes for new file DirectoryFileIndex.getContentRootForFile() return random path
  }
  return false;
}
 
Example #7
Source File: ProjectRootManagerComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeValidityChanged(@Nonnull VirtualFilePointer[] pointers) {
  if (!myProject.isDisposed()) {
    if (myInsideRefresh == 0) {
      if (affectsRoots(pointers)) {
        beforeRootsChange(false);
        if (myDoLogCachesUpdate) LOG.debug(new Throwable(pointers.length > 0 ? pointers[0].getPresentableUrl() : ""));
      }
    }
    else if (!myPointerChangesDetected) {
      //this is the first pointer changing validity
      if (affectsRoots(pointers)) {
        myPointerChangesDetected = true;
        myProject.getMessageBus().syncPublisher(ProjectTopics.PROJECT_ROOTS).beforeRootsChange(new ModuleRootEventImpl(myProject, false));
        if (myDoLogCachesUpdate) LOG.debug(new Throwable(pointers.length > 0 ? pointers[0].getPresentableUrl() : ""));
      }
    }
  }
}
 
Example #8
Source File: BackgroundTaskByVfsChangeTaskImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public BackgroundTaskByVfsChangeTaskImpl(@Nonnull Project project,
                                         @Nonnull VirtualFilePointer pointer,
                                         @Nonnull BackgroundTaskByVfsParameters parameters,
                                         @Nonnull String providerName,
                                         @Nonnull String name,
                                         @Nullable BackgroundTaskByVfsChangeProvider provider,
                                         @Nonnull BackgroundTaskByVfsChangeManagerImpl manager) {
  myProject = project;
  myParameters = parameters;
  myVirtualFilePointer = pointer;

  myProviderName = providerName;
  myName = name;
  myProvider = provider;
  myManager = manager;
}
 
Example #9
Source File: VirtualFilePointerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testMultipleNotifications() throws Exception {
  final File tempDir = createTempDirectory();
  final File file_f1 = new File(tempDir, "f1");
  final File file_f2 = new File(tempDir, "f2");
  final LoggingListener listener = new LoggingListener();
  final VirtualFilePointer pointer_f1 = createPointerByFile(file_f1, listener);
  final VirtualFilePointer pointer_f2 = createPointerByFile(file_f2, listener);
  assertFalse(pointer_f1.isValid());
  assertFalse(pointer_f2.isValid());
  file_f1.createNewFile();
  file_f2.createNewFile();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      LocalFileSystem.getInstance().refresh(false);
    }
  });
  assertEquals("[before:false:false, after:true:true]", listener.getLog().toString());
}
 
Example #10
Source File: VirtualFilePointerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testTwoPointersBecomeOneAfterFileRenamedUnderTheOtherName() throws IOException {
  final File tempDir = createTempDirectory();
  final File f1 = new File(tempDir, "f1");
  boolean created = f1.createNewFile();
  assertTrue(created);

  final String url1 = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, f1.getCanonicalPath().replace(File.separatorChar, '/'));
  final VirtualFile vFile1 = refreshAndFind(url1);

  VirtualFilePointer pointer1 = myVirtualFilePointerManager.create(url1, disposable, null);
  assertTrue(pointer1.isValid());
  String url2 = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, tempDir.getCanonicalPath().replace(File.separatorChar, '/')+"/f2");
  VirtualFilePointer pointer2 = myVirtualFilePointerManager.create(url2, disposable, null);
  assertFalse(pointer2.isValid());

  rename(vFile1, "f2");

  assertTrue(pointer1.isValid());
  assertTrue(pointer2.isValid());
}
 
Example #11
Source File: ModuleCompilerPathsManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public String getCompilerOutputUrl(@Nonnull ContentFolderTypeProvider contentFolderType) {
  if (!myInheritOutput) {
    VirtualFilePointer virtualFilePointer = myVirtualFilePointers.get(contentFolderType.getId());
    if (virtualFilePointer != null) {
      return virtualFilePointer.getUrl();
    }
  }

  String backUrl = myCompilerConfiguration.getCompilerOutputUrl() + "/" + contentFolderType.getId().toLowerCase() + "/" + myModule.getName();

  VirtualFile compilerOutput = myCompilerConfiguration.getCompilerOutput();
  if (compilerOutput == null) {
    return backUrl;
  }
  VirtualFile outDir = compilerOutput.findFileByRelativePath(contentFolderType.getId().toLowerCase() + "/" + myModule.getName());
  return outDir != null ? outDir.getUrl() : backUrl;
}
 
Example #12
Source File: ModuleCompilerPathsManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public VirtualFile getCompilerOutput(@Nonnull ContentFolderTypeProvider contentFolderType) {
  if (!myInheritOutput) {
    VirtualFilePointer virtualFilePointer = myVirtualFilePointers.get(contentFolderType.getId());
    if (virtualFilePointer != null) {
      return virtualFilePointer.getFile();
    }
  }

  VirtualFile compilerOutput = myCompilerConfiguration.getCompilerOutput();
  if (compilerOutput == null) {
    return null;
  }
  VirtualFile outDir = compilerOutput.findFileByRelativePath(contentFolderType.getId().toLowerCase() + "/" + myModule.getName());
  return outDir != null ? outDir : null;
}
 
Example #13
Source File: ModuleCompilerPathsManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Element getState() {
  if (myInheritOutput) {
    return null;
  }

  Element moduleElement = new Element(MODULE_OUTPUT_TAG);
  moduleElement.setAttribute(NAME, myModule.getName());
  if (!isExcludeOutput()) {
    moduleElement.setAttribute(EXCLUDE, String.valueOf(isExcludeOutput()));
  }

  for (Map.Entry<String, VirtualFilePointer> tempEntry : myVirtualFilePointers.entrySet()) {
    final Element elementForOutput = createElementForOutput(tempEntry.getValue());
    elementForOutput.setAttribute(TYPE, tempEntry.getKey());
    moduleElement.addContent(elementForOutput);
  }

  return moduleElement;
}
 
Example #14
Source File: HistoryEntry.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static HistoryEntry createHeavy(@Nonnull Project project,
                                       @Nonnull VirtualFile file,
                                       @Nonnull FileEditorProvider[] providers,
                                       @Nonnull FileEditorState[] states,
                                       @Nonnull FileEditorProvider selectedProvider) {
  if (project.isDisposed()) return createLight(file, providers, states, selectedProvider);

  Disposable disposable = Disposable.newDisposable();
  VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(file, disposable, null);

  HistoryEntry entry = new HistoryEntry(pointer, selectedProvider, disposable);
  for (int i = 0; i < providers.length; i++) {
    FileEditorProvider provider = providers[i];
    FileEditorState state = states[i];
    if (provider != null && state != null) {
      entry.putState(provider, state);
    }
  }
  return entry;
}
 
Example #15
Source File: ProjectRootManagerComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeValidityChanged(@Nonnull VirtualFilePointer[] pointers) {
  if (myProject.isDisposed()) {
    return;
  }

  if (myInsideRefresh == 0) {
    beforeRootsChange(false);
    if (LOG_CACHES_UPDATE || LOG.isDebugEnabled()) {
      LOG.debug(new Throwable(pointers.length > 0 ? pointers[0].getPresentableUrl() : ""));
    }
  }
  else if (!myPointerChangesDetected) {
    //this is the first pointer changing validity
    myPointerChangesDetected = true;
    myProject.getMessageBus().syncPublisher(ProjectTopics.PROJECT_ROOTS).beforeRootsChange(new ModuleRootEventImpl(myProject, false));
    if (LOG_CACHES_UPDATE || LOG.isDebugEnabled()) {
      LOG.debug(new Throwable(pointers.length > 0 ? pointers[0].getPresentableUrl() : ""));
    }
  }
}
 
Example #16
Source File: UpdateInfoTree.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void step() {
  myNext = null;
  while (myEnum.hasMoreElements()) {
    final Object o = myEnum.nextElement();
    if (o instanceof FileTreeNode) {
      final FileTreeNode treeNode = (FileTreeNode)o;
      VirtualFilePointer filePointer = treeNode.getFilePointer();
      if (!filePointer.isValid()) continue;

      myNext = getFilePath(filePointer);
      myStatus = FileStatus.MODIFIED;

      final GroupTreeNode parent = findParentGroupTreeNode(treeNode.getParent());
      if (parent != null) {
        final String id = parent.getFileGroupId();
        if (FileGroup.CREATED_ID.equals(id)) {
          myStatus = FileStatus.ADDED;
        }
        else if (FileGroup.REMOVED_FROM_REPOSITORY_ID.equals(id)) {
          myStatus = FileStatus.DELETED;
        }
      }
      break;
    }
  }
}
 
Example #17
Source File: VirtualFilePointerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void stressRead(@Nonnull final VirtualFilePointer pointer) {
  boolean b = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(10, null), null, false, new Processor<Object>() {
    @Override
    public boolean process(Object o) {
      ApplicationManager.getApplication().runReadAction(new Runnable() {
        @Override
        public void run() {
          VirtualFile file = pointer.getFile();
          if (file != null && !file.isValid()) {
            throw new IncorrectOperationException("I've caught it. I am that good");
          }
        }
      });

      return true;
    }
  });
  assertTrue(b);
}
 
Example #18
Source File: ModuleCompilerPathsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public VirtualFilePointer getCompilerOutputPointer(@Nonnull ContentFolderTypeProvider contentFolderType) {
  if (myInheritOutput) {
    throw new IllegalArgumentException("Then module is inherit output dir - output virtual file pointer not exists");
  }
  else {
    VirtualFilePointer virtualFilePointer = myVirtualFilePointers.get(contentFolderType.getId());
    if (virtualFilePointer != null) {
      return virtualFilePointer;
    }
    return new LightFilePointer(myCompilerConfiguration.getCompilerOutputUrl() + "/" + contentFolderType.getId().toLowerCase() + "/" + myModule.getName());
  }
}
 
Example #19
Source File: VirtualFilePointerContainerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public VirtualFilePointer findByUrl(@Nonnull String url) {
  checkDisposed();
  for (VirtualFilePointer pointer : ContainerUtil.concat(myList, myJarDirectories, myJarRecursiveDirectories)) {
    if (url.equals(pointer.getUrl())) return pointer;
  }
  return null;
}
 
Example #20
Source File: VirtualFilePointerContainerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private int indexOf(@Nonnull final String url) {
  for (int i = 0; i < myList.size(); i++) {
    final VirtualFilePointer pointer = myList.get(i);
    if (url.equals(pointer.getUrl())) {
      return i;
    }
  }

  return -1;
}
 
Example #21
Source File: VirtualFilePointerContainerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public String[] getUrls() {
  if (myTimeStampOfCachedThings == UNINITIALIZED) {
    // optimization: when querying urls, and nothing was cached yet, do not access disk (in cacheThings()) - can be expensive
    return myList.stream().map(VirtualFilePointer::getUrl).toArray(String[]::new);
  }
  return getOrCache().first;
}
 
Example #22
Source File: VirtualFilePointerManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@TestOnly
@Nonnull
synchronized List<VirtualFilePointer> getPointersUnder(@Nonnull VirtualFile parent, @Nonnull String childName) {
  assert !StringUtil.isEmptyOrSpaces(childName);
  MultiMap<VirtualFilePointerListener, FilePointerPartNode> nodes = MultiMap.create();
  addRelevantPointers(parent, toNameId(childName), nodes, true, parent.getFileSystem());
  List<VirtualFilePointer> pointers = new ArrayList<>();
  for (FilePointerPartNode node : nodes.values()) {
    node.addAllPointersTo(pointers);
  }
  return pointers;
}
 
Example #23
Source File: VirtualFilePointerManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
synchronized Collection<VirtualFilePointer> dumpAllPointers() {
  Collection<VirtualFilePointer> result = new THashSet<>();
  for (Map<VirtualFilePointerListener, FilePointerPartNode> myPointers : myRoots.values()) {
    for (FilePointerPartNode node : myPointers.values()) {
      dumpPointersRecursivelyTo(node, result);
    }
  }
  return result;
}
 
Example #24
Source File: VirtualFilePointerContainerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void writeJarDirs(@Nonnull List<? extends VirtualFilePointer> myJarDirectories, @Nonnull Element element, boolean recursive) {
  List<VirtualFilePointer> jarDirectories = new ArrayList<>(myJarDirectories);
  Collections.sort(jarDirectories, Comparator.comparing(VirtualFilePointer::getUrl, String.CASE_INSENSITIVE_ORDER));
  for (VirtualFilePointer pointer : jarDirectories) {
    String url = pointer.getUrl();
    final Element jarDirElement = new Element(JAR_DIRECTORY_ELEMENT);
    jarDirElement.setAttribute(URL_ATTR, url);
    jarDirElement.setAttribute(RECURSIVE_ATTR, Boolean.toString(recursive));
    element.addContent(jarDirElement);
  }
}
 
Example #25
Source File: HistoryEntry.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static HistoryEntry createLight(@Nonnull Project project, @Nonnull Element e) throws InvalidDataException {
  EntryData entryData = parseEntry(project, e);

  VirtualFilePointer pointer = new LightFilePointer(entryData.url);
  HistoryEntry entry = new HistoryEntry(pointer, entryData.selectedProvider, null);
  for (Pair<FileEditorProvider, FileEditorState> state : entryData.providerStates) {
    entry.putState(state.first, state.second);
  }
  return entry;
}
 
Example #26
Source File: HistoryEntry.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static HistoryEntry createLight(@Nonnull VirtualFile file,
                                       @Nonnull FileEditorProvider[] providers,
                                       @Nonnull FileEditorState[] states,
                                       @Nonnull FileEditorProvider selectedProvider) {
  VirtualFilePointer pointer = new LightFilePointer(file);
  HistoryEntry entry = new HistoryEntry(pointer, selectedProvider, null);
  for (int i = 0; i < providers.length; i++) {
    entry.putState(providers[i], states[i]);
  }
  return entry;
}
 
Example #27
Source File: HistoryEntry.java    From consulo with Apache License 2.0 5 votes vote down vote up
private HistoryEntry(@Nonnull VirtualFilePointer filePointer,
                     @Nullable FileEditorProvider selectedProvider,
                     @Nullable Disposable disposable) {
  myFilePointer = filePointer;
  mySelectedProvider = selectedProvider;
  myDisposable = disposable;
  myProvider2State = new HashMap<>();
}
 
Example #28
Source File: ProjectRootManagerComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void validityChanged(@Nonnull VirtualFilePointer[] pointers) {
  if (myProject.isDisposed()) {
    return;
  }

  if (myInsideRefresh > 0) {
    clearScopesCaches();
  }
  else {
    rootsChanged(false);
  }
}
 
Example #29
Source File: BackgroundTaskByVfsChangeManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void loadState(Element state) {
  for (Element element : state.getChildren("task")) {
    String url = element.getAttributeValue("url");
    String name = element.getAttributeValue("name");
    String providerName = element.getAttributeValue("provider-name");
    boolean enabled = Boolean.valueOf(element.getAttributeValue("enabled"));

    VirtualFilePointer virtualFilePointer = VirtualFilePointerManager.getInstance().create(url, this, null);

    BackgroundTaskByVfsParametersImpl parameters = new BackgroundTaskByVfsParametersImpl(myProject);

    BackgroundTaskByVfsChangeTaskImpl task = new BackgroundTaskByVfsChangeTaskImpl(myProject, virtualFilePointer, providerName, name, parameters, this);
    task.setEnabled(enabled);

    Element parametersElement = element.getChild("parameters");
    if (parametersElement != null) {
      ReplacePathToMacroMap replaceMacroToPathMap = task.createReplaceMacroToPathMap();

      replaceMacroToPathMap.substitute(parametersElement, false, true);

      XmlSerializer.deserializeInto(parameters, parametersElement);
    }

    registerTask(task);
  }
}
 
Example #30
Source File: HistoryEntry.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static HistoryEntry createHeavy(@Nonnull Project project, @Nonnull Element e) throws InvalidDataException {
  if (project.isDisposed()) return createLight(project, e);

  EntryData entryData = parseEntry(project, e);

  Disposable disposable = Disposable.newDisposable();
  VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(entryData.url, disposable, null);

  HistoryEntry entry = new HistoryEntry(pointer, entryData.selectedProvider, disposable);
  for (Pair<FileEditorProvider, FileEditorState> state : entryData.providerStates) {
    entry.putState(state.first, state.second);
  }
  return entry;
}