-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle.kts
184 lines (140 loc) · 5.15 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
@file:Suppress("PropertyName", "LocalVariableName")
plugins {
id("org.jetbrains.intellij") version "1.16.0"
java
id("org.jetbrains.grammarkit") version "2022.3.1"
// todo id("org.jetbrains.changelog") version "2.1.0"
kotlin("jvm") version "1.8.22" // sync with version below
}
group = "com.github.oowekyala"
version = "1.12.3"
val IntellijVersion = "231.9011.34" // note: "since" version should be updated manually in plugin.xml
val KotlinVersion = "1.8.22"
val JvmTarget = "17"
val PackageRoot = "/com/github/oowekyala/ijcc"
val PathToPsiRoot = "$PackageRoot/lang/psi"
repositories {
mavenCentral()
maven("https://www.jetbrains.com/intellij-repository/releases")
maven("https://cache-redirector.jetbrains.com/intellij-dependencies")
}
project.ext(configure = {
// creates secret properties
set("intellijPublishToken", "")
if (projectDir.resolve("secrets.properties").exists())
apply(from = "secrets.properties")
})
sourceSets {
main {
java {
srcDirs("$buildDir/gen")
srcDirs("src/main/kotlin")
srcDirs("src/main/java")
}
}
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5")
implementation(kotlin("reflect")) // this could be avoided
// this is for tests
testImplementation("com.github.oowekyala.treeutils:tree-matchers:2.0.2")
testImplementation("io.kotest:kotest-runner-junit5:5.6.2")
testImplementation(kotlin("test"))
constraints {
testImplementation("org.jetbrains.kotlin:kotlin-stdlib:$KotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-reflect:$KotlinVersion")
}
}
tasks {
val GenerationTaskGroup = "Code generation"
generateParser {
group = GenerationTaskGroup
description = "Generate the parser and PSI hierarchy"
sourceFile.set(file("src/main/grammars/JavaCC.bnf"))
targetRoot.set("$buildDir/gen")
pathToParser.set("$PackageRoot/lang/parser/JavaccParser.java")
pathToPsiRoot.set(PathToPsiRoot)
purgeOldFiles.set(true)
doLast {
// Eliminate the duplicate PSI classes found in the generated and main source tree
val deletedNames = listOf("JccRegularExpressionOwnerImpl.java")
fun getPsiFiles(root: String): FileCollection {
val psiInterfaces = "$root$PathToPsiRoot"
val psiImpl = "$psiInterfaces/impl"
return layout.files(file(psiInterfaces).listFiles()) + layout.files(file(psiImpl).listFiles())
}
val userPsiFiles = getPsiFiles("src/main/kotlin").map { it.nameWithoutExtension }
val genPsiFileDups = getPsiFiles("$buildDir/gen").filter { genFile ->
// in this source tree they're .java
genFile.isFile && (userPsiFiles.any { it == genFile.nameWithoutExtension } || genFile.name in deletedNames)
}
logger.info("Detected ${genPsiFileDups.count()} generated PSI files overridden by sources in the main source tree:")
genPsiFileDups.sorted().forEach { logger.info(it.name) }
delete(genPsiFileDups)
logger.info("Deleted.")
}
}
generateLexer {
group = GenerationTaskGroup
description = "Generate the JFlex lexer used by the parser"
sourceFile.set(file("src/main/grammars/JavaCC.flex"))
targetDir.set("$buildDir/gen/com/github/oowekyala/ijcc/lang/lexer")
targetClass.set("JavaccLexer")
purgeOldFiles.set(true)
}
compileJava {
dependsOn(generateParser, generateLexer)
sourceCompatibility = JvmTarget
targetCompatibility = JvmTarget
}
compileTestJava {
sourceCompatibility = JvmTarget
targetCompatibility = JvmTarget
}
compileKotlin {
dependsOn(generateParser, generateLexer)
kotlinOptions {
freeCompilerArgs = listOf(
"-Xjvm-default=all"
)
jvmTarget = JvmTarget
}
}
compileTestKotlin {
kotlinOptions.jvmTarget = JvmTarget
}
test {
testLogging {
events("failed")
setExceptionFormat("full")
}
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version.set(IntellijVersion)
updateSinceUntilBuild.set(false)
//ideaDependencyCachePath.set("deps")
plugins.set(listOf("com.intellij.java"))
}
runIde {
// this launches in the sandbox subdir
jvmArgs = listOf(
"-Xmx2G",
"-XX:+UnlockDiagnosticVMOptions"
)
configDir.set(rootProject.projectDir.resolve("sandbox").resolve("config"))
}
buildPlugin {
archiveVersion.set(project.version.toString())
archiveBaseName.set("intellij-javacc")
}
publishPlugin {
token.set(project.property("intellijPublishToken") as String)
}
patchPluginXml {
changeNotes.set(provider {
layout.files("changelog.html").singleFile.readText()
})
}
}