forked from dwhjames/aws-wrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaladoc.sbt
42 lines (30 loc) · 1.49 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
import scala.util.matching.Regex.Match
scalacOptions in (Compile, doc) ++=
Seq(
"-sourcepath", baseDirectory.value.getAbsolutePath,
"-doc-source-url", s"https://github.com/dwhjames/aws-wrap/tree/v${version.value}€{FILE_PATH}.scala")
autoAPIMappings := true
apiURL := Some(url("https://dwhjames.github.io/aws-wrap/api/current/"))
apiMappings += {
val jarFiles = (managedClasspath in Compile).value.files
val datomicJarFile = jarFiles.find(file => file.toString.contains("com.amazonaws/aws-java-sdk")).get
(datomicJarFile -> url("http://docs.aws.amazon.com/AWSJavaSDK/latest/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 (Compile, doc)).value
(t ** "*.html").get.filter(hasJavadocApiLink).foreach { f =>
log.info("Transforming " + f)
val newContent = javadocApiLink.replaceAllIn(IO.read(f), transformJavaDocLinks)
IO.write(f, newContent)
}
}
val transformJavaDocLinks: Match => String = m =>
"href=\"" + m.group(1) + "?" + m.group(2).replace(".", "/") + ".html"
val javadocApiLink = """href=\"(http://docs\.aws\.amazon\.com/AWSJavaSDK/latest/javadoc/index\.html)#([^"]*)""".r
def hasJavadocApiLink(f: File): Boolean = (javadocApiLink findFirstIn IO.read(f)).nonEmpty
transformJavaDocLinksTask <<= transformJavaDocLinksTask triggeredBy (doc in Compile)