chiark / gitweb /
Fix applicationIdSuffix / versionNameSuffix #455
authorJ-Jamet <jamet.jeremy@outlook.com>
Mon, 26 Mar 2018 17:45:06 +0000 (19:45 +0200)
committerJ-Jamet <jeremy.jamet@kunzisoft.com>
Fri, 4 May 2018 10:24:16 +0000 (12:24 +0200)
fdroidserver/common.py
tests/common.TestCase
tests/source-files/com.kunzisoft.testcase/build.gradle [new file with mode: 0644]

index bb1de220fb53a538ac98967c5447ce514aa2f1bf..8804b32d6512bbeba3ebfb5dccf1e672fed71fc0 100644 (file)
@@ -1332,7 +1332,9 @@ def remove_debuggable_flags(root_dir):
 
 vcsearch_g = re.compile(r'''.*[Vv]ersionCode\s*=?\s*["']*([0-9]+)["']*''').search
 vnsearch_g = re.compile(r'''.*[Vv]ersionName\s*=?\s*(["'])((?:(?=(\\?))\3.)*?)\1.*''').search
+vnssearch_g = re.compile(r'''.*[Vv]ersionNameSuffix\s*=?\s*(["'])((?:(?=(\\?))\3.)*?)\1.*''').search
 psearch_g = re.compile(r'''.*(packageName|applicationId)\s*=*\s*["']([^"']+)["'].*''').search
+fsearch_g = re.compile(r'''.*(applicationIdSuffix)\s*=*\s*["']([^"']+)["'].*''').search
 
 
 def app_matches_packagename(app, package):
@@ -1372,6 +1374,8 @@ def parse_androidmanifests(paths, app):
         package = None
 
         flavour = None
+        temp_app_id = None
+        temp_version_name = None
         if app.builds and 'gradle' in app.builds[-1] and app.builds[-1].gradle:
             flavour = app.builds[-1].gradle[-1]
 
@@ -1383,6 +1387,16 @@ def parse_androidmanifests(paths, app):
                     if gradle_comment.match(line):
                         continue
 
+                    if "applicationId" in line and not temp_app_id:
+                        matches = psearch_g(line)
+                        if matches:
+                            temp_app_id = matches.group(2)
+
+                    if "versionName" in line and not temp_version_name:
+                        matches = vnsearch_g(line)
+                        if matches:
+                            temp_version_name = matches.group(2)
+
                     if inside_flavour_group > 0:
                         if inside_required_flavour > 0:
                             matches = psearch_g(line)
@@ -1390,10 +1404,24 @@ def parse_androidmanifests(paths, app):
                                 s = matches.group(2)
                                 if app_matches_packagename(app, s):
                                     package = s
+                            else:
+                                # If build.gradle contains applicationIdSuffix add it to the end of package name
+                                matches = fsearch_g(line)
+                                if matches and temp_app_id:
+                                    suffix = matches.group(2)
+                                    temp_app_id = temp_app_id + suffix
+                                    if app_matches_packagename(app, temp_app_id):
+                                        package = temp_app_id
 
                             matches = vnsearch_g(line)
                             if matches:
                                 version = matches.group(2)
+                            else:
+                                # If build.gradle contains applicationNameSuffix add it to the end of version name
+                                matches = vnssearch_g(line)
+                                if matches and temp_version_name:
+                                    name_suffix = matches.group(2)
+                                    version = temp_version_name + name_suffix
 
                             matches = vcsearch_g(line)
                             if matches:
index 03acff650f09cc0df9e0a0293b7e4a47d9c19f47..f95a08207e707cae4d0405c2b99c91f500f95630 100755 (executable)
@@ -740,6 +740,45 @@ class CommonTest(unittest.TestCase):
         self.assertEqual(('1.9.8.1-ose', '197', 'at.bitfire.davdroid'),
                          fdroidserver.common.parse_androidmanifests(paths, app))
 
