sbt/project/Sxr.scala

39 lines
1.5 KiB
Scala
Raw Normal View History

2014-05-01 18:50:07 +02:00
import sbt._
import Keys._
import Scope.ThisScope
2014-05-01 18:50:07 +02:00
object Sxr {
2015-07-10 11:53:48 +02:00
val sxrConf = config("sxr").hide
2014-05-01 18:50:07 +02:00
val sxr = TaskKey[File]("sxr")
val sourceDirectories = TaskKey[Seq[File]]("sxr-source-directories")
2014-05-01 18:50:07 +02:00
lazy val settings: Seq[Setting[_]] = inTask(sxr)(inSxrSettings) ++ baseSettings
2014-05-01 18:50:07 +02:00
def baseSettings = Seq(
libraryDependencies += "org.scala-sbt.sxr" % "sxr_2.10" % "0.3.0" % sxrConf.name
)
def inSxrSettings = Seq(
managedClasspath := update.value.matching(configurationFilter(sxrConf.name)).classpath,
scalacOptions += "-P:sxr:base-directory:" + sourceDirectories.value.absString,
scalacOptions += "-Xplugin:" + managedClasspath.value.files.filter(_.getName.contains("sxr")).absString,
scalacOptions += "-Ystop-after:sxr",
target := target.in(taskGlobal).value / "browse",
2017-03-29 15:43:38 +02:00
sxr in taskGlobal := sxrTask.value
2014-05-01 18:50:07 +02:00
)
def taskGlobal = ThisScope.copy(task = Global)
2017-03-29 15:43:38 +02:00
def sxrTask = Def task {
val out = target.value
2014-05-01 18:50:07 +02:00
val outputDir = out.getParentFile / (out.getName + ".sxr")
2017-03-29 15:43:38 +02:00
val f = FileFunction.cached(streams.value.cacheDirectory / "sxr", FilesInfo.hash) { in =>
streams.value.log.info("Generating sxr output in " + outputDir.getAbsolutePath + "...")
2014-05-01 18:50:07 +02:00
IO.delete(out)
IO.createDirectory(out)
2017-03-29 15:43:38 +02:00
val comp = new compiler.RawCompiler(scalaInstance.value, classpathOptions.value, streams.value.log)
comp(in.toSeq.sorted, fullClasspath.value.files, out, scalacOptions.value)
2014-05-01 18:50:07 +02:00
Set(outputDir)
}
2017-03-29 15:43:38 +02:00
f(sources.value.toSet)
2014-05-01 18:50:07 +02:00
outputDir
}
}