<commit_before>import ReleaseTransformations._
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import scalariform.formatter.preferences._
import sbtrelease.ReleasePlugin
import scala.sys.process.Process
import sbtcrossproject.crossProject
import java.io.{File => JFile}

enablePlugins(TutPlugin)

lazy val baseModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-core-jvm`, `quill-core-js`, `quill-sql-jvm`, `quill-sql-js`, `quill-monix`
)

lazy val dbModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-jdbc`, `quill-jdbc-monix`
)

lazy val asyncModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-async`, `quill-async-mysql`, `quill-async-postgres`,
  `quill-finagle-mysql`, `quill-finagle-postgres`
)

lazy val codegenModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-codegen`, `quill-codegen-jdbc`, `quill-codegen-tests`
)

lazy val bigdataModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-cassandra`, `quill-cassandra-lagom`, `quill-cassandra-monix`, `quill-orientdb`, `quill-spark`
)

lazy val allModules =
  baseModules ++ dbModules ++ asyncModules ++ codegenModules ++ bigdataModules

lazy val filteredModules = {
  val modulesStr = sys.props.get("modules")
  println(s"Modules Argument Value: ${modulesStr}")

  modulesStr match {
    case Some("base") =>
      println("Compiling Base Modules")
      baseModules
    case Some("db") =>
      println("Compiling Database Modules")
      dbModules
    case Some("async") =>
      println("Compiling Async Database Modules")
      asyncModules
    case Some("codegen") =>
      println("Compiling Code Generator Modules")
      codegenModules
    case Some("bigdata") =>
      println("Compiling Big Data Modules")
      bigdataModules
    case _ =>
      println("Compiling All Modules")
      allModules
  }
}

lazy val `quill` =
  (project in file("."))
    .settings(commonSettings)
    .settings(`tut-settings`:_*)
    .aggregate(filteredModules.map(_.project): _*)
    .dependsOn(filteredModules: _*)

lazy val superPure = new sbtcrossproject.CrossType {
  def projectDir(crossBase: File, projectType: String): File =
    projectType match {
      case "jvm" => crossBase
      case "js"  => crossBase / s".$projectType"
    }

  def sharedSrcDir(projectBase: File, conf: String): Option[File] =
    Some(projectBase.getParentFile / "src" / conf / "scala")

  override def projectDir(crossBase: File, projectType: sbtcrossproject.Platform): File =
    projectType match {
      case JVMPlatform => crossBase
      case JSPlatform  => crossBase / ".js"
    }
}

lazy val `quill-core` =
  crossProject(JVMPlatform, JSPlatform).crossType(superPure)
    .settings(commonSettings: _*)
    .settings(mimaSettings: _*)
    .settings(libraryDependencies ++= Seq(
      "com.typesafe"               %  "config"        % "1.3.4",
      "com.typesafe.scala-logging" %% "scala-logging" % "3.9.0",
      "org.scala-lang"             %  "scala-reflect" % scalaVersion.value
    ))
    .jsSettings(
      libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "0.2.5",
      coverageExcludedPackages := ".*"
    )

lazy val `quill-core-jvm` = `quill-core`.jvm
lazy val `quill-core-js` = `quill-core`.js

lazy val `quill-sql` =
  crossProject(JVMPlatform, JSPlatform).crossType(superPure)
    .settings(commonSettings: _*)
    .settings(mimaSettings: _*)
    .jsSettings(
      coverageExcludedPackages := ".*"
    )
    .dependsOn(`quill-core` % "compile->compile;test->test")

lazy val `quill-sql-jvm` = `quill-sql`.jvm
lazy val `quill-sql-js` = `quill-sql`.js


lazy val `quill-codegen` =
  (project in file("quill-codegen"))
    .settings(commonSettings)
    .dependsOn(`quill-core-jvm` % "compile->compile;test->test")

lazy val `quill-codegen-jdbc` =
  (project in file("quill-codegen-jdbc"))
    .settings(commonSettings)
    .settings(
      fork in Test := true,
      libraryDependencies ++= Seq(
        "com.github.choppythelumberjack" %% "tryclose" % "1.0.0",
        "org.scala-lang" % "scala-compiler" % scalaVersion.value % Test
      )
    )
    .dependsOn(`quill-codegen` % "compile->compile;test->test")
    .dependsOn(`quill-jdbc` % "compile->compile;test->test")


val codeGen = taskKey[Seq[File]]("Run Code Generation Phase for Integration Testing")

lazy val `quill-codegen-tests` =
  (project in file("quill-codegen-tests"))
    .settings(basicSettings)
    .settings(
      publish := { },
      libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % Test,
      fork in Test := true,
      (sourceGenerators in Compile) += (codeGen in Compile),
      (excludeFilter in unmanagedSources) := excludePathsIfOracle {
        (unmanagedSourceDirectories in Test).value.map { dir =>
          (dir / "io" / "getquill" / "codegen" / "OracleCodegenTestCases.scala").getCanonicalPath
        } ++
        (unmanagedSourceDirectories in Test).value.map { dir =>
          (dir / "io" / "getquill" / "codegen" / "util" / "WithOracleContext.scala").getCanonicalPath
        }
      },
      (codeGen in Compile) := {
        def recrusiveList(file:JFile): List[JFile] = {
          if (file.isDirectory)
            Option(file.listFiles()).map(_.flatMap(child=> recrusiveList(child)).toList).toList.flatten
          else
            List(file)
        }
        val r = (runner in Compile).value
        val s = streams.value.log
        val sourcePath = sourceManaged.value
        val classPath = (fullClasspath in Test in `quill-codegen-jdbc`).value.map(_.data)

        // We could put the code generated products directly in the `sourcePath` directory but for some reason
        // intellij doesn't like it unless there's a `main` directory inside.
        val fileDir = new File(sourcePath, "main").getAbsoluteFile
        val dbs =
          Seq("testH2DB", "testMysqlDB", "testPostgresDB", "testSqliteDB", "testSqlServerDB"
          ) ++ includeIfOracle("testOracleDB")
        println(s"Running code generation for DBs: ${dbs.mkString(", ")}")
        r.run(
          "io.getquill.codegen.integration.CodegenTestCaseRunner",
          classPath,
          // If oracle tests are included, enable code generation for it
          fileDir.getAbsolutePath +: dbs,
          s
        )
        recrusiveList(fileDir)
      }
    )
    .dependsOn(`quill-codegen-jdbc` % "compile->test")<commit_msg>change codegen to build in test<commit_after>import ReleaseTransformations._
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import scalariform.formatter.preferences._
import sbtrelease.ReleasePlugin
import scala.sys.process.Process
import sbtcrossproject.crossProject
import java.io.{File => JFile}

enablePlugins(TutPlugin)

lazy val baseModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-core-jvm`, `quill-core-js`, `quill-sql-jvm`, `quill-sql-js`, `quill-monix`
)

