Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Support Java API doc Scaladoc/Unidoc References #1420

Merged
merged 4 commits into from
Mar 23, 2020
Merged

Conversation

seldridge
Copy link
Member

@seldridge seldridge commented Mar 3, 2020

This enables automatic Scaladoc linking to Java API docs using the same strategy that Scala upstream uses.

Linking to Scala API documentation already works.

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?

Type of Improvement

  • documentation

API Impact

None.

Backend Code Generation Impact

None.

Desired Merge Strategy

  • Squash: The PR will be squashed and merged (choose this if you have no preference.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (1.2.x, 1.3.0, 1.4.0) ?
  • Did you review?
  • Did you mark as Please Merge?

@seldridge seldridge added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Mar 3, 2020
@seldridge seldridge added this to the 1.2.X milestone Mar 3, 2020
@seldridge seldridge requested a review from a team as a code owner March 3, 2020 18:01
Copy link
Contributor

@chick chick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty simple. Can anything go wrong here?

@seldridge
Copy link
Member Author

I have no earthly idea why this isn't building on Travis... 🤷‍♀️ This works locally with a clean clone and a nuked ~/.ivy2.

@ucbjrl
Copy link
Contributor

ucbjrl commented Mar 3, 2020

It looks like the plugin has been compiled for Java 8 and won't work with Java 11 or 13.

@seldridge
Copy link
Member Author

Ugh, thanks Jim. Scala does something different for linking to Java API docs. I can at least add that.

@ucbjrl
Copy link
Contributor

ucbjrl commented Mar 4, 2020

The incompatibility doesn't appear to be fundamental in nature. If you generate a full log, you get:

[error] scala.MatchError: 11 (of class java.lang.String)
[error] 	at com.thoughtworks.sbtApiMappings.BootstrapApiMappings$.$anonfun$globalSettings$1(BootstrapApiMappings.scala:28)
[error] 	at sbt.internal.util.Init$Value.$anonfun$apply$3(Settings.scala:823)

and the code at that location is:

  private[sbtApiMappings] def defaultBootstrapJavadocUrl = {
    val javaVersion = sys.props("java.specification.version") match {
->      case VersionNumber(Seq(1, javaVersion, _*), _, _) => javaVersion // 1.6-1.8
        case VersionNumber(Seq(javaVersion, _*),    _, _) => javaVersion // 9+
        case _ =>                                            8
    }
    if (javaVersion >= 11) {
      url(s"https://docs.oracle.com/en/java/javase/${javaVersion}/docs/api/index.html")
    } else {
      url(s"https://docs.oracle.com/javase/${javaVersion}/docs/api/index.html")
    }
  }

java.specification.version for post Java 9 has changed. See https://stackoverflow.com/questions/5103121/how-to-find-the-jvm-version-from-a-program

This adds a build.sbt apiMappings to allow for Scaladoc/Unidoc linking
to Java API documentation. This uses the exact strategy that Scala
upstream uses for linking.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
@seldridge seldridge changed the title Add sbt-api-mappings plugin Support Java API doc Scaladoc/Unidoc References Mar 23, 2020
@seldridge
Copy link
Member Author

I switched this to not use the sbt-api-mappings plugin to avoid the issue that @ucbjrl found (also that plugin is sparsely updated making me nervous). Instead, this uses the same strategy that Scala uses to link against Java API documentation. The small example included works for unidoc.

Copy link
Contributor

@chick chick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mergify mergify bot merged commit bdac6e1 into master Mar 23, 2020
mergify bot pushed a commit that referenced this pull request Mar 23, 2020
* Link to Java API Documentation

This adds a build.sbt apiMappings to allow for Scaladoc/Unidoc linking
to Java API documentation. This uses the exact strategy that Scala
upstream uses for linking.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>

* Add example of Java and Scala API docs linking

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit bdac6e1)

# Conflicts:
#	build.sbt
@mergify mergify bot added the Backported This PR has been backported to marked stable branch label Mar 23, 2020
seldridge added a commit that referenced this pull request Mar 24, 2020
Manually back-ported.

* Link to Java API Documentation

This adds a build.sbt apiMappings to allow for Scaladoc/Unidoc linking
to Java API documentation. This uses the exact strategy that Scala
upstream uses for linking.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>

* Add example of Java and Scala API docs linking

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit bdac6e1)
seldridge added a commit that referenced this pull request Mar 24, 2020
Manually back-ported.

* Link to Java API Documentation

This adds a build.sbt apiMappings to allow for Scaladoc/Unidoc linking
to Java API documentation. This uses the exact strategy that Scala
upstream uses for linking.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>

* Add example of Java and Scala API docs linking

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit bdac6e1)

Co-authored-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
@jackkoenig jackkoenig deleted the sbt-api-mappings branch March 26, 2021 23:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Backported This PR has been backported to marked stable branch Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants