From 9eb11bc6f886f5195b0f6406de692a9e8d01a065 Mon Sep 17 00:00:00 2001 From: Matheus Albino Brunhara Date: Tue, 16 Apr 2024 09:50:26 -0300 Subject: [PATCH] Add --no-substitution parameter to personal-devboot/scripts/shell/job/gp/team-pipeline-local.sh script --- scripts/shell/job/gp/team-pipeline-local.sh | 310 ++++++++++---------- 1 file changed, 162 insertions(+), 148 deletions(-) diff --git a/scripts/shell/job/gp/team-pipeline-local.sh b/scripts/shell/job/gp/team-pipeline-local.sh index 4edc160..d373172 100755 --- a/scripts/shell/job/gp/team-pipeline-local.sh +++ b/scripts/shell/job/gp/team-pipeline-local.sh @@ -1,5 +1,7 @@ #!/bin/bash +# TODO, fazer o script explodir artefatos usando artifactId recuperado pela busca recursiva do arquivo pom.xml + printf "\n" show_help() { @@ -12,8 +14,9 @@ show_help() { echo " --deployments-path | -d (Required) Specify the Wildfly ports-XX/deployments path" echo " --file-paths | -f (Optional) Specify file paths to consider in the update, separation by comma (,)" echo " Specifying this will make the \"--commit-hashes\" parameter optional" - echo " --no-build | -b (Optional) If selected, the script will NOT build the maven components in order to generate the target/ folder" + echo " --no-build | --nb (Optional) If selected, the script will NOT build the maven components in order to generate the target/ folder" echo " --use-git-status | -g (Optional) Will add the files with differences from the \"git status\" command" + echo " --no-substitution | --ns (Optional) If selected, the script will NOT build the maven components in order to generate the target/ folder" echo " --start-server | -s (Optional) Will run the server after the script finishes copying the files" } @@ -24,19 +27,21 @@ deployments_path='' file_paths_arg='' build_maven=true use_git_status=false +should_substitute=true should_start_server=false while [ "$#" -gt 0 ]; do case "$1" in - --help|-h) show_help; exit ;; - --repo-dir|-r) repo_dir="$2"; shift 2;; - --commit-hashes|-c) commit_hashes_arg="$2"; shift 2;; - --commits-between|-cb) commits_between_arg="$2"; shift 2;; - --deployments-path|-d) deployments_path="$2"; shift 2;; - --file-paths|-f) file_paths_arg="$2"; shift 2;; - --no-build|-b) build_maven=false; shift 2;; - --use-git-status|-g) use_git_status=true; shift 2;; - --start-server|-s) should_start_server=true; shift 2;; + --help|-h) show_help; exit ;; + --repo-dir|-r) repo_dir="$2"; shift 2;; + --commit-hashes|-c) commit_hashes_arg="$2"; shift 2;; + --commits-between|-cb) commits_between_arg="$2"; shift 2;; + --deployments-path|-d) deployments_path="$2"; shift 2;; + --file-paths|-f) file_paths_arg="$2"; shift 2;; + --no-build|--nb) build_maven=false; shift 2;; + --use-git-status|-g) use_git_status=true; shift 2;; + --no-substitution|--ns) should_substitute=false; shift 2;; + --start-server|-s) should_start_server=true; shift 2;; *) shift ;; esac done @@ -93,6 +98,7 @@ arr_uniq() { } build_mvn() { + printf "\n" echo "[INFO] Realizando build Maven no diretório \"`pwd`\"..." mvn --quiet clean install --file ./pom.xml --settings ~/.m2/settings.xml @@ -246,11 +252,14 @@ fi if [ ! -z "$file_paths_arg" ]; then file_paths=`convert_csv_to_array "$file_paths_arg"` - if [ ! -f $f ]; then - continue - fi + for f in ${file_paths[@]}; do + if [ ! -f "$repo_dir/$f" ]; then + echo "[WARN] O arquivo informado \"$f\" não existe no repositório." + continue + fi - target_paths+=("$f") + target_paths+=($f) + done fi if $use_git_status; then @@ -311,167 +320,172 @@ for p in ${sorted_pom_paths_uniq[@]}; do non_root_deployments_files_to_explode=`find * -maxdepth 0 -type f -regextype sed -regex ".*[jew]ar" ! -name '*-client.jar' ! -name '*-sources.jar'` done -cd $deployments_path -root_deployments_files_to_explode=`find * -maxdepth 0 -type f -regextype sed -regex ".*[jew]ar"` +if $should_substitute; then + cd $deployments_path + root_deployments_files_to_explode=`find * -maxdepth 0 -type f -regextype sed -regex ".*[jew]ar"` -if [ ! -z "$root_deployments_files_to_explode" ]; then - $scripts_folder/explode-java-files.sh --files `join_by , ${root_deployments_files_to_explode}` # webdeskmapreport, etc. -fi - -for f in ${non_root_deployments_files_to_explode[@]}; do - f_prefix=`remove_suffix "$f"` - file_path=`find * -maxdepth 1 -type f -name "$f_prefix*.jar"` - - non_root_deployments_files_to_explode_full_path+=("$file_path") -done - -if [ ! -z "$non_root_deployments_files_to_explode_full_path" ]; then - $scripts_folder/explode-java-files.sh --files `join_by , ${non_root_deployments_files_to_explode_full_path}` # **/cpqd-geo-renderer-ejb, etc. -fi - -# extra paths because "cpqd-application-renderer-api-*" was inside another non-sense path -extra_paths_to_explode=(`find * -maxdepth 1 -type f -wholename "**/cpqd-application-admweb-web*.war"`) -extra_paths_to_explode+=(`find * -type f -wholename "**/cpqd-application-admweb-web*.war/**/cpqd-*-api-*.jar"`) - -if [ ! -z "$extra_paths_to_explode" ]; then - $scripts_folder/explode-java-files.sh --files `join_by , ${extra_paths_to_explode}` -fi - -src_path_const='src/main/java/' - -unsuccessful_copies=() - -for f in ${dot_java_files[@]}; do - f_dirname=`dirname $f` - f_basename=`basename $f` - class_filename=`echo ${f_basename%".java"}.class` - - path_in_deployments=`get_substring_after_string "$f_dirname" "$src_path_const"` - class_file_paths_in_deployments=`find $deployments_path -type f -wholename "**/$path_in_deployments/$class_filename"` - - middle_path_subst=`get_substring_before_string "$f_dirname" "$src_path_const"` - class_file_path_in_target=`find $repo_dir -type f -wholename "**/${middle_path_subst}target/classes/$path_in_deployments/$class_filename"` - - if [ -z "$class_file_paths_in_deployments" ]; then - echo "comando: find $deployments_path -type f -wholename \"**/$path_in_deployments/$class_filename\"" - echo "[WARN] O arquivo \"$f_basename\" não foi encontrado em algum diretório do deployments. Talvez ele precise ser copiado manualmente?" - - echo "[ASK] Se for um arquivo novo, você sabe de alguma classe vizinha dele?" - - if confirm; then - # etapas para ver se o script criará um arquivo placeholder para fazer a busca depois - echo "Informe o nome do arquivo (ex.: \"FilterResult.java\" - sem aspas):" - read neighbour_filename - neighbour_class_filename=`echo ${neighbour_filename%".java"}.class` # TODO, fazer virar função - neighbour_class_filename_in_deployments=`find $deployments_path -type f -wholename "**/$path_in_deployments/$neighbour_class_filename"` # pode dar mais de um resultado - - if [ ! -z "$neighbour_class_filename_in_deployments" ]; then - echo "O arquivo vizinho informado existe em deployments." - echo "Caminho(s):" - - for d in ${neighbour_class_filename_in_deployments[@]}; do - echo " $d" - done - - echo "[ASK] Deseja copiar o arquivo original que não foi encontrado no(s) mesmo(s) diretório(s)?" - if confirm; then - for d in ${neighbour_class_filename_in_deployments[@]}; do - touch "`dirname $d`/$class_filename" - done - else - unsuccessful_copies+=($f_basename) - echo "Pulando cópia no mesmo diretório do arquivo vizinho..." - fi - fi - else - unsuccessful_copies+=($f_basename) - echo "Pulando cópia..." - echo "comando: find $repo_dir -type f -wholename \"**/${middle_path_subst}target/classes/$path_in_deployments/$class_filename\"" - fi + if [ ! -z "$root_deployments_files_to_explode" ]; then + $scripts_folder/explode-java-files.sh --files `join_by , ${root_deployments_files_to_explode}` # webdeskmapreport, etc. fi - # for i in ${class_file_paths_in_deployments[@]}; do - # echo "i: $i" - # done + for f in ${non_root_deployments_files_to_explode[@]}; do + f_prefix=`remove_suffix "$f"` + file_path=`find * -maxdepth 1 -type f -name "$f_prefix*.jar"` - # for j in ${class_file_path_in_target[@]}; do - # echo "j: $j" - # done + non_root_deployments_files_to_explode_full_path+=("$file_path") + done - # printf "\n" - # printf "\n" - # printf "\n" + if [ ! -z "$non_root_deployments_files_to_explode_full_path" ]; then + $scripts_folder/explode-java-files.sh --files `join_by , ${non_root_deployments_files_to_explode_full_path}` # **/cpqd-geo-renderer-ejb, etc. + fi - for p in ${class_file_paths_in_deployments[@]}; do - if [ -z "$class_file_path_in_target" ]; then - echo "[WARN] O arquivo \"$f_basename\" não foi encontrado em uma pasta \"target\" fixa (\"$middle_path_subst\") do repositório. Pulando cópia..." + # extra paths because "cpqd-application-renderer-api-*" was inside another non-sense path + extra_paths_to_explode=(`find * -maxdepth 1 -type f -wholename "**/cpqd-application-admweb-web*.war"`) + if [ ! -z "$extra_paths_to_explode" ]; then + $scripts_folder/explode-java-files.sh --files `join_by , ${extra_paths_to_explode}` + fi + + extra_paths_to_explode=(`find * -type f -wholename "**/cpqd-application-admweb-web*.war/**/cpqd-*-api-*.jar"`) + if [ ! -z "$extra_paths_to_explode" ]; then + $scripts_folder/explode-java-files.sh --files `join_by , ${extra_paths_to_explode}` + fi + + src_path_const='src/main/java/' + + unsuccessful_copies=() + + for f in ${dot_java_files[@]}; do + f_dirname=`dirname $f` + f_basename=`basename $f` + class_filename=`echo ${f_basename%".java"}.class` + + path_in_deployments=`get_substring_after_string "$f_dirname" "$src_path_const"` + class_file_paths_in_deployments=`find $deployments_path -type f -wholename "**/$path_in_deployments/$class_filename"` + + middle_path_subst=`get_substring_before_string "$f_dirname" "$src_path_const"` + class_file_path_in_target=`find $repo_dir -type f -wholename "**/${middle_path_subst}target/classes/$path_in_deployments/$class_filename"` + + if [ -z "$class_file_paths_in_deployments" ]; then + echo "comando: find $deployments_path -type f -wholename \"**/$path_in_deployments/$class_filename\"" + echo "[WARN] O arquivo \"$f_basename\" não foi encontrado em algum diretório do deployments. Talvez ele precise ser copiado manualmente?" + + echo "[ASK] Se for um arquivo novo, você sabe de alguma classe vizinha dele?" - echo "[ASK] Deseja tentar fazer uma busca mais abrangente?" if confirm; then - new_class_file_path_in_target=`find $repo_dir -type f -wholename "**/target/classes/**/$class_filename"` - - if [ ! -z "$new_class_file_path_in_target" ]; then - echo "Foi encontrado um caminho válido, mais abrangente, para o arquivo." + # etapas para ver se o script criará um arquivo placeholder para fazer a busca depois + echo "Informe o nome do arquivo (ex.: \"FilterResult.java\" - sem aspas):" + read neighbour_filename + neighbour_class_filename=`echo ${neighbour_filename%".java"}.class` # TODO, fazer virar função + neighbour_class_filename_in_deployments=`find $deployments_path -type f -wholename "**/$path_in_deployments/$neighbour_class_filename"` # pode dar mais de um resultado + + if [ ! -z "$neighbour_class_filename_in_deployments" ]; then + echo "O arquivo vizinho informado existe em deployments." echo "Caminho(s):" - echo " $new_class_file_path_in_target" - echo "[ASK] Deseja usar ele na cópia?" + for d in ${neighbour_class_filename_in_deployments[@]}; do + echo " $d" + done + echo "[ASK] Deseja copiar o arquivo original que não foi encontrado no(s) mesmo(s) diretório(s)?" if confirm; then - # defino como essa variável direto porque as próximas iterações, que serão do mesmo arquivo, usarão o novo caminho - class_file_path_in_target=$new_class_file_path_in_target + for d in ${neighbour_class_filename_in_deployments[@]}; do + touch "`dirname $d`/$class_filename" + done else unsuccessful_copies+=($f_basename) + echo "Pulando cópia no mesmo diretório do arquivo vizinho..." + fi + fi + else + unsuccessful_copies+=($f_basename) + echo "Pulando cópia..." + echo "comando: find $repo_dir -type f -wholename \"**/${middle_path_subst}target/classes/$path_in_deployments/$class_filename\"" + fi + fi + + # for i in ${class_file_paths_in_deployments[@]}; do + # echo "i: $i" + # done + + # for j in ${class_file_path_in_target[@]}; do + # echo "j: $j" + # done + + # printf "\n" + # printf "\n" + # printf "\n" + + for p in ${class_file_paths_in_deployments[@]}; do + if [ -z "$class_file_path_in_target" ]; then + echo "[WARN] O arquivo \"$f_basename\" não foi encontrado em uma pasta \"target\" fixa (\"$middle_path_subst\") do repositório. Pulando cópia..." + + echo "[ASK] Deseja tentar fazer uma busca mais abrangente?" + if confirm; then + new_class_file_path_in_target=`find $repo_dir -type f -wholename "**/target/classes/**/$class_filename"` + + if [ ! -z "$new_class_file_path_in_target" ]; then + echo "Foi encontrado um caminho válido, mais abrangente, para o arquivo." + echo "Caminho(s):" + echo " $new_class_file_path_in_target" + + echo "[ASK] Deseja usar ele na cópia?" + + if confirm; then + # defino como essa variável direto porque as próximas iterações, que serão do mesmo arquivo, usarão o novo caminho + class_file_path_in_target=$new_class_file_path_in_target + else + unsuccessful_copies+=($f_basename) + continue + fi + else + unsuccessful_copies+=($f_basename) + echo "Não foi possível encontrar um caminho válido, mais abrangente, para o arquivo." + echo "Pulando cópia..." continue fi else unsuccessful_copies+=($f_basename) - echo "Não foi possível encontrar um caminho válido, mais abrangente, para o arquivo." - echo "Pulando cópia..." continue fi - else - unsuccessful_copies+=($f_basename) - continue + + # echo "comando: find $repo_dir -type f -wholename \"**/${middle_path_subst}target/classes/$path_in_deployments/$class_filename\"" + # echo "f: $f" + # echo "f_dirname: $f_dirname" + # echo "f_basename: $f_basename" + # echo "class_filename: $class_filename" + # echo "path_in_deployments: ${path_in_deployments}" + # echo "class_file_paths_in_deployments: ${class_file_paths_in_deployments}" fi - # echo "comando: find $repo_dir -type f -wholename \"**/${middle_path_subst}target/classes/$path_in_deployments/$class_filename\"" - # echo "f: $f" - # echo "f_dirname: $f_dirname" - # echo "f_basename: $f_basename" - # echo "class_filename: $class_filename" - # echo "path_in_deployments: ${path_in_deployments}" - # echo "class_file_paths_in_deployments: ${class_file_paths_in_deployments}" - fi + cp_dest=`dirname $p` - cp_dest=`dirname $p` + printf "\n" + echo "[INFO] Copiando arquivo:" + echo " De: $class_file_path_in_target" + echo " Para: $cp_dest" + + cp --force $class_file_path_in_target $cp_dest + + if [ $? -eq 0 ]; then + echo "[INFO] Concluído." + else + echo "[INFO] A cópia dos artefatos resultou em erros." + exit 1 + fi + done + done + + if [ ${#unsuccessful_copies[@]} -ne 0 ]; then + unsuccessful_copies_uniq=$(for i in "${unsuccessful_copies[@]}"; do echo $i; done | sort -u) printf "\n" - echo "[INFO] Copiando arquivo:" - echo " De: $class_file_path_in_target" - echo " Para: $cp_dest" + echo "[WARN] Houveram arquivos que não puderam ser atualizados. Consulte o log do script." - cp --force $class_file_path_in_target $cp_dest - - if [ $? -eq 0 ]; then - echo "[INFO] Concluído." - else - echo "[INFO] A cópia dos artefatos resultou em erros." - exit 1 - fi - done -done - -if [ ${#unsuccessful_copies[@]} -ne 0 ]; then - unsuccessful_copies_uniq=$(for i in "${unsuccessful_copies[@]}"; do echo $i; done | sort -u) - - printf "\n" - echo "[WARN] Houveram arquivos que não puderam ser atualizados. Consulte o log do script." - - for i in ${unsuccessful_copies_uniq[@]}; do - echo " Arquivo mal-sucedido: $i" - done + for i in ${unsuccessful_copies_uniq[@]}; do + echo " Arquivo mal-sucedido: $i" + done + fi fi if $should_start_server; then