-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathUnidoc.scala
80 lines (69 loc) · 3.93 KB
/
Unidoc.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package akka
import sbt._
import sbt.Keys._
import sbt.Project.Initialize
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)
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")
lazy val settings = Seq(
unidocDirectory <<= crossTarget / "unidoc",
unidocExclude := Seq.empty,
unidocAllSources <<= (thisProjectRef, buildStructure, unidocExclude) flatMap allSources(Compile),
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))
)
def allSources(conf: Configuration)(projectRef: ProjectRef, structure: Load.BuildStructure, exclude: Seq[String]): Task[Seq[Seq[File]]] = {
val projects = aggregated(projectRef, structure, exclude)
projects flatMap { sources in conf in LocalProject(_) get structure.data } join
}
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]] = {
(compilers, cacheDirectory, unidocSources, unidocClasspath, unidocDirectory, scalacOptions in doc, streams) map {
(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
}
}
}
}