-
Notifications
You must be signed in to change notification settings - Fork 26
/
scaladoc.sbt
54 lines (40 loc) · 1.79 KB
/
scaladoc.sbt
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
import sbtunidoc.Plugin._
import sbtunidoc.Plugin.UnidocKeys._
import scala.util.matching.Regex.Match
// substitue unidoc as the way to generate documentation
unidocSettings
packageDoc in Compile <<= packageDoc in ScalaUnidoc
artifact in (ScalaUnidoc, packageDoc) := {
val previous: Artifact = (artifact in (ScalaUnidoc, packageDoc)).value
previous.copy(classifier = Some("javadoc"))
}
scalacOptions in (Compile, doc) ++=
Seq(
"-implicits",
"-sourcepath", baseDirectory.value.getAbsolutePath,
"-doc-source-url", s"https://github.com/dwhjames/datomisca/tree/v${version.value}€{FILE_PATH}.scala")
autoAPIMappings := true
apiURL := Some(url("https://dwhjames.github.io/datomisca/api/current/"))
apiMappings += {
val jarFiles = (dependencyClasspath in Compile).value.files
def findJarFile(s: String) = jarFiles.find(file => file.toString.contains(s)).get
val datomicJarFile = findJarFile("com.datomic/datomic-free")
(datomicJarFile -> url("http://docs.datomic.com/javadoc/"))
}
lazy val transformJavaDocLinksTask = taskKey[Unit](
"Transform JavaDoc links - replace #java.io.File with ?java/io/File.html"
)
transformJavaDocLinksTask := {
val log = streams.value.log
log.info("Transforming JavaDoc links")
val t = (target in unidoc).value
(t ** "*.html").get.filter(hasJavadocApiLink).foreach { f =>
log.info("Transforming " + f)
val newContent = javadocApiLink.replaceAllIn(IO.read(f), m =>
"href=\"" + m.group(1) + "?" + m.group(2).replace(".", "/") + ".html")
IO.write(f, newContent)
}
}
val javadocApiLink = """href=\"(http://docs\.datomic\.com/javadoc/index\.html)#([^"]*)""".r
def hasJavadocApiLink(f: File): Boolean = (javadocApiLink findFirstIn IO.read(f)).nonEmpty
transformJavaDocLinksTask <<= transformJavaDocLinksTask triggeredBy (unidoc in Compile)