Merge pull request #1971 from vigdorchik/source_links

=pro #3852 scaladoc generation: add a link to source file on github.
This commit is contained in:
Patrik Nordwall 2014-02-03 02:43:34 -08:00
commit d58ed9b5d1
2 changed files with 24 additions and 14 deletions

View file

@ -786,6 +786,11 @@ object AkkaBuild extends Build {
val validatePullRequest = TaskKey[Unit]("validate-pull-request", "Additional tasks for pull request validation")
def githubUrl(v: String): String = {
val branch = if (v.endsWith("SNAPSHOT")) "master" else "v" + v
"http://github.com/akka/akka/tree/" + branch
}
// preprocessing settings for sphinx
lazy val sphinxPreprocessing = inConfig(Sphinx)(Seq(
target in preprocess <<= baseDirectory / "rst_preprocessed",
@ -793,7 +798,6 @@ object AkkaBuild extends Build {
// customization of sphinx @<key>@ replacements, add to all sphinx-using projects
// add additional replacements here
preprocessVars <<= (scalaVersion, version) { (s, v) =>
val isSnapshot = v.endsWith("SNAPSHOT")
val BinVer = """(\d+\.\d+)\.\d+""".r
Map(
"version" -> v,
@ -811,7 +815,7 @@ object AkkaBuild extends Build {
case _ => s
}),
"sigarVersion" -> Dependencies.Compile.sigar.revision,
"github" -> "http://github.com/akka/akka/tree/%s".format((if (isSnapshot) "master" else "v" + v))
"github" -> githubUrl(v)
)
},
preprocess <<= (sourceDirectory, target in preprocess, cacheDirectory, preprocessExts, preprocessVars, streams) map {
@ -888,7 +892,11 @@ object AkkaBuild extends Build {
lazy val scaladocDiagramsEnabled = System.getProperty("akka.scaladoc.diagrams", "false").toBoolean
lazy val scaladocAutoAPI = System.getProperty("akka.scaladoc.autoapi", "true").toBoolean
lazy val scaladocOptions = List("-implicits") ::: (if (scaladocDiagramsEnabled) List("-diagrams") else Nil)
def scaladocOptions(ver: String, base: File): List[String] = {
val urlString = githubUrl(ver) + "/€{FILE_PATH}.scala"
val opts = List("-implicits", "-doc-source-url", urlString, "-sourcepath", base.getAbsolutePath)
if (scaladocDiagramsEnabled) "-diagrams"::opts else opts
}
lazy val scaladocSettings: Seq[sbt.Setting[_]] = {
scaladocSettingsNoVerificationOfDiagrams ++
@ -896,18 +904,19 @@ object AkkaBuild extends Build {
}
// for projects with few (one) classes there might not be any diagrams
lazy val scaladocSettingsNoVerificationOfDiagrams: Seq[sbt.Setting[_]]= {
Seq(
scalacOptions in (Compile, doc) ++= scaladocOptions,
lazy val scaladocSettingsNoVerificationOfDiagrams: Seq[sbt.Setting[_]] = {
inTask(doc)(Seq(
scalacOptions in Compile <++= (version, baseDirectory in akka) map scaladocOptions,
autoAPIMappings := scaladocAutoAPI
)
))
}
lazy val unidocScaladocSettings: Seq[sbt.Setting[_]]= {
Seq(scalacOptions in doc ++= scaladocOptions) ++
(if (scaladocDiagramsEnabled)
Seq(sunidoc ~= scaladocVerifier)
else Seq.empty)
inTask(doc)(Seq(
scalacOptions <++= (version, baseDirectory in akka) map scaladocOptions,
autoAPIMappings := scaladocAutoAPI
)) ++
(if (scaladocDiagramsEnabled) Seq(sunidoc ~= scaladocVerifier) else Seq.empty)
}
def scaladocVerifier(file: File): File= {

View file

@ -68,10 +68,11 @@ object Unidoc {
}
def sunidocTask: Initialize[Task[File]] = {
(compilers, cacheDirectory, unidocSources, unidocClasspath, unidocDirectory, scalacOptions in doc, streams) map {
(compilers, cache, sources, classpath, target, options, s) => {
(compilers, cacheDirectory, unidocSources, unidocClasspath, unidocDirectory, scalacOptions in doc, apiMappings in (Compile, doc), streams) map {
(compilers, cache, sources, classpath, target, options, api, s) => {
val scaladoc = new Scaladoc(100, compilers.scalac)
scaladoc.cached(cache / "unidoc", "main", sources, classpath, target, options, s.log)
val opts1 = options ++ Opts.doc.externalAPI(api)
scaladoc.cached(cache / "unidoc", "main", sources, classpath, target, opts1, s.log)
target
}
}