Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyJingFish committed Oct 20, 2024
2 parents a8abc74 + 6450cb6 commit 25544fd
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 87 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
plugins {
//必须项 👇 apply 设置为 true 自动为所有module“预”配置debugMode,false则按下边步骤五的方式二
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.2.4" apply true
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.2.5" apply true
}
```
<details>
Expand All @@ -131,7 +131,7 @@
buildscript {
dependencies {
//必须项 👇
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.2.4'
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.2.5'
}
}
// 👇加上这句自动为所有module“预”配置debugMode,不加则按下边步骤五的方式二
Expand Down Expand Up @@ -186,7 +186,7 @@
//必须项 👇
plugins {
...
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.2.4"//最好放在最后一行
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.2.5"//最好放在最后一行
}
```

Expand All @@ -212,18 +212,18 @@ plugins {
dependencies {
//必须项 👇
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.2.4'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.2.5'
//非必须项 👇这个包提供了一些常见的注解切面
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.2.4'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.2.5'
//必须项 👇如果您项目内已经有了这项不用加也可以
implementation 'androidx.appcompat:appcompat:1.3.0' // 至少在1.3.0及以上
//非必须项 👇,如果你想自定义切面需要用到,⚠️支持Java和Kotlin代码写的切面
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.2.4'
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.2.5'
//非必须项 👇,如果你想自定义切面需要用到,⚠️只适用于Java代码写的切面
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.2.4'
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.2.5'
//⚠️上边的 android-aop-ksp 和 android-aop-processor 二选一
}
```
Expand Down
14 changes: 7 additions & 7 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Depend on the plug-in in <code>build.gradle</code> in the <strong>project root d
plugins {
//Required item 👇 apply is set to true to automatically apply debugMode to all modules, if false, follow step 5 below.
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.2.4" apply true
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.2.5" apply true
}
```
<details>
Expand All @@ -128,7 +128,7 @@ Depend on the plug-in in <code>build.gradle</code> in the <strong>project root d
buildscript {
dependencies {
//Required items 👇
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.2.4'
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.2.5'
}
}
//👇Add this sentence to automatically apply debugMode to all modules. If not, follow step 5 below.
Expand Down Expand Up @@ -176,7 +176,7 @@ Depend on the plug-in in <code>build.gradle</code> in the <strong>project root d
//Required items 👇
plugins {
...
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.2.4"
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.2.5"
}
```

Expand Down Expand Up @@ -206,17 +206,17 @@ plugins {
dependencies {
//Required items 👇
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.2.4'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.2.5'
//Optional 👇This package provides some common annotation aspects
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.2.4'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.2.5'
//Required item 👇If you already have this item in your project, you don’t need to add it.
implementation 'androidx.appcompat:appcompat:1.3.0' // At least in 1.3.0 and above
//Optional 👇, if you want to customize aspects, you need to use them, ⚠️supports aspects written in Java and Kotlin code
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.2.4'
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.2.5'
//Optional 👇, if you want to customize aspects, you need to use them, ⚠️only applies to aspects written in Java code
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.2.4'
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.2.5'
//⚠️Choose one of the above android-aop-ksp and android-aop-processor
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,78 +1,37 @@
package com.flyjingfish.android_aop_plugin.plugin

import com.flyjingfish.android_aop_plugin.config.RootBooleanConfig
import org.gradle.api.Plugin
import org.gradle.api.Project

abstract class BasePlugin :Plugin<Project> {
private var reflectInvokeMethod = false
private var reflectInvokeMethodOnlyDebug = false
private var debugMode = false
private var onlyDebug = false
private var isIncremental = true
private var buildConfig = true
private lateinit var pluginConfig: PluginConfig
private fun init(project: Project){
val reflectInvokeMethodStr = project.properties[RootBooleanConfig.REFLECT_INVOKE_METHOD.propertyName]?:"${RootBooleanConfig.REFLECT_INVOKE_METHOD.defaultValue}"
val debugModeStr = project.properties[RootBooleanConfig.DEBUG_MODE.propertyName]?:"${RootBooleanConfig.DEBUG_MODE.defaultValue}"
val onlyModeStr = project.properties[RootBooleanConfig.ONLY_DEBUG.propertyName]?:"${RootBooleanConfig.ONLY_DEBUG.defaultValue}"
val isIncrementalStr = project.properties[RootBooleanConfig.INCREMENTAL.propertyName]?:"${RootBooleanConfig.INCREMENTAL.defaultValue}"
val reflectInvokeMethodDebugStr = project.properties[RootBooleanConfig.REFLECT_INVOKE_METHOD_ONLY_DEBUG.propertyName]?:"${RootBooleanConfig.REFLECT_INVOKE_METHOD_ONLY_DEBUG.defaultValue}"
val buildConfigStr = project.properties[RootBooleanConfig.BUILD_CONFIG.propertyName]?:"${RootBooleanConfig.BUILD_CONFIG.defaultValue}"
debugMode = debugModeStr.toString() == "true"
reflectInvokeMethod = reflectInvokeMethodStr.toString() == "true"
onlyDebug = onlyModeStr.toString() == "true"
isIncremental = isIncrementalStr.toString() == "true"
reflectInvokeMethodOnlyDebug = reflectInvokeMethodDebugStr.toString() == "true"
buildConfig = buildConfigStr.toString() == "true"
pluginConfig = PluginConfig(project)
}

fun isIncremental():Boolean{
return isIncremental
return pluginConfig.isIncremental()
}

override fun apply(project: Project) {
init(project)
}

fun isDebugMode(buildTypeName :String?,variantName :String):Boolean{
return if (debugMode){
if (onlyDebug){
if (buildTypeName != null){
buildTypeName.lowercase() == "debug"
}else{
variantName.lowercase().contains("debug")
}
}else{
true
}
}else{
false
}
return pluginConfig.isDebugMode(buildTypeName, variantName)
}

fun isReflectInvokeMethod(buildTypeName :String?,variantName :String):Boolean{
return if (reflectInvokeMethod){
if (reflectInvokeMethodOnlyDebug){
if (buildTypeName != null){
buildTypeName.lowercase() == "debug"
}else{
variantName.lowercase().contains("debug")
}
}else{
true
}
}else{
false
}
return pluginConfig.isReflectInvokeMethod(buildTypeName, variantName)
}

fun isDebugMode():Boolean{
return debugMode
return pluginConfig.isDebugMode()
}
fun isReflectInvokeMethod():Boolean{
return reflectInvokeMethod
return pluginConfig.isReflectInvokeMethod()
}
fun hasBuildConfig():Boolean{
return buildConfig
return pluginConfig.hasBuildConfig()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class CompilePlugin(private val root:Boolean): BasePlugin() {
if (project.rootProject == project || root){
return
}
val buildTypeName = "release"
val variantName = "release"
if (hasBuildConfig()){
try {
val javaPluginExtension = project.extensions.getByType(JavaPluginExtension::class.java)
Expand Down Expand Up @@ -75,6 +77,9 @@ class CompilePlugin(private val root:Boolean): BasePlugin() {
project.tasks.register(DEBUG_MODE_FILE_TASK_NAME, DebugModeFileTask::class.java){
it.debugModeDir = debugModeDir.absolutePath
it.packageName = packageName
it.variantName = variantName
it.buildTypeName = buildTypeName
it.isAndroidModule = false
}
project.afterEvaluate {
project.tasks.findByName("compileJava")?.dependsOn(DEBUG_MODE_FILE_TASK_NAME)
Expand Down Expand Up @@ -102,8 +107,7 @@ class CompilePlugin(private val root:Boolean): BasePlugin() {
}
val compileKotlin = compileKotlinTask.get()

val buildTypeName = "release"
val variantName = "release"


val cacheDir = try {
compileKotlin.destinationDirectory.get().asFile
Expand Down Expand Up @@ -183,7 +187,6 @@ class CompilePlugin(private val root:Boolean): BasePlugin() {
null
}
val kotlinPath = cacheDir ?: File(project.buildDir.path + "/tmp/kotlin-classes/".adapterOSPath() + variantName)

doAopTask(project, isApp, variantName, buildTypeName, javaCompile, kotlinPath)
}
}
Expand Down Expand Up @@ -246,11 +249,15 @@ class CompilePlugin(private val root:Boolean): BasePlugin() {
}
}
}
val buildTypeName: String? = variant.buildType
project
.tasks
.register("$DEBUG_MODE_FILE_TASK_NAME$variantNameCapitalized", DebugModeFileTask::class.java){
it.debugModeDir = debugModeDir.absolutePath
it.packageName = packageName
it.variantName = variantName
it.buildTypeName = buildTypeName
it.isAndroidModule = true
}
}
project.afterEvaluate {
Expand All @@ -269,7 +276,7 @@ class CompilePlugin(private val root:Boolean): BasePlugin() {
if (srcDir.exists()){
//说明这个才是真正的源码所在路径
val packageFile = getPackageNameFile(srcDir,0)
val relativePath = packageFile.getRelativePath(srcDir).replace(File.separator,".")
val relativePath = packageFile.getRelativePath(srcDir).replace("/",".")
return if (relativePath.endsWith(".")){
relativePath.substring(0,relativePath.length-1)
}else{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.flyjingfish.android_aop_plugin.plugin

import com.flyjingfish.android_aop_plugin.config.RootBooleanConfig
import org.gradle.api.Plugin
import org.gradle.api.Project

class PluginConfig(private val project: Project) {
private var reflectInvokeMethod = false
private var reflectInvokeMethodOnlyDebug = false
private var debugMode = false
private var onlyDebug = false
private var isIncremental = true
private var buildConfig = true

init{
val reflectInvokeMethodStr = project.properties[RootBooleanConfig.REFLECT_INVOKE_METHOD.propertyName]?:"${RootBooleanConfig.REFLECT_INVOKE_METHOD.defaultValue}"
val debugModeStr = project.properties[RootBooleanConfig.DEBUG_MODE.propertyName]?:"${RootBooleanConfig.DEBUG_MODE.defaultValue}"
val onlyModeStr = project.properties[RootBooleanConfig.ONLY_DEBUG.propertyName]?:"${RootBooleanConfig.ONLY_DEBUG.defaultValue}"
val isIncrementalStr = project.properties[RootBooleanConfig.INCREMENTAL.propertyName]?:"${RootBooleanConfig.INCREMENTAL.defaultValue}"
val reflectInvokeMethodDebugStr = project.properties[RootBooleanConfig.REFLECT_INVOKE_METHOD_ONLY_DEBUG.propertyName]?:"${RootBooleanConfig.REFLECT_INVOKE_METHOD_ONLY_DEBUG.defaultValue}"
val buildConfigStr = project.properties[RootBooleanConfig.BUILD_CONFIG.propertyName]?:"${RootBooleanConfig.BUILD_CONFIG.defaultValue}"
debugMode = debugModeStr.toString() == "true"
reflectInvokeMethod = reflectInvokeMethodStr.toString() == "true"
onlyDebug = onlyModeStr.toString() == "true"
isIncremental = isIncrementalStr.toString() == "true"
reflectInvokeMethodOnlyDebug = reflectInvokeMethodDebugStr.toString() == "true"
buildConfig = buildConfigStr.toString() == "true"
}

fun isIncremental():Boolean{
return isIncremental
}

fun isDebugMode(buildTypeName :String?,variantName :String):Boolean{
return if (debugMode){
if (onlyDebug){
if (buildTypeName != null){
buildTypeName.lowercase() == "debug"
}else{
variantName.lowercase().contains("debug")
}
}else{
true
}
}else{
false
}
}

fun isReflectInvokeMethod(buildTypeName :String?,variantName :String):Boolean{
return if (reflectInvokeMethod){
if (reflectInvokeMethodOnlyDebug){
if (buildTypeName != null){
buildTypeName.lowercase() == "debug"
}else{
variantName.lowercase().contains("debug")
}
}else{
true
}
}else{
false
}
}

fun isDebugMode():Boolean{
return debugMode
}
fun isReflectInvokeMethod():Boolean{
return reflectInvokeMethod
}
fun hasBuildConfig():Boolean{
return buildConfig
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.flyjingfish.android_aop_plugin.tasks

import com.android.build.gradle.AppPlugin
import com.flyjingfish.android_aop_plugin.config.AndroidAopConfig
import com.flyjingfish.android_aop_plugin.plugin.BasePlugin
import com.flyjingfish.android_aop_plugin.plugin.PluginConfig
import com.flyjingfish.android_aop_plugin.utils.InitConfig
import com.flyjingfish.android_aop_plugin.utils.Utils
import com.flyjingfish.android_aop_plugin.utils.adapterOSPath
import com.flyjingfish.android_aop_plugin.utils.checkExist
Expand All @@ -15,10 +20,51 @@ import java.io.IOException
abstract class DebugModeFileTask : DefaultTask() {
@get:Input
abstract var debugModeDir : String

@get:Input
abstract var variantName : String

@get:Input
abstract var isAndroidModule : Boolean

@get:Input
abstract var buildTypeName : String?

@get:Input
abstract var packageName : String?

@TaskAction
fun taskAction() {
val pluginConfig = PluginConfig(project)
val exportFile :Boolean = if (isAndroidModule){
val isApp = project.plugins.hasPlugin(AppPlugin::class.java)
val androidAopConfig : AndroidAopConfig = if (isApp){
project.extensions.getByType(AndroidAopConfig::class.java)
}else{
var config = InitConfig.optFromJsonString(
InitConfig.readAsString(Utils.configJsonFile(project)),
AndroidAopConfig::class.java)
if (config == null){
config = AndroidAopConfig()
}
config
}

androidAopConfig.enabled && pluginConfig.isDebugMode(buildTypeName,variantName)
}else{
var config = InitConfig.optFromJsonString(
InitConfig.readAsString(Utils.configJsonFile(project)),
AndroidAopConfig::class.java)
if (config == null){
config = AndroidAopConfig()
}
config.enabled && pluginConfig.isDebugMode()
}

if (!exportFile){
return
}

val packageName = this.packageName
if (packageName.isNullOrEmpty() || packageName == "null"){
return
Expand Down
2 changes: 1 addition & 1 deletion docs/android_aop_extra.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```groovy
dependencies {
//Optional 👇This package provides some common annotation aspects
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.2.4'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.2.5'
}
```

Expand Down
Loading

0 comments on commit 25544fd

Please sign in to comment.