2019-01-02 18:55:26 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
|
2015-05-21 09:48:49 +03:00
|
|
|
*/
|
2018-03-13 23:45:55 +09:00
|
|
|
|
2014-05-07 14:49:35 +02:00
|
|
|
package akka
|
|
|
|
|
|
|
|
|
|
import sbt._
|
2019-03-25 11:15:07 +01:00
|
|
|
import sbtunidoc.BaseUnidocPlugin.autoImport.{ unidoc, unidocAllSources, unidocProjectFilter }
|
2017-10-30 03:13:14 +02:00
|
|
|
import sbtunidoc.JavaUnidocPlugin.autoImport.JavaUnidoc
|
|
|
|
|
import sbtunidoc.ScalaUnidocPlugin.autoImport.ScalaUnidoc
|
2018-03-23 16:55:48 +01:00
|
|
|
import sbtunidoc.GenJavadocPlugin.autoImport._
|
2014-05-07 14:49:35 +02:00
|
|
|
import sbt.Keys._
|
|
|
|
|
import sbt.File
|
|
|
|
|
import scala.annotation.tailrec
|
|
|
|
|
|
2018-12-05 18:53:37 +01:00
|
|
|
import sbt.ScopeFilter.ProjectFilter
|
|
|
|
|
|
2015-05-21 09:48:49 +03:00
|
|
|
object Scaladoc extends AutoPlugin {
|
2014-05-07 14:49:35 +02:00
|
|
|
|
2015-05-21 09:48:49 +03:00
|
|
|
object CliOptions {
|
|
|
|
|
val scaladocDiagramsEnabled = CliOption("akka.scaladoc.diagrams", true)
|
|
|
|
|
val scaladocAutoAPI = CliOption("akka.scaladoc.autoapi", true)
|
2014-05-07 14:49:35 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-21 09:48:49 +03:00
|
|
|
override def trigger = allRequirements
|
|
|
|
|
override def requires = plugins.JvmPlugin
|
2014-05-07 14:49:35 +02:00
|
|
|
|
2015-05-21 09:48:49 +03:00
|
|
|
val validateDiagrams = settingKey[Boolean]("Validate generated scaladoc diagrams")
|
2014-05-07 14:49:35 +02:00
|
|
|
|
2015-05-21 09:48:49 +03:00
|
|
|
override lazy val projectSettings = {
|
2019-03-25 11:15:07 +01:00
|
|
|
inTask(doc)(
|
|
|
|
|
Seq(
|
|
|
|
|
scalacOptions in Compile ++= scaladocOptions(version.value, (baseDirectory in ThisBuild).value),
|
|
|
|
|
// -release caused build failures when generating javadoc:
|
|
|
|
|
scalacOptions in Compile --= Seq("-release", "8"),
|
|
|
|
|
autoAPIMappings := CliOptions.scaladocAutoAPI.get)) ++
|
|
|
|
|
Seq(validateDiagrams in Compile := true) ++
|
|
|
|
|
CliOptions.scaladocDiagramsEnabled.ifTrue(doc in Compile := {
|
|
|
|
|
val docs = (doc in Compile).value
|
|
|
|
|
if ((validateDiagrams in Compile).value)
|
|
|
|
|
scaladocVerifier(docs)
|
|
|
|
|
docs
|
|
|
|
|
})
|
2014-05-07 14:49:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def scaladocOptions(ver: String, base: File): List[String] = {
|
|
|
|
|
val urlString = GitHub.url(ver) + "/€{FILE_PATH}.scala"
|
2016-04-04 11:50:44 +02:00
|
|
|
val opts = List("-implicits", "-groups", "-doc-source-url", urlString, "-sourcepath", base.getAbsolutePath)
|
2015-05-21 09:48:49 +03:00
|
|
|
CliOptions.scaladocDiagramsEnabled.ifTrue("-diagrams").toList ::: opts
|
2014-05-07 14:49:35 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-06 10:30:28 +02:00
|
|
|
def scaladocVerifier(file: File): File = {
|
2014-05-07 14:49:35 +02:00
|
|
|
@tailrec
|
|
|
|
|
def findHTMLFileWithDiagram(dirs: Seq[File]): Boolean = {
|
|
|
|
|
if (dirs.isEmpty) false
|
|
|
|
|
else {
|
|
|
|
|
val curr = dirs.head
|
|
|
|
|
val (newDirs, files) = curr.listFiles.partition(_.isDirectory)
|
|
|
|
|
val rest = dirs.tail ++ newDirs
|
2019-03-25 11:15:07 +01:00
|
|
|
val hasDiagram = files.exists { f =>
|
2014-05-07 14:49:35 +02:00
|
|
|
val name = f.getName
|
|
|
|
|
if (name.endsWith(".html") && !name.startsWith("index-") &&
|
2019-03-25 11:15:07 +01:00
|
|
|
!name.equals("index.html") && !name.equals("package.html")) {
|
2014-08-05 12:01:56 +02:00
|
|
|
val source = scala.io.Source.fromFile(f)(scala.io.Codec.UTF8)
|
2019-03-25 11:15:07 +01:00
|
|
|
val hd = try source
|
|
|
|
|
.getLines()
|
|
|
|
|
.exists(
|
|
|
|
|
lines =>
|
|
|
|
|
lines.contains(
|
|
|
|
|
"<div class=\"toggleContainer block diagram-container\" id=\"inheritance-diagram-container\">") ||
|
|
|
|
|
lines.contains("<svg id=\"graph"))
|
2014-08-05 12:01:56 +02:00
|
|
|
catch {
|
2019-03-25 11:15:07 +01:00
|
|
|
case e: Exception =>
|
|
|
|
|
throw new IllegalStateException("Scaladoc verification failed for file '" + f + "'", e)
|
2014-08-05 12:01:56 +02:00
|
|
|
} finally source.close()
|
2014-05-07 14:49:35 +02:00
|
|
|
hd
|
2017-10-06 10:30:28 +02:00
|
|
|
} else false
|
2014-05-07 14:49:35 +02:00
|
|
|
}
|
|
|
|
|
hasDiagram || findHTMLFileWithDiagram(rest)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we have generated scaladoc and none of the files have a diagram then fail
|
|
|
|
|
if (file.exists() && !findHTMLFileWithDiagram(List(file)))
|
|
|
|
|
sys.error("ScalaDoc diagrams not generated!")
|
|
|
|
|
else
|
|
|
|
|
file
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-21 09:48:49 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For projects with few (one) classes there might not be any diagrams.
|
|
|
|
|
*/
|
|
|
|
|
object ScaladocNoVerificationOfDiagrams extends AutoPlugin {
|
|
|
|
|
|
|
|
|
|
override def trigger = noTrigger
|
|
|
|
|
override def requires = Scaladoc
|
|
|
|
|
|
2019-03-25 11:15:07 +01:00
|
|
|
override lazy val projectSettings = Seq(Scaladoc.validateDiagrams in Compile := false)
|
2015-05-21 09:48:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unidoc settings for root project. Adds unidoc command.
|
|
|
|
|
*/
|
|
|
|
|
object UnidocRoot extends AutoPlugin {
|
|
|
|
|
|
|
|
|
|
object CliOptions {
|
|
|
|
|
val genjavadocEnabled = CliOption("akka.genjavadoc.enabled", false)
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 15:55:14 +02:00
|
|
|
object autoImport {
|
2018-12-05 18:53:37 +01:00
|
|
|
val unidocRootIgnoreProjects = settingKey[Seq[ProjectReference]]("Projects to ignore when generating unidoc")
|
2017-05-20 15:55:14 +02:00
|
|
|
}
|
|
|
|
|
import autoImport._
|
|
|
|
|
|
2015-05-21 09:48:49 +03:00
|
|
|
override def trigger = noTrigger
|
2017-10-30 03:13:14 +02:00
|
|
|
override def requires =
|
2019-03-25 11:15:07 +01:00
|
|
|
UnidocRoot.CliOptions.genjavadocEnabled
|
|
|
|
|
.ifTrue(sbtunidoc.ScalaUnidocPlugin && sbtunidoc.JavaUnidocPlugin && sbtunidoc.GenJavadocPlugin)
|
2017-10-30 03:13:14 +02:00
|
|
|
.getOrElse(sbtunidoc.ScalaUnidocPlugin)
|
2015-05-21 09:48:49 +03:00
|
|
|
|
2019-03-25 11:15:07 +01:00
|
|
|
val akkaSettings = UnidocRoot.CliOptions.genjavadocEnabled
|
|
|
|
|
.ifTrue(
|
|
|
|
|
Seq(
|
|
|
|
|
javacOptions in (JavaUnidoc, unidoc) := Seq(
|
|
|
|
|
"-Xdoclint:none",
|
|
|
|
|
"--frames",
|
|
|
|
|
"--ignore-source-errors",
|
|
|
|
|
"--no-module-directories")))
|
|
|
|
|
.getOrElse(Nil)
|
2016-01-13 12:00:46 +01:00
|
|
|
|
2017-10-30 03:13:14 +02:00
|
|
|
override lazy val projectSettings = {
|
2019-03-25 11:15:07 +01:00
|
|
|
def unidocRootProjectFilter(ignoreProjects: Seq[ProjectReference]): ProjectFilter =
|
2017-05-26 14:09:07 +02:00
|
|
|
ignoreProjects.foldLeft(inAnyProject) { _ -- inProjects(_) }
|
|
|
|
|
|
2019-03-25 11:15:07 +01:00
|
|
|
inTask(unidoc)(
|
|
|
|
|
Seq(
|
|
|
|
|
unidocProjectFilter in ScalaUnidoc := unidocRootProjectFilter(unidocRootIgnoreProjects.value),
|
|
|
|
|
unidocProjectFilter in JavaUnidoc := unidocRootProjectFilter(unidocRootIgnoreProjects.value),
|
|
|
|
|
apiMappings in ScalaUnidoc := (apiMappings in (Compile, doc)).value) ++
|
|
|
|
|
UnidocRoot.CliOptions.genjavadocEnabled
|
|
|
|
|
.ifTrue(
|
|
|
|
|
Seq(
|
|
|
|
|
// akka.stream.scaladsl.GraphDSL.Implicits.ReversePortsOps contains code that
|
|
|
|
|
// genjavadoc turns into (probably incorrect) Java code that in turn confuses the javadoc tool.
|
|
|
|
|
unidocAllSources in JavaUnidoc ~= { v =>
|
|
|
|
|
v.map(_.filterNot(_.getAbsolutePath.endsWith("scaladsl/GraphDSL.java")))
|
|
|
|
|
}))
|
|
|
|
|
.getOrElse(Nil))
|
2015-05-21 09:48:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unidoc settings for every multi-project. Adds genjavadoc specific settings.
|
|
|
|
|
*/
|
2017-10-30 03:13:14 +02:00
|
|
|
object BootstrapGenjavadoc extends AutoPlugin {
|
2015-05-21 09:48:49 +03:00
|
|
|
|
|
|
|
|
override def trigger = allRequirements
|
2019-03-25 11:15:07 +01:00
|
|
|
override def requires =
|
|
|
|
|
UnidocRoot.CliOptions.genjavadocEnabled
|
|
|
|
|
.ifTrue {
|
|
|
|
|
val onJdk8 = System.getProperty("java.version").startsWith("1.")
|
|
|
|
|
require(!onJdk8, "Javadoc generation requires at least jdk 11")
|
|
|
|
|
sbtunidoc.GenJavadocPlugin
|
|
|
|
|
}
|
|
|
|
|
.getOrElse(plugins.JvmPlugin)
|
2015-05-21 09:48:49 +03:00
|
|
|
|
2019-03-25 11:15:07 +01:00
|
|
|
override lazy val projectSettings = UnidocRoot.CliOptions.genjavadocEnabled
|
|
|
|
|
.ifTrue(Seq(
|
2019-03-19 15:16:59 +01:00
|
|
|
unidocGenjavadocVersion := "0.12",
|
2019-03-25 11:15:07 +01:00
|
|
|
scalacOptions in Compile ++= Seq("-P:genjavadoc:fabricateParams=true", "-P:genjavadoc:suppressSynthetic=false")))
|
|
|
|
|
.getOrElse(Nil)
|
2015-05-21 09:48:49 +03:00
|
|
|
}
|