Skip to content

Commit

Permalink
Merge pull request #17 from ltttttttttttt/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ltttttttttttt authored Nov 25, 2024
2 parents a336a3e + 88c9f54 commit 8385353
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 176 deletions.
136 changes: 70 additions & 66 deletions LazyPeopleHttp-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -148,70 +148,74 @@ android {
}

afterEvaluate {
tasks.findByName("signAndroidReleasePublication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signIosArm64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signIosSimulatorArm64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signIosX64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signIosArm64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signIosSimulatorArm64Publication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signIosSimulatorArm64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signIosX64Publication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signIosX64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signIosX64Publication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosX64PublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishIosX64PublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishIosX64PublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishJsPublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishJsPublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishJvmPublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishKotlinMultiplatformPublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishJvmPublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishJsPublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosX64PublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
try {
tasks.findByName("signAndroidReleasePublication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signIosArm64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signIosSimulatorArm64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signIosX64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidDebugPublicationToSonatypeRepository"))
tasks.findByName("signIosArm64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signIosSimulatorArm64Publication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signIosSimulatorArm64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signIosX64Publication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signIosX64Publication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishIosArm64PublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishAndroidReleasePublicationToSonatypeRepository"))
tasks.findByName("signIosX64Publication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
tasks.findByName("signJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosX64PublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishIosX64PublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishIosX64PublicationToSonatypeRepository"))
tasks.findByName("signJvmPublication")!!
.mustRunAfter(tasks.findByName("publishJsPublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishJsPublicationToSonatypeRepository"))
tasks.findByName("signKotlinMultiplatformPublication")!!
.mustRunAfter(tasks.findByName("publishJvmPublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishKotlinMultiplatformPublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishJvmPublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishJsPublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosX64PublicationToSonatypeRepository"))
tasks.findByName("signWasmJsPublication")!!
.mustRunAfter(tasks.findByName("publishIosSimulatorArm64PublicationToSonatypeRepository"))
} catch (e: Exception) {
e.printStackTrace()
}
}
10 changes: 8 additions & 2 deletions LazyPeopleHttp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
kotlin("multiplatform")
id("convention.publication")
kotlin("plugin.serialization") version kotlinVersion
}

group = "io.github.ltttttttttttt"
Expand All @@ -25,11 +26,16 @@ kotlin {
implementation("com.google.devtools.ksp:symbol-processing-api:$kspVersion")
implementation(project(":LazyPeopleHttp-lib"))
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationJsonVersion")
}
}
val jvmTest by getting
}
}

