diff options
author | Jakob Odersky <jakob@odersky.com> | 2016-07-14 20:51:41 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2016-07-14 20:51:41 -0700 |
commit | 7651b5484bfa14456208f1251b98ec99618408d7 (patch) | |
tree | 9b74d4ce94a5577a8bf54e65b9e3be77838881a6 | |
parent | ed9669556a27330732cf0871772699afeb4b6efb (diff) | |
download | dotfiles-7651b5484bfa14456208f1251b98ec99618408d7.tar.gz dotfiles-7651b5484bfa14456208f1251b98ec99618408d7.tar.bz2 dotfiles-7651b5484bfa14456208f1251b98ec99618408d7.zip |
sbt: add javap, utility plugin
-rw-r--r-- | home/.sbt/0.13/plugins/JavapPlugin.scala | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/home/.sbt/0.13/plugins/JavapPlugin.scala b/home/.sbt/0.13/plugins/JavapPlugin.scala new file mode 100644 index 0000000..40922e9 --- /dev/null +++ b/home/.sbt/0.13/plugins/JavapPlugin.scala @@ -0,0 +1,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 + } + } + ) +} + + + |