Skip to content

Commit

Permalink
Merge pull request #14 from 2BAB/dev
Browse files Browse the repository at this point in the history
Release 3.1.0
  • Loading branch information
2BAB authored Nov 28, 2021
2 parents 7318c84 + e190ce0 commit 7b4a832
Show file tree
Hide file tree
Showing 22 changed files with 321 additions and 277 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v1
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 8
distribution: 'zulu'
java-version: '11'
- uses: actions/cache@v2
with:
path: |
Expand All @@ -49,9 +51,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v1
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 8
distribution: 'zulu'
java-version: '11'
- uses: actions/cache@v2
with:
path: |
Expand All @@ -70,14 +74,16 @@ jobs:
AGP_VERSION: ${{ matrix.agp-version }}
strategy:
matrix:
agp-version: [ 4.2.0-rc01, 7.0.0-alpha14 ]
agp-version: [ 7.0.3, 7.1.0-beta04 ]

steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v1
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 8
distribution: 'zulu'
java-version: '11'
- uses: actions/cache@v2
with:
path: |
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ jobs:
- name: Check out
uses: actions/checkout@v2

- name: Set up JDK 1.8
uses: actions/setup-java@v1
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 1.8
distribution: 'zulu'
java-version: '11'

- name: Prepare environment
env:
Expand Down
27 changes: 0 additions & 27 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
buildscript {

val props = java.util.Properties()
file("./seal/buildSrc/src/main/resources/versions.properties").inputStream().use { props.load(it) }

repositories {
google()
mavenCentral()
mavenLocal()
}

dependencies {
classpath(kotlin("gradle-plugin", version = props["kotlinVersion"]?.toString()))
classpath("com.android.tools.build:gradle:${props["agpVersion"]?.toString()}")
classpath("me.2bab:seal:+")
}

}

allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
}
}

task("clean") {
delete(rootProject.buildDir)
}
21 changes: 21 additions & 0 deletions deps.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[versions]
kotlinVer = "1.5.31"
agpVer = "7.0.3"
polyfillVer = "0.4.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" }
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" }
mockito = { module = "org.mockito:mockito-core", version.ref = "mockitoVer" }
mockitoInline = { module = "org.mockito:mockito-inline", version.ref = "mockitoVer" }

[bundles]

[plugins]
4 changes: 2 additions & 2 deletions 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.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
22 changes: 1 addition & 21 deletions seal/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
buildscript {
val props = java.util.Properties()
file("./buildSrc/src/main/resources/versions.properties").inputStream().use { props.load(it) }

repositories {
google()
mavenCentral()
mavenLocal()
}

dependencies {
classpath(kotlin("gradle-plugin", version = props["kotlinVersion"]?.toString()))
}
}

allprojects {
group = "me.2bab"
version = BuildConfig.Versions.sealVersion
repositories {
mavenCentral()
google()
mavenLocal()
}
}
}
25 changes: 1 addition & 24 deletions seal/buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
import java.util.*

