public void applyTo(LibraryEx.ModifiableModelEx model) {
   model.setProperties(myProperties);
   for (OrderRootType type : myRoots.keySet()) {
     for (LightFilePointer pointer : myRoots.get(type)) {
       model.addRoot(pointer.getUrl(), type);
     }
   }
   for (OrderRootType rootType : myJarDirectories.getRootTypes()) {
     for (String url : myJarDirectories.getDirectories(rootType)) {
       model.addJarDirectory(url, myJarDirectories.isRecursive(rootType, url), rootType);
     }
   }
 }
  private static void fillLibrary(
      @NotNull Library library,
      @NotNull Collection<VirtualFile> libraryRoots,
      Set<VirtualFile> exclusions) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();

    Library.ModifiableModel libraryModel = library.getModifiableModel();
    for (String root : libraryModel.getUrls(OrderRootType.CLASSES)) {
      libraryModel.removeRoot(root, OrderRootType.CLASSES);
    }
    for (String root : libraryModel.getUrls(OrderRootType.SOURCES)) {
      libraryModel.removeRoot(root, OrderRootType.SOURCES);
    }
    for (VirtualFile libraryRoot : libraryRoots) {
      libraryModel.addRoot(
          libraryRoot,
          OrderRootType
              .CLASSES); // in order to consider GOPATH as library and show it in Ext. Libraries
      libraryModel.addRoot(
          libraryRoot, OrderRootType.SOURCES); // in order to find usages inside GOPATH
    }
    for (VirtualFile root : exclusions) {
      ((LibraryEx.ModifiableModelEx) libraryModel).addExcludedRoot(root.getUrl());
    }
    libraryModel.commit();
  }