From 7ac90ea5dcfe4a5d9a8eb36bcece9933ce8d1318 Mon Sep 17 00:00:00 2001 From: Jason Swenski Date: Fri, 21 May 2021 11:00:36 -0600 Subject: [PATCH] Fixes #208 - Support sbt 1.4.x+ 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. --- build.sbt | 18 +++++++++--------- project/build.properties | 2 +- .../play/ebean/sbt/PlayEbean.scala | 16 +++++++--------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/build.sbt b/build.sbt index 5931ac06..f256359f 100644 --- a/build.sbt +++ b/build.sbt @@ -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 @@ -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") @@ -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, @@ -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) diff --git a/project/build.properties b/project/build.properties index ef5a3fcb..3345669f 100644 --- a/project/build.properties +++ b/project/build.properties @@ -2,4 +2,4 @@ # Copyright (C) Lightbend Inc. # -sbt.version=1.3.10 +sbt.version=1.4.9 diff --git a/sbt-play-ebean/src/main/scala-sbt-1.0/play/ebean/sbt/PlayEbean.scala b/sbt-play-ebean/src/main/scala-sbt-1.0/play/ebean/sbt/PlayEbean.scala index 3b8a3934..b332eeb1 100644 --- a/sbt-play-ebean/src/main/scala-sbt-1.0/play/ebean/sbt/PlayEbean.scala +++ b/sbt-play-ebean/src/main/scala-sbt-1.0/play/ebean/sbt/PlayEbean.scala @@ -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 @@ -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 { @@ -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 @@ -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 @@ -118,6 +115,7 @@ object PlayEbean extends AutoPlugin { + s"product of incremental compiler: $classFile" ) } + stamps.markProduct(classFile, updateStampForClassFile(classFile, existingStamp)) })