Skip to content

Commit

Permalink
Use distinct managed sources folders (#126)
Browse files Browse the repository at this point in the history
* Use distinct managed sources folders

* Improve comments in scripted tests
  • Loading branch information
RustedBones authored Aug 1, 2022
1 parent 5772037 commit bc6bdda
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 42 deletions.
13 changes: 9 additions & 4 deletions src/main/scala/com/github/sbt/avro/SbtAvro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ object SbtAvro extends AutoPlugin {
// addArtifact doesn't take publishArtifact setting in account
artifacts ++= Classpaths.artifactDefs(avroArtifactTasks).value,
packagedArtifacts ++= Classpaths.packaged(avroArtifactTasks).value,
// use a custom folders to avoid potential conflict with other generators
avroUnpackDependencies / target := sourceManaged.value / "avro",
avroGenerate / target := sourceManaged.value / "compiled_avro"
)

// settings to be applied for both Compile and Test
Expand All @@ -67,10 +70,10 @@ object SbtAvro extends AutoPlugin {
// dependencies
avroUnpackDependencies / includeFilter := AllPassFilter,
avroUnpackDependencies / excludeFilter := HiddenFileFilter,
avroUnpackDependencies / target := sourceManaged.value / "avro",
avroUnpackDependencies / target := configSrcSub(avroUnpackDependencies / target).value,
avroUnpackDependencies := unpackDependenciesTask(avroUnpackDependencies).value,
// source generation
avroGenerate / target := sourceManaged.value / "compiled_avro",
avroGenerate / target := configSrcSub(avroGenerate / target).value,
managedSourceDirectories += (avroGenerate / target).value,
avroGenerate := sourceGeneratorTask(avroGenerate).dependsOn(avroUnpackDependencies).value,
sourceGenerators += avroGenerate.taskValue,
Expand Down Expand Up @@ -139,10 +142,12 @@ object SbtAvro extends AutoPlugin {
}

private def unpackDependenciesTask(key: TaskKey[Seq[File]]) = Def.task {
val conf = configuration.value.toConfigRef
val avroArtifacts = update
.value
.filter((key / avroDependencyIncludeFilter).value)
.toSeq.map { case (_, _, _, file) => file }.distinct
.filter(avroDependencyIncludeFilter.value)
.toSeq
.collect { case (`conf`, _, _, file) => file }

unpack(
deps = avroArtifacts,
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/sbt-avro/avscparser/test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
> compile

$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/A.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/B.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

> test

Expand Down
26 changes: 13 additions & 13 deletions src/sbt-test/sbt-avro/basic_current/test
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
> set avroSchemaParserBuilder := com.github.sbt.avro.DefaultSchemaParserBuilder.default().copy(validateDefaults = false)
> avroGenerate

$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/A.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/B.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/C.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/D.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/E.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/_A.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/_B.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/_C.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/_D.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/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
$ 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

Expand All @@ -27,9 +27,9 @@ $ exists target/scala-2.13/classes/com/github/sbt/avro/test/_E.class

> test:compile

$ exists target/scala-2.13/src_managed/test/compiled_avro/com/github/sbt/avro/test/X.java
$ exists target/scala-2.13/src_managed/test/compiled_avro/com/github/sbt/avro/test/Y.java
$ exists target/scala-2.13/src_managed/test/compiled_avro/com/github/sbt/avro/test/Z.java
$ 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
Expand Down
8 changes: 5 additions & 3 deletions src/sbt-test/sbt-avro/publishing/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ lazy val `transitive`: Project = project
name := "transitive",
version := "0.0.1-SNAPSHOT",
Compile / packageAvro / publishArtifact := true,
Test / publishArtifact := true,
libraryDependencies ++= Seq(
"com.github.sbt" % "external" % "0.0.1-SNAPSHOT" classifier "avro",
)
Expand All @@ -37,12 +38,13 @@ lazy val root: Project = project
.settings(commonSettings)
.settings(
name := "publishing-test",
avroDependencyIncludeFilter := avroDependencyIncludeFilter.value ||
// add avro jar to unpack its json avsc schema
moduleFilter(organization = "org.apache.avro", name = "avro"),
libraryDependencies ++= Seq(
"com.github.sbt" %% "transitive" % "0.0.1-SNAPSHOT" classifier "avro",
"com.github.sbt" %% "transitive" % "0.0.1-SNAPSHOT" % Test classifier "tests",
"org.specs2" %% "specs2-core" % "4.16.1" % Test
),
// add additional transitive test jar
avroDependencyIncludeFilter := avroDependencyIncludeFilter.value || artifactFilter(name = "transitive_2.13", classifier = "tests"),
// exclude specific avsc file
Compile / avroUnpackDependencies / excludeFilter := (Compile / avroUnpackDependencies / excludeFilter).value || "exclude.avsc"
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import com.github.sbt.avro.test.external
import com.github.sbt.avro.test.transitive

package com.github.sbt.avro.test

object Main extends App {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.sbt.avro.test

import com.github.sbt.avro.test.transitive.Test

object AvroTest extends App {

Test.newBuilder().setStringField("external").build()

println("success")
}
29 changes: 18 additions & 11 deletions src/sbt-test/sbt-avro/publishing/test
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ $ exists external/target/external-0.0.1-SNAPSHOT-avro.jar

> avroUnpackDependencies

$ exists target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/external/avdl.avdl
$ exists target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/external/avpr.avpr
$ exists target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/external/avsc.avsc
$ absent target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/external/exclude.avsc
$ exists target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/transitive/avsc.avsc
$ exists target/scala-2.13/src_managed/main/avro/org/apache/avro/data/Json.avsc
$ 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

> avroGenerate

$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/external/Avdl.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/external/Avpr.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/external/Avsc.java
$ absent target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/external/Excluded.java
$ exists target/scala-2.13/src_managed/main/compiled_avro/com/github/sbt/avro/test/transitive/Avsc.java
$ 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

> compile

Expand All @@ -30,4 +31,10 @@ $ 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

> Test/compile

$ exists target/scala-2.13/src_managed/avro/test/test.avsc
$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/transitive/Test.java
$ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/transitive/Test.class

> clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Test",
"namespace": "com.github.sbt.avro.test.transitive",
"type": "record",
"fields": [
{
"name": "stringField",
"type": "string"
},
{
"name": "referencedTypeField",
"type": "com.github.sbt.avro.test.external.Avsc"
}
]
}
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/settings/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ avroStringType := "String"
avroFieldVisibility := "public"
avroOptionalGetters := true
(Compile / avroSource) := (Compile / sourceDirectory).value / "avro_source"
(Compile / avroGenerate / target) := (Compile / sourceManaged).value / "avro"
(Compile / avroGenerate / target) := (Compile / sourceManaged).value
10 changes: 5 additions & 5 deletions src/sbt-test/sbt-avro/settings/test
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
> compile

$ exists target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/settings/Avdl.java
$ exists target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/settings/Avpr.java
$ exists target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/settings/ProtocolAvpr.java
$ exists target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/settings/Avsc.java
$ exists target/scala-2.13/src_managed/main/avro/com/github/sbt/avro/test/settings/ProtocolAvdl.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

Expand Down

0 comments on commit bc6bdda

Please sign in to comment.