blob: 40922e9fbeb91fd91e547ac7cd6e8965a16818b3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import sbt._
import sbt.Keys._
object JavapPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements
object autoImport {
val javapOptions = settingKey[Seq[String]]("Options to pass to javap.")
val javap = taskKey[Set[File]]("Disassemble byte code.")
}
import autoImport._
override def projectSettings = Seq(
javapOptions := Seq("-c", "-private", "-v"),
javap := {
val compiled: inc.Analysis = (compile in Compile).value
val classFiles: Set[File] = compiled.relations.allProducts.toSet
val outBaseDir = crossTarget.value / "javap"
for (cf <- classFiles) yield {
val outDir = Path.rebase(
(classDirectory in Compile).value,
crossTarget.value / "javap")(cf).get.getParentFile
IO.createDirectory(outDir)
val out: File = outDir / (cf.base + ".javap")
streams.value.log.info("Disassembling " + out.getAbsolutePath)
val opts = javapOptions.value.mkString(" ")
val ev = (Process(s"javap ${opts} ${cf.getAbsolutePath}") #> out) ! streams.value.log
if (ev != 0) sys.error(s"Error occured running javap. Exit code: ${ev}")
out
}
}
)
}
|