List<OrderRoot> (@NotNull Collection<Artifact> artifacts, @Nullable String copyTo) { final List<OrderRoot> result = new ArrayList<>(); final VirtualFileManager manager = VirtualFileManager.getInstance(); for (Artifact each : artifacts) { long ms = System.currentTimeMillis(); try { File repoFile = each.getFile(); File toFile = repoFile; if (copyTo != null) { toFile = new File(copyTo, repoFile.getName()); if (repoFile.exists()) { FileUtil.copy(repoFile, toFile); } } if (DO_REFRESH) { // search for jar file first otherwise lib root won't be found! manager.refreshAndFindFileByUrl(VfsUtilCore.pathToUrl(toFile.getPath())); final String url = VfsUtil.getUrlForLibraryRoot(toFile); final VirtualFile file = manager.refreshAndFindFileByUrl(url); if (file != null) { OrderRootType rootType = ourClassifierToRootType.getOrDefault(each.getClassifier(), OrderRootType.CLASSES); result.add(new OrderRoot(file, rootType)); } } } catch (IOException e) { LOG.warn(e); } finally { if (LOG.isTraceEnabled()) { LOG.trace("Artifact " + each.toString() + " refreshed in " + (System.currentTimeMillis() - ms) + "ms"); } } } return result; }