This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
105 lines (89 loc) · 3.02 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.util.*
plugins {
kotlin("jvm") version "1.3.71"
java
id("com.github.johnrengelman.shadow") version "5.2.0"
}
group = "top.shine5402"
version = "0.2.2"
repositories {
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
mavenCentral()
jcenter()
}
val miraiCoreVersion = "1.1.3" // 1.1.3
val miraiConsoleVersion = "0.5.2" // 1.0-M1
dependencies {
compileOnly(kotlin("stdlib-jdk8"))
compileOnly("net.mamoe:mirai-core:$miraiCoreVersion")
compileOnly("net.mamoe:mirai-console:$miraiConsoleVersion")
testImplementation(kotlin("stdlib-jdk8"))
testImplementation("net.mamoe:mirai-core:$miraiCoreVersion")
testImplementation("net.mamoe:mirai-core-qqandroid:$miraiCoreVersion")
testImplementation("net.mamoe:mirai-console:$miraiConsoleVersion")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
val runMiraiConsole by creating(JavaExec::class.java) {
group = "mirai"
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()
.transferTo1(File("$testConsoleDir/plugins/${it.name}").apply { createNewFile() }
.outputStream())
println("Copied ${it.name}")
}
}
workingDir = File(testConsoleDir)
workingDir.mkdir()
File(workingDir, "plugins").mkdir()
removeOldVersions()
copyBuildOutput()
classpath = sourceSets["test"].runtimeClasspath
main = "mirai.RunMirai"
standardInput = System.`in`
args(miraiCoreVersion, miraiConsoleVersion)
}
}
}
@Throws(IOException::class)
fun InputStream.transferTo1(out: OutputStream): Long {
Objects.requireNonNull(out, "out")
var transferred: Long = 0
val buffer = ByteArray(8192)
var read: Int
while (this.read(buffer, 0, 8192).also { read = it } >= 0) {
out.write(buffer, 0, read)
transferred += read.toLong()
}
return transferred
}