<commit_before>package org.jetbrains.plugins.scala
package compiler

import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.OrderEnumerator
import org.jetbrains.plugins.scala.compiler.data._
import org.jetbrains.plugins.scala.compiler.data.worksheet.WorksheetArgs
import org.jetbrains.plugins.scala.extensions.ObjectExt
import org.jetbrains.plugins.scala.project.settings.ScalaCompilerSettings
import org.jetbrains.plugins.scala.project.{ModuleExt, ProjectContext, VirtualFileExt}
import org.jetbrains.plugins.scala.util.ScalaPluginJars

import java.io.File

//noinspection SameParameterValue
abstract class RemoteServerConnectorBase(
  protected val module: Module,
  filesToCompile: Option[Seq[File]],
  protected val outputDir: File
) {
  filesToCompile.foreach(checkFilesToCompile)

  implicit def projectContext: ProjectContext = module.getProject

  private val sbtData = {
    val javaClassVersion = System.getProperty("java.class.version")
    SbtData.from(ScalaPluginJars.jpsRoot, javaClassVersion) match {
      case Left(msg)   => throw new IllegalArgumentException(msg)
      case Right(data) => data
    }
  }

  private val sourceRoot: Option[File] = {
    val fileToCompile = filesToCompile.flatMap(_.headOption)
    fileToCompile.flatMap(_.getAbsoluteFile.getParentFile.toOption)
  }

  protected def scalaParameters: Seq[String] =
    compilerSettings.getOptionsAsStrings(module.hasScala3)

  private val javaParameters = Seq.empty[String]

  private val moduleCompilerClasspath: Seq[File] = module.scalaCompilerClasspath
  protected var additionalCompilerClasspath: Seq[File] = Nil
  def compilerClasspath: Seq[File] = moduleCompilerClasspath ++ additionalCompilerClasspath

  private val additionalRuntimeClasspath: Seq[File] =
    compilerClasspath :+
      ScalaPluginJars.runnersJar :+
      ScalaPluginJars.compilerSharedJar :+
      outputDir

  protected def worksheetArgs: Option[WorksheetArgs] = None

  private def runtimeClasspath: Seq[File] = {
    val classesRoots = assemblyRuntimeClasspath().map(stripJarPathSuffix).map(new File(_))
    classesRoots ++ additionalRuntimeClasspath
  }

  private def stripJarPathSuffix(f: File): String =
    f.getCanonicalPath.stripSuffix("!").stripSuffix("!/")

  protected def assemblyRuntimeClasspath(): Seq[File] = {
    val enumerator = OrderEnumerator.orderEntries(module).compileOnly()
    enumerator.getClassesRoots.map(_.toFile).toSeq
  }

  protected final def arguments: Arguments = Arguments(
    sbtData = sbtData,
    compilerData = CompilerData(
      compilerJars = CompilerJarsFactory.fromFiles(compilerClasspath).toOption,
      javaHome = Some(findJdk),
      incrementalType = IncrementalityType.IDEA
    ),<commit_msg>#SCL-20388: Enumerate modules recursively when building classpath<commit_after>package org.jetbrains.plugins.scala
package compiler

import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.OrderEnumerator
import org.jetbrains.plugins.scala.compiler.data._
import org.jetbrains.plugins.scala.compiler.data.worksheet.WorksheetArgs
import org.jetbrains.plugins.scala.extensions.ObjectExt
import org.jetbrains.plugins.scala.project.settings.ScalaCompilerSettings
import org.jetbrains.plugins.scala.project.{ModuleExt, ProjectContext, VirtualFileExt}
import org.jetbrains.plugins.scala.util.ScalaPluginJars

import java.io.File

//noinspection SameParameterValue
abstract class RemoteServerConnectorBase(
  protected val module: Module,
  filesToCompile: Option[Seq[File]],
  protected val outputDir: File
) {
  filesToCompile.foreach(checkFilesToCompile)

  implicit def projectContext: ProjectContext = module.getProject

  private val sbtData = {
    val javaClassVersion = System.getProperty("java.class.version")
    SbtData.from(ScalaPluginJars.jpsRoot, javaClassVersion) match {
      case Left(msg)   => throw new IllegalArgumentException(msg)
      case Right(data) => data
    }
  }

  private val sourceRoot: Option[File] = {
    val fileToCompile = filesToCompile.flatMap(_.headOption)
    fileToCompile.flatMap(_.getAbsoluteFile.getParentFile.toOption)
  }

  protected def scalaParameters: Seq[String] =
    compilerSettings.getOptionsAsStrings(module.hasScala3)

  private val javaParameters = Seq.empty[String]

  private val moduleCompilerClasspath: Seq[File] = module.scalaCompilerClasspath
  protected var additionalCompilerClasspath: Seq[File] = Nil
  def compilerClasspath: Seq[File] = moduleCompilerClasspath ++ additionalCompilerClasspath

  private val additionalRuntimeClasspath: Seq[File] =
    compilerClasspath :+
      ScalaPluginJars.runnersJar :+
      ScalaPluginJars.compilerSharedJar :+
      outputDir

  protected def worksheetArgs: Option[WorksheetArgs] = None

  private def runtimeClasspath: Seq[File] = {
    val classesRoots = assemblyRuntimeClasspath().map(stripJarPathSuffix).map(new File(_))
    classesRoots ++ additionalRuntimeClasspath
  }

  private def stripJarPathSuffix(f: File): String =
    f.getCanonicalPath.stripSuffix("!").stripSuffix("!/")

  protected def assemblyRuntimeClasspath(): Seq[File] = {
    val enumerator = OrderEnumerator.orderEntries(module).compileOnly().recursively()
    enumerator.getClassesRoots.map(_.toFile).toSeq
  }

  protected final def arguments: Arguments = Arguments(
    sbtData = sbtData,
    compilerData = CompilerData(
      compilerJars = CompilerJarsFactory.fromFiles(compilerClasspath).toOption,
      javaHome = Some(findJdk),
      incrementalType = IncrementalityType.IDEA
    ),
{'fraction_non_alphanumeric': 0.08880028996013048, 'fraction_numerical': 0.0012685755708590069, 'mean_word_length': 5.194163860830527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3025410', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1600, 'n_words': 300}