1#!/usr/bin/env python3
2
3"""
4Copyright 2018 The Android Open Source Project
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10     http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17"""
18
19import argparse, os, subprocess, sys
20
21NAME_HELP = '''
22  The name of the artifact you want to add to the prebuilts folder.
23  E.g. android.arch.work:work-runtime-ktx:1.0.0-alpha07
24'''
25
26ANDROIDX_BUILD_ID_HELP = '''
27  The build id of https://ci.android.com/builds/branches/aosp-androidx-main/grid?
28  to use for fetching androidx prebuilts.
29'''
30
31METALAVA_BUILD_ID_HELP = '''
32  The build id of https://ci.android.com/builds/branches/aosp-metalava-master/grid?
33  to use for metalava prebuilt fetching.
34'''
35
36ALLOW_JETBRAINS_DEV_HELP = '''
37  Whether or not to allow artifacts to be fetched from Jetbrains' dev repository
38  E.g. https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev
39'''
40
41FETCH_KMP_ARTIFACTS_HELP = '''
42  If set, we'll fetch all KMP artifacts as well
43  E.g. passing -n "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1" will fetch native targets
44  of coroutines-core as well.
45'''
46
47if sys.version_info[0] < 3: raise Exception("Python 2 is not supported by this script. If your system python calls python 2 after python 2 end-of-life on Jan 1 2020, you should probably change it.")
48
49def main():
50    """Parses the command line arguments, and executes the gradle script
51    which downloads the maven artifacts.
52    """
53    os.chdir(os.path.dirname(sys.argv[0]))
54    parser = argparse.ArgumentParser(
55        description='Helps download maven artifacts to prebuilts.')
56    parser.add_argument('-n', '--name', help=NAME_HELP,
57                        required=True, dest='name')
58    parser.add_argument('-ab', '--androidx-build-id', help=ANDROIDX_BUILD_ID_HELP,
59                        required=False, dest='androidx_build_id')
60    parser.add_argument('-mb', '--metalava-build-id', help=METALAVA_BUILD_ID_HELP,
61                        required=False, dest='metalava_build_id')
62    parser.add_argument('-ajd', '--allow-jetbrains-dev', help=ALLOW_JETBRAINS_DEV_HELP,
63                        required=False, action='store_true')
64    parser.add_argument('-kmp', '--fetch-kmp-artifacts', help=FETCH_KMP_ARTIFACTS_HELP,
65                        required=False, action='store_true')
66    parse_result = parser.parse_args()
67    artifact_name = parse_result.name
68
69    command = 'importMaven.sh %s' % (artifact_name)
70    # AndroidX Build Id
71    androidx_build_id = parse_result.androidx_build_id
72    if (androidx_build_id):
73      command = command + ' --androidx-build-id %s' % (androidx_build_id)
74    # Metalava Build Id
75    metalava_build_id = parse_result.metalava_build_id
76    if (metalava_build_id):
77      command = command + ' --metalava-build-id %s' % (metalava_build_id)
78    if (parse_result.allow_jetbrains_dev):
79      command = command + ' --allow-jetbrains-dev'
80
81    my_directory = os.path.dirname(sys.argv[0])
82    sys.exit("""
83        This script is deprecated and will be removed. Please execute:
84        %s/%s
85        See %s/README.md for more details.
86    """ % (my_directory, command, my_directory))
87
88if __name__ == '__main__':
89    main()
90