From f8492f05a8f0b3587a0f18d0aef139e3ab0dc08e Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 29 Nov 2017 08:32:55 +0100 Subject: [PATCH 1/3] gradle file: use flavour specific versionCode/versionName, fall back to parsing line by line --- fdroidserver/common.py | 67 ++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 89c1a1d5..a2068e10 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1299,27 +1299,56 @@ def parse_androidmanifests(paths, app): vercode = None package = None + flavour = app.builds[-1].gradle[-1] + if has_extension(path, 'gradle'): + # first try to get version name and code from correct flavour 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) + buildfile = f.read() + + regex_string = r"" + flavour + ".*?}" + search = re.compile(regex_string, re.DOTALL) + result = search.search(buildfile) + + if result is not None: + resultgroup = result.group() + + if not package: + matches = psearch_g(resultgroup) + if matches: + s = matches.group(2) + if app_matches_packagename(app, s): + package = s + if not version: + matches = vnsearch_g(resultgroup) + if matches: + 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: try: xml = parse_xml(path) From 33aee96ed91dfcfe01da16ee143921a0f4424917 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 30 Nov 2017 11:12:18 +0100 Subject: [PATCH 2/3] added test case --- fdroidserver/common.py | 4 ++- tests/common.TestCase | 29 +++++++++++++++++++ .../fdroid/fdroidclient/build.gradle | 15 ++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index a2068e10..b2e918ba 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1299,7 +1299,9 @@ def parse_androidmanifests(paths, app): vercode = None package = None - flavour = app.builds[-1].gradle[-1] + flavour = "" + if app.builds and 'gradle' in app.builds[-1] and app.builds[-1].gradle: + flavour = app.builds[-1].gradle[-1] if has_extension(path, 'gradle'): # first try to get version name and code from correct flavour diff --git a/tests/common.TestCase b/tests/common.TestCase index a5d52f75..68b84ff3 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -492,6 +492,35 @@ class CommonTest(unittest.TestCase): self.assertEqual('b30bb971af0d134866e158ec748fcd553df97c150f58b0a963190bbafbeb0868', sig) + def test_parse_androidmanifests(self): + source_files_dir = os.path.join(os.path.dirname(__file__), 'source-files') + app = fdroidserver.metadata.App() + app.id = 'org.fdroid.fdroid' + paths = [ + os.path.join(source_files_dir, 'fdroid', 'fdroidclient', 'AndroidManifest.xml'), + os.path.join(source_files_dir, 'fdroid', 'fdroidclient', 'build.gradle'), + ] + for path in paths: + self.assertTrue(os.path.isfile(path)) + self.assertEqual(('0.94-test', '940', 'org.fdroid.fdroid'), + fdroidserver.common.parse_androidmanifests(paths, app)) + + def test_parse_androidmanifests_with_flavor(self): + source_files_dir = os.path.join(os.path.dirname(__file__), 'source-files') + app = fdroidserver.metadata.App() + build = fdroidserver.metadata.Build() + build.gradle = ['devVersion'] + app.builds = [build] + app.id = 'org.fdroid.fdroid.dev' + paths = [ + os.path.join(source_files_dir, 'fdroid', 'fdroidclient', 'AndroidManifest.xml'), + os.path.join(source_files_dir, 'fdroid', 'fdroidclient', 'build.gradle'), + ] + for path in paths: + self.assertTrue(os.path.isfile(path)) + self.assertEqual(('0.95-dev', '949', 'org.fdroid.fdroid.dev'), + fdroidserver.common.parse_androidmanifests(paths, app)) + if __name__ == "__main__": parser = optparse.OptionParser() parser.add_option("-v", "--verbose", action="store_true", default=False, diff --git a/tests/source-files/fdroid/fdroidclient/build.gradle b/tests/source-files/fdroid/fdroidclient/build.gradle index 1d994dc8..c81ff357 100644 --- a/tests/source-files/fdroid/fdroidclient/build.gradle +++ b/tests/source-files/fdroid/fdroidclient/build.gradle @@ -128,6 +128,21 @@ task binaryDeps(type: Copy, dependsOn: ':F-Droid:prepareReleaseDependencies') { android { compileSdkVersion 21 buildToolsVersion '22.0.1' + + defaultConfig { + + flavorDimensions "default" + + productFlavors { + devVersion { + applicationId "org.fdroid.fdroid.dev" + dimension "default" + versionCode 949 + versionName "0.95-dev" + } + } + + } sourceSets { main { From c7c40cb59f232844a1d74120d8536673f655e435 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 30 Nov 2017 13:42:37 +0100 Subject: [PATCH 3/3] PEP8 fixes --- tests/common.TestCase | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common.TestCase b/tests/common.TestCase index 68b84ff3..84ea77fa 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -491,7 +491,6 @@ class CommonTest(unittest.TestCase): sig = fdroidserver.common.metadata_find_developer_signature('org.smssecure.smssecure') self.assertEqual('b30bb971af0d134866e158ec748fcd553df97c150f58b0a963190bbafbeb0868', sig) - def test_parse_androidmanifests(self): source_files_dir = os.path.join(os.path.dirname(__file__), 'source-files') app = fdroidserver.metadata.App() @@ -502,7 +501,7 @@ class CommonTest(unittest.TestCase): ] for path in paths: self.assertTrue(os.path.isfile(path)) - self.assertEqual(('0.94-test', '940', 'org.fdroid.fdroid'), + self.assertEqual(('0.94-test', '940', 'org.fdroid.fdroid'), fdroidserver.common.parse_androidmanifests(paths, app)) def test_parse_androidmanifests_with_flavor(self): @@ -521,6 +520,7 @@ class CommonTest(unittest.TestCase): self.assertEqual(('0.95-dev', '949', 'org.fdroid.fdroid.dev'), fdroidserver.common.parse_androidmanifests(paths, app)) + if __name__ == "__main__": parser = optparse.OptionParser() parser.add_option("-v", "--verbose", action="store_true", default=False,