forked from JuliaEditorSupport/julia-intellij
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
196 lines (172 loc) · 5.22 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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.*
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.3.2"
val pluginVersion = if (isCI) "$pluginComingVersion-$commitHash" else pluginComingVersion
val packageName = "org.ice1000.julia"
val kotlinVersion = "1.2.70"
group = packageName
version = pluginVersion
plugins {
java
id("org.jetbrains.intellij") version "0.3.11"
id("org.jetbrains.grammarkit") version "2018.2"
kotlin("jvm") version "1.2.70"
}
allprojects {
apply { plugin("org.jetbrains.grammarkit") }
intellij {
updateSinceUntilBuild = false
instrumentCode = true
when (System.getProperty("user.name")) {
"ice1000" -> {
val root = "/home/ice1000/.local/share/JetBrains/Toolbox/apps"
localPath = "$root/IDEA-U/ch-0/182.4505.22"
alternativeIdePath = "$root/PyCharm-C/ch-0/182.4505.26"
}
"hoshino" -> version = "2018.2.1"
/*"zh"*/ else -> version = "2018.2"
}
// local developing (!isCI)
if (!isCI) {
setPlugins("org.intellij.plugins.markdown:182.2371")
} else {
setMarkdownCompileOnly()
}
}
}
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/description.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", "julia", "lang")!!
val lexerRoot = Paths.get("gen", "org", "ice1000", "julia", "lang")!!
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("julia")
targetRoot = "gen/"
pathToParser = path(parserRoot + "JuliaParser.java")
pathToPsiRoot = path(parserRoot + "psi")
purgeOldFiles = true
}
val genLexer = task<GenerateLexer>("genLexer") {
group = genParser.group
description = "Generate the Lexer"
source = flex("julia")
targetDir = path(lexerRoot)
targetClass = "JuliaLexer"
purgeOldFiles = true
}
val genDocfmtParser = task<GenerateParser>("genDocfmtParser") {
group = genParser.group
description = "Generate the Parser for DocumentFormat.jl"
source = bnf("docfmt")
targetRoot = "gen/"
val root = parserRoot + "docfmt"
pathToParser = path(root + "DocfmtParser.java")
pathToPsiRoot = path(root + "psi")
purgeOldFiles = true
}
val genDocfmtLexer = task<GenerateLexer>("genDocfmtLexer") {
group = genParser.group
description = "Generate the Lexer for DocumentFormat.jl"
source = flex("docfmt")
targetDir = path(lexerRoot + "docfmt")
targetClass = "DocfmtLexer"
purgeOldFiles = true
}
val cleanGenerated = task("cleanGenerated") {
group = tasks["clean"].group
description = "Remove all generated codes"
doFirst { delete("gen") }
}
tasks.withType<KotlinCompile> {
dependsOn(
genParser,
genLexer,
genDocfmtParser,
genDocfmtLexer
)
kotlinOptions {
jvmTarget = "1.8"
languageVersion = "1.2"
apiVersion = "1.2"
freeCompilerArgs = listOf("-Xjvm-default=enable")
}
}
tasks.withType<Delete> { dependsOn(cleanGenerated) }
fun setMarkdownCompileOnly() {
repositories {
maven("https://dl.bintray.com/jetbrains/markdown/")
}
dependencies {
compileOnly("org.jetbrains", "markdown", "0.1.28")
}
}