diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13c0fa9..faaf3e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - scala: [2.12.20] + scala: [3.3.4, 2.12.20] java: [temurin@11] runs-on: ${{ matrix.os }} steps: @@ -68,7 +68,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - scala: [2.12.20] + scala: [3.3.4] java: [temurin@11] runs-on: ${{ matrix.os }} steps: @@ -88,6 +88,16 @@ jobs: - name: Setup sbt uses: sbt/setup-sbt@v1 + - name: Download target directories (3.3.4) + uses: actions/download-artifact@v4 + with: + name: target-${{ matrix.os }}-3.3.4-${{ matrix.java }} + + - name: Inflate target directories (3.3.4) + run: | + tar xf targets.tar + rm targets.tar + - name: Download target directories (2.12.20) uses: actions/download-artifact@v4 with: diff --git a/.scalafmt.conf b/.scalafmt.conf index 49fa214..d878e6b 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,6 +1,12 @@ version = "3.8.3" runner.dialect = scala212 +fileOverride { + "glob:**/scala-3/**" { + runner.dialect = scala3 + } +} + maxColumn = 100 lineEndings=preserve binPack.literalArgumentLists = true diff --git a/build.sbt b/build.sbt index e05cc68..da13862 100644 --- a/build.sbt +++ b/build.sbt @@ -30,7 +30,10 @@ ThisBuild / developers := List( ) // sbt-github-actions -ThisBuild / scalaVersion := "2.12.20" +lazy val scala3 = "3.3.4" +lazy val scala212 = "2.12.20" +ThisBuild / scalaVersion := scala3 +ThisBuild / crossScalaVersions := Seq(scala3, scala212) ThisBuild / githubWorkflowBuild := Seq( WorkflowStep.Sbt(name = Some("Build project"), commands = List("compile", "test", "scripted")) ) @@ -96,9 +99,20 @@ lazy val `sbt-avro`: Project = project .enablePlugins(BuildInfoPlugin, SbtPlugin) .settings( description := "Sbt plugin for compiling Avro sources", + (pluginCrossBuild / sbtVersion) := { + scalaBinaryVersion.value match { + case "2.12" => "1.5.0" + case _ => "2.0.0-M2" + } + }, + scriptedSbt := { + scalaBinaryVersion.value match { + case "2.12" => "1.10.3" + case _ => "2.0.0-M2" + } + }, buildInfoKeys := Seq[BuildInfoKey](name, version), buildInfoPackage := "com.github.sbt.avro", - pluginCrossBuild / sbtVersion := "1.3.0", Compile / scalacOptions ++= Seq("-deprecation"), scriptedLaunchOpts ++= Seq( "-Xmx1024M", diff --git a/plugin/src/main/scala-2.12/com/github/sbt/avro/PluginCompat.scala b/plugin/src/main/scala-2.12/com/github/sbt/avro/PluginCompat.scala new file mode 100644 index 0000000..9fe5414 --- /dev/null +++ b/plugin/src/main/scala-2.12/com/github/sbt/avro/PluginCompat.scala @@ -0,0 +1,14 @@ +package com.github.sbt.avro +import sbt.* +import xsbti.FileConverter + +import java.nio.file.{ Path => NioPath } + +private[avro] object PluginCompat { + type FileRef = java.io.File + type Out = java.io.File + + def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath = + a.data.toPath() + def toFileRef(f: File): FileRef = f +} diff --git a/plugin/src/main/scala-3/com/github/sbt/avro/PluginCompat.scala b/plugin/src/main/scala-3/com/github/sbt/avro/PluginCompat.scala new file mode 100644 index 0000000..b612713 --- /dev/null +++ b/plugin/src/main/scala-3/com/github/sbt/avro/PluginCompat.scala @@ -0,0 +1,14 @@ +package com.github.sbt.avro + +import java.nio.file.{Path => NioPath} +import sbt.* +import xsbti.{FileConverter, HashedVirtualFileRef, VirtualFile} + +private[avro] object PluginCompat: + type FileRef = HashedVirtualFileRef + type Out = VirtualFile + + def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath = + conv.toPath(a.data) + + def toFileRef(f: File)(using conv: FileConverter): FileRef = conv.toVirtualFile(f.toPath) diff --git a/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala b/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala index f7f5e12..5d922ef 100644 --- a/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala +++ b/plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala @@ -1,8 +1,9 @@ package com.github.sbt.avro import sbt.Keys.* -import sbt.* +import sbt.{*, given} import Path.relativeTo +import PluginCompat.* import sbt.librarymanagement.DependencyFilter import java.io.File @@ -45,10 +46,11 @@ object SbtAvro extends AutoPlugin { val avroGenerate = taskKey[Seq[File]]("Generate Java sources for Avro schemas.") val avroUnpackDependencies = taskKey[Seq[File]]("Unpack avro dependencies.") - val packageAvro = taskKey[File]("Produces an avro artifact, such as a jar containing avro schemas.") + val packageAvro = taskKey[FileRef]("Produces an avro artifact, such as a jar containing avro schemas.") // format: on - lazy val avroArtifactTasks: Seq[TaskKey[File]] = Seq(Compile, Test).map(_ / packageAvro) + lazy val avroArtifactTasks: Seq[TaskKey[FileRef]] = + Seq(Compile, Test).map(conf => conf / packageAvro) lazy val defaultSettings: Seq[Setting[_]] = Seq( // compiler @@ -108,8 +110,11 @@ object SbtAvro extends AutoPlugin { import autoImport._ - def packageAvroMappings: Def.Initialize[Task[Seq[(File, String)]]] = Def.task { - avroUnmanagedSourceDirectories.value.flatMap(src => (src ** AvroFilter).pair(relativeTo(src))) + def packageAvroMappings: Def.Initialize[Task[Seq[(FileRef, String)]]] = Def.task { + implicit val conv: xsbti.FileConverter = fileConverter.value + avroUnmanagedSourceDirectories.value + .flatMap(src => (src ** AvroFilter).pair(relativeTo(src))) + .map { case (p, path) => toFileRef(p) -> path } } override def trigger: PluginTrigger = noTrigger @@ -158,6 +163,7 @@ object SbtAvro extends AutoPlugin { private def unpackDependenciesTask(key: TaskKey[Seq[File]]) = Def.task { val cacheBaseDirectory = Defaults.makeCrossTarget( streams.value.cacheDirectory, + scalaVersion.value, scalaBinaryVersion.value, (pluginCrossBuild / sbtBinaryVersion).value, sbtPlugin.value, @@ -184,6 +190,7 @@ object SbtAvro extends AutoPlugin { val externalSrcDir = (avroUnpackDependencies / target).value val srcDirs = avroUnmanagedSourceDirectories.value :+ externalSrcDir val outDir = (key / target).value + implicit val conv: xsbti.FileConverter = fileConverter.value // used by PluginCompat val cachedCompile = { import sbt.util.CacheStoreFactory @@ -215,7 +222,10 @@ object SbtAvro extends AutoPlugin { // TODO Cache class loader val avroClassLoader = new URLClassLoader( "AvroClassLoader", - (Avro / dependencyClasspath).value.map(_.data.toURI.toURL).toArray, + (Avro / dependencyClasspath).value + .map(toNioPath) + .map(_.toUri.toURL) + .toArray, this.getClass.getClassLoader ) @@ -234,13 +244,13 @@ object SbtAvro extends AutoPlugin { try { val recs = records.map(avroClassLoader.loadClass) - val avdls = srcDirs.flatMap(d => (d ** AvroAvdlFilter).get) + val avdls = srcDirs.flatMap(d => (d ** AvroAvdlFilter).get()) val avscs = srcDirs.flatMap(d => - (d ** AvroAvscFilter).get.map(avsc => - new AvroFileRef(d, avsc.relativeTo(d).get.toString) - ) + (d ** AvroAvscFilter) + .get() + .map(avsc => new AvroFileRef(d, avsc.relativeTo(d).get.toString)) ) - val avprs = srcDirs.flatMap(d => (d ** AvroAvrpFilter).get) + val avprs = srcDirs.flatMap(d => (d ** AvroAvrpFilter).get()) out.log.info( s"Avro compiler ${avroVersion.value} using stringType=${avroStringType.value}" @@ -251,7 +261,7 @@ object SbtAvro extends AutoPlugin { compiler.compileAvscs(avscs.toArray, outDir) compiler.compileAvprs(avprs.toArray, outDir) - (outDir ** SbtAvro.JavaFileFilter).get.toSet + (outDir ** SbtAvro.JavaFileFilter).get().toSet } finally { avroClassLoader.close() } @@ -263,7 +273,7 @@ object SbtAvro extends AutoPlugin { } } - cachedCompile((srcDirs ** AvroFilter).get.toSet, avroSpecificRecords.value).toSeq + cachedCompile((srcDirs ** AvroFilter).get().toSet, avroSpecificRecords.value).toSeq } } diff --git a/plugin/src/sbt-test/sbt-avro/avscparser/project/build.properties b/plugin/src/sbt-test/sbt-avro/avscparser/project/build.properties deleted file mode 100644 index bc73906..0000000 --- a/plugin/src/sbt-test/sbt-avro/avscparser/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.10.3 diff --git a/plugin/src/sbt-test/sbt-avro/basic/build.sbt b/plugin/src/sbt-test/sbt-avro/basic/build.sbt index 783479a..fb58aae 100644 --- a/plugin/src/sbt-test/sbt-avro/basic/build.sbt +++ b/plugin/src/sbt-test/sbt-avro/basic/build.sbt @@ -1,17 +1,96 @@ ThisBuild / scalaVersion := "2.13.11" -lazy val basic = crossProject( - Avro("1.12.0"), - Avro("1.11.3"), - Avro("1.10.0"), - Avro("1.9.2"), - Avro("1.8.2"), - ) - .crossType(CrossType.Pure) +lazy val files = Seq( + "A", "B", "C", "D", "E", "_A", "_B", "_C", "_D", "_E", "LogicalTypesTest" +) + +lazy val testFiles = Seq( + "X", "Y", "Z" +) + +val checkGenerated = TaskKey[Unit]("checkGenerated") +val checkCompiled = TaskKey[Unit]("checkCompiled") + +def exists(f: File): Unit = assert(f.exists(), s"$f does not exist") + +val checkSettings = inConfig(Compile)(Def.settings( + checkGenerated := { + files.foreach { f => + exists(crossTarget.value / "src_managed" / "compiled_avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / s"$f.java") + } + }, + checkCompiled := { + files.foreach { f => + exists(classDirectory.value / "com" / "github" / "sbt" / "avro" / "test" / s"$f.class") + } + } +)) ++ inConfig(Test)(Def.settings( + checkGenerated := { + testFiles.foreach { f => + exists(crossTarget.value / "src_managed" / "compiled_avro" / "test" / "com" / "github" / "sbt" / "avro" / "test" / s"$f.java") + } + }, + checkCompiled := { + testFiles.foreach { f => + exists(classDirectory.value / "com" / "github" / "sbt" / "avro" / "test" / s"$f.class") + } + } +)) + + +lazy val `basic` = project .in(file(".")) - .avroSettings("1.9.2")( - libraryDependencies += "joda-time" % "joda-time" % "2.12.7" + .aggregate( + `basic8`, + `basic9`, + `basic10`, + `basic11`, + `basic12` + ) + +lazy val `basic8` = project + .in(file(".basic_8")) + .enablePlugins(SbtAvro) + .settings(checkSettings) + .settings( + avroVersion := "1.8.2", + libraryDependencies += "joda-time" % "joda-time" % "2.12.7", + sourceDirectory := file(".") / "src" + ) + +lazy val `basic9` = project + .in(file(".basic_9")) + .enablePlugins(SbtAvro) + .settings(checkSettings) + .settings( + avroVersion := "1.9.2", + libraryDependencies += "joda-time" % "joda-time" % "2.12.7", + sourceDirectory := file(".") / "src" + ) + +lazy val `basic10` = project + .in(file(".basic_10")) + .enablePlugins(SbtAvro) + .settings(checkSettings) + .settings( + avroVersion := "1.10.0", + sourceDirectory := file(".") / "src" + ) + +lazy val `basic11` = project + .in(file(".basic_11")) + .enablePlugins(SbtAvro) + .settings(checkSettings) + .settings( + avroVersion := "1.11.3", + sourceDirectory := file(".") / "src" ) - .avroSettings("1.8.2")( - libraryDependencies += "joda-time" % "joda-time" % "2.12.7" + +lazy val `basic12` = project + .in(file(".basic_12")) + .enablePlugins(SbtAvro) + .settings(checkSettings) + .settings( + avroVersion := "1.12.0", + sourceDirectory := file(".") / "src" ) diff --git a/plugin/src/sbt-test/sbt-avro/basic/project/Avro.scala b/plugin/src/sbt-test/sbt-avro/basic/project/Avro.scala deleted file mode 100644 index eefba9a..0000000 --- a/plugin/src/sbt-test/sbt-avro/basic/project/Avro.scala +++ /dev/null @@ -1,24 +0,0 @@ -import sbt._ -import Keys._ -import sbtcrossproject._ -import com.github.sbt.avro.SbtAvro - -case class Avro(version: String) extends Platform { - - import CrossPlugin.autoImport._ - import SbtAvro.autoImport._ - - def identifier: String = "avro-" + version.split('.')(1) - def sbtSuffix: String = "Avro_" + version.split('.')(1) - def enable(project: Project): Project = project - .enablePlugins(SbtAvro) - .settings( - avroVersion := version, - Compile / avroUnmanagedSourceDirectories ++= crossProjectCrossType.value - .sharedSrcDir(baseDirectory.value, "main") - .map(_.getParentFile / "avro"), - Test / avroUnmanagedSourceDirectories ++= crossProjectCrossType.value - .sharedSrcDir(baseDirectory.value, "test") - .map(_.getParentFile / "avro"), - ) -} diff --git a/plugin/src/sbt-test/sbt-avro/basic/project/AvroCrossPlugin.scala b/plugin/src/sbt-test/sbt-avro/basic/project/AvroCrossPlugin.scala deleted file mode 100644 index dbe99c1..0000000 --- a/plugin/src/sbt-test/sbt-avro/basic/project/AvroCrossPlugin.scala +++ /dev/null @@ -1,25 +0,0 @@ -import scala.language.implicitConversions - -import sbt._ -import sbtcrossproject._ - -object AvroCrossPlugin extends sbt.AutoPlugin { - object autoImport { - - implicit def AvroCrossProjectBuilderOps(builder: CrossProject.Builder): AvroCrossProjectOps = - new AvroCrossProjectOps(builder.crossType(CrossType.Full)) - - implicit class AvroCrossProjectOps(project: CrossProject) { - def avro(version: String): Project = project.projects(Avro(version)) - - def avroSettings(version: String)(ss: Def.SettingsDefinition*): CrossProject = - avroConfigure(version)(_.settings(ss: _*)) - - def avroEnablePlugins(version: String)(plugins: Plugins*): CrossProject = - avroConfigure(version)(_.enablePlugins(plugins: _*)) - - def avroConfigure(version: String)(transformer: Project => Project): CrossProject = - project.configurePlatform(Avro(version))(transformer) - } - } -} diff --git a/plugin/src/sbt-test/sbt-avro/basic/project/build.properties b/plugin/src/sbt-test/sbt-avro/basic/project/build.properties deleted file mode 100644 index bc73906..0000000 --- a/plugin/src/sbt-test/sbt-avro/basic/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.10.3 diff --git a/plugin/src/sbt-test/sbt-avro/basic/project/plugins.sbt b/plugin/src/sbt-test/sbt-avro/basic/project/plugins.sbt index a97f6e3..c52f4d5 100644 --- a/plugin/src/sbt-test/sbt-avro/basic/project/plugins.sbt +++ b/plugin/src/sbt-test/sbt-avro/basic/project/plugins.sbt @@ -3,5 +3,3 @@ sys.props.get("plugin.version") match { case _ => sys.error("""|The system property 'plugin.version' is not defined. |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) } - -addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "1.3.2") diff --git a/plugin/src/sbt-test/sbt-avro/basic/src/main/avro/logicalType.avsc b/plugin/src/sbt-test/sbt-avro/basic/src/main/avro/logicalType.avsc index 46bac38..5705d1a 100644 --- a/plugin/src/sbt-test/sbt-avro/basic/src/main/avro/logicalType.avsc +++ b/plugin/src/sbt-test/sbt-avro/basic/src/main/avro/logicalType.avsc @@ -1,6 +1,6 @@ { "name": "LogicalTypesTest", - "namespace": "org.apache.parquet.avro", + "namespace": "com.github.sbt.avro.test", "doc": "Record for testing logical types", "type": "record", "fields": [ diff --git a/plugin/src/sbt-test/sbt-avro/basic/test b/plugin/src/sbt-test/sbt-avro/basic/test index d23c116..2ec71eb 100644 --- a/plugin/src/sbt-test/sbt-avro/basic/test +++ b/plugin/src/sbt-test/sbt-avro/basic/test @@ -1,39 +1,10 @@ > avroGenerate +> checkGenerated -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/A.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/B.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/C.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/D.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/E.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_A.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_B.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_C.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_D.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_E.java +# use product instead of compile to get classes in classDirectory +> products +> checkCompiled -$ exists .avro-11/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/A.java -$ exists .avro-10/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/A.java -$ exists .avro-9/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/A.java -$ exists .avro-8/target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/A.java - -> compile - -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/A.class -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/B.class -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/C.class -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/D.class -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/E.class -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/_A.class -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/_B.class -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/_C.class -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/_D.class -$ exists .avro-12/target/scala-2.13/classes/com/github/sbt/avro/test/_E.class - -> Test/compile - -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/X.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/Y.java -$ exists .avro-12/target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/Z.java -$ exists .avro-12/target/scala-2.13/test-classes/com/github/sbt/avro/test/X.class -$ exists .avro-12/target/scala-2.13/test-classes/com/github/sbt/avro/test/Y.class -$ exists .avro-12/target/scala-2.13/test-classes/com/github/sbt/avro/test/Z.class +> Test/products +> Test/checkGenerated +> Test/checkCompiled diff --git a/plugin/src/sbt-test/sbt-avro/publishing/build.sbt b/plugin/src/sbt-test/sbt-avro/publishing/build.sbt index 7aff966..eee5367 100644 --- a/plugin/src/sbt-test/sbt-avro/publishing/build.sbt +++ b/plugin/src/sbt-test/sbt-avro/publishing/build.sbt @@ -1,3 +1,9 @@ +val checkUnpacked = TaskKey[Unit]("checkUnpacked") +val checkGenerated = TaskKey[Unit]("checkGenerated") + +def exists(f: File): Unit = assert(f.exists(), s"$f does not exist") +def absent(f: File): Unit = assert(!f.exists(), s"$f does exists") + lazy val commonSettings = Seq( organization := "com.github.sbt", scalaVersion := "2.13.15" @@ -53,5 +59,25 @@ lazy val root: Project = project // add additional transitive test jar avroDependencyIncludeFilter := avroDependencyIncludeFilter.value || artifactFilter(name = "transitive", classifier = "tests"), // exclude specific avsc file - Compile / avroUnpackDependencies / excludeFilter := (Compile / avroUnpackDependencies / excludeFilter).value || "exclude.avsc" + Compile / avroUnpackDependencies / excludeFilter := (Compile / avroUnpackDependencies / excludeFilter).value || "exclude.avsc", + + Compile / checkUnpacked := { + exists(crossTarget.value / "src_managed" / "avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / "external" / "avdl.avdl") + exists(crossTarget.value / "src_managed" / "avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / "external" / "avpr.avpr") + exists(crossTarget.value / "src_managed" / "avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / "external" / "avsc.avsc") + absent(crossTarget.value / "src_managed" / "avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / "external" / "exclude.avsc") + exists(crossTarget.value / "src_managed" / "avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / "transitive" / "avsc.avsc") + }, + Compile / checkGenerated := { + exists(crossTarget.value / "src_managed" / "compiled_avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / "external" / "Avdl.java") + exists(crossTarget.value / "src_managed" / "compiled_avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / "external" / "Avpr.java") + exists(crossTarget.value / "src_managed" / "compiled_avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / "external" / "Avsc.java") + exists(crossTarget.value / "src_managed" / "compiled_avro" / "main" / "com" / "github" / "sbt" / "avro" / "test" / "transitive" / "Avsc.java") + }, + Test / checkUnpacked := { + exists(crossTarget.value / "src_managed" / "avro" / "test" / "test.avsc") + }, + Test / checkGenerated := { + exists(crossTarget.value / "src_managed" / "compiled_avro" / "test" / "com" / "github" / "sbt" / "avro" / "test" / "transitive" / "Test.java") + } ) diff --git a/plugin/src/sbt-test/sbt-avro/publishing/project/build.properties b/plugin/src/sbt-test/sbt-avro/publishing/project/build.properties deleted file mode 100644 index bc73906..0000000 --- a/plugin/src/sbt-test/sbt-avro/publishing/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.10.3 diff --git a/plugin/src/sbt-test/sbt-avro/publishing/src/main/scala/com/github/sbt/avro/test/Main.scala b/plugin/src/sbt-test/sbt-avro/publishing/src/main/scala/com/github/sbt/avro/test/Main.scala index 9a72733..52bd9cb 100644 --- a/plugin/src/sbt-test/sbt-avro/publishing/src/main/scala/com/github/sbt/avro/test/Main.scala +++ b/plugin/src/sbt-test/sbt-avro/publishing/src/main/scala/com/github/sbt/avro/test/Main.scala @@ -3,6 +3,8 @@ package com.github.sbt.avro.test object Main extends App { external.Avsc.newBuilder().setStringField("external").build() + external.Avpr.newBuilder().setStringField("external").build() + external.Avdl.newBuilder().setStringField("external").build() transitive.Avsc.newBuilder().setStringField("transitive").build() println("success") diff --git a/plugin/src/sbt-test/sbt-avro/publishing/src/test/scala/com/github/sbt/avro/test/Test.scala b/plugin/src/sbt-test/sbt-avro/publishing/src/test/scala/com/github/sbt/avro/test/AvroTest.scala similarity index 100% rename from plugin/src/sbt-test/sbt-avro/publishing/src/test/scala/com/github/sbt/avro/test/Test.scala rename to plugin/src/sbt-test/sbt-avro/publishing/src/test/scala/com/github/sbt/avro/test/AvroTest.scala diff --git a/plugin/src/sbt-test/sbt-avro/publishing/test b/plugin/src/sbt-test/sbt-avro/publishing/test index c4c3c66..03e6fa8 100644 --- a/plugin/src/sbt-test/sbt-avro/publishing/test +++ b/plugin/src/sbt-test/sbt-avro/publishing/test @@ -1,53 +1,17 @@ -> external/packageAvro - -$ exists external/target/external-0.0.1-SNAPSHOT-avro.jar - > external/publishLocal - > transitive/publishLocal > avroUnpackDependencies - -$ exists target/scala-2.13/src_managed/avro/main/com/github/sbt/avro/test/external/avdl.avdl -$ exists target/scala-2.13/src_managed/avro/main/com/github/sbt/avro/test/external/avpr.avpr -$ exists target/scala-2.13/src_managed/avro/main/com/github/sbt/avro/test/external/avsc.avsc -$ absent target/scala-2.13/src_managed/avro/main/com/github/sbt/avro/test/external/exclude.avsc - -$ exists target/scala-2.13/src_managed/avro/main/com/github/sbt/avro/test/transitive/avsc.avsc - -$ absent target/scala-2.13/src_managed/avro/main/com/github/sbt/avro/test/transitive/test.avsc +> checkUnpacked > avroGenerate - -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/external/Avdl.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/external/Avpr.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/external/Avsc.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/transitive/Avsc.java +> checkGenerated > +compile -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/external/Avdl.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/external/Avpr.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/external/Avsc.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/transitive/Avsc.class - - -$ exists target/scala-2.12/classes/com/github/sbt/avro/test/external/Avdl.class -$ exists target/scala-2.12/classes/com/github/sbt/avro/test/external/Avpr.class -$ exists target/scala-2.12/classes/com/github/sbt/avro/test/external/Avsc.class -$ exists target/scala-2.12/classes/com/github/sbt/avro/test/transitive/Avsc.class - > Test/avroUnpackDependencies - -$ exists target/scala-2.13/src_managed/avro/test/test.avsc - +> Test/checkUnpacked > Test/avroGenerate - -$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/transitive/Test.java - +> Test/checkGenerated > +Test/compile - -$ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/transitive/Test.class -$ exists target/scala-2.12/test-classes/com/github/sbt/avro/test/transitive/Test.class - > clean diff --git a/plugin/src/sbt-test/sbt-avro/recompile/build.sbt b/plugin/src/sbt-test/sbt-avro/recompile/build.sbt index 7551a20..b65d4a5 100644 --- a/plugin/src/sbt-test/sbt-avro/recompile/build.sbt +++ b/plugin/src/sbt-test/sbt-avro/recompile/build.sbt @@ -8,6 +8,8 @@ libraryDependencies ++= Seq( "org.specs2" %% "specs2-core" % "4.20.9" % Test ) +// sut custom output for cross-build sbt v1 & v2 +avroGenerate / target := file("target") / "compiled_avro" avroStringType := "String" avroFieldVisibility := "public" avroOptionalGetters := true diff --git a/plugin/src/sbt-test/sbt-avro/recompile/project/build.properties b/plugin/src/sbt-test/sbt-avro/recompile/project/build.properties deleted file mode 100644 index bc73906..0000000 --- a/plugin/src/sbt-test/sbt-avro/recompile/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.10.3 diff --git a/plugin/src/sbt-test/sbt-avro/recompile/test b/plugin/src/sbt-test/sbt-avro/recompile/test index ba58487..3b0c732 100644 --- a/plugin/src/sbt-test/sbt-avro/recompile/test +++ b/plugin/src/sbt-test/sbt-avro/recompile/test @@ -1,28 +1,28 @@ > avroGenerate -$ exists target/scala-2.13/src_managed/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java +$ exists target/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java # reference file created after 1st generation $ touch target/reference.txt # cache should not recompile > avroGenerate -$ newer target/reference.txt target/scala-2.13/src_managed/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java +$ newer target/reference.txt target/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java # regenerate after clean > clean > avroGenerate -$exists target/scala-2.13/src_managed/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java +$exists target/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java # add new source file should re-compile $ copy-file record.avsc src/main/avro/record.avsc > avroGenerate -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/Record.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java +$ exists target/compiled_avro/main/com/github/sbt/avro/test/Record.java +$ exists target/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java # update reference file $ touch target/reference.txt # cache should not recompile > avroGenerate -$ newer target/reference.txt target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/Record.java -$ newer target/reference.txt target/scala-2.13/src_managed/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java +$ newer target/reference.txt target/compiled_avro/main/com/github/sbt/avro/test/Record.java +$ newer target/reference.txt target/compiled_avro/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java diff --git a/plugin/src/sbt-test/sbt-avro/sbt_1.3/build.sbt b/plugin/src/sbt-test/sbt-avro/sbt_1.3/build.sbt deleted file mode 100644 index 391e135..0000000 --- a/plugin/src/sbt-test/sbt-avro/sbt_1.3/build.sbt +++ /dev/null @@ -1,5 +0,0 @@ -enablePlugins(SbtAvro) - -name := "basic-test" -scalaVersion := "2.13.11" -libraryDependencies += "org.apache.avro" % "avro" % avroVersion.value diff --git a/plugin/src/sbt-test/sbt-avro/sbt_1.3/project/build.properties b/plugin/src/sbt-test/sbt-avro/sbt_1.3/project/build.properties deleted file mode 100644 index 080a737..0000000 --- a/plugin/src/sbt-test/sbt-avro/sbt_1.3/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.3.0 diff --git a/plugin/src/sbt-test/sbt-avro/sbt_1.3/project/plugins.sbt b/plugin/src/sbt-test/sbt-avro/sbt_1.3/project/plugins.sbt deleted file mode 100644 index c52f4d5..0000000 --- a/plugin/src/sbt-test/sbt-avro/sbt_1.3/project/plugins.sbt +++ /dev/null @@ -1,5 +0,0 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-avro" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} diff --git a/plugin/src/sbt-test/sbt-avro/sbt_1.3/src b/plugin/src/sbt-test/sbt-avro/sbt_1.3/src deleted file mode 120000 index 12c7604..0000000 --- a/plugin/src/sbt-test/sbt-avro/sbt_1.3/src +++ /dev/null @@ -1 +0,0 @@ -../basic/src \ No newline at end of file diff --git a/plugin/src/sbt-test/sbt-avro/sbt_1.3/test b/plugin/src/sbt-test/sbt-avro/sbt_1.3/test deleted file mode 100644 index f410585..0000000 --- a/plugin/src/sbt-test/sbt-avro/sbt_1.3/test +++ /dev/null @@ -1,34 +0,0 @@ -> avroGenerate - -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/A.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/B.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/C.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/D.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/E.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_A.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_B.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_C.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_D.java -$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_E.java - -> compile - -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/A.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/B.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/C.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/D.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/E.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_A.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_B.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_C.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_D.class -$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_E.class - -> Test/compile - -$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/X.java -$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/Y.java -$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/Z.java -$ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/X.class -$ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/Y.class -$ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/Z.class diff --git a/plugin/src/sbt-test/sbt-avro/settings/project/build.properties b/plugin/src/sbt-test/sbt-avro/settings/project/build.properties deleted file mode 100644 index bc73906..0000000 --- a/plugin/src/sbt-test/sbt-avro/settings/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.10.3 diff --git a/plugin/src/sbt-test/sbt-avro/settings/src/test/scala/com/github/sbt/avro/test/settings/SettingsSpec.scala b/plugin/src/sbt-test/sbt-avro/settings/src/test/scala/com/github/sbt/avro/test/settings/SettingsSpec.scala index c086b14..c5c931e 100644 --- a/plugin/src/sbt-test/sbt-avro/settings/src/test/scala/com/github/sbt/avro/test/settings/SettingsSpec.scala +++ b/plugin/src/sbt-test/sbt-avro/settings/src/test/scala/com/github/sbt/avro/test/settings/SettingsSpec.scala @@ -1,8 +1,10 @@ package com.github.sbt.avro.test.settings import java.io.File +import java.nio.ByteBuffer import java.util.Optional +import org.apache.avro.specific.TestRecordWithLogicalTypes import org.apache.avro.Schema import org.apache.avro.generic.GenericData.StringType import org.specs2.mutable.Specification @@ -10,30 +12,41 @@ import com.github.sbt.avro.test.settings.{Avdl, Avpr, Avsc} class SettingsSpec extends Specification { - "stringField setting should be respected for *.avsc compilation" >> { + // avroStringType + "avroStringType setting should be respected for *.avsc compilation" >> { classOf[Avsc].getDeclaredField("stringField").getType == classOf[String] } - "stringField setting should be respected for *.avdl compilation" >> { + "avroStringType setting should be respected for *.avdl compilation" >> { classOf[Avdl].getDeclaredField("stringField").getType == classOf[String] } - "stringField setting should be respected for *.avpr compilation" >> { + "avroStringType setting should be respected for *.avpr compilation" >> { classOf[Avpr].getDeclaredField("stringField").getType == classOf[String] } - "fieldVisibility setting should be respected for *.avsc compilation" >> { + "stringField setting should be respected for recompiled record" >> { + classOf[TestRecordWithLogicalTypes].getDeclaredField("s").getType == classOf[String] + } + + // avroFieldVisibility + "avroFieldVisibility setting should be respected for *.avsc compilation" >> { !classOf[Avsc].getDeclaredField("stringField").isAnnotationPresent(classOf[Deprecated]) } - "fieldVisibility setting should be respected for *.avdl compilation" >> { + "avroFieldVisibility setting should be respected for *.avdl compilation" >> { !classOf[Avdl].getDeclaredField("stringField").isAnnotationPresent(classOf[Deprecated]) } - "fieldVisibility setting should be respected for *.avpr compilation" >> { + "avroFieldVisibility setting should be respected for *.avpr compilation" >> { !classOf[Avpr].getDeclaredField("stringField").isAnnotationPresent(classOf[Deprecated]) } + "avroFieldVisibility setting should be respected for recompiled record" >> { + !classOf[TestRecordWithLogicalTypes].getDeclaredField("s").isAnnotationPresent(classOf[Deprecated]) + } + + // avroOptionalGetters "avroOptionalGetters setting should be respected for *.avsc compilation" >> { classOf[Avsc].getDeclaredMethod("getStringField").getReturnType == classOf[Optional[String]] } @@ -45,4 +58,13 @@ class SettingsSpec extends Specification { "avroOptionalGetters setting should be respected for *.avpr compilation" >> { classOf[Avpr].getDeclaredMethod("getStringField").getReturnType == classOf[Optional[String]] } + + "avroOptionalGetters setting should be respected for recompiled record" >> { + classOf[TestRecordWithLogicalTypes].getDeclaredMethod("getS").getReturnType == classOf[Optional[String]] + } + + // avroEnableDecimalLogicalType + "avroEnableDecimalLogicalType setting should be respected for recompiled record" >> { + classOf[TestRecordWithLogicalTypes].getDeclaredField("bd").getType == classOf[ByteBuffer] + } } diff --git a/plugin/src/sbt-test/sbt-avro/settings/test b/plugin/src/sbt-test/sbt-avro/settings/test index 59f1cd9..dfffb83 100644 --- a/plugin/src/sbt-test/sbt-avro/settings/test +++ b/plugin/src/sbt-test/sbt-avro/settings/test @@ -1,17 +1 @@ -> compile - -$ exists target/scala-2.13/src_managed/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java --$ exec grep BigDecimal target/scala-2.13/src_managed/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java --$ exec grep CharSequence target/scala-2.13/src_managed/main/org/apache/avro/specific/TestRecordWithLogicalTypes.java - -$ exists target/scala-2.13/src_managed/main/com/github/sbt/avro/test/settings/Avdl.java -$ exists target/scala-2.13/src_managed/main/com/github/sbt/avro/test/settings/Avpr.java -$ exists target/scala-2.13/src_managed/main/com/github/sbt/avro/test/settings/ProtocolAvpr.java -$ exists target/scala-2.13/src_managed/main/com/github/sbt/avro/test/settings/Avsc.java -$ exists target/scala-2.13/src_managed/main/com/github/sbt/avro/test/settings/ProtocolAvdl.java - > test - -> clean - -> compile