Пример #1
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);
  }
Пример #2
0
 @Override
 @NotNull
 public VirtualFile[] getFiles(@NotNull OrderRootType rootType) {
   assert !isDisposed();
   final List<VirtualFile> expanded = new ArrayList<VirtualFile>();
   for (VirtualFile file : myRoots.get(rootType).getFiles()) {
     if (file.isDirectory()) {
       if (myJarDirectories.contains(rootType, file.getUrl())) {
         collectJarFiles(file, expanded, myJarDirectories.isRecursive(rootType, file.getUrl()));
         continue;
       }
     }
     expanded.add(file);
   }
   return VfsUtilCore.toVirtualFileArray(expanded);
 }
Пример #3
0
 @Override
 public void readExternal(Element element) throws InvalidDataException {
   readName(element);
   readProperties(element);
   readRoots(element);
   myJarDirectories.readExternal(element);
   myRootsWatcher.updateWatchedRoots();
 }
Пример #4
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);
 }
Пример #5
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;
 }
Пример #6
0
 LibraryImpl(LibraryTable table, Element element, ModifiableRootModel rootModel)
     throws InvalidDataException {
   this(
       table,
       rootModel,
       null,
       element.getAttributeValue(LIBRARY_NAME_ATTR),
       (PersistentLibraryKind<?>)
           LibraryKind.findById(element.getAttributeValue(LIBRARY_TYPE_ATTR)));
   readProperties(element);
   myJarDirectories.readExternal(element);
   readRoots(element);
   myRootsWatcher.updateWatchedRoots();
 }
Пример #7
0
  public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    final LibraryImpl library = (LibraryImpl) o;

    if (!myJarDirectories.equals(library.myJarDirectories)) return false;
    if (myName != null ? !myName.equals(library.myName) : library.myName != null) return false;
    if (myRoots != null ? !myRoots.equals(library.myRoots) : library.myRoots != null) return false;
    if (myKind != null ? !myKind.equals(library.myKind) : library.myKind != null) return false;
    if (myProperties != null
        ? !myProperties.equals(library.myProperties)
        : library.myProperties != null) return false;

    return true;
  }
Пример #8
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);
 }
Пример #9
0
 private void commit(@NotNull LibraryImpl fromModel) {
   if (myLibraryTable != null) {
     ApplicationManager.getApplication().assertWriteAccessAllowed();
   }
   if (!Comparing.equal(fromModel.myName, myName)) {
     myName = fromModel.myName;
     if (myLibraryTable instanceof LibraryTableBase) {
       ((LibraryTableBase) myLibraryTable).fireLibraryRenamed(this);
     }
   }
   myKind = fromModel.getKind();
   myProperties = fromModel.myProperties;
   if (areRootsChanged(fromModel)) {
     disposeMyPointers();
     copyRootsFrom(fromModel);
     myJarDirectories.copyFrom(fromModel.myJarDirectories);
     myRootsWatcher.updateWatchedRoots();
     myRootProvider.fireRootSetChanged();
   }
 }
Пример #10
0
 public int hashCode() {
   int result = myName != null ? myName.hashCode() : 0;
   result = 31 * result + (myRoots != null ? myRoots.hashCode() : 0);
   result = 31 * result + (myJarDirectories != null ? myJarDirectories.hashCode() : 0);
   return result;
 }
Пример #11
0
 @Override
 public boolean isJarDirectory(@NotNull final String url, @NotNull final OrderRootType rootType) {
   return myJarDirectories.contains(rootType, url);
 }