Björn Pedersen | c357ceb | 2015-05-27 10:17:36 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 2 | # Copyright (C) 2013 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | from __future__ import print_function |
Paladox none | f262d68 | 2020-02-02 01:40:48 +0000 | [diff] [blame] | 17 | import argparse |
David Ostrovsky | 520f29c | 2014-05-22 21:44:29 +0200 | [diff] [blame] | 18 | from os import path, environ |
Jacek Centkowski | 3509776 | 2018-02-07 12:44:05 +0100 | [diff] [blame] | 19 | from subprocess import check_output, CalledProcessError |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 20 | from sys import stderr |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 21 | |
Paladox none | f262d68 | 2020-02-02 01:40:48 +0000 | [diff] [blame] | 22 | parser = argparse.ArgumentParser() |
| 23 | parser.add_argument('--repository', help='maven repository id') |
| 24 | parser.add_argument('--url', help='maven repository url') |
| 25 | parser.add_argument('-o') |
| 26 | parser.add_argument('-a', help='action (valid actions are: install,deploy)') |
| 27 | parser.add_argument('-v', help='gerrit version') |
| 28 | parser.add_argument('-s', action='append', help='triplet of artifactId:type:path') |
| 29 | args = parser.parse_args() |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 30 | |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 31 | if not args.v: |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 32 | print('version is empty', file=stderr) |
| 33 | exit(1) |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 34 | |
David Ostrovsky | 520f29c | 2014-05-22 21:44:29 +0200 | [diff] [blame] | 35 | root = path.abspath(__file__) |
David Ostrovsky | fdbfcad | 2016-11-15 06:35:29 -0800 | [diff] [blame] | 36 | while not path.exists(path.join(root, 'WORKSPACE')): |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 37 | root = path.dirname(root) |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 38 | |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 39 | if 'install' == args.a: |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 40 | cmd = [ |
| 41 | 'mvn', |
| 42 | 'install:install-file', |
| 43 | '-Dversion=%s' % args.v, |
| 44 | ] |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 45 | elif 'deploy' == args.a: |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 46 | cmd = [ |
| 47 | 'mvn', |
| 48 | 'gpg:sign-and-deploy-file', |
David Pursehouse | 2be2df6 | 2019-06-04 21:20:47 +0900 | [diff] [blame] | 49 | '-Dversion=%s' % args.v, |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 50 | '-DrepositoryId=%s' % args.repository, |
| 51 | '-Durl=%s' % args.url, |
| 52 | ] |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 53 | else: |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 54 | print("unknown action -a %s" % args.a, file=stderr) |
| 55 | exit(1) |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 56 | |
| 57 | for spec in args.s: |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 58 | artifact, packaging_type, src = spec.split(':') |
| 59 | exe = cmd + [ |
Chad Horohoe | 6914232 | 2018-05-17 10:19:22 -0700 | [diff] [blame] | 60 | '-DpomFile=%s' % path.join(root, 'tools', 'maven', |
| 61 | '%s_pom.xml' % artifact), |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 62 | '-Dpackaging=%s' % packaging_type, |
| 63 | '-Dfile=%s' % src, |
| 64 | ] |
| 65 | try: |
| 66 | if environ.get('VERBOSE'): |
| 67 | print(' '.join(exe), file=stderr) |
| 68 | check_output(exe) |
| 69 | except Exception as e: |
| 70 | print('%s command failed: %s\n%s' % (args.a, ' '.join(exe), e), |
| 71 | file=stderr) |
| 72 | if environ.get('VERBOSE') and isinstance(e, CalledProcessError): |
| 73 | print('Command output\n%s' % e.output, file=stderr) |
| 74 | exit(1) |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 75 | |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 76 | |
| 77 | out = stderr |
| 78 | if args.o: |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 79 | out = open(args.o, 'w') |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 80 | |
| 81 | with out as fd: |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 82 | if args.repository: |
| 83 | print('Repository: %s' % args.repository, file=fd) |
| 84 | if args.url: |
| 85 | print('URL: %s' % args.url, file=fd) |
| 86 | print('Version: %s' % args.v, file=fd) |