From 43589a0a8c2a867e26575a46d17ffa27f123ecde Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Tue, 23 Nov 2021 20:43:01 -0800 Subject: [PATCH] Don't use unsupported -sourcepath flag for Scala 3 (#221) --- .../GithubActionsScaladocSourceUrl.scala | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/github-actions/src/main/scala/com/thoughtworks/sbtBestPractice/githubActions/GithubActionsScaladocSourceUrl.scala b/github-actions/src/main/scala/com/thoughtworks/sbtBestPractice/githubActions/GithubActionsScaladocSourceUrl.scala index dd1db01..521c338 100644 --- a/github-actions/src/main/scala/com/thoughtworks/sbtBestPractice/githubActions/GithubActionsScaladocSourceUrl.scala +++ b/github-actions/src/main/scala/com/thoughtworks/sbtBestPractice/githubActions/GithubActionsScaladocSourceUrl.scala @@ -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) <pop.atry@gmail.com> @@ -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()