mirror of https://github.com/sbt/sbt.git
Move background job service directory location
Rather than putting the background job temporary files in whatever java.io.tmpdir points to, this commit moves the files into a subdirectory of target in the project root directory. To make the directory configurable via settings, I had to move the declaration of the bgJobService setting later in the project initialization process. I don't think this should matter because background jobs shouldn't be created until after the project has loaded all of its settings..
This commit is contained in:
parent
73edc8d4ff
commit
73a196798f
|
|
@ -351,7 +351,7 @@ object Defaults extends BuildCommon {
|
||||||
sys.env.contains("CI") || SysProp.ci,
|
sys.env.contains("CI") || SysProp.ci,
|
||||||
// watch related settings
|
// watch related settings
|
||||||
pollInterval :== Watch.defaultPollInterval,
|
pollInterval :== Watch.defaultPollInterval,
|
||||||
) ++ LintUnused.lintSettings
|
) ++ LintUnused.lintSettings ++ DefaultBackgroundJobService.backgroundJobServiceSettings
|
||||||
)
|
)
|
||||||
|
|
||||||
def defaultTestTasks(key: Scoped): Seq[Setting[_]] =
|
def defaultTestTasks(key: Scoped): Seq[Setting[_]] =
|
||||||
|
|
|
||||||
|
|
@ -251,6 +251,7 @@ object Keys {
|
||||||
val javaOptions = taskKey[Seq[String]]("Options passed to a new JVM when forking.").withRank(BPlusTask)
|
val javaOptions = taskKey[Seq[String]]("Options passed to a new JVM when forking.").withRank(BPlusTask)
|
||||||
val envVars = taskKey[Map[String, String]]("Environment variables used when forking a new JVM").withRank(BTask)
|
val envVars = taskKey[Map[String, String]]("Environment variables used when forking a new JVM").withRank(BTask)
|
||||||
|
|
||||||
|
val bgJobServiceDirectory = settingKey[File]("The directory for temporary files used by background jobs.")
|
||||||
val bgJobService = settingKey[BackgroundJobService]("Job manager used to run background jobs.")
|
val bgJobService = settingKey[BackgroundJobService]("Job manager used to run background jobs.")
|
||||||
val bgList = taskKey[Seq[JobHandle]]("List running background jobs.")
|
val bgList = taskKey[Seq[JobHandle]]("List running background jobs.")
|
||||||
val ps = taskKey[Seq[JobHandle]]("bgList variant that displays on the log.")
|
val ps = taskKey[Seq[JobHandle]]("bgList variant that displays on the log.")
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ object StandardMain {
|
||||||
try {
|
try {
|
||||||
MainLoop.runLogged(s)
|
MainLoop.runLogged(s)
|
||||||
} finally {
|
} finally {
|
||||||
try DefaultBackgroundJobService.backgroundJobService.shutdown()
|
try DefaultBackgroundJobService.shutdown()
|
||||||
finally hook.close()
|
finally hook.close()
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ import java.io.{ Closeable, File, FileInputStream, IOException }
|
||||||
import java.nio.file.attribute.BasicFileAttributes
|
import java.nio.file.attribute.BasicFileAttributes
|
||||||
import java.nio.file.{ FileVisitResult, Files, Path, SimpleFileVisitor }
|
import java.nio.file.{ FileVisitResult, Files, Path, SimpleFileVisitor }
|
||||||
import java.security.{ DigestInputStream, MessageDigest }
|
import java.security.{ DigestInputStream, MessageDigest }
|
||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import java.util.concurrent.atomic.{ AtomicLong, AtomicReference }
|
||||||
|
|
||||||
import sbt.Def.{ Classpath, ScopedKey, Setting }
|
import sbt.Def.{ Classpath, ScopedKey, Setting }
|
||||||
import sbt.Scope.GlobalScope
|
import sbt.Scope.GlobalScope
|
||||||
|
|
@ -61,13 +62,16 @@ private[sbt] abstract class AbstractBackgroundJobService extends BackgroundJobSe
|
||||||
private val nextId = new AtomicLong(1)
|
private val nextId = new AtomicLong(1)
|
||||||
private val pool = new BackgroundThreadPool()
|
private val pool = new BackgroundThreadPool()
|
||||||
|
|
||||||
private var serviceTempDirOpt: Option[File] = None
|
private[sbt] def serviceTempDirBase: File
|
||||||
private def serviceTempDir = serviceTempDirOpt match {
|
private val serviceTempDirRef = new AtomicReference[File]
|
||||||
case Some(dir) => dir
|
private def serviceTempDir: File = serviceTempDirRef.synchronized {
|
||||||
case _ =>
|
serviceTempDirRef.get match {
|
||||||
val dir = IO.createTemporaryDirectory
|
case null =>
|
||||||
serviceTempDirOpt = Some(dir)
|
val dir = IO.createUniqueDirectory(serviceTempDirBase)
|
||||||
dir
|
serviceTempDirRef.set(dir)
|
||||||
|
dir
|
||||||
|
case s => s
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// hooks for sending start/stop events
|
// hooks for sending start/stop events
|
||||||
protected def onAddJob(@deprecated("unused", "") job: JobHandle): Unit = ()
|
protected def onAddJob(@deprecated("unused", "") job: JobHandle): Unit = ()
|
||||||
|
|
@ -166,7 +170,7 @@ private[sbt] abstract class AbstractBackgroundJobService extends BackgroundJobSe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pool.close()
|
pool.close()
|
||||||
serviceTempDirOpt foreach IO.delete
|
Option(serviceTempDirRef.get).foreach(IO.delete)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def withHandle(job: JobHandle)(f: ThreadJobHandle => Unit): Unit = job match {
|
private def withHandle(job: JobHandle)(f: ThreadJobHandle => Unit): Unit = job match {
|
||||||
|
|
@ -465,14 +469,37 @@ private[sbt] class BackgroundThreadPool extends java.io.Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private[sbt] class DefaultBackgroundJobService extends AbstractBackgroundJobService {
|
private[sbt] class DefaultBackgroundJobService(private[sbt] val serviceTempDirBase: File)
|
||||||
|
extends AbstractBackgroundJobService {
|
||||||
|
@deprecated("Use the constructor that specifies the background job temporary directory", "1.4.0")
|
||||||
|
def this() = this(IO.createTemporaryDirectory)
|
||||||
override def makeContext(id: Long, spawningTask: ScopedKey[_], state: State): ManagedLogger = {
|
override def makeContext(id: Long, spawningTask: ScopedKey[_], state: State): ManagedLogger = {
|
||||||
val extracted = Project.extract(state)
|
val extracted = Project.extract(state)
|
||||||
LogManager.constructBackgroundLog(extracted.structure.data, state)(spawningTask)
|
LogManager.constructBackgroundLog(extracted.structure.data, state)(spawningTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private[sbt] object DefaultBackgroundJobService {
|
private[sbt] object DefaultBackgroundJobService {
|
||||||
lazy val backgroundJobService: DefaultBackgroundJobService = new DefaultBackgroundJobService
|
|
||||||
lazy val backgroundJobServiceSetting: Setting[_] =
|
private[this] val backgroundJobServices = new ConcurrentHashMap[File, DefaultBackgroundJobService]
|
||||||
((Keys.bgJobService in GlobalScope) :== backgroundJobService)
|
private[sbt] def shutdown(): Unit = {
|
||||||
|
backgroundJobServices.values.forEach(_.shutdown())
|
||||||
|
backgroundJobServices.clear()
|
||||||
|
}
|
||||||
|
private[sbt] lazy val backgroundJobServiceSetting: Setting[_] =
|
||||||
|
(Keys.bgJobService in GlobalScope) := {
|
||||||
|
val path = (sbt.Keys.bgJobServiceDirectory in GlobalScope).value
|
||||||
|
val newService = new DefaultBackgroundJobService(path)
|
||||||
|
backgroundJobServices.putIfAbsent(path, newService) match {
|
||||||
|
case null => newService
|
||||||
|
case s =>
|
||||||
|
newService.shutdown()
|
||||||
|
s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private[sbt] lazy val backgroundJobServiceSettings: Seq[Def.Setting[_]] = Def.settings(
|
||||||
|
Keys.bgJobServiceDirectory in GlobalScope := {
|
||||||
|
sbt.Keys.appConfiguration.value.baseDirectory / "target" / "bg-jobs"
|
||||||
|
},
|
||||||
|
backgroundJobServiceSetting
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,6 @@ private[sbt] object Load {
|
||||||
def injectGlobal(state: State): Seq[Setting[_]] =
|
def injectGlobal(state: State): Seq[Setting[_]] =
|
||||||
(appConfiguration in GlobalScope :== state.configuration) +:
|
(appConfiguration in GlobalScope :== state.configuration) +:
|
||||||
LogManager.settingsLogger(state) +:
|
LogManager.settingsLogger(state) +:
|
||||||
DefaultBackgroundJobService.backgroundJobServiceSetting +:
|
|
||||||
EvaluateTask.injectSettings
|
EvaluateTask.injectSettings
|
||||||
|
|
||||||
def defaultWithGlobal(
|
def defaultWithGlobal(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue