#!/bin/bash cd "$(dirname "$0")" function prepareFile(){ path="$1" tmp_path="$(basename "$path")" ( sed -n '/CODE AUTOMATICALLY GENERATED BY genQueryMapper.sh/q;p' "$path" echo -e '\t// DO NOT EDIT BELOW THIS LINE, OR CHANGE THIS COMMENT, CODE AUTOMATICALLY GENERATED BY genQueryMapper.sh\n' ) > "$tmp_path" echo "$tmp_path" } function finishFile(){ path="$1" tmp_path="$(basename "$path")" echo -e "}\n" >> "$tmp_path" mv "$tmp_path" "$path" } result="$(prepareFile "src/main/java/com/moparisthebest/jdbc/ResultSetMapper.java")" # single object types cat src/main/java/com/moparisthebest/jdbc/ResultSetMapper.java | grep public | egrep '(toObject|toSingleMap|toResultSetIterable|toStream)\(' | grep ', Calendar cal)' | while read method do #echo "method: $method" method_name=$(echo $method | egrep -o '[^ ]+\(') echo "ResultSetMapper.$method_name)" [ "$method_name" == 'toStream(' ] && echo -e '\t//IFJAVA8_START\n' >> "$result" cat >> "$result" <> "$result" done #everything else cat src/main/java/com/moparisthebest/jdbc/ResultSetMapper.java | grep public | grep '(ResultSet rs' | grep ', int arrayMaxLength, Calendar cal)' | while read method do #echo "method: $method" method_name=$(echo $method | egrep -o '[^ ]+\(') echo "ResultSetMapper.$method_name)" for args in '' ', int arrayMaxLength' ', Calendar cal' do cat >> "$result" </dev/null # QueryMapper.java cat >> "$query" <> "$query" <> "$caching_query" <> "$null_query" [ "$method_name" == 'toStream(' ] && echo -e '\t//IFJAVA8_END\n' | tee -a "$query" "$caching_query" "$null_query" >/dev/null done finishFile "src/main/java/com/moparisthebest/jdbc/QueryMapper.java" finishFile "src/main/java/com/moparisthebest/jdbc/CachingQueryMapper.java" finishFile "src/main/java/com/moparisthebest/jdbc/NullQueryMapper.java"