lazy val dbModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-jdbc`, `quill-jdbc-monix`
)

lazy val asyncModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-async`, `quill-async-mysql`, `quill-async-postgres`,
  `quill-finagle-mysql`, `quill-finagle-postgres`
)

lazy val codegenModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-codegen`, `quill-codegen-jdbc`, `quill-codegen-tests`
)

lazy val bigdataModules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
  `quill-cassandra`, `quill-cassandra-lagom`, `quill-cassandra-monix`, `quill-orientdb`, `quill-spark`
)

lazy val allModules =
  baseModules ++ dbModules ++ asyncModules ++ codegenModules ++ bigdataModules

lazy val filteredModules = {
  val modulesStr = sys.props.get("modules")
  println(s"Modules Argument Value: ${modulesStr}")

  modulesStr match {
    case Some("base") =>
      println("Compiling Base Modules")
      baseModules
    case Some("db") =>
      println("Compiling Database Modules")
      dbModules
    case Some("async") =>
      println("Compiling Async Database Modules")
      asyncModules
    case Some("codegen") =>
      println("Compiling Code Generator Modules")
      codegenModules
    case Some("bigdata") =>
      println("Compiling Big Data Modules")
      bigdataModules
    case _ =>
      println("Compiling All Modules")
      allModules
  }
}

lazy val `quill` =
  (project in file("."))
    .settings(commonSettings)
    .settings(`tut-settings`:_*)
    .aggregate(filteredModules.map(_.project): _*)
    .dependsOn(filteredModules: _*)

lazy val superPure = new sbtcrossproject.CrossType {
  def projectDir(crossBase: File, projectType: String): File =
    projectType match {
      case "jvm" => crossBase
      case "js"  => crossBase / s".$projectType"
    }

  def sharedSrcDir(projectBase: File, conf: String): Option[File] =
    Some(projectBase.getParentFile / "src" / conf / "scala")

  override def projectDir(crossBase: File, projectType: sbtcrossproject.Platform): File =
    projectType match {
      case JVMPlatform => crossBase
      case JSPlatform  => crossBase / ".js"
    }
}

lazy val `quill-core` =
  crossProject(JVMPlatform, JSPlatform).crossType(superPure)
    .settings(commonSettings: _*)
    .settings(mimaSettings: _*)
    .settings(libraryDependencies ++= Seq(
      "com.typesafe"               %  "config"        % "1.3.4",
      "com.typesafe.scala-logging" %% "scala-logging" % "3.9.0",
      "org.scala-lang"             %  "scala-reflect" % scalaVersion.value
    ))
    .jsSettings(
      libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "0.2.5",
      coverageExcludedPackages := ".*"
    )

lazy val `quill-core-jvm` = `quill-core`.jvm
lazy val `quill-core-js` = `quill-core`.js

lazy val `quill-sql` =
  crossProject(JVMPlatform, JSPlatform).crossType(superPure)
    .settings(commonSettings: _*)
    .settings(mimaSettings: _*)
    .jsSettings(
      coverageExcludedPackages := ".*"
    )
    .dependsOn(`quill-core` % "compile->compile;test->test")

lazy val `quill-sql-jvm` = `quill-sql`.jvm
lazy val `quill-sql-js` = `quill-sql`.js


lazy val `quill-codegen` =
  (project in file("quill-codegen"))
    .settings(commonSettings)
    .dependsOn(`quill-core-jvm` % "compile->compile;test->test")

lazy val `quill-codegen-jdbc` =
  (project in file("quill-codegen-jdbc"))
    .settings(commonSettings)
    .settings(
      fork in Test := true,
      libraryDependencies ++= Seq(
        "com.github.choppythelumberjack" %% "tryclose" % "1.0.0",
        "org.scala-lang" % "scala-compiler" % scalaVersion.value % Test
      )
    )
    .dependsOn(`quill-codegen` % "compile->compile;test->test")
    .dependsOn(`quill-jdbc` % "compile->compile;test->test")


val codegen = taskKey[Seq[File]]("Run Code Generation Phase for Integration Testing")

lazy val `quill-codegen-tests` =
  (project in file("quill-codegen-tests"))
    .settings(basicSettings)
    .settings(
      publish := {},
      publishLocal := {},
      publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo"))),
      libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % Test,
      fork in Test := true,
      (sourceGenerators in Test) += (codegen in Test),
      (excludeFilter in unmanagedSources) := excludePathsIfOracle {
        (unmanagedSourceDirectories in Test).value.map { dir =>
          (dir / "io" / "getquill" / "codegen" / "OracleCodegenTestCases.scala").getCanonicalPath
        } ++
        (unmanagedSourceDirectories in Test).value.map { dir =>
          (dir / "io" / "getquill" / "codegen" / "util" / "WithOracleContext.scala").getCanonicalPath
        }
      },
      (codegen in Test) := {
        def recrusiveList(file:JFile): List[JFile] = {
          if (file.isDirectory)
            Option(file.listFiles()).map(_.flatMap(child=> recrusiveList(child)).toList).toList.flatten
          else
            List(file)
        }
        val r = (runner in Compile).value
        val s = streams.value.log
        val sourcePath = sourceManaged.value
        val classPath = (fullClasspath in Test in `quill-codegen-jdbc`).value.map(_.data)

        // We could put the code generated products directly in the `sourcePath` directory but for some reason
        // intellij doesn't like it unless there's a `main` directory inside.
        val fileDir = new File(sourcePath, "main").getAbsoluteFile
        val dbs =
          Seq("testH2DB", "testMysqlDB", "testPostgresDB", "testSqliteDB", "testSqlServerDB"
          ) ++ includeIfOracle("testOracleDB")
        println(s"Running code generation for DBs: ${dbs.mkString(", ")}")
        r.run(
          "io.getquill.codegen.integration.CodegenTestCaseRunner",
          classPath,
          // If oracle tests are included, enable code generation for it
          fileDir.getAbsolutePath +: dbs,
          s
        )
        recrusiveList(fileDir)
      }
    )
    .dependsOn(`quill-codegen-jdbc` % "compile->test")
{'fraction_non_alphanumeric': 0.13903120633442012, 'fraction_numerical': 0.0020183201366247476, 'mean_word_length': 3.2211664482306683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, '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': '1000372', 'n_tokens_mistral': 4290, 'n_tokens_neox': 4247, 'n_words': 820}