List<LibraryDescriptor> (final Set<? extends File> jars) { final Map<File, LibraryDescriptor> rootToLibraryMap = new HashMap<>(); for (File jar : jars) { final File parent = jar.getParentFile(); LibraryDescriptor lib = rootToLibraryMap.get(parent); if (lib == null) { lib = new LibraryDescriptor(parent.getName(), new HashSet<>()); rootToLibraryMap.put(parent, lib); } lib.addJars(Collections.singleton(jar)); } return new ArrayList<>(rootToLibraryMap.values()); }