I have an sbt (0.11.2) plugin that needs to get a path to text files inside the plugin. How do I do that? baseDirectory, sourceDirectories etc are set to the base of the project that's including the plugin, not the base of the plugin itself.
I'd like to provide a command to the plugin user that pulls defaults from a ruby file inside the plugin, and then allows the plugin user to override those defaults.
Why don't you use good old Java's Class.getResource or Class.getResourceAsStream method? E.g. like this:
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
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With