Skip to content

Commit

Permalink
Merge pull request #9 from avdv/sbt-1.4-compat
Browse files Browse the repository at this point in the history
Support sbt version >= 1.4
  • Loading branch information
avdv authored Oct 16, 2020
2 parents c30cf11 + 57e957f commit b2f5a37
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enablePlugins(SbtPlugin)
scalaVersion in ThisBuild := "2.12.8"

// utest
libraryDependencies += "com.lihaoyi" %% "utest" % "0.7.4" % Test
libraryDependencies += "com.lihaoyi" %% "utest" % "0.7.5" % Test
testFrameworks += new TestFramework("utest.runner.Framework")

bintrayPackageLabels := Seq("sbt","plugin")
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.2.7
sbt.version=1.2.8
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.6")

addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.0.0")

Expand Down
28 changes: 24 additions & 4 deletions src/main/scala/sbthyperlink/HyperlinkPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import sbt.{ Def, _ }
import sbt.Keys._
import sbt.plugins.CorePlugin
import sbt.internal._
import sbt.internal.util.MainAppender._
import sbt.internal.util.MainAppender
import sbt.internal.util.ConsoleAppender

import scala.util.matching.Regex
Expand Down Expand Up @@ -84,10 +84,30 @@ object HyperlinkPlugin extends AutoPlugin {
hyperlinkRegex := Default.regex(baseDirectory.value),
hyperlinkAction := FileAction,
logManager := {
LogManager.withScreenLogger {
// we use internal sbt APIs, which are incompatible between < 1.4 and >= 1.4
// see https://github.com/sbt/sbt/issues/5931 and https://github.com/sbt/sbt/pull/5731
// work-around using reflection
import scala.reflect.runtime.{ universe => ru }

val mirror = ru.runtimeMirror(getClass.getClassLoader)
val mainAppenderType = mirror.typeOf[MainAppender.type]
val mainAppenderModuleSymbol = mainAppenderType.termSymbol.asModule
val mainAppender = mirror.reflect(mirror.reflectModule(mainAppenderModuleSymbol).instance)
val defaultScreenMethodSymbol =
mainAppenderType.decl(ru.TermName("defaultScreen")).asTerm.alternatives.collectFirst {
case m if m.asMethod.paramLists.foldLeft(0)(_ + _.size) == 1 => m.asMethod
}
val defaultScreen = mainAppender.reflectMethod(defaultScreenMethodSymbol.get)

val logManagerType = mirror.typeOf[LogManager.type]
val logManagerModuleSymbol = logManagerType.termSymbol.asModule
val logManager = mirror.reflect(mirror.reflectModule(logManagerModuleSymbol).instance)
val withScreenLoggerMethodSymbol = logManagerType.decl(ru.TermName("withScreenLogger")).asMethod
val withScreenLogger = logManager.reflectMethod(withScreenLoggerMethodSymbol)

withScreenLogger({
(_: ScopedKey[_], state: State)
val extracted = Project.extract(state)
val basedir = extracted.get(baseDirectory)
val action: HyperlinkAction = extracted.get(hyperlinkAction)
val regex: Regex = extracted.get(hyperlinkRegex)

Expand All @@ -100,7 +120,7 @@ object HyperlinkPlugin extends AutoPlugin {

override def print(s: String): Unit = super.print(filter(s))
}))
}
}).asInstanceOf[LogManager]
}
)
}

0 comments on commit b2f5a37

Please sign in to comment.