2014-05-01 18:50:07 +02:00
|
|
|
import sbt._
|
|
|
|
|
import Keys._
|
|
|
|
|
import Scope.ThisScope
|
2011-06-10 13:48:53 +02:00
|
|
|
|
2017-05-03 16:52:36 +02:00
|
|
|
import sbt.librarymanagement.syntax._
|
|
|
|
|
|
|
|
|
|
import sbt.internal.inc.RawCompiler
|
|
|
|
|
|
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")
|
2011-06-10 13:48:53 +02:00
|
|
|
|
2014-05-01 18:50:07 +02:00
|
|
|
lazy val settings: Seq[Setting[_]] = inTask(sxr)(inSxrSettings) ++ baseSettings
|
2011-06-10 13:48:53 +02:00
|
|
|
|
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,
|
2017-04-21 09:14:31 +02:00
|
|
|
scalacOptions += "-Xplugin:" + managedClasspath.value.files
|
|
|
|
|
.filter(_.getName.contains("sxr"))
|
|
|
|
|
.absString,
|
2014-05-01 18:50:07 +02:00
|
|
|
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-04-21 09:14:31 +02:00
|
|
|
val comp =
|
2017-05-03 16:52:36 +02:00
|
|
|
new RawCompiler(scalaInstance.value, classpathOptions.value, streams.value.log)
|
2017-03-29 15:43:38 +02:00
|
|
|
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
|
|
|
|
|
}
|
2011-06-10 13:48:53 +02:00
|
|
|
}
|