From b96c7202320372fafe555966c8cf7e2d468b1c06 Mon Sep 17 00:00:00 2001 From: Julian Peeters Date: Wed, 1 Nov 2023 13:42:00 -0700 Subject: [PATCH] Release version 2.8.0 Crossbuild for Scala 3, remove Scavro, remove reflective compilation. --- README.md | 25 +- .../src/main/scala/format/Scavro.scala | 200 --------- .../main/scala/format/SpecificRecord.scala | 4 +- .../src/main/scala/format/Standard.scala | 4 +- .../format/abstractions/SourceFormat.scala | 4 +- .../scala/format/scavro/ScavroImporter.scala | 194 --------- .../format/scavro/ScavroJavaTreehugger.scala | 42 -- .../format/scavro/ScavroMethodRenamer.scala | 81 ---- .../scavro/ScavroNamespaceRenamer.scala | 48 --- .../format/scavro/ScavroScalaTreehugger.scala | 70 ---- .../avrohuggers/ScavroProtocolhugger.scala | 81 ---- .../avrohuggers/ScavroSchemahugger.scala | 72 ---- .../scavro/converters/JavaConverter.scala | 134 ------ .../scavro/converters/ScalaConverter.scala | 102 ----- .../scavro/trees/ScavroCaseClassTree.scala | 159 ------- .../scavro/trees/ScavroObjectTree.scala | 119 ------ .../format/scavro/trees/ScavroTraitTree.scala | 69 ---- .../specific/SpecificScalaTreehugger.scala | 4 +- .../specific/converters/JavaConverter.scala | 4 +- .../specific/converters/ScalaConverter.scala | 6 +- .../specific/methods/GetGenerator.scala | 2 +- .../specific/methods/GetSchemaGenerator.scala | 4 +- .../specific/methods/PutGenerator.scala | 2 +- .../trees/SpecificCaseClassTree.scala | 2 +- .../standard/StandardScalaTreehugger.scala | 5 +- .../avrohuggers/StandardProtocolhugger.scala | 2 +- .../avrohuggers/StandardSchemahugger.scala | 2 +- .../standard/trees/StandardTraitTree.scala | 2 +- .../main/scala/generators/FileGenerator.scala | 2 +- .../scala/generators/StringGenerator.scala | 2 +- .../scala/input/NestedSchemaExtractor.scala | 2 +- .../input/parsers/StringInputParser.scala | 27 +- .../scala/input/parsers/TreeInputParser.scala | 387 ------------------ .../PackageSplitter.scala | 62 --- .../input/reflectivecompilation/Toolbox.scala | 11 - .../schemagen/EnumSchemaGenerator.scala | 42 -- .../schemagen/FieldSchemaGenerator.scala | 109 ----- .../schemagen/RecordSchemaGenerator.scala | 77 ---- .../scala/matchers/DefaultValueMatcher.scala | 3 +- .../src/main/scala/matchers/JSONMatcher.scala | 70 ---- .../src/main/scala/matchers/TypeMatcher.scala | 3 - .../matchers/custom/CustomTypeMatcher.scala | 2 +- .../src/main/scala/stores/SchemaStore.scala | 10 +- .../stores/TypecheckDependencyStore.scala | 17 - .../expected/comments/scavro/Example4.scala | 50 --- .../expected/comments/scavro/Example5.scala | 48 --- .../expected/comments/scavro/NoSpaces1.scala | 50 --- .../expected/comments/scavro/NoSpaces2.scala | 29 -- .../expected/comments/scavro/NoSpaces3.scala | 33 -- .../miguno/avro/model/twitter_schema.scala | 33 -- .../example/idl/array/ArrayAsScalaArray.scala | 38 -- .../example/idl/array/ArrayAsScalaList.scala | 38 -- .../example/idl/array/ArrayAsScalaSeq.scala | 38 -- .../idl/array/ArrayAsScalaVector.scala | 38 -- .../example/idl/case/model/Defaults.scala | 127 ------ .../idl/case/model/ImportProtocol.scala | 84 ---- .../example/idl/java/model/DefaultEnum.java | 13 - .../example/idl/java/model/Defaults.scala | 118 ------ .../idl/java/model/ImportProtocol.scala | 84 ---- .../scavro/example/idl/model/BinaryIdl.scala | 32 -- .../scavro/example/idl/model/Defaults.scala | 123 ------ .../example/idl/model/EnumProtocol.scala | 45 -- .../example/idl/model/ImportProtocol.scala | 84 ---- .../scavro/example/idl/model/Names.scala | 28 -- .../example/idl/model/NestedProtocol.scala | 70 ---- .../scavro/example/idl/model/Recursive.scala | 34 -- .../example/idl/seq/model/Defaults.scala | 127 ------ .../example/idl/string/model/Defaults.scala | 98 ----- .../idl/string/model/ImportProtocol.scala | 74 ---- .../scavro/example/model/BinarySc.scala | 32 -- .../scavro/example/model/ClashInner.scala | 46 --- .../scavro/example/model/ClashOuter.scala | 50 --- .../scavro/example/model/ClashRecord.scala | 30 -- .../scavro/example/model/Compass.scala | 38 -- .../scavro/example/model/Direction.scala | 7 - .../scavro/example/model/Level0.scala | 28 -- .../scavro/example/model/Level1.scala | 28 -- .../scavro/example/model/Level2.scala | 28 -- .../expected/scavro/example/model/Suit.scala | 7 - .../expected/scavro/example/model/User.scala | 40 -- .../scavro/example/proto/model/BinaryPr.scala | 32 -- .../example/proto/model/EnumProtocol.scala | 45 -- .../scavro/example/proto/model/Message.scala | 28 -- .../scavro/model/model/UnionRecord.scala | 28 -- .../scavro/model/v2/model/NestedRecord.scala | 38 -- .../other/ns/case/ExternalDependency.scala | 28 -- .../expected/scavro/other/ns/case/Suit.scala | 11 - .../other/ns/java/ExternalDependency.scala | 28 -- .../expected/scavro/other/ns/java/Suit.java | 15 - .../other/ns/model/ExternalDependency.scala | 28 -- .../expected/scavro/other/ns/model/Suit.scala | 7 - .../other/ns/string/ExternalDependency.scala | 28 -- .../scavro/test/model/Calculator.scala | 110 ----- .../model/ComplexExternalDependency.scala | 36 -- .../expected/scavro/test/model/Joystick.scala | 48 --- .../specific/example/idl/EnumProtocol.scala | 45 -- .../specific/example/proto/EnumProtocol.scala | 45 -- .../array/scala-3.3/ArrayAsScalaArray.scala | 40 ++ .../array/scala-3.3/ArrayAsScalaList.scala | 40 ++ .../idl/array/scala-3.3/ArrayAsScalaSeq.scala | 40 ++ .../array/scala-3.3/ArrayAsScalaVector.scala | 40 ++ .../specific/SpecificCustomEnumSpec.scala | 8 +- .../specific/SpecificFileToFileSpec.scala | 8 +- .../specific/SpecificFileToStringsSpec.scala | 4 +- .../specific/SpecificStringToFileSpec.scala | 23 +- .../standard/StandardCustomEnumSpec.scala | 12 +- .../src/test/scala/util/AvrohuggerSpec.scala | 14 +- .../src/main/scala/tool/GeneratorTool.scala | 57 +-- .../src/main/scala/tool/Runner.scala | 4 +- .../avro/examples/baseball/Mascot.scala | 28 -- .../avro/examples/baseball/Nickname.scala | 28 -- .../avro/examples/baseball/Player.scala | 38 -- .../avro/examples/baseball/Wrestler.scala | 38 -- .../com/miguno/avro/twitter_schema.scala | 33 -- .../example/proto/model/Message.scala | 28 -- .../avro/examples/baseball/Player_3.scala | 58 +++ .../avro/examples/baseball/Wrestler_3.scala | 58 +++ .../src/test/scala/Directory.scala | 32 +- .../test/scala/ScavroGeneratorToolSpec.scala | 70 ---- .../scala/SpecificGeneratorToolSpec.scala | 17 +- .../scala/StandardGeneratorToolSpec.scala | 2 +- build.sbt | 10 +- project/build.properties | 2 +- 123 files changed, 396 insertions(+), 5075 deletions(-) delete mode 100644 avrohugger-core/src/main/scala/format/Scavro.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/ScavroImporter.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/ScavroJavaTreehugger.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/ScavroMethodRenamer.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/ScavroNamespaceRenamer.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/ScavroScalaTreehugger.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/avrohuggers/ScavroProtocolhugger.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/avrohuggers/ScavroSchemahugger.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/converters/JavaConverter.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/converters/ScalaConverter.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/trees/ScavroCaseClassTree.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/trees/ScavroObjectTree.scala delete mode 100644 avrohugger-core/src/main/scala/format/scavro/trees/ScavroTraitTree.scala delete mode 100644 avrohugger-core/src/main/scala/input/parsers/TreeInputParser.scala delete mode 100644 avrohugger-core/src/main/scala/input/reflectivecompilation/PackageSplitter.scala delete mode 100644 avrohugger-core/src/main/scala/input/reflectivecompilation/Toolbox.scala delete mode 100644 avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/EnumSchemaGenerator.scala delete mode 100644 avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/FieldSchemaGenerator.scala delete mode 100644 avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/RecordSchemaGenerator.scala delete mode 100644 avrohugger-core/src/main/scala/matchers/JSONMatcher.scala delete mode 100644 avrohugger-core/src/main/scala/stores/TypecheckDependencyStore.scala delete mode 100644 avrohugger-core/src/test/expected/comments/scavro/Example4.scala delete mode 100644 avrohugger-core/src/test/expected/comments/scavro/Example5.scala delete mode 100644 avrohugger-core/src/test/expected/comments/scavro/NoSpaces1.scala delete mode 100644 avrohugger-core/src/test/expected/comments/scavro/NoSpaces2.scala delete mode 100644 avrohugger-core/src/test/expected/comments/scavro/NoSpaces3.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/com/miguno/avro/model/twitter_schema.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaArray.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaList.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaSeq.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaVector.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/case/model/Defaults.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/case/model/ImportProtocol.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/java/model/DefaultEnum.java delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/java/model/Defaults.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/java/model/ImportProtocol.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/model/BinaryIdl.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/model/Defaults.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/model/EnumProtocol.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/model/ImportProtocol.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/model/Names.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/model/NestedProtocol.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/model/Recursive.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/seq/model/Defaults.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/string/model/Defaults.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/idl/string/model/ImportProtocol.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/BinarySc.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/ClashInner.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/ClashOuter.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/ClashRecord.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/Compass.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/Direction.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/Level0.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/Level1.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/Level2.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/Suit.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/model/User.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/proto/model/BinaryPr.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/proto/model/EnumProtocol.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/example/proto/model/Message.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/model/model/UnionRecord.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/model/v2/model/NestedRecord.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/other/ns/case/ExternalDependency.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/other/ns/case/Suit.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/other/ns/java/ExternalDependency.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/other/ns/java/Suit.java delete mode 100644 avrohugger-core/src/test/expected/scavro/other/ns/model/ExternalDependency.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/other/ns/model/Suit.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/other/ns/string/ExternalDependency.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/test/model/Calculator.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/test/model/ComplexExternalDependency.scala delete mode 100644 avrohugger-core/src/test/expected/scavro/test/model/Joystick.scala delete mode 100644 avrohugger-core/src/test/expected/specific/example/idl/EnumProtocol.scala delete mode 100644 avrohugger-core/src/test/expected/specific/example/proto/EnumProtocol.scala create mode 100644 avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaArray.scala create mode 100644 avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaList.scala create mode 100644 avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaSeq.scala create mode 100644 avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaVector.scala delete mode 100644 avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Mascot.scala delete mode 100644 avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Nickname.scala delete mode 100644 avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Player.scala delete mode 100644 avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Wrestler.scala delete mode 100644 avrohugger-tools/src/test/compiler/output-scavro/com/miguno/avro/twitter_schema.scala delete mode 100644 avrohugger-tools/src/test/compiler/output-scavro/example/proto/model/Message.scala create mode 100644 avrohugger-tools/src/test/compiler/output-specific/avro/examples/baseball/Player_3.scala create mode 100644 avrohugger-tools/src/test/compiler/output-specific/avro/examples/baseball/Wrestler_3.scala delete mode 100644 avrohugger-tools/src/test/scala/ScavroGeneratorToolSpec.scala diff --git a/README.md b/README.md index 1863de5f..27c46c88 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,6 @@ API](https://avro.apache.org/docs/1.11.1/getting-started-java/#serializing-and-d therefore have mutable `var` fields (for use with the Avro Specific API - Scalding, Spark, Avro, etc.). -* `Scavro` (`@deprecated` since avrohugger v1.5.0) Case classes with immutable fields, intended to wrap Java generated -Avro classes (for use with the [Scavro](https://github.com/oedura/scavro#scavro-reader-and-writer) -runtime, Java classes provided separately (see [Scavro Plugin](https://github.com/oedura/scavro#scavro-plugin) or [sbt-avro](https://github.com/sbt/sbt-avro))). - ##### Supports generating case classes with arbitrary fields of the following datatypes: |Avro|`Standard`|`SpecificRecord`|Notes| @@ -115,7 +111,7 @@ _Note:_ Currently [Treehugger](http://eed3si9n.com/treehugger/comments.html#Scal * **Library For Scala 2.12, and 2.13** * **Parses Schemas and IDLs with Avro version 1.11** -* **Generates Code Compatible with Scala 2.12, 2.13** +* **Generates Code Compatible with Scala 2.12, 2.13, 3** @@ -123,13 +119,13 @@ _Note:_ Currently [Treehugger](http://eed3si9n.com/treehugger/comments.html#Scal ##### Get the dependency with: - "com.julianpeeters" %% "avrohugger-core" % "1.7.0" + "com.julianpeeters" %% "avrohugger-core" % "2.8.0" ##### Description: -Instantiate a `Generator` with `Standard`, `Scavro`, or `SpecificRecord` source -formats. Then use +Instantiate a `Generator` with `Standard` or `SpecificRecord` source formats. +Then use `tToFile(input: T, outputDir: String): Unit` @@ -214,7 +210,7 @@ namespace rewritten. Multiple conflicting wildcards are not permitted. ##### Get the dependency with: - "com.julianpeeters" %% "avrohugger-filesorter" % "1.7.0" + "com.julianpeeters" %% "avrohugger-filesorter" % "2.8.0" ##### Description: @@ -234,22 +230,17 @@ To ensure dependent schemas are compiled in the proper order (thus avoiding `org #### `avrohugger-tools` - Download the avrohugger-tools jar for Scala [2.12](https://search.maven.org/remotecontent?filepath=com/julianpeeters/avrohugger-tools_2.12/1.7.0/avrohugger-tools_2.12-1.7.0-assembly.jar), or Scala [2.13](https://search.maven.org/remotecontent?filepath=com/julianpeeters/avrohugger-tools_2.13/1.7.0/avrohugger-tools_2.13-1.7.0-assembly.jar) (>30MB!) and use it like the avro-tools jar `Usage: [-string] (schema|protocol|datafile) input... outputdir`: + Download the avrohugger-tools jar for Scala [2.12](https://search.maven.org/remotecontent?filepath=com/julianpeeters/avrohugger-tools_2.12/2.8.0/avrohugger-tools_2.12-2.8.0-assembly.jar), or Scala [2.13](https://search.maven.org/remotecontent?filepath=com/julianpeeters/avrohugger-tools_2.13/2.8.0/avrohugger-tools_2.13-2.8.0-assembly.jar) (>30MB!) and use it like the avro-tools jar `Usage: [-string] (schema|protocol|datafile) input... outputdir`: * `generate` generates Scala case class definitions: -`java -jar /path/to/avrohugger-tools_2.12-1.7.0-assembly.jar generate schema user.avsc . ` +`java -jar /path/to/avrohugger-tools_2.12-2.8.0-assembly.jar generate schema user.avsc . ` * `generate-specific` generates definitions that extend Avro's `SpecificRecordBase`: -`java -jar /path/to/avrohugger-tools_2.12-1.7.0-assembly.jar generate-specific schema user.avsc . ` - - -* `generate-scavro` (`@deprecated` since avrohugger v1.5.0) generates definitions that extend Scavro's `AvroSerializable`: - -`java -jar /path/to/avrohugger-tools_2.12-1.7.0-assembly.jar generate-scavro schema user.avsc . ` +`java -jar /path/to/avrohugger-tools_2.12-2.8.0-assembly.jar generate-specific schema user.avsc . ` ## Warnings diff --git a/avrohugger-core/src/main/scala/format/Scavro.scala b/avrohugger-core/src/main/scala/format/Scavro.scala deleted file mode 100644 index 7e243520..00000000 --- a/avrohugger-core/src/main/scala/format/Scavro.scala +++ /dev/null @@ -1,200 +0,0 @@ -package avrohugger -package format - -import format.abstractions.SourceFormat -import format.scavro.{ - ScavroNamespaceRenamer, - ScavroJavaTreehugger, - ScavroScalaTreehugger -} -import matchers.TypeMatcher -import models.CompilationUnit -import stores.{ ClassStore, SchemaStore } -import types._ - -import treehugger.forest._ -import definitions.RootClass - -import org.apache.avro.{ Protocol, Schema } -import org.apache.avro.Schema.Type.{ ENUM, RECORD } - -object Scavro extends SourceFormat { - - val toolName = "generate-scavro" - val toolShortDescription = "Generates Scala wrapper code for the given schema." - - val javaTreehugger = ScavroJavaTreehugger - - val scalaTreehugger = ScavroScalaTreehugger - - val defaultTypes: AvroScalaTypes = AvroScalaTypes.defaults.copy(array = ScalaArray) - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def asCompilationUnits( - classStore: ClassStore, - maybeNamespace: Option[String], - schemaOrProtocol: Either[Schema, Protocol], - schemaStore: SchemaStore, - maybeOutDir: Option[String], - typeMatcher: TypeMatcher, - restrictedFields: Boolean, - targetScalaPartialVersion: String): List[CompilationUnit] = { - - registerTypes(schemaOrProtocol, classStore, typeMatcher) - - // By default, Scavro format generates Scala classes in packages that are - // the same as the Java package with `model` appended. - val maybeScavroModelNamespace: Option[String] = - ScavroNamespaceRenamer.renameNamespace( - maybeNamespace, - schemaOrProtocol, - typeMatcher) - - val enumType = typeMatcher.avroScalaTypes.enum - - schemaOrProtocol match { - case Left(schema) => { - schema.getType match { - case RECORD => { - val scalaCompilationUnit = getScalaCompilationUnit( - classStore, - maybeScavroModelNamespace, - schemaOrProtocol, - typeMatcher, - schemaStore, - maybeOutDir, - restrictedFields, - targetScalaPartialVersion) - List(scalaCompilationUnit) - } - case ENUM => { - enumType match { - // java enums can't be represented as trees so they can't be - // handled by treehugger. Their compilation unit must de generated - // separately, and they will be excluded from scala compilation - // units. - case JavaEnum => { - val javaCompilationUnit = getJavaEnumCompilationUnit( - classStore, - maybeScavroModelNamespace, - schema, - maybeOutDir, - typeMatcher) - List(javaCompilationUnit) - } - case ScalaEnumeration => { - val scalaCompilationUnit = getScalaCompilationUnit( - classStore, - maybeScavroModelNamespace, - schemaOrProtocol, - typeMatcher, - schemaStore, - maybeOutDir, - restrictedFields, - targetScalaPartialVersion) - List(scalaCompilationUnit) - } - case ScalaCaseObjectEnum => { - val scalaCompilationUnit = getScalaCompilationUnit( - classStore, - maybeScavroModelNamespace, - schemaOrProtocol, - typeMatcher, - schemaStore, - maybeOutDir, - restrictedFields, - targetScalaPartialVersion) - List(scalaCompilationUnit) - } - case EnumAsScalaString => { - List.empty - } - } - - } - case _ => sys.error("Only RECORD or ENUM can be toplevel definitions") - } - } - case Right(protocol) => { - val scalaCompilationUnit = getScalaCompilationUnit( - classStore, - maybeScavroModelNamespace, - Right(protocol), - typeMatcher, - schemaStore, - maybeOutDir, - restrictedFields, - targetScalaPartialVersion) - enumType match { - // java enums can't be represented as trees so they can't be - // handled by treehugger. Their compilation unit must de generated - // separately, and they will be excluded from scala compilation - // units. - case JavaEnum => { - val localSubtypes = getLocalSubtypes(protocol) - val localRecords = localSubtypes.filterNot(isEnum) - val localEnums = localSubtypes.filter(isEnum) - val javaCompilationUnits = localEnums.map(schema => { - getJavaEnumCompilationUnit( - classStore, - maybeScavroModelNamespace, - schema, - maybeOutDir, - typeMatcher) - }) - if (localRecords.length >= 1) scalaCompilationUnit +: javaCompilationUnits - else javaCompilationUnits - } - case ScalaCaseObjectEnum => List(scalaCompilationUnit) - case ScalaEnumeration => List(scalaCompilationUnit) - case EnumAsScalaString => List(scalaCompilationUnit) - } - } - } - } - - def getName( - schemaOrProtocol: Either[Schema, Protocol], - typeMatcher: TypeMatcher): String = { - schemaOrProtocol match { - case Left(schema) => schema.getName - case Right(protocol) => { - val enumType = typeMatcher.avroScalaTypes.enum - val localSubTypes = enumType match { - case JavaEnum => getLocalSubtypes(protocol).filterNot(isEnum) - case ScalaCaseObjectEnum => getLocalSubtypes(protocol) - case ScalaEnumeration => getLocalSubtypes(protocol) - case EnumAsScalaString => getLocalSubtypes(protocol).filterNot(isEnum) - } - if (localSubTypes.length > 1) protocol.getName - else localSubTypes.headOption match { - case Some(schema) => schema.getName - case None => protocol.getName - } - } - } - } - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def compile( - classStore: ClassStore, - maybeNamespace: Option[String], - schemaOrProtocol: Either[Schema, Protocol], - outDir: String, - schemaStore: SchemaStore, - typeMatcher: TypeMatcher, - restrictedFields: Boolean, - targetScalaPartialVersion: String): Unit = { - val compilationUnits: List[CompilationUnit] = asCompilationUnits( - classStore, - maybeNamespace, - schemaOrProtocol, - schemaStore, - Some(outDir), - typeMatcher, - restrictedFields, - targetScalaPartialVersion) - compilationUnits.foreach(writeToFile) - } - -} diff --git a/avrohugger-core/src/main/scala/format/SpecificRecord.scala b/avrohugger-core/src/main/scala/format/SpecificRecord.scala index bf9a6656..7bee2d0d 100644 --- a/avrohugger-core/src/main/scala/format/SpecificRecord.scala +++ b/avrohugger-core/src/main/scala/format/SpecificRecord.scala @@ -27,7 +27,7 @@ object SpecificRecord extends SourceFormat{ val javaTreehugger = SpecificJavaTreehugger val scalaTreehugger = SpecificScalaTreehugger - val defaultTypes: AvroScalaTypes = AvroScalaTypes.defaults.copy(enum = JavaEnum) + val defaultTypes: AvroScalaTypes = AvroScalaTypes.defaults.copy(`enum` = JavaEnum) def asCompilationUnits( classStore: ClassStore, @@ -40,7 +40,7 @@ object SpecificRecord extends SourceFormat{ targetScalaPartialVersion: String): List[CompilationUnit] = { registerTypes(schemaOrProtocol, classStore, typeMatcher) - val enumType = typeMatcher.avroScalaTypes.enum + val enumType = typeMatcher.avroScalaTypes.`enum` val namespace = CustomNamespaceMatcher.checkCustomNamespace( diff --git a/avrohugger-core/src/main/scala/format/Standard.scala b/avrohugger-core/src/main/scala/format/Standard.scala index 2aa75488..81a19f6d 100644 --- a/avrohugger-core/src/main/scala/format/Standard.scala +++ b/avrohugger-core/src/main/scala/format/Standard.scala @@ -38,7 +38,7 @@ object Standard extends SourceFormat { typeMatcher, maybeDefaultNamespace = ns) - val enumType = typeMatcher.avroScalaTypes.enum + val enumType = typeMatcher.avroScalaTypes.`enum` schemaOrProtocol match { case Left(schema) => { @@ -179,7 +179,7 @@ object Standard extends SourceFormat { schemaOrProtocol match { case Left(schema) => schema.getName case Right(protocol) => { - val localSubTypes = typeMatcher.avroScalaTypes.enum match { + val localSubTypes = typeMatcher.avroScalaTypes.`enum` match { case JavaEnum => getLocalSubtypes(protocol).filterNot(isEnum) case ScalaCaseObjectEnum => getLocalSubtypes(protocol) case ScalaEnumeration => getLocalSubtypes(protocol) diff --git a/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala b/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala index 7284daae..54ebf5f8 100644 --- a/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala +++ b/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala @@ -80,7 +80,7 @@ trait SourceFormat { def fileExt( schemaOrProtocol: Either[Schema, Protocol], typeMatcher: TypeMatcher): String = { - val enumType = typeMatcher.avroScalaTypes.enum + val enumType = typeMatcher.avroScalaTypes.`enum` def enumExt: String = enumType match { case JavaEnum => ".java" case ScalaCaseObjectEnum => ".scala" @@ -177,7 +177,7 @@ trait SourceFormat { classStore: ClassStore, typeMatcher: TypeMatcher): Unit = { def registerSchema(schema: Schema): Unit = { - val typeName = typeMatcher.avroScalaTypes.enum match { + val typeName = typeMatcher.avroScalaTypes.`enum` match { case JavaEnum => schema.getName case ScalaCaseObjectEnum => schema.getName case ScalaEnumeration => renameEnum(schema, "Value") diff --git a/avrohugger-core/src/main/scala/format/scavro/ScavroImporter.scala b/avrohugger-core/src/main/scala/format/scavro/ScavroImporter.scala deleted file mode 100644 index a97c7fed..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/ScavroImporter.scala +++ /dev/null @@ -1,194 +0,0 @@ -package avrohugger -package format -package scavro - -import avrohugger.format.abstractions.Importer -import avrohugger.input.DependencyInspector -import avrohugger.matchers.TypeMatcher -import avrohugger.stores.SchemaStore -import avrohugger.types._ -import org.apache.avro.{Protocol, Schema} -import treehugger.forest._ -import definitions._ -import treehuggerDSL._ - -import scala.jdk.CollectionConverters._ - -object ScavroImporter extends Importer { - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def asRenamedImportTree(imported: Import) = { - val packageSym = imported.expr - val typeNames = imported.selectors.map(s => treeToString(s.name)) - val renames = typeNames.distinct.sorted.map(typeName => { - val renamedType = "J" + typeName - RENAME(typeName) ==> renamedType - }) - IMPORT(packageSym, renames) - } - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def getImports( - schemaOrProtocol: Either[Schema, Protocol], - currentNamespace: Option[String], - schemaStore: SchemaStore, - typeMatcher: TypeMatcher): List[Import] = { - - def checkJavaConversions(schemaOrProtocol: Either[Schema, Protocol]): Option[Import] = { - - def checkForArrays(schema: Schema, used: List[Schema] = List.empty): List[Schema] = { - schema.getType match { - case Schema.Type.MAP => - checkForArrays(schema.getValueType, used) - case Schema.Type.RECORD => - getFieldSchemas(schema).flatMap(s => { - if (used.contains(s)) List(s) - else checkForArrays(s, used :+ s) - }) - case Schema.Type.UNION => - val types = schema.getTypes().asScala - if (types.length != 2 || - !types.map(x => x.getType).contains(Schema.Type.NULL) || - types.filterNot(x => x.getType == Schema.Type.NULL).length != 1) { - sys.error("Unions beyond nullable fields are not supported") - } - else { - val maybeType = types.find(x => x.getType != Schema.Type.NULL) - maybeType match { - case Some(s) => checkForArrays(s, used) - case None => sys.error("There was no type in this union") - } - } - case _ => List(schema) - } - } - - val schemas: List[Schema] = schemaOrProtocol match { - case Left(schema) => checkForArrays(schema) - case Right(protocol) => { - protocol.getTypes().asScala.toList - .filter(schema => isRecord(schema)) - .flatMap(schema => checkForArrays(schema)) - } - } - - val hasArrayField: Boolean = - schemas.map(schema => schema.getType).contains(Schema.Type.ARRAY) - - val convPackage = RootClass.newClass("scala.jdk.CollectionConverters") - val javaConvertersImport = IMPORT(convPackage, "_") - - if(hasArrayField) Some(javaConvertersImport) - else None - } - - lazy val SchemaClass = RootClass.newClass("org.apache.avro.Schema") - lazy val ScavroPackage = RootClass.newPackage("org.oedura.scavro") - - lazy val schemaImport = IMPORT(SchemaClass) - lazy val scavroImport = IMPORT( - ScavroPackage, - "AvroMetadata", - "AvroReader", - "AvroSerializeable") - - lazy val baseImports: List[Import] = - List(schemaImport, scavroImport) - lazy val maybeJavaConversionsImport: Option[Import] = - checkJavaConversions(schemaOrProtocol) - - // gets all record schemas, including the root schema, which need renaming - def getAllRecordSchemas(topLevelSchemas: List[Schema]): List[Schema] = { - topLevelSchemas - .filter(isRecord) - .flatMap(schema => schema +: getFieldSchemas(schema)) - .distinct - } - - // gets imported Java model classes, returning them as Import trees - def getJavaRecordImports( - recordSchemas: List[Schema], - namespace: Option[String], - typeMatcher: TypeMatcher): List[Import] = { - - def asImportDef(packageName: String, fields: List[Schema]): Import = { - val importedPackageSym = RootClass.newClass(packageName) - val importedTypes = - fields.map(field => DependencyInspector.getReferredTypeName(field)) - IMPORT(importedPackageSym, importedTypes) - } - - def requiresImportDef( - schema: Schema, - typeMatcher: TypeMatcher): Boolean = { - def isTopLevel(schema: Schema) = typeMatcher.avroScalaTypes.enum match { - case EnumAsScalaString => - isRecord(schema) - case JavaEnum | ScalaEnumeration | ScalaCaseObjectEnum => - (isRecord(schema) || (isEnum(schema))) - } - isTopLevel(schema) && Option(schema.getNamespace) != namespace - } - - recordSchemas - .filter(schema => requiresImportDef(schema, typeMatcher)) - .groupBy(schema => Option(schema.getNamespace).getOrElse("")) - .toList - .map(group => group match { - case(packageName, fields) => asImportDef(packageName, fields) - }) - } - - // gets imported Scavro model classes, returning them as Import trees - def getTopLevelImports( - recordSchemas: List[Schema], - namespace: Option[String]): List[Import] = { - recordSchemas - .filter(schema => DependencyInspector.getReferredNamespace(schema).isDefined) - .filter(schema => { - val renamedNamespace = ScavroNamespaceRenamer.renameNamespace( - DependencyInspector.getReferredNamespace(schema), - Left(schema), - typeMatcher) - renamedNamespace != namespace - }) - .groupBy(schema => { - val renamedNamespace = ScavroNamespaceRenamer.renameNamespace( - DependencyInspector.getReferredNamespace(schema), - Left(schema), - typeMatcher) - renamedNamespace.get - }) - .toList.map(group => group match { - case(packageName, fields) => { - val importedPackageSym = RootClass.newClass(packageName) - val importedTypes = fields.map(field => DependencyInspector.getReferredTypeName(field)) - IMPORT(importedPackageSym, importedTypes) - } - }) - } - val topLevelSchemas = getTopLevelSchemas(schemaOrProtocol, schemaStore, typeMatcher) - - val allRecordSchemas = getAllRecordSchemas(topLevelSchemas) - val scalaRecordImports = getUserDefinedImports( - allRecordSchemas, - currentNamespace, - typeMatcher) - - val javaRecordImports = getJavaRecordImports( - allRecordSchemas, - currentNamespace, - typeMatcher) - - val renamedJavaImports = javaRecordImports.map(asRenamedImportTree) - val scalaRecords = getRecordSchemas(topLevelSchemas) - val enumSchemas = getEnumSchemas(topLevelSchemas) - val scalaImports = getTopLevelImports(scalaRecords ++ enumSchemas, currentNamespace) - - val recordImports = (scalaImports ++ renamedJavaImports).distinct - - if (allRecordSchemas.isEmpty) List.empty - else baseImports ++ recordImports ++ maybeJavaConversionsImport - } - -} diff --git a/avrohugger-core/src/main/scala/format/scavro/ScavroJavaTreehugger.scala b/avrohugger-core/src/main/scala/format/scavro/ScavroJavaTreehugger.scala deleted file mode 100644 index 005dcf9f..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/ScavroJavaTreehugger.scala +++ /dev/null @@ -1,42 +0,0 @@ -package avrohugger -package format -package scavro - -import format.abstractions.JavaTreehugger -import stores.ClassStore -import org.apache.avro.Schema - - -object ScavroJavaTreehugger extends JavaTreehugger { - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def asJavaCodeString( - classStore: ClassStore, - namespace: Option[String], - schema: Schema): String = { - - // Avro's SpecificCompiler only writes files, but we need a string - // so write the Java file and read - val tempDir = createTempDir("avrohugger_scavro") - writeJavaTempFile(schema, tempDir) - val tempPath = s"$tempDir/${schema.getFullName.replace('.','/')}.java" - val fileContents = scala.io.Source.fromFile(tempPath) - val schemaPackage = "package " + schema.getNamespace - val updatedPackage = namespace match { - case Some(ns) => "package " + ns - case None => "" - } - val schemaNamespace = """\"namespace\":\"""" +schema.getNamespace+ """\",""" - val updatedNamespace = namespace match { - case Some(ns) => """\"namespace\":\"""" + ns + """\",""" - case None => "" - } - val codeString = fileContents.mkString - .replace(schemaPackage, updatedPackage) - .replace(schemaNamespace, updatedNamespace) - fileContents.close - deleteTempDirOnExit(tempDir) - codeString - } - -} diff --git a/avrohugger-core/src/main/scala/format/scavro/ScavroMethodRenamer.scala b/avrohugger-core/src/main/scala/format/scavro/ScavroMethodRenamer.scala deleted file mode 100644 index 564f2215..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/ScavroMethodRenamer.scala +++ /dev/null @@ -1,81 +0,0 @@ -package avrohugger -package format -package scavro - -import org.apache.avro.Schema -import org.apache.avro.Schema.Field -import org.apache.avro.compiler.specific.SpecificCompiler - -import scala.jdk.CollectionConverters._ - -object ScavroMethodRenamer { - - /** Adapted from: https://github.com/apache/avro/blob/master/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java#L867 - * Generates a method name from a field name. - * @param schema the schema in which the field is defined. - * @param field the field for which to generate the accessor name. - * @param prefix method name prefix, e.g. "get" or "set". - * @param postfix method name postfix, e.g. "" or "Builder". - * @return the generated method name. - */ - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def generateMethodName( - schema: Schema, - field: Field, - prefix: String, - postfix: String): String = { - - /* Reserved words for accessor/mutator methods */ - var ACCESSOR_MUTATOR_RESERVED_WORDS: java.util.Set[String] = - ((Set("class", "schema", "classSchema") ++ Scavro.RESERVED_WORDS)).asJava - - /* Reserved words for error types */ - val ERROR_RESERVED_WORDS: java.util.Set[String] = - (Set("message", "cause") ++ ACCESSOR_MUTATOR_RESERVED_WORDS.asScala).asJava - - // Check for the special case in which the schema defines two fields whose - // names are identical except for the case of the first character: - val firstChar: Char = field.name().charAt(0) - val conflictingFieldName: String = { - val s1 = if (Character.isLowerCase(firstChar)) Character.toUpperCase(firstChar) else Character.toLowerCase(firstChar) - val s2 = if (field.name().length() > 1) field.name().substring(1) else "" - s"$s1$s2" - } - val fieldNameConflict: Boolean = Option(schema.getField(conflictingFieldName)).isDefined - - val methodBuilder: StringBuilder = new StringBuilder(prefix) - val fieldName: String = - SpecificCompiler.mangle( - field.name(), - if(schema.isError()) ERROR_RESERVED_WORDS else ACCESSOR_MUTATOR_RESERVED_WORDS, - true) - - var nextCharToUpper: Boolean = true - (0 until fieldName.length).map(ii => { - if (fieldName.charAt(ii) == '_') { - nextCharToUpper = true - } - else if (nextCharToUpper) { - methodBuilder.append(Character.toUpperCase(fieldName.charAt(ii))) - nextCharToUpper = false - } - else { - methodBuilder.append(fieldName.charAt(ii)) - } - }) - methodBuilder.append(postfix) - - // If there is a field name conflict append $0 or $1 - if (fieldNameConflict) { - if (methodBuilder.charAt(methodBuilder.length - 1) != '$') { - methodBuilder.append('$') - } - methodBuilder.append(if(Character.isLowerCase(firstChar))'0' else '1') - } - - methodBuilder.toString() - } - - - -} \ No newline at end of file diff --git a/avrohugger-core/src/main/scala/format/scavro/ScavroNamespaceRenamer.scala b/avrohugger-core/src/main/scala/format/scavro/ScavroNamespaceRenamer.scala deleted file mode 100644 index 4824fe3f..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/ScavroNamespaceRenamer.scala +++ /dev/null @@ -1,48 +0,0 @@ -package avrohugger -package format -package scavro - -import avrohugger.matchers.TypeMatcher -import avrohugger.matchers.custom.CustomNamespaceMatcher -import org.apache.avro.{ Schema, Protocol } - -object ScavroNamespaceRenamer { - // By default, Scavro generates Scala classes in packages that are the same - // as the Java package with `model` appended. - // TypeMatcher is here because it holds the custom namespace map - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def renameNamespace( - maybeNamespace: Option[String], - schemaOrProtocol: Either[Schema, Protocol], - typeMatcher: TypeMatcher): Option[String] = { - - val scavroModelDefaultPackage: String = - typeMatcher.customNamespaces - .get("SCAVRO_DEFAULT_PACKAGE$") - .getOrElse("model") - - val someScavroModelDefaultNamespace = maybeNamespace match { - case Some(ns) => Some(ns + "." + scavroModelDefaultPackage) - case None => sys.error("Scavro requires a namespace because Java " + - "classes cannot be imported from the default package") - } - val scavroModelNamespace = { - val ns = schemaOrProtocol match { - case Left(schema) => Option(schema.getNamespace) - case Right(protocol) => Option(protocol.getNamespace) - } - ns match { - case Some(schemaNS) => { - CustomNamespaceMatcher.checkCustomNamespace( - ns, - typeMatcher, - maybeDefaultNamespace = someScavroModelDefaultNamespace) - } - case None => someScavroModelDefaultNamespace - } - } - - scavroModelNamespace - } - -} \ No newline at end of file diff --git a/avrohugger-core/src/main/scala/format/scavro/ScavroScalaTreehugger.scala b/avrohugger-core/src/main/scala/format/scavro/ScavroScalaTreehugger.scala deleted file mode 100644 index 70eff4f5..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/ScavroScalaTreehugger.scala +++ /dev/null @@ -1,70 +0,0 @@ -package avrohugger -package format -package scavro - -import format.abstractions.ScalaTreehugger -import avrohuggers.{ ScavroProtocolhugger, ScavroSchemahugger } -import matchers.TypeMatcher -import stores.{ ClassStore, SchemaStore } - -import org.apache.avro.{ Protocol, Schema } - -import treehugger.forest._ -import treehuggerDSL._ - -object ScavroScalaTreehugger extends ScalaTreehugger { - - val schemahugger = ScavroSchemahugger - val protocolhugger = ScavroProtocolhugger - val importer = ScavroImporter - - // SpecificCompiler can't return a tree for Java enums, so return - // a String here for a consistent api vis a vis *ToFile and *ToStrings - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def asScalaCodeString( - classStore: ClassStore, - namespace: Option[String], - schemaOrProtocol: Either[Schema, Protocol], - typeMatcher: TypeMatcher, - schemaStore: SchemaStore, - restrictedFields: Boolean, - targetScalaPartialVersion: String): String = { - - val imports: List[Import] = importer.getImports( - schemaOrProtocol, namespace, schemaStore, typeMatcher) - - val topLevelDefs: List[Tree] = schemaOrProtocol match { - case Left(schema) => schemahugger.toTrees( - schemaStore, - classStore, - namespace, - schema, - typeMatcher, - None, - None, - restrictedFields, - targetScalaPartialVersion - ) - case Right(protocol) => protocolhugger.toTrees( - schemaStore, - classStore, - namespace, - protocol, - typeMatcher, - None, - None, - restrictedFields, - targetScalaPartialVersion - ) - } - // wrap the imports and classdef in a block with a comment and a package - val tree = { - val blockContent = imports ++ topLevelDefs - if (namespace.isDefined) BLOCK(blockContent).inPackage(namespace.get) - else BLOCK(blockContent:_*).withoutPackage - }.withDoc("MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY") - - treeToString(tree) - } - -} diff --git a/avrohugger-core/src/main/scala/format/scavro/avrohuggers/ScavroProtocolhugger.scala b/avrohugger-core/src/main/scala/format/scavro/avrohuggers/ScavroProtocolhugger.scala deleted file mode 100644 index b89809d7..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/avrohuggers/ScavroProtocolhugger.scala +++ /dev/null @@ -1,81 +0,0 @@ -package avrohugger -package format -package scavro -package avrohuggers - -import format.abstractions.avrohuggers.Protocolhugger -import generators.ScalaDocGenerator -import matchers.TypeMatcher -import stores.{ClassStore, SchemaStore} -import trees.ScavroTraitTree -import types._ - -import org.apache.avro.Protocol - -import treehugger.forest._ - -object ScavroProtocolhugger extends Protocolhugger { - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def toTrees( - schemaStore: SchemaStore, - classStore: ClassStore, - namespace: Option[String], - protocol: Protocol, - typeMatcher: TypeMatcher, - maybeBaseTrait: Option[String], - maybeFlags: Option[List[Long]], - restrictedFields: Boolean, - targetScalaPartialVersion: String): List[Tree] = { - - val name: String = protocol.getName - val maybeNewBaseTrait = Some(name) - val maybeNewFlags = Some(List(Flags.FINAL.toLong)) - val traitDef = ScavroTraitTree.toADTRootDef(protocol, typeMatcher) - val localSubTypes = getLocalSubtypes(protocol) - val adtSubTypes = typeMatcher.avroScalaTypes.enum match { - case JavaEnum => localSubTypes.filterNot(isEnum) - case ScalaCaseObjectEnum => localSubTypes - case ScalaEnumeration => localSubTypes - case EnumAsScalaString => localSubTypes.filterNot(isEnum) - } - if (adtSubTypes.length > 1 && typeMatcher.avroScalaTypes.protocol == types.ScalaADT) { - traitDef +: localSubTypes.flatMap(schema => { - ScavroSchemahugger.toTrees( - schemaStore, - classStore, - namespace, - schema, - typeMatcher, - maybeNewBaseTrait, - maybeNewFlags, - restrictedFields, - targetScalaPartialVersion) - }) - } - // if only one Scala type is defined, then don't generate sealed trait - else { - // no sealed trait tree, but could still need a top-level doc - val docTrees = { - Option(protocol.getDoc) match { - case Some(doc) => - List(ScalaDocGenerator.docToScalaDoc(Right(protocol), EmptyTree)) - case None => List.empty - } - } - docTrees ::: adtSubTypes.flatMap(schema => { - ScavroSchemahugger.toTrees( - schemaStore, - classStore, - namespace, - schema, - typeMatcher, - maybeBaseTrait, - maybeFlags, - restrictedFields, - targetScalaPartialVersion) - }) - } - } - -} diff --git a/avrohugger-core/src/main/scala/format/scavro/avrohuggers/ScavroSchemahugger.scala b/avrohugger-core/src/main/scala/format/scavro/avrohuggers/ScavroSchemahugger.scala deleted file mode 100644 index ac75ebc7..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/avrohuggers/ScavroSchemahugger.scala +++ /dev/null @@ -1,72 +0,0 @@ -package avrohugger -package format -package scavro -package avrohuggers - -import format.abstractions.avrohuggers.Schemahugger -import trees.{ ScavroCaseClassTree, ScavroObjectTree, ScavroTraitTree } -import matchers.TypeMatcher -import stores.{ClassStore, SchemaStore} -import types._ - -import org.apache.avro.Schema -import org.apache.avro.Schema.Type.{ ENUM, RECORD } - -import treehugger.forest._ -import definitions._ - -object ScavroSchemahugger extends Schemahugger{ - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def toTrees( - schemaStore: SchemaStore, - classStore: ClassStore, - namespace: Option[String], - schema: Schema, - typeMatcher: TypeMatcher, - maybeBaseTrait: Option[String], - maybeFlags: Option[List[Long]], - restrictedFields: Boolean, - targetScalaPartialVersion: String): List[Tree] = { - val ScalaClass = RootClass.newClass(schema.getName) - val JavaClass = RootClass.newClass("J" + schema.getName) - schema.getType match { - case RECORD => - val caseClassDef = ScavroCaseClassTree.toCaseClassDef( - classStore, - namespace, - schema, - ScalaClass, - JavaClass, - typeMatcher, - maybeBaseTrait, - maybeFlags, - restrictedFields) - val companionDef = ScavroObjectTree.toCompanionDef( - classStore, - schema, - ScalaClass, - JavaClass, - typeMatcher, - maybeFlags) - List(caseClassDef, companionDef) - case ENUM => typeMatcher.avroScalaTypes.enum match { - case JavaEnum => - List.empty - case ScalaCaseObjectEnum => - ScavroTraitTree.toCaseObjectEnumDef(schema, maybeBaseTrait) - case ScalaEnumeration => - val objectDef = ScavroObjectTree.toScalaEnumDef( - classStore, - schema, - maybeBaseTrait, - maybeFlags) - List(objectDef) - case EnumAsScalaString => List.empty - } - case _ => - sys.error("Only RECORD and ENUM can be top-level definitions") - } - } - -} diff --git a/avrohugger-core/src/main/scala/format/scavro/converters/JavaConverter.scala b/avrohugger-core/src/main/scala/format/scavro/converters/JavaConverter.scala deleted file mode 100644 index 572a60cf..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/converters/JavaConverter.scala +++ /dev/null @@ -1,134 +0,0 @@ -package avrohugger -package format -package scavro -package converters - -import matchers.TypeMatcher -import stores.ClassStore -import types._ -import org.apache.avro.Schema -import treehugger.forest._ -import treehuggerDSL._ - -import scala.jdk.CollectionConverters._ - -class JavaConverter( - classStore: ClassStore, - namespace: Option[String], - typeMatcher: TypeMatcher) { - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def checkCustomNumberType( - numberType: AvroScalaNumberType, - defaultNumberType: AvroScalaNumberType, - tree: Tree, - nativeType: String): Tree = { - if (numberType == defaultNumberType) tree - else tree DOT nativeType - } - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def checkCustomEnumType( - schema: Schema, - enumType: AvroScalaEnumType, - tree: Tree): Tree = { - enumType match { - case EnumAsScalaString => tree - case JavaEnum | ScalaEnumeration | ScalaCaseObjectEnum => { - val conversionCases = schema.getEnumSymbols.asScala.map(enumSymbol => { - CASE(REF(schema.getName) DOT(enumSymbol)) ==> { - (REF("J" + schema.getName) DOT(enumSymbol)) - } - }) - tree MATCH(conversionCases) - } - } - } - - // Recursive definition takes a field's schema, and a tree that represents the - // source code to be written. The initial tree that is passed in is a - // REF("fieldName"), which is wrapped in a pattern match tree (e.g., to sort - // None and Some(x) if the field is a union). A Schema is passed in order to - // get access to the field's type parameters while the tree is built up. - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def convertToJava( - schema: Schema, - tree: Tree, - fieldPath: List[String] = List.empty): Tree = { - - schema.getType match { - case Schema.Type.ENUM => { - checkCustomEnumType(schema, typeMatcher.avroScalaTypes.`enum`, tree) - } - case Schema.Type.RECORD => { - tree DOT "toAvro" - } - case Schema.Type.UNION => { - val types = schema.getTypes().asScala - // check if it's the kind of union that we support (nullable fields) - if (types.length != 2 || - !types.map(x => x.getType).contains(Schema.Type.NULL) || - types.filterNot(x => x.getType == Schema.Type.NULL).length != 1) { - sys.error("Unions beyond nullable fields are not supported") - } - else { - val maybeType = types.find(x => x.getType != Schema.Type.NULL) - maybeType match { - case Some(schema) => - val convertedToJava = convertToJava(schema, REF("x"), fieldPath) - val conversionCases = List( - CASE(SOME(ID("x"))) ==> convertedToJava, - CASE(NONE) ==> NULL - ) - tree MATCH(conversionCases:_*) - case None => sys.error("There was no type in this union") - } - } - } - case Schema.Type.ARRAY => { - val elementType = { - typeMatcher.toJavaType(classStore, namespace, schema.getElementType) - } - val JavaArrayClass = TYPE_REF(REF("java.util.List") APPLYTYPE(elementType)) - val ArrayListClass = TYPE_REF(REF("java.util.ArrayList") APPLYTYPE(elementType)) - BLOCK( - VAL("array", JavaArrayClass) := NEW(ArrayListClass), - tree FOREACH( LAMBDA(PARAM("element")) ==> - BLOCK( - REF("array").DOT("add").APPLY(convertToJava(schema.getElementType, REF("element"), fieldPath)) - ) - ), - REF("array") - ) - } - case Schema.Type.MAP => { - val keyType = typeMatcher.avroStringType - val valueType = { - typeMatcher.toJavaType(classStore, namespace, schema.getValueType) - } - val JavaMapClass = TYPE_REF(REF("java.util.Map") APPLYTYPE(keyType, valueType)) - val HashMapClass = TYPE_REF(REF("java.util.HashMap") APPLYTYPE(keyType, valueType)) - val valueConversion = convertToJava(schema.getValueType, REF("value"), fieldPath) - BLOCK( - VAL("map", JavaMapClass) := NEW(HashMapClass), - tree FOREACH( LAMBDA(PARAM("kvp")) ==> - BLOCK( - VAL("key") := REF("kvp._1"), - VAL("value") := REF("kvp._2"), - REF("map").DOT("put").APPLY(REF("key"), valueConversion) - ) - ), - REF("map") - ) - } - case Schema.Type.INT => checkCustomNumberType(typeMatcher.avroScalaTypes.int, ScalaInt, tree, "toInt") - case Schema.Type.FLOAT => checkCustomNumberType(typeMatcher.avroScalaTypes.float, ScalaFloat, tree, "toFloat") - case Schema.Type.DOUBLE => checkCustomNumberType(typeMatcher.avroScalaTypes.double, ScalaDouble, tree, "toDouble") - case Schema.Type.LONG => checkCustomNumberType(typeMatcher.avroScalaTypes.long, ScalaLong, tree, "toLong") - case Schema.Type.FIXED => sys.error("the FIXED datatype is not yet supported") - case Schema.Type.BYTES => REF("java.nio.ByteBuffer") DOT "wrap" APPLY tree - case _ => tree - } - } - -} diff --git a/avrohugger-core/src/main/scala/format/scavro/converters/ScalaConverter.scala b/avrohugger-core/src/main/scala/format/scavro/converters/ScalaConverter.scala deleted file mode 100644 index a1cc1081..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/converters/ScalaConverter.scala +++ /dev/null @@ -1,102 +0,0 @@ -package avrohugger -package format -package scavro -package converters - -import matchers.TypeMatcher -import types._ - -import treehugger.forest._ -import definitions._ -import treehuggerDSL._ - -import org.apache.avro.Schema - -import scala.language.postfixOps -import scala.jdk.CollectionConverters._ - -class ScalaConverter(typeMatcher: TypeMatcher) { - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def convertFromJava( - schema: Schema, - tree: Tree, - fieldPath: List[String] = List.empty): Tree = { - - schema.getType match { - case Schema.Type.ENUM => typeMatcher.avroScalaTypes.enum match { - case EnumAsScalaString => tree TOSTRING - case JavaEnum | ScalaEnumeration | ScalaCaseObjectEnum => { - val conversionCases = schema.getEnumSymbols.asScala.map(enumSymbol => { - CASE(REF("J" + schema.getName) DOT(enumSymbol)) ==> (REF(schema.getName) DOT(enumSymbol)) - }) - tree MATCH(conversionCases) - } - } - case Schema.Type.RECORD => { - REF(schema.getName).DOT("metadata").DOT("fromAvro").APPLY(tree) - } - case Schema.Type.UNION => { - val types = schema.getTypes().asScala - // check if it's the kind of union that we support (i.e. nullable fields) - if (types.length != 2 || - !types.map(x => x.getType).contains(Schema.Type.NULL) || - types.filterNot(x => x.getType == Schema.Type.NULL).length != 1) { - sys.error("Unions beyond nullable fields are not supported") - } - // the union represents a nullable field, the kind of union supported in avrohugger - else { - val typeParamSchema = types.find(x => x.getType != Schema.Type.NULL).get - val nullConversion = CASE(NULL) ==> NONE - val someConversion = CASE(WILDCARD) ==> SOME(convertFromJava(typeParamSchema, tree, fieldPath)) - val conversionCases = List(nullConversion, someConversion) - tree MATCH(conversionCases:_*) - } - } - case Schema.Type.NULL => NULL - case Schema.Type.STRING => tree TOSTRING - case Schema.Type.INT => tree DOT "toInt" - case Schema.Type.FLOAT => tree DOT "toFloat" - case Schema.Type.DOUBLE => tree DOT "toDouble" - case Schema.Type.LONG => tree DOT "toLong" - - case Schema.Type.ARRAY => { - val seqArgs = SEQARG(tree DOT "asScala") - val collection = typeMatcher.avroScalaTypes.array match { - case ScalaArray => ARRAY(seqArgs) - case ScalaList => LIST(seqArgs) - case ScalaSeq => SEQ(seqArgs) - case ScalaVector => VECTOR(seqArgs) - } - collection MAP(LAMBDA(PARAM("x")) ==> BLOCK(convertFromJava(schema.getElementType, REF("x"), fieldPath))) - } - case Schema.Type.MAP => { - val JavaMap = RootClass.newClass("java.util.Map[_,_]") - val resultExpr = { - BLOCK( - REF("scala.jdk.CollectionConverters.mapAsScalaMapConverter") - .APPLY(REF("map")) - .DOT("asScala") - .DOT("toMap") - .MAP(LAMBDA(PARAM("kvp")) ==> BLOCK( - VAL("key") := REF("kvp._1").DOT("toString"), - VAL("value") := REF("kvp._2"), - PAREN(REF("key"), convertFromJava(schema.getValueType, REF("value"), fieldPath))) - ) - ) - } - val mapConversion = CASE(ID("map") withType(JavaMap)) ==> resultExpr - tree MATCH(mapConversion) - } - case Schema.Type.FIXED => sys.error("the FIXED datatype is not yet supported") - case Schema.Type.BYTES => { - val JavaBuffer = RootClass.newClass("java.nio.ByteBuffer") - tree MATCH CASE(ID("buffer") withType(JavaBuffer)) ==> Block( - REF("buffer") DOT "array" APPLY(Nil) - ) - } - case _ => tree - } - } - -} diff --git a/avrohugger-core/src/main/scala/format/scavro/trees/ScavroCaseClassTree.scala b/avrohugger-core/src/main/scala/format/scavro/trees/ScavroCaseClassTree.scala deleted file mode 100644 index 5908f6c3..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/trees/ScavroCaseClassTree.scala +++ /dev/null @@ -1,159 +0,0 @@ -package avrohugger -package format -package scavro -package trees - -import generators.ScalaDocGenerator -import converters.JavaConverter -import matchers.{ DefaultValueMatcher, TypeMatcher } -import stores.ClassStore -import org.apache.avro.Schema -import treehugger.forest._ -import treehuggerDSL._ - -import scala.jdk.CollectionConverters._ -import scala.language.postfixOps - -object ScavroCaseClassTree { - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def toCaseClassDef( - classStore: ClassStore, - namespace: Option[String], - schema: Schema, - ScalaClass: Symbol, - JavaClass: Symbol, - typeMatcher: TypeMatcher, - maybeBaseTrait: Option[String], - maybeFlags: Option[List[Long]], - restrictedFields: Boolean) = { - - val mixin = TYPE_REF(REF("AvroSerializeable")) - val avroFields = schema.getFields().asScala.toList - - val shouldGenerateSimpleClass = restrictedFields && avroFields.size > 22 - - val scalaClassParams: List[ValDef] = avroFields.map { f => - val fieldName = FieldRenamer.rename(f.name) - val fieldType = typeMatcher.toScalaType(classStore, namespace, f.schema) - val defaultValue = DefaultValueMatcher.getDefaultValue( - classStore, - namespace, - f, - typeMatcher) - PARAM(fieldName, fieldType) := defaultValue - } - - val scalaClassAccessors: List[Tree] = avroFields.map(field => { - val javaConverter = new JavaConverter(classStore, namespace, typeMatcher) - javaConverter.convertToJava(field.schema, REF(FieldRenamer.rename(field.name))) - }) - - val maybeFlagsWithCaseClassFinal = - if (shouldGenerateSimpleClass) maybeFlags - else maybeFlags.map { flags => - if (flags.contains(Flags.FINAL)) flags - else flags :+ Flags.FINAL.toLong - } - - - // There could be base traits, flags, or both, and could have no fields - val caseClassDef = (maybeBaseTrait, maybeFlagsWithCaseClassFinal) match { - case (Some(baseTrait), Some(flags)) => - if (shouldGenerateSimpleClass) { - CLASSDEF(ScalaClass) - .withFlags(flags:_*) - .withParams(scalaClassParams) - .withParents(mixin) - .withParents(baseTrait) - } - else if (!avroFields.isEmpty) { - CASECLASSDEF(ScalaClass) - .withFlags(flags:_*) - .withParams(scalaClassParams) - .withParents(mixin) - .withParents(baseTrait) - } - else { // for "empty" records: empty params and no no-arg ctor - CASECLASSDEF(ScalaClass) - .withFlags(flags:_*) - .withParams(PARAM("")) - .withParents(mixin) - .withParents(baseTrait) - } - case (Some(baseTrait), None) => - if (shouldGenerateSimpleClass) { - CLASSDEF(ScalaClass) - .withParams(scalaClassParams) - .withParents(mixin) - .withParents(baseTrait) - } - else if (!avroFields.isEmpty) { - CASECLASSDEF(ScalaClass) - .withParams(scalaClassParams) - .withFlags(Flags.FINAL) - .withParents(mixin) - .withParents(baseTrait) - } - else { // for "empty" records: empty params and no no-arg ctor - CASECLASSDEF(ScalaClass) - .withParams(PARAM("")) - .withFlags(Flags.FINAL) - .withParents(mixin) - .withParents(baseTrait) - } - case (None, Some(flags)) => - if (shouldGenerateSimpleClass) { - CLASSDEF(ScalaClass) - .withFlags(flags:_*) - .withParams(scalaClassParams) - .withParents(mixin) - } - else if (!avroFields.isEmpty) { - CASECLASSDEF(ScalaClass) - .withFlags(flags:_*) - .withParams(scalaClassParams) - .withParents(mixin) - } - else { // for "empty" records: empty params and no no-arg ctor - CASECLASSDEF(ScalaClass) - .withFlags(flags:_*) - .withParams(PARAM("")) - .withParents(mixin) - } - case (None, None) => - if (shouldGenerateSimpleClass) { - CLASSDEF(ScalaClass) - .withParams(scalaClassParams) - .withParents(mixin) - } - else if (!avroFields.isEmpty) { - CASECLASSDEF(ScalaClass) - .withParams(scalaClassParams) - .withFlags(Flags.FINAL) - .withParents(mixin) - } - else { // for "empty" records: empty params and no no-arg ctor - CASECLASSDEF(ScalaClass) - .withParams(PARAM("")) - .withFlags(Flags.FINAL) - .withParents(mixin) - } - } - - // Defines case class, adapted from https://github.com/oysterbooks/scavro/blob/code_generation/src/main/scala/oyster/scavro/plugin/ScalaCodegen.scala - val caseClassTree = caseClassDef := BLOCK ( - TYPEVAR("J") := REF(JavaClass), - DEF("toAvro", JavaClass) withFlags(Flags.OVERRIDE) := BLOCK( - NEW(JavaClass, scalaClassAccessors: _*) - ) - ) : Tree - - val treeWithScalaDoc = ScalaDocGenerator.docToScalaDoc( - Left(schema), - caseClassTree) - - treeWithScalaDoc - } - -} diff --git a/avrohugger-core/src/main/scala/format/scavro/trees/ScavroObjectTree.scala b/avrohugger-core/src/main/scala/format/scavro/trees/ScavroObjectTree.scala deleted file mode 100644 index d78949f0..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/trees/ScavroObjectTree.scala +++ /dev/null @@ -1,119 +0,0 @@ -package avrohugger -package format -package scavro -package trees - -import generators.ScalaDocGenerator -import converters.ScalaConverter -import matchers.TypeMatcher -import stores.ClassStore -import org.apache.avro.Schema -import treehugger.forest._ -import treehuggerDSL._ - -import scala.jdk.CollectionConverters._ - -object ScavroObjectTree { - - // for generating enums - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def toScalaEnumDef( - classStore: ClassStore, - schema: Schema, - maybeBaseTrait: Option[String], - maybeFlags: Option[List[Long]], - useFullName: Boolean = false - ) = { - - val objectDef = (maybeBaseTrait, maybeFlags) match { - case (Some(baseTrait), Some(flags)) => - OBJECTDEF(schema.getName) - .withFlags(flags:_*) - .withParents("Enumeration") - .withParents(baseTrait) - case (Some (baseTrait), None) => - OBJECTDEF(schema.getName) - .withParents(baseTrait) - .withParents("Enumeration") - case (None, Some(flags)) => - OBJECTDEF(schema.getName) - .withFlags(flags:_*) - .withParents("Enumeration") - case (None, None) => - OBJECTDEF(schema.getName) - .withParents("Enumeration") - } - - val objectTree = objectDef := BLOCK( - TYPEVAR(schema.getName) := REF("Value"), - VAL(schema.getEnumSymbols.asScala.mkString(", ")) := REF("Value") - ) - - val treeWithScalaDoc = ScalaDocGenerator.docToScalaDoc( - Left(schema), - objectTree) - - treeWithScalaDoc - } - - // for generating companion objects of case class records - def toCompanionDef( - classStore: ClassStore, - schema: Schema, - ScalaClass: Symbol, - JavaClass: Symbol, - typeMatcher: TypeMatcher, - maybeFlags: Option[List[Long]]) = { - - val AvroMetadata = - TYPE_REF(REF("AvroMetadata")) APPLYTYPE(ScalaClass, JavaClass) - val Class = - TYPE_REF(REF("Class")) APPLYTYPE(JavaClass) - val AvroReader = - TYPE_REF(REF("AvroReader")) APPLYTYPE(ScalaClass) - val toAvroType = - TYPE_REF(LAMBDA(PARAM("j", JavaClass)) ==> TYPE_REF(ScalaClass)) - - val javaClassAccessors: List[Tree] = - schema.getFields().asScala.toList.map(avroField => { - val nameGet = ScavroMethodRenamer.generateMethodName(schema, avroField, "get", "") - val getterTree = REF("j") DOT nameGet - val scalaConverter = new ScalaConverter(typeMatcher) - scalaConverter.convertFromJava(avroField.schema, getterTree) - }) - - val objectDef = maybeFlags match { - case Some(flags) => OBJECTDEF(ScalaClass).withFlags(flags:_*) - case None => OBJECTDEF(ScalaClass) - } - - // adapted from https://github.com/oysterbooks/scavro/blob/code_generation/src/main/scala/oyster/scavro/plugin/ScalaCodegen.scala - val objectTree = { - val anonReaderDef = ANONDEF(AvroReader) - val avroType = TYPE_REF(Class) - val javaType = TYPE_REF(JavaClass) - val scalaTypeApplied = TYPE_REF(ScalaClass) APPLY(javaClassAccessors:_*) - objectDef := BLOCK ( - DEF("reader") withFlags(Flags.IMPLICIT) := NEW(anonReaderDef := BLOCK( - TYPEVAR("J") withFlags(Flags.OVERRIDE) := REF(JavaClass) - )), - VAL("metadata", TYPE_REF(AvroMetadata)) - withFlags(Flags.IMPLICIT) := NEW(ANONDEF(AvroMetadata) := BLOCK( - VAL("avroClass", avroType) - withFlags(Flags.OVERRIDE) := REF("classOf") APPLYTYPE(JavaClass), - VAL("schema") withFlags(Flags.OVERRIDE) withType("Schema") := - javaType DOT "getClassSchema" APPLY(Nil), - VAL("fromAvro", TYPE_REF(PAREN(javaType)) TYPE_=> ScalaClass) - withFlags(Flags.OVERRIDE) := BLOCK( - LAMBDA(PARAM("j", JavaClass)) ==> scalaTypeApplied - ) - ) - ) - ) - } - - objectTree - - } - -} diff --git a/avrohugger-core/src/main/scala/format/scavro/trees/ScavroTraitTree.scala b/avrohugger-core/src/main/scala/format/scavro/trees/ScavroTraitTree.scala deleted file mode 100644 index ac488596..00000000 --- a/avrohugger-core/src/main/scala/format/scavro/trees/ScavroTraitTree.scala +++ /dev/null @@ -1,69 +0,0 @@ -package avrohugger -package format -package scavro -package trees - -import generators.ScalaDocGenerator -import matchers.TypeMatcher -import types._ - -import treehugger.forest._ -import treehuggerDSL._ - -import org.apache.avro.Schema.Type.{ ENUM, RECORD } -import org.apache.avro.{ Protocol, Schema } - -import scala.jdk.CollectionConverters._ - - -object ScavroTraitTree { - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def toADTRootDef(protocol: Protocol, typeMatcher: TypeMatcher) = { - def isEnum(schema: Schema) = schema.getType == ENUM - val sealedTraitTree = TRAITDEF(protocol.getName).withFlags(Flags.SEALED) - val adtRootTree = { - val adtSubTypes = typeMatcher.avroScalaTypes.enum match { - case JavaEnum => protocol.getTypes().asScala.toList.filterNot(isEnum) - case ScalaCaseObjectEnum => protocol.getTypes().asScala.toList - case ScalaEnumeration => protocol.getTypes().asScala.toList - case EnumAsScalaString => protocol.getTypes().asScala.filterNot(isEnum) - } - if (adtSubTypes.forall(schema => schema.getType == RECORD)) { - sealedTraitTree - .withParents("AvroSerializeable") - .withParents("Product") - .withParents("Serializable") - } - else sealedTraitTree - } - val treeWithScalaDoc = ScalaDocGenerator.docToScalaDoc( - Right(protocol), - adtRootTree) - - treeWithScalaDoc - } - - @deprecated("Scavro will no longer be supported", "avrohugger 1.5.0") - def toCaseObjectEnumDef(schema: Schema, - maybeBaseTrait: Option[String]): List[Tree] = { - val adtRootTree: Tree = maybeBaseTrait match { - case Some(baseTrait) => - TRAITDEF(schema.getName).withFlags(Flags.SEALED).withParents(baseTrait) - case None => - TRAITDEF(schema.getName).withFlags(Flags.SEALED) - } - val adtSubTypes: List[Tree] = schema.getEnumSymbols.asScala - .map(enumSymbol => enumSymbol.toString) - .map(enumSymbolString => { - (CASEOBJECTDEF(enumSymbolString).withParents(schema.getName): Tree) - }).toList - val objectTree = OBJECTDEF(schema.getName) := Block(adtSubTypes:_*) - val adtRootTreeWithScalaDoc: Tree = ScalaDocGenerator.docToScalaDoc( - Left(schema), - adtRootTree) - List(adtRootTreeWithScalaDoc, objectTree) - } - - -} diff --git a/avrohugger-core/src/main/scala/format/specific/SpecificScalaTreehugger.scala b/avrohugger-core/src/main/scala/format/specific/SpecificScalaTreehugger.scala index 90c51edb..491e8786 100644 --- a/avrohugger-core/src/main/scala/format/specific/SpecificScalaTreehugger.scala +++ b/avrohugger-core/src/main/scala/format/specific/SpecificScalaTreehugger.scala @@ -64,8 +64,8 @@ object SpecificScalaTreehugger extends ScalaTreehugger { // wrap the definitions in a block with a comment and a package val tree = { val blockContent = imports ++ topLevelDefs - if (namespace.isDefined) BLOCK(blockContent:_*).inPackage(namespace.get) - else BLOCK(blockContent:_*).withoutPackage + if (namespace.isDefined) BLOCK(blockContent).inPackage(namespace.get) + else BLOCK(blockContent).withoutPackage }.withDoc("MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY") val codeString = treeToString(tree) diff --git a/avrohugger-core/src/main/scala/format/specific/converters/JavaConverter.scala b/avrohugger-core/src/main/scala/format/specific/converters/JavaConverter.scala index 892d9ed7..7c430cff 100644 --- a/avrohugger-core/src/main/scala/format/specific/converters/JavaConverter.scala +++ b/avrohugger-core/src/main/scala/format/specific/converters/JavaConverter.scala @@ -59,7 +59,7 @@ object JavaConverter { NULL } ) - tree MATCH (conversionCases: _*) + tree MATCH (conversionCases) } else { tree } @@ -187,7 +187,7 @@ object JavaConverter { tree } case Schema.Type.ENUM => { - typeMatcher.avroScalaTypes.enum match { + typeMatcher.avroScalaTypes.`enum` match { case EnumAsScalaString => val defaultTree: Tree = REF("getSchema").DOT("getFields").DOT("get").APPLY(REF("field$")).DOT("schema") val schemaTree: Tree = diff --git a/avrohugger-core/src/main/scala/format/specific/converters/ScalaConverter.scala b/avrohugger-core/src/main/scala/format/specific/converters/ScalaConverter.scala index 2393193b..369e89af 100644 --- a/avrohugger-core/src/main/scala/format/specific/converters/ScalaConverter.scala +++ b/avrohugger-core/src/main/scala/format/specific/converters/ScalaConverter.scala @@ -101,7 +101,7 @@ object ScalaConverter { val errorExpr = NEW("org.apache.avro.AvroRuntimeException", errorMessage) val conversionCases = List(arrayConversion) val arrayMatchError = CASE(WILDCARD) ==> errorExpr - tree MATCH(conversionCases:_*) + tree MATCH(conversionCases) } case Schema.Type.STRING => LogicalType.foldLogicalTypes( @@ -185,13 +185,13 @@ object ScalaConverter { val nullConversion = CASE(NULL) ==> NONE val someConversion = CASE(WILDCARD) ==> SOME(expr) val conversionCases = List(nullConversion, someConversion) - tree MATCH (conversionCases: _*) + tree MATCH (conversionCases) } else { tree } } case Schema.Type.ENUM => { - typeMatcher.avroScalaTypes.enum match { + typeMatcher.avroScalaTypes.`enum` match { case EnumAsScalaString => tree TOSTRING case JavaEnum | ScalaEnumeration | ScalaCaseObjectEnum => tree } diff --git a/avrohugger-core/src/main/scala/format/specific/methods/GetGenerator.scala b/avrohugger-core/src/main/scala/format/specific/methods/GetGenerator.scala index bfb09117..220062fe 100644 --- a/avrohugger-core/src/main/scala/format/specific/methods/GetGenerator.scala +++ b/avrohugger-core/src/main/scala/format/specific/methods/GetGenerator.scala @@ -37,7 +37,7 @@ object GetGenerator { val casesGet = indexedFields.map(field => asGetCase(field, classSymbol, typeMatcher, targetScalaPartialVersion)):+errorCase DEF("get", AnyRefClass) withParams(PARAM("field$", IntClass)) := BLOCK( - REF("field$") withAnnots(ANNOT("switch")) MATCH(casesGet:_*) + REF("field$") withAnnots(ANNOT("switch")) MATCH(casesGet) ) } } diff --git a/avrohugger-core/src/main/scala/format/specific/methods/GetSchemaGenerator.scala b/avrohugger-core/src/main/scala/format/specific/methods/GetSchemaGenerator.scala index 66256e34..c148c6a6 100644 --- a/avrohugger-core/src/main/scala/format/specific/methods/GetSchemaGenerator.scala +++ b/avrohugger-core/src/main/scala/format/specific/methods/GetSchemaGenerator.scala @@ -9,7 +9,7 @@ import treehuggerDSL._ case class GetSchemaGenerator(companionObjectName: Symbol) { def toDef = { - val SchemaClass = RootClass.newClass("org.apache.avro.Schema") - DEF("getSchema", SchemaClass) := REF(companionObjectName) DOT "SCHEMA$" + val SchemaClass = RootClass.newClass("org.apache.avro.Schema") + DEF("getSchema", SchemaClass) := REF(companionObjectName) DOT "SCHEMA$" } } \ No newline at end of file diff --git a/avrohugger-core/src/main/scala/format/specific/methods/PutGenerator.scala b/avrohugger-core/src/main/scala/format/specific/methods/PutGenerator.scala index 7c816504..c1a3193e 100644 --- a/avrohugger-core/src/main/scala/format/specific/methods/PutGenerator.scala +++ b/avrohugger-core/src/main/scala/format/specific/methods/PutGenerator.scala @@ -42,7 +42,7 @@ object PutGenerator { val casesPut = indexedFields.map(field => asPutCase(field)):+ errorCase DEF("put", UnitClass) withParams(PARAM("field$", IntClass), PARAM("value", AnyClass)) := BLOCK( - REF("field$") withAnnots(ANNOT("switch")) MATCH(casesPut:_*), UNIT + REF("field$") withAnnots(ANNOT("switch")) MATCH(casesPut), UNIT ) } diff --git a/avrohugger-core/src/main/scala/format/specific/trees/SpecificCaseClassTree.scala b/avrohugger-core/src/main/scala/format/specific/trees/SpecificCaseClassTree.scala index 5c0ad2ed..246e3060 100644 --- a/avrohugger-core/src/main/scala/format/specific/trees/SpecificCaseClassTree.scala +++ b/avrohugger-core/src/main/scala/format/specific/trees/SpecificCaseClassTree.scala @@ -57,7 +57,7 @@ object SpecificCaseClassTree { defaultValue }) val defThis = DEFTHIS.withParams(PARAM("")).tree := { - THIS APPLY(defaultParams:_*) + THIS APPLY(defaultParams) } // methods - first add an index the the schema's fields diff --git a/avrohugger-core/src/main/scala/format/standard/StandardScalaTreehugger.scala b/avrohugger-core/src/main/scala/format/standard/StandardScalaTreehugger.scala index 65b43fdc..643a9830 100644 --- a/avrohugger-core/src/main/scala/format/standard/StandardScalaTreehugger.scala +++ b/avrohugger-core/src/main/scala/format/standard/StandardScalaTreehugger.scala @@ -19,13 +19,14 @@ object StandardScalaTreehugger extends ScalaTreehugger { val importer = StandardImporter def asScalaCodeString( - classStore: ClassStore, + classStore: ClassStore, namespace: Option[String], schemaOrProtocol: Either[Schema, Protocol], typeMatcher: TypeMatcher, schemaStore: SchemaStore, restrictedFields: Boolean, - targetScalaPartialVersion: String): String = { + targetScalaPartialVersion: String, + ): String = { val imports = importer.getImports( schemaOrProtocol, namespace, schemaStore, typeMatcher) diff --git a/avrohugger-core/src/main/scala/format/standard/avrohuggers/StandardProtocolhugger.scala b/avrohugger-core/src/main/scala/format/standard/avrohuggers/StandardProtocolhugger.scala index 6bbbea71..df261270 100644 --- a/avrohugger-core/src/main/scala/format/standard/avrohuggers/StandardProtocolhugger.scala +++ b/avrohugger-core/src/main/scala/format/standard/avrohuggers/StandardProtocolhugger.scala @@ -30,7 +30,7 @@ object StandardProtocolhugger extends Protocolhugger { val localSubTypes = getLocalSubtypes(protocol) - val adtSubTypes = typeMatcher.avroScalaTypes.enum match { + val adtSubTypes = typeMatcher.avroScalaTypes.`enum` match { case JavaEnum => localSubTypes.filterNot(isEnum) case ScalaCaseObjectEnum => localSubTypes case ScalaEnumeration => localSubTypes diff --git a/avrohugger-core/src/main/scala/format/standard/avrohuggers/StandardSchemahugger.scala b/avrohugger-core/src/main/scala/format/standard/avrohuggers/StandardSchemahugger.scala index e9555f96..ef3a5a4f 100644 --- a/avrohugger-core/src/main/scala/format/standard/avrohuggers/StandardSchemahugger.scala +++ b/avrohugger-core/src/main/scala/format/standard/avrohuggers/StandardSchemahugger.scala @@ -42,7 +42,7 @@ object StandardSchemahugger extends Schemahugger { case ScalaCaseClass => List(classDef) case ScalaCaseClassWithSchema => List(classDef, companionDef) } - case ENUM => typeMatcher.avroScalaTypes.enum match { + case ENUM => typeMatcher.avroScalaTypes.`enum` match { case JavaEnum => List.empty case ScalaCaseObjectEnum => diff --git a/avrohugger-core/src/main/scala/format/standard/trees/StandardTraitTree.scala b/avrohugger-core/src/main/scala/format/standard/trees/StandardTraitTree.scala index 8fa2ce6d..d86a30c9 100644 --- a/avrohugger-core/src/main/scala/format/standard/trees/StandardTraitTree.scala +++ b/avrohugger-core/src/main/scala/format/standard/trees/StandardTraitTree.scala @@ -19,7 +19,7 @@ object StandardTraitTree { def isEnum(schema: Schema) = schema.getType == ENUM val sealedTraitTree = TRAITDEF(protocol.getName).withFlags(Flags.SEALED) val adtRootTree = { - val adtSubTypes = typeMatcher.avroScalaTypes.enum match { + val adtSubTypes = typeMatcher.avroScalaTypes.`enum` match { case JavaEnum => protocol.getTypes().asScala.toList.filterNot(isEnum) case ScalaCaseObjectEnum => protocol.getTypes().asScala.toList case ScalaEnumeration => protocol.getTypes().asScala.toList diff --git a/avrohugger-core/src/main/scala/generators/FileGenerator.scala b/avrohugger-core/src/main/scala/generators/FileGenerator.scala index 84e47cb9..fa7eca59 100644 --- a/avrohugger-core/src/main/scala/generators/FileGenerator.scala +++ b/avrohugger-core/src/main/scala/generators/FileGenerator.scala @@ -4,7 +4,7 @@ package generators import avrohugger.format.abstractions.SourceFormat import avrohugger.input.DependencyInspector import avrohugger.input.NestedSchemaExtractor -import avrohugger.input.reflectivecompilation.schemagen._ +// import avrohugger.input.reflectivecompilation.schemagen._ import avrohugger.input.parsers.{ FileInputParser, StringInputParser} import avrohugger.matchers.TypeMatcher import avrohugger.stores.{ ClassStore, SchemaStore } diff --git a/avrohugger-core/src/main/scala/generators/StringGenerator.scala b/avrohugger-core/src/main/scala/generators/StringGenerator.scala index 9c0ed801..3aa41e8b 100644 --- a/avrohugger-core/src/main/scala/generators/StringGenerator.scala +++ b/avrohugger-core/src/main/scala/generators/StringGenerator.scala @@ -4,7 +4,7 @@ package generators import avrohugger.format.abstractions.SourceFormat import avrohugger.input.DependencyInspector import avrohugger.input.NestedSchemaExtractor -import avrohugger.input.reflectivecompilation.schemagen._ +// import avrohugger.input.reflectivecompilation.schemagen._ import avrohugger.input.parsers.{ FileInputParser, StringInputParser} import avrohugger.matchers.TypeMatcher import avrohugger.stores.{ ClassStore, SchemaStore } diff --git a/avrohugger-core/src/main/scala/input/NestedSchemaExtractor.scala b/avrohugger-core/src/main/scala/input/NestedSchemaExtractor.scala index bc149b80..f932c5f5 100644 --- a/avrohugger-core/src/main/scala/input/NestedSchemaExtractor.scala +++ b/avrohugger-core/src/main/scala/input/NestedSchemaExtractor.scala @@ -51,7 +51,7 @@ object NestedSchemaExtractor { } val flatSchemas = fieldSchemas.flatMap(fieldSchema => flattenSchema(fieldSchema)) def topLevelTypes(schema: Schema) = { - if (typeMatcher.avroScalaTypes.enum == EnumAsScalaString) (schema.getType == RECORD | schema.getType == FIXED) + if (typeMatcher.avroScalaTypes.`enum` == EnumAsScalaString) (schema.getType == RECORD | schema.getType == FIXED) else (schema.getType == RECORD | schema.getType == ENUM | schema.getType == FIXED) } val nestedTopLevelSchemas = flatSchemas.filter(topLevelTypes) diff --git a/avrohugger-core/src/main/scala/input/parsers/StringInputParser.scala b/avrohugger-core/src/main/scala/input/parsers/StringInputParser.scala index 50f817a6..55e48be0 100644 --- a/avrohugger-core/src/main/scala/input/parsers/StringInputParser.scala +++ b/avrohugger-core/src/main/scala/input/parsers/StringInputParser.scala @@ -2,8 +2,7 @@ package avrohugger package input package parsers -import reflectivecompilation.{ PackageSplitter, Toolbox } -import stores.{ SchemaStore, TypecheckDependencyStore } +import stores.SchemaStore import org.apache.avro.Protocol import org.apache.avro.Schema @@ -20,7 +19,6 @@ import java.io.FileNotFoundException class StringInputParser { lazy val schemaParser = new Parser() - lazy val typecheckDependencyStore = new TypecheckDependencyStore def getSchemaOrProtocols( inputString: String, @@ -55,32 +53,11 @@ class StringInputParser { List(Right(protocol)) } catch { - case e: ParseException => { - if (e.getMessage.contains("FileNotFoundException")) { - sys.error("Imports not supported in String IDLs, only avdl files.") - } - else tryCaseClass(str, schemaStore) - } + case e: ParseException => sys.error(s"Unable to parse: ${e}") case npe: NullPointerException => sys.error("Imports not supported in String IDLs, only avdl files.") case unknown: Throwable => sys.error("Unexpected exception: " + unknown) } } - - @deprecated("Reflective compilation will no longer be supported", "avrohugger 1.5.0") - def tryCaseClass( - str: String, - schemaStore: SchemaStore): List[Either[Schema, Protocol]] = { - val compilationUnits = PackageSplitter.getCompilationUnits(str) - val scalaDocs = ScalaDocParser.getScalaDocs(compilationUnits) - val trees = compilationUnits.map(src => Toolbox.toolBox.parse(src)) - val treesZippedWithDocs = trees.zip(scalaDocs) - val schemas = treesZippedWithDocs.flatMap(treeAndDocs => { - val tree = treeAndDocs._1 - val docs = treeAndDocs._2 - TreeInputParser.parse(tree, docs, schemaStore, typecheckDependencyStore) - }) - schemas.map(schema => Left(schema)) - } // tries schema first, then protocol, then idl, then for case class defs val schemaOrProtocols = trySchema(inputString) diff --git a/avrohugger-core/src/main/scala/input/parsers/TreeInputParser.scala b/avrohugger-core/src/main/scala/input/parsers/TreeInputParser.scala deleted file mode 100644 index 5cfc2e55..00000000 --- a/avrohugger-core/src/main/scala/input/parsers/TreeInputParser.scala +++ /dev/null @@ -1,387 +0,0 @@ -package avrohugger -package input -package parsers - -import reflectivecompilation.schemagen.{ - EnumSchemaGenerator, - RecordSchemaGenerator -} -import stores.{ SchemaStore, TypecheckDependencyStore} - -import scala.reflect._ -import scala.reflect.api._ -import scala.reflect.runtime.universe._ -import scala.reflect.runtime.universe.Flag._ -import scala.tools.reflect.ToolBox - -import org.apache.avro.Schema - -object TreeInputParser { - - def parse( - tree: Tree, - maybeScalaDocs: List[Option[String]], - schemaStore: SchemaStore, - typecheckDependencyStore: TypecheckDependencyStore): List[Schema] = { - - // e.g. takes `package test.one; package dev.helper;`, - // returns `test.one.dev.helper` - def squashNamespace(pkgTrees: Seq[RefTree]): Name = { - def extractNamespace(pkgTree: RefTree) ={ - // necessary because just using `.name` results in `one.helper` - val owner = pkgTree.name - val children = pkgTree.children - val namespace = children match { - case List() => s"$owner" //empty corresponds to a single-level package - case List(child) => s"$child.$owner" - case _ => sys.error("multiple children not supported") - } - namespace - } - val pkgString = pkgTrees.map(tree => extractNamespace(tree)).mkString(".") - TermName(pkgString) - } - - def enforceSingleScalaDoc( - className: String, - maybeScalaDoc: List[Option[String]]) = { - maybeScalaDoc match { - case List(doc) => doc - case x => sys.error("Expected single ScalaDoc, found " + x) - } - } - - def generateSchema( - namespace: Option[Name], - classDefTree: Tree, - maybeScalaDocs: List[Option[String]], - schemaStore: SchemaStore): List[Schema] = { - classDefTree match { - // case classes get mapped to records - case t @ q"$mods class $className[..$tparams](..$fields)(...$rest) extends ..$parents { $self => ..$body }" => { - val maybeScalaDoc = enforceSingleScalaDoc( - className.toString, - maybeScalaDocs) - List( - RecordSchemaGenerator.generateSchema( - className.toString, - namespace, fields, - maybeScalaDoc, - schemaStore, - typecheckDependencyStore)) - } - // objects get mapped to empty records or enums - case t @ q"$mods object $objectName extends ..$parents { $self => ..$body }" => { - val values = body.collect{ case ValDef(mods, NameTag(name), tpt, tpe) => name } - val maybeScalaDoc = enforceSingleScalaDoc(objectName.toString, maybeScalaDocs) - // case objects get mapped to empty records - if (mods.flags == CASE) { - List( - RecordSchemaGenerator.generateSchema( - objectName.toString, - namespace, - List.empty, - maybeScalaDoc, - schemaStore, - typecheckDependencyStore)) - } - // objects that extend Enumeration get mapped to enums - else { - List( - EnumSchemaGenerator.generateSchema( - objectName.toString, - namespace, - values, - maybeScalaDoc, - schemaStore)) - } - } - case definition => sys.error(s"""Unsupported definition. Expected case class or object definition, - but found $definition with tree: ${showRaw(definition)}""") - } - } - - def resubmit(classDefs: List[Tree], individuallyPackaged: List[Tree], maybeScalaDocs: List[Option[String]]) = { - storeAsDependencies(classDefs) - val individuallyPackagedZippedWithmaybeScalaDocs = individuallyPackaged.zip(maybeScalaDocs) - individuallyPackagedZippedWithmaybeScalaDocs.reverse.map(treeWithDocs => { - val tree = treeWithDocs._1 - val scalaDoc = List(treeWithDocs._2) - parse(tree, scalaDoc, schemaStore, typecheckDependencyStore) - }).flatten - } - - // Reflective compilation can't seem to handle packages, so field types are typechecked - // against manually provided classes as dependencies. (Object defs alone won't suffice!) - def storeAsDependencies(topLevelDefs: List[Tree]) = { - topLevelDefs.reverse.foreach(topLevelDef => { - topLevelDef match { - case t @ q"$mods class $className[..$tparams](..$fields)(...$rest) extends ..$parents { $self => ..$body }" => { - typecheckDependencyStore.accept(q"case class $className()") - } - case t @ q"$mods object $objectName extends ..$parents { $self => ..$body }" => { - //Store as a class otherwise typecheck won't see it as a type - typecheckDependencyStore.accept(q" case class ${objectName.toTypeName}();") - } - } - }) - } - - // if multiple classes are found, each is wrapped in the package def and resubmitted - tree match { - //TODO: better way than hard-coding for each number of possible enclosing packages? - //TODO: handle imports a) overlook extraneous imports b) imported record types - // need to be fully qualified, generated schemas using the right namespace. - - // nine packages: results in quasiquote error: Don't know how to unquote here - - // eight packages - case compilationUnit @ q"""package $packageName8 { - package $packageName7 { - package $packageName6 { - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { - $classDef}}}}}}}}""" => { - val packageTrees = Seq(packageName8, packageName7, packageName6, packageName5, packageName4, packageName3, packageName2, packageName1) - val namespace = Some(squashNamespace(packageTrees)) - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - // seven packages - case compilationUnit @ q"""package $packageName7 { - package $packageName6 { - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { - $classDef}}}}}}}""" => { - val packageTrees = Seq(packageName7, packageName6, packageName5, packageName4, packageName3, packageName2, packageName1) - val namespace = Some(squashNamespace(packageTrees)) - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - // six packages - case compilationUnit @ q"""package $packageName6 { - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { - $classDef}}}}}}""" => { - val packageTrees = Seq(packageName6, packageName5, packageName4, packageName3, packageName2, packageName1) - val namespace = Some(squashNamespace(packageTrees)) - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - // five packages - case compilationUnit @ q"""package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { - $classDef}}}}}""" => { - val packageTrees = Seq(packageName5, packageName4, packageName3, packageName2, packageName1) - val namespace = Some(squashNamespace(packageTrees)) - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - // four packages - case compilationUnit @ q"""package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { - $classDef}}}}""" => { - val packageTrees = Seq(packageName4, packageName3, packageName2, packageName1) - val namespace = Some(squashNamespace(packageTrees)) - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - // three packages - case compilationUnit @ q"""package $packageName3 { - package $packageName2 { - package $packageName1 { - $classDef}}}""" => { - val packageTrees = Seq(packageName3, packageName2, packageName1) - val namespace = Some(squashNamespace(packageTrees)) - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - // two packages - case compilationUnit @ q"""package $packageName2 { - package $packageName1 { - $classDef}}""" => { - val packageTrees = Seq(packageName2, packageName1) - val namespace = Some(squashNamespace(packageTrees)) - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - // single package - case compilationUnit @ q"""package $packageName { $classDef }""" => { - val packageTrees = Seq(packageName) - val namespace = Some(squashNamespace(packageTrees)) - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - // default package - case class - case classDef @ q"$mods class $name[..$tparams](..$fields)(...$rest) extends ..$parents { $self => ..$body }" => { - val namespace = None - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - // default package - case object - case classDef @ q"$mods object $tname extends { ..$earlydefns } with ..$parents { $self => ..$body }" => { - val namespace = None - storeAsDependencies(List(classDef)) - generateSchema(namespace, classDef, maybeScalaDocs, schemaStore) - } - - - - // match list of classes in a package, wrap them each in the package and resubmit - // to be matched as a single class def in 0 or more packages. - - //TODO: So much hard-coding of the number of package levels. A better way? - // multiple classes in the same package get reparsed as indidually packaged classDefs - - // Reverse the list of individually packaged compilation units so most nested classes - // are expanded first. - - // default package - case compilationUnit @ q"""..$classDefs""" => { - val individuallyPackaged = classDefs.map(cd => q"""$cd""") - resubmit(classDefs, individuallyPackaged, maybeScalaDocs) - } - // one package - case compilationUnit @ q""" - package $packageName { ..$classDefs }""" => { - val individuallyPackaged = classDefs.map(cd => q""" - package $packageName { $cd }""") - resubmit(classDefs, individuallyPackaged, maybeScalaDocs) - } - // two package - case compilationUnit @ q""" - package $packageName2 { - package $packageName1 { ..$classDefs }}""" => { - val individuallyPackaged = classDefs.map(cd => q""" - package $packageName2 { - package $packageName1 { $cd }}""") - resubmit(classDefs, individuallyPackaged, maybeScalaDocs) - } - // three package - case compilationUnit @ q""" - package $packageName3 { - package $packageName2 { - package $packageName1 { ..$classDefs }}}""" => { - val individuallyPackaged = classDefs.map(cd => q""" - package $packageName3 { - package $packageName2 { - package $packageName1 { $cd }}}""") - resubmit(classDefs, individuallyPackaged, maybeScalaDocs) - } - // four package - case compilationUnit @ q""" - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { ..$classDefs }}}}""" => { - val individuallyPackaged = classDefs.map(cd => q""" - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { $cd }}}}""") - resubmit(classDefs, individuallyPackaged, maybeScalaDocs) - } - // five package - case compilationUnit @ q""" - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { ..$classDefs }}}}}""" => { - val individuallyPackaged = classDefs.map(cd => q""" - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { $cd }}}}}""") - resubmit(classDefs, individuallyPackaged, maybeScalaDocs) - } - - // six package - case compilationUnit @ q""" - package $packageName6 { - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { ..$classDefs }}}}}}""" => { - val individuallyPackaged = classDefs.map(cd => q""" - package $packageName6 { - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { $cd }}}}}}""") - resubmit(classDefs, individuallyPackaged, maybeScalaDocs) - } - - // seven package - case compilationUnit @ q""" - package $packageName7 { - package $packageName6 { - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { ..$classDefs }}}}}}}""" => { - val individuallyPackaged = classDefs.map(cd => q""" - package $packageName7 { - package $packageName6 { - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { $cd }}}}}}}""") - resubmit(classDefs, individuallyPackaged, maybeScalaDocs) - } - - // eight package - case compilationUnit @ q""" - package $packageName8 { - package $packageName7 { - package $packageName6 { - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { ..$classDefs }}}}}}}}""" => { - val individuallyPackaged = classDefs.map(cd => q""" - package $packageName8 { - package $packageName7 { - package $packageName6 { - package $packageName5 { - package $packageName4 { - package $packageName3 { - package $packageName2 { - package $packageName1 { $cd }}}}}}}}""") - resubmit(classDefs, individuallyPackaged, maybeScalaDocs) - } - - case EmptyTree => List() - - // check to see if tree was an objectDef - case x => sys.error(s"""Unsupported class definition format: $x. - |Possible causes: - |1) Imports not yet supported by Scala reflection typechecker. - |2) Package declarations cannot be more than eight levels deep. - |""".trim.stripMargin) - - } - - - } -} diff --git a/avrohugger-core/src/main/scala/input/reflectivecompilation/PackageSplitter.scala b/avrohugger-core/src/main/scala/input/reflectivecompilation/PackageSplitter.scala deleted file mode 100644 index 954568e7..00000000 --- a/avrohugger-core/src/main/scala/input/reflectivecompilation/PackageSplitter.scala +++ /dev/null @@ -1,62 +0,0 @@ -package avrohugger -package input -package reflectivecompilation - -import scala.jdk.CollectionConverters._ - -object PackageSplitter { - - @deprecated("Reflective compilation will no longer be supported", "avrohugger 1.5.0") - def getCompilationUnits(code: String): List[String] = { - - def getCompilationUnits( - lines : List[String], - pkgResult: List[String]= List(), - compUnitResult: List[String]= List() ): List[String] = { - - def getBody( - code: List[String], - bodyResult: List[String] = List()): List[String] = { - code match { - case head::tail if head.startsWith("package") => { - val repackagedBody = (pkgResult:::bodyResult).mkString("\n") - getCompilationUnits(code, List(), compUnitResult :+ repackagedBody) - } - case head::tail => getBody(tail, bodyResult:+head) - case Nil => compUnitResult:+((pkgResult:::bodyResult).mkString("\n")) - } - } - val compilationUnits = lines match { - case head::tail if head.startsWith("package") => { - getCompilationUnits(tail, pkgResult:+head, compUnitResult) - } - case ls => getBody(ls) - } - compilationUnits - } - - // the parser can only parse packages if their contents are within explicit blocks - def wrapPackages(code: String): String = { - // match package definitions that don't already wrap their contents in { } - val nonWrappedRegEx = "(?!(package .*? \\{))(package ([a-zA-Z_$][a-zA-Z\\d_$]*\\.)*[a-zA-Z_$][a-zA-Z\\d_$]*)".r - nonWrappedRegEx.findFirstIn(code) match { - case Some(nonWrappedPackage) => { - val openPackage = nonWrappedPackage + " {" - val closePackage = "}" - val wrappedPackage = { - nonWrappedRegEx.replaceFirstIn(code, openPackage) + closePackage - } - wrapPackages(wrappedPackage)} - case None => code - } - } - - val lines = code.split("\n").toList - val compilationUnits = getCompilationUnits(lines) - val formatted = compilationUnits.map(compUnit => wrapPackages(compUnit)) - // reversed so the most nested classes need to be expanded first - formatted.reverse - } - -} - diff --git a/avrohugger-core/src/main/scala/input/reflectivecompilation/Toolbox.scala b/avrohugger-core/src/main/scala/input/reflectivecompilation/Toolbox.scala deleted file mode 100644 index 615fafeb..00000000 --- a/avrohugger-core/src/main/scala/input/reflectivecompilation/Toolbox.scala +++ /dev/null @@ -1,11 +0,0 @@ -package avrohugger -package input -package reflectivecompilation - -import scala.reflect.runtime.universe._ -import scala.reflect.runtime.currentMirror -import scala.tools.reflect.ToolBox - -object Toolbox { - lazy val toolBox = currentMirror.mkToolBox() -} \ No newline at end of file diff --git a/avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/EnumSchemaGenerator.scala b/avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/EnumSchemaGenerator.scala deleted file mode 100644 index 3c29de6d..00000000 --- a/avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/EnumSchemaGenerator.scala +++ /dev/null @@ -1,42 +0,0 @@ -package avrohugger -package input -package reflectivecompilation -package schemagen - -import parsers.ScalaDocParser -import stores.SchemaStore - -import org.apache.avro.Schema - -import java.util.{Arrays => JArrays} - -import scala.reflect.runtime.universe.Name -import scala.jdk.CollectionConverters._ - -object EnumSchemaGenerator { - - @deprecated("Reflective compilation will no longer be supported", "avrohugger 1.5.0") - def generateSchema( - className: String, - namespace: Option[Name], - values: List[Name], - maybeScalaDoc: Option[String], - schemaStore: SchemaStore): Schema = { - - // conversion from Option to String/null is for compatibility with Apache Avro - val ns = namespace match { - case Some(n) => n.toString - case None => null - } - - val vals = JArrays.asList(values.map(value => value.toString).toArray:_*) - - val doc = ScalaDocParser.getTopLevelDoc(maybeScalaDoc) - - val avroSchema = Schema.createEnum(className, doc, ns, vals) - - schemaStore.accept(avroSchema) - avroSchema - } - -} diff --git a/avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/FieldSchemaGenerator.scala b/avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/FieldSchemaGenerator.scala deleted file mode 100644 index 0d2a2a43..00000000 --- a/avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/FieldSchemaGenerator.scala +++ /dev/null @@ -1,109 +0,0 @@ -package avrohugger -package input -package reflectivecompilation -package schemagen - -import matchers.JsonMatcher -import stores.SchemaStore - -import org.apache.avro.Schema -import org.apache.avro.Schema.Field -import org.apache.avro.Schema.{ Type => AvroType } -import org.apache.avro.util.Utf8 - -import java.util.{Arrays => JArrays} - -import scala.reflect.runtime.universe._ -import scala.tools.reflect.ToolBox - -class FieldSchemaGenerator() { - - @deprecated("Reflective compilation will no longer be supported", "avrohugger 1.5.0") - def toAvroField( - namespace: Option[Name], - nme: TermName, - tpe: Type, - dv: Tree, - maybeFieldDoc: Option[String], - schemaStore: SchemaStore): Field = { - - //map is adapted from https://github.com/radlab/avro-scala-compiler-plugin/blob/master/src/main/scala/plugin/SchemaGen.scala - def createSchema(tpe: Type) : Schema = { - - tpe match { - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Int] && args.length == 0) => { - Schema.create(AvroType.INT) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Float] && args.length == 0) => { - Schema.create(AvroType.FLOAT) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Long] && args.length == 0) => { - Schema.create(AvroType.LONG) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Double] && args.length == 0) => { - Schema.create(AvroType.DOUBLE) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Boolean] && args.length == 0) => { - Schema.create(AvroType.BOOLEAN) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[String] && args.length == 0) => { - Schema.create(AvroType.STRING) - } case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Null] && args.length == 0) => { - Schema.create(AvroType.NULL) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[java.nio.ByteBuffer] && args.length == 0) => { - Schema.create(AvroType.BYTES) - } case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Utf8] && args.length == 0) => { - Schema.create(AvroType.STRING) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[List[Any]] && args.length == 1) => { - Schema.createArray(createSchema(args.head)) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Option[Any]] && args.length == 1) => { - if (args.head <:< typeOf[Option[Any]]) { - throw new UnsupportedOperationException("Implementation limitation: Cannot immediately nest Option types") - } - else Schema.createUnion(JArrays.asList(Array(createSchema(typeOf[Null]), createSchema(args.head)):_*)) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Map[String, Any]] && args.length == 2) => { - Schema.createMap(createSchema(args(1))) - } - case x @ TypeRef(pre, symbol, args) if (x <:< typeOf[Product with Serializable] ) => { - // if a case class (a nested record) is found, reuse the schema that was made - // and stored when its macro was expanded. alternatives: reflectively getting - // the schema from its companion, or regenerating the schema. - try { - // reflective compilation can't see the package name, so we add it explicitly - namespace match { - case Some(ns) => schemaStore.schemas(s"$ns.${x.toString}") - case None => schemaStore.schemas(x.toString) - } - } - catch { - case t: Throwable => { - sys.error(s"""Found field with type $tpe, but $tpe has not yet been - |expanded. Due to limitations of reflective compilation, please define - |your top-level class first, nested records following.""".stripMargin) - } - } - } - case null => throw new UnsupportedOperationException("""ToolBox typecheck - |returned null. Perhaps there was a problem storing previously defined - | types to the TypecheckDependencyStore""".trim.stripMargin) - case x => throw new UnsupportedOperationException("Could not generate schema. Cannot support yet: " + x ) - } - } - - val fieldDoc = maybeFieldDoc match { - case Some(doc) => doc - case None => null - } - - new Field( - nme.toString.trim, - createSchema(tpe), - fieldDoc, - JsonMatcher.toJsonNode(namespace, dv, schemaStore) - ) - } -} diff --git a/avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/RecordSchemaGenerator.scala b/avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/RecordSchemaGenerator.scala deleted file mode 100644 index 5ab240dd..00000000 --- a/avrohugger-core/src/main/scala/input/reflectivecompilation/schemagen/RecordSchemaGenerator.scala +++ /dev/null @@ -1,77 +0,0 @@ -package avrohugger -package input -package reflectivecompilation -package schemagen - -import parsers.ScalaDocParser -import stores.{ SchemaStore, TypecheckDependencyStore } - -import org.apache.avro.Schema.Field -import org.apache.avro.Schema - -import java.util.{ Arrays => JArrays } - -import scala.reflect.runtime.universe._ -import scala.reflect.runtime.currentMirror -import scala.jdk.CollectionConverters._ - -object RecordSchemaGenerator { - - @deprecated("Reflective compilation will no longer be supported", "avrohugger 1.5.0") - def generateSchema( - className: String, - namespace: Option[Name], - fields: List[ValDef], - maybeScalaDoc: Option[String], - schemaStore: SchemaStore, - typecheckDependencyStore: TypecheckDependencyStore): Schema = { - - // Can't seem to typecheck packaged classes, so splice-in unpackaged versions - // and later the FieldSchemaGenerator's type matcher must be passed the field's - // namespace explicitly. - def typeCheck(t: Tree) = { - val dependencies = typecheckDependencyStore.knownClasses.values.toList - Toolbox.toolBox.typecheck(q"..$dependencies; {type T = $t}") match { - case x @ Block(classDefs, Block(List(TypeDef(mods, name, tparams, rhs)), const)) => rhs.tpe - case _ => t.tpe // if there are no fields, then no dependencies either - } - } - - def toAvroFieldSchema(valDef: ValDef) = { - val (referredNamespace, fieldType) = valDef.tpt match { - case tq"$ns.$typeName" => (Some(TermName(ns.toString)), tq"$typeName") - case t => (namespace, t) - } - - val maybeFieldDoc = ScalaDocParser.fieldDocsMap(maybeScalaDoc).get(valDef.name.toString) - - new FieldSchemaGenerator().toAvroField( - referredNamespace, - valDef.name, - typeCheck(fieldType), - valDef.rhs, - maybeFieldDoc, - schemaStore - ) - } - - // conversion from Option to String/null is for compatibility with Apache Avro - val ns = namespace match { - case Some(n) => n.toString - case None => null - } - - val avroFields = fields.map(valDef => { - toAvroFieldSchema(valDef) - }) - - // conversion from Option to String/null is for compatibility with Apache Avro - val recordDoc = ScalaDocParser.getTopLevelDoc(maybeScalaDoc) - - val avroSchema = Schema.createRecord(className, recordDoc, ns, false) - avroSchema.setFields(JArrays.asList(avroFields.toArray:_*)) - schemaStore.accept(avroSchema) - avroSchema - } - -} diff --git a/avrohugger-core/src/main/scala/matchers/DefaultValueMatcher.scala b/avrohugger-core/src/main/scala/matchers/DefaultValueMatcher.scala index eef3b34f..79abdc85 100644 --- a/avrohugger-core/src/main/scala/matchers/DefaultValueMatcher.scala +++ b/avrohugger-core/src/main/scala/matchers/DefaultValueMatcher.scala @@ -82,7 +82,7 @@ object DefaultValueMatcher { ) case Schema.Type.ENUM => { val refName = if (useFullName) schema.getFullName else schema.getName - typeMatcher.avroScalaTypes.enum match { + typeMatcher.avroScalaTypes.`enum` match { case JavaEnum => (REF(refName) DOT node.textValue()) case ScalaEnumeration => (REF(refName) DOT node.textValue()) case ScalaCaseObjectEnum => (REF(refName) DOT node.textValue()) @@ -133,7 +133,6 @@ object DefaultValueMatcher { ) ) } - case x => throw new Exception(s"Can't extract a default field, type not yet supported: $x") } } val defaultValue = org.apache.avro.util.internal.Accessor.defaultValue(field) diff --git a/avrohugger-core/src/main/scala/matchers/JSONMatcher.scala b/avrohugger-core/src/main/scala/matchers/JSONMatcher.scala deleted file mode 100644 index 81be6f49..00000000 --- a/avrohugger-core/src/main/scala/matchers/JSONMatcher.scala +++ /dev/null @@ -1,70 +0,0 @@ -package avrohugger -package matchers - -import stores.SchemaStore - -import scala.reflect.runtime.universe._ -import scala.reflect.runtime._ - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node._ - -object JsonMatcher { - - def toJsonNode(namespace: Option[Name], dv: Tree, schemaStore: SchemaStore) : JsonNode = { - - def getFullName(nme: String): String = { - namespace match { - case Some(ns) => s"$ns+$nme" - case None => nme - } - } - - lazy val jsonNodeFactory = JsonNodeFactory.instance - - dv match { - // use of null here is for Java interop, builds Avro FieldConstructor w/o default value - case EmptyTree => null - case Literal(Constant(x: Unit)) => jsonNodeFactory.nullNode - case Literal(Constant(x: Boolean)) => jsonNodeFactory.booleanNode(x) - case Literal(Constant(x: Int)) => jsonNodeFactory.numberNode(x) - case Literal(Constant(x: Long)) => jsonNodeFactory.numberNode(x) - case Literal(Constant(x: Float)) => jsonNodeFactory.numberNode(x) - case Literal(Constant(x: Double)) => jsonNodeFactory.numberNode(x) - case Literal(Constant(x: String)) => jsonNodeFactory.textNode(x) - case Literal(Constant(null)) => jsonNodeFactory.nullNode - case Ident(NameTag("None")) => jsonNodeFactory.nullNode - case Apply(Ident(NameTag("Some")), List(x)) => toJsonNode(namespace, x, schemaStore) - case Apply(Ident(NameTag("List")), xs) => { - val jsonArray = jsonNodeFactory.arrayNode - xs.map(x => toJsonNode(namespace, x, schemaStore)).map(v => jsonArray.add(v)) - jsonArray - } - case Apply(Ident(NameTag("Map")), kvps) => { - val jsonObject = jsonNodeFactory.objectNode - kvps.foreach(kvp => kvp match { - case Apply(Select(Literal(Constant(key: String)), NameTag(tn)), List(x)) => { - jsonObject.set(key, toJsonNode(namespace, x, schemaStore)) - } - }) - jsonObject - } - // if the default value is another (i.e. nested) record/case class - case Apply(Ident(NameTag(name)), xs) if schemaStore.schemas.contains(getFullName(name.toString)) => { - val jsonObject = jsonNodeFactory.objectNode - xs.zipWithIndex.map( x => { - val value = x._1 - val index = x._2 - val nestedRecordField = schemaStore.schemas(getFullName(name.toString)).getFields().get(index) - // values from the tree, field names from cross referencing tree's pos with schema field pos - // (they always correspond since the schema is defined based on the fields in a class def) - jsonObject.set(nestedRecordField.name, toJsonNode(namespace, value, schemaStore)) - }) - jsonObject - } - // enum - case Select(Ident(NameTag(enum)), NameTag(enumValue)) => jsonNodeFactory.textNode(enumValue.toString()) - case x => sys.error(s"Could not extract default value. Found: $x, ${showRaw(x)}") - } - } -} diff --git a/avrohugger-core/src/main/scala/matchers/TypeMatcher.scala b/avrohugger-core/src/main/scala/matchers/TypeMatcher.scala index 9e4829da..acd5a4c4 100644 --- a/avrohugger-core/src/main/scala/matchers/TypeMatcher.scala +++ b/avrohugger-core/src/main/scala/matchers/TypeMatcher.scala @@ -88,7 +88,6 @@ class TypeMatcher( val unionSchemas = schema.getTypes().asScala.toList unionTypeImpl(unionSchemas, matchType) } - case x => sys.error( s"$x is not supported or not a valid Avro type") } } @@ -157,7 +156,6 @@ class TypeMatcher( //Scavro requires Java types be generated for mapping Java classes to Scala - // in the future, scavro may allow this to be set val avroStringType = TYPE_REF("CharSequence") def toJavaType( @@ -207,7 +205,6 @@ class TypeMatcher( } else sys.error("unions not yet supported beyond nullable fields") } - case x => sys.error( s"$x is not supported or not a valid Avro type") } } diff --git a/avrohugger-core/src/main/scala/matchers/custom/CustomTypeMatcher.scala b/avrohugger-core/src/main/scala/matchers/custom/CustomTypeMatcher.scala index 290cc16c..8e803344 100644 --- a/avrohugger-core/src/main/scala/matchers/custom/CustomTypeMatcher.scala +++ b/avrohugger-core/src/main/scala/matchers/custom/CustomTypeMatcher.scala @@ -53,7 +53,7 @@ object CustomTypeMatcher { case JavaTimeLocalTime => RootClass.newClass(nme.createNameType("java.time.LocalTime")) } - def checkCustomDecimalType(decimalType: AvroScalaDecimalType, schema: Schema) = + def checkCustomDecimalType(decimalType: AvroScalaDecimalType, schema: Schema): Type = LogicalType.foldLogicalTypes( schema = schema, default = TYPE_ARRAY(ByteClass)) { diff --git a/avrohugger-core/src/main/scala/stores/SchemaStore.scala b/avrohugger-core/src/main/scala/stores/SchemaStore.scala index 7399780a..44506d66 100644 --- a/avrohugger-core/src/main/scala/stores/SchemaStore.scala +++ b/avrohugger-core/src/main/scala/stores/SchemaStore.scala @@ -8,13 +8,11 @@ import scala.jdk.CollectionConverters._ class SchemaStore { - val schemas: scala.collection.concurrent.Map[String, Schema] = { + val schemas: scala.collection.concurrent.Map[String, Schema] = new ConcurrentHashMap[String, Schema]().asScala - } - def accept(schema: Schema) = { - val fullName = schema.getFullName - val _ = schemas += (fullName -> schema) - } + def accept(schema: Schema) = + schemas += (schema.getFullName -> schema) + } \ No newline at end of file diff --git a/avrohugger-core/src/main/scala/stores/TypecheckDependencyStore.scala b/avrohugger-core/src/main/scala/stores/TypecheckDependencyStore.scala deleted file mode 100644 index ccf41aee..00000000 --- a/avrohugger-core/src/main/scala/stores/TypecheckDependencyStore.scala +++ /dev/null @@ -1,17 +0,0 @@ -package avrohugger -package stores - -import java.util.concurrent.ConcurrentHashMap - -import scala.reflect.runtime.universe._ -import scala.jdk.CollectionConverters._ - -class TypecheckDependencyStore { - - val knownClasses: scala.collection.concurrent.Map[String, Tree] = new ConcurrentHashMap[String, Tree]().asScala - - def accept(tree: Tree) = { - val _ = knownClasses += (tree.toString -> tree) - } - -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/comments/scavro/Example4.scala b/avrohugger-core/src/test/expected/comments/scavro/Example4.scala deleted file mode 100644 index 338df803..00000000 --- a/avrohugger-core/src/test/expected/comments/scavro/Example4.scala +++ /dev/null @@ -1,50 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package com.example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import com.example.{NoSpaces4 => JNoSpaces4, NoSpaces5 => JNoSpaces5} - -sealed trait Example4 extends AvroSerializeable with Product with Serializable - -final case class NoSpaces4(comment_property1: String) extends AvroSerializeable with Example4 { - type J = JNoSpaces4 - override def toAvro: JNoSpaces4 = { - new JNoSpaces4(comment_property1) - } -} - -final object NoSpaces4 { - implicit def reader = new AvroReader[NoSpaces4] { - override type J = JNoSpaces4 - } - implicit val metadata: AvroMetadata[NoSpaces4, JNoSpaces4] = new AvroMetadata[NoSpaces4, JNoSpaces4] { - override val avroClass: Class[JNoSpaces4] = classOf[JNoSpaces4] - override val schema: Schema = JNoSpaces4.getClassSchema() - override val fromAvro: (JNoSpaces4) => NoSpaces4 = { - (j: JNoSpaces4) => NoSpaces4(j.getCommentProperty1.toString) - } - } -} - -final case class NoSpaces5(comment_property2: String) extends AvroSerializeable with Example4 { - type J = JNoSpaces5 - override def toAvro: JNoSpaces5 = { - new JNoSpaces5(comment_property2) - } -} - -final object NoSpaces5 { - implicit def reader = new AvroReader[NoSpaces5] { - override type J = JNoSpaces5 - } - implicit val metadata: AvroMetadata[NoSpaces5, JNoSpaces5] = new AvroMetadata[NoSpaces5, JNoSpaces5] { - override val avroClass: Class[JNoSpaces5] = classOf[JNoSpaces5] - override val schema: Schema = JNoSpaces5.getClassSchema() - override val fromAvro: (JNoSpaces5) => NoSpaces5 = { - (j: JNoSpaces5) => NoSpaces5(j.getCommentProperty2.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/comments/scavro/Example5.scala b/avrohugger-core/src/test/expected/comments/scavro/Example5.scala deleted file mode 100644 index a7fac07e..00000000 --- a/avrohugger-core/src/test/expected/comments/scavro/Example5.scala +++ /dev/null @@ -1,48 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package com.example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import com.example.{NoSpaces6 => JNoSpaces6, NoSpaces7 => JNoSpaces7} - -final case class NoSpaces6(comment_property1: String) extends AvroSerializeable { - type J = JNoSpaces6 - override def toAvro: JNoSpaces6 = { - new JNoSpaces6(comment_property1) - } -} - -object NoSpaces6 { - implicit def reader = new AvroReader[NoSpaces6] { - override type J = JNoSpaces6 - } - implicit val metadata: AvroMetadata[NoSpaces6, JNoSpaces6] = new AvroMetadata[NoSpaces6, JNoSpaces6] { - override val avroClass: Class[JNoSpaces6] = classOf[JNoSpaces6] - override val schema: Schema = JNoSpaces6.getClassSchema() - override val fromAvro: (JNoSpaces6) => NoSpaces6 = { - (j: JNoSpaces6) => NoSpaces6(j.getCommentProperty1.toString) - } - } -} - -final case class NoSpaces7(comment_property2: String) extends AvroSerializeable { - type J = JNoSpaces7 - override def toAvro: JNoSpaces7 = { - new JNoSpaces7(comment_property2) - } -} - -object NoSpaces7 { - implicit def reader = new AvroReader[NoSpaces7] { - override type J = JNoSpaces7 - } - implicit val metadata: AvroMetadata[NoSpaces7, JNoSpaces7] = new AvroMetadata[NoSpaces7, JNoSpaces7] { - override val avroClass: Class[JNoSpaces7] = classOf[JNoSpaces7] - override val schema: Schema = JNoSpaces7.getClassSchema() - override val fromAvro: (JNoSpaces7) => NoSpaces7 = { - (j: JNoSpaces7) => NoSpaces7(j.getCommentProperty2.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/comments/scavro/NoSpaces1.scala b/avrohugger-core/src/test/expected/comments/scavro/NoSpaces1.scala deleted file mode 100644 index b366d2a4..00000000 --- a/avrohugger-core/src/test/expected/comments/scavro/NoSpaces1.scala +++ /dev/null @@ -1,50 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package com.example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import com.example.{NoSpaces1 => JNoSpaces1} - -/** - * The comment applies to the `NoSpaces1` record, but is not indented to the - * level of the record specification. - * @param single_line_comment_property This is a single line comment that is indented for readability, - * and is not affected by indentation. - * @param multi_line_property This multi-line comment on `mult_line_property` that would be affected by indentation. - * - * This is another paragraph - * - * - * This is an indented block and should be shown as - * such. - * - * Here is a code block that apparently does not work for avrodoc. E.g. no [GFM](https://help.github.com/articles/github-flavored-markdown) support. - * - * ```ruby - * # this is a Ruby code block - * def method(arg1, arg2=nil) - * puts "hello world!" - * end - * ``` - */ -final case class NoSpaces1(single_line_comment_property: String, multi_line_property: String) extends AvroSerializeable { - type J = JNoSpaces1 - override def toAvro: JNoSpaces1 = { - new JNoSpaces1(single_line_comment_property, multi_line_property) - } -} - -object NoSpaces1 { - implicit def reader = new AvroReader[NoSpaces1] { - override type J = JNoSpaces1 - } - implicit val metadata: AvroMetadata[NoSpaces1, JNoSpaces1] = new AvroMetadata[NoSpaces1, JNoSpaces1] { - override val avroClass: Class[JNoSpaces1] = classOf[JNoSpaces1] - override val schema: Schema = JNoSpaces1.getClassSchema() - override val fromAvro: (JNoSpaces1) => NoSpaces1 = { - (j: JNoSpaces1) => NoSpaces1(j.getSingleLineCommentProperty.toString, j.getMultiLineProperty.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/comments/scavro/NoSpaces2.scala b/avrohugger-core/src/test/expected/comments/scavro/NoSpaces2.scala deleted file mode 100644 index 714882d9..00000000 --- a/avrohugger-core/src/test/expected/comments/scavro/NoSpaces2.scala +++ /dev/null @@ -1,29 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package com.example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import com.example.{NoSpaces2 => JNoSpaces2} - -/** @param comment_property This is a single line comment on a field, in a record that has no comment. */ -final case class NoSpaces2(comment_property: String) extends AvroSerializeable { - type J = JNoSpaces2 - override def toAvro: JNoSpaces2 = { - new JNoSpaces2(comment_property) - } -} - -object NoSpaces2 { - implicit def reader = new AvroReader[NoSpaces2] { - override type J = JNoSpaces2 - } - implicit val metadata: AvroMetadata[NoSpaces2, JNoSpaces2] = new AvroMetadata[NoSpaces2, JNoSpaces2] { - override val avroClass: Class[JNoSpaces2] = classOf[JNoSpaces2] - override val schema: Schema = JNoSpaces2.getClassSchema() - override val fromAvro: (JNoSpaces2) => NoSpaces2 = { - (j: JNoSpaces2) => NoSpaces2(j.getCommentProperty.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/comments/scavro/NoSpaces3.scala b/avrohugger-core/src/test/expected/comments/scavro/NoSpaces3.scala deleted file mode 100644 index b63ad8de..00000000 --- a/avrohugger-core/src/test/expected/comments/scavro/NoSpaces3.scala +++ /dev/null @@ -1,33 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package com.example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import com.example.{NoSpaces3 => JNoSpaces3} - -/** - * The comment applies to the `NoSpaces3` record, but is not indented to the - * level of the record specification. - * @param comment_property - */ -final case class NoSpaces3(comment_property: String) extends AvroSerializeable { - type J = JNoSpaces3 - override def toAvro: JNoSpaces3 = { - new JNoSpaces3(comment_property) - } -} - -object NoSpaces3 { - implicit def reader = new AvroReader[NoSpaces3] { - override type J = JNoSpaces3 - } - implicit val metadata: AvroMetadata[NoSpaces3, JNoSpaces3] = new AvroMetadata[NoSpaces3, JNoSpaces3] { - override val avroClass: Class[JNoSpaces3] = classOf[JNoSpaces3] - override val schema: Schema = JNoSpaces3.getClassSchema() - override val fromAvro: (JNoSpaces3) => NoSpaces3 = { - (j: JNoSpaces3) => NoSpaces3(j.getCommentProperty.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/com/miguno/avro/model/twitter_schema.scala b/avrohugger-core/src/test/expected/scavro/com/miguno/avro/model/twitter_schema.scala deleted file mode 100644 index 7bbaf28f..00000000 --- a/avrohugger-core/src/test/expected/scavro/com/miguno/avro/model/twitter_schema.scala +++ /dev/null @@ -1,33 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package com.miguno.avro.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import com.miguno.avro.{twitter_schema => Jtwitter_schema} - -/** - * @param username Name of the user account on Twitter.com - * @param tweet The content of the user's Twitter message - * @param timestamp Unix epoch time in milliseconds - */ -final case class twitter_schema(username: String, tweet: String, timestamp: Long) extends AvroSerializeable { - type J = Jtwitter_schema - override def toAvro: Jtwitter_schema = { - new Jtwitter_schema(username, tweet, timestamp) - } -} - -object twitter_schema { - implicit def reader = new AvroReader[twitter_schema] { - override type J = Jtwitter_schema - } - implicit val metadata: AvroMetadata[twitter_schema, Jtwitter_schema] = new AvroMetadata[twitter_schema, Jtwitter_schema] { - override val avroClass: Class[Jtwitter_schema] = classOf[Jtwitter_schema] - override val schema: Schema = Jtwitter_schema.getClassSchema() - override val fromAvro: (Jtwitter_schema) => twitter_schema = { - (j: Jtwitter_schema) => twitter_schema(j.getUsername.toString, j.getTweet.toString, j.getTimestamp.toLong) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaArray.scala b/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaArray.scala deleted file mode 100644 index 88f41c64..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaArray.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.array.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.array.{ArrayIdl => JArrayIdl} - -import scala.jdk.CollectionConverters._ - -final case class ArrayIdl(data: Array[Int]) extends AvroSerializeable { - type J = JArrayIdl - override def toAvro: JArrayIdl = { - new JArrayIdl({ - val array: java.util.List[java.lang.Integer] = new java.util.ArrayList[java.lang.Integer] - data foreach { element => - array.add(element) - } - array - }) - } -} - -object ArrayIdl { - implicit def reader = new AvroReader[ArrayIdl] { - override type J = JArrayIdl - } - implicit val metadata: AvroMetadata[ArrayIdl, JArrayIdl] = new AvroMetadata[ArrayIdl, JArrayIdl] { - override val avroClass: Class[JArrayIdl] = classOf[JArrayIdl] - override val schema: Schema = JArrayIdl.getClassSchema() - override val fromAvro: (JArrayIdl) => ArrayIdl = { - (j: JArrayIdl) => ArrayIdl(Array((j.getData.asScala: _*)) map { x => - x.toInt - }) - } - } -} diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaList.scala b/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaList.scala deleted file mode 100644 index aae85ba1..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaList.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.array.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.array.{ArrayIdl => JArrayIdl} - -import scala.jdk.CollectionConverters._ - -final case class ArrayIdl(data: List[Int]) extends AvroSerializeable { - type J = JArrayIdl - override def toAvro: JArrayIdl = { - new JArrayIdl({ - val array: java.util.List[java.lang.Integer] = new java.util.ArrayList[java.lang.Integer] - data foreach { element => - array.add(element) - } - array - }) - } -} - -object ArrayIdl { - implicit def reader = new AvroReader[ArrayIdl] { - override type J = JArrayIdl - } - implicit val metadata: AvroMetadata[ArrayIdl, JArrayIdl] = new AvroMetadata[ArrayIdl, JArrayIdl] { - override val avroClass: Class[JArrayIdl] = classOf[JArrayIdl] - override val schema: Schema = JArrayIdl.getClassSchema() - override val fromAvro: (JArrayIdl) => ArrayIdl = { - (j: JArrayIdl) => ArrayIdl(List((j.getData.asScala: _*)) map { x => - x.toInt - }) - } - } -} diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaSeq.scala b/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaSeq.scala deleted file mode 100644 index ab55b3a1..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaSeq.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.array.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.array.{ArrayIdl => JArrayIdl} - -import scala.jdk.CollectionConverters._ - -final case class ArrayIdl(data: Seq[Int]) extends AvroSerializeable { - type J = JArrayIdl - override def toAvro: JArrayIdl = { - new JArrayIdl({ - val array: java.util.List[java.lang.Integer] = new java.util.ArrayList[java.lang.Integer] - data foreach { element => - array.add(element) - } - array - }) - } -} - -object ArrayIdl { - implicit def reader = new AvroReader[ArrayIdl] { - override type J = JArrayIdl - } - implicit val metadata: AvroMetadata[ArrayIdl, JArrayIdl] = new AvroMetadata[ArrayIdl, JArrayIdl] { - override val avroClass: Class[JArrayIdl] = classOf[JArrayIdl] - override val schema: Schema = JArrayIdl.getClassSchema() - override val fromAvro: (JArrayIdl) => ArrayIdl = { - (j: JArrayIdl) => ArrayIdl(Seq((j.getData.asScala: _*)) map { x => - x.toInt - }) - } - } -} diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaVector.scala b/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaVector.scala deleted file mode 100644 index 83f546e5..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/array/ArrayAsScalaVector.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.array.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.array.{ArrayIdl => JArrayIdl} - -import scala.jdk.CollectionConverters._ - -final case class ArrayIdl(data: Vector[Int]) extends AvroSerializeable { - type J = JArrayIdl - override def toAvro: JArrayIdl = { - new JArrayIdl({ - val array: java.util.List[java.lang.Integer] = new java.util.ArrayList[java.lang.Integer] - data foreach { element => - array.add(element) - } - array - }) - } -} - -object ArrayIdl { - implicit def reader = new AvroReader[ArrayIdl] { - override type J = JArrayIdl - } - implicit val metadata: AvroMetadata[ArrayIdl, JArrayIdl] = new AvroMetadata[ArrayIdl, JArrayIdl] { - override val avroClass: Class[JArrayIdl] = classOf[JArrayIdl] - override val schema: Schema = JArrayIdl.getClassSchema() - override val fromAvro: (JArrayIdl) => ArrayIdl = { - (j: JArrayIdl) => ArrayIdl(Vector((j.getData.asScala: _*)) map { x => - x.toInt - }) - } - } -} diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/case/model/Defaults.scala b/avrohugger-core/src/test/expected/scavro/example/idl/case/model/Defaults.scala deleted file mode 100644 index 4cae2266..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/case/model/Defaults.scala +++ /dev/null @@ -1,127 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.`case`.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{DefaultEnum => JDefaultEnum, DefaultTest => JDefaultTest, Embedded => JEmbedded} - -import scala.jdk.CollectionConverters._ - -sealed trait Defaults - -sealed trait DefaultEnum extends DefaultsF - -object DefaultEnum { - case object SPADES extends DefaultEnum - case object DIAMONDS extends DefaultEnum - case object CLUBS extends DefaultEnum - case object HEARTS extends DefaultEnum -} - -final case class Embedded(inner: Int) extends AvroSerializeable with Defaults { - type J = JEmbedded - override def toAvro: JEmbedded = { - new JEmbedded(inner) - } -} - -final object Embedded { - implicit def reader = new AvroReader[Embedded] { - override type J = JEmbedded - } - implicit val metadata: AvroMetadata[Embedded, JEmbedded] = new AvroMetadata[Embedded, JEmbedded] { - override val avroClass: Class[JEmbedded] = classOf[JEmbedded] - override val schema: Schema = JEmbedded.getClassSchema() - override val fromAvro: (JEmbedded) => Embedded = { - (j: JEmbedded) => Embedded(j.getInner.toInt) - } - } -} - -final case class DefaultTest(suit: DefaultEnum = DefaultEnum.SPADES, number: Int = 0, str: String = "str", optionString: Option[String] = None, optionStringValue: Option[String] = Some("default"), embedded: Embedded = new Embedded(1), defaultArray: Array[Int] = Array(1, 3, 4, 5), optionalEnum: Option[DefaultEnum] = None, defaultMap: Map[String, String] = Map("Hello" -> "world", "Merry" -> "Christmas"), byt: Array[Byte] = Array[Byte](-61, -65)) extends AvroSerializeable with Defaults { - type J = JDefaultTest - override def toAvro: JDefaultTest = { - new JDefaultTest(suit match { - case DefaultEnum.SPADES => JDefaultEnum.SPADES - case DefaultEnum.DIAMONDS => JDefaultEnum.DIAMONDS - case DefaultEnum.CLUBS => JDefaultEnum.CLUBS - case DefaultEnum.HEARTS => JDefaultEnum.HEARTS - }, number, str, optionString match { - case Some(x) => x - case None => null - }, optionStringValue match { - case Some(x) => x - case None => null - }, embedded.toAvro, { - val array: java.util.List[java.lang.Integer] = new java.util.ArrayList[java.lang.Integer] - defaultArray foreach { element => - array.add(element) - } - array - }, optionalEnum match { - case Some(x) => x match { - case DefaultEnum.SPADES => JDefaultEnum.SPADES - case DefaultEnum.DIAMONDS => JDefaultEnum.DIAMONDS - case DefaultEnum.CLUBS => JDefaultEnum.CLUBS - case DefaultEnum.HEARTS => JDefaultEnum.HEARTS - } - case None => null - }, { - val map: java.util.Map[CharSequence, CharSequence] = new java.util.HashMap[CharSequence, CharSequence] - defaultMap foreach { kvp => - val key = kvp._1 - val value = kvp._2 - map.put(key, value) - } - map - }, java.nio.ByteBuffer.wrap(byt)) - } -} - -final object DefaultTest { - implicit def reader = new AvroReader[DefaultTest] { - override type J = JDefaultTest - } - implicit val metadata: AvroMetadata[DefaultTest, JDefaultTest] = new AvroMetadata[DefaultTest, JDefaultTest] { - override val avroClass: Class[JDefaultTest] = classOf[JDefaultTest] - override val schema: Schema = JDefaultTest.getClassSchema() - override val fromAvro: (JDefaultTest) => DefaultTest = { - (j: JDefaultTest) => DefaultTest(j.getSuit match { - case JDefaultEnum.SPADES => DefaultEnum.SPADES - case JDefaultEnum.DIAMONDS => DefaultEnum.DIAMONDS - case JDefaultEnum.CLUBS => DefaultEnum.CLUBS - case JDefaultEnum.HEARTS => DefaultEnum.HEARTS - }, j.getNumber.toInt, j.getStr.toString, j.getOptionString match { - case null => None - case _ => Some(j.getOptionString.toString) - }, j.getOptionStringValue match { - case null => None - case _ => Some(j.getOptionStringValue.toString) - }, Embedded.metadata.fromAvro(j.getEmbedded), Array((j.getDefaultArray.asScala: _*)) map { x => - x.toInt - }, j.getOptionalEnum match { - case null => None - case _ => Some(j.getOptionalEnum match { - case JDefaultEnum.SPADES => DefaultEnum.SPADES - case JDefaultEnum.DIAMONDS => DefaultEnum.DIAMONDS - case JDefaultEnum.CLUBS => DefaultEnum.CLUBS - case JDefaultEnum.HEARTS => DefaultEnum.HEARTS - }) - }, j.getDefaultMap match { - case (map: java.util.Map[_,_]) => { - scala.jdk.CollectionConverters.mapAsScalaMapConverter(map).asScala.toMap map { kvp => - val key = kvp._1.toString - val value = kvp._2 - (key, value.toString) - } - } - }, j.getByt match { - case (buffer: java.nio.ByteBuffer) => { - buffer.array() - } - }) - } - } -} diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/case/model/ImportProtocol.scala b/avrohugger-core/src/test/expected/scavro/example/idl/case/model/ImportProtocol.scala deleted file mode 100644 index c88d980a..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/case/model/ImportProtocol.scala +++ /dev/null @@ -1,84 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.case.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import other.ns.case.{ExternalDependency, Suit} - -import example.idl.{DependentRecord => JDependentRecord, DependentRecord2 => JDependentRecord2, DependentRecord3 => JDependentRecord3, Embedded => JEmbedded} - -import other.ns.{ExternalDependency => JExternalDependency, Suit => JSuit} - -sealed trait ImportProtocol extends AvroSerializeable with Product with Serializable - -final case class DependentRecord(dependency: ExternalDependency, number: Int) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord - override def toAvro: JDependentRecord = { - new JDependentRecord(dependency.toAvro, number) - } -} - -final object DependentRecord { - implicit def reader = new AvroReader[DependentRecord] { - override type J = JDependentRecord - } - implicit val metadata: AvroMetadata[DependentRecord, JDependentRecord] = new AvroMetadata[DependentRecord, JDependentRecord] { - override val avroClass: Class[JDependentRecord] = classOf[JDependentRecord] - override val schema: Schema = JDependentRecord.getClassSchema() - override val fromAvro: (JDependentRecord) => DependentRecord = { - (j: JDependentRecord) => DependentRecord(ExternalDependency.metadata.fromAvro(j.getDependency), j.getNumber.toInt) - } - } -} - -final case class DependentRecord2(dependency: Suit, name: String) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord2 - override def toAvro: JDependentRecord2 = { - new JDependentRecord2(dependency match { - case Suit.SPADES => JSuit.SPADES - case Suit.DIAMONDS => JSuit.DIAMONDS - case Suit.CLUBS => JSuit.CLUBS - case Suit.HEARTS => JSuit.HEARTS - }, name) - } -} - -final object DependentRecord2 { - implicit def reader = new AvroReader[DependentRecord2] { - override type J = JDependentRecord2 - } - implicit val metadata: AvroMetadata[DependentRecord2, JDependentRecord2] = new AvroMetadata[DependentRecord2, JDependentRecord2] { - override val avroClass: Class[JDependentRecord2] = classOf[JDependentRecord2] - override val schema: Schema = JDependentRecord2.getClassSchema() - override val fromAvro: (JDependentRecord2) => DependentRecord2 = { - (j: JDependentRecord2) => DependentRecord2(j.getDependency match { - case JSuit.SPADES => Suit.SPADES - case JSuit.DIAMONDS => Suit.DIAMONDS - case JSuit.CLUBS => Suit.CLUBS - case JSuit.HEARTS => Suit.HEARTS - }, j.getName.toString) - } - } -} - -final case class DependentRecord3(dependency: Embedded, value: Boolean) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord3 - override def toAvro: JDependentRecord3 = { - new JDependentRecord3(dependency.toAvro, value) - } -} - -final object DependentRecord3 { - implicit def reader = new AvroReader[DependentRecord3] { - override type J = JDependentRecord3 - } - implicit val metadata: AvroMetadata[DependentRecord3, JDependentRecord3] = new AvroMetadata[DependentRecord3, JDependentRecord3] { - override val avroClass: Class[JDependentRecord3] = classOf[JDependentRecord3] - override val schema: Schema = JDependentRecord3.getClassSchema() - override val fromAvro: (JDependentRecord3) => DependentRecord3 = { - (j: JDependentRecord3) => DependentRecord3(Embedded.metadata.fromAvro(j.getDependency), j.getValue) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/java/model/DefaultEnum.java b/avrohugger-core/src/test/expected/scavro/example/idl/java/model/DefaultEnum.java deleted file mode 100644 index 2cb2f420..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/java/model/DefaultEnum.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Autogenerated by Avro - * - * DO NOT EDIT DIRECTLY - */ -package example.idl.java.model; -@org.apache.avro.specific.AvroGenerated -public enum DefaultEnum implements org.apache.avro.generic.GenericEnumSymbol { - SPADES, DIAMONDS, CLUBS, HEARTS ; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"DefaultEnum\",\"namespace\":\"example.idl.java.model\",\"symbols\":[\"SPADES\",\"DIAMONDS\",\"CLUBS\",\"HEARTS\"]}"); - public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } - public org.apache.avro.Schema getSchema() { return SCHEMA$; } -} diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/java/model/Defaults.scala b/avrohugger-core/src/test/expected/scavro/example/idl/java/model/Defaults.scala deleted file mode 100644 index d837a9b0..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/java/model/Defaults.scala +++ /dev/null @@ -1,118 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.java.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{DefaultEnum => JDefaultEnum, DefaultTest => JDefaultTest, Embedded => JEmbedded} - -import scala.jdk.CollectionConverters._ - -sealed trait Defaults extends AvroSerializeable with Product with Serializable - -final case class Embedded(inner: Int) extends AvroSerializeable with Defaults { - type J = JEmbedded - override def toAvro: JEmbedded = { - new JEmbedded(inner) - } -} - -final object Embedded { - implicit def reader = new AvroReader[Embedded] { - override type J = JEmbedded - } - implicit val metadata: AvroMetadata[Embedded, JEmbedded] = new AvroMetadata[Embedded, JEmbedded] { - override val avroClass: Class[JEmbedded] = classOf[JEmbedded] - override val schema: Schema = JEmbedded.getClassSchema() - override val fromAvro: (JEmbedded) => Embedded = { - (j: JEmbedded) => Embedded(j.getInner.toInt) - } - } -} - -final case class DefaultTest(suit: DefaultEnum = DefaultEnum.SPADES, number: Int = 0, str: String = "str", optionString: Option[String] = None, optionStringValue: Option[String] = Some("default"), embedded: Embedded = new Embedded(1), defaultArray: Array[Int] = Array(1, 3, 4, 5), optionalEnum: Option[DefaultEnum] = None, defaultMap: Map[String, String] = Map("Hello" -> "world", "Merry" -> "Christmas"), byt: Array[Byte] = Array[Byte](-61, -65)) extends AvroSerializeable with Defaults { - type J = JDefaultTest - override def toAvro: JDefaultTest = { - new JDefaultTest(suit match { - case DefaultEnum.SPADES => JDefaultEnum.SPADES - case DefaultEnum.DIAMONDS => JDefaultEnum.DIAMONDS - case DefaultEnum.CLUBS => JDefaultEnum.CLUBS - case DefaultEnum.HEARTS => JDefaultEnum.HEARTS - }, number, str, optionString match { - case Some(x) => x - case None => null - }, optionStringValue match { - case Some(x) => x - case None => null - }, embedded.toAvro, { - val array: java.util.List[java.lang.Integer] = new java.util.ArrayList[java.lang.Integer] - defaultArray foreach { element => - array.add(element) - } - array - }, optionalEnum match { - case Some(x) => x match { - case DefaultEnum.SPADES => JDefaultEnum.SPADES - case DefaultEnum.DIAMONDS => JDefaultEnum.DIAMONDS - case DefaultEnum.CLUBS => JDefaultEnum.CLUBS - case DefaultEnum.HEARTS => JDefaultEnum.HEARTS - } - case None => null - }, { - val map: java.util.Map[CharSequence, CharSequence] = new java.util.HashMap[CharSequence, CharSequence] - defaultMap foreach { kvp => - val key = kvp._1 - val value = kvp._2 - map.put(key, value) - } - map - }, java.nio.ByteBuffer.wrap(byt)) - } -} - -final object DefaultTest { - implicit def reader = new AvroReader[DefaultTest] { - override type J = JDefaultTest - } - implicit val metadata: AvroMetadata[DefaultTest, JDefaultTest] = new AvroMetadata[DefaultTest, JDefaultTest] { - override val avroClass: Class[JDefaultTest] = classOf[JDefaultTest] - override val schema: Schema = JDefaultTest.getClassSchema() - override val fromAvro: (JDefaultTest) => DefaultTest = { - (j: JDefaultTest) => DefaultTest(j.getSuit match { - case JDefaultEnum.SPADES => DefaultEnum.SPADES - case JDefaultEnum.DIAMONDS => DefaultEnum.DIAMONDS - case JDefaultEnum.CLUBS => DefaultEnum.CLUBS - case JDefaultEnum.HEARTS => DefaultEnum.HEARTS - }, j.getNumber.toInt, j.getStr.toString, j.getOptionString match { - case null => None - case _ => Some(j.getOptionString.toString) - }, j.getOptionStringValue match { - case null => None - case _ => Some(j.getOptionStringValue.toString) - }, Embedded.metadata.fromAvro(j.getEmbedded), Array((j.getDefaultArray.asScala: _*)) map { x => - x.toInt - }, j.getOptionalEnum match { - case null => None - case _ => Some(j.getOptionalEnum match { - case JDefaultEnum.SPADES => DefaultEnum.SPADES - case JDefaultEnum.DIAMONDS => DefaultEnum.DIAMONDS - case JDefaultEnum.CLUBS => DefaultEnum.CLUBS - case JDefaultEnum.HEARTS => DefaultEnum.HEARTS - }) - }, j.getDefaultMap match { - case (map: java.util.Map[_,_]) => { - scala.jdk.CollectionConverters.mapAsScalaMapConverter(map).asScala.toMap map { kvp => - val key = kvp._1.toString - val value = kvp._2 - (key, value.toString) - } - } - }, j.getByt match { - case (buffer: java.nio.ByteBuffer) => { - buffer.array() - } - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/java/model/ImportProtocol.scala b/avrohugger-core/src/test/expected/scavro/example/idl/java/model/ImportProtocol.scala deleted file mode 100644 index ebe87856..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/java/model/ImportProtocol.scala +++ /dev/null @@ -1,84 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.java.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import other.ns.java.{ExternalDependency, Suit} - -import example.idl.{DependentRecord => JDependentRecord, DependentRecord2 => JDependentRecord2, DependentRecord3 => JDependentRecord3, Embedded => JEmbedded} - -import other.ns.{ExternalDependency => JExternalDependency, Suit => JSuit} - -sealed trait ImportProtocol extends AvroSerializeable with Product with Serializable - -final case class DependentRecord(dependency: ExternalDependency, number: Int) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord - override def toAvro: JDependentRecord = { - new JDependentRecord(dependency.toAvro, number) - } -} - -final object DependentRecord { - implicit def reader = new AvroReader[DependentRecord] { - override type J = JDependentRecord - } - implicit val metadata: AvroMetadata[DependentRecord, JDependentRecord] = new AvroMetadata[DependentRecord, JDependentRecord] { - override val avroClass: Class[JDependentRecord] = classOf[JDependentRecord] - override val schema: Schema = JDependentRecord.getClassSchema() - override val fromAvro: (JDependentRecord) => DependentRecord = { - (j: JDependentRecord) => DependentRecord(ExternalDependency.metadata.fromAvro(j.getDependency), j.getNumber.toInt) - } - } -} - -final case class DependentRecord2(dependency: Suit, name: String) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord2 - override def toAvro: JDependentRecord2 = { - new JDependentRecord2(dependency match { - case Suit.SPADES => JSuit.SPADES - case Suit.DIAMONDS => JSuit.DIAMONDS - case Suit.CLUBS => JSuit.CLUBS - case Suit.HEARTS => JSuit.HEARTS - }, name) - } -} - -final object DependentRecord2 { - implicit def reader = new AvroReader[DependentRecord2] { - override type J = JDependentRecord2 - } - implicit val metadata: AvroMetadata[DependentRecord2, JDependentRecord2] = new AvroMetadata[DependentRecord2, JDependentRecord2] { - override val avroClass: Class[JDependentRecord2] = classOf[JDependentRecord2] - override val schema: Schema = JDependentRecord2.getClassSchema() - override val fromAvro: (JDependentRecord2) => DependentRecord2 = { - (j: JDependentRecord2) => DependentRecord2(j.getDependency match { - case JSuit.SPADES => Suit.SPADES - case JSuit.DIAMONDS => Suit.DIAMONDS - case JSuit.CLUBS => Suit.CLUBS - case JSuit.HEARTS => Suit.HEARTS - }, j.getName.toString) - } - } -} - -final case class DependentRecord3(dependency: Embedded, value: Boolean) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord3 - override def toAvro: JDependentRecord3 = { - new JDependentRecord3(dependency.toAvro, value) - } -} - -final object DependentRecord3 { - implicit def reader = new AvroReader[DependentRecord3] { - override type J = JDependentRecord3 - } - implicit val metadata: AvroMetadata[DependentRecord3, JDependentRecord3] = new AvroMetadata[DependentRecord3, JDependentRecord3] { - override val avroClass: Class[JDependentRecord3] = classOf[JDependentRecord3] - override val schema: Schema = JDependentRecord3.getClassSchema() - override val fromAvro: (JDependentRecord3) => DependentRecord3 = { - (j: JDependentRecord3) => DependentRecord3(Embedded.metadata.fromAvro(j.getDependency), j.getValue) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/model/BinaryIdl.scala b/avrohugger-core/src/test/expected/scavro/example/idl/model/BinaryIdl.scala deleted file mode 100644 index 1fbd4a9f..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/model/BinaryIdl.scala +++ /dev/null @@ -1,32 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{BinaryIdl => JBinaryIdl} - -final case class BinaryIdl(data: Array[Byte]) extends AvroSerializeable { - type J = JBinaryIdl - override def toAvro: JBinaryIdl = { - new JBinaryIdl(java.nio.ByteBuffer.wrap(data)) - } -} - -object BinaryIdl { - implicit def reader = new AvroReader[BinaryIdl] { - override type J = JBinaryIdl - } - implicit val metadata: AvroMetadata[BinaryIdl, JBinaryIdl] = new AvroMetadata[BinaryIdl, JBinaryIdl] { - override val avroClass: Class[JBinaryIdl] = classOf[JBinaryIdl] - override val schema: Schema = JBinaryIdl.getClassSchema() - override val fromAvro: (JBinaryIdl) => BinaryIdl = { - (j: JBinaryIdl) => BinaryIdl(j.getData match { - case (buffer: java.nio.ByteBuffer) => { - buffer.array() - } - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/model/Defaults.scala b/avrohugger-core/src/test/expected/scavro/example/idl/model/Defaults.scala deleted file mode 100644 index 5c9e6557..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/model/Defaults.scala +++ /dev/null @@ -1,123 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{DefaultEnum => JDefaultEnum, DefaultTest => JDefaultTest, Embedded => JEmbedded} - -import scala.jdk.CollectionConverters._ - -sealed trait Defaults - -final object DefaultEnum extends Enumeration with Defaults { - type DefaultEnum = Value - val SPADES, DIAMONDS, CLUBS, HEARTS = Value -} - -final case class Embedded(inner: Int) extends AvroSerializeable with Defaults { - type J = JEmbedded - override def toAvro: JEmbedded = { - new JEmbedded(inner) - } -} - -final object Embedded { - implicit def reader = new AvroReader[Embedded] { - override type J = JEmbedded - } - implicit val metadata: AvroMetadata[Embedded, JEmbedded] = new AvroMetadata[Embedded, JEmbedded] { - override val avroClass: Class[JEmbedded] = classOf[JEmbedded] - override val schema: Schema = JEmbedded.getClassSchema() - override val fromAvro: (JEmbedded) => Embedded = { - (j: JEmbedded) => Embedded(j.getInner.toInt) - } - } -} - -final case class DefaultTest(suit: DefaultEnum.Value = DefaultEnum.SPADES, number: Int = 0, str: String = "str", optionString: Option[String] = None, optionStringValue: Option[String] = Some("default"), embedded: example.idl.Embedded = new Embedded(1), defaultArray: Array[Int] = Array(1, 3, 4, 5), optionalEnum: Option[DefaultEnum.Value] = None, defaultMap: Map[String, String] = Map("Hello" -> "world", "Merry" -> "Christmas"), byt: Array[Byte] = Array[Byte](-61, -65)) extends AvroSerializeable with Defaults { - type J = JDefaultTest - override def toAvro: JDefaultTest = { - new JDefaultTest(suit match { - case DefaultEnum.SPADES => JDefaultEnum.SPADES - case DefaultEnum.DIAMONDS => JDefaultEnum.DIAMONDS - case DefaultEnum.CLUBS => JDefaultEnum.CLUBS - case DefaultEnum.HEARTS => JDefaultEnum.HEARTS - }, number, str, optionString match { - case Some(x) => x - case None => null - }, optionStringValue match { - case Some(x) => x - case None => null - }, embedded.toAvro, { - val array: java.util.List[java.lang.Integer] = new java.util.ArrayList[java.lang.Integer] - defaultArray foreach { element => - array.add(element) - } - array - }, optionalEnum match { - case Some(x) => x match { - case DefaultEnum.SPADES => JDefaultEnum.SPADES - case DefaultEnum.DIAMONDS => JDefaultEnum.DIAMONDS - case DefaultEnum.CLUBS => JDefaultEnum.CLUBS - case DefaultEnum.HEARTS => JDefaultEnum.HEARTS - } - case None => null - }, { - val map: java.util.Map[CharSequence, CharSequence] = new java.util.HashMap[CharSequence, CharSequence] - defaultMap foreach { kvp => - val key = kvp._1 - val value = kvp._2 - map.put(key, value) - } - map - }, java.nio.ByteBuffer.wrap(byt)) - } -} - -final object DefaultTest { - implicit def reader = new AvroReader[DefaultTest] { - override type J = JDefaultTest - } - implicit val metadata: AvroMetadata[DefaultTest, JDefaultTest] = new AvroMetadata[DefaultTest, JDefaultTest] { - override val avroClass: Class[JDefaultTest] = classOf[JDefaultTest] - override val schema: Schema = JDefaultTest.getClassSchema() - override val fromAvro: (JDefaultTest) => DefaultTest = { - (j: JDefaultTest) => DefaultTest(j.getSuit match { - case JDefaultEnum.SPADES => DefaultEnum.SPADES - case JDefaultEnum.DIAMONDS => DefaultEnum.DIAMONDS - case JDefaultEnum.CLUBS => DefaultEnum.CLUBS - case JDefaultEnum.HEARTS => DefaultEnum.HEARTS - }, j.getNumber.toInt, j.getStr.toString, j.getOptionString match { - case null => None - case _ => Some(j.getOptionString.toString) - }, j.getOptionStringValue match { - case null => None - case _ => Some(j.getOptionStringValue.toString) - }, Embedded.metadata.fromAvro(j.getEmbedded), Array((j.getDefaultArray.asScala: _*)) map { x => - x.toInt - }, j.getOptionalEnum match { - case null => None - case _ => Some(j.getOptionalEnum match { - case JDefaultEnum.SPADES => DefaultEnum.SPADES - case JDefaultEnum.DIAMONDS => DefaultEnum.DIAMONDS - case JDefaultEnum.CLUBS => DefaultEnum.CLUBS - case JDefaultEnum.HEARTS => DefaultEnum.HEARTS - }) - }, j.getDefaultMap match { - case (map: java.util.Map[_,_]) => { - scala.jdk.CollectionConverters.mapAsScalaMapConverter(map).asScala.toMap map { kvp => - val key = kvp._1.toString - val value = kvp._2 - (key, value.toString) - } - } - }, j.getByt match { - case (buffer: java.nio.ByteBuffer) => { - buffer.array() - } - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/model/EnumProtocol.scala b/avrohugger-core/src/test/expected/scavro/example/idl/model/EnumProtocol.scala deleted file mode 100644 index bccccc68..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/model/EnumProtocol.scala +++ /dev/null @@ -1,45 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{Card => JCard, Suit => JSuit} - -sealed trait EnumProtocol - -final object Suit extends Enumeration with EnumProtocol { - type Suit = Value - val SPADES, DIAMONDS, CLUBS, HEARTS = Value -} - -final case class Card(suit: Suit.Value, number: Int) extends AvroSerializeable with EnumProtocol { - type J = JCard - override def toAvro: JCard = { - new JCard(suit match { - case Suit.SPADES => JSuit.SPADES - case Suit.DIAMONDS => JSuit.DIAMONDS - case Suit.CLUBS => JSuit.CLUBS - case Suit.HEARTS => JSuit.HEARTS - }, number) - } -} - -final object Card { - implicit def reader = new AvroReader[Card] { - override type J = JCard - } - implicit val metadata: AvroMetadata[Card, JCard] = new AvroMetadata[Card, JCard] { - override val avroClass: Class[JCard] = classOf[JCard] - override val schema: Schema = JCard.getClassSchema() - override val fromAvro: (JCard) => Card = { - (j: JCard) => Card(j.getSuit match { - case JSuit.SPADES => Suit.SPADES - case JSuit.DIAMONDS => Suit.DIAMONDS - case JSuit.CLUBS => Suit.CLUBS - case JSuit.HEARTS => Suit.HEARTS - }, j.getNumber.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/model/ImportProtocol.scala b/avrohugger-core/src/test/expected/scavro/example/idl/model/ImportProtocol.scala deleted file mode 100644 index 55ef838b..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/model/ImportProtocol.scala +++ /dev/null @@ -1,84 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import other.ns.model.{ExternalDependency, Suit} - -import example.idl.{DependentRecord => JDependentRecord, DependentRecord2 => JDependentRecord2, DependentRecord3 => JDependentRecord3, Embedded => JEmbedded} - -import other.ns.{ExternalDependency => JExternalDependency, Suit => JSuit} - -sealed trait ImportProtocol extends AvroSerializeable with Product with Serializable - -final case class DependentRecord(dependency: ExternalDependency, number: Int) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord - override def toAvro: JDependentRecord = { - new JDependentRecord(dependency.toAvro, number) - } -} - -final object DependentRecord { - implicit def reader = new AvroReader[DependentRecord] { - override type J = JDependentRecord - } - implicit val metadata: AvroMetadata[DependentRecord, JDependentRecord] = new AvroMetadata[DependentRecord, JDependentRecord] { - override val avroClass: Class[JDependentRecord] = classOf[JDependentRecord] - override val schema: Schema = JDependentRecord.getClassSchema() - override val fromAvro: (JDependentRecord) => DependentRecord = { - (j: JDependentRecord) => DependentRecord(ExternalDependency.metadata.fromAvro(j.getDependency), j.getNumber.toInt) - } - } -} - -final case class DependentRecord2(dependency: Suit.Value, name: String) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord2 - override def toAvro: JDependentRecord2 = { - new JDependentRecord2(dependency match { - case Suit.SPADES => JSuit.SPADES - case Suit.DIAMONDS => JSuit.DIAMONDS - case Suit.CLUBS => JSuit.CLUBS - case Suit.HEARTS => JSuit.HEARTS - }, name) - } -} - -final object DependentRecord2 { - implicit def reader = new AvroReader[DependentRecord2] { - override type J = JDependentRecord2 - } - implicit val metadata: AvroMetadata[DependentRecord2, JDependentRecord2] = new AvroMetadata[DependentRecord2, JDependentRecord2] { - override val avroClass: Class[JDependentRecord2] = classOf[JDependentRecord2] - override val schema: Schema = JDependentRecord2.getClassSchema() - override val fromAvro: (JDependentRecord2) => DependentRecord2 = { - (j: JDependentRecord2) => DependentRecord2(j.getDependency match { - case JSuit.SPADES => Suit.SPADES - case JSuit.DIAMONDS => Suit.DIAMONDS - case JSuit.CLUBS => Suit.CLUBS - case JSuit.HEARTS => Suit.HEARTS - }, j.getName.toString) - } - } -} - -final case class DependentRecord3(dependency: Embedded, value: Boolean) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord3 - override def toAvro: JDependentRecord3 = { - new JDependentRecord3(dependency.toAvro, value) - } -} - -final object DependentRecord3 { - implicit def reader = new AvroReader[DependentRecord3] { - override type J = JDependentRecord3 - } - implicit val metadata: AvroMetadata[DependentRecord3, JDependentRecord3] = new AvroMetadata[DependentRecord3, JDependentRecord3] { - override val avroClass: Class[JDependentRecord3] = classOf[JDependentRecord3] - override val schema: Schema = JDependentRecord3.getClassSchema() - override val fromAvro: (JDependentRecord3) => DependentRecord3 = { - (j: JDependentRecord3) => DependentRecord3(Embedded.metadata.fromAvro(j.getDependency), j.getValue) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/model/Names.scala b/avrohugger-core/src/test/expected/scavro/example/idl/model/Names.scala deleted file mode 100644 index 8bae2981..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/model/Names.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{Names => JNames} - -final case class Names(`protected`: String, `ends_with_`: String) extends AvroSerializeable { - type J = JNames - override def toAvro: JNames = { - new JNames(`protected`, `ends_with_`) - } -} - -object Names { - implicit def reader = new AvroReader[Names] { - override type J = JNames - } - implicit val metadata: AvroMetadata[Names, JNames] = new AvroMetadata[Names, JNames] { - override val avroClass: Class[JNames] = classOf[JNames] - override val schema: Schema = JNames.getClassSchema() - override val fromAvro: (JNames) => Names = { - (j: JNames) => Names(j.getProtected$.toString, j.getEndsWith.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/model/NestedProtocol.scala b/avrohugger-core/src/test/expected/scavro/example/idl/model/NestedProtocol.scala deleted file mode 100644 index ae6bce86..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/model/NestedProtocol.scala +++ /dev/null @@ -1,70 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{Level0 => JLevel0, Level1 => JLevel1, Level2 => JLevel2} - -sealed trait NestedProtocol extends AvroSerializeable with Product with Serializable - -final case class Level2(name: String) extends AvroSerializeable with NestedProtocol { - type J = JLevel2 - override def toAvro: JLevel2 = { - new JLevel2(name) - } -} - -final object Level2 { - implicit def reader = new AvroReader[Level2] { - override type J = JLevel2 - } - implicit val metadata: AvroMetadata[Level2, JLevel2] = new AvroMetadata[Level2, JLevel2] { - override val avroClass: Class[JLevel2] = classOf[JLevel2] - override val schema: Schema = JLevel2.getClassSchema() - override val fromAvro: (JLevel2) => Level2 = { - (j: JLevel2) => Level2(j.getName.toString) - } - } -} - -final case class Level1(level2: example.idl.Level2) extends AvroSerializeable with NestedProtocol { - type J = JLevel1 - override def toAvro: JLevel1 = { - new JLevel1(level2.toAvro) - } -} - -final object Level1 { - implicit def reader = new AvroReader[Level1] { - override type J = JLevel1 - } - implicit val metadata: AvroMetadata[Level1, JLevel1] = new AvroMetadata[Level1, JLevel1] { - override val avroClass: Class[JLevel1] = classOf[JLevel1] - override val schema: Schema = JLevel1.getClassSchema() - override val fromAvro: (JLevel1) => Level1 = { - (j: JLevel1) => Level1(Level2.metadata.fromAvro(j.getLevel2)) - } - } -} - -final case class Level0(level1: example.idl.Level1) extends AvroSerializeable with NestedProtocol { - type J = JLevel0 - override def toAvro: JLevel0 = { - new JLevel0(level1.toAvro) - } -} - -final object Level0 { - implicit def reader = new AvroReader[Level0] { - override type J = JLevel0 - } - implicit val metadata: AvroMetadata[Level0, JLevel0] = new AvroMetadata[Level0, JLevel0] { - override val avroClass: Class[JLevel0] = classOf[JLevel0] - override val schema: Schema = JLevel0.getClassSchema() - override val fromAvro: (JLevel0) => Level0 = { - (j: JLevel0) => Level0(Level1.metadata.fromAvro(j.getLevel1)) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/model/Recursive.scala b/avrohugger-core/src/test/expected/scavro/example/idl/model/Recursive.scala deleted file mode 100644 index e2533119..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/model/Recursive.scala +++ /dev/null @@ -1,34 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{Recursive => JRecursive} - -final case class Recursive(name: String, recursive: Option[example.idl.Recursive]) extends AvroSerializeable { - type J = JRecursive - override def toAvro: JRecursive = { - new JRecursive(name, recursive match { - case Some(x) => x.toAvro - case None => null - }) - } -} - -object Recursive { - implicit def reader = new AvroReader[Recursive] { - override type J = JRecursive - } - implicit val metadata: AvroMetadata[Recursive, JRecursive] = new AvroMetadata[Recursive, JRecursive] { - override val avroClass: Class[JRecursive] = classOf[JRecursive] - override val schema: Schema = JRecursive.getClassSchema() - override val fromAvro: (JRecursive) => Recursive = { - (j: JRecursive) => Recursive(j.getName.toString, j.getRecursive match { - case null => None - case _ => Some(Recursive.metadata.fromAvro(j.getRecursive)) - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/seq/model/Defaults.scala b/avrohugger-core/src/test/expected/scavro/example/idl/seq/model/Defaults.scala deleted file mode 100644 index 67475944..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/seq/model/Defaults.scala +++ /dev/null @@ -1,127 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.seq.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{DefaultEnum => JDefaultEnum, DefaultTest => JDefaultTest, Embedded => JEmbedded} - -import scala.jdk.CollectionConverters._ - -sealed trait Defaults - -sealed trait DefaultEnum extends Defaults - -object DefaultEnum { - case object SPADES extends DefaultEnum - case object DIAMONDS extends DefaultEnum - case object CLUBS extends DefaultEnum - case object HEARTS extends DefaultEnum -} - -final case class Embedded(inner: Int) extends AvroSerializeable with Defaults { - type J = JEmbedded - override def toAvro: JEmbedded = { - new JEmbedded(inner) - } -} - -final object Embedded { - implicit def reader = new AvroReader[Embedded] { - override type J = JEmbedded - } - implicit val metadata: AvroMetadata[Embedded, JEmbedded] = new AvroMetadata[Embedded, JEmbedded] { - override val avroClass: Class[JEmbedded] = classOf[JEmbedded] - override val schema: Schema = JEmbedded.getClassSchema() - override val fromAvro: (JEmbedded) => Embedded = { - (j: JEmbedded) => Embedded(j.getInner.toInt) - } - } -} - -final case class DefaultTest(suit: DefaultEnum = DefaultEnum.SPADES, number: Int = 0, str: String = "str", optionString: Option[String] = None, optionStringValue: Option[String] = Some("default"), embedded: Embedded = new Embedded(1), defaultArray: Seq[Int] = Seq(1, 3, 4, 5), optionalEnum: Option[DefaultEnum] = None, defaultMap: Map[String, String] = Map("Hello" -> "world", "Merry" -> "Christmas"), byt: Array[Byte] = Array[Byte](-61, -65)) extends AvroSerializeable with Defaults { - type J = JDefaultTest - override def toAvro: JDefaultTest = { - new JDefaultTest(suit match { - case DefaultEnum.SPADES => JDefaultEnum.SPADES - case DefaultEnum.DIAMONDS => JDefaultEnum.DIAMONDS - case DefaultEnum.CLUBS => JDefaultEnum.CLUBS - case DefaultEnum.HEARTS => JDefaultEnum.HEARTS - }, number, str, optionString match { - case Some(x) => x - case None => null - }, optionStringValue match { - case Some(x) => x - case None => null - }, embedded.toAvro, { - val array: java.util.List[java.lang.Integer] = new java.util.ArrayList[java.lang.Integer] - defaultArray foreach { element => - array.add(element) - } - array - }, optionalEnum match { - case Some(x) => x match { - case DefaultEnum.SPADES => JDefaultEnum.SPADES - case DefaultEnum.DIAMONDS => JDefaultEnum.DIAMONDS - case DefaultEnum.CLUBS => JDefaultEnum.CLUBS - case DefaultEnum.HEARTS => JDefaultEnum.HEARTS - } - case None => null - }, { - val map: java.util.Map[CharSequence, CharSequence] = new java.util.HashMap[CharSequence, CharSequence] - defaultMap foreach { kvp => - val key = kvp._1 - val value = kvp._2 - map.put(key, value) - } - map - }, java.nio.ByteBuffer.wrap(byt)) - } -} - -final object DefaultTest { - implicit def reader = new AvroReader[DefaultTest] { - override type J = JDefaultTest - } - implicit val metadata: AvroMetadata[DefaultTest, JDefaultTest] = new AvroMetadata[DefaultTest, JDefaultTest] { - override val avroClass: Class[JDefaultTest] = classOf[JDefaultTest] - override val schema: Schema = JDefaultTest.getClassSchema() - override val fromAvro: (JDefaultTest) => DefaultTest = { - (j: JDefaultTest) => DefaultTest(j.getSuit match { - case JDefaultEnum.SPADES => DefaultEnum.SPADES - case JDefaultEnum.DIAMONDS => DefaultEnum.DIAMONDS - case JDefaultEnum.CLUBS => DefaultEnum.CLUBS - case JDefaultEnum.HEARTS => DefaultEnum.HEARTS - }, j.getNumber.toInt, j.getStr.toString, j.getOptionString match { - case null => None - case _ => Some(j.getOptionString.toString) - }, j.getOptionStringValue match { - case null => None - case _ => Some(j.getOptionStringValue.toString) - }, Embedded.metadata.fromAvro(j.getEmbedded), Seq((j.getDefaultArray.asScala: _*)) map { x => - x.toInt - }, j.getOptionalEnum match { - case null => None - case _ => Some(j.getOptionalEnum match { - case JDefaultEnum.SPADES => DefaultEnum.SPADES - case JDefaultEnum.DIAMONDS => DefaultEnum.DIAMONDS - case JDefaultEnum.CLUBS => DefaultEnum.CLUBS - case JDefaultEnum.HEARTS => DefaultEnum.HEARTS - }) - }, j.getDefaultMap match { - case (map: java.util.Map[_,_]) => { - scala.collection.JavaConverters.mapAsScalaMapConverter(map).asScala.toMap map { kvp => - val key = kvp._1.toString - val value = kvp._2 - (key, value.toString) - } - } - }, j.getByt match { - case (buffer: java.nio.ByteBuffer) => { - buffer.array() - } - }) - } - } -} diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/string/model/Defaults.scala b/avrohugger-core/src/test/expected/scavro/example/idl/string/model/Defaults.scala deleted file mode 100644 index 14c1ddf7..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/string/model/Defaults.scala +++ /dev/null @@ -1,98 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.string.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{DefaultTest => JDefaultTest, Embedded => JEmbedded} - -import scala.jdk.CollectionConverters._ - -sealed trait Defaults extends AvroSerializeable with Product with Serializable - -final case class Embedded(inner: Int) extends AvroSerializeable with Defaults { - type J = JEmbedded - override def toAvro: JEmbedded = { - new JEmbedded(inner) - } -} - -final object Embedded { - implicit def reader = new AvroReader[Embedded] { - override type J = JEmbedded - } - implicit val metadata: AvroMetadata[Embedded, JEmbedded] = new AvroMetadata[Embedded, JEmbedded] { - override val avroClass: Class[JEmbedded] = classOf[JEmbedded] - override val schema: Schema = JEmbedded.getClassSchema() - override val fromAvro: (JEmbedded) => Embedded = { - (j: JEmbedded) => Embedded(j.getInner.toInt) - } - } -} - -final case class DefaultTest(suit: String = "SPADES", number: Int = 0, str: String = "str", optionString: Option[String] = None, optionStringValue: Option[String] = Some("default"), embedded: Embedded = new Embedded(1), defaultArray: Array[Int] = Array(1, 3, 4, 5), optionalEnum: Option[String] = None, defaultMap: Map[String, String] = Map("Hello" -> "world", "Merry" -> "Christmas"), byt: Array[Byte] = Array[Byte](-61, -65)) extends AvroSerializeable with Defaults { - type J = JDefaultTest - override def toAvro: JDefaultTest = { - new JDefaultTest(suit, number, str, optionString match { - case Some(x) => x - case None => null - }, optionStringValue match { - case Some(x) => x - case None => null - }, embedded.toAvro, { - val array: java.util.List[java.lang.Integer] = new java.util.ArrayList[java.lang.Integer] - defaultArray foreach { element => - array.add(element) - } - array - }, optionalEnum match { - case Some(x) => x - case None => null - }, { - val map: java.util.Map[CharSequence, CharSequence] = new java.util.HashMap[CharSequence, CharSequence] - defaultMap foreach { kvp => - val key = kvp._1 - val value = kvp._2 - map.put(key, value) - } - map - }, java.nio.ByteBuffer.wrap(byt)) - } -} - -final object DefaultTest { - implicit def reader = new AvroReader[DefaultTest] { - override type J = JDefaultTest - } - implicit val metadata: AvroMetadata[DefaultTest, JDefaultTest] = new AvroMetadata[DefaultTest, JDefaultTest] { - override val avroClass: Class[JDefaultTest] = classOf[JDefaultTest] - override val schema: Schema = JDefaultTest.getClassSchema() - override val fromAvro: (JDefaultTest) => DefaultTest = { - (j: JDefaultTest) => DefaultTest(j.getSuit.toString, j.getNumber.toInt, j.getStr.toString, j.getOptionString match { - case null => None - case _ => Some(j.getOptionString.toString) - }, j.getOptionStringValue match { - case null => None - case _ => Some(j.getOptionStringValue.toString) - }, Embedded.metadata.fromAvro(j.getEmbedded), Array((j.getDefaultArray.asScala: _*)) map { x => - x.toInt - }, j.getOptionalEnum match { - case null => None - case _ => Some(j.getOptionalEnum.toString) - }, j.getDefaultMap match { - case (map: java.util.Map[_,_]) => { - scala.collection.JavaConverters.mapAsScalaMapConverter(map).asScala.toMap map { kvp => - val key = kvp._1.toString - val value = kvp._2 - (key, value.toString) - } - } - }, j.getByt match { - case (buffer: java.nio.ByteBuffer) => { - buffer.array() - } - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/idl/string/model/ImportProtocol.scala b/avrohugger-core/src/test/expected/scavro/example/idl/string/model/ImportProtocol.scala deleted file mode 100644 index d336a1c2..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/idl/string/model/ImportProtocol.scala +++ /dev/null @@ -1,74 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.string.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import other.ns.string.ExternalDependency - -import example.idl.{DependentRecord => JDependentRecord, DependentRecord2 => JDependentRecord2, DependentRecord3 => JDependentRecord3, Embedded => JEmbedded} - -import other.ns.{ExternalDependency => JExternalDependency} - -sealed trait ImportProtocol extends AvroSerializeable with Product with Serializable - -final case class DependentRecord(dependency: ExternalDependency, number: Int) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord - override def toAvro: JDependentRecord = { - new JDependentRecord(dependency.toAvro, number) - } -} - -final object DependentRecord { - implicit def reader = new AvroReader[DependentRecord] { - override type J = JDependentRecord - } - implicit val metadata: AvroMetadata[DependentRecord, JDependentRecord] = new AvroMetadata[DependentRecord, JDependentRecord] { - override val avroClass: Class[JDependentRecord] = classOf[JDependentRecord] - override val schema: Schema = JDependentRecord.getClassSchema() - override val fromAvro: (JDependentRecord) => DependentRecord = { - (j: JDependentRecord) => DependentRecord(ExternalDependency.metadata.fromAvro(j.getDependency), j.getNumber.toInt) - } - } -} - -final case class DependentRecord2(dependency: String, name: String) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord2 - override def toAvro: JDependentRecord2 = { - new JDependentRecord2(dependency, name) - } -} - -final object DependentRecord2 { - implicit def reader = new AvroReader[DependentRecord2] { - override type J = JDependentRecord2 - } - implicit val metadata: AvroMetadata[DependentRecord2, JDependentRecord2] = new AvroMetadata[DependentRecord2, JDependentRecord2] { - override val avroClass: Class[JDependentRecord2] = classOf[JDependentRecord2] - override val schema: Schema = JDependentRecord2.getClassSchema() - override val fromAvro: (JDependentRecord2) => DependentRecord2 = { - (j: JDependentRecord2) => DependentRecord2(j.getDependency.toString, j.getName.toString) - } - } -} - -final case class DependentRecord3(dependency: Embedded, value: Boolean) extends AvroSerializeable with ImportProtocol { - type J = JDependentRecord3 - override def toAvro: JDependentRecord3 = { - new JDependentRecord3(dependency.toAvro, value) - } -} - -final object DependentRecord3 { - implicit def reader = new AvroReader[DependentRecord3] { - override type J = JDependentRecord3 - } - implicit val metadata: AvroMetadata[DependentRecord3, JDependentRecord3] = new AvroMetadata[DependentRecord3, JDependentRecord3] { - override val avroClass: Class[JDependentRecord3] = classOf[JDependentRecord3] - override val schema: Schema = JDependentRecord3.getClassSchema() - override val fromAvro: (JDependentRecord3) => DependentRecord3 = { - (j: JDependentRecord3) => DependentRecord3(Embedded.metadata.fromAvro(j.getDependency), j.getValue) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/BinarySc.scala b/avrohugger-core/src/test/expected/scavro/example/model/BinarySc.scala deleted file mode 100644 index 8c770b6f..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/BinarySc.scala +++ /dev/null @@ -1,32 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.{BinarySc => JBinarySc} - -final case class BinarySc(data: Array[Byte]) extends AvroSerializeable { - type J = JBinarySc - override def toAvro: JBinarySc = { - new JBinarySc(java.nio.ByteBuffer.wrap(data)) - } -} - -object BinarySc { - implicit def reader = new AvroReader[BinarySc] { - override type J = JBinarySc - } - implicit val metadata: AvroMetadata[BinarySc, JBinarySc] = new AvroMetadata[BinarySc, JBinarySc] { - override val avroClass: Class[JBinarySc] = classOf[JBinarySc] - override val schema: Schema = JBinarySc.getClassSchema() - override val fromAvro: (JBinarySc) => BinarySc = { - (j: JBinarySc) => BinarySc(j.getData match { - case (buffer: java.nio.ByteBuffer) => { - buffer.array() - } - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/ClashInner.scala b/avrohugger-core/src/test/expected/scavro/example/model/ClashInner.scala deleted file mode 100644 index ae86779d..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/ClashInner.scala +++ /dev/null @@ -1,46 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.avro.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.avro.{ClashInner => JClashInner} - -final case class ClashInner(some: Option[Int], other: Option[Int], id: Option[Int]) extends AvroSerializeable { - type J = JClashInner - override def toAvro: JClashInner = { - new JClashInner(some match { - case Some(x) => x - case None => null - }, other match { - case Some(x) => x - case None => null - }, id match { - case Some(x) => x - case None => null - }) - } -} - -object ClashInner { - implicit def reader = new AvroReader[ClashInner] { - override type J = JClashInner - } - implicit val metadata: AvroMetadata[ClashInner, JClashInner] = new AvroMetadata[ClashInner, JClashInner] { - override val avroClass: Class[JClashInner] = classOf[JClashInner] - override val schema: Schema = JClashInner.getClassSchema() - override val fromAvro: (JClashInner) => ClashInner = { - (j: JClashInner) => ClashInner(j.getSome match { - case null => None - case _ => Some(j.getSome.toInt) - }, j.getOther match { - case null => None - case _ => Some(j.getOther.toInt) - }, j.getId match { - case null => None - case _ => Some(j.getId.toInt) - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/ClashOuter.scala b/avrohugger-core/src/test/expected/scavro/example/model/ClashOuter.scala deleted file mode 100644 index 4b13ca3b..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/ClashOuter.scala +++ /dev/null @@ -1,50 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.avro.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.avro.{ClashInner => JClashInner, ClashOuter => JClashOuter} - -import scala.jdk.CollectionConverters._ - -final case class ClashOuter(inner: Option[Array[Option[example.avro.ClashInner]]]) extends AvroSerializeable { - type J = JClashOuter - override def toAvro: JClashOuter = { - new JClashOuter(inner match { - case Some(x) => { - val array: java.util.List[JClashInner] = new java.util.ArrayList[JClashInner] - x foreach { element => - array.add(element match { - case Some(x) => x.toAvro - case None => null - }) - } - array - } - case None => null - }) - } -} - -object ClashOuter { - implicit def reader = new AvroReader[ClashOuter] { - override type J = JClashOuter - } - implicit val metadata: AvroMetadata[ClashOuter, JClashOuter] = new AvroMetadata[ClashOuter, JClashOuter] { - override val avroClass: Class[JClashOuter] = classOf[JClashOuter] - override val schema: Schema = JClashOuter.getClassSchema() - override val fromAvro: (JClashOuter) => ClashOuter = { - (j: JClashOuter) => ClashOuter(j.getInner match { - case null => None - case _ => Some(Array((j.getInner.asScala: _*)) map { x => - x match { - case null => None - case _ => Some(ClashInner.metadata.fromAvro(x)) - } - }) - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/ClashRecord.scala b/avrohugger-core/src/test/expected/scavro/example/model/ClashRecord.scala deleted file mode 100644 index 7844015c..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/ClashRecord.scala +++ /dev/null @@ -1,30 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.avro.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.avro.{ClashInner => JClashInner, ClashOuter => JClashOuter, ClashRecord => JClashRecord} - -import scala.jdk.CollectionConverters._ - -final case class ClashRecord(some: Int, outer: example.avro.ClashOuter, id: Int) extends AvroSerializeable { - type J = JClashRecord - override def toAvro: JClashRecord = { - new JClashRecord(some, outer.toAvro, id) - } -} - -object ClashRecord { - implicit def reader = new AvroReader[ClashRecord] { - override type J = JClashRecord - } - implicit val metadata: AvroMetadata[ClashRecord, JClashRecord] = new AvroMetadata[ClashRecord, JClashRecord] { - override val avroClass: Class[JClashRecord] = classOf[JClashRecord] - override val schema: Schema = JClashRecord.getClassSchema() - override val fromAvro: (JClashRecord) => ClashRecord = { - (j: JClashRecord) => ClashRecord(j.getSome.toInt, ClashOuter.metadata.fromAvro(j.getOuter), j.getId.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/Compass.scala b/avrohugger-core/src/test/expected/scavro/example/model/Compass.scala deleted file mode 100644 index 3eac22df..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/Compass.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.{Compass => JCompass, Direction => JDirection} - -final case class Compass(direction: Direction.Value) extends AvroSerializeable { - type J = JCompass - override def toAvro: JCompass = { - new JCompass(direction match { - case Direction.NORTH => JDirection.NORTH - case Direction.SOUTH => JDirection.SOUTH - case Direction.EAST => JDirection.EAST - case Direction.WEST => JDirection.WEST - }) - } -} - -object Compass { - implicit def reader = new AvroReader[Compass] { - override type J = JCompass - } - implicit val metadata: AvroMetadata[Compass, JCompass] = new AvroMetadata[Compass, JCompass] { - override val avroClass: Class[JCompass] = classOf[JCompass] - override val schema: Schema = JCompass.getClassSchema() - override val fromAvro: (JCompass) => Compass = { - (j: JCompass) => Compass(j.getDirection match { - case JDirection.NORTH => Direction.NORTH - case JDirection.SOUTH => Direction.SOUTH - case JDirection.EAST => Direction.EAST - case JDirection.WEST => Direction.WEST - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/Direction.scala b/avrohugger-core/src/test/expected/scavro/example/model/Direction.scala deleted file mode 100644 index b062efec..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/Direction.scala +++ /dev/null @@ -1,7 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.model - -object Direction extends Enumeration { - type Direction = Value - val NORTH, SOUTH, EAST, WEST = Value -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/Level0.scala b/avrohugger-core/src/test/expected/scavro/example/model/Level0.scala deleted file mode 100644 index cd7e0dcb..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/Level0.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.{Level0 => JLevel0, Level1 => JLevel1, Level2 => JLevel2} - -final case class Level0(level1: Level1) extends AvroSerializeable { - type J = JLevel0 - override def toAvro: JLevel0 = { - new JLevel0(level1.toAvro) - } -} - -object Level0 { - implicit def reader = new AvroReader[Level0] { - override type J = JLevel0 - } - implicit val metadata: AvroMetadata[Level0, JLevel0] = new AvroMetadata[Level0, JLevel0] { - override val avroClass: Class[JLevel0] = classOf[JLevel0] - override val schema: Schema = JLevel0.getClassSchema() - override val fromAvro: (JLevel0) => Level0 = { - (j: JLevel0) => Level0(Level1.metadata.fromAvro(j.getLevel1)) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/Level1.scala b/avrohugger-core/src/test/expected/scavro/example/model/Level1.scala deleted file mode 100644 index e33e3bb7..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/Level1.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.{Level1 => JLevel1, Level2 => JLevel2} - -final case class Level1(level2: Level2) extends AvroSerializeable { - type J = JLevel1 - override def toAvro: JLevel1 = { - new JLevel1(level2.toAvro) - } -} - -object Level1 { - implicit def reader = new AvroReader[Level1] { - override type J = JLevel1 - } - implicit val metadata: AvroMetadata[Level1, JLevel1] = new AvroMetadata[Level1, JLevel1] { - override val avroClass: Class[JLevel1] = classOf[JLevel1] - override val schema: Schema = JLevel1.getClassSchema() - override val fromAvro: (JLevel1) => Level1 = { - (j: JLevel1) => Level1(Level2.metadata.fromAvro(j.getLevel2)) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/Level2.scala b/avrohugger-core/src/test/expected/scavro/example/model/Level2.scala deleted file mode 100644 index 08650131..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/Level2.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.{Level2 => JLevel2} - -final case class Level2(name: String) extends AvroSerializeable { - type J = JLevel2 - override def toAvro: JLevel2 = { - new JLevel2(name) - } -} - -object Level2 { - implicit def reader = new AvroReader[Level2] { - override type J = JLevel2 - } - implicit val metadata: AvroMetadata[Level2, JLevel2] = new AvroMetadata[Level2, JLevel2] { - override val avroClass: Class[JLevel2] = classOf[JLevel2] - override val schema: Schema = JLevel2.getClassSchema() - override val fromAvro: (JLevel2) => Level2 = { - (j: JLevel2) => Level2(j.getName.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/Suit.scala b/avrohugger-core/src/test/expected/scavro/example/model/Suit.scala deleted file mode 100644 index 3cb30db4..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/Suit.scala +++ /dev/null @@ -1,7 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.model - -object Suit extends Enumeration { - type Suit = Value - val SPADES, DIAMONDS, CLUBS, HEARTS = Value -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/model/User.scala b/avrohugger-core/src/test/expected/scavro/example/model/User.scala deleted file mode 100644 index fda00887..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/model/User.scala +++ /dev/null @@ -1,40 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.{User => JUser} - -final case class User(name: String, favorite_number: Option[Int], favorite_color: Option[String]) extends AvroSerializeable { - type J = JUser - override def toAvro: JUser = { - new JUser(name, favorite_number match { - case Some(x) => x - case None => null - }, favorite_color match { - case Some(x) => x - case None => null - }) - } -} - -object User { - implicit def reader = new AvroReader[User] { - override type J = JUser - } - implicit val metadata: AvroMetadata[User, JUser] = new AvroMetadata[User, JUser] { - override val avroClass: Class[JUser] = classOf[JUser] - override val schema: Schema = JUser.getClassSchema() - override val fromAvro: (JUser) => User = { - (j: JUser) => User(j.getName.toString, j.getFavoriteNumber match { - case null => None - case _ => Some(j.getFavoriteNumber.toInt) - }, j.getFavoriteColor match { - case null => None - case _ => Some(j.getFavoriteColor.toString) - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/proto/model/BinaryPr.scala b/avrohugger-core/src/test/expected/scavro/example/proto/model/BinaryPr.scala deleted file mode 100644 index 99edcdab..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/proto/model/BinaryPr.scala +++ /dev/null @@ -1,32 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.proto.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.proto.{BinaryPr => JBinaryPr} - -final case class BinaryPr(data: Array[Byte]) extends AvroSerializeable { - type J = JBinaryPr - override def toAvro: JBinaryPr = { - new JBinaryPr(java.nio.ByteBuffer.wrap(data)) - } -} - -object BinaryPr { - implicit def reader = new AvroReader[BinaryPr] { - override type J = JBinaryPr - } - implicit val metadata: AvroMetadata[BinaryPr, JBinaryPr] = new AvroMetadata[BinaryPr, JBinaryPr] { - override val avroClass: Class[JBinaryPr] = classOf[JBinaryPr] - override val schema: Schema = JBinaryPr.getClassSchema() - override val fromAvro: (JBinaryPr) => BinaryPr = { - (j: JBinaryPr) => BinaryPr(j.getData match { - case (buffer: java.nio.ByteBuffer) => { - buffer.array() - } - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/proto/model/EnumProtocol.scala b/avrohugger-core/src/test/expected/scavro/example/proto/model/EnumProtocol.scala deleted file mode 100644 index aa1dafa6..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/proto/model/EnumProtocol.scala +++ /dev/null @@ -1,45 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.proto.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.proto.{Card => JCard, Suit => JSuit} - -sealed trait EnumProtocol - -final object Suit extends Enumeration with EnumProtocol { - type Suit = Value - val SPADES, HEARTS, DIAMONDS, CLUBS = Value -} - -final case class Card(suit: Suit.Value, number: Int) extends AvroSerializeable with EnumProtocol { - type J = JCard - override def toAvro: JCard = { - new JCard(suit match { - case Suit.SPADES => JSuit.SPADES - case Suit.HEARTS => JSuit.HEARTS - case Suit.DIAMONDS => JSuit.DIAMONDS - case Suit.CLUBS => JSuit.CLUBS - }, number) - } -} - -final object Card { - implicit def reader = new AvroReader[Card] { - override type J = JCard - } - implicit val metadata: AvroMetadata[Card, JCard] = new AvroMetadata[Card, JCard] { - override val avroClass: Class[JCard] = classOf[JCard] - override val schema: Schema = JCard.getClassSchema() - override val fromAvro: (JCard) => Card = { - (j: JCard) => Card(j.getSuit match { - case JSuit.SPADES => Suit.SPADES - case JSuit.HEARTS => Suit.HEARTS - case JSuit.DIAMONDS => Suit.DIAMONDS - case JSuit.CLUBS => Suit.CLUBS - }, j.getNumber.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/example/proto/model/Message.scala b/avrohugger-core/src/test/expected/scavro/example/proto/model/Message.scala deleted file mode 100644 index 8b0186f3..00000000 --- a/avrohugger-core/src/test/expected/scavro/example/proto/model/Message.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.proto.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.proto.{Message => JMessage} - -final case class Message(to: String, from: String, body: String) extends AvroSerializeable { - type J = JMessage - override def toAvro: JMessage = { - new JMessage(to, from, body) - } -} - -object Message { - implicit def reader = new AvroReader[Message] { - override type J = JMessage - } - implicit val metadata: AvroMetadata[Message, JMessage] = new AvroMetadata[Message, JMessage] { - override val avroClass: Class[JMessage] = classOf[JMessage] - override val schema: Schema = JMessage.getClassSchema() - override val fromAvro: (JMessage) => Message = { - (j: JMessage) => Message(j.getTo.toString, j.getFrom.toString, j.getBody.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/model/model/UnionRecord.scala b/avrohugger-core/src/test/expected/scavro/model/model/UnionRecord.scala deleted file mode 100644 index 6caefc9b..00000000 --- a/avrohugger-core/src/test/expected/scavro/model/model/UnionRecord.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package model.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import model.{UnionRecord => JUnionRecord} - -final case class UnionRecord(blah: String) extends AvroSerializeable { - type J = JUnionRecord - override def toAvro: JUnionRecord = { - new JUnionRecord(blah) - } -} - -object UnionRecord { - implicit def reader = new AvroReader[UnionRecord] { - override type J = JUnionRecord - } - implicit val metadata: AvroMetadata[UnionRecord, JUnionRecord] = new AvroMetadata[UnionRecord, JUnionRecord] { - override val avroClass: Class[JUnionRecord] = classOf[JUnionRecord] - override val schema: Schema = JUnionRecord.getClassSchema() - override val fromAvro: (JUnionRecord) => UnionRecord = { - (j: JUnionRecord) => UnionRecord(j.getBlah.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/model/v2/model/NestedRecord.scala b/avrohugger-core/src/test/expected/scavro/model/v2/model/NestedRecord.scala deleted file mode 100644 index 04a43ac3..00000000 --- a/avrohugger-core/src/test/expected/scavro/model/v2/model/NestedRecord.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package model.v2.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import model.model.UnionRecord - -import model.{UnionRecord => JUnionRecord} - -import model.v2.{NestedRecord => JNestedRecord} - -final case class NestedRecord(nestedunion: Option[UnionRecord]) extends AvroSerializeable { - type J = JNestedRecord - override def toAvro: JNestedRecord = { - new JNestedRecord(nestedunion match { - case Some(x) => x.toAvro - case None => null - }) - } -} - -object NestedRecord { - implicit def reader = new AvroReader[NestedRecord] { - override type J = JNestedRecord - } - implicit val metadata: AvroMetadata[NestedRecord, JNestedRecord] = new AvroMetadata[NestedRecord, JNestedRecord] { - override val avroClass: Class[JNestedRecord] = classOf[JNestedRecord] - override val schema: Schema = JNestedRecord.getClassSchema() - override val fromAvro: (JNestedRecord) => NestedRecord = { - (j: JNestedRecord) => NestedRecord(j.getNestedunion match { - case null => None - case _ => Some(UnionRecord.metadata.fromAvro(j.getNestedunion)) - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/other/ns/case/ExternalDependency.scala b/avrohugger-core/src/test/expected/scavro/other/ns/case/ExternalDependency.scala deleted file mode 100644 index 7e1aaed3..00000000 --- a/avrohugger-core/src/test/expected/scavro/other/ns/case/ExternalDependency.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package other.ns.case - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import other.ns.{ExternalDependency => JExternalDependency} - -final case class ExternalDependency(number: Int) extends AvroSerializeable { - type J = JExternalDependency - override def toAvro: JExternalDependency = { - new JExternalDependency(number) - } -} - -object ExternalDependency { - implicit def reader = new AvroReader[ExternalDependency] { - override type J = JExternalDependency - } - implicit val metadata: AvroMetadata[ExternalDependency, JExternalDependency] = new AvroMetadata[ExternalDependency, JExternalDependency] { - override val avroClass: Class[JExternalDependency] = classOf[JExternalDependency] - override val schema: Schema = JExternalDependency.getClassSchema() - override val fromAvro: (JExternalDependency) => ExternalDependency = { - (j: JExternalDependency) => ExternalDependency(j.getNumber.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/other/ns/case/Suit.scala b/avrohugger-core/src/test/expected/scavro/other/ns/case/Suit.scala deleted file mode 100644 index abbdba0d..00000000 --- a/avrohugger-core/src/test/expected/scavro/other/ns/case/Suit.scala +++ /dev/null @@ -1,11 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package other.ns.case - -sealed trait Suit - -object Suit { - case object SPADES extends Suit - case object DIAMONDS extends Suit - case object CLUBS extends Suit - case object HEARTS extends Suit -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/other/ns/java/ExternalDependency.scala b/avrohugger-core/src/test/expected/scavro/other/ns/java/ExternalDependency.scala deleted file mode 100644 index 609b8348..00000000 --- a/avrohugger-core/src/test/expected/scavro/other/ns/java/ExternalDependency.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package other.ns.java - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import other.ns.{ExternalDependency => JExternalDependency} - -final case class ExternalDependency(number: Int) extends AvroSerializeable { - type J = JExternalDependency - override def toAvro: JExternalDependency = { - new JExternalDependency(number) - } -} - -object ExternalDependency { - implicit def reader = new AvroReader[ExternalDependency] { - override type J = JExternalDependency - } - implicit val metadata: AvroMetadata[ExternalDependency, JExternalDependency] = new AvroMetadata[ExternalDependency, JExternalDependency] { - override val avroClass: Class[JExternalDependency] = classOf[JExternalDependency] - override val schema: Schema = JExternalDependency.getClassSchema() - override val fromAvro: (JExternalDependency) => ExternalDependency = { - (j: JExternalDependency) => ExternalDependency(j.getNumber.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/other/ns/java/Suit.java b/avrohugger-core/src/test/expected/scavro/other/ns/java/Suit.java deleted file mode 100644 index 85f7f8b6..00000000 --- a/avrohugger-core/src/test/expected/scavro/other/ns/java/Suit.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Autogenerated by Avro - * - * DO NOT EDIT DIRECTLY - */ -package other.ns.java; -@org.apache.avro.specific.AvroGenerated -public enum Suit implements org.apache.avro.generic.GenericEnumSymbol { - SPADES, DIAMONDS, CLUBS, HEARTS ; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"Suit\",\"namespace\":\"other.ns.java\",\"symbols\":[\"SPADES\",\"DIAMONDS\",\"CLUBS\",\"HEARTS\"]}"); - public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } - - @Override - public org.apache.avro.Schema getSchema() { return SCHEMA$; } -} diff --git a/avrohugger-core/src/test/expected/scavro/other/ns/model/ExternalDependency.scala b/avrohugger-core/src/test/expected/scavro/other/ns/model/ExternalDependency.scala deleted file mode 100644 index f6f1c11f..00000000 --- a/avrohugger-core/src/test/expected/scavro/other/ns/model/ExternalDependency.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package other.ns.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import other.ns.{ExternalDependency => JExternalDependency} - -final case class ExternalDependency(number: Int) extends AvroSerializeable { - type J = JExternalDependency - override def toAvro: JExternalDependency = { - new JExternalDependency(number) - } -} - -object ExternalDependency { - implicit def reader = new AvroReader[ExternalDependency] { - override type J = JExternalDependency - } - implicit val metadata: AvroMetadata[ExternalDependency, JExternalDependency] = new AvroMetadata[ExternalDependency, JExternalDependency] { - override val avroClass: Class[JExternalDependency] = classOf[JExternalDependency] - override val schema: Schema = JExternalDependency.getClassSchema() - override val fromAvro: (JExternalDependency) => ExternalDependency = { - (j: JExternalDependency) => ExternalDependency(j.getNumber.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/other/ns/model/Suit.scala b/avrohugger-core/src/test/expected/scavro/other/ns/model/Suit.scala deleted file mode 100644 index ab157aa6..00000000 --- a/avrohugger-core/src/test/expected/scavro/other/ns/model/Suit.scala +++ /dev/null @@ -1,7 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package other.ns.model - -object Suit extends Enumeration { - type Suit = Value - val SPADES, DIAMONDS, CLUBS, HEARTS = Value -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/other/ns/string/ExternalDependency.scala b/avrohugger-core/src/test/expected/scavro/other/ns/string/ExternalDependency.scala deleted file mode 100644 index 9bd6c8ad..00000000 --- a/avrohugger-core/src/test/expected/scavro/other/ns/string/ExternalDependency.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package other.ns.string - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import other.ns.{ExternalDependency => JExternalDependency} - -final case class ExternalDependency(number: Int) extends AvroSerializeable { - type J = JExternalDependency - override def toAvro: JExternalDependency = { - new JExternalDependency(number) - } -} - -object ExternalDependency { - implicit def reader = new AvroReader[ExternalDependency] { - override type J = JExternalDependency - } - implicit val metadata: AvroMetadata[ExternalDependency, JExternalDependency] = new AvroMetadata[ExternalDependency, JExternalDependency] { - override val avroClass: Class[JExternalDependency] = classOf[JExternalDependency] - override val schema: Schema = JExternalDependency.getClassSchema() - override val fromAvro: (JExternalDependency) => ExternalDependency = { - (j: JExternalDependency) => ExternalDependency(j.getNumber.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/test/model/Calculator.scala b/avrohugger-core/src/test/expected/scavro/test/model/Calculator.scala deleted file mode 100644 index c2182c20..00000000 --- a/avrohugger-core/src/test/expected/scavro/test/model/Calculator.scala +++ /dev/null @@ -1,110 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package test.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import test.{Added => JAdded, Divided => JDivided, Multiplied => JMultiplied, Reset => JReset, Subtracted => JSubtracted} - -sealed trait Calculator extends AvroSerializeable with Product with Serializable - -final case class Added(value: Int) extends AvroSerializeable with Calculator { - type J = JAdded - override def toAvro: JAdded = { - new JAdded(value) - } -} - -final object Added { - implicit def reader = new AvroReader[Added] { - override type J = JAdded - } - implicit val metadata: AvroMetadata[Added, JAdded] = new AvroMetadata[Added, JAdded] { - override val avroClass: Class[JAdded] = classOf[JAdded] - override val schema: Schema = JAdded.getClassSchema() - override val fromAvro: (JAdded) => Added = { - (j: JAdded) => Added(j.getValue.toInt) - } - } -} - -final case class Subtracted(value: Int) extends AvroSerializeable with Calculator { - type J = JSubtracted - override def toAvro: JSubtracted = { - new JSubtracted(value) - } -} - -final object Subtracted { - implicit def reader = new AvroReader[Subtracted] { - override type J = JSubtracted - } - implicit val metadata: AvroMetadata[Subtracted, JSubtracted] = new AvroMetadata[Subtracted, JSubtracted] { - override val avroClass: Class[JSubtracted] = classOf[JSubtracted] - override val schema: Schema = JSubtracted.getClassSchema() - override val fromAvro: (JSubtracted) => Subtracted = { - (j: JSubtracted) => Subtracted(j.getValue.toInt) - } - } -} - -final case class Divided(value: Int) extends AvroSerializeable with Calculator { - type J = JDivided - override def toAvro: JDivided = { - new JDivided(value) - } -} - -final object Divided { - implicit def reader = new AvroReader[Divided] { - override type J = JDivided - } - implicit val metadata: AvroMetadata[Divided, JDivided] = new AvroMetadata[Divided, JDivided] { - override val avroClass: Class[JDivided] = classOf[JDivided] - override val schema: Schema = JDivided.getClassSchema() - override val fromAvro: (JDivided) => Divided = { - (j: JDivided) => Divided(j.getValue.toInt) - } - } -} - -final case class Multiplied(value: Int) extends AvroSerializeable with Calculator { - type J = JMultiplied - override def toAvro: JMultiplied = { - new JMultiplied(value) - } -} - -final object Multiplied { - implicit def reader = new AvroReader[Multiplied] { - override type J = JMultiplied - } - implicit val metadata: AvroMetadata[Multiplied, JMultiplied] = new AvroMetadata[Multiplied, JMultiplied] { - override val avroClass: Class[JMultiplied] = classOf[JMultiplied] - override val schema: Schema = JMultiplied.getClassSchema() - override val fromAvro: (JMultiplied) => Multiplied = { - (j: JMultiplied) => Multiplied(j.getValue.toInt) - } - } -} - -final case class Reset() extends AvroSerializeable with Calculator { - type J = JReset - override def toAvro: JReset = { - new JReset - } -} - -final object Reset { - implicit def reader = new AvroReader[Reset] { - override type J = JReset - } - implicit val metadata: AvroMetadata[Reset, JReset] = new AvroMetadata[Reset, JReset] { - override val avroClass: Class[JReset] = classOf[JReset] - override val schema: Schema = JReset.getClassSchema() - override val fromAvro: (JReset) => Reset = { - (j: JReset) => Reset() - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/test/model/ComplexExternalDependency.scala b/avrohugger-core/src/test/expected/scavro/test/model/ComplexExternalDependency.scala deleted file mode 100644 index 0f3a9a8a..00000000 --- a/avrohugger-core/src/test/expected/scavro/test/model/ComplexExternalDependency.scala +++ /dev/null @@ -1,36 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package test.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import model.model.UnionRecord - -import model.v2.model.NestedRecord - -import model.{UnionRecord => JUnionRecord} - -import model.v2.{NestedRecord => JNestedRecord} - -import test.{ComplexExternalDependency => JComplexExternalDependency} - -final case class ComplexExternalDependency(nestedrecord: NestedRecord) extends AvroSerializeable { - type J = JComplexExternalDependency - override def toAvro: JComplexExternalDependency = { - new JComplexExternalDependency(nestedrecord.toAvro) - } -} - -object ComplexExternalDependency { - implicit def reader = new AvroReader[ComplexExternalDependency] { - override type J = JComplexExternalDependency - } - implicit val metadata: AvroMetadata[ComplexExternalDependency, JComplexExternalDependency] = new AvroMetadata[ComplexExternalDependency, JComplexExternalDependency] { - override val avroClass: Class[JComplexExternalDependency] = classOf[JComplexExternalDependency] - override val schema: Schema = JComplexExternalDependency.getClassSchema() - override val fromAvro: (JComplexExternalDependency) => ComplexExternalDependency = { - (j: JComplexExternalDependency) => ComplexExternalDependency(NestedRecord.metadata.fromAvro(j.getNestedrecord)) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/scavro/test/model/Joystick.scala b/avrohugger-core/src/test/expected/scavro/test/model/Joystick.scala deleted file mode 100644 index e29685b0..00000000 --- a/avrohugger-core/src/test/expected/scavro/test/model/Joystick.scala +++ /dev/null @@ -1,48 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package test.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import test.{Down => JDown, Up => JUp} - -final case class Up(value: Int) extends AvroSerializeable { - type J = JUp - override def toAvro: JUp = { - new JUp(value) - } -} - -object Up { - implicit def reader = new AvroReader[Up] { - override type J = JUp - } - implicit val metadata: AvroMetadata[Up, JUp] = new AvroMetadata[Up, JUp] { - override val avroClass: Class[JUp] = classOf[JUp] - override val schema: Schema = JUp.getClassSchema() - override val fromAvro: (JUp) => Up = { - (j: JUp) => Up(j.getValue.toInt) - } - } -} - -final case class Down(value: Int) extends AvroSerializeable { - type J = JDown - override def toAvro: JDown = { - new JDown(value) - } -} - -object Down { - implicit def reader = new AvroReader[Down] { - override type J = JDown - } - implicit val metadata: AvroMetadata[Down, JDown] = new AvroMetadata[Down, JDown] { - override val avroClass: Class[JDown] = classOf[JDown] - override val schema: Schema = JDown.getClassSchema() - override val fromAvro: (JDown) => Down = { - (j: JDown) => Down(j.getValue.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/specific/example/idl/EnumProtocol.scala b/avrohugger-core/src/test/expected/specific/example/idl/EnumProtocol.scala deleted file mode 100644 index 58bccf4a..00000000 --- a/avrohugger-core/src/test/expected/specific/example/idl/EnumProtocol.scala +++ /dev/null @@ -1,45 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.idl.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.idl.{Card => JCard, Suit => JSuit} - -sealed trait EnumProtocol extends AvroSerializeable with Product with Serializable - -final object Suit extends Enumeration with EnumProtocol { - type Suit = Value - val SPADES, DIAMONDS, CLUBS, HEARTS = Value -} - -final case class Card(suit: Suit.Value, number: Int) extends AvroSerializeable with EnumProtocol { - type J = JCard - override def toAvro: JCard = { - new JCard(suit match { - case Suit.SPADES => JSuit.SPADES - case Suit.DIAMONDS => JSuit.DIAMONDS - case Suit.CLUBS => JSuit.CLUBS - case Suit.HEARTS => JSuit.HEARTS - }, number) - } -} - -final object Card { - implicit def reader = new AvroReader[Card] { - override type J = JCard - } - implicit val metadata: AvroMetadata[Card, JCard] = new AvroMetadata[Card, JCard] { - override val avroClass: Class[JCard] = classOf[JCard] - override val schema: Schema = JCard.getClassSchema() - override val fromAvro: (JCard) => Card = { - (j: JCard) => Card(j.getSuit match { - case JSuit.SPADES => Suit.SPADES - case JSuit.DIAMONDS => Suit.DIAMONDS - case JSuit.CLUBS => Suit.CLUBS - case JSuit.HEARTS => Suit.HEARTS - }, j.getNumber.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/specific/example/proto/EnumProtocol.scala b/avrohugger-core/src/test/expected/specific/example/proto/EnumProtocol.scala deleted file mode 100644 index c05f1326..00000000 --- a/avrohugger-core/src/test/expected/specific/example/proto/EnumProtocol.scala +++ /dev/null @@ -1,45 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.proto.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.proto.{Card => JCard, Suit => JSuit} - -sealed trait EnumProtocol extends AvroSerializeable with Product with Serializable - -final object Suit extends Enumeration with EnumProtocol { - type Suit = Value - val SPADES, HEARTS, DIAMONDS, CLUBS = Value -} - -final case class Card(suit: Suit.Value, number: Int) extends AvroSerializeable with EnumProtocol { - type J = JCard - override def toAvro: JCard = { - new JCard(suit match { - case Suit.SPADES => JSuit.SPADES - case Suit.HEARTS => JSuit.HEARTS - case Suit.DIAMONDS => JSuit.DIAMONDS - case Suit.CLUBS => JSuit.CLUBS - }, number) - } -} - -final object Card { - implicit def reader = new AvroReader[Card] { - override type J = JCard - } - implicit val metadata: AvroMetadata[Card, JCard] = new AvroMetadata[Card, JCard] { - override val avroClass: Class[JCard] = classOf[JCard] - override val schema: Schema = JCard.getClassSchema() - override val fromAvro: (JCard) => Card = { - (j: JCard) => Card(j.getSuit match { - case JSuit.SPADES => Suit.SPADES - case JSuit.HEARTS => Suit.HEARTS - case JSuit.DIAMONDS => Suit.DIAMONDS - case JSuit.CLUBS => Suit.CLUBS - }, j.getNumber.toInt) - } - } -} \ No newline at end of file diff --git a/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaArray.scala b/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaArray.scala new file mode 100644 index 00000000..c20f545c --- /dev/null +++ b/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaArray.scala @@ -0,0 +1,40 @@ +/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ +package example.idl.array + +import scala.annotation.switch + +final case class ArrayIdl(var data: Array[Int]) extends org.apache.avro.specific.SpecificRecordBase { + def this() = this(Array.empty) + def get(field$: Int): AnyRef = { + (field$: @switch) match { + case 0 => { + scala.jdk.CollectionConverters.BufferHasAsJava({ + data map { x => + x + } + }.toBuffer).asJava + }.asInstanceOf[AnyRef] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + } + def put(field$: Int, value: Any): Unit = { + (field$: @switch) match { + case 0 => this.data = { + value match { + case (array: java.util.List[?]) => { + scala.jdk.CollectionConverters.IteratorHasAsScala(array.iterator).asScala.map({ x => + x + }).toArray(scala.reflect.ClassTag(classOf[Int])).asInstanceOf[Array[Int]] + } + } + }.asInstanceOf[Array[Int]] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + () + } + def getSchema: org.apache.avro.Schema = example.idl.array.ArrayIdl.SCHEMA$ +} + +object ArrayIdl { + val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ArrayIdl\",\"namespace\":\"example.idl.array\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"array\",\"items\":\"int\"}}]}") +} diff --git a/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaList.scala b/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaList.scala new file mode 100644 index 00000000..d260ae34 --- /dev/null +++ b/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaList.scala @@ -0,0 +1,40 @@ +/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ +package example.idl.array + +import scala.annotation.switch + +final case class ArrayIdl(var data: List[Int]) extends org.apache.avro.specific.SpecificRecordBase { + def this() = this(List.empty) + def get(field$: Int): AnyRef = { + (field$: @switch) match { + case 0 => { + scala.jdk.CollectionConverters.BufferHasAsJava({ + data map { x => + x + } + }.toBuffer).asJava + }.asInstanceOf[AnyRef] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + } + def put(field$: Int, value: Any): Unit = { + (field$: @switch) match { + case 0 => this.data = { + value match { + case (array: java.util.List[?]) => { + scala.jdk.CollectionConverters.IteratorHasAsScala(array.iterator).asScala.map({ x => + x + }).toList + } + } + }.asInstanceOf[List[Int]] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + () + } + def getSchema: org.apache.avro.Schema = example.idl.array.ArrayIdl.SCHEMA$ +} + +object ArrayIdl { + val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ArrayIdl\",\"namespace\":\"example.idl.array\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"array\",\"items\":\"int\"}}]}") +} diff --git a/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaSeq.scala b/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaSeq.scala new file mode 100644 index 00000000..c83fcaa9 --- /dev/null +++ b/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaSeq.scala @@ -0,0 +1,40 @@ +/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ +package example.idl.array + +import scala.annotation.switch + +final case class ArrayIdl(var data: Seq[Int]) extends org.apache.avro.specific.SpecificRecordBase { + def this() = this(Seq.empty) + def get(field$: Int): AnyRef = { + (field$: @switch) match { + case 0 => { + scala.jdk.CollectionConverters.BufferHasAsJava({ + data map { x => + x + } + }.toBuffer).asJava + }.asInstanceOf[AnyRef] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + } + def put(field$: Int, value: Any): Unit = { + (field$: @switch) match { + case 0 => this.data = { + value match { + case (array: java.util.List[?]) => { + scala.jdk.CollectionConverters.IteratorHasAsScala(array.iterator).asScala.map({ x => + x + }).toSeq + } + } + }.asInstanceOf[Seq[Int]] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + () + } + def getSchema: org.apache.avro.Schema = example.idl.array.ArrayIdl.SCHEMA$ +} + +object ArrayIdl { + val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ArrayIdl\",\"namespace\":\"example.idl.array\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"array\",\"items\":\"int\"}}]}") +} diff --git a/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaVector.scala b/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaVector.scala new file mode 100644 index 00000000..ed80b791 --- /dev/null +++ b/avrohugger-core/src/test/expected/specificrecord/example/idl/array/scala-3.3/ArrayAsScalaVector.scala @@ -0,0 +1,40 @@ +/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ +package example.idl.array + +import scala.annotation.switch + +final case class ArrayIdl(var data: Vector[Int]) extends org.apache.avro.specific.SpecificRecordBase { + def this() = this(Vector.empty) + def get(field$: Int): AnyRef = { + (field$: @switch) match { + case 0 => { + scala.jdk.CollectionConverters.BufferHasAsJava({ + data map { x => + x + } + }.toBuffer).asJava + }.asInstanceOf[AnyRef] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + } + def put(field$: Int, value: Any): Unit = { + (field$: @switch) match { + case 0 => this.data = { + value match { + case (array: java.util.List[?]) => { + scala.jdk.CollectionConverters.IteratorHasAsScala(array.iterator).asScala.map({ x => + x + }).toVector + } + } + }.asInstanceOf[Vector[Int]] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + () + } + def getSchema: org.apache.avro.Schema = example.idl.array.ArrayIdl.SCHEMA$ +} + +object ArrayIdl { + val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"ArrayIdl\",\"namespace\":\"example.idl.array\",\"fields\":[{\"name\":\"data\",\"type\":{\"type\":\"array\",\"items\":\"int\"}}]}") +} diff --git a/avrohugger-core/src/test/scala/specific/SpecificCustomEnumSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificCustomEnumSpec.scala index 9962509d..bbb6ad9c 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificCustomEnumSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificCustomEnumSpec.scala @@ -18,7 +18,7 @@ class SpecificCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( SpecificRecord, - Some(SpecificRecord.defaultTypes.copy(enum = JavaEnum, protocol = ScalaADT)), + Some(SpecificRecord.defaultTypes.copy(`enum` = JavaEnum, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.java"), ("other.ns" -> "other.ns.java"))) @@ -42,7 +42,7 @@ class SpecificCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( SpecificRecord, - Some(SpecificRecord.defaultTypes.copy(enum = JavaEnum, protocol = ScalaADT)), + Some(SpecificRecord.defaultTypes.copy(`enum` = JavaEnum, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.java"), ("other.ns" -> "other.ns.java"))) @@ -74,7 +74,7 @@ class SpecificCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( SpecificRecord, - Some(SpecificRecord.defaultTypes.copy(enum = EnumAsScalaString, protocol = ScalaADT)), + Some(SpecificRecord.defaultTypes.copy(`enum` = EnumAsScalaString, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.string"), ("other.ns" -> "other.ns.string"))) @@ -94,7 +94,7 @@ class SpecificCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( SpecificRecord, - Some(SpecificRecord.defaultTypes.copy(enum = EnumAsScalaString, protocol = ScalaADT)), + Some(SpecificRecord.defaultTypes.copy(`enum` = EnumAsScalaString, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.string"), ("other.ns" -> "other.ns.string"))) diff --git a/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala index eccda949..f3f4d237 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala @@ -300,7 +300,7 @@ class SpecificFileToFileSpec extends Specification { } } - def e20: Result = Result.forall(Seq(OptionalShapelessCoproduct, OptionShapelessCoproduct, OptionEitherShapelessCoproduct)) { unionType: AvroScalaUnionType => + def e20: Result = Result.forall(Seq(OptionalShapelessCoproduct, OptionShapelessCoproduct, OptionEitherShapelessCoproduct))( unionType => { val inOrderSchema = new java.io.File("avrohugger-core/src/test/avro/unions_with_coproduct2.avsc") val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(AvroScalaTypes.defaults.copy(union = unionType))) val outDir = gen.defaultOutputDir + s"/specific/$unionType" @@ -313,13 +313,13 @@ class SpecificFileToFileSpec extends Specification { "UnionOfNullWithTwoNonNullTypes", "UnionOfMoreThanTwoNonNullTypes", "UnionOfNullWithMoreThanTwoNonNullTypes" - )) { className => + )) ( className => { val generatedFile = s"target/generated-sources/specific/$unionType/com/example/avrohugger/unions_with_coproduct_avsc2/$className.scala" val expectationFile = s"avrohugger-core/src/test/expected/specific/$unionType/com/example/avrohugger/unions_with_coproduct_avsc2/$className.scala" generatedFile must containExpectedContentIn(expectationFile) - } - } + }) + }) def e21 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestProtocol.avdl") diff --git a/avrohugger-core/src/test/scala/specific/SpecificFileToStringsSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificFileToStringsSpec.scala index 7e9f060c..e403e9f4 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificFileToStringsSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificFileToStringsSpec.scala @@ -170,7 +170,7 @@ class SpecificFileToStringsSpec extends Specification { def e14 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator(SpecificRecord) - val List(dep3, dep2, dep1, enum, adt) = gen.fileToStrings(infile) + val List(dep3, dep2, dep1, enm, adt) = gen.fileToStrings(infile) val expectedADT = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/ImportProtocol.scala") val expectedDep1 = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Defaults.scala") @@ -180,7 +180,7 @@ class SpecificFileToStringsSpec extends Specification { adt === expectedADT dep1 === expectedDep1 - enum === expectedEnum + enm === expectedEnum dep2 === expectedDep2 dep3 === expectedDep3 } diff --git a/avrohugger-core/src/test/scala/specific/SpecificStringToFileSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificStringToFileSpec.scala index 3b68a732..997f63d5 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificStringToFileSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificStringToFileSpec.scala @@ -272,22 +272,23 @@ class SpecificStringToFileSpec extends Specification { val schemaString = schema.toString() val gen = Generator(format = SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" - val outDirF = new File(outDir, "massive") + val outDirF: File = new File(outDir, "massive") outDirF.mkdirs() outDirF.list().foreach(new File(outDirF, _).delete()) gen.stringToFile(schemaString, outDir) - val sources = outDirF.list().map(f => new File(outDirF, f)).map { f => - f -> { - val src = Source.fromFile(f) - try { - src.mkString("") - } finally { - src.close() + val sources: Map[File, String] = + outDirF.list().toList.map(f => new File(outDirF, f)).map { f => + f -> { + val src = Source.fromFile(f) + try { + src.mkString("") + } finally { + src.close() + } } - } - }.toMap + }.toMap - sources.collect { case (f, source) if source.contains("mkString") => f } must not beEmpty + sources.collect { case (f, source) if source.contains("mkString") => f } must not(beEmpty) } } diff --git a/avrohugger-core/src/test/scala/standard/StandardCustomEnumSpec.scala b/avrohugger-core/src/test/scala/standard/StandardCustomEnumSpec.scala index d2616fc3..5b08f9ad 100644 --- a/avrohugger-core/src/test/scala/standard/StandardCustomEnumSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardCustomEnumSpec.scala @@ -21,7 +21,7 @@ class StandardCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( Standard, - Some(Standard.defaultTypes.copy(enum = JavaEnum, protocol = ScalaADT)), + Some(Standard.defaultTypes.copy(`enum` = JavaEnum, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.java"), ("other.ns" -> "other.ns.java"))) @@ -45,7 +45,7 @@ class StandardCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( Standard, - Some(Standard.defaultTypes.copy(enum = JavaEnum, protocol = ScalaADT)), + Some(Standard.defaultTypes.copy(`enum` = JavaEnum, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.java"), ("other.ns" -> "other.ns.java"))) @@ -75,7 +75,7 @@ class StandardCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( Standard, - Some(Standard.defaultTypes.copy(enum = ScalaCaseObjectEnum, protocol = ScalaADT)), + Some(Standard.defaultTypes.copy(`enum` = ScalaCaseObjectEnum, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.case"), ("other.ns" -> "other.ns.case"))) @@ -97,7 +97,7 @@ class StandardCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( Standard, - Some(Standard.defaultTypes.copy(enum = ScalaCaseObjectEnum, protocol = ScalaADT)), + Some(Standard.defaultTypes.copy(`enum` = ScalaCaseObjectEnum, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.case"), ("other.ns" -> "other.ns.case"))) @@ -125,7 +125,7 @@ class StandardCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( Standard, - Some(Standard.defaultTypes.copy(enum = EnumAsScalaString, protocol = ScalaADT)), + Some(Standard.defaultTypes.copy(`enum` = EnumAsScalaString, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.string"), ("other.ns" -> "other.ns.string"))) @@ -145,7 +145,7 @@ class StandardCustomEnumSpec extends Specification { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") val gen = new Generator( Standard, - Some(Standard.defaultTypes.copy(enum = EnumAsScalaString, protocol = ScalaADT)), + Some(Standard.defaultTypes.copy(`enum` = EnumAsScalaString, protocol = ScalaADT)), Map( ("example.idl" -> "example.idl.string"), ("other.ns" -> "other.ns.string"))) diff --git a/avrohugger-core/src/test/scala/util/AvrohuggerSpec.scala b/avrohugger-core/src/test/scala/util/AvrohuggerSpec.scala index e4852e26..52f60850 100644 --- a/avrohugger-core/src/test/scala/util/AvrohuggerSpec.scala +++ b/avrohugger-core/src/test/scala/util/AvrohuggerSpec.scala @@ -24,7 +24,6 @@ class AvrohuggerSpec( val sourceFormatName = sourceFormat match { case SpecificRecord => "specific" case Standard => "standard" - case Scavro => "scavro" } val gen = new Generator(sourceFormat) @@ -43,17 +42,8 @@ class AvrohuggerSpec( val expectedBase = FileSystems.getDefault.getPath("avrohugger-core", "src", "test", "expected", sourceFormatName) val generatedBase = FileSystems.getDefault.getPath("target", "generated-sources", sourceFormatName) - private def prefixedFileString(prefixPath: Path, p: Path) = { - val fullPath = sourceFormat match { - case Scavro => { - Option(p.getParent) match { - case Some(parent) => parent ++ "model" ++ p.getFileName - case None => FileSystems.getDefault.getPath("model") ++ p - } - } - case _ => p - } - readFile((prefixPath ++ fullPath).toFile) + private def prefixedFileString(prefixPath: Path, path: Path) = { + readFile((prefixPath ++ path).toFile) } def generatedString(p: Path) = prefixedFileString(generatedBase, p) diff --git a/avrohugger-tools/src/main/scala/tool/GeneratorTool.scala b/avrohugger-tools/src/main/scala/tool/GeneratorTool.scala index bfff6d47..99efd89a 100644 --- a/avrohugger-tools/src/main/scala/tool/GeneratorTool.scala +++ b/avrohugger-tools/src/main/scala/tool/GeneratorTool.scala @@ -44,44 +44,45 @@ class GeneratorTool(sourceFormat: SourceFormat, .println(" outputdir - directory to write generated scala"); System.err.println(" -string - use java.lang.String instead of Utf8"); 1; - } + } else { - var stringType: StringType = StringType.CharSequence; + var stringType: StringType = StringType.CharSequence; - var arg = 0; - if ("-string".equals(args.get(arg))) { - stringType = StringType.String; - arg+=1; - } + var arg = 0; + if ("-string".equals(args.get(arg))) { + stringType = StringType.String; + arg+=1; + } - val method: String = args.get(arg); - var inputs: List[File] = new ArrayList[File](); + val method: String = args.get(arg); + var inputs: List[File] = new ArrayList[File](); - for (i <- (arg + 1) until (args.size() - 1)) { - Try { - inputs.add(new File(args.get(i))); + for (i <- (arg + 1) until (args.size() - 1)) { + Try { + inputs.add(new File(args.get(i))); + } } - } - if ("datafile".equals(method)) { - for (src: File <- determineInputs(inputs, DATAFILE_FILTER)) { - generator.fileToFile(src, args.asScala.last) + if ("datafile".equals(method)) { + for (src: File <- determineInputs(inputs, DATAFILE_FILTER)) { + generator.fileToFile(src, args.asScala.last) + } + } else if ("schema".equals(method)) { + for (src: File <- AvscFileSorter.sortSchemaFiles(determineInputs(inputs, SCHEMA_FILTER))) { + generator.fileToFile(src, args.asScala.last) + } } - } else if ("schema".equals(method)) { - for (src: File <- AvscFileSorter.sortSchemaFiles(determineInputs(inputs, SCHEMA_FILTER))) { - generator.fileToFile(src, args.asScala.last) + else if ("protocol".equals(method)) { + for (src: File <- determineInputs(inputs, PROTOCOL_FILTER)) { + generator.fileToFile(src, args.asScala.last) + } } - } - else if ("protocol".equals(method)) { - for (src: File <- determineInputs(inputs, PROTOCOL_FILTER)) { - generator.fileToFile(src, args.asScala.last) + else { + sys.error("Expected \"datafile\", \"schema\" or \"protocol\"."); + 1; } + 0; } - else { - sys.error("Expected \"datafile\", \"schema\" or \"protocol\"."); - 1; - } - 0; } @Override diff --git a/avrohugger-tools/src/main/scala/tool/Runner.scala b/avrohugger-tools/src/main/scala/tool/Runner.scala index af54dff8..d0dba647 100644 --- a/avrohugger-tools/src/main/scala/tool/Runner.scala +++ b/avrohugger-tools/src/main/scala/tool/Runner.scala @@ -2,7 +2,7 @@ package avrohugger package tool import format.abstractions.SourceFormat -import format.{Scavro, SpecificRecord, Standard} +import format.{SpecificRecord, Standard} import java.util.Arrays import java.util.Map import java.util.TreeMap @@ -23,7 +23,7 @@ class Runner(in: InputStream, out: PrintStream, err: PrintStream) { * Available tools, initialized in constructor. */ val toolsMap: Map[String, Tool] = new TreeMap[String, Tool](); - val formats = Array[SourceFormat](Standard, SpecificRecord, Scavro) + val formats = Array[SourceFormat](Standard, SpecificRecord) val tools = formats.map(format => new GeneratorTool(format)) for (tool <- tools.toArray[Tool]) { var prev: Tool = toolsMap.put(tool.getName(), tool); diff --git a/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Mascot.scala b/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Mascot.scala deleted file mode 100644 index e3eeeef4..00000000 --- a/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Mascot.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package avro.examples.baseball.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import avro.examples.baseball.{Mascot => JMascot} - -final case class Mascot(name: String) extends AvroSerializeable { - type J = JMascot - override def toAvro: JMascot = { - new JMascot(name) - } -} - -object Mascot { - implicit def reader = new AvroReader[Mascot] { - override type J = JMascot - } - implicit val metadata: AvroMetadata[Mascot, JMascot] = new AvroMetadata[Mascot, JMascot] { - override val avroClass: Class[JMascot] = classOf[JMascot] - override val schema: Schema = JMascot.getClassSchema() - override val fromAvro: (JMascot) => Mascot = { - (j: JMascot) => Mascot(j.getName.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Nickname.scala b/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Nickname.scala deleted file mode 100644 index 25f50d39..00000000 --- a/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Nickname.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package avro.examples.baseball.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import avro.examples.baseball.{Nickname => JNickname} - -final case class Nickname(name: String) extends AvroSerializeable { - type J = JNickname - override def toAvro: JNickname = { - new JNickname(name) - } -} - -object Nickname { - implicit def reader = new AvroReader[Nickname] { - override type J = JNickname - } - implicit val metadata: AvroMetadata[Nickname, JNickname] = new AvroMetadata[Nickname, JNickname] { - override val avroClass: Class[JNickname] = classOf[JNickname] - override val schema: Schema = JNickname.getClassSchema() - override val fromAvro: (JNickname) => Nickname = { - (j: JNickname) => Nickname(j.getName.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Player.scala b/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Player.scala deleted file mode 100644 index d31f14c1..00000000 --- a/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Player.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package avro.examples.baseball.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import avro.examples.baseball.{Nickname => JNickname, Player => JPlayer} - -import scala.jdk.CollectionConverters._ - -final case class Player(number: Int, first_name: String, last_name: String, nicknames: Array[Nickname]) extends AvroSerializeable { - type J = JPlayer - override def toAvro: JPlayer = { - new JPlayer(number, first_name, last_name, { - val array: java.util.List[JNickname] = new java.util.ArrayList[JNickname] - nicknames foreach { element => - array.add(element.toAvro) - } - array - }) - } -} - -object Player { - implicit def reader = new AvroReader[Player] { - override type J = JPlayer - } - implicit val metadata: AvroMetadata[Player, JPlayer] = new AvroMetadata[Player, JPlayer] { - override val avroClass: Class[JPlayer] = classOf[JPlayer] - override val schema: Schema = JPlayer.getClassSchema() - override val fromAvro: (JPlayer) => Player = { - (j: JPlayer) => Player(j.getNumber.toInt, j.getFirstName.toString, j.getLastName.toString, Array((j.getNicknames.asScala: _*)) map { x => - Nickname.metadata.fromAvro(x) - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Wrestler.scala b/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Wrestler.scala deleted file mode 100644 index 6917b81f..00000000 --- a/avrohugger-tools/src/test/compiler/output-scavro/avro/examples/baseball/Wrestler.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package avro.examples.baseball.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import avro.examples.baseball.{Mascot => JMascot, Wrestler => JWrestler} - -import scala.jdk.CollectionConverters._ - -final case class Wrestler(number: Int, first_name: String, last_name: String, nicknames: Array[Mascot]) extends AvroSerializeable { - type J = JWrestler - override def toAvro: JWrestler = { - new JWrestler(number, first_name, last_name, { - val array: java.util.List[JMascot] = new java.util.ArrayList[JMascot] - nicknames foreach { element => - array.add(element.toAvro) - } - array - }) - } -} - -object Wrestler { - implicit def reader = new AvroReader[Wrestler] { - override type J = JWrestler - } - implicit val metadata: AvroMetadata[Wrestler, JWrestler] = new AvroMetadata[Wrestler, JWrestler] { - override val avroClass: Class[JWrestler] = classOf[JWrestler] - override val schema: Schema = JWrestler.getClassSchema() - override val fromAvro: (JWrestler) => Wrestler = { - (j: JWrestler) => Wrestler(j.getNumber.toInt, j.getFirstName.toString, j.getLastName.toString, Array((j.getNicknames.asScala: _*)) map { x => - Mascot.metadata.fromAvro(x) - }) - } - } -} \ No newline at end of file diff --git a/avrohugger-tools/src/test/compiler/output-scavro/com/miguno/avro/twitter_schema.scala b/avrohugger-tools/src/test/compiler/output-scavro/com/miguno/avro/twitter_schema.scala deleted file mode 100644 index 7bbaf28f..00000000 --- a/avrohugger-tools/src/test/compiler/output-scavro/com/miguno/avro/twitter_schema.scala +++ /dev/null @@ -1,33 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package com.miguno.avro.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import com.miguno.avro.{twitter_schema => Jtwitter_schema} - -/** - * @param username Name of the user account on Twitter.com - * @param tweet The content of the user's Twitter message - * @param timestamp Unix epoch time in milliseconds - */ -final case class twitter_schema(username: String, tweet: String, timestamp: Long) extends AvroSerializeable { - type J = Jtwitter_schema - override def toAvro: Jtwitter_schema = { - new Jtwitter_schema(username, tweet, timestamp) - } -} - -object twitter_schema { - implicit def reader = new AvroReader[twitter_schema] { - override type J = Jtwitter_schema - } - implicit val metadata: AvroMetadata[twitter_schema, Jtwitter_schema] = new AvroMetadata[twitter_schema, Jtwitter_schema] { - override val avroClass: Class[Jtwitter_schema] = classOf[Jtwitter_schema] - override val schema: Schema = Jtwitter_schema.getClassSchema() - override val fromAvro: (Jtwitter_schema) => twitter_schema = { - (j: Jtwitter_schema) => twitter_schema(j.getUsername.toString, j.getTweet.toString, j.getTimestamp.toLong) - } - } -} \ No newline at end of file diff --git a/avrohugger-tools/src/test/compiler/output-scavro/example/proto/model/Message.scala b/avrohugger-tools/src/test/compiler/output-scavro/example/proto/model/Message.scala deleted file mode 100644 index 8b0186f3..00000000 --- a/avrohugger-tools/src/test/compiler/output-scavro/example/proto/model/Message.scala +++ /dev/null @@ -1,28 +0,0 @@ -/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ -package example.proto.model - -import org.apache.avro.Schema - -import org.oedura.scavro.{AvroMetadata, AvroReader, AvroSerializeable} - -import example.proto.{Message => JMessage} - -final case class Message(to: String, from: String, body: String) extends AvroSerializeable { - type J = JMessage - override def toAvro: JMessage = { - new JMessage(to, from, body) - } -} - -object Message { - implicit def reader = new AvroReader[Message] { - override type J = JMessage - } - implicit val metadata: AvroMetadata[Message, JMessage] = new AvroMetadata[Message, JMessage] { - override val avroClass: Class[JMessage] = classOf[JMessage] - override val schema: Schema = JMessage.getClassSchema() - override val fromAvro: (JMessage) => Message = { - (j: JMessage) => Message(j.getTo.toString, j.getFrom.toString, j.getBody.toString) - } - } -} \ No newline at end of file diff --git a/avrohugger-tools/src/test/compiler/output-specific/avro/examples/baseball/Player_3.scala b/avrohugger-tools/src/test/compiler/output-specific/avro/examples/baseball/Player_3.scala new file mode 100644 index 00000000..d671c8c4 --- /dev/null +++ b/avrohugger-tools/src/test/compiler/output-specific/avro/examples/baseball/Player_3.scala @@ -0,0 +1,58 @@ +/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ +package avro.examples.baseball + +import scala.annotation.switch + +final case class Player(var number: Int, var first_name: String, var last_name: String, var nicknames: Seq[avro.examples.baseball.Nickname]) extends org.apache.avro.specific.SpecificRecordBase { + def this() = this(0, "", "", Seq.empty) + def get(field$: Int): AnyRef = { + (field$: @switch) match { + case 0 => { + number + }.asInstanceOf[AnyRef] + case 1 => { + first_name + }.asInstanceOf[AnyRef] + case 2 => { + last_name + }.asInstanceOf[AnyRef] + case 3 => { + scala.jdk.CollectionConverters.BufferHasAsJava({ + nicknames map { x => + x + } + }.toBuffer).asJava + }.asInstanceOf[AnyRef] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + } + def put(field$: Int, value: Any): Unit = { + (field$: @switch) match { + case 0 => this.number = { + value + }.asInstanceOf[Int] + case 1 => this.first_name = { + value.toString + }.asInstanceOf[String] + case 2 => this.last_name = { + value.toString + }.asInstanceOf[String] + case 3 => this.nicknames = { + value match { + case (array: java.util.List[?]) => { + scala.jdk.CollectionConverters.IteratorHasAsScala(array.iterator).asScala.map({ x => + x + }).toSeq + } + } + }.asInstanceOf[Seq[avro.examples.baseball.Nickname]] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + () + } + def getSchema: org.apache.avro.Schema = avro.examples.baseball.Player.SCHEMA$ +} + +object Player { + val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Player\",\"namespace\":\"avro.examples.baseball\",\"fields\":[{\"name\":\"number\",\"type\":\"int\"},{\"name\":\"first_name\",\"type\":\"string\"},{\"name\":\"last_name\",\"type\":\"string\"},{\"name\":\"nicknames\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Nickname\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}}}]}") +} \ No newline at end of file diff --git a/avrohugger-tools/src/test/compiler/output-specific/avro/examples/baseball/Wrestler_3.scala b/avrohugger-tools/src/test/compiler/output-specific/avro/examples/baseball/Wrestler_3.scala new file mode 100644 index 00000000..c3c6309d --- /dev/null +++ b/avrohugger-tools/src/test/compiler/output-specific/avro/examples/baseball/Wrestler_3.scala @@ -0,0 +1,58 @@ +/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ +package avro.examples.baseball + +import scala.annotation.switch + +final case class Wrestler(var number: Int, var first_name: String, var last_name: String, var nicknames: Seq[avro.examples.baseball.Mascot]) extends org.apache.avro.specific.SpecificRecordBase { + def this() = this(0, "", "", Seq.empty) + def get(field$: Int): AnyRef = { + (field$: @switch) match { + case 0 => { + number + }.asInstanceOf[AnyRef] + case 1 => { + first_name + }.asInstanceOf[AnyRef] + case 2 => { + last_name + }.asInstanceOf[AnyRef] + case 3 => { + scala.jdk.CollectionConverters.BufferHasAsJava({ + nicknames map { x => + x + } + }.toBuffer).asJava + }.asInstanceOf[AnyRef] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + } + def put(field$: Int, value: Any): Unit = { + (field$: @switch) match { + case 0 => this.number = { + value + }.asInstanceOf[Int] + case 1 => this.first_name = { + value.toString + }.asInstanceOf[String] + case 2 => this.last_name = { + value.toString + }.asInstanceOf[String] + case 3 => this.nicknames = { + value match { + case (array: java.util.List[?]) => { + scala.jdk.CollectionConverters.IteratorHasAsScala(array.iterator).asScala.map({ x => + x + }).toSeq + } + } + }.asInstanceOf[Seq[avro.examples.baseball.Mascot]] + case _ => new org.apache.avro.AvroRuntimeException("Bad index") + } + () + } + def getSchema: org.apache.avro.Schema = avro.examples.baseball.Wrestler.SCHEMA$ +} + +object Wrestler { + val SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Wrestler\",\"namespace\":\"avro.examples.baseball\",\"fields\":[{\"name\":\"number\",\"type\":\"int\"},{\"name\":\"first_name\",\"type\":\"string\"},{\"name\":\"last_name\",\"type\":\"string\"},{\"name\":\"nicknames\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Mascot\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}}}]}") +} \ No newline at end of file diff --git a/avrohugger-tools/src/test/scala/Directory.scala b/avrohugger-tools/src/test/scala/Directory.scala index 7766052c..b93bd2b0 100644 --- a/avrohugger-tools/src/test/scala/Directory.scala +++ b/avrohugger-tools/src/test/scala/Directory.scala @@ -49,9 +49,11 @@ object Directory { val TEST_EXPECTED_SPECIFIC_PLAYER = TEST_EXPECTED_SPECIFIC_OUTPUT_BASE_DIR + "avro/examples/baseball/Player.scala" val TEST_EXPECTED_SPECIFIC_PLAYER_213 = TEST_EXPECTED_SPECIFIC_OUTPUT_BASE_DIR + "avro/examples/baseball/Player_2.13.scala" + val TEST_EXPECTED_SPECIFIC_PLAYER_3 = TEST_EXPECTED_SPECIFIC_OUTPUT_BASE_DIR + "avro/examples/baseball/Player_3.scala" val TEST_EXPECTED_SPECIFIC_WRESTLER = TEST_EXPECTED_SPECIFIC_OUTPUT_BASE_DIR + "avro/examples/baseball/Wrestler.scala" val TEST_EXPECTED_SPECIFIC_WRESTLER_213 = TEST_EXPECTED_SPECIFIC_OUTPUT_BASE_DIR + "avro/examples/baseball/Wrestler_2.13.scala" + val TEST_EXPECTED_SPECIFIC_WRESTLER_3 = TEST_EXPECTED_SPECIFIC_OUTPUT_BASE_DIR + "avro/examples/baseball/Wrestler_3.scala" val TEST_EXPECTED_SPECIFIC_TWITTER = TEST_EXPECTED_SPECIFIC_OUTPUT_BASE_DIR + "com/miguno/avro/twitter_schema.scala" val TEST_EXPECTED_SPECIFIC_MESSAGE = @@ -59,22 +61,6 @@ object Directory { val TEST_EXPECTED_SPECIFIC_MAIL = TEST_EXPECTED_SPECIFIC_OUTPUT_BASE_DIR + "example/proto/Mail.scala" - val TEST_EXPECTED_SCAVRO_OUTPUT_BASE_DIR = - TEST_DIR + "output-scavro/" - val TEST_EXPECTED_SCAVRO_NICKNAME = - TEST_EXPECTED_SCAVRO_OUTPUT_BASE_DIR + "avro/examples/baseball/Nickname.scala" - val TEST_EXPECTED_SCAVRO_MASCOT = - TEST_EXPECTED_SCAVRO_OUTPUT_BASE_DIR + "avro/examples/baseball/Mascot.scala" - val TEST_EXPECTED_SCAVRO_PLAYER = - TEST_EXPECTED_SCAVRO_OUTPUT_BASE_DIR + "avro/examples/baseball/Player.scala" - val TEST_EXPECTED_SCAVRO_WRESTLER = - TEST_EXPECTED_SCAVRO_OUTPUT_BASE_DIR + "avro/examples/baseball/Wrestler.scala" - val TEST_EXPECTED_SCAVRO_TWITTER = - TEST_EXPECTED_SCAVRO_OUTPUT_BASE_DIR + "com/miguno/avro/twitter_schema.scala" - val TEST_EXPECTED_SCAVRO_MESSAGE = - TEST_EXPECTED_SCAVRO_OUTPUT_BASE_DIR + "example/proto/model/Message.scala" - - // where test output goes val TEST_OUTPUT_BASE_DIR = "avrohugger-tools/target/compiler/output/" @@ -118,18 +104,4 @@ object Directory { val TEST_OUTPUT_SPECIFIC_MAIL = TEST_OUTPUT_SPECIFIC_BASE_DIR + "example/proto/Mail.scala" - val TEST_OUTPUT_SCAVRO_BASE_DIR = "avrohugger-tools/target/compiler/output-scavro/" - val TEST_OUTPUT_SCAVRO_PLAYER = - TEST_OUTPUT_SCAVRO_BASE_DIR + "avro/examples/baseball/model/Player.scala" - val TEST_OUTPUT_SCAVRO_NICKNAME = - TEST_OUTPUT_SCAVRO_BASE_DIR + "avro/examples/baseball/model/Nickname.scala" - val TEST_OUTPUT_SCAVRO_WRESTLER = - TEST_OUTPUT_SCAVRO_BASE_DIR + "avro/examples/baseball/model/Wrestler.scala" - val TEST_OUTPUT_SCAVRO_MASCOT = - TEST_OUTPUT_SCAVRO_BASE_DIR + "avro/examples/baseball/model/Mascot.scala" - val TEST_OUTPUT_SCAVRO_TWITTER = - TEST_OUTPUT_SCAVRO_BASE_DIR + "com/miguno/avro/model/twitter_schema.scala" - val TEST_OUTPUT_SCAVRO_MESSAGE = - TEST_OUTPUT_SCAVRO_BASE_DIR + "example/proto/model/Message.scala" - } diff --git a/avrohugger-tools/src/test/scala/ScavroGeneratorToolSpec.scala b/avrohugger-tools/src/test/scala/ScavroGeneratorToolSpec.scala deleted file mode 100644 index 23a8b672..00000000 --- a/avrohugger-tools/src/test/scala/ScavroGeneratorToolSpec.scala +++ /dev/null @@ -1,70 +0,0 @@ - -import avrohugger.format.Scavro -import avrohugger.tool.{Main, Directory, GeneratorTool} -import org.apache.avro.tool.Tool - -import org.specs2._ -import scala.jdk.CollectionConverters._ -import scala.util.Try - -/** - * Verifies that the GeneratorTool generates Scala source properly - */ -class ScavroGeneratorToolSpec extends mutable.Specification { - - - // Runs the actual generator tool with the given input args - private def doCompile(args: Array[String]) = { - val tool = new GeneratorTool(Scavro) - Try{ - tool.run(null, null, null, args.toIndexedSeq.asJava) - } - } - - "match the expected single protocol file" in { - doCompile(Array[String] ("protocol", - Directory.TEST_INPUT_DIR + "/mail.avpr", - Directory.TEST_OUTPUT_SCAVRO_BASE_DIR - )) - Util.readFile(Directory.TEST_OUTPUT_SCAVRO_MESSAGE) === Util.readFile(Directory.TEST_EXPECTED_SCAVRO_MESSAGE) - } - - "match the expected single datafile file" in { - doCompile(Array[String] ("datafile", - Directory.TEST_INPUT_DIR + "/twitter.avro", - Directory.TEST_OUTPUT_SCAVRO_BASE_DIR - )) - // Util.readFile(Directory.TEST_OUTPUT_SCAVRO_TWITTER) === Util.readFile(Directory.TEST_EXPECTED_SCAVRO_TWITTER) - skipped - } - - "match the expected single schema file" in { - doCompile(Array[String] ("schema", - Directory.TEST_INPUT_DIR + "/nickname.avsc", - Directory.TEST_OUTPUT_SCAVRO_BASE_DIR - )) - // Util.readFile(Directory.TEST_OUTPUT_SCAVRO_NICKNAME) === Util.readFile(Directory.TEST_EXPECTED_SCAVRO_NICKNAME) - skipped - } - - "match the expected dependent files" in { - doCompile(Array[String]("schema", - Directory.TEST_INPUT_DIR + "/nickname.avsc", - Directory.TEST_INPUT_DIR + "/player.avsc", - Directory.TEST_OUTPUT_SCAVRO_BASE_DIR - )) - // Util.readFile(Directory.TEST_OUTPUT_SCAVRO_PLAYER) === Util.readFile(Directory.TEST_EXPECTED_SCAVRO_PLAYER) - skipped - } - - "match the expected file and directory" in { - doCompile(Array[String]("schema", - Directory.TEST_INPUT_DIR + "/mascot.avsc", - Directory.TEST_INPUT_DIR, - Directory.TEST_OUTPUT_SCAVRO_BASE_DIR - )) - // Util.readFile(Directory.TEST_OUTPUT_SCAVRO_WRESTLER) === Util.readFile(Directory.TEST_EXPECTED_SCAVRO_WRESTLER) - skipped - } - -} \ No newline at end of file diff --git a/avrohugger-tools/src/test/scala/SpecificGeneratorToolSpec.scala b/avrohugger-tools/src/test/scala/SpecificGeneratorToolSpec.scala index ff535919..9a9770e2 100644 --- a/avrohugger-tools/src/test/scala/SpecificGeneratorToolSpec.scala +++ b/avrohugger-tools/src/test/scala/SpecificGeneratorToolSpec.scala @@ -54,10 +54,9 @@ class SpecificGeneratorToolSpec extends mutable.Specification { )) val testPlayerFile = - if (avrohugger.internal.ScalaVersion.version == "2.13") - Directory.TEST_EXPECTED_SPECIFIC_PLAYER_213 - else - Directory.TEST_EXPECTED_SPECIFIC_PLAYER + if (avrohugger.internal.ScalaVersion.version == "2.13") Directory.TEST_EXPECTED_SPECIFIC_PLAYER_213 + else if (avrohugger.internal.ScalaVersion.version == "3.3") Directory.TEST_EXPECTED_SPECIFIC_PLAYER_3 + else Directory.TEST_EXPECTED_SPECIFIC_PLAYER Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_NICKNAME) === Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_NICKNAME) Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_PLAYER) === Util.readFile(testPlayerFile) @@ -70,11 +69,11 @@ class SpecificGeneratorToolSpec extends mutable.Specification { Directory.TEST_OUTPUT_SPECIFIC_BASE_DIR )) - val testWrestlerFile = - if (avrohugger.internal.ScalaVersion.version == "2.13") - Directory.TEST_EXPECTED_SPECIFIC_WRESTLER_213 - else - Directory.TEST_EXPECTED_SPECIFIC_WRESTLER + def testWrestlerFile: String = { + if (avrohugger.internal.ScalaVersion.version == "2.13") Directory.TEST_EXPECTED_SPECIFIC_WRESTLER_213 + else if (avrohugger.internal.ScalaVersion.version == "3.3") Directory.TEST_EXPECTED_SPECIFIC_WRESTLER_3 + else Directory.TEST_EXPECTED_SPECIFIC_WRESTLER + } Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_MASCOT) === Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_MASCOT) Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_WRESTLER) === Util.readFile(testWrestlerFile) diff --git a/avrohugger-tools/src/test/scala/StandardGeneratorToolSpec.scala b/avrohugger-tools/src/test/scala/StandardGeneratorToolSpec.scala index 31fac551..e76cf1be 100644 --- a/avrohugger-tools/src/test/scala/StandardGeneratorToolSpec.scala +++ b/avrohugger-tools/src/test/scala/StandardGeneratorToolSpec.scala @@ -18,7 +18,7 @@ class StandardGeneratorToolSpec extends mutable.Specification { private def doCompile(args: List[String]) = { val tool = new GeneratorTool(Standard) Try{ - tool.run(null, null, null, Seq(args:_*).asJava) + tool.run(null, null, null, args.asJava) } } diff --git a/build.sbt b/build.sbt index ca2b6aef..1ecf5b3a 100644 --- a/build.sbt +++ b/build.sbt @@ -2,12 +2,12 @@ lazy val avroVersion = "1.11.3" lazy val commonSettings = Seq( organization := "com.julianpeeters", - version := "1.7.0", + version := "2.8.0", ThisBuild / versionScheme := Some("semver-spec"), scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature"), Test / scalacOptions ++= Seq("-Yrangepos"), - scalaVersion := "2.13.12", - crossScalaVersions := Seq("2.12.18", scalaVersion.value), + scalaVersion := "3.3.1", + crossScalaVersions := Seq("2.12.18", "2.13.12", scalaVersion.value), libraryDependencies += "org.apache.avro" % "avro" % avroVersion, libraryDependencies += "org.apache.avro" % "avro-compiler" % avroVersion, libraryDependencies := { CrossVersion.partialVersion(scalaVersion.value) match { @@ -24,8 +24,6 @@ lazy val commonSettings = Seq( case _ => libraryDependencies.value }}, - libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value, - libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value, // for testing libraryDependencies += "org.specs2" %% "specs2-core" % "4.20.2" % "test", publishMavenStyle := true, @@ -62,7 +60,7 @@ lazy val avrohugger = (project in file(".")) lazy val `avrohugger-core` = (project in file("avrohugger-core")) .settings( commonSettings, - libraryDependencies += "com.eed3si9n" %% "treehugger" % "0.4.4", + libraryDependencies += ("com.eed3si9n" %% "treehugger" % "0.4.4").cross(CrossVersion.for3Use2_13), Compile / sourceGenerators += addScalaVersionFile.taskValue ) diff --git a/project/build.properties b/project/build.properties index 27430827..e8a1e246 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.6 +sbt.version=1.9.7