1#!/usr/bin/env bash 2# Copyright (c) 2022-2024 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 22compress_jar=$7 23final_path=$(pwd) 24 25jar_dir="jar" 26pack_jar_file="app_packing_tool.jar" 27fastjson_jar_file="fastjson-1.2.83.jar" 28compress_jar_file="commons-compress-1.24.0.jar" 29jar_directory="${root_path}/jar" 30pack_jar_path="${root_path}/${jar_dir}/${pack_jar_file}" 31manifest_path="${root_path}/META-INF/packing_tool/MANIFEST.MF" 32 33out_dir="${root_path}/out/${toolchain}/packing_tool" 34if [ -d "${out_dir}/ohos" ] 35 then 36 echo "${out_dir}/ohos exist" 37 else 38 mkdir -p "${out_dir}/ohos" 39fi 40 41compile_command="javac -source 1.8 -target 1.8 -cp ${fastjson_jar}:${compress_jar} -d ${out_dir} ${compile_java}" 42eval ${compile_command} 43 44temp_dir="$root_path/jar/packing_temp_${toolchain}" 45if [ -d "${temp_dir}" ] 46 then 47 echo "${temp_dir} exit" 48 else 49 mkdir ${temp_dir} 50fi 51 52cd ${out_dir} 53product_pack_jar_command="jar -cvfm ${temp_dir}/${pack_jar_file} ${manifest_path} ./ohos" 54eval ${product_pack_jar_command} 55 56# merge app_packing_tool.jar and fastjson/commons-compress 57cp ${fastjson_jar} "${temp_dir}/${fastjson_jar_file}" 58cp ${compress_jar} "${temp_dir}/${compress_jar_file}" 59detach_pack_jar_command="jar -xvf ${pack_jar_file}" 60detach_fastjson_jar_command="jar -xvf ${fastjson_jar_file}" 61detach_compress_jar_command="jar -xvf ${compress_jar_file}" 62cd ${temp_dir} 63eval ${detach_pack_jar_command} 64eval ${detach_fastjson_jar_command} 65eval ${detach_compress_jar_command} 66cp "$root_path/jar/NOTICE" "META-INF/NOTICE.txt" 67rm ${pack_jar_file} 68rm ${fastjson_jar_file} 69rm ${compress_jar_file} 70 71cd ${jar_directory} 72temp_pack_jar_dir="${root_path}/jar/packtool_${toolchain}" 73temp_pack_jar_path="${root_path}/jar/packtool_${toolchain}/${pack_jar_file}" 74merge_pack_fast_jar_command="jar -cvfm ${temp_pack_jar_path} ${manifest_path} -C ${temp_dir} ." 75if [ -d "${temp_pack_jar_dir}" ] 76 then 77 echo "${temp_pack_jar_dir} exist" 78 else 79 mkdir -p ${temp_pack_jar_dir} 80fi 81eval ${merge_pack_fast_jar_command} 82 83# make out dir 84final_pack_out_path="${final_path}/${pack_build_out_path}" 85final_pack_jar_path="${final_path}/${pack_build_out_jar_path}" 86if [ -d "$final_pack_out_path" ] 87 then 88 echo "${final_pack_out_path} exist" 89 else 90 mkdir -p ${final_pack_out_path} 91fi 92copy_command="cp ${temp_pack_jar_path} ${final_pack_jar_path}" 93eval ${copy_command} 94if [ -f "${pack_jar_file}"] 95 then 96 echo "${pack_jar_file} exist" 97 else 98 cp ${temp_pack_jar_path} ${pack_jar_file} 99fi 100rm -rf ${temp_pack_jar_dir} 101rm -rf ${temp_dir} 102rm -rf ${out_dir} 103