private static void createOrReplaceSourceFolder(@NotNull SourceFolderManager sourceFolderManager,
                                                  @NotNull ContentEntry contentEntry,
                                                  @NotNull final SourceRoot sourceRoot,
                                                  @NotNull Module module,
                                                  @NotNull JpsModuleSourceRootType<?> sourceRootType,
                                                  boolean createEmptyContentRootDirectories,
                                                  @NotNull ProjectModelExternalSource externalSource) {
    String path = sourceRoot.getPath();
    if (SystemInfo.isWindows) {
      if (!path.isEmpty() && StringUtil.isWhiteSpace(path.charAt(path.length() - 1))) {
        LOG.warn("Source root ending with a space found. Such directories is not properly supported by JDK on Windows, see https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8190546. " +
                 "The source root will not be added: '" + path + "'");
        return;
      }
    }

    if (createEmptyContentRootDirectories) {
      createEmptyDirectory(path);
    }

    SourceFolder folder = findSourceFolder(contentEntry, sourceRoot);
    if (folder != null) {
      final JpsModuleSourceRootType<?> folderRootType = folder.getRootType();
      if (sourceRootType.equals(folderRootType)) {
        return;
      }
      contentEntry.removeSourceFolder(folder);
    }

    String url = pathToUrl(path);
    if (!Files.exists(Path.of(path))) {
      logTrace("Source folder [%s] does not exist and will not be created, will add when dir is created", url);
      logUnitTest("Adding source folder listener to watch [%s] for creation in project [hashCode=%d]", url, module.getProject().hashCode());
      sourceFolderManager.addSourceFolder(module, url, sourceRootType);
    }
    else {
      contentEntry.addSourceFolder(url, sourceRootType, externalSource);
    }
  }
private static void createOrReplaceSourceFolder(@NotNull SourceFolderManager sourceFolderManager,
                                                  @NotNull ContentEntry contentEntry,
                                                  @NotNull final SourceRoot sourceRoot,
                                                  @NotNull Module module,
                                                  @NotNull JpsModuleSourceRootType<?> sourceRootType,
                                                  boolean createEmptyContentRootDirectories,
                                                  @NotNull ProjectModelExternalSource externalSource)