Skip to content

Commit

Permalink
Merge pull request #7 from 2BAB/dev
Browse files Browse the repository at this point in the history
refactor: replace update-task by update-taskaction
  • Loading branch information
2BAB committed Aug 14, 2022
2 parents ffd96c1 + b838b13 commit cdc783c
Show file tree
Hide file tree
Showing 43 changed files with 1,072 additions and 833 deletions.
26 changes: 21 additions & 5 deletions .github/workflows/ci.yml
Expand Up @@ -65,14 +65,10 @@ jobs:
- run: |
./gradlew test
functional-tests:
name: Functional tests
name: Functional Tests
runs-on: ubuntu-latest
env:
JAVA_TOOL_OPTIONS: -Xmx4g
AGP_VERSION: ${{ matrix.agp-version }}
strategy:
matrix:
agp-version: [ 7.1.2, 7.2.0-beta04 ]

steps:
- uses: actions/checkout@v2
Expand All @@ -89,5 +85,25 @@ jobs:
key: ${{ runner.os }}-${{ github.job }}-${{ matrix.agp-version }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-${{ github.job }}-${{ matrix.agp-version }}-
- name: Prepare environment
env:
SIGNING_SECRET_KEY_CONTENT: ${{ secrets.SIGNING_SECRET_KEY_CONTENT }}
SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}
run: |
git fetch --unshallow
sudo bash -c "echo '$SIGNING_SECRET_KEY_CONTENT' | base64 -d > '$SIGNING_SECRET_KEY_RING_FILE'"
- name: Build & Release all Polyfill libraries to MavenLocal
run: chmod +x ./publish_to_local.sh | ./publish_to_local.sh
env:
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}
SIGNING_SECRET_KEY_CONTENT: ${{ secrets.SIGNING_SECRET_KEY_CONTENT }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GH_DEV_TOKEN: ${{ secrets.GH_DEV_TOKEN }}

- run: |
./gradlew functionalTest
51 changes: 26 additions & 25 deletions README.md
Expand Up @@ -19,8 +19,8 @@ If you are not familiar with new Artifact/Variant API of AGP (since 7.0), please

``` kotlin
dependencies {
compileOnly("com.android.tools.build:gradle:7.1.2")
implementation("me.2bab:polyfill:0.6.2") <--
compileOnly("com.android.tools.build:gradle:7.2.2")
implementation("me.2bab:polyfill:0.7.0") <--
}
```

Expand All @@ -37,7 +37,7 @@ class TestPlugin : Plugin<Project> {
}
```

3. Config your TaskProvider with the help of Polyfill's `variant.artifactsPolyfill.*`, which has similar API style with `variant.artifacts` one of AGP:
3. Config your `TaskProvider` (for `get/getAll()`) or `PolyfillAction`(for `use()` as well as `get/getAll()`) with the help of Polyfill's `variant.artifactsPolyfill.*` AIs, which has similar style with `variant.artifacts` ones of AGP:

``` kotlin
val androidExtension = project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java)
Expand All @@ -54,25 +54,27 @@ androidExtension.onVariants { variant ->
...

// use()
val preHookManifestTask1 = project.tasks.register<PreUpdateManifestsTask>(
"preUpdate${variant.name.capitalize()}Manifest1"
)
variant.artifactsPolyfill.use( <--
taskProvider = preHookManifestTask1,
wiredWith = TestPlugin.PreUpdateManifestsTask::beforeMergeInputs,
val preHookManifestTaskAction1 = PreUpdateManifestsTaskAction(buildDir, id = "preHookManifestTaskAction1")
variant.artifactsPolyfill.use(
action = preHookManifestTaskAction1,
toInPlaceUpdate = PolyfilledMultipleArtifact.ALL_MANIFESTS
)
}

...

abstract class PreUpdateManifestsTask : DefaultTask() {
@get:InputFiles
abstract val beforeMergeInputs: ListProperty<RegularFile> <--

@TaskAction
fun beforeMerge() {
beforeMergeInputs.get().let { files -> ...}
class PreUpdateManifestsTaskAction(
private val buildDir: File,
private val id: String
) : PolyfillAction<List<RegularFile>> {
override fun onTaskConfigure(task: Task) {}

override fun onExecute(beforeMergeInputs: Provider<List<RegularFile>>) {
val manifestPathsOutput = TestPlugin.getOutputFile(buildDir, "all-manifests-by-${id}.json")
manifestPathsOutput.createNewFile()
beforeMergeInputs.get().let { files ->
manifestPathsOutput.writeText(JSON.toJSONString(files.map { it.asFile.absolutePath }))
}
}
}
```
Expand All @@ -95,11 +97,11 @@ All supported Artifacts are listed below:

``` Kotlin
project.extensions.getByType<PolyfillExtension>()
.registerPincerTaskConfig(DUMMY_SINGLE_ARTIFACT, DummySingleArtifactImpl::class)
.registerTaskExtensionConfig(DUMMY_SINGLE_ARTIFACT, DummySingleArtifactImpl::class)
```


Check more in `./test-plugin` and `./polyfill/src/functionalTest`.
Check more in `./polyfill-test-plugin` and `./polyfill/src/functionalTest`.



Expand Down Expand Up @@ -131,13 +133,12 @@ Polyfill is only supported & tested on latest **2** Minor versions of Android Gr

**Changelog** can be found from [Github Releases](https://github.com/2BAB/Polyfill/releases).

| AGP Version | Latest Support Version |
|:-----------:|:----------------------:|
| 7.1.x | 0.5.0 |
| 7.0.x | 0.4.1 |
| 4.2.0 | 0.3.1 (Migrated to MavenCentral) |

(The project currently compiles with the latest version of AGP 7.0, and compiles and tests against the both AGP 7.0 and 7.1 on CI.)
| AGP Version | Latest Support Version |
|:-------------:|:--------------------------------:|
| 7.2.x / 7.1.x | 0.7.0 |
| 7.1.x | 0.6.2 |
| 7.0.x | 0.4.1 |
| 4.2.0 | 0.3.1 (Migrated to MavenCentral) |


## Git Commit Check
Expand Down
55 changes: 28 additions & 27 deletions README_zh.md
Expand Up @@ -15,12 +15,12 @@ Polyfill 是一个第三方的**工件仓库**,服务于编写 Android 构建

## 快速上手

1. 添加 Polyfill 至你的插件工程(独立的插件工程或者 `buildSrc`):
1. 添加 Polyfill 至你的 Gradle 插件工程(独立的插件工程或者 `buildSrc`):

``` kotlin
dependencies {
compileOnly("com.android.tools.build:gradle:7.1.2")
implementation("me.2bab:polyfill:0.6.2") <--
compileOnly("com.android.tools.build:gradle:7.2.2")
implementation("me.2bab:polyfill:0.7.0") <--
}
```

Expand All @@ -38,7 +38,7 @@ class TestPlugin : Plugin<Project> {
}
```

3. 借助 Polyfill 的 `variant.artifactsPolyfill.*` 配置你的 `TaskProvider`,其 API 风格与 AGP 的 `variant.artifacts` 相近:
3. 借助 Polyfill 的 `variant.artifactsPolyfill.*` 相关 API 配置你的 `TaskProvider`(仅获取 Artifact 时) 或 `PolyfillAction`(需要修改 Artifact 时),其风格与 AGP 的 `variant.artifacts` 相近:

``` kotlin
val androidExtension = project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java)
Expand All @@ -55,25 +55,27 @@ androidExtension.onVariants { variant ->
...

// use()
val preHookManifestTask1 = project.tasks.register<PreUpdateManifestsTask>(
"preUpdate${variant.name.capitalize()}Manifest1"
)
variant.artifactsPolyfill.use( <--
taskProvider = preHookManifestTask1,
wiredWith = TestPlugin.PreUpdateManifestsTask::beforeMergeInputs,
val preHookManifestTaskAction1 = PreUpdateManifestsTaskAction(buildDir, id = "preHookManifestTaskAction1")
variant.artifactsPolyfill.use(
action = preHookManifestTaskAction1,
toInPlaceUpdate = PolyfilledMultipleArtifact.ALL_MANIFESTS
)
}

...

abstract class PreUpdateManifestsTask : DefaultTask() {
@get:InputFiles
abstract val beforeMergeInputs: ListProperty<RegularFile> <--

@TaskAction
fun beforeMerge() {
beforeMergeInputs.get().let { files -> ...}
class PreUpdateManifestsTaskAction(
private val buildDir: File,
private val id: String
) : PolyfillAction<List<RegularFile>> {
override fun onTaskConfigure(task: Task) {}

override fun onExecute(beforeMergeInputs: Provider<List<RegularFile>>) {
val manifestPathsOutput = TestPlugin.getOutputFile(buildDir, "all-manifests-by-${id}.json")
manifestPathsOutput.createNewFile()
beforeMergeInputs.get().let { files ->
manifestPathsOutput.writeText(JSON.toJSONString(files.map { it.asFile.absolutePath }))
}
}
}
```
Expand All @@ -96,10 +98,10 @@ abstract class PreUpdateManifestsTask : DefaultTask() {

``` Kotlin
project.extensions.getByType<PolyfillExtension>()
.registerPincerTaskConfig(DUMMY_SINGLE_ARTIFACT, DummySingleArtifactImpl::class)
.registerTaskExtensionConfig(DUMMY_SINGLE_ARTIFACT, DummySingleArtifactImpl::class)
```

更多信息请查看 `./test-plugin``./polyfill/src/functionalTest`.
更多信息请查看 `./polyfill-test-plugin``./polyfill/src/functionalTest`.


## 为什么需要 Polyfill?
Expand Down Expand Up @@ -129,15 +131,14 @@ project.extensions.getByType<PolyfillExtension>()

## 兼容说明

Polyfill 只支持并在最新的两个 Android Gradle Plugin 版本进行测试。

| AGP Version | Latest Support Version |
|:-----------:|:----------------------:|
| 7.1.x | 0.5.0 |
| 7.0.x | 0.4.1 |
| 4.2.0 | 0.3.1 (MavenCentral) |
Polyfill 只支持并在最新的两个 Android Gradle Plugin (minor) 版本进行测试。

(目前本工程基于 AGP 7.0 的最新版本进行开发,在 CI 环境下还会同时编译&测试 7.0/7.1 版本的兼容性)
| AGP Version | Latest Support Version |
|:-------------:|:--------------------------------:|
| 7.2.x / 7.1.x | 0.7.0 |
| 7.1.x | 0.6.2 |
| 7.0.x | 0.4.1 |
| 4.2.0 | 0.3.1 (Migrated to MavenCentral) |


## Git Commit Check
Expand Down
Expand Up @@ -12,7 +12,7 @@ object BuildConfig {
}

object Versions {
const val polyfillDevVersion = "0.6.2"
const val polyfillDevVersion = "0.7.0"

val polyfillSourceCompatibilityVersion = JavaVersion.VERSION_1_8
val polyfillTargetCompatibilityVersion = JavaVersion.VERSION_1_8
Expand Down
19 changes: 15 additions & 4 deletions deps.versions.toml
@@ -1,21 +1,32 @@
[versions]
kotlinVer = "1.6.10"
# 7.2.0-beta03
agpVer = "7.1.2"
kotlinVer = "1.6.21"
buildConfigVer = "3.0.3"

agpVer = "7.2.2"
agpPatchIgnoredVer = "7.2.0" # To be used by backport version matching
agpBackportVer = "7.1.3"
agpBackportPatchIgnoredVer = "7.1.0" # To be used by backport version matching, e.g. apply backport patches when (7.1.0 <= ver < 7.2.0)
agpNextBetaVer = "7.3.0-beta01"

# 30.2.0-beta03
androidToolVer = "30.1.2"
androidToolVer = "30.2.0"

mockitoVer = "3.9.0"

[libraries]
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agpVer" }
android-gradle-backport = { module = "com.android.tools.build:gradle", version.ref = "agpBackportVer" }
android-tools-sdkcommon = { module = "com.android.tools:sdk-common", version.ref = "androidToolVer" }
android-tools-common = { module = "com.android.tools:common", version.ref = "androidToolVer" }
android-tools-sdklib = { module = "com.android.tools:sdklib", version.ref = "androidToolVer" }
kotlin-std = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlinVer" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlinVer" }
kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.3.2" }
kotlin-coroutine = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version = "1.6.0" }
guava = { module = "com.google.guava:guava", version = "30.1.1-jre" }
fastJson = { module = "com.alibaba:fastjson", version = "1.2.73" }
zip4j = { module = "net.lingala.zip4j:zip4j", version = "2.6.2" }
hamcrest = { module = "org.hamcrest:hamcrest-library", version = "2.2" }
junit = { module = "junit:junit", version = "4.12" }
mockito = { module = "org.mockito:mockito-core", version.ref = "mockitoVer" }
mockitoInline = { module = "org.mockito:mockito-inline", version.ref = "mockitoVer" }
Expand Down
42 changes: 42 additions & 0 deletions functional-test/build.gradle.kts
@@ -0,0 +1,42 @@
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
}

group = "me.2bab"

java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
implementation(deps.kotlin.std)
}

testing {
suites {
val functionalTest by registering(JvmTestSuite::class) {
useJUnitJupiter()
testType.set(TestSuiteType.FUNCTIONAL_TEST)
dependencies {
implementation(deps.hamcrest)
implementation("dev.gradleplugins:gradle-test-kit:7.4.1")
implementation(deps.kotlin.coroutine)
implementation(deps.kotlin.serialization)
implementation(deps.fastJson)
}
}
}
}

tasks.named("check") {
dependsOn(testing.suites.named("functionalTest"))
}

tasks.withType<Test> {
testLogging {
this.showStandardStreams = true
}
}
@@ -0,0 +1,28 @@
package me.xx2bab.koncat;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class CaseInsensitiveSubstringMatcher extends TypeSafeMatcher<String> {

private final String subString;

private CaseInsensitiveSubstringMatcher(final String subString) {
this.subString = subString;
}

@Override
protected boolean matchesSafely(final String actualString) {
return actualString.toLowerCase().contains(this.subString.toLowerCase());
}

@Override
public void describeTo(final Description description) {
description.appendText("containing substring \"" + this.subString + "\"");
}

public static Matcher<String> containsIgnoringCase(final String subString) {
return new CaseInsensitiveSubstringMatcher(subString);
}
}

0 comments on commit cdc783c

Please sign in to comment.