Skip to content

Commit

Permalink
more avro
Browse files Browse the repository at this point in the history
  • Loading branch information
kjozsa committed Nov 28, 2024
1 parent 0d96aaa commit 8f11d07
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
37 changes: 32 additions & 5 deletions fineract-avro-schemas/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ tasks.register("preprocessAvroSchemas") {
inputs.dir(avroSourceDir)
outputs.dir(avroPreProcessedDir)

doFirst {
println("Preprocessing Avro schemas from $avroSourceDir to $avroPreProcessedDir")
file(avroPreProcessedDir).mkdirs()
}

doLast {
copy {
from(avroSourceDir)
Expand All @@ -54,6 +59,7 @@ tasks.register("preprocessAvroSchemas") {
line.replace("\"bigdecimal\"", file("$projectDir/src/main/resources/avro-templates/bigdecimal.avsc").readText(Charsets.UTF_8))
}
}
println("Preprocessing complete. Files in target directory: ${file(avroPreProcessedDir).list()?.joinToString()}")
}
}

Expand All @@ -64,6 +70,15 @@ tasks.register<com.github.davidmc24.gradle.plugin.avro.GenerateAvroJavaTask>("ge

source(avroPreProcessedDir)
setOutputDir(file(avroGeneratedSourcesDir))

doFirst {
println("Generating Avro Java classes from $avroPreProcessedDir to $avroGeneratedSourcesDir")
file(avroGeneratedSourcesDir).mkdirs()
}

doLast {
println("Generation complete. Generated files: ${file(avroGeneratedSourcesDir).walk().filter { it.isFile }.joinToString()}")
}
}

avro {
Expand Down Expand Up @@ -143,32 +158,44 @@ tasks.withType<JavaCompile>().configureEach {
// Custom task to ensure Avro generation is complete
tasks.register("ensureAvroGenerated") {
dependsOn("generateAvroJava")

doFirst {
println("Verifying Avro generation...")
val outputDir = file("$buildDir/generated-src/avro/main")
println("Output directory exists: ${outputDir.exists()}")
println("Output directory contents: ${outputDir.walk().filter { it.isFile }.joinToString()}")
}

doLast {
val outputDir = file(avroGeneratedSourcesDir)
val outputDir = file("$buildDir/generated-src/avro/main")
if (!outputDir.exists() || outputDir.list()?.isEmpty() != false) {
throw GradleException("Avro sources were not generated properly")
throw GradleException("Avro sources were not generated properly in $outputDir")
}

// Verify specific expected files exist
val expectedFile = file("$avroGeneratedSourcesDir/org/apache/fineract/avro/BulkMessageItemV1.java")
val expectedFile = file("$buildDir/generated-src/avro/main/org/apache/fineract/avro/BulkMessageItemV1.java")
if (!expectedFile.exists()) {
println("Failed to find $expectedFile")
println("Directory contents:")
outputDir.walk().forEach { println(it) }
throw GradleException("Critical Avro file BulkMessageItemV1.java was not generated")
}
println("Avro generation verification complete - all required files present")
}
}

tasks.named("compileJava") {
dependsOn("ensureAvroGenerated")
mustRunAfter("ensureAvroGenerated")
inputs.dir(avroPreProcessedDir)
outputs.dir(avroGeneratedSourcesDir)
outputs.dir(file("$buildDir/generated-src/avro/main"))
outputs.cacheIf { false }
}

tasks.named("jar") {
dependsOn("compileJava")
mustRunAfter("compileJava")
inputs.dir(avroGeneratedSourcesDir)
inputs.dir(file("$buildDir/generated-src/avro/main"))
outputs.cacheIf { false }
}

Expand Down
2 changes: 1 addition & 1 deletion fineract-core/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ gradle.projectsEvaluated {
// Double check that the required Avro class exists
def avroFile = project(':fineract-avro-schemas').file("build/generated-src/avro/main/org/apache/fineract/avro/BulkMessageItemV1.java")
if (!avroFile.exists()) {
throw new GradleException("Required Avro class BulkMessageItemV1.java not found. Build will fail.")
throw new GradleException("Required Avro class BulkMessageItemV1.java not found at ${avroFile.absolutePath}. Build will fail.")
}
}
}
Expand Down

0 comments on commit 8f11d07

Please sign in to comment.