blob: 9f03a5972a9175e1633fa180ad3fa263621963f9 [file] [log] [blame]
Björn Pedersenc357ceb2015-05-27 10:17:36 +02001#!/usr/bin/env python
David Pursehouse9a13f852014-03-26 14:45:02 -07002# 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
17from optparse import OptionParser
18import os.path
19import re
20import sys
21
22parser = OptionParser()
23opts, args = parser.parse_args()
24
25if not len(args):
26 parser.error('not enough arguments')
27elif len(args) > 1:
28 parser.error('too many arguments')
29
David Pursehouse8612f892015-07-06 14:08:34 +090030DEST_PATTERN = r'\g<1>%s\g<3>' % args[0]
David Pursehouse9a13f852014-03-26 14:45:02 -070031
David Pursehouse8612f892015-07-06 14:08:34 +090032
33def replace_in_file(filename, src_pattern):
34 try:
35 f = open(filename, "r")
36 s = f.read()
37 f.close()
38 s = re.sub(src_pattern, DEST_PATTERN, s)
39 f = open(filename, "w")
40 f.write(s)
41 f.close()
42 except IOError as err:
43 print('error updating %s: %s' % (filename, err), file=sys.stderr)
44
45
46src_pattern = re.compile(r'^(\s*<version>)([-.\w]+)(</version>\s*)$',
47 re.MULTILINE)
David Ostrovsky947b5e52015-09-24 21:52:17 +020048for project in ['gerrit-acceptance-framework', 'gerrit-extension-api',
49 'gerrit-plugin-api', 'gerrit-plugin-archetype',
50 'gerrit-plugin-gwt-archetype', 'gerrit-plugin-gwtui',
51 'gerrit-plugin-js-archetype', 'gerrit-war']:
David Pursehouse9a13f852014-03-26 14:45:02 -070052 pom = os.path.join(project, 'pom.xml')
David Pursehouse8612f892015-07-06 14:08:34 +090053 replace_in_file(pom, src_pattern)
David Pursehousea022f3e2015-01-22 16:42:36 +090054
David Pursehouse8612f892015-07-06 14:08:34 +090055src_pattern = re.compile(r"^(GERRIT_VERSION = ')([-.\w]+)(')$", re.MULTILINE)
56replace_in_file('VERSION', src_pattern)
57
58src_pattern = re.compile(r'^(\s*-DarchetypeVersion=)([-.\w]+)(\s*\\)$',
59 re.MULTILINE)
60replace_in_file(os.path.join('Documentation', 'dev-plugins.txt'), src_pattern)