blob: 60e9f15608f57cefcbc0453357b2350cfe0a70cd [file] [log] [blame]
Björn Pedersenc357ceb2015-05-27 10:17:36 +02001#!/usr/bin/env python
Shawn Pearce06497862013-07-29 15:44:49 -07002# 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
16from __future__ import print_function
Paladox nonef262d682020-02-02 01:40:48 +000017import argparse
David Ostrovsky520f29c2014-05-22 21:44:29 +020018from os import path, environ
Jacek Centkowski35097762018-02-07 12:44:05 +010019from subprocess import check_output, CalledProcessError
Shawn Pearce06497862013-07-29 15:44:49 -070020from sys import stderr
Shawn Pearce06497862013-07-29 15:44:49 -070021
Paladox nonef262d682020-02-02 01:40:48 +000022parser = argparse.ArgumentParser()
23parser.add_argument('--repository', help='maven repository id')
24parser.add_argument('--url', help='maven repository url')
25parser.add_argument('-o')
26parser.add_argument('-a', help='action (valid actions are: install,deploy)')
27parser.add_argument('-v', help='gerrit version')
28parser.add_argument('-s', action='append', help='triplet of artifactId:type:path')
29args = parser.parse_args()
Shawn Pearce06497862013-07-29 15:44:49 -070030
Shawn Pearce06497862013-07-29 15:44:49 -070031if not args.v:
Chad Horohoedd224702018-05-16 22:33:06 -040032 print('version is empty', file=stderr)
33 exit(1)
Shawn Pearce06497862013-07-29 15:44:49 -070034
David Ostrovsky520f29c2014-05-22 21:44:29 +020035root = path.abspath(__file__)
David Ostrovskyfdbfcad2016-11-15 06:35:29 -080036while not path.exists(path.join(root, 'WORKSPACE')):
Chad Horohoedd224702018-05-16 22:33:06 -040037 root = path.dirname(root)
Shawn Pearcea7a3ee12013-09-20 10:42:37 -070038
Shawn Pearce06497862013-07-29 15:44:49 -070039if 'install' == args.a:
Chad Horohoedd224702018-05-16 22:33:06 -040040 cmd = [
41 'mvn',
42 'install:install-file',
43 '-Dversion=%s' % args.v,
44 ]
Shawn Pearce06497862013-07-29 15:44:49 -070045elif 'deploy' == args.a:
Chad Horohoedd224702018-05-16 22:33:06 -040046 cmd = [
47 'mvn',
48 'gpg:sign-and-deploy-file',
David Pursehouse2be2df62019-06-04 21:20:47 +090049 '-Dversion=%s' % args.v,
Chad Horohoedd224702018-05-16 22:33:06 -040050 '-DrepositoryId=%s' % args.repository,
51 '-Durl=%s' % args.url,
52 ]
Shawn Pearce06497862013-07-29 15:44:49 -070053else:
Chad Horohoedd224702018-05-16 22:33:06 -040054 print("unknown action -a %s" % args.a, file=stderr)
55 exit(1)
Shawn Pearce06497862013-07-29 15:44:49 -070056
57for spec in args.s:
Chad Horohoedd224702018-05-16 22:33:06 -040058 artifact, packaging_type, src = spec.split(':')
59 exe = cmd + [
Chad Horohoe69142322018-05-17 10:19:22 -070060 '-DpomFile=%s' % path.join(root, 'tools', 'maven',
61 '%s_pom.xml' % artifact),
Chad Horohoedd224702018-05-16 22:33:06 -040062 '-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 Pearcea7a3ee12013-09-20 10:42:37 -070075
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020076
77out = stderr
78if args.o:
Chad Horohoedd224702018-05-16 22:33:06 -040079 out = open(args.o, 'w')
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020080
81with out as fd:
Chad Horohoedd224702018-05-16 22:33:06 -040082 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)