Skip to content

Commit

Permalink
Merge pull request #8 from 2BAB/dev
Browse files Browse the repository at this point in the history
0.8.0: support InternalArtifactType & configuration cahce
  • Loading branch information
2BAB committed Oct 7, 2022
2 parents cdc783c + 7c1cb04 commit cb4b61c
Show file tree
Hide file tree
Showing 19 changed files with 352 additions and 197 deletions.
32 changes: 18 additions & 14 deletions README.md
Expand Up @@ -20,7 +20,7 @@ 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.2.2")
implementation("me.2bab:polyfill:0.7.0") <--
implementation("me.2bab:polyfill:0.8.0") <--
}
```

Expand Down Expand Up @@ -61,21 +61,25 @@ androidExtension.onVariants { variant ->
)
}

...

...
class PreUpdateManifestsTaskAction(
private val buildDir: File,
private val id: String
buildDir: File,
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 }))
override fun onExecute(artifact: Provider<List<RegularFile>>) {
artifact.get().let { files ->
files.forEach {
val manifestFile = it.asFile
// Check per manifest input and filter whatever you want, remove broken pieces, etc.
// val updatedContent = manifestFile.readText().replace("abc", "def")
// manifestFile.writeText(updatedContent)
}
}
}

}
```

Expand All @@ -92,17 +96,16 @@ All supported Artifacts are listed below:
| ALL_RESOURCES |`ListProvider<Directory>`| To retrieve all `/res` directories that will paticipate merge process. |
| ALL_JAVA_RES |`ListProvider<RegularFile>`| To retrieve all Java Resources that will paticipate merge process. |

In addition, `Artifact.Single<FILE_TYPE>``Artifact.Multiple<FILE_TYPE>` and their implementations such as `InternalArtifactType` are supported by `get(...)/getAll(...)`. You can access more internal Artifacts of AGP through them.

4. In addition, if aforementioned API sets are not satisfied for your requirement, a public data pipeline mechanism with a bunch of variant tools that provided by Polyfill are opening to customized Artifacts registry.(PR is welcome as well!)
4. If aforementioned API sets are not satisfied for your requirement, a public data pipeline mechanism with a bunch of variant tools that provided by Polyfill are opening to customized Artifacts registry.(PR is welcome as well!)

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


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

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


## Why Polyfill?
Expand Down Expand Up @@ -135,6 +138,7 @@ Polyfill is only supported & tested on latest **2** Minor versions of Android Gr

| AGP Version | Latest Support Version |
|:-------------:|:--------------------------------:|
| 7.2.x / 7.1.x | 0.8.0 |
| 7.2.x / 7.1.x | 0.7.0 |
| 7.1.x | 0.6.2 |
| 7.0.x | 0.4.1 |
Expand Down
28 changes: 17 additions & 11 deletions README_zh.md
Expand Up @@ -20,7 +20,7 @@ Polyfill 是一个第三方的**工件仓库**,服务于编写 Android 构建
``` kotlin
dependencies {
compileOnly("com.android.tools.build:gradle:7.2.2")
implementation("me.2bab:polyfill:0.7.0") <--
implementation("me.2bab:polyfill:0.8.0") <--
}
```

Expand Down Expand Up @@ -62,21 +62,25 @@ androidExtension.onVariants { variant ->
)
}

...

...
class PreUpdateManifestsTaskAction(
private val buildDir: File,
private val id: String
buildDir: File,
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 }))
override fun onExecute(artifact: Provider<List<RegularFile>>) {
artifact.get().let { files ->
files.forEach {
val manifestFile = it.asFile
// Check per manifest input and filter whatever you want, remove broken pieces, etc.
// val updatedContent = manifestFile.readText().replace("abc", "def")
// manifestFile.writeText(updatedContent)
}
}
}

}
```

Expand All @@ -94,7 +98,9 @@ class PreUpdateManifestsTaskAction(
| ALL_RESOURCES |`ListProvider<Directory>`| To retrieve all `/res` directories that will paticipate merge process. |
| ALL_JAVA_RES |`ListProvider<RegularFile>`| To retrieve all Java Resources that will paticipate merge process. |

4. 另外,如果上述 API 集无法满足你的需求,Polyfill 提供了其底层的数据管道机制以及获取数据的便捷工具,方便注册自定义的工件(同样欢迎直接提交 PR)。
另外 `Artifact.Single<FILE_TYPE>``Artifact.Multiple<FILE_TYPE>` 和它们的实现类例如 `InternalArtifactType` 均被 `get(...)/getAll(...)` 支持,通过它们你可以获取更多 AGP 内部的 Artifacts.

4. 如果上述 API 集无法满足你的需求,Polyfill 提供了其底层的数据管道机制以及获取数据的便捷工具,方便注册自定义的工件(同样欢迎直接提交 PR)。

``` Kotlin
project.extensions.getByType<PolyfillExtension>()
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Expand Up @@ -14,5 +14,5 @@ dependencies {
implementation(kotlin("stdlib"))

// Github Release
implementation("com.github.breadmoirai:github-release:2.2.12")
implementation("com.github.breadmoirai:github-release:2.4.1")
}
Expand Up @@ -12,7 +12,7 @@ object BuildConfig {
}

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

