private void attachLibraries(
      @NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    if (!libraryRoots.isEmpty()) {
      ApplicationManager.getApplication()
          .runWriteAction(
              () -> {
                ModuleRootManager model = ModuleRootManager.getInstance(myModule);
                LibraryOrderEntry goLibraryEntry =
                    OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());

                if (goLibraryEntry != null && goLibraryEntry.isValid()) {
                  Library library = goLibraryEntry.getLibrary();
                  if (library != null && !((LibraryEx) library).isDisposed()) {
                    fillLibrary(library, libraryRoots, exclusions);
                  }
                } else {
                  LibraryTable libraryTable =
                      LibraryTablesRegistrar.getInstance().getLibraryTable(myModule.getProject());
                  Library library = libraryTable.createLibrary(getLibraryName());
                  fillLibrary(library, libraryRoots, exclusions);
                  ModuleRootModificationUtil.addDependency(myModule, library);
                }
              });
      showNotification(myModule.getProject());
    } else {
      removeLibraryIfNeeded();
    }
  }
 @Nullable
 @Override
 public Library findIdeLibrary(@NotNull LibraryData libraryData) {
   final LibraryTable libraryTable =
       LibraryTablesRegistrar.getInstance().getLibraryTable(myProject);
   for (Library ideLibrary : libraryTable.getLibraries()) {
     if (isRelated(ideLibrary, libraryData)) return ideLibrary;
   }
   return null;
 }
  private static void fillGlobalLibraries(List<GlobalLibrary> globals) {
    final Iterator<Library> iterator =
        LibraryTablesRegistrar.getInstance().getLibraryTable().getLibraryIterator();
    while (iterator.hasNext()) {
      Library library = iterator.next();
      final String name = library.getName();

      if (name != null) {
        final List<String> paths = convertToLocalPaths(library.getFiles(OrderRootType.CLASSES));
        globals.add(new GlobalLibrary(name, paths));
      }
    }
  }
 private String getDUnitPath() {
   LibraryTable projectLibraryTable =
       LibraryTablesRegistrar.getInstance().getLibraryTable(project);
   for (Library lib : projectLibraryTable.getLibraries()) {
     String name = lib.getName();
     if (name != null) {
       if (name.contains("d-unit-")) {
         VirtualFile[] files = lib.getFiles(OrderRootType.CLASSES);
         if (files.length > 0) {
           return dubImportPath(files[0].getCanonicalPath());
         }
       }
     }
   }
   return null;
 }
 public static Library findLibraryByName(Project project, String name) {
   final LibraryTablesRegistrar tablesRegistrar = LibraryTablesRegistrar.getInstance();
   Library lib = tablesRegistrar.getLibraryTable().getLibraryByName(name);
   if (lib == null) {
     lib = tablesRegistrar.getLibraryTable(project).getLibraryByName(name);
   }
   if (lib == null) {
     for (LibraryTable table : tablesRegistrar.getCustomLibraryTables()) {
       lib = table.getLibraryByName(name);
       if (lib != null) {
         break;
       }
     }
   }
   return lib;
 }
 public Library createOrGetXtendJavaLibrary(
     final ModifiableRootModel rootModel, final Module module) {
   LibraryTablesRegistrar _instance = LibraryTablesRegistrar.getInstance();
   Project _project = module.getProject();
   LibraryTable _libraryTable = _instance.getLibraryTable(_project);
   Library[] _libraries = _libraryTable.getLibraries();
   LibraryTablesRegistrar _instance_1 = LibraryTablesRegistrar.getInstance();
   LibraryTable _libraryTable_1 = _instance_1.getLibraryTable();
   Library[] _libraries_1 = _libraryTable_1.getLibraries();
   final Iterable<Library> libraryTable =
       Iterables.<Library>concat(
           ((Iterable<? extends Library>) Conversions.doWrapArray(_libraries)),
           ((Iterable<? extends Library>) Conversions.doWrapArray(_libraries_1)));
   final Function1<Library, Boolean> _function =
       new Function1<Library, Boolean>() {
         @Override
         public Boolean apply(final Library it) {
           String _name = it.getName();
           boolean _startsWith = false;
           if (_name != null) {
             _startsWith = _name.startsWith(XtendLibraryDescription.XTEND_LIBRARY_NAME);
           }
           return Boolean.valueOf(_startsWith);
         }
       };
   final Iterable<Library> xtendLibs = IterableExtensions.<Library>filter(libraryTable, _function);
   boolean _isEmpty = IterableExtensions.isEmpty(xtendLibs);
   boolean _not = (!_isEmpty);
   if (_not) {
     final Function1<Library, Boolean> _function_1 =
         new Function1<Library, Boolean>() {
           @Override
           public Boolean apply(final Library it) {
             String _name = it.getName();
             return Boolean.valueOf(
                 Objects.equal(_name, XtendLibraryDescription.XTEND_LIBRARY_NAME));
           }
         };
     boolean _exists = IterableExtensions.<Library>exists(xtendLibs, _function_1);
     if (_exists) {
       final Function1<Library, Boolean> _function_2 =
           new Function1<Library, Boolean>() {
             @Override
             public Boolean apply(final Library it) {
               String _name = it.getName();
               return Boolean.valueOf(
                   Objects.equal(_name, XtendLibraryDescription.XTEND_LIBRARY_NAME));
             }
           };
       return IterableExtensions.<Library>findFirst(xtendLibs, _function_2);
     } else {
       return IterableExtensions.<Library>head(xtendLibs);
     }
   } else {
     final NewLibraryConfiguration libDescr = this.xtendLibDescr.createLibraryDescription();
     LibraryTable _moduleLibraryTable = rootModel.getModuleLibraryTable();
     final LibraryTable.ModifiableModel model = _moduleLibraryTable.getModifiableModel();
     String _defaultLibraryName = libDescr.getDefaultLibraryName();
     final Library createdLib = model.createLibrary(_defaultLibraryName);
     final Library.ModifiableModel libModel = createdLib.getModifiableModel();
     HashMap<OrderRootType, List<String>> _libraryRoots = this.xtendLibDescr.libraryRoots();
     final Procedure2<OrderRootType, List<String>> _function_3 =
         new Procedure2<OrderRootType, List<String>>() {
           @Override
           public void apply(final OrderRootType type, final List<String> roots) {
             final Procedure1<String> _function =
                 new Procedure1<String>() {
                   @Override
                   public void apply(final String it) {
                     libModel.addRoot(it, type);
                   }
                 };
             IterableExtensions.<String>forEach(roots, _function);
           }
         };
     MapExtensions.<OrderRootType, List<String>>forEach(_libraryRoots, _function_3);
     libModel.commit();
     model.commit();
     return createdLib;
   }
 }
 @Override
 public LibraryTablePresentation getLibraryTablePresentation() {
   return LibraryTablesRegistrar.getInstance().getLibraryTable().getPresentation();
 }
 @Nullable
 @Override
 public Library getLibraryByName(String name) {
   return LibraryTablesRegistrar.getInstance().getLibraryTable(myProject).getLibraryByName(name);
 }
 @NotNull
 @Override
 public Library[] getAllLibraries() {
   return LibraryTablesRegistrar.getInstance().getLibraryTable(myProject).getLibraries();
 }