-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
157 lines (136 loc) · 4.24 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import org.gradle.language.base.internal.plugins.CleanRule
import org.jetbrains.grammarkit.GrammarKitPluginExtension
import org.jetbrains.grammarkit.tasks.*
import org.jetbrains.intellij.tasks.PatchPluginXmlTask
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.*
import java.nio.file.*
import java.net.URL
import java.util.stream.Collectors
val isCI = !System.getenv("CI").isNullOrBlank()
val commitHash = kotlin.run {
val process: Process = Runtime.getRuntime().exec("git rev-parse --short HEAD")
process.waitFor()
@Suppress("RemoveExplicitTypeArguments")
val output = process.inputStream.use {
process.inputStream.use {
it.readBytes().let<ByteArray, String>(::String)
}
}
process.destroy()
output.trim()
}
val pluginComingVersion = "0.1"
val pluginVersion = if (isCI) "$pluginComingVersion-$commitHash" else pluginComingVersion
val packageName = "org.ice1000.slisp"
val kotlinVersion = "1.2.41"
group = packageName
version = pluginVersion
plugins {
java
id("org.jetbrains.intellij") version "0.3.5"
id("org.jetbrains.grammarkit") version "2018.1.7"
kotlin("jvm") version "1.2.41"
}
apply { plugin("org.jetbrains.grammarkit") }
configure<GrammarKitPluginExtension> {
grammarKitRelease = "2017.1.5"
}
intellij {
updateSinceUntilBuild = false
instrumentCode = true
val root = "/home/ice1000/.local/share/JetBrains/Toolbox/apps"
localPath = "$root/IDEA-U/ch-0/182.3684.101"
alternativeIdePath = "$root/PyCharm-C/ch-0/182.3684.100"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<PatchPluginXmlTask> {
changeNotes(file("res/META-INF/change-notes.html").readText())
pluginDescription(file("res/META-INF/descriptions.html").readText())
version(pluginComingVersion)
pluginId(packageName)
}
java.sourceSets {
"main" {
withConvention(KotlinSourceSet::class) {
listOf(java, kotlin).forEach { it.srcDirs("src", "gen") }
}
resources.srcDirs("res")
}
"test" {
withConvention(KotlinSourceSet::class) {
listOf(java, kotlin).forEach { it.srcDirs("test") }
}
resources.srcDirs("testData")
}
}
repositories { mavenCentral() }
dependencies {
compileOnly(kotlin("stdlib", kotlinVersion))
compile(kotlin("stdlib-jdk8", kotlinVersion).toString()) {
exclude(module = "kotlin-runtime")
exclude(module = "kotlin-reflect")
exclude(module = "kotlin-stdlib")
}
compile("org.eclipse.mylyn.github", "org.eclipse.egit.github.core", "2.1.5") {
exclude(module = "gson")
}
testCompile(kotlin("test-junit", kotlinVersion))
testCompile("junit", "junit", "4.12")
}
task("displayCommitHash") {
group = "help"
description = "Display the newest commit hash"
doFirst { println("Commit hash: $commitHash") }
}
task("isCI") {
group = "help"
description = "Check if it's running in a continuous-integration"
doFirst { println(if (isCI) "Yes, I'm on a CI." else "No, I'm not on CI.") }
}
// Don't specify type explicitly. Will be incorrectly recognized
val parserRoot = Paths.get("org", "ice1000", "slisp")!!
val lexerRoot = Paths.get("gen", "org", "ice1000", "slisp")!!
fun path(more: Iterable<*>) = more.joinToString(File.separator)
fun bnf(name: String) = Paths.get("grammar", "$name-grammar.bnf").toString()
fun flex(name: String) = Paths.get("grammar", "$name-lexer.flex").toString()
val genParser = task<GenerateParser>("genParser") {
group = tasks["init"].group
description = "Generate the Parser and PsiElement classes"
source = bnf("slisp")
targetRoot = "gen/"
pathToParser = path(parserRoot + "SLispParser.java")
pathToPsiRoot = path(parserRoot + "psi")
purgeOldFiles = true
}
val genLexer = task<GenerateLexer>("genLexer") {
group = genParser.group
description = "Generate the Lexer"
source = flex("slisp")
targetDir = path(lexerRoot)
targetClass = "SLispLexer"
purgeOldFiles = true
}
val cleanGenerated = task("cleanGenerated") {
group = tasks["clean"].group
description = "Remove all generated codes"
doFirst {
delete("gen", "pinpoint-piggy")
}
}
tasks.withType<KotlinCompile> {
dependsOn(genParser, genLexer)
kotlinOptions {
jvmTarget = "1.8"
languageVersion = "1.2"
apiVersion = "1.2"
freeCompilerArgs = listOf("-Xenable-jvm-default")
}
}
tasks.withType<Delete> {
dependsOn(cleanGenerated)
}