Skip to content

Commit

Permalink
Merge pull request didi#1131 from didi/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
RealOnlyone authored May 30, 2023
2 parents 5becdc9 + c519148 commit 4c0754f
Show file tree
Hide file tree
Showing 112 changed files with 4,638 additions and 4,585 deletions.
28 changes: 16 additions & 12 deletions Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,22 @@ android {

//dokit 扩展

//dokitExt {
// //通用设置
// comm {
// //地图经纬度开关
// gpsSwitch true
// //网络开关
// networkSwitch true
// //大图开关
// bigImgSwitch true
// //webView js 抓包
// webViewSwitch true
// }

dokit {
gpsEnable true
bigImageEnable true
webView {
network true
dokitWeb true
vConsole true
}
gps {
didi true
baidu true
}
}

//dokit {
//
// slowMethod {
// //调用栈模式配置
Expand Down
2 changes: 0 additions & 2 deletions Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
<uses-permission
android:name="android.permission.READ_FRAME_BUFFER"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" /> <!-- tencent Android Q新增权限,允许应用在后台发起定位,如应用target为Q,请添加此权限 -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <!-- tencent 如果设置了target >= 28 如果需要启动后台定位则必须声明这个权限 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- 用于进行网络定位 -->
Expand Down
2 changes: 1 addition & 1 deletion Android/app/src/main/res/values-en-rUS/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">DoKitDemo</string>
<string name="app_name">DoKit</string>
<string name="app_build_types">BuildType</string>
<string name="app_btn_jump">Jump Other Activity</string>
<string name="app_btn_mc">MC</string>
Expand Down
2 changes: 1 addition & 1 deletion Android/app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">DoKitDemo</string>
<string name="app_name">DoKit</string>
<string name="app_build_types">当前编译环境</string>
<string name="app_btn_jump">跳转其他Activity</string>
<string name="app_btn_mc">一机多控</string>
Expand Down
2 changes: 1 addition & 1 deletion Android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">DoKitDemo</string>
<string name="app_name">DoKit</string>
<string name="dk_kit_demo">demo</string>
<string name="dk_titlebar_back">&#060;</string>
<string name="app_build_types">当前编译环境</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fun MethodNode.isEmptyMethod(): Boolean {

fun MethodNode.isMainMethod(className: String): Boolean {
if (this.name == "main" && this.desc == "([Ljava/lang/String;)V") {
// "====isMainMethod====$className ${this.name} ${this.desc} ${this.access}".println()
"====isMainMethod====$className ${this.name} ${this.desc} ${this.access}".println()
return true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.didichuxing.doraemonkit.plugin

import com.didichuxing.doraemonkit.plugin.extension.CommExt
import com.didichuxing.doraemonkit.plugin.extension.DoKitExt
import com.didichuxing.doraemonkit.plugin.extension.SlowMethodExt
import org.gradle.api.Project
import com.didichuxing.doraemonkit.plugin.extension.DoKitExtension
import com.didichuxing.doraemonkit.plugin.extension.SlowMethodExtension
import com.didichuxing.doraemonkit.plugin.thirdlib.ThirdLibInfo

/**
* ================================================
Expand All @@ -16,20 +15,11 @@ import org.gradle.api.Project
*/
object DoKitExtUtil {

/**
* 是否包含dokitx-rpc模块
*/
var HAS_DOKIT_RPC_MODULE = false
//private var mApplicationId: String = ""

var HAS_DOKIT_TCP_HOOK_DJ = false

var DOKIT_GPS_MOCK_INCLUDE = false

/**
* 三方库版本信息
*/
// val THIRD_LIB_INFOS = mutableMapOf<String, ThirdLibInfo>()

val THIRD_LIB_INFOS = mutableListOf<ThirdLibInfo>()

Expand Down Expand Up @@ -64,7 +54,7 @@ object DoKitExtUtil {
/**
* 慢函数策略 默认为函数调用栈策略
*/
var SLOW_METHOD_STRATEGY = SlowMethodExt.STRATEGY_STACK
var SLOW_METHOD_STRATEGY = SlowMethodExtension.STRATEGY_STACK

private val applications: MutableSet<String> = mutableSetOf()

Expand All @@ -73,9 +63,8 @@ object DoKitExtUtil {
*/
private var appPackageName: String = ""

var commExt = CommExt()
private set
val slowMethodExt = SlowMethodExt()

val slowMethodExt = SlowMethodExtension()


fun dokitPluginSwitchOpen(): Boolean {
Expand All @@ -97,9 +86,8 @@ object DoKitExtUtil {
* @param dokitEx dokitExtension
* @param appExtension appExtension
*/
fun init(dokitEx: DoKitExt) {
fun init(dokitEx: DoKitExtension) {
//设置普通的配置
commExt = dokitEx.comm
//slowMethodExt.strategy = dokitEx.slowMethod.strategy
//slowMethodExt.methodSwitch = dokitEx.slowMethod.methodSwitch
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,56 @@ package com.didichuxing.doraemonkit.plugin

import com.android.build.gradle.AppExtension
import com.android.build.gradle.LibraryExtension
import com.didichuxing.doraemonkit.plugin.extension.DoKitExt
import com.didichuxing.doraemonkit.plugin.extension.SlowMethodExt
import com.didichuxing.doraemonkit.plugin.extension.DoKitExtension
import com.didichuxing.doraemonkit.plugin.extension.SlowMethodExtension
import com.didichuxing.doraemonkit.plugin.processor.DoKitPluginConfigProcessor
import com.didichuxing.doraemonkit.plugin.stack_method.MethodStackNodeUtil
import com.didichuxing.doraemonkit.plugin.thirdlib.ThirdLibVariantProcessor
import com.didichuxing.doraemonkit.plugin.transform.*
import com.didiglobal.booster.gradle.GTE_V3_4
import com.didiglobal.booster.gradle.dependencies
import com.didiglobal.booster.gradle.getAndroid
import com.didiglobal.booster.gradle.getProperty
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.result.ResolvedArtifactResult


/**
* when 也可以用来取代 if-else if链。
* 如果不提供参数,所有的分支条件都是简单的布尔表达式,而当一个分支的条件为真时则执行该分支:
*/

/**
* 作用域函数:let、run、with、apply 以及 also
* 它们的唯一目的是在对象的上下文中执行代码块
* 由于作用域函数本质上都非常相似,因此了解它们之间的区别很重要。每个作用域函数之间有两个主要区别:
* 引用上下文对象的方式:
* 作为 lambda 表达式的接收者(this)或者作为 lambda 表达式的参数(it)
* run、with 以及 apply 通过关键字 this 引用上下文对象
* let 及 also 将上下文对象作为 lambda 表达式参数
*
* 返回值:
* apply 及 also 返回上下文对象。
* let、run 及 with 返回 lambda 表达式结果.
*/
/**
* 函数 对象引用 返回值 是否是扩展函数
* let it Lambda 表达式结果 是
* run this Lambda 表达式结果 是
* run - Lambda 表达式结果 不是:调用无需上下文对象
* with this Lambda 表达式结果 不是:把上下文对象当做参数
* apply this 上下文对象 是
* also it 上下文对象 是
*/

/**
*对一个非空(non-null)对象执行 lambda 表达式:let
*将表达式作为变量引入为局部作用域中:let
*对象配置:apply
*对象配置并且计算结果:run
*在需要表达式的地方运行语句:非扩展的 run
*附加效果:also
*一个对象的一组函数调用:with
*/

/**
* ================================================
Expand All @@ -23,58 +61,26 @@ import org.gradle.api.artifacts.result.ResolvedArtifactResult
* 描 述:
* 修订历史:
* ================================================
*
* DoKit 插件入口
*/

class DoKitPlugin : Plugin<Project> {
override fun apply(project: Project) {
//创建指定扩展 并将project 传入构造函数
val doKitExt = project.extensions.create("dokitExt", DoKitExt::class.java)
val doKit = project.extensions.create("dokit", DoKitExtension::class.java)
"dokit plugin apply ${doKit}".println()

project.gradle.addListener(DoKitTransformTaskExecutionListener(project))

//println("project.plugins===>${project.plugins}")
/**
* when 也可以用来取代 if-else if链。
* 如果不提供参数,所有的分支条件都是简单的布尔表达式,而当一个分支的条件为真时则执行该分支:
*/

/**
* 作用域函数:let、run、with、apply 以及 also
* 它们的唯一目的是在对象的上下文中执行代码块
* 由于作用域函数本质上都非常相似,因此了解它们之间的区别很重要。每个作用域函数之间有两个主要区别:
* 引用上下文对象的方式:
* 作为 lambda 表达式的接收者(this)或者作为 lambda 表达式的参数(it)
* run、with 以及 apply 通过关键字 this 引用上下文对象
* let 及 also 将上下文对象作为 lambda 表达式参数
*
* 返回值:
* apply 及 also 返回上下文对象。
* let、run 及 with 返回 lambda 表达式结果.
*/
/**
* 函数 对象引用 返回值 是否是扩展函数
* let it Lambda 表达式结果 是
* run this Lambda 表达式结果 是
* run - Lambda 表达式结果 不是:调用无需上下文对象
* with this Lambda 表达式结果 不是:把上下文对象当做参数
* apply this 上下文对象 是
* also it 上下文对象 是
*/

/**
*对一个非空(non-null)对象执行 lambda 表达式:let
*将表达式作为变量引入为局部作用域中:let
*对象配置:apply
*对象配置并且计算结果:run
*在需要表达式的地方运行语句:非扩展的 run
*附加效果:also
*一个对象的一组函数调用:with
*/

when {
project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.dynamic-feature") -> {
if (!isReleaseTask(project)) {
project.getAndroid<AppExtension>().let { androidExt ->
val pluginSwitch = project.getProperty("DOKIT_PLUGIN_SWITCH", true)
val logSwitch = project.getProperty("DOKIT_LOG_SWITCH", false)

val slowMethodSwitch = project.getProperty("DOKIT_METHOD_SWITCH", false)
val slowMethodStrategy = project.getProperty("DOKIT_METHOD_STRATEGY", 0)
val methodStackLevel = project.getProperty("DOKIT_METHOD_STACK_LEVEL", 5)
Expand All @@ -94,7 +100,7 @@ class DoKitPlugin : Plugin<Project> {
if (DoKitExtUtil.DOKIT_PLUGIN_SWITCH) {
//注册transform
androidExt.registerTransform(commNewInstance(project))
if (slowMethodSwitch && slowMethodStrategy == SlowMethodExt.STRATEGY_STACK) {
if (slowMethodSwitch && slowMethodStrategy == SlowMethodExtension.STRATEGY_STACK) {
MethodStackNodeUtil.METHOD_STACK_KEYS.add(0, mutableSetOf<String>())
val methodStackRange = 1 until methodStackLevel
if (methodStackLevel > 1) {
Expand All @@ -111,14 +117,6 @@ class DoKitPlugin : Plugin<Project> {
}
}

//项目评估完毕回调
// project.afterEvaluate { project ->
// "===afterEvaluate===".println()
// androidExt.applicationVariants.forEach { variant ->
// DoKitPluginConfigProcessor(project).process(variant)
// }
// }

/**
* 所有项目的build.gradle执行完毕
* wiki:https://juejin.im/post/6844903607679057934
Expand All @@ -127,6 +125,7 @@ class DoKitPlugin : Plugin<Project> {
project.gradle.projectsEvaluated {
"===projectsEvaluated===".println()
androidExt.applicationVariants.forEach { variant ->
ThirdLibVariantProcessor(project).process(variant)
DoKitPluginConfigProcessor(project).process(variant)
}

Expand All @@ -136,6 +135,7 @@ class DoKitPlugin : Plugin<Project> {
//task依赖关系图建立完毕
project.gradle.taskGraph.whenReady {
"===taskGraph.whenReady===".println()
"dokit config :: ${doKit}".println()
}

}
Expand All @@ -152,6 +152,7 @@ class DoKitPlugin : Plugin<Project> {
}
project.afterEvaluate {
libraryExt.libraryVariants.forEach { variant ->
ThirdLibVariantProcessor(project).process(variant)
DoKitPluginConfigProcessor(project).process(variant)
}
}
Expand All @@ -168,8 +169,8 @@ class DoKitPlugin : Plugin<Project> {
}

private fun commNewInstance(project: Project): DoKitBaseTransform = when {
GTE_V3_4 -> DoKitCommTransformV34(project)
else -> DoKitCommTransform(project)
GTE_V3_4 -> DoKitCommonTransformV34(project)
else -> DoKitCommonTransform(project)
}

private fun dependNewInstance(project: Project, index: Int): DoKitBaseTransform = when {
Expand All @@ -178,4 +179,4 @@ class DoKitPlugin : Plugin<Project> {
}


}
}
Loading

0 comments on commit 4c0754f

Please sign in to comment.