David Ostrovsky | 2b5fe09 | 2021-03-03 11:52:30 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Dave Borowitz | 9b87707 | 2017-10-01 16:17:42 -0400 | [diff] [blame] | 2 | # Copyright (C) 2014 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 |
Dave Borowitz | 9b87707 | 2017-10-01 16:17:42 -0400 | [diff] [blame] | 18 | import os.path |
| 19 | import re |
| 20 | import sys |
| 21 | |
Paladox none | f262d68 | 2020-02-02 01:40:48 +0000 | [diff] [blame] | 22 | parser = argparse.ArgumentParser() |
| 23 | parser.add_argument('version') |
| 24 | args = parser.parse_args() |
Dave Borowitz | 9b87707 | 2017-10-01 16:17:42 -0400 | [diff] [blame] | 25 | |
Paladox none | f262d68 | 2020-02-02 01:40:48 +0000 | [diff] [blame] | 26 | DEST_PATTERN = r'\g<1>%s\g<3>' % args.version |
Dave Borowitz | 9b87707 | 2017-10-01 16:17:42 -0400 | [diff] [blame] | 27 | |
| 28 | def replace_in_file(filename, src_pattern): |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 29 | try: |
| 30 | f = open(filename, "r") |
| 31 | s = f.read() |
| 32 | f.close() |
| 33 | s = re.sub(src_pattern, DEST_PATTERN, s) |
| 34 | f = open(filename, "w") |
| 35 | f.write(s) |
| 36 | f.close() |
| 37 | except IOError as err: |
| 38 | print('error updating %s: %s' % (filename, err), file=sys.stderr) |
Dave Borowitz | 9b87707 | 2017-10-01 16:17:42 -0400 | [diff] [blame] | 39 | |
| 40 | |
| 41 | src_pattern = re.compile(r'^(\s*<version>)([-.\w]+)(</version>\s*)$', |
| 42 | re.MULTILINE) |
| 43 | for project in ['gerrit-acceptance-framework', 'gerrit-extension-api', |
David Ostrovsky | 7163dac | 2017-07-29 06:49:38 +0200 | [diff] [blame] | 44 | 'gerrit-plugin-api', 'gerrit-war']: |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 45 | pom = os.path.join('tools', 'maven', '%s_pom.xml' % project) |
| 46 | replace_in_file(pom, src_pattern) |
Dave Borowitz | 9b87707 | 2017-10-01 16:17:42 -0400 | [diff] [blame] | 47 | |
| 48 | src_pattern = re.compile(r'^(GERRIT_VERSION = ")([-.\w]+)(")$', re.MULTILINE) |
| 49 | replace_in_file('version.bzl', src_pattern) |