-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rearrange project, move embedded branch into master.
- Loading branch information
1 parent
deae311
commit 4c2931d
Showing
38 changed files
with
459 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,143 +1,21 @@ | ||
plugins { | ||
java | ||
kotlin("jvm") version "1.4.0" | ||
kotlin("plugin.serialization") version "1.4.0" | ||
kotlin("kapt") version "1.4.0" | ||
java | ||
id("com.github.johnrengelman.shadow") version "6.0.0" | ||
id("com.github.gmazzo.buildconfig") version "2.0.2" | ||
} | ||
|
||
val projectVersion = "0.3.0" | ||
version = projectVersion | ||
group = "yyuueexxiinngg" | ||
|
||
repositories { | ||
maven(url = "https://mirrors.huaweicloud.com/repository/maven") | ||
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap") | ||
gradlePluginPortal() | ||
jcenter() | ||
mavenCentral() | ||
} | ||
|
||
val miraiCoreVersion = "1.3.3" | ||
val miraiConsoleVersion = "1.0-RC-1" | ||
val ktorVersion = "1.4.1" | ||
val kotlinVersion = "1.4.0" | ||
val kotlinSerializationVersion = "1.0.1" | ||
val autoService = "1.0-rc7" | ||
|
||
fun ktor(id: String, version: String = this@Build_gradle.ktorVersion) = "io.ktor:ktor-$id:$version" | ||
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version" | ||
fun String.runCommand(workingDir: File): String? { | ||
return try { | ||
val parts = this.split("\\s".toRegex()) | ||
val proc = ProcessBuilder(*parts.toTypedArray()) | ||
.directory(workingDir) | ||
.redirectOutput(ProcessBuilder.Redirect.PIPE) | ||
.redirectError(ProcessBuilder.Redirect.PIPE) | ||
.start() | ||
|
||
proc.waitFor(60, TimeUnit.MINUTES) | ||
proc.inputStream.bufferedReader().readText().trim() | ||
} catch (e: java.io.IOException) { | ||
e.printStackTrace() | ||
null | ||
} | ||
} | ||
|
||
dependencies { | ||
kapt("com.google.auto.service", "auto-service", autoService) | ||
|
||
compileOnly(kotlin("stdlib-jdk8")) | ||
compileOnly("net.mamoe:mirai-core:$miraiCoreVersion") | ||
compileOnly("net.mamoe:mirai-console:$miraiConsoleVersion") | ||
compileOnly("net.mamoe:mirai-console-terminal:$miraiConsoleVersion") | ||
compileOnly(kotlin("serialization", kotlinVersion)) | ||
compileOnly("com.google.auto.service", "auto-service-annotations", autoService) | ||
|
||
implementation(kotlinx("serialization-cbor", kotlinSerializationVersion)) | ||
implementation(kotlinx("serialization-json", kotlinSerializationVersion)) | ||
implementation("ch.qos.logback:logback-classic:1.2.3") | ||
implementation("com.google.code.gson:gson:2.8.6") | ||
|
||
api(ktor("server-cio")) | ||
api(ktor("client-okhttp")) | ||
api(ktor("websockets")) | ||
api(ktor("client-websockets")) | ||
api(kotlin("reflect", kotlinVersion)) | ||
|
||
testImplementation(kotlin("stdlib-jdk8")) | ||
testImplementation("net.mamoe:mirai-core:$miraiCoreVersion") | ||
testImplementation("net.mamoe:mirai-core-qqandroid:$miraiCoreVersion") | ||
testImplementation("net.mamoe:mirai-console:$miraiConsoleVersion") | ||
testImplementation("net.mamoe:mirai-console-terminal:$miraiConsoleVersion") | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
tasks { | ||
compileKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
kotlinOptions.freeCompilerArgs = listOf("-Xjvm-default=all") | ||
} | ||
compileTestKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
kotlinOptions.freeCompilerArgs = listOf("-Xjvm-default=all") | ||
} | ||
|
||
buildConfig { | ||
val commitHash = "git rev-parse --short HEAD".runCommand(projectDir) | ||
buildConfigField("String", "VERSION", "\"$projectVersion\"") | ||
if (commitHash != null) { buildConfigField("String", "COMMIT_HASH", "\"$commitHash\"") } | ||
} | ||
|
||
shadowJar { | ||
dependsOn(generateBuildConfig) | ||
} | ||
|
||
val runMiraiConsole by creating(JavaExec::class.java) { | ||
group = "mirai" | ||
main = "mirai.RunMirai" | ||
dependsOn(shadowJar) | ||
dependsOn(testClasses) | ||
|
||
val testConsoleDir = "test" | ||
|
||
doFirst { | ||
fun removeOldVersions() { | ||
File("$testConsoleDir/plugins/").walk() | ||
.filter { it.name.matches(Regex("""${project.name}-.*-all.jar""")) } | ||
.forEach { | ||
it.delete() | ||
println("deleting old files: ${it.name}") | ||
} | ||
} | ||
|
||
fun copyBuildOutput() { | ||
File("build/libs/").walk() | ||
.filter { it.name.contains("-all") } | ||
.maxBy { it.lastModified() } | ||
?.let { | ||
println("Coping ${it.name}") | ||
it.inputStream() | ||
.transferTo(File("$testConsoleDir/plugins/${it.name}").apply { createNewFile() } | ||
.outputStream()) | ||
println("Copied ${it.name}") | ||
} | ||
} | ||
|
||
workingDir = File(testConsoleDir) | ||
workingDir.mkdir() | ||
File(workingDir, "plugins").mkdir() | ||
removeOldVersions() | ||
copyBuildOutput() | ||
allprojects { | ||
group = "com.github.yyuueexxiinngg" | ||
version = Versions.projectVersion | ||
|
||
classpath = sourceSets["test"].runtimeClasspath | ||
standardInput = System.`in` | ||
args(miraiCoreVersion, miraiConsoleVersion) | ||
} | ||
repositories { | ||
maven(url = "https://mirrors.huaweicloud.com/repository/maven") | ||
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap") | ||
gradlePluginPortal() | ||
jcenter() | ||
mavenCentral() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
jcenter() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import java.io.File | ||
import java.util.concurrent.TimeUnit | ||
|
||
object Versions { | ||
const val projectVersion = "0.3.0" | ||
|
||
const val miraiCoreVersion = "1.3.3" | ||
const val miraiConsoleVersion = "1.0-RC-1" | ||
|
||
const val ktorVersion = "1.4.1" | ||
const val kotlinVersion = "1.4.0" | ||
const val kotlinSerializationVersion = "1.0.1" | ||
const val autoService = "1.0-rc7" | ||
const val logback = "1.2.3" | ||
const val gson = "2.8.6" | ||
|
||
// OneBot Kotlin | ||
const val clikt = "3.0.1" | ||
} | ||
|
||
fun ktor(id: String, version: String = Versions.ktorVersion) = "io.ktor:ktor-$id:$version" | ||
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version" | ||
|
||
fun String.runCommand(workingDir: File): String? { | ||
return try { | ||
val parts = this.split("\\s".toRegex()) | ||
val proc = ProcessBuilder(*parts.toTypedArray()) | ||
.directory(workingDir) | ||
.redirectOutput(ProcessBuilder.Redirect.PIPE) | ||
.redirectError(ProcessBuilder.Redirect.PIPE) | ||
.start() | ||
|
||
proc.waitFor(60, TimeUnit.MINUTES) | ||
proc.inputStream.bufferedReader().readText().trim() | ||
} catch (e: java.io.IOException) { | ||
e.printStackTrace() | ||
null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
plugins { | ||
java | ||
kotlin("jvm") | ||
id("com.github.johnrengelman.shadow") | ||
} | ||
|
||
dependencies { | ||
implementation(kotlin("stdlib-jdk8")) | ||
implementation("net.mamoe:mirai-core:${Versions.miraiCoreVersion}") | ||
implementation("net.mamoe:mirai-core-qqandroid:${Versions.miraiCoreVersion}") | ||
implementation("net.mamoe:mirai-console:${Versions.miraiConsoleVersion}") | ||
implementation("net.mamoe:mirai-console-terminal:${Versions.miraiConsoleVersion}") | ||
implementation("com.github.ajalt.clikt:clikt:${Versions.clikt}") | ||
|
||
implementation(project(":onebot-mirai")) | ||
} | ||
|
||
val jar by tasks.getting(Jar::class) { | ||
manifest { | ||
attributes["Main-Class"] = "com.github.yyuueexxiinngg.onebot.MainKt" | ||
} | ||
} | ||
|
||
tasks { | ||
val runEmbedded by creating(JavaExec::class.java) { | ||
group = "onebot-kotlin" | ||
main = "com.github.yyuueexxiinngg.onebot.MainKt" | ||
workingDir = File("../test") | ||
dependsOn(shadowJar) | ||
dependsOn(testClasses) | ||
doFirst { | ||
classpath = sourceSets["test"].runtimeClasspath | ||
standardInput = System.`in` | ||
args("--backend", "mirai") | ||
} | ||
} | ||
} | ||
|
||
kotlin.sourceSets.all { | ||
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn") | ||
} | ||
|
||
kotlin.target.compilations.all { | ||
kotlinOptions.freeCompilerArgs += "-Xjvm-default=enable" | ||
kotlinOptions.jvmTarget = "1.8" | ||
} |
Oops, something went wrong.