@VisibleForTesting
  static @Nullable File chooseAuxiliaryArtifactFile(@NotNull File main, @NotNull Set<File> auxiliaries) {
    Iterator<File> auxiliariesIterator = auxiliaries.iterator();
    if (!auxiliariesIterator.hasNext()) {
      return null;
    }

    File firstAuxiliary = auxiliariesIterator.next();
    if (!auxiliariesIterator.hasNext()) {
      return firstAuxiliary;
    }

    String mainName = main.getName();
    String firstAuxiliaryName = firstAuxiliary.getName();

    int commonSuffixOfAuxiliaries = firstAuxiliaryName.length();
    do {
      File nextAuxiliary = auxiliariesIterator.next();
      int commonSuffix = StringUtils.commonSuffixLength(firstAuxiliaryName, nextAuxiliary.getName());
      if (commonSuffix < commonSuffixOfAuxiliaries) {
        commonSuffixOfAuxiliaries = commonSuffix;
      }
    } while (auxiliariesIterator.hasNext());

    int commonSuffixOfMainAndAuxiliaries =
      Math.min(commonSuffixOfAuxiliaries, StringUtils.commonSuffixLength(mainName, firstAuxiliaryName));
    String mainSuffixlessName = mainName.substring(0, mainName.length() - commonSuffixOfMainAndAuxiliaries);

    int commonPrefixOfMainAndShortlistedAuxiliaries = 0;
    TreeMap<String, File> shortlistedAuxiliariesBySuffixlessName =
      new TreeMap<>(Comparator.comparingInt(String::length).thenComparing(String::compareTo));
    for (File auxiliary : auxiliaries) {
      String auxiliaryName = auxiliary.getName();
      String auxiliarySuffixlessName = auxiliaryName.substring(0, auxiliaryName.length() - commonSuffixOfAuxiliaries);
      int commonPrefixNaive = StringUtils.commonPrefixLength(mainSuffixlessName, auxiliarySuffixlessName);
      Matcher commonPrefixExcessMatcher = PUNCTUATION_IN_SUFFIX_PATTERN.matcher(auxiliarySuffixlessName).region(0, commonPrefixNaive);
      int commonPrefix = commonPrefixExcessMatcher.find() ? commonPrefixExcessMatcher.start() : commonPrefixNaive;
      if (commonPrefix >= commonPrefixOfMainAndShortlistedAuxiliaries) {
        if (commonPrefix > commonPrefixOfMainAndShortlistedAuxiliaries) {
          commonPrefixOfMainAndShortlistedAuxiliaries = commonPrefix;
          shortlistedAuxiliariesBySuffixlessName.clear();
        }
        shortlistedAuxiliariesBySuffixlessName.put(auxiliarySuffixlessName, auxiliary);
      }
    }

    return shortlistedAuxiliariesBySuffixlessName.firstEntry().getValue();
  }
@VisibleForTesting
  static @Nullable File chooseAuxiliaryArtifactFile(@NotNull File main, @NotNull Set<File> auxiliaries)