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 | |
| 22 | parser = OptionParser() |
| 23 | opts, args = parser.parse_args() |
| 24 | |
| 25 | if not len(args): |
| 26 | parser.error('not enough arguments') |
| 27 | elif len(args) > 1: |
| 28 | parser.error('too many arguments') |
| 29 | |
| 30 | new_version = args[0] |
| 31 | pattern = re.compile(r'(\s*)<version>[-.\w]+</version>') |
| 32 | |
Edwin Kempin | c7ddc2c | 2014-05-21 11:12:35 +0200 | [diff] [blame] | 33 | for project in ['gerrit-extension-api', 'gerrit-plugin-api', |
| 34 | 'gerrit-plugin-archetype', 'gerrit-plugin-gwt-archetype', |
David Ostrovsky | 520f29c | 2014-05-22 21:44:29 +0200 | [diff] [blame] | 35 | 'gerrit-plugin-gwtui', 'gerrit-plugin-js-archetype', |
| 36 | 'gerrit-war']: |
David Pursehouse | 9a13f85 | 2014-03-26 14:45:02 -0700 | [diff] [blame] | 37 | pom = os.path.join(project, 'pom.xml') |
| 38 | try: |
| 39 | outxml = "" |
| 40 | found = False |
| 41 | for line in open(pom, "r"): |
| 42 | m = pattern.match(line) |
| 43 | if m and not found: |
| 44 | outxml += "%s<version>%s</version>\n" % (m.group(1), new_version) |
| 45 | found = True |
| 46 | else: |
| 47 | outxml += line |
| 48 | with open(pom, "w") as outfile: |
| 49 | outfile.write(outxml) |
| 50 | except IOError as err: |
| 51 | print('error updating %s: %s' % (pom, err), file=sys.stderr) |