object BuildConfig {

val props = Properties()

init {
javaClass.classLoader.getResourceAsStream("versions.properties")
.use { props.load(it) }
}

object Versions {
val sealVersion by lazy { props["sealVersion"].toString() }
}

object Deps {
const val ktStd = "stdlib-jdk8"
val agp by lazy { "com.android.tools.build:gradle:${props["agpVersion"]}" }
const val polyfill = "me.2bab:polyfill:0.2.1"

// Test
const val junit = "junit:junit:4.12"
const val mockito = "org.mockito:mockito-core:3.9.0"
const val mockitoInline = "org.mockito:mockito-inline:3.9.0"

const val fastJson = "com.alibaba:fastjson:1.2.73"
const val zip4j = "net.lingala.zip4j:zip4j:2.6.2"
const val sealVersion = "3.1.0"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ plugins {
idea
}

val defaultAGPVer = BuildConfig.props["agpVersion"].toString()
val defaultAGP = BuildConfig.Deps.agp
val versionCatalog = extensions.getByType<VersionCatalogsExtension>().named("deps")
val defaultAGPVer = versionCatalog.findVersion("agpVer").get().requiredVersion
val defaultAGP = versionCatalog.findDependency("android-gradle-plugin").get()

val fixtureClasspath: Configuration by configurations.creating
tasks.pluginUnderTestMetadata {
Expand Down
3 changes: 0 additions & 3 deletions seal/buildSrc/src/main/resources/versions.properties

This file was deleted.

23 changes: 13 additions & 10 deletions seal/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import BuildConfig.Deps

plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("java-gradle-plugin")
`github-release`
`maven-central-publish`
Expand All @@ -24,15 +23,19 @@ gradlePlugin {
}

dependencies {
implementation(deps.polyfill.main)
implementation(deps.polyfill.manifest)

implementation(gradleApi())
implementation(kotlin(Deps.ktStd))
compileOnly(Deps.agp)
implementation(Deps.polyfill)
implementation(deps.kotlin.std)
implementation(deps.kotlin.serialization)

compileOnly(deps.android.gradle.plugin)

testImplementation(gradleTestKit())
testImplementation(Deps.junit)
testImplementation(Deps.mockito)
testImplementation(Deps.mockitoInline)
testImplementation(Deps.fastJson)
testImplementation(Deps.zip4j)
testImplementation(deps.junit)
testImplementation(deps.mockito)
testImplementation(deps.mockitoInline)
testImplementation(deps.fastJson)
testImplementation(deps.zip4j)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@ import me.xx2bab.seal.dom.PreciseProcessor
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.*

abstract class ManifestAfterMergeTask : DefaultTask() {

@get:Input
@get:Nested
abstract val rules: SetProperty<SealRule>

@get:InputFile
abstract val mergedManifest: RegularFileProperty

// @get:OutputFile
// abstract val updatedManifest: RegularFileProperty
@get:OutputFile
abstract val updatedManifest: RegularFileProperty

@TaskAction
fun afterMerge() {
val extractRules = rules.get().filter { it.hookType == HookType.AFTER_MERGE.name }
val file = mergedManifest.asFile.get()
val inputFile = mergedManifest.asFile.get()
val outputFile = updatedManifest.asFile.get()
val processor: GeneralProcessor = PreciseProcessor(extractRules, project.logger)
processor.process(file, file)
processor.process(inputFile, outputFile)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import me.xx2bab.seal.SealRuleBuilder.HookType
import me.xx2bab.seal.dom.GeneralProcessor
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.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.*

abstract class ManifestBeforeMergeTask : DefaultTask() {

@get:Input
@get:Nested
abstract val rules: SetProperty<SealRule>

@get:InputFiles
Expand Down
5 changes: 1 addition & 4 deletions seal/plugin/src/main/kotlin/me/xx2bab/seal/SealExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ package me.xx2bab.seal
import org.gradle.api.Named
import java.util.concurrent.atomic.AtomicInteger

abstract class SealExtension: Named {
abstract class SealExtension {

val rules = mutableSetOf<SealRule>()
private val idGenerator = AtomicInteger(0)

override fun getName(): String {
return "seal"
}

fun beforeMerge(ruleName: String = ""): SealRuleBuilder {
return SealRuleBuilder(rules,
Expand Down
52 changes: 26 additions & 26 deletions seal/plugin/src/main/kotlin/me/xx2bab/seal/SealPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
package me.xx2bab.seal

import me.xx2bab.polyfill.Polyfill
import me.xx2bab.polyfill.manifest.source.ManifestAfterMergeListener
import me.xx2bab.polyfill.manifest.source.ManifestBeforeMergeListener
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 me.xx2bab.polyfill.manifest.source.ManifestMergeOutputProvider
import com.android.build.api.artifact.SingleArtifact
import org.gradle.api.Plugin
import org.gradle.api.Project

class SealPlugin: Plugin<Project> {
class SealPlugin : Plugin<Project> {

override fun apply(project: Project) {
val polyfill = Polyfill.createApplicationPolyfill(project)
val extension = project.extensions.create("seal", SealExtension::class.java)
val androidExtension = project.extensions.findByType(AndroidComponentsExtension::class.java)!!

polyfill.onVariantProperties { prop ->
// Before
val preUpdateTask = project.tasks.register("preUpdate${prop.name.capitalize()}Manifest",
ManifestBeforeMergeTask::class.java) {
androidExtension.onVariants { variant ->
val polyfill = ApplicationVariantPolyfill(project, variant)

// Before merge
val preUpdateTask = project.tasks.register(
"preUpdate${variant.name.capitalize()}Manifest",
ManifestBeforeMergeTask::class.java
) {
it.rules.set(extension.rules)
it.beforeMergeInputs.set(polyfill.getProvider(prop, ManifestMergeInputProvider::class.java).get())
it.beforeMergeInputs.set(polyfill.newProvider(ManifestMergeInputProvider::class.java).obtain())
}
val beforeMergeListener = ManifestBeforeMergeListener(preUpdateTask)
polyfill.addAGPTaskListener(prop, beforeMergeListener)
val beforeMergeAction = ManifestBeforeMergeAction(preUpdateTask)
polyfill.addAGPTaskAction(beforeMergeAction)

// After
val postUpdateTask = project.tasks.register("postUpdate${prop.name.capitalize()}Manifest",
ManifestAfterMergeTask::class.java) {
// After merge
val postUpdateTask = project.tasks.register(
"postUpdate${variant.name.capitalize()}Manifest",
ManifestAfterMergeTask::class.java
) {
it.rules.set(extension.rules)
it.mergedManifest.set(polyfill.getProvider(prop, ManifestMergeOutputProvider::class.java).get())
}
val afterMergeListener = ManifestAfterMergeListener(postUpdateTask)
polyfill.addAGPTaskListener(prop, afterMergeListener)

// The official API (which is better obviously) is not gonna work on 4.2.0-alpha12,
// we may switch back after API is stable.
/*prop.artifacts.use(manifestUpdater)
.wiredWithFiles(ManifestAfterMergeTask::mergedManifest,
ManifestAfterMergeTask::updatedManifest)
.toTransform(ArtifactType.MERGED_MANIFEST)*/
variant.artifacts.use(postUpdateTask).wiredWithFiles(
ManifestAfterMergeTask::mergedManifest,
ManifestAfterMergeTask::updatedManifest
).toTransform(SingleArtifact.MERGED_MANIFEST)
}
}

Expand Down
Loading

0 comments on commit 7b4a832

Please sign in to comment.