diff --git a/scripts/shell/job/gp/explode-java-files.sh b/scripts/shell/job/gp/explode-java-files.sh index c18b9a7..3931dca 100755 --- a/scripts/shell/job/gp/explode-java-files.sh +++ b/scripts/shell/job/gp/explode-java-files.sh @@ -42,6 +42,10 @@ else files=(`find * -maxdepth 0 -type f -regextype sed -regex $regex_search`) fi +if ! $revert; then + echo "[INFO] Exploding files" +fi + for f in ${files[@]}; do if [ ! -f "$f" ]; then continue @@ -60,6 +64,8 @@ for f in ${files[@]}; do # for removal of files after else f=$file_without_old_suffix else + echo " `basename $f`" + mv $f $f.old unzip -qq -d $f $f.old touch $f.dodeploy diff --git a/scripts/shell/job/gp/team-pipeline-local.sh b/scripts/shell/job/gp/team-pipeline-local.sh index d373172..73cc39e 100755 --- a/scripts/shell/job/gp/team-pipeline-local.sh +++ b/scripts/shell/job/gp/team-pipeline-local.sh @@ -1,7 +1,5 @@ #!/bin/bash -# TODO, fazer o script explodir artefatos usando artifactId recuperado pela busca recursiva do arquivo pom.xml - printf "\n" show_help() { @@ -98,8 +96,11 @@ arr_uniq() { } build_mvn() { + build_cur=`pwd` + printf "\n" - echo "[INFO] Realizando build Maven no diretório \"`pwd`\"..." + echo "[INFO] Realizando build Maven:" + echo " ${build_cur#"$repo_dir"}" mvn --quiet clean install --file ./pom.xml --settings ~/.m2/settings.xml @@ -289,10 +290,10 @@ pom_paths_uniq=$(for i in "${pom_paths[@]}"; do echo $i; done | sort -u) sorted_pom_paths_uniq=($(sort_pom_paths_for_compilation_order "${pom_paths_uniq[@]}")) -echo "[INFO] Pom order:" +echo "[INFO] Pom order" for p in ${sorted_pom_paths_uniq[@]}; do - echo "$p" + echo " $p" done for p in ${sorted_pom_paths_uniq[@]}; do @@ -305,8 +306,10 @@ done non_root_deployments_files_to_explode=() non_root_deployments_files_to_explode_full_path=() +artifact_ids_to_explode=() for p in ${sorted_pom_paths_uniq[@]}; do pom_dir=$repo_dir/`dirname $p` + artifact_ids_to_explode+=(`xmlstarlet sel -N pom="http://maven.apache.org/POM/4.0.0" -t -v '/pom:project/pom:artifactId' $pom_dir/pom.xml`) if [ ! -d "$pom_dir/target" ]; then echo "[INFO] Could not find the \"target\" folder in \"$pom_dir\"" @@ -320,6 +323,13 @@ 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 +# adding some artifact IDs because "cpqd-application" might have a sibling called "cpqd-etics" +extra_artifact_ids_to_explode=() +for a in ${artifact_ids_to_explode[@]}; do + extra_artifact_ids_to_explode+=(a) + extra_artifact_ids_to_explode+=("${a/-application-/-etics-}") +done + if $should_substitute; then cd $deployments_path root_deployments_files_to_explode=`find * -maxdepth 0 -type f -regextype sed -regex ".*[jew]ar"` @@ -328,6 +338,28 @@ if $should_substitute; then $scripts_folder/explode-java-files.sh --files `join_by , ${root_deployments_files_to_explode}` # webdeskmapreport, 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"`) + 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 * -maxdepth 1 -type f -wholename "**/cpqd-etics-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 + + extra_paths_to_explode=(`find * -type f -wholename "**/cpqd-etics-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 + 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"` @@ -339,53 +371,88 @@ if $should_substitute; 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"`) - if [ ! -z "$extra_paths_to_explode" ]; then - $scripts_folder/explode-java-files.sh --files `join_by , ${extra_paths_to_explode}` - fi + # exploding files by found artifactIds + for a in ${artifact_ids_to_explode[@]}; do + artifactId_paths_to_explode=(`find * -type f -wholename "**/$a*"`) + if [ ! -z "$artifactId_paths_to_explode" ]; then + $scripts_folder/explode-java-files.sh --files `join_by , ${artifactId_paths_to_explode}` + fi + done - 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 + # TODO, remover + # cd $deployments_path + # $scripts_folder/explode-java-files.sh --revert true + # exit 0 src_path_const='src/main/java/' + # TODO, add known exceptions to automatically search for alternative target paths and deployment paths + # known_exceptions_alternative_target_paths=(CacheGeneratorCleanupStartupBean.java) + # known_exceptions_alternative_deployments_paths=(CacheGeneratorCleanupStartupBean.java) + unsuccessful_copies=() for f in ${dot_java_files[@]}; do f_dirname=`dirname $f` f_basename=`basename $f` + + # TODO, remover + # if [ $f_basename != "CacheGeneratorCleanupStartupBean.java" ]; then continue; fi + 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"` + 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?" + is_done=false + if [ ! -z "$class_file_paths_in_deployments" ]; then + is_done=true + else + # echo "comando: find $deployments_path -type f -wholename \"**/$path_in_deployments/$class_filename\"" + + # procurando de forma mais abrangente + bigger_search=`find $deployments_path -type f -wholename "**/$class_filename"` + if [ ! -z "$bigger_search" ]; then + printf "\n" + echo "[INFO] O arquivo \"$f_basename\" não foi encontrado no diretório esperado em deployments, mas há caminho(s) alternativo(s):" + for f in ${bigger_search[@]}; do + echo " $f" + done + printf "\n" + echo "[ASK] Você deseja copiar para esse(s) caminho(s)?" + if confirm; then + class_file_paths_in_deployments=$bigger_search + is_done=true + fi + fi + fi + + if ! $is_done; then + printf "\n" + 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 + printf "\n" 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=`echo ${neighbour_filename%".java"}.class` 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):" + printf "\n" + echo "O arquivo vizinho informado existe em deployments. Caminho(s):" for d in ${neighbour_class_filename_in_deployments[@]}; do echo " $d" done + printf "\n" 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 @@ -393,30 +460,20 @@ if $should_substitute; then done else unsuccessful_copies+=($f_basename) + printf "\n" echo "Pulando cópia no mesmo diretório do arquivo vizinho..." fi fi else unsuccessful_copies+=($f_basename) + printf "\n" 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 + printf "\n" 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?" @@ -424,10 +481,11 @@ if $should_substitute; 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" + printf "\n" + echo "Foi encontrado um caminho válido, mais abrangente, para o arquivo:" + echo " $new_class_file_path_in_target" + printf "\n" echo "[ASK] Deseja usar ele na cópia?" if confirm; then @@ -439,22 +497,14 @@ if $should_substitute; then 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..." + printf "\n" + echo "Não foi possível encontrar um caminho válido, mais abrangente, para o arquivo. Pulando cópia..." continue fi else unsuccessful_copies+=($f_basename) continue 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 @@ -468,26 +518,29 @@ if $should_substitute; then cp --force $class_file_path_in_target $cp_dest if [ $? -eq 0 ]; then + printf "\n" echo "[INFO] Concluído." else + printf "\n" echo "[INFO] A cópia dos artefatos resultou em erros." exit 1 fi done done - if [ ${#unsuccessful_copies[@]} -ne 0 ]; then + 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." + echo "Arquivo mal-sucedidos: $i" for i in ${unsuccessful_copies_uniq[@]}; do - echo " Arquivo mal-sucedido: $i" + echo " $i" done fi fi if $should_start_server; then - $cur/debugports-01.sh + "$cur/debugports-01.sh" fi