3 # Copyright 2019 Samsung Electronics Co., Ltd.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 PS4='+['$(readlink -f "$0")' ${FUNCNAME[0]%main}#$LINENO] '
20 echo '---> maven-coverity.sh'
22 #-----------------------------------------------------------------------------
23 # Process parameters for JS/PHP/Ruby files analysis
25 FS_CAPTURE_SEARCH_PARAMS=''
26 if [ -n "${SEARCH_PATHS:=}" ]; then
27 for SEARCH_PATH in ${SEARCH_PATHS}; do
28 if [ -d "${SEARCH_PATH}" ]; then
29 FS_CAPTURE_SEARCH_PARAMS="${FS_CAPTURE_SEARCH_PARAMS} --fs-capture-search '${SEARCH_PATH}'"
31 echo "'${SEARCH_PATH}' from \$SEARCH_PATHS is not an existing directory." >&2
37 for EXCLUDE_REGEX in ${SEARCH_EXCLUDE_REGEXS:=}; do
38 FS_CAPTURE_SEARCH_PARAMS="${FS_CAPTURE_SEARCH_PARAMS} --fs-capture-search-exclude-regex '${EXCLUDE_REGEX}'"
41 #-----------------------------------------------------------------------------
42 # Check if we are allowed to submit results to Coverity Scan service
43 # and have not exceeded our upload quota limits
44 # See also: https://scan.coverity.com/faq#frequency
52 --form "project=${COVERITY_PROJECT_NAME}" \
53 --form "token=${COVERITY_TOKEN}" \
54 'https://scan.coverity.com/api/upload_permitted'
57 IS_COVERITY_UPLOAD_PERMITTED=$(
58 echo "${CURL_OUTPUT}" \
59 | jq '.upload_permitted'
61 if [ x"${IS_COVERITY_UPLOAD_PERMITTED}" != x'true' ]; then
62 echo "Upload quota reached. Next upload permitted at "$(echo "${CURL_OUTPUT}" | jq '.next_upload_permitted_at') >&2
66 #-----------------------------------------------------------------------------
67 # Get Coverity Scan build tool
74 --form "project=${COVERITY_PROJECT_NAME}" \
75 --form "token=${COVERITY_TOKEN}" \
76 --output 'coverity_tool.tgz' \
77 'https://scan.coverity.com/download/linux64'
84 --form "project=${COVERITY_PROJECT_NAME}" \
85 --form "token=${COVERITY_TOKEN}" \
87 --output 'coverity_tool.md5' \
88 'https://scan.coverity.com/download/linux64'
90 echo -n ' coverity_tool.tgz' >> 'coverity_tool.md5'
91 md5sum --check 'coverity_tool.md5'
96 --file='coverity_tool.tgz'
98 COVERITY_BUILD_TOOL_DIRECTORY=$(
103 --file='coverity_tool.tgz'
106 COVERITY_BINARY_DIRECTORY="${COVERITY_BUILD_TOOL_DIRECTORY}bin"
107 test -d "${COVERITY_BINARY_DIRECTORY}" \
109 export PATH="${PATH}:${COVERITY_BINARY_DIRECTORY}"
111 rm 'coverity_tool.tgz'
113 #-----------------------------------------------------------------------------
120 ${FS_CAPTURE_SEARCH_PARAMS} \
121 "${MVN}" clean install \
123 --global-settings "${GLOBAL_SETTINGS_FILE}" \
124 --settings "${SETTINGS_FILE}" \
137 '^Translation unit:$' \
139 's!^[[:digit:]]\+ -> !!' \
140 > 'coverity-scan-analysed-files.log'
142 #-----------------------------------------------------------------------------
143 # Submit results to Coverity service
148 --file='results.tgz' \
156 --form "project=${COVERITY_PROJECT_NAME}" \
157 --form "email=${COVERITY_USER_EMAIL}" \
158 --form "token=${COVERITY_TOKEN}" \
159 --form 'file=@results.tgz' \
160 --form "version=${GIT_COMMIT:0:7}" \
161 --form "description=${GIT_BRANCH}" \
162 'https://scan.coverity.com/builds'
164 #-----------------------------------------------------------------------------