Skip to content

Commit

Permalink
Don't use unsupported -sourcepath flag for Scala 3 (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry authored Nov 24, 2021
1 parent c5c6e0b commit 43589a0
Showing 1 changed file with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.thoughtworks.sbtBestPractice.git.{Git => GitPlugin}
import org.eclipse.jgit.lib.Constants
import sbt.Keys._
import sbt._
import Ordering.Implicits._

/** @author
* 杨博 (Yang Bo) <[email protected]>
Expand All @@ -16,16 +17,20 @@ object GithubActionsScaladocSourceUrl extends AutoPlugin {
override def projectSettings = Seq(
scalacOptions in Compile in doc := {
val originalScalacOptions = (scalacOptions in Compile in doc).value
GitPlugin.gitWorkTree.value match {
case Some(rootDirectory) =>
originalScalacOptions.indexOf("-sourcepath") match {
case -1 =>
originalScalacOptions ++ Seq("-sourcepath", rootDirectory.toString)
case i =>
originalScalacOptions.updated(i + 1, rootDirectory.toString)
}
case None =>
originalScalacOptions
if (VersionNumber(scalaVersion.value).numbers < Seq(3L)) {
GitPlugin.gitWorkTree.value match {
case Some(rootDirectory) =>
originalScalacOptions.indexOf("-sourcepath") match {
case -1 =>
originalScalacOptions ++ Seq("-sourcepath", rootDirectory.toString)
case i =>
originalScalacOptions.updated(i + 1, rootDirectory.toString)
}
case None =>
originalScalacOptions
}
} else {
originalScalacOptions
}
},
scalacOptions in Compile in doc := {
Expand All @@ -35,12 +40,17 @@ object GithubActionsScaladocSourceUrl extends AutoPlugin {
val repository = repositoryBuilder.build()
try {
val hash = repository.resolve(Constants.HEAD).name
val sourceUrl = raw"https://github.com/$slug/blob/${hash}€{FILE_PATH}.scala"
originalScalacOptions.indexOf("-doc-source-url") match {
case -1 =>
originalScalacOptions ++ Seq("-doc-source-url", sourceUrl)
case i =>
originalScalacOptions.updated(i + 1, sourceUrl)
if (VersionNumber(scalaVersion.value).numbers < Seq(3L)) {
val sourceUrl = raw"https://github.com/$slug/blob/${hash}€{FILE_PATH}.scala"
originalScalacOptions.indexOf("-doc-source-url") match {
case -1 =>
originalScalacOptions ++ Seq("-doc-source-url", sourceUrl)
case i =>
originalScalacOptions.updated(i + 1, sourceUrl)
}
} else {
val pathPrefix = GitPlugin.gitWorkTree.value.fold("")(_.toString())
originalScalacOptions :+ raw"-source-links:$pathPrefix:github://$slug/$hash"
}
} finally {
repository.close()
Expand Down

0 comments on commit 43589a0

Please sign in to comment.