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 16haptobin_build_jar_path=$2 17out_build_path=$3 18toolchain=$4 19final_path=$(pwd) 20 21temp_path="." 22jar_dir="jar" 23haptobin_jar_file="haptobin_tool.jar" 24haptobin_jar_path="${final_path}/${out_build_path}" 25haptobin_jar_file_path="${final_path}/${haptobin_build_jar_path}" 26fastjson_jar_path="${root_path}/jar/fastjson-1.2.83.jar" 27# make out dir 28if [ -d "${haptobin_jar_path}" ] 29 then 30 echo "${haptobin_jar_path} exist" 31 else 32 mkdir -p ${haptobin_jar_path} 33fi 34final_jar_path="${root_path}/jar/${haptobin_jar_file}" 35manifest_path=${root_path}/META-INF/packingbin_tool/MANIFEST.MF 36 37# compile java class 38out_dir="${root_path}/out/${toolchain}/haptobin" 39if [ -d "${out_dir}/ohos" ] 40 then 41 echo "${out_dir}/ohos exist" 42 else 43 mkdir -p "${out_dir}/ohos" 44fi 45java_suffix=".java" 46class_suffix=".class" 47out_class="${temp_path}/${out_dir}" 48java_collection="" 49declare -a compile_class=( 50 "Log" 51 "PackFormatter" 52 "BinaryTool" 53 "FileUtils" 54 "ConvertHapToBin" 55 "BundleException" 56 "Utility" 57) 58compile_class_length=${#compile_class[@]} 59for ((i=0; i<${compile_class_length};++i)) 60do 61 java_collection="${java_collection} ${root_path}/adapter/ohos/${compile_class[$i]}${java_suffix}" 62done 63 64compile_command="javac -source 1.8 -target 1.8 -cp ${fastjson_jar_path} -d ${out_dir} ${java_collection}" 65eval ${compile_command} 66cd ${out_dir} 67temp_jar_path="${root_path}/jar/haptobin_${toolchain}/${haptobin_jar_file}" 68temp_jar_dir="${root_path}/jar/haptobin_${toolchain}" 69pack_command="jar -cvfm ${temp_jar_path}/ ${manifest_path} ./ohos" 70if [ -d "${temp_jar_dir}" ] 71 then 72 echo "${temp_jar_dir} exist" 73 else 74 mkdir -p "${temp_jar_dir}" 75fi 76eval ${pack_command} 77 78copy_command="cp ${temp_jar_path} ${haptobin_jar_file_path}" 79eval ${copy_command} 80# copy to developtoo/packintool/jar 81if [ -f "${final_jar_path}" ] 82 then 83 echo "${final_jar_path} exist" 84 else 85 eval "cp ${temp_jar_path} ${final_jar_path}" 86fi 87rm -rf ${temp_jar_dir}