+        app = fdroidserver.metadata.App()
+        build = fdroidserver.metadata.Build()
+        build.gradle = ['libre']
+        app.builds = [build]
+        app.id = 'com.kunzisoft.fdroidtest.applicationidsuffix.libre'
+        paths = [
+            os.path.join(source_files_dir, 'com.kunzisoft.testcase', 'build.gradle'),
+        ]
+        for path in paths:
+            self.assertTrue(os.path.isfile(path))
+        self.assertEqual(('1.0-libre', '1', 'com.kunzisoft.fdroidtest.applicationidsuffix.libre'),
+                         fdroidserver.common.parse_androidmanifests(paths, app))
+
+        app = fdroidserver.metadata.App()
+        build = fdroidserver.metadata.Build()
+        build.gradle = ['pro']
+        app.builds = [build]
+        app.id = 'com.kunzisoft.fdroidtest.applicationidsuffix.pro'
+        paths = [
+            os.path.join(source_files_dir, 'com.kunzisoft.testcase', 'build.gradle'),
+        ]
+        for path in paths:
+            self.assertTrue(os.path.isfile(path))
+        self.assertEqual(('20180430-pro', '20180430', 'com.kunzisoft.fdroidtest.applicationidsuffix.pro'),
+                         fdroidserver.common.parse_androidmanifests(paths, app))
+
+        app = fdroidserver.metadata.App()
+        build = fdroidserver.metadata.Build()
+        build.gradle = ['free']
+        app.builds = [build]
+        app.id = 'com.kunzisoft.fdroidtest.applicationidsuffix'
+        paths = [
+            os.path.join(source_files_dir, 'com.kunzisoft.testcase', 'build.gradle'),
+        ]
+        for path in paths:
+            self.assertTrue(os.path.isfile(path))
+        self.assertEqual(('1.0-free', '1', 'com.kunzisoft.fdroidtest.applicationidsuffix'),
+                         fdroidserver.common.parse_androidmanifests(paths, app))
+
 
 if __name__ == "__main__":
     parser = optparse.OptionParser()
diff --git a/tests/source-files/com.kunzisoft.testcase/build.gradle b/tests/source-files/com.kunzisoft.testcase/build.gradle
new file mode 100644 (file)
index 0000000..4319e20
--- /dev/null
@@ -0,0 +1,62 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 27
+    defaultConfig {
+        applicationId "com.kunzisoft.fdroidtest.applicationidsuffix"
+        minSdkVersion 14
+        targetSdkVersion 27
+        versionCode 1
+        versionName "1.0"
+        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+    }
+    buildTypes {
+        release {
+            minifyEnabled = false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+
+    dexOptions {
+    }
+
+    flavorDimensions "tier"
+    productFlavors {
+        libre {
+            applicationIdSuffix = ".libre"
+            versionNameSuffix "-libre"
+            buildConfigField "boolean", "FULL_VERSION", "true"
+            buildConfigField "boolean", "CLOSED_STORE", "false"
+            // ApplicationId : com.kunzisoft.fdroidtest.applicationidsuffix.libre
+            // Version code : 1
+            // Version name : 1.0-libre
+        }
+        pro {
+            applicationIdSuffix = ".pro"
+            versionCode 20180430
+            versionName "20180430-pro"
+            buildConfigField "boolean", "FULL_VERSION", "true"
+            buildConfigField "boolean", "CLOSED_STORE", "true"
+            // ApplicationId : com.kunzisoft.fdroidtest.applicationidsuffix.pro
+            // Version code : 20180430
+            // Version name : 20180430-pro
+        }
+        free {
+            versionNameSuffix "-free"
+            buildConfigField "boolean", "FULL_VERSION", "false"
+            buildConfigField "boolean", "CLOSED_STORE", "true"
+            // ApplicationId : com.kunzisoft.fdroidtest.applicationidsuffix
+            // Version code : 1
+            // Version name : 1.0-free
+        }
+    }
+}
+
+dependencies {
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
+    implementation 'com.android.support:appcompat-v7:27.1.1'
+    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
+    testImplementation 'junit:junit:4.12'
+    androidTestImplementation 'com.android.support.test:runner:1.0.2'
+    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
+}