From ffbd5b4d4342a4b0e820d232eb3fade43108b33b Mon Sep 17 00:00:00 2001 From: Maciej Cenkar Date: Fri, 3 Mar 2023 14:12:51 +0100 Subject: [PATCH] fix: https://github.com/julianpeeters/sbt-avrohugger/issues/94 Files were generated into not-existing folder, added call to create all missing parent folders. --- .../scala/format/abstractions/SourceFormat.scala | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala b/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala index 06a50f35..699096ec 100644 --- a/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala +++ b/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala @@ -51,7 +51,7 @@ trait SourceFormat { typeMatcher: TypeMatcher, restrictedFields: Boolean, targetScalaPartialVersion: String): List[CompilationUnit] - + def compile( classStore: ClassStore, namespace: Option[String], @@ -61,7 +61,7 @@ trait SourceFormat { typeMatcher: TypeMatcher, restrictedFields: Boolean, targetScalaPartialVersion: String): Unit - + val defaultTypes: AvroScalaTypes def getName( @@ -87,7 +87,7 @@ trait SourceFormat { case ScalaEnumeration => ".scala" case EnumAsScalaString => sys.error("Only RECORD and ENUM can be top-level definitions") } - + schemaOrProtocol match { case Left(schema) => schema.getType match { case RECORD => ".scala" @@ -97,7 +97,7 @@ trait SourceFormat { } case Right(protocol) => ".scala" } - + } def getFilePath( @@ -202,7 +202,7 @@ trait SourceFormat { case _ => sys.error("Only RECORD, ENUM or FIXED can be top-level definitions") } } - + // From: https://github.com/apache/avro/blob/33d495840c896b693b7f37b5ec786ac1acacd3b4/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java#L70 val RESERVED_WORDS: Set[String] = Set("abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "do", "double", @@ -222,7 +222,8 @@ trait SourceFormat { } val contents = compilationUnit.codeString.getBytes() try { // delete old and/or create new - Files.deleteIfExists(path) + Files.deleteIfExists(path) // delete file if exists + Files.createDirectories(path.getParent) // create all parent folders Files.write(path, contents, StandardOpenOption.CREATE) () } @@ -232,4 +233,4 @@ trait SourceFormat { } } -} \ No newline at end of file +}