Skip to content

Commit

Permalink
Merge pull request #15 from 2BAB/dev
Browse files Browse the repository at this point in the history
Upgrade Polyfill to 0.5.0 with new `variant.artifactsPolyfill.*` API
  • Loading branch information
2BAB authored Mar 20, 2022
2 parents 1f690fb + 795f7a0 commit f787342
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions deps.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[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"
mockitoVer = "3.9.0"

[libraries]
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agpVer" }
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" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion publish_to_local.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./gradlew clean :seal:plugin:assemble :seal:plugin:publishToMavenLocal
./gradlew clean :seal:plugin:assemble :seal:plugin:publishSealPluginPublicationToMavenLocal
2 changes: 1 addition & 1 deletion seal/buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object BuildConfig {

object Versions {
const val sealVersion = "3.1.0"
const val sealVersion = "3.2.0"
}

}
2 changes: 1 addition & 1 deletion seal/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("jvm")
`kotlin-dsl`
kotlin("plugin.serialization")
id("java-gradle-plugin")
`github-release`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +19,7 @@ abstract class ManifestBeforeMergeTask : DefaultTask() {
abstract val rules: SetProperty<SealRule>

@get:InputFiles
abstract val beforeMergeInputs: SetProperty<FileSystemLocation>
abstract val beforeMergeInputs: ListProperty<RegularFile>

@TaskAction
fun beforeMerge() {
Expand Down
45 changes: 23 additions & 22 deletions seal/plugin/src/main/kotlin/me/xx2bab/seal/SealPlugin.kt
Original file line number Diff line number Diff line change
@@ -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<Project> {

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<SealExtension>("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<ManifestBeforeMergeTask>(
"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<ManifestAfterMergeTask>(
"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)
}
}

Expand Down
7 changes: 0 additions & 7 deletions seal/plugin/src/main/kotlin/me/xx2bab/seal/StringExt.kt

This file was deleted.

5 changes: 0 additions & 5 deletions test-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,3 @@ seal {
// .deleteAttr()

}
project.tasks.whenTaskAdded {
if (this is com.android.build.gradle.tasks.ProcessMultiApkApplicationManifest) {
println("detected ProcessMultiApkApplicationManifest")
}
}
2 changes: 1 addition & 1 deletion test-library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
}

lint {
isAbortOnError = false
// isAbortOnError = false
}

sourceSets["main"].java.srcDir("src/main/kotlin")
Expand Down

0 comments on commit f787342

Please sign in to comment.