Compare commits

...

2 Commits

Author SHA1 Message Date
fc31966b5c fix NPE of ktorm 2023-10-27 19:13:44 +08:00
1613393381 update gradle build scripts 2023-10-27 18:11:28 +08:00
63 changed files with 368 additions and 392 deletions

View File

@ -1,31 +1,39 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.9.20-RC2"
id("ts-gradle")
val kotlinVersion = "1.9.20-RC2"
kotlin("jvm") version kotlinVersion
kotlin("plugin.allopen") version kotlinVersion apply false
id("ts-gradle-env") apply false
id("ts-gradle-install") apply false
id("ts-gradle-test") apply false
id("ts-gradle-publish") apply false
id("ts-gradle-repos") apply false
}
allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "maven-publish")
apply(plugin = "ts-gradle-env")
apply(plugin = "ts-gradle-install")
apply(plugin = "ts-gradle-test")
apply(plugin = "ts-gradle-publish")
apply(plugin = "ts-gradle-repos")
group = "cn.tursom"
version = "1.1-SNAPSHOT"
useTursomRepositories()
tasks.withType<KotlinCompile>().configureEach {
//kotlinOptions.jvmTarget = "21"
kotlinOptions.jvmTarget = "21"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
//kotlinOptions.useIR = true
}
if (!isTestRunning) {
tasks.withType<Test> {
enabled = false
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
//autoConfigPublish()
}
dependencies {

3
local.example.yml Normal file
View File

@ -0,0 +1,3 @@
tursom:
artifactoryUser: XXXX
artifactoryPassword: XXXX

View File

@ -39,6 +39,8 @@ include("ts-database:ts-redis")
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
version("kotlin-version", "1.9.20-RC2")
val kotlinCoroutineVersion = "1.7.3"
version("kotlin-coroutines", kotlinCoroutineVersion)
library(

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
api(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core:ts-log"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutineVersion)

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutineVersion)

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":ts-core"))
compileOnly(group = "io.netty", name = "netty-all", version = nettyVersion)

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
api(project(":ts-core:ts-delegation"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-buffer"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-buffer"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.9")

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-delegation"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
api(group = "com.sun.mail", name = "javax.mail", version = "1.6.2")

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
api(project(":ts-core"))

View File

@ -1,9 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
id("ts-gradle")
kotlin("plugin.allopen") version "1.5.21"
kotlin("plugin.allopen")
}
dependencies {

View File

@ -1,9 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
id("ts-gradle")
kotlin("plugin.allopen") version "1.5.21"
kotlin("plugin.allopen")
}
dependencies {
@ -22,3 +20,7 @@ artifacts {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xjvm-default=all"
}
tasks.withType<Test>() {
jvmArgs = listOf("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}

View File

@ -37,22 +37,27 @@ object Proxy {
inline operator fun <T : Any> get(
clazz: Class<T>,
container: MutableProxyContainer = defaultContainer(),
useDirectAccessor: Boolean = false,
builder: (Class<T>) -> T,
): Pair<T, MutableProxyContainer> {
val target = getCachedTarget(clazz)
val directAccessor = builder(target)
val obj = builder(target)
val directAccessor = if (useDirectAccessor) builder(target) else obj
container.target = obj
container.ctx[directAccessorKey] = directAccessor
if (useDirectAccessor) container.ctx[directAccessorKey] = directAccessor
injectCallback(obj as Factory, container, directAccessor as Factory)
return obj to container
}
inline fun <reified T : Any> get() = get(T::class.java)
inline fun <reified T : Any> get(
container: MutableProxyContainer = defaultContainer(),
useDirectAccessor: Boolean = false,
) = get(T::class.java, container, useDirectAccessor)
inline operator fun <reified T : Any> get(
argumentTypes: Array<out Class<*>>,
arguments: Array<out Any?>,
@ -122,15 +127,20 @@ object Proxy {
container,
)
operator fun <T : Any> get(clazz: Class<T>, container: MutableProxyContainer = defaultContainer()) =
get(clazz, container, Class<T>::newInstance)
operator fun <T : Any> get(
clazz: Class<T>,
container: MutableProxyContainer = defaultContainer(),
useDirectAccessor: Boolean = false,
) =
get(clazz, container, useDirectAccessor, Class<T>::newInstance)
operator fun <T : Any> get(
clazz: Class<T>,
argumentTypes: Array<out Class<*>>,
arguments: Array<out Any?>,
container: MutableProxyContainer = defaultContainer(),
) = get(clazz, container) {
useDirectAccessor: Boolean = false,
) = get(clazz, container, useDirectAccessor) {
it.getConstructor(*argumentTypes).newInstance(*arguments)
}

View File

@ -68,7 +68,7 @@ class Example {
@Test
fun test() {
val (t, container) = Proxy.get<TestClass>()
val (t, container) = Proxy.get<TestClass>(useDirectAccessor = true)
val getA = GetA(t)
println(getA.t == t)

View File

@ -1,15 +0,0 @@
package cn.tursom.proxy
fun b() {
repeat(9) { i -> repeat(i) { j -> print("$j*$i=${i * j} ") };println() }
}
fun a() {
repeat(9) { i -> repeat(i) { j -> print("$j*$i=${i * j} ") };println() }
}
fun main() {
(1..9).map { i -> println((1..i).map { "$it*$i=${i * it}" }) }
}

View File

@ -1,9 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
id("ts-gradle")
kotlin("plugin.allopen") version "1.5.21"
kotlin("plugin.allopen")
}
dependencies {

View File

@ -1,9 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
id("ts-gradle")
kotlin("plugin.allopen") version "1.5.21"
kotlin("plugin.allopen")
}
dependencies {

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":ts-core"))
api(project(":ts-core:ts-buffer"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
// 解析XML https://mvnrepository.com/artifact/org.dom4j/dom4j

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
// 解析YAML

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))

View File

@ -14,11 +14,11 @@ class ExtSqlDialect(
override fun createSqlFormatter(database: Database, beautifySql: Boolean, indentSize: Int): SqlFormatter {
val formatter = sqlDialect.createSqlFormatter(database, beautifySql, indentSize)
val (proxyFormatter, container) = Proxy.get(formatter.javaClass) { InstantAllocator(it) }
run {
val extSqlFormatter = ExtSqlFormatter(formatter)
extSqlFormatter.registerVisitor(DirectSqlExpression.visitor)
container.addProxy(extSqlFormatter)
}
val extSqlFormatter = ExtSqlFormatter(formatter)
extSqlFormatter.registerVisitor(DirectSqlExpression.visitor)
container.addProxy(extSqlFormatter)
formatter.javaClass.allFieldsSequence.forEach { field ->
field.isAccessible = true
field.set(proxyFormatter, field.get(formatter))

View File

@ -1,13 +1,12 @@
package cn.tursom.database.ktorm.ext
import cn.tursom.proxy.function.ProxyMethod
import cn.tursom.reflect.asm.ReflectAsmKtField
import org.ktorm.expression.SqlExpression
import org.ktorm.expression.SqlFormatter
class ExtSqlFormatter(
private val prevFormatter: SqlFormatter,
) : ProxyMethod {
) {
companion object {
private val builderField = ReflectAsmKtField.get<SqlFormatter, StringBuilder>("_builder")
}

View File

@ -19,4 +19,12 @@ internal class ExtSqlDialectTest {
formatter.visit(IntSqlType sql "select count(*) from user u where u.uid = subscribe.mid" eq 0)
println(formatter.sql)
}
}
}
data class User(var name: String, var age: Int)
fun main() {
}

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
implementation(project(":ts-core"))

5
ts-gradle/README.md Normal file
View File

@ -0,0 +1,5 @@
## 模块介绍
本模块负责管理各种通用的 gradle 插件,并提供给本项目使用。目前已有的各种插件如下:
- ts-gradle-env: 提供各种环境支持,包括将 yaml 与 properties 文件的内容读取到 ext 中,以及提供一些

View File

@ -1,17 +1,17 @@
//import java.text.SimpleDateFormat
//imextracted.text.SimpleDateFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*
plugins {
kotlin("jvm") version "1.9.10"
kotlin("jvm") version "1.9.10" apply false
`java-gradle-plugin`
`maven-publish`
}
try {
val properties = Properties()
properties.load(file("local.properties").inputStream())
properties.forEach { (k, v) ->
ext.set(k.toString(), v)
project.ext.set(k.toString(), v)
try {
setProperty(k.toString(), v)
} catch (_: Exception) {
@ -20,104 +20,117 @@ try {
} catch (_: Exception) {
}
group = "cn.tursom"
//version = SimpleDateFormat("yy.MM.dd-HH.mm").format(Date())
version = "1.1-SNAPSHOT"
allprojects {
group = "cn.tursom"
version = "1.1-SNAPSHOT"
repositories {
maven {
url = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-public/")
apply(plugin = "maven-publish")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "java-gradle-plugin")
repositories {
maven {
url = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-public/")
}
}
}
dependencies {
implementation(group = "org.yaml", name = "snakeyaml", version = "2.0")
implementation(fileTree(mapOf("dir" to "libs", "include" to arrayOf("*.jar"))))
}
extensions.configure(PublishingExtension::class) {
repositories {
publishToTursom(this, this@allprojects)
publishToGithub(this, this@allprojects)
registerPublishRepos(this, this@allprojects)
}
publications {
create<MavenPublication>("plugin") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
gradlePlugin {
plugins {
create("ts-gradle") {
// 在 app 模块需要通过 id 引用这个插件
id = "ts-gradle"
// 实现这个插件的类的路径
implementationClass = "cn.tursom.gradle.TursomGradlePlugin"
from(components["java"])
try {
artifact(tasks["kotlinSourcesJar"])
} catch (e: Exception) {
}
}
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "17"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
//kotlinOptions.useIR = true
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
publishing {
repositories {
fun publishToTursom(repositoryHandler: RepositoryHandler, project: Project) {
try {
repositoryHandler.maven {
name = "tursom"
val releasesRepoUrl = project.uri("https://jmp.mvn.tursom.cn:20080/repository/maven-releases/")
val snapshotRepoUrl = project.uri("https://jmp.mvn.tursom.cn:20080/repository/maven-snapshots/")
url = if (project.project.version.toString().endsWith("SNAPSHOT")) snapshotRepoUrl else releasesRepoUrl
println(url)
credentials {
val artifactoryUser: String = project.rootProject.ext["tursom.artifactoryUser"] as String
val artifactoryPassword: String = project.rootProject.ext["tursom.artifactoryPassword"] as String
username = artifactoryUser
password = artifactoryPassword
}
}
} catch (e: Exception) {
println("cannot push to repository tursom: ${e.javaClass}: ${e.message}")
}
}
fun publishToGithub(repositoryHandler: RepositoryHandler, project: Project) {
try {
repositoryHandler.maven {
name = "GitHubPackages"
val githubUser: String = project.rootProject.ext["github.artifactoryUser"] as String
val githubToken: String = project.rootProject.ext["github.artifactoryPassword"] as String
url = project.uri("https://maven.pkg.github.com/$githubUser/TursomServer")
credentials {
username = githubUser
password = githubToken
}
}
} catch (e: Exception) {
println("cannot push to repository github")
}
}
fun registerPublishRepos(repositoryHandler: RepositoryHandler, project: Project) {
val repositoriesRegex = "repositories\\.[a-zA-z]*".toRegex()
project.rootProject.properties.keys.asSequence().filter {
it matches repositoriesRegex
}.forEach {
val repositoryName = project.rootProject.ext.properties["$it.name"]?.toString() ?: it.substringAfterLast('.')
try {
maven {
name = "tursom"
val releasesRepoUrl = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-releases/")
val snapshotRepoUrl = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-snapshots/")
url = if (project.version.toString().endsWith("SNAPSHOT")) snapshotRepoUrl else releasesRepoUrl
val artifactoryUser = project.rootProject.ext.properties["$it.artifactoryUser"].toString()
val artifactoryPassword = project.rootProject.ext.properties["$it.artifactoryPassword"].toString()
repositoryHandler.maven {
name = repositoryName
val releasesRepoUrl = project.rootProject.ext.properties["$it.release"]?.let { project.uri(it.toString()) }
val snapshotRepoUrl = project.rootProject.ext.properties["$it.snapshot"]?.let { project.uri(it.toString()) }
val repoUrl = project.rootProject.ext.properties["$it.url"]?.let { project.uri(it.toString()) }
url = if (project.project.version.toString().endsWith("SNAPSHOT")
&& snapshotRepoUrl != null
) {
snapshotRepoUrl
} else releasesRepoUrl ?: repoUrl!!
credentials {
val artifactoryUser: String = rootProject.ext["tursom.artifactoryUser"] as String
val artifactoryPassword: String = rootProject.ext["tursom.artifactoryPassword"] as String
username = artifactoryUser
password = artifactoryPassword
}
}
} catch (e: Exception) {
println("cannot push to repository tursom: ${e.javaClass}: ${e.message}")
}
try {
maven {
name = "GitHubPackages"
val githubUser: String = rootProject.ext["github.artifactoryUser"] as String
val githubToken: String = rootProject.ext["github.artifactoryPassword"] as String
url = uri("https://maven.pkg.github.com/$githubUser/TursomServer")
credentials {
username = githubUser
password = githubToken
}
}
} catch (e: Exception) {
println("cannot push to repository github")
}
val repositoriesRegex = "repositories\\.[a-zA-z]*".toRegex()
rootProject.properties.keys.asSequence().filter {
it matches repositoriesRegex
}.forEach {
val repositoryName = rootProject.ext.properties["$it.name"]?.toString() ?: it.substringAfterLast('.')
try {
val artifactoryUser = rootProject.ext.properties["$it.artifactoryUser"].toString()
val artifactoryPassword = rootProject.ext.properties["$it.artifactoryPassword"].toString()
maven {
name = repositoryName
val releasesRepoUrl = rootProject.ext.properties["$it.release"]?.let { uri(it.toString()) }
val snapshotRepoUrl = rootProject.ext.properties["$it.snapshot"]?.let { uri(it.toString()) }
val repoUrl = rootProject.ext.properties["$it.url"]?.let { uri(it.toString()) }
url = if (project.version.toString().endsWith("SNAPSHOT")
&& snapshotRepoUrl != null
) {
snapshotRepoUrl
} else releasesRepoUrl ?: repoUrl!!
credentials {
username = artifactoryUser
password = artifactoryPassword
}
}
} catch (e: Exception) {
println("cannot push to repository $repositoryName")
}
println("cannot push to repository $repositoryName")
}
}
publications {
create<MavenPublication>("plugin") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
from(components["java"])
try {
artifact(tasks["kotlinSourcesJar"])
} catch (e: Exception) {
}
}
}
}
}

View File

@ -0,0 +1,2 @@
tursom.artifactoryUser: XXXX
tursom.artifactoryPassword: XXXX

View File

@ -1,3 +1,9 @@
include("ts-gradle-env")
include("ts-gradle-test")
include("ts-gradle-install")
include("ts-gradle-publish")
include("ts-gradle-repos")
pluginManagement {
repositories {
maven {

View File

@ -1,7 +0,0 @@
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtraPropertiesExtension
internal val Project.ext: ExtraPropertiesExtension
get() = (this as ExtensionAware).extensions
.getByName("ext") as ExtraPropertiesExtension

View File

@ -1,68 +0,0 @@
import org.gradle.api.DomainObjectCollection
import org.gradle.api.NamedDomainObjectCollection
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import java.util.concurrent.TimeUnit
fun Project.excludeTest() {
if (gradle.startParameter.taskNames.firstOrNull { taskName ->
taskName.contains("test", true)
} == null) {
tasks.run {
named("test") { it.enabled = false }
named("testClasses") { it.enabled = false }
named("compileTestJava") { it.enabled = false }
try {
named("compileTestKotlin") { it.enabled = false }
} catch (_: Exception) {
}
named("processTestResources") { it.enabled = false }
}
}
}
fun DomainObjectCollection<Configuration>.noExpire() {
all {
it.resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
it.resolutionStrategy.cacheDynamicVersionsFor(0, TimeUnit.SECONDS)
}
}
fun Project.useTursomRepositories(
useAliyunMirror: Boolean = false,
mavenCentral: Boolean = false,
tursom: Boolean = true
) {
repositories.run {
if (useAliyunMirror) {
maven {
it.url = uri("https://maven.aliyun.com/repository/public")
}
}
if (mavenCentral) {
mavenCentral()
}
if (tursom) {
maven {
it.url = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-public")
}
}
}
try {
configurations.noExpire()
} catch (_: Exception) {
}
}
fun <T> NamedDomainObjectCollection<T>.contains(name: String) = try {
findByName(name)
} catch (e: Exception) {
null
} != null
operator fun Project.get(key: String) = ext[key]?.toString()
val Project.isTestRunning
get() = gradle.startParameter.taskNames.firstOrNull { taskName ->
taskName.endsWith(":test")
} != null

View File

@ -0,0 +1,12 @@
dependencies {
implementation(group = "org.yaml", name = "snakeyaml", version = "2.0")
}
gradlePlugin {
plugins {
create("ts-gradle-env") {
id = "ts-gradle-env"
implementationClass = "cn.tursom.gradle.EnvPlugin"
}
}
}

View File

@ -1,17 +1,14 @@
package cn.tursom.gradle
import autoConfigPublish
import contains
import excludeTest
import ext
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.yaml.snakeyaml.Yaml
import java.io.FileNotFoundException
import java.util.*
class TursomGradlePlugin : Plugin<Project> {
class EnvPlugin : Plugin<Project> {
companion object {
val yaml = Yaml()
var project: Project? = null
@ -33,22 +30,9 @@ class TursomGradlePlugin : Plugin<Project> {
loadYaml(target, propertiesFile)
}
}
//println(target.ext.properties)
target.excludeTest()
if (!target.tasks.contains("install")) run install@{
val publishToMavenLocal = target.tasks.findByName("publishToMavenLocal") ?: return@install
target.tasks.register("install", DefaultTask::class.java) {
it.finalizedBy(publishToMavenLocal)
}
}
target.autoConfigPublish()
}
}
fun loadProperties(target: Project, propertiesFile: String) = try {
val properties = Properties()
properties.load(target.file(propertiesFile).inputStream())
@ -60,7 +44,7 @@ fun loadProperties(target: Project, propertiesFile: String) = try {
fun loadYaml(target: Project, propertiesFile: String) {
try {
TursomGradlePlugin.yaml.load<Map<String, Any>>(target.file(propertiesFile).inputStream()).forEach { (k, v) ->
EnvPlugin.yaml.load<Map<String, Any>>(target.file(propertiesFile).inputStream()).forEach { (k, v) ->
put(target, k, v)
}
} catch (e: Exception) {
@ -94,3 +78,7 @@ fun setProperty(target: Project, key: String, value: Any) {
} catch (e: Exception) {
}
}
val Project.ext: ExtraPropertiesExtension
get() = (this as ExtensionAware).extensions
.getByName("ext") as ExtraPropertiesExtension

View File

@ -0,0 +1,8 @@
gradlePlugin {
plugins {
create("ts-gradle-install") {
id = "ts-gradle-install"
implementationClass = "cn.tursom.gradle.InstallPlugin"
}
}
}

View File

@ -0,0 +1,23 @@
package cn.tursom.gradle
import org.gradle.api.DefaultTask
import org.gradle.api.NamedDomainObjectCollection
import org.gradle.api.Plugin
import org.gradle.api.Project
class InstallPlugin : Plugin<Project> {
override fun apply(target: Project) {
if (!target.tasks.contains("install")) run install@{
val publishToMavenLocal = target.tasks.findByName("publishToMavenLocal") ?: return@install
target.tasks.register("install", DefaultTask::class.java) {
it.finalizedBy(publishToMavenLocal)
}
}
}
}
fun <T> NamedDomainObjectCollection<T>.contains(name: String) = try {
findByName(name)
} catch (e: Exception) {
null
} != null

View File

@ -0,0 +1,12 @@
dependencies {
implementation(project(":ts-gradle-env"))
}
gradlePlugin {
plugins {
create("ts-gradle-publish") {
id = "ts-gradle-publish"
implementationClass = "cn.tursom.gradle.PublishPlugin"
}
}
}

View File

@ -1,10 +1,21 @@
package cn.tursom.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.repositories.PasswordCredentials
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.publish.PublicationContainer
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
class PublishPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.autoConfigPublish()
}
}
fun Project.autoConfigPublish() {
try {
extensions.configure(PublishingExtension::class.java, ::publish)
@ -173,4 +184,4 @@ private fun Project.getVersionWithProperties(): String {
}
return version
}
}

View File

@ -0,0 +1,14 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
gradlePlugin {
plugins {
create("ts-gradle-repos") {
id = "ts-gradle-repos"
implementationClass = "cn.tursom.gradle.ReposPlugin"
}
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
}

View File

@ -6,7 +6,7 @@ import org.gradle.api.Action
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
private const val defaultVersion = "1.0-SNAPSHOT"
private const val defaultVersion = "1.1-SNAPSHOT"
private fun DependencyHandler.add(
configurationName: String,

View File

@ -0,0 +1,54 @@
package cn.tursom.gradle
import org.gradle.api.DomainObjectCollection
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.dsl.RepositoryHandler
import java.util.concurrent.TimeUnit
class ReposPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.useTursomRepositories()
}
}
fun Project.useTursomRepositories(
useAliyunMirror: Boolean = false,
mavenCentral: Boolean = false,
tursom: Boolean = true
) {
repositories.useTursomRepositories(useAliyunMirror, mavenCentral, tursom)
try {
configurations.noExpire()
} catch (_: Exception) {
}
}
context (Project)
fun RepositoryHandler.useTursomRepositories(
useAliyunMirror: Boolean,
mavenCentral: Boolean,
tursom: Boolean
) {
if (useAliyunMirror) {
maven {
it.url = project.uri("https://maven.aliyun.com/repository/public")
}
}
if (mavenCentral) {
mavenCentral()
}
if (tursom) {
maven {
it.url = project.uri("https://jmp.mvn.tursom.cn:20080/repository/maven-public")
}
}
}
fun DomainObjectCollection<Configuration>.noExpire() {
all {
it.resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
it.resolutionStrategy.cacheDynamicVersionsFor(0, TimeUnit.SECONDS)
}
}

View File

@ -0,0 +1,8 @@
gradlePlugin {
plugins {
create("ts-gradle-test") {
id = "ts-gradle-test"
implementationClass = "cn.tursom.gradle.TestPlugin"
}
}
}

View File

@ -0,0 +1,38 @@
package cn.tursom.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
class TestPlugin : Plugin<Project> {
override fun apply(target: Project) {
if (target.isTestTask()) {
target.tasks.withType(Test::class.java) {
it.jvmArgs = listOf("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}
} else {
target.excludeTest()
}
}
}
fun Project.excludeTest() {
try {
tasks.run {
named("test") { it.enabled = false }
named("testClasses") { it.enabled = false }
named("compileTestJava") { it.enabled = false }
try {
named("compileTestKotlin") { it.enabled = false }
} catch (_: Exception) {
}
named("processTestResources") { it.enabled = false }
}
} catch (e: Exception) {
println("W: exclude tests failed with ${e.javaClass.name}: ${e.message}")
}
}
fun Project.isTestTask() = gradle.startParameter.taskNames.any { taskName ->
taskName.contains("test", true)
}

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-coroutine"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-buffer"))

View File

@ -1,7 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
val brotliVersion = "1.7.1"
val operatingSystem: OperatingSystem =
org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem()

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":ts-core"))
api(project(":ts-core:ts-buffer"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":ts-core"))
api(project(":ts-core:ts-buffer"))