ConfigDirsSearchResult (@NotNull Path newConfigDir, @Nullable ConfigImportSettings settings, @NotNull List<String> otherProductPrefixes) { // looking for existing config directories ... Set<Path> homes = new HashSet<>(); homes.add(newConfigDir.getParent()); // ... in the vicinity of the new config directory homes.add(newConfigDir.getFileSystem().getPath(PathManager.getDefaultConfigPathFor("X")).getParent()); // ... in the default location Path historic = newConfigDir.getFileSystem().getPath(defaultConfigPath("X2019.3")); Path historicHome = SystemInfoRt.isMac ? historic.getParent() : historic.getParent().getParent(); homes.add(historicHome); // ... in the historic location String prefix = getPrefixFromSelector(PathManager.getPathsSelector()); if (prefix == null) prefix = getPrefixFromSelector(getNameWithVersion(newConfigDir)); if (prefix == null) { String productName = ApplicationNamesInfo.getInstance().getFullProductName(); if (productName != null) prefix = productName.replace(" ", ""); } if (prefix == null) prefix = PlatformUtils.getPlatformPrefix(); List<Path> exactCandidates = new ArrayList<>(); List<Path> otherPreferredCandidates = new ArrayList<>(); for (Path home : homes) { if (home == null || !Files.isDirectory(home)) { continue; } if (home.equals(newConfigDir.getParent()) && ProjectManagerEx.IS_PER_PROJECT_INSTANCE_ENABLED && ProjectManagerEx.Companion.isChildProcessPath(newConfigDir)) { exactCandidates.add(home); break; } boolean dotted = !SystemInfoRt.isMac && home == historicHome; try (DirectoryStream<Path> stream = Files.newDirectoryStream(home)) { for (Path path : stream) { if (!path.equals(newConfigDir) && Files.isDirectory(path)) { String name = path.getFileName().toString(); String pathPrefix = getPrefixFromSelector(getNameWithVersion(path)); if (nameMatchesPrefixStrictly(name, prefix, dotted)) { if (settings == null || settings.shouldBeSeenAsImportCandidate(path, pathPrefix, otherProductPrefixes)) { exactCandidates.add(path); } } else if (exactCandidates.isEmpty() && ContainerUtil.exists(otherProductPrefixes, other -> nameMatchesPrefixStrictly(name, other, dotted))) { if (settings == null || settings.shouldBeSeenAsImportCandidate(path, pathPrefix, otherProductPrefixes)) { otherPreferredCandidates.add(path); } } } } } catch (IOException ignore) { } } List<Path> candidates; boolean exact; if (!exactCandidates.isEmpty()) { candidates = exactCandidates; exact = true; } else if (!otherPreferredCandidates.isEmpty()) { candidates = otherPreferredCandidates; exact = false; } else { return new ConfigDirsSearchResult(List.of(), true); } List<Pair<Path, FileTime>> lastModified = new ArrayList<>(); for (Path child : candidates) { Path candidate = child, config = child.resolve(CONFIG); if (Files.isDirectory(config)) candidate = config; FileTime max = null; for (String name : OPTIONS) { try { FileTime cur = Files.getLastModifiedTime(candidate.resolve(name)); if (max == null || cur.compareTo(max) > 0) { max = cur; } } catch (IOException ignore) { } } lastModified.add(new Pair<>(candidate, max != null ? max : FileTime.fromMillis(0))); } lastModified.sort((o1, o2) -> { int diff = o2.second.compareTo(o1.second); if (diff == 0) { diff = NaturalComparator.INSTANCE.compare(o2.first.toString(), o1.first.toString()); } return diff; }); return new ConfigDirsSearchResult(lastModified, exact); }