in sbt-idea-compiler-indices/src/main/scala/org/jetbrains/sbt/indices/SbtIntellijIndicesPlugin.scala [45:127]
private[this] def perConfig: Seq[Def.Setting[_]] = Seq(
incOptions ~= patchIncOptions,
compile := Def.taskDyn {
val previousValue = compile.taskValue
val buildBaseDir = (baseDirectory in ThisBuild).value
if (!isIdeaProject(buildBaseDir)) Def.task(previousValue.value)
else {
val log = streams.value.log
val projectId = thisProject.value.id
val configurationId = configuration.value
val compilationId = UUID.randomUUID()
val itype = incrementalityType.value
val version = scalaBinaryVersion.value
val infoDir = compilationInfoDir(buildBaseDir, s"$projectId-$configurationId").toPath
val port = ideaPort.value
infoDir.lock(log = log.debug(_))
val compilationStartTimestamp = System.currentTimeMillis()
val socket =
try notifyIdeaStart(port, buildBaseDir.getPath, compilationId)
catch { case e: Throwable => infoDir.unlock(log = log.debug(_)); throw e }
Def.taskDyn {
val previousResult = itype match {
case IncrementalityType.Incremental => previousCompile.value
case IncrementalityType.NonIncremental => PreviousResult.empty()
}
Def.task {
val oldTaskValue = previousValue.value
val isOffline = socket.isEmpty
val pconfig = configurationId match {
case Compile => PConfiguration.Compile
case Test => PConfiguration.Test
case conf =>
sys.error(
s"Unsupported configuration $conf. Only Compile and Test configuration are supported by idea-compiler-indices."
)
}
val compilationInfoFile = dumpCompilationInfo(
isOffline,
oldTaskValue,
previousResult,
projectId,
version,
itype,
infoDir.toFile,
pconfig,
compilationStartTimestamp,
compilationId
)
val result = CompilationResult(
successful = true,
compilationStartTimestamp,
compilationInfoFile
)
socket.foreach(notifyFinish(_, result))
oldTaskValue
}
}.result.map {
case Inc(cause) =>
// compilation failed case
val failedRes = CompilationResult(
successful = false,
compilationStartTimestamp,
None
)
socket.foreach(notifyFinish(_, failedRes))
throw cause
case Value(canalysis) => canalysis
}.andFinally {
try infoDir.unlock(log = log.debug(_))
finally socket.foreach(_.close())
}
}
}.value