Skip to content

Commit

Permalink
Merge pull request #1418 from Friendseeker/fix-scripted-compile-errors
Browse files Browse the repository at this point in the history
[2.x] Fix compile errors in `zinc-scripted`
  • Loading branch information
eed3si9n authored Oct 3, 2024
2 parents f40a0d3 + 31e332d commit 5534ab4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ object ScriptedMain {

def detectScriptedTests(scriptedBase: File): Map[String, Set[String]] = {
val scriptedFiles: NameFilter = ("test": NameFilter) | "pending"
val pairs = (scriptedBase * AllPassFilter * AllPassFilter * scriptedFiles).get.map { f =>
val pairs = (scriptedBase * AllPassFilter * AllPassFilter * scriptedFiles).get().map { f =>
val p = f.getParentFile
(p.getParentFile.getName, p.getName)
}

pairs.groupBy(_._1).mapValues(_.map(_._2).toSet)
pairs.groupBy(_._1).view.mapValues(_.map(_._2).toSet).toMap
}

private def parseScripted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import sbt.internal.scripted.{ StatementHandler, TestFailed }
import sbt.internal.util.ManagedLogger
import sjsonnew.support.scalajson.unsafe.{ Converter, Parser => JsonParser }

import scala.{ PartialFunction => ?=> }
import scala.collection.mutable
import scala.concurrent.{ blocking, Await, Future, Promise }
import scala.concurrent.duration._
Expand Down Expand Up @@ -141,11 +140,19 @@ class IncHandler(directory: Path, cacheDir: Path, scriptedLog: ManagedLogger, co

def initBuild: Build = {
if (Files.exists(directory / "build.json")) {
import sjsonnew._, BasicJsonProtocol._
implicit val pathFormat = IsoString.iso[Path](_.toString, Paths.get(_))
implicit val projectFormat =
caseClass(Project.apply _, Project.unapply _)("name", "dependsOn", "in", "scalaVersion")
implicit val buildFormat = caseClass(Build.apply _, Build.unapply _)("projects")
import sjsonnew.{ IsoString, JsonFormat }
import sjsonnew.BasicJsonProtocol._
given pathISOString: IsoString[Path] = IsoString.iso[Path](_.toString, Paths.get(_))
given pathFormat: JsonFormat[Path] = isoStringFormat[Path](using pathISOString)
given projectFormat: JsonFormat[Project] =
caseClass4(Project.apply, p => Some(p.name, p.dependsOn, p.in, p.scalaVersion))(
"name",
"dependsOn",
"in",
"scalaVersion",
)
given buildFormat: JsonFormat[Build] =
caseClass1(Build.apply, b => Some(b.projects))("projects")
// Do not parseFromFile as it leaves file open, causing problems on Windows.
val json = {
val channel = Files.newByteChannel(directory / "build.json")
Expand Down Expand Up @@ -267,20 +274,21 @@ class IncHandler(directory: Path, cacheDir: Path, scriptedLog: ManagedLogger, co
private def dropRightColon(s: String) = if (s endsWith ":") s.dropRight(1) else s

private def onArgs(commandName: String)(
pf: (ProjectStructure, List[String], IncState) ?=> Future[Unit]
pf: PartialFunction[(ProjectStructure, List[String], IncState), Future[Unit]]
): (String, IncCommand) =
commandName ->
((p, xs, i) => applyOrElse(pf, (p, xs, i), p.unrecognizedArguments(commandName, xs)))

private def noArgs(commandName: String)(
pf: (ProjectStructure, IncState) ?=> Future[Unit]
pf: PartialFunction[(ProjectStructure, IncState), Future[Unit]]
): (String, IncCommand) =
commandName ->
((p, xs, i) => {
applyOrElse(pf, (p, i), p.acceptsNoArguments(commandName, xs))
})

private def applyOrElse[A, B](pf: A ?=> B, x: A, fb: => B): B = pf.applyOrElse(x, (_: A) => fb)
private def applyOrElse[A, B](pf: PartialFunction[A, B], x: A, fb: => B): B =
pf.applyOrElse(x, (_: A) => fb)
}

case class ProjectStructure(
Expand Down Expand Up @@ -312,12 +320,12 @@ case class ProjectStructure(
val javaSourceDirectory = baseDirectory / "src" / "main" / "java"

def scalaSources: List[Path] =
((scalaSourceDirectory.toFile ** "*.scala").get ++ (baseDirectory.toFile * "*.scala").get)
((scalaSourceDirectory.toFile ** "*.scala").get() ++ (baseDirectory.toFile * "*.scala").get())
.map(_.toPath)
.toList

def javaSources: List[Path] =
((javaSourceDirectory.toFile ** "*.java").get ++ (baseDirectory.toFile * "*.java").get)
((javaSourceDirectory.toFile ** "*.java").get() ++ (baseDirectory.toFile * "*.java").get())
.map(_.toPath)
.toList

Expand Down Expand Up @@ -369,7 +377,7 @@ case class ProjectStructure(
}

def unmanagedJars: List[Path] =
((baseDirectory / "lib").toFile ** "*.jar").get.toList.map(_.toPath)
((baseDirectory / "lib").toFile ** "*.jar").get().toList.map(_.toPath)

def dependsOnRef: Vector[ProjectStructure] = dependsOn.map(lookupProject(_))

Expand Down Expand Up @@ -473,14 +481,14 @@ case class ProjectStructure(
assert(
missing.isEmpty,
s"""Missing ${missing.size} products:${missing.map("\n " + _).mkString}
|Generated:${generatedClassFiles.get.toList.map("\n " + _).mkString}""".stripMargin
|Generated:${generatedClassFiles.get().toList.map("\n " + _).mkString}""".stripMargin
)
()
}

def checkNoGeneratedClassFiles(): Future[Unit] =
Future {
val allPlainClassFiles = generatedClassFiles.get.toList.map(_.toString)
val allPlainClassFiles = generatedClassFiles.get().toList.map(_.toString)
val allClassesInJar: List[String] =
outputJar.toList.filter(Files.exists(_)).flatMap(p => JarUtils.listClassFiles(p.toFile))
if (allPlainClassFiles.nonEmpty || allClassesInJar.nonEmpty) {
Expand Down Expand Up @@ -711,7 +719,7 @@ case class ProjectStructure(
IO.copy(Seq(currentJar.toFile -> targetJar.toFile))
()
case None =>
val sources = (classesDir.toFile ** -DirectoryFilter).get.flatMap { f =>
val sources = (classesDir.toFile ** -DirectoryFilter).get().flatMap { f =>
IO.relativize(classesDir.toFile, f) match {
case Some(path) => List((f, path))
case _ => Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import sbt.io.IO
import sbt.util.{ Level, Logger }

import scala.collection.parallel.ParSeq
import collection.parallel.CollectionsHaveToParArray
import sbt.inc.ScriptedMain._

object ScriptedRunnerImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ final class ScriptedTests(
// Test group and names may be file filters (like '*')
val groupAndNameDirs = for {
ScriptedTest(group, name) <- tests
groupDir <- resourceBaseDirectory.toFile.glob(group).get.map(_.toPath)
testDir <- groupDir.toFile.*(name).get.map(_.toPath)
groupDir <- resourceBaseDirectory.toFile.glob(group).get().map(_.toPath)
testDir <- groupDir.toFile.*(name).get().map(_.toPath)
} yield (groupDir, testDir)

val labelsAndDirs = groupAndNameDirs.map {
Expand Down Expand Up @@ -157,7 +157,7 @@ final class ScriptedTests(
// Run the test and delete files (except global that holds local scala jars)
val runTest = () => commonRunTest(label, batchTmpDir, handlers, runner, states, logger)
val result = runOrHandleDisabled(label, batchTmpDir, runTest, logger)
IO.delete(batchTmpDir.toFile.*("*" -- "global").get)
IO.delete(batchTmpDir.toFile.*("*" -- "global").get())
result
}
finally runner.cleanUpHandlers(seqHandlers, states)
Expand Down

0 comments on commit 5534ab4

Please sign in to comment.