gradle file: use flavour specific versionCode/versionName, fall back to parsing line by line

This commit is contained in:
tobiasKaminsky 2017-11-29 08:32:55 +01:00
parent 5607ccdc41
commit f8492f05a8
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7

View file

@ -1299,27 +1299,56 @@ def parse_androidmanifests(paths, app):
vercode = None vercode = None
package = None package = None
flavour = app.builds[-1].gradle[-1]
if has_extension(path, 'gradle'): if has_extension(path, 'gradle'):
# first try to get version name and code from correct flavour
with open(path, 'r') as f: with open(path, 'r') as f:
for line in f: buildfile = f.read()
if gradle_comment.match(line):
continue regex_string = r"" + flavour + ".*?}"
# Grab first occurence of each to avoid running into search = re.compile(regex_string, re.DOTALL)
# alternative flavours and builds. result = search.search(buildfile)
if not package:
matches = psearch_g(line) if result is not None:
if matches: resultgroup = result.group()
s = matches.group(2)
if app_matches_packagename(app, s): if not package:
package = s matches = psearch_g(resultgroup)
if not version: if matches:
matches = vnsearch_g(line) s = matches.group(2)
if matches: if app_matches_packagename(app, s):
version = matches.group(2) package = s
if not vercode: if not version:
matches = vcsearch_g(line) matches = vnsearch_g(resultgroup)
if matches: if matches:
vercode = matches.group(1) version = matches.group(2)
if not vercode:
matches = vcsearch_g(resultgroup)
if matches:
vercode = matches.group(1)
else:
# fall back to parse file line by line
with open(path, 'r') as f:
for line in f:
if gradle_comment.match(line):
continue
# Grab first occurence of each to avoid running into
# alternative flavours and builds.
if not package:
matches = psearch_g(line)
if matches:
s = matches.group(2)
if app_matches_packagename(app, s):
package = s
if not version:
matches = vnsearch_g(line)
if matches:
version = matches.group(2)
if not vercode:
matches = vcsearch_g(line)
if matches:
vercode = matches.group(1)
else: else:
try: try:
xml = parse_xml(path) xml = parse_xml(path)