Skip to content

Commit

Permalink
Feat:gradle Plugin Portal (#18)
Browse files Browse the repository at this point in the history
* add AGP 8.1 wrapper

* remove plugin library

* fixed gradle version to 7.6.1:
1. plugin_publish require at least 7.6.1;
2. gradle 4.2 test will failure when gradle upgrade above 8.0;
3. AGP 8.1.1 running ok.

* version 3.5.1
  • Loading branch information
cpacm authored Aug 17, 2023
1 parent c22ca56 commit 56a0231
Show file tree
Hide file tree
Showing 48 changed files with 221 additions and 372 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
- name: Before script
run: |
chmod +x gradlew
chmod +x gradle/publishPluginToMavenLocal.sh
- name: Run Gradle command
run: |
Expand Down
27 changes: 3 additions & 24 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Maven
name: Publish Gradle Portal
on:
release:
types: [ published ]
Expand Down Expand Up @@ -32,26 +32,5 @@ jobs:
./gradlew clean
./gradlew build
# 解码秘钥
- name: Decode
run: |
echo "${{secrets.SIGNING_SECRET_KEY_RING_FILE}}" > ~/.gradle/secring.gpg.b64
base64 -d ~/.gradle/secring.gpg.b64 > ~/.gradle/secring.gpg
- name: Publish library to Sonatype
env:
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: ./gradlew :autotracker-gradle-plugin:growingio-plugin-library:publish -PNEXUS_USERNAME="${NEXUS_USERNAME}" -PNEXUS_PASSWORD="${NEXUS_PASSWORD}" -Psigning.keyId=${{secrets.SIGNING_KEY_ID}} -Psigning.password=${{secrets.SIGNING_PASSWORD}} -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg)

- name: Publish plugin to Sonatype
env:
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: ./gradlew :autotracker-gradle-plugin:publish -PNEXUS_USERNAME="${NEXUS_USERNAME}" -PNEXUS_PASSWORD="${NEXUS_PASSWORD}" -Psigning.keyId=${{secrets.SIGNING_KEY_ID}} -Psigning.password=${{secrets.SIGNING_PASSWORD}} -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg)

