-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use unsupported -sourcepath flag for Scala 3 (#221)
- Loading branch information
Showing
1 changed file
with
26 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
|
@@ -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 := { | ||
|
@@ -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() | ||
|