2023-01-08 17:13:31 +08:00
|
|
|
/*
|
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* license agreements; and to You under the Apache License, version 2.0:
|
|
|
|
|
*
|
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
2023-06-22 14:19:26 +01:00
|
|
|
* This file is part of the Apache Pekko project, which was derived from Akka.
|
2023-01-08 17:13:31 +08:00
|
|
|
*/
|
|
|
|
|
|
2019-01-02 18:55:26 +08:00
|
|
|
/*
|
2022-02-04 12:36:44 +01:00
|
|
|
* Copyright (C) 2009-2022 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
|
|
|
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 {
|
2024-01-22 07:15:16 +01:00
|
|
|
lazy val scaladocDiagramsEnabled = CliOption("pekko.scaladoc.diagrams", true)
|
|
|
|
|
lazy val scaladocAutoAPI = CliOption("pekko.scaladoc.autoapi", true)
|
2014-05-07 14:49:35 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-22 07:15:16 +01:00
|
|
|
override lazy val trigger = allRequirements
|
|
|
|
|
override lazy val 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)) ++
|
2023-06-13 19:43:50 +02:00
|
|
|
Seq(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",
|
2023-01-31 12:26:50 +01:00
|
|
|
"Apache Pekko",
|
2019-04-16 00:10:42 -07:00
|
|
|
"-doc-version",
|
2019-08-27 11:02:15 +02:00
|
|
|
ver,
|
|
|
|
|
"-doc-canonical-base-url",
|
2023-01-31 12:26:50 +01:00
|
|
|
"https://pekko.apache.org/api/pekko/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 {
|
|
|
|
|
|
2024-01-22 07:15:16 +01:00
|
|
|
override lazy val trigger = noTrigger
|
|
|
|
|
override lazy val requires = Scaladoc
|
2015-05-21 09:48:49 +03:00
|
|
|
|
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 {
|
2024-01-22 07:15:16 +01:00
|
|
|
lazy val genjavadocEnabled = CliOption("pekko.genjavadoc.enabled", false)
|
2015-05-21 09:48:49 +03:00
|
|
|
}
|
|
|
|
|
|
2017-05-20 15:55:14 +02:00
|
|
|
object autoImport {
|
2024-01-22 07:15:16 +01:00
|
|
|
lazy val unidocRootIgnoreProjects = settingKey[Seq[ProjectReference]]("Projects to ignore when generating unidoc")
|
2017-05-20 15:55:14 +02:00
|
|
|
}
|
|
|
|
|
import autoImport._
|
|
|
|
|
|
2024-01-22 07:15:16 +01:00
|
|
|
override lazy val trigger = noTrigger
|
|
|
|
|
override lazy val 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
|
|
|
|
2024-01-22 07:15:16 +01:00
|
|
|
lazy val pekkoSettings = UnidocRoot.CliOptions.genjavadocEnabled
|
2020-03-30 16:48:15 +02:00
|
|
|
.ifTrue(Seq(
|
2025-07-30 13:34:30 +01:00
|
|
|
JavaUnidoc / unidoc / javacOptions :=
|
|
|
|
|
Seq("-Xdoclint:none", "--ignore-source-errors", "--no-module-directories")
|
|
|
|
|
))
|
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),
|
2023-07-10 22:19:11 +09:00
|
|
|
Compile / doc / apiMappings ++= {
|
2023-09-24 03:08:15 +09:00
|
|
|
val entries: Seq[Attributed[File]] =
|
|
|
|
|
(LocalProject("slf4j") / Compile / fullClasspath).value ++
|
|
|
|
|
(LocalProject("persistence") / Compile / fullClasspath).value ++
|
|
|
|
|
(LocalProject("remote") / Compile / fullClasspath).value ++
|
|
|
|
|
(LocalProject("stream") / Compile / fullClasspath).value
|
2023-07-10 22:19:11 +09:00
|
|
|
|
|
|
|
|
def mappingsFor(organization: String, names: List[String], location: String,
|
|
|
|
|
revision: String => String = identity): Seq[(File, URL)] = {
|
|
|
|
|
for {
|
|
|
|
|
entry: Attributed[File] <- entries
|
|
|
|
|
module: ModuleID <- entry.get(moduleID.key)
|
|
|
|
|
if module.organization == organization
|
|
|
|
|
if names.exists(module.name.startsWith)
|
|
|
|
|
} yield entry.data -> url(location.format(module.revision))
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-24 03:08:15 +09:00
|
|
|
val mappings: Seq[(File, URL)] = {
|
|
|
|
|
mappingsFor("org.slf4j", List("slf4j-api"), "https://www.javadoc.io/doc/org.slf4j/slf4j-api/%s/") ++
|
|
|
|
|
mappingsFor("com.typesafe", List("config"), "https://www.javadoc.io/doc/com.typesafe/config/%s/") ++
|
|
|
|
|
mappingsFor("io.aeron", List("aeron-client", "aeron-driver"),
|
|
|
|
|
"https://www.javadoc.io/doc/io.aeron/aeron-all/%s/") ++
|
|
|
|
|
mappingsFor("org.reactivestreams", List("reactive-streams"),
|
|
|
|
|
"https://www.javadoc.io/doc/org.reactivestreams/reactive-streams/%s/")
|
|
|
|
|
}
|
2023-07-10 22:19:11 +09:00
|
|
|
|
|
|
|
|
mappings.toMap
|
|
|
|
|
},
|
2021-05-25 12:50:51 +02:00
|
|
|
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 =>
|
2023-02-22 12:48:15 +01:00
|
|
|
// org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.ReversePortsOps
|
2021-08-02 19:27:03 +02:00
|
|
|
// 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
|
|
|
|
2024-01-22 07:15:16 +01:00
|
|
|
override lazy val trigger = allRequirements
|
2023-09-24 03:08:15 +09:00
|
|
|
|
2024-01-22 07:15:16 +01:00
|
|
|
override lazy val requires =
|
2019-03-25 11:15:07 +01:00
|
|
|
UnidocRoot.CliOptions.genjavadocEnabled
|
|
|
|
|
.ifTrue {
|
|
|
|
|
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(
|
2024-03-03 09:16:54 +01:00
|
|
|
unidocGenjavadocVersion := "0.19",
|
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
|
|
|
}
|