1#!/bin/bash
2set -e
3# Make sure that entries are not added for packages that are already fully handled using
4# annotations.
5LOCAL_DIR="$( dirname ${BASH_SOURCE} )"
6# Each team should add a <team>_PACKAGES and <team>_EMAIL with the list of packages and
7# the team email to use in the event of this detecting an entry in a <team> package. Also
8# add <team> to the TEAMS list.
9LIBCORE_PACKAGES="\
10  android.icu \
11  android.system \
12  android.test \
13  com.android.bouncycastle \
14  com.android.conscrypt \
15  com.android.i18n.phonenumbers \
16  com.android.okhttp \
17  com.sun \
18  dalvik \
19  java \
20  javax \
21  junit \
22  libcore \
23  org.apache.harmony \
24  org.json \
25  org.w3c.dom \
26  org.xml.sax \
27  sun \
28  "
29LIBCORE_EMAIL=libcore-team@android.com
30
31# List of teams.
32TEAMS=LIBCORE
33
34# Generate the list of packages and convert to a regular expression.
35PACKAGES=$(for t in $TEAMS; do echo $(eval echo \${${t}_PACKAGES}); done)
36RE=$(echo ${PACKAGES} | sed "s/ /|/g")
37git show --name-only --pretty=format: $1 | grep "config/hiddenapi-.*txt" | while read file; do
38    ENTRIES=$(grep -E "^L(${RE})/" <(git show $1:$file))
39    if [[ -n "${ENTRIES}" ]]; then
40      echo -e "\e[1m\e[31m$file $1 contains the following entries\e[0m"
41      echo -e "\e[1m\e[31mfor packages that are handled using UnsupportedAppUsage. Please remove\e[0m"
42      echo -e "\e[1m\e[31mthese entries and add annotations instead.\e[0m"
43      # Partition the entries by team and provide contact details to aid in fixing the issue.
44      for t in ${TEAMS}
45      do
46        PACKAGES=$(eval echo \${${t}_PACKAGES})
47        RE=$(echo ${PACKAGES} | sed "s/ /|/g")
48        TEAM_ENTRIES=$(grep -E "^L(${RE})/" <(echo "${ENTRIES}"))
49        if [[ -n "${TEAM_ENTRIES}" ]]; then
50          EMAIL=$(eval echo \${${t}_EMAIL})
51          echo -e "\e[33mContact ${EMAIL} or compat- for help with the following:\e[0m"
52          for i in ${ENTRIES}
53          do
54            echo -e "\e[33m  ${i}\e[0m"
55          done
56        fi
57      done
58      exit 1
59    fi
60done
61