• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2# Copyright (c) 2022-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
22compress_jar=$7
23io_jar=$8
24fastjson2_jar=$9
25fastjson2ext_jar=${10}
26final_path=$(pwd)
27
28jar_dir="jar"
29pack_jar_file="app_packing_tool.jar"
30fastjson_jar_file="fastjson-2.0.52.jar"
31fastjson2_jar_file="fastjson2-2.0.52.jar"
32fastjson2ext_jar_file="fastjson2-extension-2.0.52.jar"
33compress_jar_file="commons-compress-1.26.1.jar"
34io_jar_file="commons-io-2.15.1.jar"
35jar_directory="${root_path}/jar"
36pack_jar_path="${root_path}/${jar_dir}/${pack_jar_file}"
37manifest_path="${root_path}/META-INF/packing_tool/MANIFEST.MF"
38
39out_dir="${root_path}/out/${toolchain}/packTool"
40if [ -d "${out_dir}/ohos" ]
41    then
42        echo "${out_dir}/ohos exist"
43    else
44        mkdir -p "${out_dir}/ohos"
45fi
46
47compile_command="javac -source 1.8 -target 1.8 \
48-cp ${fastjson_jar}:${compress_jar}:${io_jar}:${fastjson2_jar}:${fastjson2ext_jar} -d ${out_dir} ${compile_java}"
49eval ${compile_command}
50
51temp_dir="$root_path/jar/packing_temp_${toolchain}"
52if [ -d "${temp_dir}" ]
53    then
54        echo "${temp_dir} exit"
55    else
56        mkdir ${temp_dir}
57fi
58
59cd ${out_dir}
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/commons-compress
64cp ${fastjson_jar} "${temp_dir}/${fastjson_jar_file}"
65cp ${fastjson2_jar} "${temp_dir}/${fastjson2_jar_file}"
66cp ${fastjson2ext_jar} "${temp_dir}/${fastjson2ext_jar_file}"
67cp ${compress_jar} "${temp_dir}/${compress_jar_file}"
68cp ${io_jar} "${temp_dir}/${io_jar_file}"
69detach_pack_jar_command="jar -xvf ${pack_jar_file}"
70detach_fastjson_jar_command="jar -xvf ${fastjson_jar_file}"
71detach_fastjson2_jar_command="jar -xvf ${fastjson2_jar_file}"
72detach_fastjson2ext_jar_command="jar -xvf ${fastjson2ext_jar_file}"
73detach_io_jar_command="jar -xvf ${io_jar_file}"
74detach_compress_jar_command="jar -xvf ${compress_jar_file}"
75cd ${temp_dir}
76eval ${detach_pack_jar_command}
77eval ${detach_fastjson2ext_jar_command}
78eval ${detach_fastjson2_jar_command}
79eval ${detach_fastjson_jar_command}
80eval ${detach_io_jar_command}
81eval ${detach_compress_jar_command}
82cp "$root_path/jar/NOTICE" "META-INF/NOTICE.txt"
83rm ${pack_jar_file}
84rm ${fastjson_jar_file}
85rm ${fastjson2_jar_file}
86rm ${fastjson2ext_jar_file}
87rm ${compress_jar_file}
88rm ${io_jar_file}
89
90cd ${jar_directory}
91temp_pack_jar_dir="${root_path}/jar/packtool_${toolchain}"
92temp_pack_jar_path="${root_path}/jar/packtool_${toolchain}/${pack_jar_file}"
93merge_pack_fast_jar_command="jar -cvfm ${temp_pack_jar_path} ${manifest_path} -C ${temp_dir} ."
94if [ -d "${temp_pack_jar_dir}" ]
95    then
96        echo "${temp_pack_jar_dir} exist"
97    else
98        mkdir -p ${temp_pack_jar_dir}
99fi
100eval ${merge_pack_fast_jar_command}
101
102# make out dir
103final_pack_out_path="${final_path}/${pack_build_out_path}"
104final_pack_jar_path="${final_path}/${pack_build_out_jar_path}"
105if [ -d "$final_pack_out_path" ]
106    then
107        echo "${final_pack_out_path} exist"
108    else
109        mkdir -p ${final_pack_out_path}
110fi
111copy_command="cp ${temp_pack_jar_path} ${final_pack_jar_path}"
112eval ${copy_command}
113if [ -f "${pack_jar_file}"]
114    then
115        echo "${pack_jar_file} exist"
116    else
117        cp ${temp_pack_jar_path} ${pack_jar_file}
118fi
119rm -rf ${temp_pack_jar_dir}
120rm -rf ${temp_dir}
121rm -rf ${out_dir}
122