Skip to content

Commit

Permalink
Fix inverted settings
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones committed Oct 25, 2024
1 parent 9600eee commit 6bc181a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ object SbtAvro extends AutoPlugin {
compiler.setFieldVisibility(avroFieldVisibility.value.toUpperCase)
compiler.setUseNamespace(avroUseNamespace.value)
compiler.setEnableDecimalLogicalType(avroEnableDecimalLogicalType.value)
compiler.setCreateSetters(avroOptionalGetters.value)
compiler.setOptionalGetters(avroCreateSetters.value)
compiler.setCreateSetters(avroCreateSetters.value)
compiler.setOptionalGetters(avroOptionalGetters.value)

try {
val recs = records.map(avroClassLoader.loadClass)
Expand Down
1 change: 1 addition & 0 deletions plugin/src/sbt-test/sbt-avro/settings/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ libraryDependencies ++= Seq(

avroStringType := "String"
avroFieldVisibility := "public"
avroCreateSetters := false
avroOptionalGetters := true
avroEnableDecimalLogicalType := false
Compile / avroSpecificRecords += "org.apache.avro.specific.TestRecordWithLogicalTypes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class SettingsSpec extends Specification {

// avroStringType
"avroStringType setting should be respected for *.avsc compilation" >> {
classOf[Avsc].getDeclaredField("stringField").getType == classOf[String]
classOf[Avsc].getDeclaredField("stringField").getType === classOf[String]
}

"avroStringType setting should be respected for *.avdl compilation" >> {
classOf[Avdl].getDeclaredField("stringField").getType == classOf[String]
classOf[Avdl].getDeclaredField("stringField").getType === classOf[String]
}

"avroStringType setting should be respected for *.avpr compilation" >> {
classOf[Avpr].getDeclaredField("stringField").getType == classOf[String]
classOf[Avpr].getDeclaredField("stringField").getType === classOf[String]
}

"stringField setting should be respected for recompiled record" >> {
classOf[TestRecordWithLogicalTypes].getDeclaredField("s").getType == classOf[String]
classOf[TestRecordWithLogicalTypes].getDeclaredField("s").getType === classOf[String]
}

// avroFieldVisibility
Expand All @@ -46,25 +46,42 @@ class SettingsSpec extends Specification {
!classOf[TestRecordWithLogicalTypes].getDeclaredField("s").isAnnotationPresent(classOf[Deprecated])
}

// avroCreateSetters
"avroCreateSetters setting should be respected for *.avsc compilation" >> {
classOf[Avsc].getDeclaredMethod("setStringField") must throwA[NoSuchMethodException]
}

"avroCreateSetters setting should be respected for *.avdl compilation" >> {
classOf[Avdl].getDeclaredMethod("setStringField") must throwA[NoSuchMethodException]
}

"avroCreateSetters setting should be respected for *.avpr compilation" >> {
classOf[Avpr].getDeclaredMethod("stringField") must throwA[NoSuchMethodException]
}

"avroCreateSetters setting should be respected for recompiled record" >> {
classOf[TestRecordWithLogicalTypes].getDeclaredMethod("setS") must throwA[NoSuchMethodException]
}

// avroOptionalGetters
"avroOptionalGetters setting should be respected for *.avsc compilation" >> {
classOf[Avsc].getDeclaredMethod("getStringField").getReturnType == classOf[Optional[String]]
classOf[Avsc].getDeclaredMethod("getStringField").getReturnType === classOf[Optional[String]]
}

"avroOptionalGetters setting should be respected for *.avdl compilation" >> {
classOf[Avdl].getDeclaredMethod("getStringField").getReturnType == classOf[Optional[String]]
classOf[Avdl].getDeclaredMethod("getStringField").getReturnType === classOf[Optional[String]]
}

"avroOptionalGetters setting should be respected for *.avpr compilation" >> {
classOf[Avpr].getDeclaredMethod("getStringField").getReturnType == classOf[Optional[String]]
classOf[Avpr].getDeclaredMethod("getStringField").getReturnType === classOf[Optional[String]]
}

"avroOptionalGetters setting should be respected for recompiled record" >> {
classOf[TestRecordWithLogicalTypes].getDeclaredMethod("getS").getReturnType == classOf[Optional[String]]
classOf[TestRecordWithLogicalTypes].getDeclaredMethod("getS").getReturnType === classOf[Optional[String]]
}

// avroEnableDecimalLogicalType
"avroEnableDecimalLogicalType setting should be respected for recompiled record" >> {
classOf[TestRecordWithLogicalTypes].getDeclaredField("bd").getType == classOf[ByteBuffer]
classOf[TestRecordWithLogicalTypes].getDeclaredField("bd").getType === classOf[ByteBuffer]
}
}

0 comments on commit 6bc181a

Please sign in to comment.