private void removeDescendants(VirtualFile file, VirtualFilePointerContainer container) {
   for (VirtualFile virtualFile : container.getFiles()) {
     if (VfsUtil.isAncestor(file, virtualFile, false)) {
       container.remove(myPointerManager.create(virtualFile, this, null));
     }
   }
 }
コード例 #2
0
 @Override
 @NotNull
 public String[] getUrls(@NotNull OrderRootType rootType) {
   assert !isDisposed();
   final VirtualFilePointerContainer result = myRoots.get(rootType);
   return result.getUrls();
 }
コード例 #3
0
  @Override
  public void writeExternal(Element rootElement) throws WriteExternalException {
    LOG.assertTrue(!isDisposed(), "Already disposed!");

    Element element = new Element(ELEMENT);
    if (myName != null) {
      element.setAttribute(LIBRARY_NAME_ATTR, myName);
    }
    if (myKind != null) {
      element.setAttribute(LIBRARY_TYPE_ATTR, myKind.getKindId());
      final Object state = myProperties.getState();
      if (state != null) {
        final Element propertiesElement = XmlSerializer.serialize(state, SERIALIZATION_FILTERS);
        if (propertiesElement != null
            && (!propertiesElement.getContent().isEmpty()
                || !propertiesElement.getAttributes().isEmpty())) {
          element.addContent(propertiesElement.setName(PROPERTIES_ELEMENT));
        }
      }
    }
    ArrayList<OrderRootType> storableRootTypes = new ArrayList<OrderRootType>();
    storableRootTypes.addAll(Arrays.asList(OrderRootType.getAllTypes()));
    if (myKind != null) {
      storableRootTypes.addAll(Arrays.asList(myKind.getAdditionalRootTypes()));
    }
    for (OrderRootType rootType : sortRootTypes(storableRootTypes)) {
      final VirtualFilePointerContainer roots = myRoots.get(rootType);
      if (roots.size() == 0 && rootType.skipWriteIfEmpty()) continue; // compatibility iml/ipr
      final Element rootTypeElement = new Element(rootType.name());
      roots.writeExternal(rootTypeElement, ROOT_PATH_ELEMENT);
      element.addContent(rootTypeElement);
    }
    myJarDirectories.writeExternal(element);
    rootElement.addContent(element);
  }
コード例 #4
0
 @Override
 public void moveRootDown(@NotNull String url, @NotNull OrderRootType rootType) {
   assert !isDisposed();
   LOG.assertTrue(isWritable());
   final VirtualFilePointerContainer container = myRoots.get(rootType);
   container.moveDown(url);
 }
  @Nullable
  public ExcludesConfigurationState getActualState() {
    ensureOldSettingsLoaded();
    if (myExcludedFiles.isEmpty() && myExcludedFrameworks.isEmpty()) {
      return null;
    }

    final ExcludesConfigurationState state = new ExcludesConfigurationState();
    state.getFrameworkTypes().addAll(myExcludedFrameworks);
    Collections.sort(state.getFrameworkTypes(), String.CASE_INSENSITIVE_ORDER);

    for (String typeId : myExcludedFiles.keySet()) {
      final VirtualFilePointerContainer container = myExcludedFiles.get(typeId);
      for (String url : container.getUrls()) {
        state.getFiles().add(new ExcludedFileState(url, typeId));
      }
    }
    Collections.sort(
        state.getFiles(),
        new Comparator<ExcludedFileState>() {
          @Override
          public int compare(ExcludedFileState o1, ExcludedFileState o2) {
            return StringUtil.comparePairs(
                o1.getFrameworkType(), o1.getUrl(), o2.getFrameworkType(), o2.getUrl(), true);
          }
        });
    return state;
  }
コード例 #6
0
 private void disposeMyPointers() {
   for (VirtualFilePointerContainer container :
       new THashSet<VirtualFilePointerContainer>(myRoots.values())) {
     container.killAll();
   }
   Disposer.dispose(myPointersDisposable);
   Disposer.register(this, myPointersDisposable);
 }
コード例 #7
0
  @Override
  public void addRoot(@NotNull VirtualFile file, @NotNull OrderRootType rootType) {
    LOG.assertTrue(isWritable());
    assert !isDisposed();

    final VirtualFilePointerContainer container = myRoots.get(rootType);
    container.add(file);
  }
 @Override
 public void addExcludedFramework(@NotNull FrameworkType type) {
   convert();
   myExcludedFrameworks.add(type.getId());
   final VirtualFilePointerContainer container = myExcludedFiles.remove(type.getId());
   if (container != null) {
     container.clear();
   }
 }
