我有一个sbt(0.11.2)插件,需要获取插件内文本文件的路径.我怎么做?baseDirectory,sourceDirectories等被设置为包含插件的项目的基础,而不是插件本身的基础.
我想向插件用户提供一个命令,从插件中的ruby文件中提取默认值,然后允许插件用户覆盖这些默认值.
为什么不使用旧的 Java 的 Class.getResource 或 Class.getResourceAsStream 方法?例如这样:
object TestPlugin extends Plugin {
override def settings = super.settings ++ Seq(
commands += testCommand
)
def testCommand = Command.command("test")(action)
def action(state: State) = {
try {
val in = getClass.getResourceAsStream("/test.txt")
val text = Source.fromInputStream(in).getLines mkString System.getProperty("line.separator")
logger(state).info(text)
in.close()
state
} catch {
case e: Exception =>
logger(state).error(e.getMessage)
state.fail
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
392 次 |
| 最近记录: |