Skip to content

Commit

Permalink
Update how we write the generated file, more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelWilcox committed Sep 1, 2023
1 parent 6e9db8c commit 0d927b2
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSFile
import com.squareup.anvil.compiler.api.AnvilApplicabilityChecker
import com.squareup.anvil.compiler.internal.testing.parseSimpleFileContents
import java.io.OutputStream
import java.io.OutputStreamWriter
import java.nio.charset.StandardCharsets

Expand All @@ -32,21 +33,21 @@ private class SimpleSymbolProcessor(
sources = listOfNotNull(result.originatingFile).toTypedArray()
)
val file = env.codeGenerator.createNewFile(dependencies, packageName, fileName)

// Don't use writeTo(file) because that tries to handle directories under the hood
OutputStreamWriter(file, StandardCharsets.UTF_8)
.buffered()
.use { writer ->
writer.write(result.content)
writer.flush()
env.logger.info("Content written to file")
}
file.appendText(result.content)
env.logger.info("Content written to file")
}
.toList()
val files = resolver.getAllFiles().toList()
env.logger.info("All files : ${files.joinToString { it.fileName }}")

return emptyList()
}
}

fun OutputStream.appendText(str: String) {
this.write(str.toByteArray())
}

internal data class SimpleMapperResult(
val content: String,
val originatingFile: KSFile?,
Expand Down

0 comments on commit 0d927b2

Please sign in to comment.