-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from bjaglin/caching
Opt-in caching for scalafix invocations
- Loading branch information
Showing
25 changed files
with
804 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/scala-sbt-0.13/sbt/internal/sbtscalafix/Caching.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package sbt.internal.sbtscalafix | ||
|
||
import java.io.ByteArrayOutputStream | ||
|
||
import sbinary._ | ||
import sbt._ | ||
import scalafix.internal.sbt.Arg | ||
|
||
import scala.util.DynamicVariable | ||
|
||
object Caching { | ||
|
||
val lastModifiedStyle = FilesInfo.lastModified | ||
|
||
trait CacheKeysStamper | ||
extends InputCache[Seq[Arg.CacheKey]] | ||
with CacheImplicits { | ||
private val output = new DynamicVariable[Output](null) | ||
|
||
implicit val lastModifiedFormat = FileInfo.lastModified.format | ||
val baFormat = implicitly[Format[Array[Byte]]] | ||
val baEquiv = implicitly[Equiv[Array[Byte]]] | ||
|
||
protected def stamp: Arg.CacheKey => Unit | ||
|
||
final def write[T](t: T)(implicit format: Format[T]): Unit = | ||
format.writes(output.value, t) | ||
|
||
override final type Internal = Array[Byte] | ||
override final def convert(keys: Seq[Arg.CacheKey]): Array[Byte] = { | ||
val baos = new ByteArrayOutputStream() | ||
output.withValue(new JavaOutput(baos)) { | ||
keys.foreach(stamp) | ||
} | ||
Hash.apply(baos.toByteArray) | ||
} | ||
override final def read(from: Input): Array[Byte] = | ||
baFormat.reads(from) | ||
override final def write(to: Output, ba: Array[Byte]): Unit = | ||
baFormat.writes(to, ba) | ||
override final def equiv: Equiv[Array[Byte]] = | ||
baEquiv | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/scala-sbt-1.0/sbt/internal/sbtscalafix/Caching.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package sbt.internal.sbtscalafix | ||
|
||
import sbt.FileInfo | ||
import scalafix.internal.sbt.Arg | ||
import sjsonnew._ | ||
|
||
import scala.util.DynamicVariable | ||
|
||
object Caching { | ||
|
||
val lastModifiedStyle = FileInfo.lastModified | ||
|
||
trait CacheKeysStamper | ||
extends JsonFormat[Seq[Arg.CacheKey]] | ||
with BasicJsonProtocol { | ||
private val builder = new DynamicVariable[Builder[_]](null) | ||
|
||
protected def stamp: Arg.CacheKey => Unit | ||
|
||
final def write[T](t: T)(implicit format: JsonFormat[T]): Unit = | ||
format.write(t, builder.value) | ||
|
||
override final def write[J](obj: Seq[Arg.CacheKey], b: Builder[J]): Unit = { | ||
b.beginArray() | ||
builder.withValue(b) { | ||
obj.foreach(stamp) | ||
} | ||
b.endArray() | ||
} | ||
|
||
// we actually don't need to read anything back, see https://github.com/sbt/sbt/pull/5513 | ||
override final def read[J]( | ||
jsOpt: Option[J], | ||
unbuilder: Unbuilder[J] | ||
): Seq[Arg.CacheKey] = ??? | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.