David Pursehouse | 9a13f85 | 2014-03-26 14:45:02 -0700 | [diff] [blame] | 1 | #!/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 | |
| 16 | from __future__ import print_function |
| 17 | from optparse import OptionParser |
| 18 | import os.path |
| 19 | import re |
| 20 | import sys |
| 21 | |
David Pursehouse | a022f3e | 2015-01-22 16:42:36 +0900 | [diff] [blame] | 22 | version_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 | # |
| 26 | GERRIT_VERSION = '%s' |
| 27 | """ |
David Pursehouse | 9a13f85 | 2014-03-26 14:45:02 -0700 | [diff] [blame] | 28 | parser = OptionParser() |
| 29 | opts, args = parser.parse_args() |
| 30 | |
| 31 | if not len(args): |
| 32 | parser.error('not enough arguments') |
| 33 | elif len(args) > 1: |
| 34 | parser.error('too many arguments') |
| 35 | |
| 36 | new_version = args[0] |
| 37 | pattern = re.compile(r'(\s*)<version>[-.\w]+</version>') |
| 38 | |
Edwin Kempin | c7ddc2c | 2014-05-21 11:12:35 +0200 | [diff] [blame] | 39 | for project in ['gerrit-extension-api', 'gerrit-plugin-api', |
| 40 | 'gerrit-plugin-archetype', 'gerrit-plugin-gwt-archetype', |
David Ostrovsky | 520f29c | 2014-05-22 21:44:29 +0200 | [diff] [blame] | 41 | 'gerrit-plugin-gwtui', 'gerrit-plugin-js-archetype', |
| 42 | 'gerrit-war']: |
David Pursehouse | 9a13f85 | 2014-03-26 14:45:02 -0700 | [diff] [blame] | 43 | 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 Pursehouse | a022f3e | 2015-01-22 16:42:36 +0900 | [diff] [blame] | 58 | |
| 59 | try: |
| 60 | with open('VERSION', "w") as version_file: |
| 61 | version_file.write(version_text % new_version) |
| 62 | except IOError as err: |
| 63 | print('error updating VERSION: %s' % err, file=sys.stderr) |