diff --git a/bridge/src/main/java/com/github/sbt/avro/AvroCompilerBridge.java b/bridge/src/main/java/com/github/sbt/avro/AvroCompilerBridge.java index 1d41939..1dc1712 100644 --- a/bridge/src/main/java/com/github/sbt/avro/AvroCompilerBridge.java +++ b/bridge/src/main/java/com/github/sbt/avro/AvroCompilerBridge.java @@ -90,7 +90,7 @@ public void compileIdls(File[] idls, File target) throws Exception { Protocol protocol = parser.CompilationUnit(); SpecificCompiler compiler = new SpecificCompiler(protocol); configureCompiler(compiler); - compiler.compileToDestination(idl, target); + compiler.compileToDestination(null, target); } } @@ -101,15 +101,14 @@ public void compileAvscs(File[] avscs, File target) throws Exception { System.out.println("Compiling Avro schema: " + schema); files.add(schema); } - Map schemas = parser.parseFiles(files); - - for (Map.Entry entry: schemas.entrySet()) { - File file = entry.getKey(); - Schema schema = entry.getValue(); - SpecificCompiler compiler = new SpecificCompiler(schema); - configureCompiler(compiler); - compiler.compileToDestination(file, target); - } + List schemas = parser.parseFiles(files); + + // This is a trick to use a single instance on the SpecificCompiler for all schemas + // only avro 1.12+ SpecificCompiler has a constructor accepting a schema collection + Schema schema = Schema.createUnion(schemas); + SpecificCompiler compiler = new SpecificCompiler(schema); + configureCompiler(compiler); + compiler.compileToDestination(null, target); } @Override diff --git a/bridge/src/main/java/com/github/sbt/avro/AvscFilesParser.java b/bridge/src/main/java/com/github/sbt/avro/AvscFilesParser.java index a4bb548..7670891 100644 --- a/bridge/src/main/java/com/github/sbt/avro/AvscFilesParser.java +++ b/bridge/src/main/java/com/github/sbt/avro/AvscFilesParser.java @@ -31,7 +31,7 @@ public void addTypes(Iterable types) { } } - public Map parseFiles(Collection files) { + public List parseFiles(Collection files) { Set unparsedFiles = new HashSet<>(files); Map parsedFiles = new HashMap<>(); Map parseExceptions = new HashMap<>(); @@ -72,7 +72,7 @@ public Map parseFiles(Collection files) { throw new SchemaGenerationException("Can not parse schema files:\n" + failedFiles); } - return parsedFiles; + return new ArrayList<>(parsedFiles.values()); } private void stashParser(Schema.Parser parser) { diff --git a/bridge/src/test/scala/com/github/sbt/avro/AvscFilesParserSpec.scala b/bridge/src/test/scala/com/github/sbt/avro/AvscFilesParserSpec.scala index ebefc2b..6685660 100644 --- a/bridge/src/test/scala/com/github/sbt/avro/AvscFilesParserSpec.scala +++ b/bridge/src/test/scala/com/github/sbt/avro/AvscFilesParserSpec.scala @@ -33,7 +33,7 @@ class AvscFilesParserSpec extends Specification { val sourceFiles = fullyQualifiedNames ++ simpleNames val schemas = parser.parseFiles(sourceFiles.asJava) - val names = schemas.asScala.values.map(_.getFullName) + val names = schemas.asScala.map(_.getFullName) names must contain( exactly( "com.github.sbt.avro.test.A", @@ -69,7 +69,7 @@ class AvscFilesParserSpec extends Specification { val parent = new File(sourceDir, "test_records.avsc") parser.addTypes(Seq(dependant).asJava) val schemas = parser.parseFiles(Seq(parent).asJava) - val names = schemas.asScala.values.map(_.getFullName) + val names = schemas.asScala.map(_.getFullName) names must contain(exactly("com.github.sbt.avro.TestSpecificRecordParent")) }