2019-01-02 18:55:26 +08:00
|
|
|
/*
|
2021-01-08 17:55:38 +01:00
|
|
|
* Copyright (C) 2009-2021 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
|
2020-04-28 11:49:42 +02:00
|
|
|
import com.lightbend.sbt.publishrsync.PublishRsyncPlugin.autoImport.publishRsyncArtifacts
|
2014-05-07 14:49:35 +02:00
|
|
|
|
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
|
2020-04-01 12:26:05 +02:00
|
|
|
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(
|
2021-05-25 12:50:51 +02:00
|
|
|
Compile / scalacOptions ++= scaladocOptions(version.value, (ThisBuild / baseDirectory).value),
|
2019-03-25 11:15:07 +01:00
|
|
|
// -release caused build failures when generating javadoc:
|
2021-05-25 12:50:51 +02:00
|
|
|
Compile / scalacOptions --= Seq("-release", "8"),
|
2019-03-25 11:15:07 +01:00
|
|
|
autoAPIMappings := CliOptions.scaladocAutoAPI.get)) ++
|
2021-10-25 08:18:22 +02:00
|
|
|
Seq(
|
|
|
|
|
// Publishing scala3 docs is broken (https://github.com/akka/akka/issues/30788),
|
|
|
|
|
// for now we just skip it:
|
|
|
|
|
Compile / doc / sources := (
|
|
|
|
|
if (scalaVersion.value.startsWith("3.")) Seq()
|
|
|
|
|
else (Compile / doc / sources).value
|
|
|
|
|
),
|
|
|
|
|
Compile / validateDiagrams := true) ++
|
2021-05-25 12:50:51 +02:00
|
|
|
CliOptions.scaladocDiagramsEnabled.ifTrue(Compile / doc := {
|
|
|
|
|
val docs = (Compile / doc).value
|
|
|
|
|
if ((Compile / validateDiagrams).value)
|
2019-03-25 11:15:07 +01:00
|
|
|
scaladocVerifier(docs)
|
|
|
|
|
docs
|
|
|
|
|
})
|
2014-05-07 14:49:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def scaladocOptions(ver: String, base: File): List[String] = {
|
2019-08-27 11:02:15 +02:00
|
|
|
val urlString = GitHub.url(ver) + "/€{FILE_PATH_EXT}#L€{FILE_LINE}"
|
2019-04-16 00:10:42 -07:00
|
|
|
val opts = List(
|
|
|
|
|
"-implicits",
|
|
|
|
|
"-groups",
|
|
|
|
|
"-doc-source-url",
|
|
|
|
|
urlString,
|
|
|
|
|
"-sourcepath",
|
|
|
|
|
base.getAbsolutePath,
|
|
|
|
|
"-doc-title",
|
|
|
|
|
"Akka",
|
|
|
|
|
"-doc-version",
|
2019-08-27 11:02:15 +02:00
|
|
|
ver,
|
|
|
|
|
"-doc-canonical-base-url",
|
2019-12-03 09:16:05 +01:00
|
|
|
"https://doc.akka.io/api/akka/current/")
|
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
|
|
|
|
|
|
2021-05-25 12:50:51 +02:00
|
|
|
override lazy val projectSettings = Seq(Compile / Scaladoc.validateDiagrams := 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
|
2020-03-30 16:48:15 +02:00
|
|
|
.ifTrue(Seq(
|
2021-05-25 12:50:51 +02:00
|
|
|
JavaUnidoc / unidoc / javacOptions := {
|
2020-03-30 16:48:15 +02:00
|
|
|
if (JdkOptions.isJdk8) Seq("-Xdoclint:none")
|
|
|
|
|
else Seq("-Xdoclint:none", "--ignore-source-errors", "--no-module-directories")
|
|
|
|
|
},
|
2020-04-28 11:49:42 +02:00
|
|
|
publishRsyncArtifacts ++= {
|
2020-03-30 16:48:15 +02:00
|
|
|
val releaseVersion = if (isSnapshot.value) "snapshot" else version.value
|
|
|
|
|
(Compile / unidoc).value match {
|
|
|
|
|
case Seq(japi, api) =>
|
2020-04-27 15:27:14 +02:00
|
|
|
Seq((japi -> s"www/japi/akka/$releaseVersion"), (api -> s"www/api/akka/$releaseVersion"))
|
2020-03-30 16:48:15 +02:00
|
|
|
}
|
2020-04-27 15:27:14 +02:00
|
|
|
}))
|
2019-03-25 11:15:07 +01:00
|
|
|
.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(
|
2021-05-25 12:50:51 +02:00
|
|
|
ScalaUnidoc / unidocProjectFilter := unidocRootProjectFilter(unidocRootIgnoreProjects.value),
|
|
|
|
|
JavaUnidoc / unidocProjectFilter := unidocRootProjectFilter(unidocRootIgnoreProjects.value),
|
|
|
|
|
ScalaUnidoc / apiMappings := (Compile / doc / apiMappings).value) ++
|
2019-03-25 11:15:07 +01:00
|
|
|
UnidocRoot.CliOptions.genjavadocEnabled
|
2021-08-02 19:27:03 +02:00
|
|
|
.ifTrue(Seq(JavaUnidoc / unidocAllSources ~= { v =>
|
|
|
|
|
v.map(
|
|
|
|
|
_.filterNot(
|
|
|
|
|
s =>
|
|
|
|
|
// akka.stream.scaladsl.GraphDSL.Implicits.ReversePortsOps
|
|
|
|
|
// contains code that genjavadoc turns into (probably
|
|
|
|
|
// incorrect) Java code that in turn confuses the javadoc
|
|
|
|
|
// tool.
|
|
|
|
|
s.getAbsolutePath.endsWith("scaladsl/GraphDSL.java") ||
|
|
|
|
|
// Since adding -P:genjavadoc:strictVisibility=true,
|
|
|
|
|
// the javadoc tool would NullPointerException while
|
|
|
|
|
// determining the upper bound for some generics:
|
|
|
|
|
s.getAbsolutePath.endsWith("TopicImpl.java") ||
|
|
|
|
|
s.getAbsolutePath.endsWith("PersistencePlugin.java") ||
|
|
|
|
|
s.getAbsolutePath.endsWith("GraphDelegate.java") ||
|
|
|
|
|
s.getAbsolutePath.contains("/impl/")))
|
|
|
|
|
}))
|
2019-03-25 11:15:07 +01:00
|
|
|
.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 {
|
2019-04-16 00:10:42 -07:00
|
|
|
// require 11, fail fast for 8, 9, 10
|
2019-10-03 05:02:40 +02:00
|
|
|
require(JdkOptions.isJdk11orHigher, "Javadoc generation requires at least jdk 11")
|
2019-03-25 11:15:07 +01:00
|
|
|
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(
|
2021-07-20 11:08:47 +02:00
|
|
|
unidocGenjavadocVersion := "0.18",
|
2021-08-02 19:27:03 +02:00
|
|
|
Compile / scalacOptions ++= Seq(
|
|
|
|
|
"-P:genjavadoc:fabricateParams=false",
|
|
|
|
|
"-P:genjavadoc:suppressSynthetic=false",
|
|
|
|
|
"-P:genjavadoc:strictVisibility=true")))
|
2019-03-25 11:15:07 +01:00
|
|
|
.getOrElse(Nil)
|
2015-05-21 09:48:49 +03:00
|
|
|
}
|