1#  Copyright (C) 2023 The Android Open Source Project
2#
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.
14import sys
15import os
16import subprocess
17
18# Purpose: This simple script allows one to generate @ApiTest api annotations easily from a full list of apis.
19# Usage: python generate-apitest-annotation.py <keyword>
20#
21# Example Output:
22# @ApiTest(apis = {"android.car.VehiclePropertyIds#INVALID",
23#                 "android.car.VehiclePropertyIds#INFO_VIN"}
24
25rootDir = os.getenv("ANDROID_BUILD_TOP")
26
27if len(sys.argv) < 2:
28    print("Must specify a key word to filter classes on: ex. VehiclePropertyIds")
29    sys.exit(1)
30
31filter_keyword = sys.argv[1]
32
33# Generate class list using tool
34java_cmd = "java -jar " + rootDir + "/packages/services/Car/tools/GenericCarApiBuilder" \
35                                    "/GenericCarApiBuilder.jar --print-all-apis " \
36                                    "--root-dir " + rootDir
37full_api_list = subprocess.check_output(java_cmd, shell=True).decode('utf-8').strip().split("\n")
38
39output = "@ApiTest(apis = {"
40for api in full_api_list:
41    if filter_keyword in api:
42        tokens = api.split()
43        output += "\"" + tokens[0] + "." + tokens[1] + "#" + tokens[3]
44
45        # Trim arguments from methods
46        if '(' in output:
47            output = output[:output.index('(')]
48
49        output += "\","
50
51output = output[:-1] + "})"
52print(output)
53
54
55