Skip to content

Commit

Permalink
Fixes playframework#208 - Support sbt 1.4.x+
Browse files Browse the repository at this point in the history
sbt 1.4.x introduces a breaking changes to how plugins can hook
into the compiler as well as some API changes for stamping files
so that the incremental compiler can recognize modifications

This pull requests updates sbt-play-ebean to account for those
changes with respect to ebean enhancement.
  • Loading branch information
jmswenski committed May 21, 2021
1 parent 58b3652 commit 7ac90ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sbt.Append.appendSeq
import xsbti.compile.CompileAnalysis

// Customise sbt-dynver's behaviour to make it work with tags which aren't v-prefixed
dynverVTagPrefix in ThisBuild := false
ThisBuild / dynverVTagPrefix := false

// Sanity-check: assert that version comes from a tag (e.g. not a too-shallow clone)
// https://github.com/dwijnand/sbt-dynver/#sanity-checking-the-version
Expand Down Expand Up @@ -42,10 +42,10 @@ lazy val core = project
crossScalaVersions := Seq(scala212, scala213),
Dependencies.ebean,
mimaSettings,
compile in Compile := enhanceEbeanClasses(
(dependencyClasspath in Compile).value,
(compile in Compile).value,
(classDirectory in Compile).value,
Compile / compile := enhanceEbeanClasses(
(Compile / dependencyClasspath).value,
(Compile / compile).value,
(Compile / classDirectory).value,
"play/db/ebean/**"
),
jacocoReportSettings := JacocoReportSettings("Jacoco Coverage Report", None, JacocoThresholds(), Seq(JacocoReportFormats.XML), "utf-8")
Expand All @@ -61,10 +61,10 @@ lazy val plugin = project
Dependencies.plugin,
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % Versions.play),
crossScalaVersions := Seq(scala212),
resourceGenerators in Compile += generateVersionFile.taskValue,
Compile / resourceGenerators += generateVersionFile.taskValue,
scriptedLaunchOpts ++= Seq(
s"-Dscala.version=${scalaVersion.value}",
s"-Dscala.crossVersions=${(crossScalaVersions in core).value.mkString(",")}",
s"-Dscala.crossVersions=${(core / crossScalaVersions).value.mkString(",")}",
s"-Dproject.version=${version.value}",
),
scriptedBufferLog := false,
Expand All @@ -90,8 +90,8 @@ def enhanceEbeanClasses(classpath: Classpath, analysis: CompileAnalysis, classDi

// Version file
def generateVersionFile = Def.task {
val version = (Keys.version in core).value
val file = (resourceManaged in Compile).value / "play-ebean.version.properties"
val version = (core / Keys.version).value
val file = (Compile / resourceManaged).value / "play-ebean.version.properties"
val content = s"play-ebean.version=$version"
IO.write(file, content)
Seq(file)
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Copyright (C) Lightbend Inc. <https://www.lightbend.com>
#

sbt.version=1.3.10
sbt.version=1.4.9
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import java.net.URLClassLoader
import io.ebean.enhance.Transformer
import io.ebean.enhance.ant.OfflineFileTransform
import sbt.Keys._
import sbt.internal.inc.Hash
import sbt.internal.inc.LastModified
import sbt.internal.inc.Stamper
import sbt.internal.inc.{FarmHash, LastModified, PlainVirtualFileConverter, Stamper}
import sbt.AutoPlugin
import sbt.Compile
import sbt.Def
Expand All @@ -17,7 +15,7 @@ import sbt.taskKey
import xsbti.compile.CompileResult
import xsbti.compile.analysis.Stamp
import sbt._

import xsbti.VirtualFileRef
import scala.util.control.NonFatal

object PlayEbean extends AutoPlugin {
Expand Down Expand Up @@ -67,7 +65,6 @@ object PlayEbean extends AutoPlugin {
val result = manipulateBytecode.value
val agentArgs = playEbeanAgentArgs.value
val analysis = result.analysis.asInstanceOf[sbt.internal.inc.Analysis]

val agentArgsString = agentArgs.map { case (key, value) => s"$key=$value" }.mkString(";")

val originalContextClassLoader = Thread.currentThread.getContextClassLoader
Expand Down Expand Up @@ -95,16 +92,16 @@ object PlayEbean extends AutoPlugin {
}

val allProducts = analysis.relations.allProducts

val converter = new PlainVirtualFileConverter()
/**
* Updates stamp of product (class file) by preserving the type of a passed stamp.
* This way any stamp incremental compiler chooses to use to mark class files will
* be supported.
*/
def updateStampForClassFile(file: File, stamp: Stamp): Stamp =
def updateStampForClassFile(fileRef: VirtualFileRef, stamp: Stamp): Stamp =
stamp match {
case _: LastModified => Stamper.forLastModified(file)
case _: Hash => Stamper.forHash(file)
case _: LastModified => Stamper.forLastModifiedP(converter.toPath(fileRef))
case _: FarmHash => Stamper.forFarmHashP(converter.toPath(fileRef))
}

// Since we may have modified some of the products of the incremental compiler, that is, the compiled template
Expand All @@ -118,6 +115,7 @@ object PlayEbean extends AutoPlugin {
+ s"product of incremental compiler: $classFile"
)
}

stamps.markProduct(classFile, updateStampForClassFile(classFile, existingStamp))
})

Expand Down

0 comments on commit 7ac90ea

Please sign in to comment.