- name: Close And Release Package
env:
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: ./gradlew :autotracker-gradle-plugin:tryCloseAndReleaseRepository -PNEXUS_USERNAME="${NEXUS_USERNAME}" -PNEXUS_PASSWORD="${NEXUS_PASSWORD}"
- name: Publish plugin to gradlePortal
run: ./gradlew :autotracker-gradle-plugin:publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }}
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies {
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'

implementation 'com.growingio.android:autotracker-cdp:3.5.0-SNAPSHOT'
implementation 'com.growingio.android:autotracker-cdp:3.5.0'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.growingio.android.plugin.utils
package com.growingio.android.plugin.transform

import com.growingio.android.plugin.util.normalize
import java.io.Closeable
import java.io.File
import java.net.URLClassLoader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.growingio.android.plugin.utils
package com.growingio.android.plugin.transform

import com.growingio.android.plugin.util.asIterable
import java.io.*
import java.util.concurrent.ForkJoinPool
import java.util.concurrent.ForkJoinTask
Expand Down Expand Up @@ -53,9 +54,6 @@ fun Iterator<File>.search(filter: (File) -> Boolean = { true }): Collection<File
@JvmOverloads
fun Array<File>.search(filter: (File) -> Boolean = { true }): Collection<File> = FileSearch(this, filter).execute()


fun <T> Iterator<T>.asIterable(): Iterable<T> = Iterable { this }

fun <T> ForkJoinTask<T>.execute(): T {
val pool = ForkJoinPool()
val result = pool.invoke(this)
Expand Down Expand Up @@ -114,31 +112,4 @@ fun ByteArray.redirect(file: File): Long = this.inputStream().use { it.redirect(
fun ByteArray.redirect(output: OutputStream): Long = this.inputStream().copyTo(output)


val NCPU = Runtime.getRuntime().availableProcessors()

fun normalize(type: String) = if (type.contains('/')) {
type.replace('/', '.')
} else {
type
}

fun String.unNormalize(): String {
return if (this.contains('.')) {
this.replace('.', '/')
} else {
this
}
}


fun String.simpleClass(): String {
return this.split("/").last()
}

fun isAndroidGenerated(className: String): Boolean {
return className.contains("R$") ||
className.contains("R2$") ||
className.contains("R.class") ||
className.contains("R2.class") ||
className.contains("BuildConfig.class")
}
val NCPU = Runtime.getRuntime().availableProcessors()
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")

package com.growingio.android.plugin.transform

import com.android.build.api.transform.Transform
import com.android.build.api.transform.TransformInvocation
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.internal.pipeline.TransformManager
import com.growingio.android.plugin.utils.AbstractKlassPool
import com.growingio.android.plugin.utils.info
import com.growingio.android.plugin.util.info
import org.gradle.api.Project
import java.lang.management.ManagementFactory
import java.lang.management.ThreadMXBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package com.growingio.android.plugin.transform

import com.android.build.api.transform.*
import com.growingio.android.plugin.utils.AbstractKlassPool
import com.growingio.android.plugin.utils.NCPU
import com.growingio.android.plugin.utils.e
import com.growingio.android.plugin.utils.info
import com.growingio.android.plugin.util.e
import com.growingio.android.plugin.util.info
import java.io.File
import java.net.URI
import java.util.concurrent.Executors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.growingio.android.plugin.transform

import com.growingio.android.plugin.utils.KlassPool
import java.io.File

interface AutoTrackerContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.android.build.gradle.AppExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.api.BaseVariant
import com.growingio.android.plugin.utils.*
import com.growingio.android.plugin.util.e
import org.apache.commons.compress.archivers.jar.JarArchiveEntry
import org.apache.commons.compress.archivers.zip.ParallelScatterZipCreator
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
Expand Down
14 changes: 14 additions & 0 deletions autotracker-gradle-plugin/agp-wrapper-81/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id("org.jetbrains.kotlin.jvm")
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
implementation(project(":agp-wrapper"))
implementation(gradleApi())
compileOnly("com.android.tools.build:gradle-api:8.1.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.growingio.android.plugin.util

import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.HasAndroidTest
import com.android.build.api.variant.HasUnitTest
import org.gradle.api.Project

class AndroidComponentsExtensionCompatApi81Impl(
private val project: Project
) : AndroidComponentsExtensionCompat {

override fun onAllVariants(block: (ComponentCompat) -> Unit) {
val actual = project.extensions.getByType(AndroidComponentsExtension::class.java)
actual.onVariants { variant ->
block.invoke(ComponentCompatApi81Impl(variant))

(variant as? HasAndroidTest)?.androidTest?.let { block.invoke(ComponentCompatApi81Impl(it)) }

(variant as? HasUnitTest)?.unitTest?.let { block.invoke(ComponentCompatApi81Impl(it)) }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.growingio.android.plugin.util

import com.android.build.api.instrumentation.AsmClassVisitorFactory
import com.android.build.api.instrumentation.FramesComputationMode
import com.android.build.api.instrumentation.InstrumentationParameters
import com.android.build.api.instrumentation.InstrumentationScope
import com.android.build.api.variant.Component

internal class ComponentCompatApi81Impl(private val component: Component) : ComponentCompat() {

override val name: String
get() = component.name

override fun <ParamT : InstrumentationParameters> transformClassesWith(
classVisitorFactoryImplClass: Class<out AsmClassVisitorFactory<ParamT>>,
scope: InstrumentationScope,
instrumentationParamsConfig: (ParamT) -> Unit
) {
component.instrumentation.transformClassesWith(
classVisitorFactoryImplClass,
scope,
instrumentationParamsConfig
)
}

override fun setAsmFramesComputationMode(mode: FramesComputationMode) {
component.instrumentation.setAsmFramesComputationMode(mode)
}
}
3 changes: 2 additions & 1 deletion autotracker-gradle-plugin/agp-wrapper-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation(project(":agp-wrapper-70"))
implementation(project(":agp-wrapper-71"))
implementation(project(":agp-wrapper-72"))
implementation(project(":agp-wrapper-81"))
implementation(gradleApi())
compileOnly("com.android.tools.build:gradle-api:${rootProject.ext.get("agp_version")}")
compileOnly("com.android.tools.build:gradle-api:${rootProject.extra["agp_version"]}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import org.gradle.api.Project
fun getAndroidComponentsExtension(project: Project): AndroidComponentsExtensionCompat {
val version = SimpleAGPVersion.ANDROID_GRADLE_PLUGIN_VERSION
return when {
version >= SimpleAGPVersion(8, 1) -> {
AndroidComponentsExtensionCompatApi81Impl(project)
}
version >= SimpleAGPVersion(7, 2) -> {
AndroidComponentsExtensionCompatApi72Impl(project)
}
Expand Down
2 changes: 1 addition & 1 deletion autotracker-gradle-plugin/agp-wrapper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ java {

dependencies {
implementation(gradleApi())
compileOnly("com.android.tools.build:gradle-api:${rootProject.ext.get("agp_version")}")
compileOnly("com.android.tools.build:gradle-api:${rootProject.extra["agp_version"]}")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.growingio.android.plugin.util

fun <T> Iterator<T>.asIterable(): Iterable<T> = Iterable { this }

fun String.simpleClass(): String {
return this.split("/").last()
}

fun String.unNormalize(): String {
return if (this.contains('.')) {
this.replace('.', '/')
} else {
this
}
}

fun normalize(type: String) = if (type.contains('/')) {
type.replace('/', '.')
} else {
type
}

fun isAndroidGenerated(className: String): Boolean {
return className.contains("R$") ||
className.contains("R2$") ||
className.contains("R.class") ||
className.contains("R2.class") ||
className.contains("BuildConfig.class")
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.growingio.android.plugin.utils
package com.growingio.android.plugin.util

/**
* <p>
Expand Down
Loading

0 comments on commit 56a0231

Please sign in to comment.