1#!/usr/bin/env bash 2# Copyright (c) 2023-2025 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14set -eux 15set -o pipefail 16root_path=$1 17pack_build_out_jar_path=$2 18pack_build_out_path=$3 19toolchain=$4 20compile_java=$5 21fastjson_jar=$6 22fastjson2_jar=$7 23fastjson2ext_jar=$8 24final_path=$(pwd) 25 26jar_dir="jar" 27pack_jar_file="app_check_tool.jar" 28fastjson_jar_file="fastjson-2.0.52.jar" 29fastjson2_jar_file="fastjson2-2.0.52.jar" 30fastjson2ext_jar_file="fastjson2-extension-2.0.52.jar" 31jar_directory="${root_path}/jar" 32pack_jar_path="${root_path}/${jar_dir}/${pack_jar_file}" 33manifest_path="${root_path}/META-INF/check_tool/MANIFEST.MF" 34css_path="${root_path}/adapter/ohos/scan_template.css" 35html_path="${root_path}/adapter/ohos/scan_template.html" 36 37out_dir="${root_path}/out/${toolchain}/check_tool" 38if [ -d "${out_dir}/ohos" ] 39 then 40 echo "${out_dir}/ohos exist" 41 else 42 mkdir -p "${out_dir}/ohos" 43fi 44 45compile_command="javac -source 1.8 -target 1.8 \ 46-cp ${fastjson_jar}:${fastjson2_jar}:${fastjson2ext_jar} -d ${out_dir} ${compile_java}" 47eval ${compile_command} 48 49temp_dir="$root_path/jar/check_temp_${toolchain}" 50if [ -d "${temp_dir}" ] 51 then 52 echo "${temp_dir} exit" 53 else 54 mkdir ${temp_dir} 55fi 56 57cd ${out_dir} 58cp ${css_path} ./ohos 59cp ${html_path} ./ohos 60product_pack_jar_command="jar -cvfm ${temp_dir}/${pack_jar_file} ${manifest_path} ./ohos" 61eval ${product_pack_jar_command} 62 63# merge app_packing_tool.jar and fastjson 64cp ${fastjson_jar} "${temp_dir}/${fastjson_jar_file}" 65cp ${fastjson2_jar} "${temp_dir}/${fastjson2_jar_file}" 66cp ${fastjson2ext_jar} "${temp_dir}/${fastjson2ext_jar_file}" 67detach_pack_jar_command="jar -xvf ${pack_jar_file}" 68detach_fastjson_jar_command="jar -xvf ${fastjson_jar_file}" 69detach_fastjson2_jar_command="jar -xvf ${fastjson2_jar_file}" 70detach_fastjson2ext_jar_command="jar -xvf ${fastjson2ext_jar_file}" 71cd ${temp_dir} 72eval ${detach_pack_jar_command} 73eval ${detach_fastjson2ext_jar_command} 74eval ${detach_fastjson2_jar_command} 75eval ${detach_fastjson_jar_command} 76rm ${pack_jar_file} 77rm ${fastjson_jar_file} 78rm ${fastjson2_jar_file} 79rm ${fastjson2ext_jar_file} 80 81cd ${jar_directory} 82temp_pack_jar_dir="${root_path}/jar/checktool_${toolchain}" 83temp_pack_jar_path="${root_path}/jar/checktool_${toolchain}/${pack_jar_file}" 84merge_pack_fast_jar_command="jar -cvfm ${temp_pack_jar_path} ${manifest_path} -C ${temp_dir} ." 85if [ -d "${temp_pack_jar_dir}" ] 86 then 87 echo "${temp_pack_jar_dir} exist" 88 else 89 mkdir -p ${temp_pack_jar_dir} 90fi 91eval ${merge_pack_fast_jar_command} 92 93# make out dir 94final_pack_out_path="${final_path}/${pack_build_out_path}" 95final_pack_jar_path="${final_path}/${pack_build_out_jar_path}" 96if [ -d "$final_pack_out_path" ] 97 then 98 echo "${final_pack_out_path} exist" 99 else 100 mkdir -p ${final_pack_out_path} 101fi 102copy_command="cp ${temp_pack_jar_path} ${final_pack_jar_path}" 103eval ${copy_command} 104if [ -f "${pack_jar_file}"] 105 then 106 echo "${pack_jar_file} exist" 107 else 108 cp ${temp_pack_jar_path} ${pack_jar_file} 109fi 110rm -rf ${temp_pack_jar_dir} 111rm -rf ${temp_dir} 112rm -rf ${out_dir} 113