Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inverted settings #207

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
}
}