blob: d02fc26c7697e6fba82931122767e2291d810453 [file] [log] [blame]
David Ostrovsky2b5fe092021-03-03 11:52:30 +01001#!/usr/bin/env python3
Dave Borowitz9b877072017-10-01 16:17:42 -04002# 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
16from __future__ import print_function
Paladox nonef262d682020-02-02 01:40:48 +000017import argparse
Dave Borowitz9b877072017-10-01 16:17:42 -040018import os.path
19import re
20import sys
21
Paladox nonef262d682020-02-02 01:40:48 +000022parser = argparse.ArgumentParser()
23parser.add_argument('version')
24args = parser.parse_args()
Dave Borowitz9b877072017-10-01 16:17:42 -040025
Paladox nonef262d682020-02-02 01:40:48 +000026DEST_PATTERN = r'\g<1>%s\g<3>' % args.version
Dave Borowitz9b877072017-10-01 16:17:42 -040027
28def replace_in_file(filename, src_pattern):
Chad Horohoedd224702018-05-16 22:33:06 -040029 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 Borowitz9b877072017-10-01 16:17:42 -040039
40
41src_pattern = re.compile(r'^(\s*<version>)([-.\w]+)(</version>\s*)$',
42 re.MULTILINE)
43for project in ['gerrit-acceptance-framework', 'gerrit-extension-api',
David Ostrovsky7163dac2017-07-29 06:49:38 +020044 'gerrit-plugin-api', 'gerrit-war']:
Chad Horohoedd224702018-05-16 22:33:06 -040045 pom = os.path.join('tools', 'maven', '%s_pom.xml' % project)
46 replace_in_file(pom, src_pattern)
Dave Borowitz9b877072017-10-01 16:17:42 -040047
48src_pattern = re.compile(r'^(GERRIT_VERSION = ")([-.\w]+)(")$', re.MULTILINE)
49replace_in_file('version.bzl', src_pattern)