Skip to content

Commit

Permalink
switch import sbt.Process to scala Process
Browse files Browse the repository at this point in the history
  • Loading branch information
Cause Chung committed Aug 12, 2017
1 parent 1eb2181 commit 93d9f46
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/main/scala/com/github/cuzfrog/sbttmpfs/ExMethod.scala
Expand Up @@ -3,7 +3,9 @@ package com.github.cuzfrog.sbttmpfs
import java.io.File
import java.nio.file.Files

import sbt.{IO, Logger, Process}
import sbt.{IO, Logger}

import scala.sys.process.Process

/**
* Created by cuz on 17-5-7.
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/github/cuzfrog/sbttmpfs/LinkTool.scala
Expand Up @@ -8,6 +8,8 @@ import sbt._
import scala.collection.concurrent.TrieMap
import ExMethod._

import scala.sys.process.Process

private object LinkTool {

//symlinks and their target tmpfs dir, used for clean old links after task clean.
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/github/cuzfrog/sbttmpfs/MountTool.scala
Expand Up @@ -5,6 +5,8 @@ import java.io.File
import ExMethod._
import sbt._

import scala.sys.process.Process

private object MountTool {

/**
Expand Down
32 changes: 17 additions & 15 deletions src/main/scala/com/github/cuzfrog/sbttmpfs/SbtTmpfsPlugin.scala
Expand Up @@ -2,6 +2,7 @@ package com.github.cuzfrog.sbttmpfs

import sbt.{Def, _}
import Keys._
import sbt.internal.util.ManagedLogger

object SbtTmpfsPlugin extends AutoPlugin {

Expand All @@ -12,13 +13,13 @@ object SbtTmpfsPlugin extends AutoPlugin {
case object Mount extends TmpfsDirectoryMode
}

val tmpfsOn = taskKey[Unit]("Link or mount tmpfs.")
val tmpfsLink =
val tmpfsOn: TaskKey[Unit] = taskKey[Unit]("Link or mount tmpfs.")
val tmpfsLink: TaskKey[Unit] =
taskKey[Unit]("Link tmpfs to cross-target or user defined directories.")
val tmpfsMount = taskKey[Unit]("Mount tmpfs point to target.")
val tmpfsDirectoryMode =
val tmpfsMount: TaskKey[Unit] = taskKey[Unit]("Mount tmpfs point to target.")
val tmpfsDirectoryMode: SettingKey[TmpfsDirectoryMode] =
settingKey[TmpfsDirectoryMode]("Control mount target or link dir within target. Default: Symlink")
val tmpfsMappingDirectories =
val tmpfsMappingDirectories: SettingKey[Map[sbt.File, Seq[sbt.File]]] =
settingKey[Map[File, Seq[File]]](
"""|Keys are source directories that will be synchronized to tmpfs.
|Values are destination dirs where keys are synchronized to.
Expand All @@ -27,22 +28,23 @@ object SbtTmpfsPlugin extends AutoPlugin {
|Default is empty.
""".stripMargin
)
val tmpfsSyncMapping =
val tmpfsSyncMapping: TaskKey[Unit] =
taskKey[Unit]("Synchronize dirs defined in tmpfsMappingDirectories.")
//val tmpfsCleanDeadLinks = taskKey[Unit]("Try to clean dead links.")

// --------- link -------- keys --------
val tmpfsLinkDirectories =
val tmpfsLinkDirectories: SettingKey[Seq[sbt.File]] =
settingKey[Seq[File]]("Directories that will be linked to tmpfs. Show this key to see default.")
val tmpfsLinkBaseDirectory =
val tmpfsLinkBaseDirectory: SettingKey[sbt.File] =
settingKey[File]("Base directory to contain linked target dirs. Default is sbt.IO.temporaryDirectory/sbttmpfs.")

// --------- mount -------- keys --------
val tmpfsMountDirectories =
val tmpfsMountDirectories: SettingKey[Seq[sbt.File]] =
settingKey[Seq[File]]("Directories that will be mount with tmpfs. Default is target dir.")
val tmpfsMountCommand =
val tmpfsMountCommand: SettingKey[String] =
settingKey[String]("Default: 'sudo mount -t tmpfs -o size={tmpfsMountSize}m tmpfs' + dirPath.")
val tmpfsMountSizeLimit = settingKey[Int]("How much RAM limit to tmpfs. In MB. Default: 256m.")
val tmpfsMountSizeLimit: SettingKey[Int] =
settingKey[Int]("How much RAM limit to tmpfs. In MB. Default: 256m.")

private val extraTargetDirList = Seq("resolution-cache")
@volatile lazy val defaultSbtTmpfsSettings: Seq[Def.Setting[_]] = Seq(
Expand All @@ -61,21 +63,21 @@ object SbtTmpfsPlugin extends AutoPlugin {

private val taskDefinition = Seq(
tmpfsLink := {
implicit val logger = streams.value.log
implicit val logger: ManagedLogger = streams.value.log
val mode = tmpfsDirectoryMode.value
if (mode == TmpfsDirectoryMode.Symlink) {
LinkTool.link(tmpfsLinkDirectories.value, tmpfsLinkBaseDirectory.value)
} else logger.debug(s"[SbtTmpfsPlugin] call tmpfsLink, but mode is: $mode, abort.")
},
tmpfsMount := {
implicit val logger = streams.value.log
implicit val logger: ManagedLogger = streams.value.log
val mode = tmpfsDirectoryMode.value
if (mode == TmpfsDirectoryMode.Mount) {
MountTool.mount(tmpfsMountDirectories.value, tmpfsMountCommand.value)
} else logger.debug(s"[SbtTmpfsPlugin] call tmpfsMount, but mode is: $mode abort.")
},
tmpfsSyncMapping := Def.taskDyn {
implicit val logger = streams.value.log
implicit val logger: ManagedLogger = streams.value.log
val mode = tmpfsDirectoryMode.value
logger.debug(s"[SbtTmpfsPlugin] sync mapping with mode: $mode")
mode match {
Expand All @@ -94,7 +96,7 @@ object SbtTmpfsPlugin extends AutoPlugin {
}
}.value,
(initialize in Compile) := {
implicit val logger = sLog.value
implicit val logger: Logger = sLog.value
logger.debug("[SbtTmpfsPlugin] try to clean dead symlinks.")
LinkTool.cleanDeadLinks(target.value.listFiles()) //clean possible different cross version.
LinkTool.cleanDeadLinks(tmpfsLinkDirectories.value)
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/com/github/cuzfrog/sbttmpfs/SyncTool.scala
Expand Up @@ -5,6 +5,8 @@ import java.io.File
import ExMethod._
import sbt._

import scala.sys.process.Process

/**
* Created by cuz on 17-5-7.
*/
Expand Down Expand Up @@ -66,6 +68,6 @@ private object SyncTool {
//see fileSyncTest/FileSyncTest.md.
private def sync(src: File, dest: File)(implicit logger: Logger): Unit = {
logger.debug(s"[SbtTmpfsPlugin] sync from $src to $dest.")
sbt.Process(s"""cp -au ${src.getAbsolutePath}/. ${dest.getAbsolutePath}""").!
Process(s"""cp -au ${src.getAbsolutePath}/. ${dest.getAbsolutePath}""").!
}
}

0 comments on commit 93d9f46

Please sign in to comment.