pekko/project/Unidoc.scala

81 lines
3.9 KiB
Scala
Raw Normal View History

2011-09-23 10:21:03 +02:00
package akka
2011-07-08 10:20:10 +12:00
import sbt._
2011-12-09 21:55:49 +13:00
import sbt.Keys._
import sbt.Project.Initialize
2011-07-08 10:20:10 +12:00
object Unidoc {
lazy val JavaDoc = config("genjavadoc") extend Compile
lazy val GenJavaDocEnabled = Option(sys.props("akka.genjavadoc.enabled")) filter (_.toLowerCase == "true") map (_ => true) getOrElse false
lazy val javadocSettings =
inConfig(JavaDoc)(Defaults.configSettings) ++ Seq(
packageDoc in Compile <<= packageDoc in JavaDoc,
sources in JavaDoc <<= (target, compile in Compile, sources in Compile) map ((t, c, s) =>
if (GenJavaDocEnabled) (t / "java" ** "*.java").get ++ s.filter(_.getName.endsWith(".java"))
else throw new RuntimeException("cannot build java docs without -Dakka.genjavadoc.enabled=true")
),
javacOptions in JavaDoc := Seq(),
artifactName in packageDoc in JavaDoc := ((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar")
) ++ (if (GenJavaDocEnabled) Seq(
libraryDependencies += Dependencies.Compile.genjavadoc,
scalacOptions <+= target map (t => "-P:genjavadoc:out=" + (t / "java"))
) else Nil)
2011-07-08 10:20:10 +12:00
val unidocDirectory = SettingKey[File]("unidoc-directory")
val unidocExclude = SettingKey[Seq[String]]("unidoc-exclude")
val unidocAllSources = TaskKey[Seq[Seq[File]]]("unidoc-all-sources")
val unidocSources = TaskKey[Seq[File]]("unidoc-sources")
val unidocAllClasspaths = TaskKey[Seq[Classpath]]("unidoc-all-classpaths")
val unidocClasspath = TaskKey[Seq[File]]("unidoc-classpath")
val unidoc = TaskKey[(File, File)]("unidoc", "Create unified scaladoc and javadoc for all aggregates")
val sunidoc = TaskKey[File]("sunidoc", "Create unified scaladoc for all aggregates")
val junidoc = TaskKey[File]("junidoc", "Create unified javadoc for all aggregates")
val junidocAllSources = TaskKey[Seq[Seq[File]]]("junidoc-all-sources")
val junidocSources = TaskKey[Seq[File]]("junidoc-sources")
2011-07-08 10:20:10 +12:00
lazy val settings = Seq(
unidocDirectory <<= crossTarget / "unidoc",
unidocExclude := Seq.empty,
unidocAllSources <<= (thisProjectRef, buildStructure, unidocExclude) flatMap allSources(Compile),
2011-07-08 10:20:10 +12:00
unidocSources <<= unidocAllSources map { _.flatten },
unidocAllClasspaths <<= (thisProjectRef, buildStructure, unidocExclude) flatMap allClasspaths,
unidocClasspath <<= unidocAllClasspaths map { _.flatten.map(_.data).distinct },
junidocAllSources <<= (thisProjectRef, buildStructure, unidocExclude) flatMap allSources(JavaDoc),
junidocSources <<= junidocAllSources map { _.flatten },
sunidoc <<= sunidocTask,
junidoc <<= (doc in JavaDoc),
unidoc <<= (sunidoc, junidoc) map ((s, t) (s, t))
2011-07-08 10:20:10 +12:00
)
def allSources(conf: Configuration)(projectRef: ProjectRef, structure: Load.BuildStructure, exclude: Seq[String]): Task[Seq[Seq[File]]] = {
2011-07-08 10:20:10 +12:00
val projects = aggregated(projectRef, structure, exclude)
projects flatMap { sources in conf in LocalProject(_) get structure.data } join
2011-07-08 10:20:10 +12:00
}
def allClasspaths(projectRef: ProjectRef, structure: Load.BuildStructure, exclude: Seq[String]): Task[Seq[Classpath]] = {
val projects = aggregated(projectRef, structure, exclude)
projects flatMap { dependencyClasspath in Compile in LocalProject(_) get structure.data } join
}
def aggregated(projectRef: ProjectRef, structure: Load.BuildStructure, exclude: Seq[String]): Seq[String] = {
val aggregate = Project.getProject(projectRef, structure).toSeq.flatMap(_.aggregate)
aggregate flatMap { ref =>
if (exclude contains ref.project) Seq.empty
else ref.project +: aggregated(ref, structure, exclude)
}
}
def sunidocTask: Initialize[Task[File]] = {
2011-12-08 17:05:01 +13:00
(compilers, cacheDirectory, unidocSources, unidocClasspath, unidocDirectory, scalacOptions in doc, streams) map {
2011-07-08 10:20:10 +12:00
(compilers, cache, sources, classpath, target, options, s) => {
val scaladoc = new Scaladoc(100, compilers.scalac)
scaladoc.cached(cache / "unidoc", "main", sources, classpath, target, options, s.log)
target
}
}
}
}