1#!/usr/bin/env bash 2# Copyright (c) 2022 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 -e 15root_path=$1 16pack_build_out_jar_path=$2 17pack_build_out_path=$3 18toolchain=$4 19final_path=$(pwd) 20 21jar_dir="jar" 22pack_jar_file="app_packing_tool.jar" 23fastjson_jar_file="fastjson-1.2.83.jar" 24jar_directory="${root_path}/jar" 25pack_jar_path="${root_path}/${jar_dir}/${pack_jar_file}" 26manifest_path="${root_path}/META-INF/packing_tool/MANIFEST.MF" 27 28out_dir="${root_path}/out/${toolchain}/packing_tool" 29if [ -d "${out_dir}/ohos" ] 30 then 31 echo "${out_dir}/ohos exist" 32 else 33 mkdir -p "${out_dir}/ohos" 34fi 35 36jar_path="${root_path}/jar" 37fastjson_jar_path="${root_path}/jar/fastjson-1.2.83.jar" 38java_suffix=".java" 39java_collection="" 40declare -a compile_class=( 41 "BundleException" 42 "CommandParser" 43 "CompressEntrance" 44 "Compressor" 45 "CompressVerify" 46 "Log" 47 "PackFormatter" 48 "ShowHelp" 49 "Utility" 50 "ModuleJsonUtil" 51 "Version" 52 "FileUtils" 53 "ModuleApiVersion" 54 "VerifyCollection" 55 "DistroFilter" 56 "ApiVersion" 57 "ScreenShape" 58 "ScreenDensity" 59 "ScreenWindow" 60 "CountryCode" 61 "ModuleMetadataInfo" 62 "HapVerify" 63 "HapVerifyInfo" 64 "HQFVerify" 65 "HQFInfo" 66 "DependencyItem" 67 "PreloadItem" 68 ) 69compile_class_length=${#compile_class[@]} 70for ((i=0; i<${compile_class_length};++i)) 71do 72 java_collection="${java_collection} ${root_path}/adapter/ohos/${compile_class[$i]}${java_suffix}" 73done 74compile_command="javac -source 1.8 -target 1.8 -cp ${fastjson_jar_path} -d ${out_dir} ${java_collection}" 75eval ${compile_command} 76 77temp_dir="$root_path/jar/temp_${toolchain}" 78if [ -d "${temp_dir}" ] 79 then 80 echo "${temp_dir} exit" 81 else 82 mkdir ${temp_dir} 83fi 84 85cd ${out_dir} 86product_pack_jar_command="jar -cvfm ${temp_dir}/${pack_jar_file} ${manifest_path} ./ohos" 87eval ${product_pack_jar_command} 88 89# merge app_packing_tool.jar and fastjson 90cp ${fastjson_jar_path} "${temp_dir}/${fastjson_jar_file}" 91detach_pack_jar_command="jar -xvf ${pack_jar_file}" 92detach_fastjson_jar_command="jar -xvf ${fastjson_jar_file}" 93cd ${temp_dir} 94eval ${detach_pack_jar_command} 95eval ${detach_fastjson_jar_command} 96rm ${pack_jar_file} 97rm ${fastjson_jar_file} 98 99cd ${jar_directory} 100temp_pack_jar_dir="${root_path}/jar/packtool_${toolchain}" 101temp_pack_jar_path="${root_path}/jar/packtool_${toolchain}/${pack_jar_file}" 102merge_pack_fast_jar_command="jar -cvfm ${temp_pack_jar_path} ${manifest_path} -C ${temp_dir} ." 103if [ -d "${temp_pack_jar_dir}" ] 104 then 105 echo "${temp_pack_jar_dir} exist" 106 else 107 mkdir -p ${temp_pack_jar_dir} 108fi 109eval ${merge_pack_fast_jar_command} 110 111# make out dir 112final_pack_out_path="${final_path}/${pack_build_out_path}" 113final_pack_jar_path="${final_path}/${pack_build_out_jar_path}" 114if [ -d "$final_pack_out_path" ] 115 then 116 echo "${final_pack_out_path} exist" 117 else 118 mkdir -p ${final_pack_out_path} 119fi 120copy_command="cp ${temp_pack_jar_path} ${final_pack_jar_path}" 121eval ${copy_command} 122if [ -f "${pack_jar_file}"] 123 then 124 echo "${pack_jar_file} exist" 125 else 126 cp ${temp_pack_jar_path} ${pack_jar_file} 127fi 128rm -rf ${temp_pack_jar_dir} 129rm -rf ${temp_dir}