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