tasks.findByName("signKotlinMultiplatformPublication")!!
.dependsOn(tasks.findByName("publishJvmPublicationToSonatypeRepository"))
try {
tasks.findByName("signKotlinMultiplatformPublication")!!
.dependsOn(tasks.findByName("publishJvmPublicationToSonatypeRepository"))
} catch (e: Exception) {
e.printStackTrace()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.lt.lazy_people_http.options

import kotlinx.serialization.*

/**
* creator: lt 2024/11/25 lt.dygzs@qq.com
* effect : 自定义输出文件配置
* warning: 属性替换规则参考[ReplaceRule]
*/
interface CustomizeOutputFileBean {
//生成的文件名
val fileName: String

//生成文件的扩展名
val extensionName: String

//文件顶部内容(导包,类声明等)
val fileTopContent: String

//文件底部内容(类结尾括号,扩展方法等)
val fileBottomContent: String

//suspend方法内容(方法的声明和方法体)
val suspendFunContent: FunctionBean

//方法内容(方法的声明和方法体)
val funContent: FunctionBean
}

/**
* 属性替换规则
*/
object ReplaceRule {
/*类级别*/
fun String._packageName(packageName: String) = replace("##packageName##", packageName)//包名
fun String._className(className: String) = replace("##className##", className)//生成后的类名
fun String._originalClassName(originalClassName: String) = replace("##originalClassName##", originalClassName)//原类名

/*方法级*/
fun String._functionName(functionName: String) = replace("##functionName##", functionName)//方法名
fun String._funParameter(funParameter: String) = replace("##funParameter##", funParameter)//方法参数及类型
fun String._returnType(returnType: String) = replace("##returnType##", returnType)//方法返回值类型
fun String._url(url: String) = replace("##url##", url)//请求url
fun String._queryParameter(queryParameter: String) = replace("##queryParameter##", queryParameter)//query请求参数
fun String._fieldParameter(fieldParameter: String) = replace("##fieldParameter##", fieldParameter)//field请求参数
fun String._runtimeParameter(runtimeParameter: String) =
replace("##runtimeParameter##", runtimeParameter)//运行时设置的请求参数

fun String._type(type: String) = replace("##type##", type)//需要被解析的类型,如果是suspend方法则与returnType一致
fun String._requestMethod(requestMethod: String) = replace("##requestMethod##", requestMethod)//网络请求使用的方法
fun String._headers(headers: String) = replace("##headers##", headers)//注解中声明的请求头
fun String._functionAnnotations(functionAnnotations: String) =
replace("##functionAnnotations##", functionAnnotations)//方法上所有声明的注解

fun String._responseName(responseName: String) = replace("##responseName##", responseName)//自定义的返回值类型,比如Flow

/*参数级*/
fun String._kt(key: String, type: String) = replace("##key##", key).replace("##type##", type)//参数及类型
fun String._kv(key: String, value: String) = replace("##key##", key).replace("##value##", value)//参数名及参数值

}

@Serializable
class CustomizeOutputFileBeanImpl(
override val fileName: String = "##className##",
override val extensionName: String = "kt",
override val fileTopContent: String = "package ##packageName##\n" +
"\n" +
"import com.lt.lazy_people_http._lazyPeopleHttpFlatten\n" +
"import com.lt.lazy_people_http.call.Call\n" +
"import com.lt.lazy_people_http.call.CallCreator\n" +
"import com.lt.lazy_people_http.config.LazyPeopleHttpConfig\n" +
"import com.lt.lazy_people_http.request.RequestMethod\n" +
"import com.lt.lazy_people_http.service.HttpServiceImpl\n" +
"import kotlin.reflect.typeOf\n" +
"\n" +
"class ##className##(\n" +
" val config: LazyPeopleHttpConfig,\n" +
") : ##originalClassName##, HttpServiceImpl {\n" +
" private inline fun <reified T> T?._toJson() = CallCreator.parameterToJson(config, this)\n\n",
override val fileBottomContent: String = "}\n\n" +
"fun kotlin.reflect.KClass<##originalClassName##>.createService(config: LazyPeopleHttpConfig): ##originalClassName## =\n" +
" ##className##(config)",
override val suspendFunContent: FunctionBean = FunctionBean(
" override suspend fun ##functionName##(##funParameter##): ##returnType## {\n" +
" return CallCreator.createResponse<Call<##returnType##>>(\n" +
" config,\n" +
" \"##url##\",\n" +
" ##queryParameter##,\n" +
" ##fieldParameter##,\n" +
" ##runtimeParameter##,\n" +
" typeOf<##type##>(),\n" +
" ##requestMethod##,\n" +
" ##headers##,\n" +
" ##functionAnnotations##,\n" +
" ##responseName##,\n" +
" ).await()\n" +
" }\n\n",
),
override val funContent: FunctionBean = FunctionBean(
" override fun ##functionName##(##funParameter##): ##returnType## {\n" +
" return CallCreator.createResponse(\n" +
" config,\n" +
" \"##url##\",\n" +
" ##queryParameter##,\n" +
" ##fieldParameter##,\n" +
" ##runtimeParameter##,\n" +
" typeOf<##type##>(),\n" +
" ##requestMethod##,\n" +
" ##headers##,\n" +
" ##functionAnnotations##,\n" +
" ##responseName##,\n" +
" )\n" +
" }\n\n",
),
) : CustomizeOutputFileBean

/**
* 方法内容
*/
@Serializable
class FunctionBean(
//方法内容
val content: String,
//方法参数及类型
val funParameterKT: String = "##key##: ##type##",
//query参数
val queryParameter: ParameterBean = ParameterBean(),
//field参数
val fieldParameter: ParameterBean = ParameterBean(),
//运行时参数
val runtimeParameter: ParameterBean = ParameterBean(),
//请求头
val header: ParameterBean = ParameterBean(),
)

/**
* 参数内容
*/
@Serializable
class ParameterBean(
val emptyValue: String = "null",
val arrayStart: String = "arrayOf(",
val arrayEnd: String = ")",
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ internal class KspOptions(environment: SymbolProcessorEnvironment) {
private val suffix = "WithLazyPeopleHttp"//后缀
private val options = environment.options
private val isGetFunAnnotations = "getFunAnnotations$suffix"
private val createCallFunName = "createCallFunName$suffix"
private val functionReplaceFrom = "functionReplaceFrom$suffix"
private val functionReplaceTo = "functionReplaceTo$suffix"
private val customizeOutputFile = "customizeOutputFile$suffix"

/**
* 是否需要在请求信息[RequestInfo]中附带"获取方法和其参数以及返回值上的注解(不包含Type的注解)"的方式
*/
fun isGetFunAnnotations(): Boolean =
options[isGetFunAnnotations] == "true"

/**
* 获取创建Call的方法名,可以自定义创建Call的子类
*/
fun getCreateCallFunName(): String =
options[createCallFunName].ifNullOfEmpty { "CallCreator.createResponse" }

/**
* 要将方法名的名称当做url时将某值替换为[functionReplaceTo]
*/
Expand All @@ -37,4 +31,9 @@ internal class KspOptions(environment: SymbolProcessorEnvironment) {
* 要将方法名的名称当做url时将[functionReplaceFrom]替换为设置的值
*/
fun getFunctionReplaceTo(): String = options[functionReplaceTo] ?: ""

/**
* 自定义输出文件的规则,参考[CustomizeOutputFileBean],需要一个json文件,内容是List<CustomizeOutputFile>
*/
fun getCustomizeOutputFile(): String = options[customizeOutputFile] ?: ""
}
Loading

0 comments on commit 8385353

Please sign in to comment.