blob: 28f6b65ec35fce4551ec9675cc077f4afe3548e7 [file] [log] [blame]
David Pursehouse9a13f852014-03-26 14:45:02 -07001#!/usr/bin/python
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
16from __future__ import print_function
17from optparse import OptionParser
18import os.path
19import re
20import sys
21
David Pursehousea022f3e2015-01-22 16:42:36 +090022version_text = """# Maven style API version (e.g. '2.x-SNAPSHOT').
23# Used by :api_install and :api_deploy targets
24# when talking to the destination repository.
25#
26GERRIT_VERSION = '%s'
27"""
David Pursehouse9a13f852014-03-26 14:45:02 -070028parser = OptionParser()
29opts, args = parser.parse_args()
30
31if not len(args):
32 parser.error('not enough arguments')
33elif len(args) > 1:
34 parser.error('too many arguments')
35
36new_version = args[0]
37pattern = re.compile(r'(\s*)<version>[-.\w]+</version>')
38
Edwin Kempinc7ddc2c2014-05-21 11:12:35 +020039for project in ['gerrit-extension-api', 'gerrit-plugin-api',
40 'gerrit-plugin-archetype', 'gerrit-plugin-gwt-archetype',
David Ostrovsky520f29c2014-05-22 21:44:29 +020041 'gerrit-plugin-gwtui', 'gerrit-plugin-js-archetype',
42 'gerrit-war']:
David Pursehouse9a13f852014-03-26 14:45:02 -070043 pom = os.path.join(project, 'pom.xml')
44 try:
45 outxml = ""
46 found = False
47 for line in open(pom, "r"):
48 m = pattern.match(line)
49 if m and not found:
50 outxml += "%s<version>%s</version>\n" % (m.group(1), new_version)
51 found = True
52 else:
53 outxml += line
54 with open(pom, "w") as outfile:
55 outfile.write(outxml)
56 except IOError as err:
57 print('error updating %s: %s' % (pom, err), file=sys.stderr)
David Pursehousea022f3e2015-01-22 16:42:36 +090058
59try:
60 with open('VERSION', "w") as version_file:
61 version_file.write(version_text % new_version)
62except IOError as err:
63 print('error updating VERSION: %s' % err, file=sys.stderr)