@@ -43,14 +43,16 @@ find_schema_class_file() {
4343 # Otherwise we fallback on finding the filename containing the schema code
4444 # to end with Schema or is named InputModel
4545 # We might want to improve this in the future
46- schema_class_file =" $( grep -lr " ^@schema" src | head -n 1 || return 0) "
46+ schema_class_files =" $( grep -lr " ^@schema" src || return 0) "
4747
48- if [[ -z " ${schema_class_file} " ]]; then
49- schema_class_file=" $( find src -name " *Schema.scala" -o -name " InputModel.scala" | head -n 1 || return 0) "
50- fi
51-
52- echo " ${schema_class_file} "
48+ # if [[ -z "${schema_class_file}" ]]; then
49+ # schema_class_file="$(find src -name "*Schema.scala" -o -name "InputModel.scala" | head -n 1 || return 0)"
50+ # fi
5351
52+ for schema_class_file in $( grep -lr " ^@schema" src)
53+ do
54+ echo $schema_class_file
55+ done
5456}
5557
5658find_schema_class () {
@@ -135,27 +137,34 @@ trap clean_temporary_folder EXIT
135137
136138check_binary_exists " sbt"
137139
138- target_schema_file =" schemas/schema.avsc "
140+ target_dir_schema =" schemas"
139141
140142generator_source_folder=" $( mktemp -d) "
141143generator_code_file=" ${generator_source_folder} /SchemaGenerator.scala"
142144
143- [[ ! -f " ${target_schema_file} " ]] || checksum_before=" $( get_md5sum " ${target_schema_file} " ) "
145+ schema_class_files=" $( find_schema_class_file) "
146+ [[ -n " ${schema_class_files} " ]] || error " Could not find any schema class file"
144147
145- schema_class_file=" $( find_schema_class_file) "
146- [[ -n " ${schema_class_file} " ]] || error " Could not find any schema class file"
148+ for schema_class_file in $schema_class_files
149+ do
150+ schema_class=" $( find_schema_class " ${schema_class_file} " ) "
151+ schema_library=" $( find_avro_library " ${schema_class_file} " ) "
147152
148- schema_class=" $( find_schema_class " ${schema_class_file} " ) "
149- schema_library=" $( find_avro_library " ${schema_class_file} " ) "
153+ class_name=" ${schema_class##* .} "
154+ target_schema_file=" $target_dir_schema /$class_name .avsc"
155+
156+ [[ ! -f " ${target_schema_file} " ]] || checksum_before=" $( get_md5sum " ${target_schema_file} " ) "
150157
151- generate_schema_generator_code " ${schema_class} " " ${schema_library} " > " ${generator_code_file} "
152- run_schema_generator_code " ${generator_code_file} " " ${target_schema_file} "
158+ generate_schema_generator_code " ${schema_class} " " ${schema_library} " > " ${generator_code_file} "
159+ run_schema_generator_code " ${generator_code_file} " " ${target_schema_file} "
153160
154- if ! is_git_tracked " ${target_schema_file} " ; then
155- error " Schema file \" ${target_schema_file} \" is not tracked by git. Please commit it."
156- fi
161+ if ! is_git_tracked " ${target_schema_file} " ; then
162+ error " Schema file \" ${target_schema_file} \" is not tracked by git. Please commit it."
163+ fi
157164
158- checksum_after=" $( get_md5sum " ${target_schema_file} " ) "
165+ checksum_after=" $( get_md5sum " ${target_schema_file} " ) "
159166if [[ " ${checksum_after} " != " ${checksum_before:- } " ]]; then
160- error " Schema file \" ${target_schema_file} \" was missing or not consistent with code. Please commit the updated version."
167+ error " Schema files \" ${target_schema_file} \" was missing or not consistent with code. Please commit the updated version."
161168fi
169+
170+ done
0 commit comments