From ab26f8bf5e7c85c3ad50408d7fec57ddb605fed5 Mon Sep 17 00:00:00 2001 From: 2BAB Date: Sun, 20 Mar 2022 09:54:37 +0800 Subject: [PATCH 1/4] refactor: upgrade polyfill to 0.5.0 Use the new API set which is similar to AGP Variant APIs --- deps.versions.toml | 8 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- seal/plugin/build.gradle.kts | 2 +- .../me/xx2bab/seal/ManifestBeforeMergeTask.kt | 4 +- .../main/kotlin/me/xx2bab/seal/SealPlugin.kt | 45 ++++++++++--------- .../main/kotlin/me/xx2bab/seal/StringExt.kt | 7 --- test-app/build.gradle.kts | 5 --- test-library/build.gradle.kts | 2 +- 8 files changed, 33 insertions(+), 42 deletions(-) delete mode 100644 seal/plugin/src/main/kotlin/me/xx2bab/seal/StringExt.kt diff --git a/deps.versions.toml b/deps.versions.toml index 6e13536..40216e3 100644 --- a/deps.versions.toml +++ b/deps.versions.toml @@ -1,7 +1,7 @@ [versions] -kotlinVer = "1.5.31" -agpVer = "7.0.3" -polyfillVer = "0.4.0" +kotlinVer = "1.6.10" +agpVer = "7.1.2" +polyfillVer = "0.5.0.2-SNAPSHOT" mockitoVer = "3.9.0" [libraries] @@ -9,7 +9,7 @@ android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref kotlin-std = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlinVer" } kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core-jvm", version = "1.3.1" } polyfill-main = { module = "me.2bab:polyfill", version.ref = "polyfillVer" } -polyfill-manifest = { module = "me.2bab:polyfill-manifest", version.ref = "polyfillVer" } +polyfill-manifest = { module = "me.2bab:android-manifest-parser", version.ref = "polyfillVer" } fastJson = { module = "com.alibaba:fastjson", version = "1.2.73" } zip4j = { module = "net.lingala.zip4j:zip4j", version = "2.6.2" } junit = { module = "junit:junit", version = "4.12" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 54e9a60..4605298 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists \ No newline at end of file diff --git a/seal/plugin/build.gradle.kts b/seal/plugin/build.gradle.kts index 3a21f73..d8b548e 100644 --- a/seal/plugin/build.gradle.kts +++ b/seal/plugin/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("jvm") + `kotlin-dsl` kotlin("plugin.serialization") id("java-gradle-plugin") `github-release` diff --git a/seal/plugin/src/main/kotlin/me/xx2bab/seal/ManifestBeforeMergeTask.kt b/seal/plugin/src/main/kotlin/me/xx2bab/seal/ManifestBeforeMergeTask.kt index 40a772e..9785ac2 100644 --- a/seal/plugin/src/main/kotlin/me/xx2bab/seal/ManifestBeforeMergeTask.kt +++ b/seal/plugin/src/main/kotlin/me/xx2bab/seal/ManifestBeforeMergeTask.kt @@ -6,6 +6,8 @@ import me.xx2bab.seal.dom.PreciseProcessor import org.gradle.api.DefaultTask import org.gradle.api.artifacts.ArtifactCollection import org.gradle.api.file.FileSystemLocation +import org.gradle.api.file.RegularFile +import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.api.provider.SetProperty @@ -17,7 +19,7 @@ abstract class ManifestBeforeMergeTask : DefaultTask() { abstract val rules: SetProperty @get:InputFiles - abstract val beforeMergeInputs: SetProperty + abstract val beforeMergeInputs: ListProperty @TaskAction fun beforeMerge() { diff --git a/seal/plugin/src/main/kotlin/me/xx2bab/seal/SealPlugin.kt b/seal/plugin/src/main/kotlin/me/xx2bab/seal/SealPlugin.kt index 7cb9684..3a06e32 100644 --- a/seal/plugin/src/main/kotlin/me/xx2bab/seal/SealPlugin.kt +++ b/seal/plugin/src/main/kotlin/me/xx2bab/seal/SealPlugin.kt @@ -1,44 +1,45 @@ package me.xx2bab.seal -import com.android.build.api.variant.AndroidComponentsExtension -import me.xx2bab.polyfill.ApplicationVariantPolyfill -import me.xx2bab.polyfill.manifest.source.ManifestBeforeMergeAction -import me.xx2bab.polyfill.manifest.source.ManifestMergeInputProvider import com.android.build.api.artifact.SingleArtifact +import com.android.build.api.variant.ApplicationAndroidComponentsExtension import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.register +import me.xx2bab.polyfill.* class SealPlugin : Plugin { override fun apply(project: Project) { - val extension = project.extensions.create("seal", SealExtension::class.java) - val androidExtension = project.extensions.findByType(AndroidComponentsExtension::class.java)!! + project.apply(plugin = "me.2bab.polyfill") + val extension = project.extensions.create("seal") + val androidExtension = + project.extensions.findByType(ApplicationAndroidComponentsExtension::class.java)!! androidExtension.onVariants { variant -> - val polyfill = ApplicationVariantPolyfill(project, variant) - // Before merge - val preUpdateTask = project.tasks.register( + val preUpdateTask = project.tasks.register( "preUpdate${variant.name.capitalize()}Manifest", - ManifestBeforeMergeTask::class.java ) { - it.rules.set(extension.rules) - it.beforeMergeInputs.set(polyfill.newProvider(ManifestMergeInputProvider::class.java).obtain()) + rules.set(extension.rules) } - val beforeMergeAction = ManifestBeforeMergeAction(preUpdateTask) - polyfill.addAGPTaskAction(beforeMergeAction) + variant.artifactsPolyfill.use( + taskProvider = preUpdateTask, + wiredWith = ManifestBeforeMergeTask::beforeMergeInputs, + toInPlaceUpdate = PolyfilledMultipleArtifact.ALL_MANIFESTS + ) // After merge - val postUpdateTask = project.tasks.register( - "postUpdate${variant.name.capitalize()}Manifest", - ManifestAfterMergeTask::class.java + val postUpdateTask = project.tasks.register( + "postUpdate${variant.name.capitalize()}Manifest" ) { - it.rules.set(extension.rules) + rules.set(extension.rules) } - variant.artifacts.use(postUpdateTask).wiredWithFiles( - ManifestAfterMergeTask::mergedManifest, - ManifestAfterMergeTask::updatedManifest - ).toTransform(SingleArtifact.MERGED_MANIFEST) + variant.artifacts.use(postUpdateTask) + .wiredWithFiles(ManifestAfterMergeTask::mergedManifest, + ManifestAfterMergeTask::updatedManifest) + .toTransform(SingleArtifact.MERGED_MANIFEST) } } diff --git a/seal/plugin/src/main/kotlin/me/xx2bab/seal/StringExt.kt b/seal/plugin/src/main/kotlin/me/xx2bab/seal/StringExt.kt deleted file mode 100644 index be2dd77..0000000 --- a/seal/plugin/src/main/kotlin/me/xx2bab/seal/StringExt.kt +++ /dev/null @@ -1,7 +0,0 @@ -package me.xx2bab.seal - -import java.util.* - -fun String.capitalize() = replaceFirstChar { - if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() -} diff --git a/test-app/build.gradle.kts b/test-app/build.gradle.kts index 0ab98f2..3c325ab 100644 --- a/test-app/build.gradle.kts +++ b/test-app/build.gradle.kts @@ -103,8 +103,3 @@ seal { // .deleteAttr() } -project.tasks.whenTaskAdded { - if (this is com.android.build.gradle.tasks.ProcessMultiApkApplicationManifest) { - println("detected ProcessMultiApkApplicationManifest") - } -} \ No newline at end of file diff --git a/test-library/build.gradle.kts b/test-library/build.gradle.kts index 6a88758..c0c0773 100644 --- a/test-library/build.gradle.kts +++ b/test-library/build.gradle.kts @@ -13,7 +13,7 @@ android { } lint { - isAbortOnError = false +// isAbortOnError = false } sourceSets["main"].java.srcDir("src/main/kotlin") From 2d1b8e4ad5fe1c4469f9463b56e67d584b445bfa Mon Sep 17 00:00:00 2001 From: 2BAB Date: Sun, 20 Mar 2022 09:56:02 +0800 Subject: [PATCH 2/4] release: update CI with new AGP versions Specify the publication explicitly to avoid unnecessary publications --- .github/workflows/ci.yml | 2 +- publish_to_local.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65ab2ea..7972075 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,7 +74,7 @@ jobs: AGP_VERSION: ${{ matrix.agp-version }} strategy: matrix: - agp-version: [ 7.0.3, 7.1.0-beta04 ] + agp-version: [ 7.1.2, 7.2.0-beta04 ] steps: - uses: actions/checkout@v2 diff --git a/publish_to_local.sh b/publish_to_local.sh index 1a7a6c0..d50e1a3 100755 --- a/publish_to_local.sh +++ b/publish_to_local.sh @@ -1 +1 @@ -./gradlew clean :seal:plugin:assemble :seal:plugin:publishToMavenLocal \ No newline at end of file +./gradlew clean :seal:plugin:assemble :seal:plugin:publishSealPluginPublicationToMavenLocal \ No newline at end of file From 65a579a5567c9d9f999533e8a118f947adbb7ddc Mon Sep 17 00:00:00 2001 From: 2BAB Date: Sun, 20 Mar 2022 09:56:16 +0800 Subject: [PATCH 3/4] release: bump the version to 3.2.0 --- seal/buildSrc/src/main/kotlin/BuildConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seal/buildSrc/src/main/kotlin/BuildConfig.kt b/seal/buildSrc/src/main/kotlin/BuildConfig.kt index 6ca8754..1b386e5 100644 --- a/seal/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/seal/buildSrc/src/main/kotlin/BuildConfig.kt @@ -1,7 +1,7 @@ object BuildConfig { object Versions { - const val sealVersion = "3.1.0" + const val sealVersion = "3.2.0" } } \ No newline at end of file From 795f7a0ca6990ba0f51bca9f81de1384f63af470 Mon Sep 17 00:00:00 2001 From: 2BAB Date: Sun, 20 Mar 2022 10:13:39 +0800 Subject: [PATCH 4/4] fix: use the production version of polyfill --- deps.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps.versions.toml b/deps.versions.toml index 40216e3..4d797bb 100644 --- a/deps.versions.toml +++ b/deps.versions.toml @@ -1,7 +1,7 @@ [versions] kotlinVer = "1.6.10" agpVer = "7.1.2" -polyfillVer = "0.5.0.2-SNAPSHOT" +polyfillVer = "0.5.0" mockitoVer = "3.9.0" [libraries]