val polyfillSourceCompatibilityVersion = JavaVersion.VERSION_1_8
val polyfillTargetCompatibilityVersion = JavaVersion.VERSION_1_8
Expand Down
Expand Up @@ -6,17 +6,6 @@ import me.xx2bab.polyfill.buildscript.BuildConfig.Versions
import java.util.*

val taskName = "releaseArtifactsToGithub"
val artifacts: DirectoryProperty = project.objects.directoryProperty()
artifacts.set(Path.getAggregatedJarDirectory(project))

// Temporary workaround for directory is not recognized by ReleaseAssets
gradle.taskGraph.whenReady {
beforeTask {
if (this is GithubReleaseTask) {
this.setReleaseAssets(Path.getAggregatedJarDirectory(project).listFiles())
}
}
}

val tokenFromEnv: String? = System.getenv("GH_DEV_TOKEN")
val token: String = if (!tokenFromEnv.isNullOrBlank()) {
Expand All @@ -33,11 +22,10 @@ val repo = "polyfill"
val tagBranch = "master"
val version = Versions.polyfillDevVersion
val releaseNotes = ""
createGithubReleaseTaskInternal(artifacts, token, repo, tagBranch, version, releaseNotes)
createGithubReleaseTaskInternal(token, repo, tagBranch, version, releaseNotes)


fun createGithubReleaseTaskInternal(
artifacts: DirectoryProperty,
token: String,
repo: String,
tagBranch: String,
Expand All @@ -46,20 +34,21 @@ fun createGithubReleaseTaskInternal(
): TaskProvider<GithubReleaseTask> {
// val id = version.replace(".", "")
return project.tasks.register<GithubReleaseTask>("releaseArtifactsToGithub") {
setAuthorization("Token $token")
setOwner("2bab")
setRepo(repo)
setTagName(version)
setTargetCommitish(tagBranch)
setReleaseName("v${version}")
setBody(releaseNotes)
setDraft(false)
setPrerelease(false)
setReleaseAssets(artifacts)
setOverwrite(true)
setAllowUploadToExisting(true)
setApiEndpoint("https://api.github.com")
setDryRun(false)
authorization.set("Token $token")
owner.set("2bab")
this.repo.set(repo)
tagName.set(version)
targetCommitish.set(tagBranch)
releaseName.set("v${version}")
body.set(releaseNotes)
draft.set(false)
prerelease.set(false)
overwrite.set(true)
allowUploadToExisting.set(true)
apiEndpoint.set("https://api.github.com")
dryRun.set(false)
generateReleaseNotes.set(false)
releaseAssets.from(fileTree(Path.getAggregatedJarDirectory(project)))
}
}

1 change: 0 additions & 1 deletion deps.versions.toml
Expand Up @@ -10,7 +10,6 @@ agpNextBetaVer = "7.3.0-beta01"

# 30.2.0-beta03
androidToolVer = "30.2.0"

mockitoVer = "3.9.0"

[libraries]
Expand Down
Expand Up @@ -167,5 +167,12 @@ class SampleProjectTest {
assertThat(out.readText(), StringContains("android-lib/build/intermediates/library_java_res/debug/res.jar"))
}

@ParameterizedTest
@MethodSource("agpVerProvider")
fun javaResourceMergePreHookConfigureAction_GetSuccessfully(agpVer: String) {
val out =
File("./build/test-app-for-$agpVer/${testProjectJsonOutputPath}/all-java-res-by-getAllInputJavaResForDebug.json")
assertThat("all-java-res-by-getAllInputJavaResForDebug.json does not exist", out.exists())
}

}

0 comments on commit cb4b61c

Please sign in to comment.