コード例 #9
0
 @Override
 public void addJarDirectory(
     @NotNull final VirtualFile file, final boolean recursive, @NotNull OrderRootType rootType) {
   assert !isDisposed();
   LOG.assertTrue(isWritable());
   final VirtualFilePointerContainer container = myRoots.get(rootType);
   container.add(file);
   myJarDirectories.add(rootType, file.getUrl(), recursive);
 }
コード例 #10
0
 private void readRoots(Element element) throws InvalidDataException {
   for (OrderRootType rootType : getAllRootTypes()) {
     final Element rootChild = element.getChild(rootType.name());
     if (rootChild == null) {
       continue;
     }
     VirtualFilePointerContainer roots = myRoots.get(rootType);
     roots.readExternal(rootChild, ROOT_PATH_ELEMENT);
   }
 }
コード例 #11
0
 private void copyRootsFrom(LibraryImpl fromModel) {
   myRoots.clear();
   for (Map.Entry<OrderRootType, VirtualFilePointerContainer> entry :
       fromModel.myRoots.entrySet()) {
     OrderRootType rootType = entry.getKey();
     VirtualFilePointerContainer container = entry.getValue();
     VirtualFilePointerContainer clone = container.clone(myPointersDisposable);
     myRoots.put(rootType, clone);
   }
 }
 private void doLoadState(@Nullable ExcludesConfigurationState state) {
   myExcludedFrameworks.clear();
   for (VirtualFilePointerContainer container : myExcludedFiles.values()) {
     container.clear();
   }
   if (state != null) {
     myExcludedFrameworks.addAll(state.getFrameworkTypes());
     for (ExcludedFileState fileState : state.getFiles()) {
       myExcludedFiles.get(fileState.getFrameworkType()).add(fileState.getUrl());
     }
   }
 }
コード例 #13
0
 @Override
 @NotNull
 public VirtualFilePointerContainer clone(
     @NotNull Disposable parent, @Nullable VirtualFilePointerListener listener) {
   assert !myDisposed;
   VirtualFilePointerContainer clone =
       myVirtualFilePointerManager.createContainer(parent, listener);
   for (VirtualFilePointer pointer : myList) {
     clone.add(pointer.getUrl());
   }
   return clone;
 }
コード例 #14
0
 @Override
 public boolean removeRoot(@NotNull String url, @NotNull OrderRootType rootType) {
   assert !isDisposed();
   LOG.assertTrue(isWritable());
   final VirtualFilePointerContainer container = myRoots.get(rootType);
   final VirtualFilePointer byUrl = container.findByUrl(url);
   if (byUrl != null) {
     container.remove(byUrl);
     myJarDirectories.remove(rootType, url);
     return true;
   }
   return false;
 }
コード例 #15
0
 private LibraryImpl(
     @NotNull LibraryImpl from, LibraryImpl newSource, ModifiableRootModel rootModel) {
   this(from.myLibraryTable, rootModel, newSource, from.myName, from.myKind);
   assert !from.isDisposed();
   if (from.myKind != null && from.myProperties != null) {
     myProperties = myKind.createDefaultProperties();
     //noinspection unchecked
     myProperties.loadState(from.myProperties.getState());
   }
   for (OrderRootType rootType : getAllRootTypes()) {
     final VirtualFilePointerContainer thisContainer = myRoots.get(rootType);
     final VirtualFilePointerContainer thatContainer = from.myRoots.get(rootType);
     thisContainer.addAll(thatContainer);
   }
   myJarDirectories.copyFrom(from.myJarDirectories);
 }
 private static boolean isUnder(VirtualFile file, final VirtualFilePointerContainer container) {
   for (VirtualFile excludedFile : container.getFiles()) {
     if (VfsUtil.isAncestor(excludedFile, file, false)) {
       return true;
     }
   }
   return false;
 }
  @Override
  public void addExcludedFile(@NotNull VirtualFile file, @Nullable FrameworkType type) {
    convert();
    final String typeId = type != null ? type.getId() : null;
    if (typeId != null && myExcludedFrameworks.contains(typeId) || isFileExcluded(file, typeId)) {
      return;
    }

    final VirtualFilePointerContainer container = myExcludedFiles.get(typeId);
    if (typeId == null) {
      for (VirtualFilePointerContainer pointerContainer : myExcludedFiles.values()) {
        removeDescendants(file, pointerContainer);
      }
    } else {
      removeDescendants(file, container);
    }
    container.add(file);
  }
コード例 #18
0
 @Override
 public boolean isValid(@NotNull final String url, @NotNull final OrderRootType rootType) {
   final VirtualFilePointerContainer container = myRoots.get(rootType);
   final VirtualFilePointer fp = container.findByUrl(url);
   return fp != null && fp.isValid();
 }