-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
110 lines (97 loc) · 3.25 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
106
107
108
109
110
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
plugins {
java
val kotlinVersion = "1.9.0"
id("org.jetbrains.kotlin.jvm") version kotlinVersion apply false
}
fun printOutput(output: CharSequence): Task {
return tasks.create("printOutput") {
println("#educational_plugin_checker_version 1")
val separator = System.lineSeparator()
val lines = output.toString().split("(?<=$separator)|(?=$separator)")
for (line in lines) {
println("#educational_plugin$line")
}
}
}
subprojects {
apply(plugin = "java")
apply(plugin = "kotlin")
repositories {
mavenCentral()
}
sourceSets {
main {
java.srcDir("src")
}
test {
java.srcDir("test")
}
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
}
tasks {
withType<JavaCompile> {
sourceCompatibility = "11"
targetCompatibility = "11"
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
withType<Test> {
useJUnitPlatform()
outputs.upToDateWhen { false }
addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(testDescriptor: TestDescriptor) {}
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
if (result.resultType == TestResult.ResultType.FAILURE) {
val message = result.exception?.message ?: "Wrong answer"
val lines = message.lines()
println("#educational_plugin FAILED + ${lines[0]}")
lines.subList(1, lines.size).forEach { line ->
println("#educational_plugin$line")
}
// we need this to separate output of different tests
println()
}
}
override fun afterSuite(suite: TestDescriptor, result: TestResult) {}
})
}
}
if (project.hasProperty("educationalRun") && "true" == project.property("educationalRun").toString()
.toLowerCaseAsciiOnly()
) {
val runOutput = StringBuilder()
tasks {
named("run") {
logging.addStandardOutputListener {
runOutput.append(it)
}
doLast {
printOutput(runOutput.toString())
}
}
}
}
}
project(":util") {
dependencies {
implementation("org.junit.jupiter:junit-jupiter:5.8.2")
}
}
configure(subprojects.filter { it.name != "util" }) {
dependencies {
testImplementation(project(":util"))
tasks.register("buildTaskMD") {
val templateFile = File(projectDir, "task_template.md")
val targetFile = File(projectDir, "task.md")
if (templateFile.exists()) {
ResolveTemplate.resolveTemplate(templateFile, targetFile, rootDir)
}
}
}
}