<commit_before>package org.jetbrains.sbt
package project

import java.io.File

import com.intellij.openapi.externalSystem.model.ExternalSystemException
import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType
import org.jetbrains.sbt.project.data.{ContentRootNode, LibraryNode, ModuleDependencyNode, ModuleNode}
import org.jetbrains.sbt.project.sources.SharedSourcesModuleType
import org.jetbrains.sbt.{structure => sbtStructure}

/**
 * @author <NAME>
 */
trait ExternalSourceRootResolution { self: SbtProjectResolver =>

  def createSharedSourceModules(projectToModuleNode: Map[sbtStructure.ProjectData, ModuleNode],
                                libraryNodes: Seq[LibraryNode],
                                moduleFilesDirectory: File,
                                warnings: String => Unit
                               ): Seq[ModuleNode] = {

    val projects = projectToModuleNode.keys.toSeq

    val (sharedRoots, externalRoots) = sharedAndExternalRootsIn(projects).partition(_.projects.length > 1)

    if (externalRoots.nonEmpty) {
      val externalRootsStr = externalRoots.map(_.root.directory).distinct.mkString("<ul><li>", "</li><li>", "</li></ul>")
      val msg =
        s"""
          | <p>
          | The following source roots are outside of the corresponding base directories:
          | $externalRootsStr
          | These source roots cannot be included in the IDEA project model.
          | </p><p>
          | <strong>Solution:</strong> declare an sbt project for these sources and include the project in dependencies.
          | </p>
        """.stripMargin

      warnings(msg)
    }

    val grouped = groupSharedRoots(sharedRoots)
    grouped.map { group =>
      createSourceModuleNodesAndDependencies(group, projectToModuleNode, libraryNodes, moduleFilesDirectory)
    }
  }

  def createSourceModuleNodesAndDependencies(rootGroup: RootGroup,
                                             projectToModuleNode: Map[sbtStructure.ProjectData, ModuleNode],
                                             libraryNodes: Seq[LibraryNode],
                                             moduleFilesDirectory: File): ModuleNode = {
    val projects = rootGroup.projects

    val sourceModuleNode = {<commit_msg>Treat source directories outside of module root just like source directories shared between different sbt sub-projects rather than throwing warnings about them. Throwing warnings isn't very useful, because many sbt project configs depend on generated sources in target or elsewhere. This should be ok now that we find common roots between shared sources.<commit_after>package org.jetbrains.sbt
package project

import java.io.File

import com.intellij.openapi.externalSystem.model.ExternalSystemException
import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType
import org.jetbrains.sbt.project.data.{ContentRootNode, LibraryNode, ModuleDependencyNode, ModuleNode}
import org.jetbrains.sbt.project.sources.SharedSourcesModuleType
import org.jetbrains.sbt.{structure => sbtStructure}

/**
 * @author <NAME>
 */
trait ExternalSourceRootResolution { self: SbtProjectResolver =>

  def createSharedSourceModules(projectToModuleNode: Map[sbtStructure.ProjectData, ModuleNode],
                                libraryNodes: Seq[LibraryNode],
                                moduleFilesDirectory: File,
                                warnings: String => Unit
                               ): Seq[ModuleNode] = {

    val projects = projectToModuleNode.keys.toSeq
    val sharedRoots = sharedAndExternalRootsIn(projects)
    val grouped = groupSharedRoots(sharedRoots)
    grouped.map { group =>
      createSourceModuleNodesAndDependencies(group, projectToModuleNode, libraryNodes, moduleFilesDirectory)
    }
  }

  def createSourceModuleNodesAndDependencies(rootGroup: RootGroup,
                                             projectToModuleNode: Map[sbtStructure.ProjectData, ModuleNode],
                                             libraryNodes: Seq[LibraryNode],
                                             moduleFilesDirectory: File): ModuleNode = {
    val projects = rootGroup.projects

    val sourceModuleNode = {
{'fraction_non_alphanumeric': 0.07701449964345139, 'fraction_numerical': 0.0002376990729736154, 'mean_word_length': 2.720601237842617, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5455162', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1005, 'n_words': 245}