From 0fefecde1e3b3e9287fd43ee1b82e1e2f57bac56 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sat, 12 Jun 2021 23:59:18 +0200 Subject: [PATCH 1/2] Fix matching substring flavour detection com.github.jameshnsears.quoteunquote defines flavours 'fdroid' and 'fdroidS'. The old code used flavour in line, which matches both and the wrong one was selected. Closes: #912 --- MANIFEST.in | 1 + fdroidserver/common.py | 3 +- tests/common.TestCase | 13 + .../build.gradle | 232 ++++++++++++++++++ 4 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 tests/source-files/com.github.jameshnsears.quoteunquote/build.gradle diff --git a/MANIFEST.in b/MANIFEST.in index 7f478ba8..19d3c346 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -715,6 +715,7 @@ include tests/source-files/com.anpmech.launcher/app/build.gradle include tests/source-files/com.anpmech.launcher/app/src/main/AndroidManifest.xml include tests/source-files/com.anpmech.launcher/build.gradle include tests/source-files/com.anpmech.launcher/settings.gradle +include tests/source-files/com.github.jameshnsears.quoteunquote/build.gradle include tests/source-files/com.integreight.onesheeld/build.gradle include tests/source-files/com.integreight.onesheeld/gradle/wrapper/gradle-wrapper.properties include tests/source-files/com.integreight.onesheeld/localeapi/build.gradle diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 661775a0..1c2ddf1d 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1683,7 +1683,8 @@ def parse_androidmanifests(paths, app): if '}' in line: inside_required_flavour -= 1 else: - if flavour and (flavour in line): + if flavour and re.match( + r'.*[\'"\s]{flavour}[\'"\s].*'.format(flavour=flavour), line): inside_required_flavour = 1 if '{' in line: diff --git a/tests/common.TestCase b/tests/common.TestCase index 1f79483e..0f567ad3 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -1235,6 +1235,19 @@ class CommonTest(unittest.TestCase): self.assertEqual(('1.0', '1', 'com.kunzisoft.fdroidtest.applicationidsuffix.underscore_first'), fdroidserver.common.parse_androidmanifests(paths, app)) + app = fdroidserver.metadata.App() + build = fdroidserver.metadata.Build() + build.gradle = ['fdroid'] + app['Builds'] = [build] + app.id = 'com.github.jameshnsears.quoteunquote' + paths = [ + os.path.join('source-files', 'com.github.jameshnsears.quoteunquote', 'build.gradle'), + ] + for path in paths: + self.assertTrue(os.path.isfile(path)) + self.assertEqual(('2.5.2-fdroid', '73', 'com.github.jameshnsears.quoteunquote'), + fdroidserver.common.parse_androidmanifests(paths, app)) + def test_get_all_gradle_and_manifests(self): """Test whether the function works with relative and absolute paths""" a = fdroidserver.common.get_all_gradle_and_manifests(Path('source-files/cn.wildfirechat.chat')) diff --git a/tests/source-files/com.github.jameshnsears.quoteunquote/build.gradle b/tests/source-files/com.github.jameshnsears.quoteunquote/build.gradle new file mode 100644 index 00000000..bb55589e --- /dev/null +++ b/tests/source-files/com.github.jameshnsears.quoteunquote/build.gradle @@ -0,0 +1,232 @@ +apply plugin: 'com.android.application' +apply plugin: 'com.google.gms.google-services' +apply plugin: 'kotlin-android' + +apply from: '../jacoco.gradle' +apply from: '../ktlint.gradle' +apply from: '../detekt.gradle' +apply from: '../checkstyle.gradle' +apply from: '../sonarcube.gradle' + +def localPropertiesFile = rootProject.file("local.properties") +def localProperties = new Properties() + +if (!localPropertiesFile.exists()) { + localProperties.setProperty("RELEASE_STORE_PASSWORD", "") + localProperties.setProperty("RELEASE_KEY_PASSWORD", "") + localProperties.setProperty("RELEASE_KEY_ALIAS", "") + localProperties.setProperty("RELEASE_STORE_FILE", "keystore.jks") + Writer writer = new FileWriter(localPropertiesFile, false) + localProperties.store(writer, "empty, as creating the file is done manually via gpg") + writer.close() + + file(project(':app').projectDir.path + "/keystore.jks").text = "" +} + +localProperties.load(new FileInputStream(localPropertiesFile)) + +android { + compileSdkVersion 30 + // compileSdkVersion "android-S" + + signingConfigs { + googleplay { + keyAlias localProperties['RELEASE_KEY_ALIAS'] + keyPassword localProperties['RELEASE_KEY_PASSWORD'] + storeFile file(localProperties['RELEASE_STORE_FILE']) + storePassword localProperties['RELEASE_STORE_PASSWORD'] + } + } + + defaultConfig { + minSdkVersion 24 + targetSdkVersion 30 + // minSdkVersion "S" + // targetSdkVersion "S" + + applicationId "com.github.jameshnsears.quoteunquote" + + versionCode 73 + versionName "2.5.2" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunnerArguments clearPackageData: 'true' + + javaCompileOptions { + annotationProcessorOptions { + arguments += ["room.schemaLocation": + "$projectDir/schemas".toString()] + } + } + } + + packagingOptions { + exclude "**/module-info.class" + exclude 'LICENSE' + exclude 'README.md' + } + + lintOptions { + abortOnError true + warningsAsErrors false + checkAllWarnings = true + xmlReport false + htmlReport true + } + + buildTypes { + def gitHash = { -> + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-parse', '--short=8', 'HEAD' + standardOutput = stdout + } + return stdout.toString().trim() + } + + release { + minifyEnabled true + shrinkResources true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + + buildConfigField("String", "GIT_HASH", "\"$gitHash\"") + buildConfigField("String", "DATABASE_QUOTATIONS", "\"quotations.db.prod\"") + } + debug { + testCoverageEnabled true + buildConfigField("String", "GIT_HASH", "\"$gitHash\"") + buildConfigField("String", "DATABASE_QUOTATIONS", "\"quotations.db.dev\"") + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + } + + flavorDimensions 'Version' + productFlavors { + 'googleplay' { + dimension 'Version' + versionNameSuffix "-googleplay" + signingConfig signingConfigs.googleplay + } + 'googleplayS' { + dimension 'Version' + versionNameSuffix "-googleplay-S" + signingConfig signingConfigs.googleplay + } + 'fdroid' { + dimension 'Version' + versionNameSuffix "-fdroid" + isDefault true + } + 'fdroidS' { + dimension 'Version' + versionNameSuffix "-fdroid-S" + } + } + + sourceSets { + androidTest { + assets.srcDirs += files("$projectDir/schemas".toString()) + } + fdroid { + assets.srcDirs = ['src/main/assets'] + java.srcDirs = ['src/main/java', 'src/fdroid/java'] + } + fdroidS { + assets.srcDirs = ['src/main/assets'] + java.srcDirs = ['src/main/java', 'src/fdroid/java'] + } + googleplay { + assets.srcDirs = ['src/main/assets'] + java.srcDirs = ['src/main/java'] + } + googleplayS { + assets.srcDirs = ['src/main/assets'] + java.srcDirs = ['src/main/java'] + } + } + + testOptions { + // will make tests run very slowly on the emulator/device + affects coverage # + // execution 'ANDROIDX_TEST_ORCHESTRATOR' + + animationsDisabled true + unitTests { + includeAndroidResources = true + returnDefaultValues = true + all { + maxHeapSize = "1024m" + jacoco { + includeNoLocationClasses = true + excludes = ['jdk.internal.*'] + } + } + } + } + + buildFeatures { + viewBinding = true + } +} + +dependencies { + androidTestImplementation "androidx.arch.core:core-testing:2.1.0" + androidTestImplementation 'androidx.room:room-testing:2.3.0' + androidTestImplementation 'androidx.test:core:1.4.0-beta01' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test:rules:1.3.0' + androidTestImplementation 'androidx.test:runner:1.3.0' + androidTestImplementation 'io.mockk:mockk-android:1.11.0' + + annotationProcessor 'androidx.room:room-compiler:2.3.0' + + debugImplementation 'androidx.fragment:fragment-testing:1.3.4' + debugImplementation 'androidx.test:core:1.4.0-beta01' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7' + + implementation 'androidx.activity:activity:1.2.3' + implementation 'androidx.fragment:fragment:1.3.4' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.core:core-ktx:1.5.0' + fdroidSImplementation 'androidx.core:core-ktx:1.6.0-beta02' + googleplaySImplementation 'androidx.core:core-ktx:1.6.0-beta02' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1' + implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' + implementation 'androidx.multidex:multidex:2.0.1' + implementation 'androidx.room:room-guava:2.3.0' + implementation 'androidx.room:room-runtime:2.3.0' + implementation 'androidx.room:room-rxjava2:2.3.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0' + implementation 'com.jakewharton.timber:timber:4.7.1' + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' + implementation 'io.reactivex.rxjava2:rxjava:2.2.21' + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.10' + + implementation project(path: ':cloudLib') + implementation project(path: ':utilsLib') + + testImplementation 'androidx.arch.core:core-testing:2.1.0' + testImplementation 'androidx.room:room-testing:2.3.0' + testImplementation 'androidx.test:core-ktx:1.3.0' + testImplementation 'androidx.test.ext:junit:1.1.2' + testImplementation 'androidx.test:rules:1.3.0' + testImplementation 'com.google.guava:guava:30.1.1-jre' + testImplementation 'io.mockk:mockk:1.11.0' + testImplementation 'junit:junit:4.13.2' + testImplementation 'org.robolectric:robolectric:4.5.1' +} + +repositories { + mavenCentral() +} From 1e6de7eb349b9e44ad019cbfc12224f1a3a41255 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 13 Jun 2021 00:49:41 +0200 Subject: [PATCH 2/2] Support '{' in extra line in parse_androidmanifests If the flavour group starts in a separate line don't count it as a second group. Closes: #899 --- MANIFEST.in | 1 + fdroidserver/common.py | 13 +++- tests/common.TestCase | 13 ++++ .../com.jens.automation2/build.gradle | 77 +++++++++++++++++++ 4 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 tests/source-files/com.jens.automation2/build.gradle diff --git a/MANIFEST.in b/MANIFEST.in index 19d3c346..2d4fe372 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -729,6 +729,7 @@ include tests/source-files/com.integreight.onesheeld/pullToRefreshlibrary/src/ma include tests/source-files/com.integreight.onesheeld/quickReturnHeader/build.gradle include tests/source-files/com.integreight.onesheeld/quickReturnHeader/src/main/AndroidManifest.xml include tests/source-files/com.integreight.onesheeld/settings.gradle +include tests/source-files/com.jens.automation2/build.gradle include tests/source-files/com.kunzisoft.testcase/build.gradle include tests/source-files/com.nextcloud.client/build.gradle include tests/source-files/com.nextcloud.client.dev/src/generic/fastlane/metadata/android/en-US/full_description.txt diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 1c2ddf1d..55595798 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1649,7 +1649,7 @@ def parse_androidmanifests(paths, app): temp_version_name = matches.group(2) if inside_flavour_group > 0: - if inside_required_flavour > 0: + if inside_required_flavour > 1: matches = psearch_g(line) if matches: s = matches.group(2) @@ -1678,14 +1678,19 @@ def parse_androidmanifests(paths, app): if matches: vercode = matches.group(1) + if inside_required_flavour > 0: if '{' in line: inside_required_flavour += 1 if '}' in line: inside_required_flavour -= 1 + if inside_required_flavour == 1: + inside_required_flavour -= 1 else: - if flavour and re.match( - r'.*[\'"\s]{flavour}[\'"\s].*'.format(flavour=flavour), line): - inside_required_flavour = 1 + if flavour: + if re.match(r'.*[\'"\s]{flavour}[\'"\s].*\{{.*'.format(flavour=flavour), line): + inside_required_flavour = 2 + elif re.match(r'.*[\'"\s]{flavour}[\'"\s].*'.format(flavour=flavour), line): + inside_required_flavour = 1 if '{' in line: inside_flavour_group += 1 diff --git a/tests/common.TestCase b/tests/common.TestCase index 0f567ad3..38e7dd9b 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -1248,6 +1248,19 @@ class CommonTest(unittest.TestCase): self.assertEqual(('2.5.2-fdroid', '73', 'com.github.jameshnsears.quoteunquote'), fdroidserver.common.parse_androidmanifests(paths, app)) + app = fdroidserver.metadata.App() + build = fdroidserver.metadata.Build() + build.gradle = ['fdroidFlavor'] + app['Builds'] = [build] + app.id = 'com.jens.automation2' + paths = [ + os.path.join('source-files', 'com.jens.automation2', 'build.gradle'), + ] + for path in paths: + self.assertTrue(os.path.isfile(path)) + self.assertEqual(('1.6.34-fdroid', '105', 'com.jens.automation2'), + fdroidserver.common.parse_androidmanifests(paths, app)) + def test_get_all_gradle_and_manifests(self): """Test whether the function works with relative and absolute paths""" a = fdroidserver.common.get_all_gradle_and_manifests(Path('source-files/cn.wildfirechat.chat')) diff --git a/tests/source-files/com.jens.automation2/build.gradle b/tests/source-files/com.jens.automation2/build.gradle new file mode 100644 index 00000000..1ed6b0cf --- /dev/null +++ b/tests/source-files/com.jens.automation2/build.gradle @@ -0,0 +1,77 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 29 + + defaultConfig { + applicationId "com.jens.automation2" + minSdkVersion 16 + compileSdkVersion 29 + buildToolsVersion '29.0.2' + useLibrary 'org.apache.http.legacy' + versionCode 105 + versionName "1.6.34" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + lintOptions { + checkReleaseBuilds false + abortOnError false + } + + flavorDimensions "version" + + productFlavors + { + googlePlayFlavor + { + dimension "version" +// applicationIdSuffix ".googlePlay" + versionNameSuffix "-googlePlay" + targetSdkVersion 29 + } + + fdroidFlavor + { + dimension "version" +// applicationIdSuffix ".fdroid" + versionNameSuffix "-fdroid" + targetSdkVersion 28 + } + + apkFlavor + { + dimension "version" +// applicationIdSuffix ".apk" + versionNameSuffix "-apk" + targetSdkVersion 28 + } + } +} + +dependencies { + + + + implementation 'com.linkedin.dexmaker:dexmaker:2.25.0' + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +}