1#!/bin/bash
2#
3# Copyright (C) 2022 The Android Open Source Project
4#
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
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16
17set -e
18
19REPO_ROOT="$1"
20
21FILES_TO_CHECK=()
22for i in "${@:2}"; do
23  if [[ $i == *_failures.txt ]]; then
24    FILES_TO_CHECK+=($i)
25  fi
26done
27
28# if no libcore_*_failures.txt files were changed
29if [ ${#FILES_TO_CHECK[@]} -eq 0 ]; then
30  exit 0
31fi
32
33TMP_DIR=`mktemp -d`
34# check if tmp dir was created
35if [[ ! "$TMP_DIR" || ! -d "$TMP_DIR" ]]; then
36  echo "Could not create temp dir"
37  exit 1
38fi
39
40function cleanup {
41  rm -rf "$TMP_DIR"
42}
43
44# register the cleanup function to be called on the EXIT signal
45trap cleanup EXIT
46
47GSON_JAR="${REPO_ROOT}/external/caliper/lib/gson-2.2.2.jar"
48
49javac --class-path "$GSON_JAR" "${REPO_ROOT}/art/tools/PresubmitJsonLinter.java" -d "$TMP_DIR"
50java --class-path "$TMP_DIR:$GSON_JAR" PresubmitJsonLinter "${FILES_TO_CHECK[@]}"
51