-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.gradle.kts
384 lines (348 loc) · 10.2 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
plugins {
java
antlr
jacoco
pmd
checkstyle
`maven-publish`
signing
id("io.spring.dependency-management") version "1.1.0"
id("org.jlleitschuh.gradle.ktlint") version "11.1.0"
// id("org.cqfn.diktat.diktat-gradle-plugin") version "1.0.2"
kotlin("jvm") version "1.8.10"
id("com.github.dawnwords.jacoco.badge") version "0.2.4"
}
val mvnUsername: String? by project
val mvnPassword: String? by project
val mvnPublicationVersion: String? by project
val candidates: String? by project
val amount: String? by project
group = "org.polystat"
version = mvnPublicationVersion ?: "0.6.0"
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "11"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "11"
}
// The Java grammar source file for ANTLR
val javaParserG4FilePath = "grammar/JavaParser.g4"
val javaLexerG4FilePath = "grammar/JavaLexer.g4"
// Where to put generated parser
val javaParserSavePath = "src/main/java/org/polystat/j2eo/antlrParser"
val antlrJar = "antlr-4.9.2-complete.jar"
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom("com.jcabi:parent:0.57.0")
}
}
dependencies {
// Library for command-line arguments support
implementation("commons-cli:commons-cli:1.5.0")
// Functional stuff
implementation("io.arrow-kt:arrow-core:1.1.5")
// Kotlin logger
implementation("org.slf4j:slf4j-simple:2.0.7")
implementation("io.github.microutils:kotlin-logging-jvm:3.0.5")
implementation("org.junit.platform:junit-platform-commons:1.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
implementation(kotlin("stdlib-jdk8"))
// Use ANTLR for parser generation
antlr("org.antlr:antlr4:4.12.0")
implementation("org.polystat:j2ast:0.2.0")
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
withJavadocJar()
withSourcesJar()
}
tasks.javadoc {
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
}
val fatJar = task("fatJar", type = Jar::class) {
// baseName = "${project.name}-fat"
// manifest Main-Class attribute is optional.
// (Used only to provide default main class for executable jar)
manifest {
attributes["Main-Class"] = "org.polystat.j2eo.main.Main2" // fully qualified class name of default main class
}
// Include dependencies
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
with(tasks["jar"] as CopySpec)
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks {
compileKotlin {
dependsOn(generateGrammarSource)
}
compileTestKotlin {
dependsOn(generateTestGrammarSource)
}
runKtlintFormatOverMainSourceSet {
dependsOn(generateGrammarSource)
}
runKtlintFormatOverTestSourceSet {
dependsOn(generateTestGrammarSource)
}
classes {
dependsOn(ktlintFormat)
}
ktlintFormat {
finalizedBy(ktlintCheck)
}
// diktatFix {
// finalizedBy(diktatCheck)
// }
pmdMain {
dependsOn(classes)
}
checkstyleMain {
dependsOn(classes)
}
pmdTest {
dependsOn(testClasses)
}
checkstyleTest {
dependsOn(testClasses)
}
jacocoTestReport {
dependsOn(test)
finalizedBy(generateJacocoBadge)
}
test {
dependsOn(pmdTest, checkstyleTest)
finalizedBy(jacocoTestReport)
}
build {
dependsOn(fatJar)
}
}
tasks.withType(JavaCompile::class).configureEach {
options.forkOptions.jvmArgs!!.addAll(
arrayOf(
"--add-opens", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED"
)
)
}
tasks.javadoc {
exclude("parser/**")
}
tasks.test {
ignoreFailures = true
useJUnitPlatform()
systemProperty("candidates", candidates ?: "false")
systemProperty("amount", amount ?: "15")
}
pmd {
isIgnoreFailures = true
isConsoleOutput = false
toolVersion = "6.55.0"
rulesMinimumPriority.set(5)
ruleSets = listOf("category/java/codestyle.xml")
}
ktlint {
verbose.set(true)
outputToConsole.set(true)
coloredOutput.set(true)
ignoreFailures.set(false)
reporters {
reporter(ReporterType.CHECKSTYLE)
reporter(ReporterType.JSON)
reporter(ReporterType.HTML)
}
filter {
exclude("**/style-violations.kt")
}
}
// diktat {
// reporterType = "sarif"
// ignoreFailures = true
// }
tasks.getByName("build") {
println("Building parser with ANTLR...")
runAntlr()
}
checkstyle {
toolVersion = "9.3"
isShowViolations = false
isIgnoreFailures = false
}
tasks.withType<Checkstyle>().configureEach {
reports {
xml.required.set(false)
html.required.set(true)
html.stylesheet = resources.text.fromFile("config/xsl/checkstyle-simple.xsl")
}
}
tasks.withType<JacocoCoverageVerification> {
/*violationRules {
rule {
limit {
minimum = BigDecimal(0.62)
}
}
}*/
afterEvaluate {
classDirectories.setFrom(
files(
classDirectories.files.map {
fileTree(it).apply {
exclude("parser/**")
}
}
)
)
}
}
tasks.withType<JacocoReport> {
afterEvaluate {
classDirectories.setFrom(
files(
classDirectories.files.map {
fileTree(it).apply {
exclude("parser/**")
}
}
)
)
}
reports.csv.required.set(true)
}
tasks.jacocoTestReport {
reports {
xml.required.set(true)
}
}
jacocoBadgeGenSetting {
jacocoReportPath = "$buildDir/reports/jacoco/test/jacocoTestReport.xml"
readmePath = "$projectDir/README.md"
// since v0.2.0, percentage limitation (0-100) for different type of coverage
// limit = ['instruction': 0, 'branch': 0, 'line': 0, 'method': 0, 'class': 0]
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = "org.polystat"
artifactId = "j2eo"
version = project.version as String
from(components["java"])
pom {
name.set("j2eo")
description.set("Java to EO transpiler.")
url.set("https://github.com/polystat/j2eo")
// properties.set(mapOf(
// "myProp" to "value",
// "prop.with.dots" to "anotherValue"
// ))
licenses {
license {
name.set("MIT")
url.set("https://github.com/polystat/polystat/blob/master/LICENSE.txt")
}
}
developers {
developer {
id.set("zouev")
name.set("Eugene Zouev")
email.set("[email protected]")
}
developer {
id.set("IamMaxim58")
name.set("Maxim Stepanov")
email.set("[email protected]")
}
developer {
id.set("Ilia_Mil")
name.set("Ilya Milyoshin")
email.set("[email protected]")
}
developer {
id.set("egorklementev")
name.set("Egor Klementev")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:[email protected]:polystat/polystat.git")
developerConnection.set("scm:git:[email protected]:polystat/polystat.git")
url.set("https://github.com/polystat/polystat")
}
}
repositories {
maven {
credentials {
println("Applying Maven credentials")
username = mvnUsername
password = mvnPassword
}
url = uri("https://s01.oss.sonatype.org/content/repositories/releases/")
}
}
}
}
}
signing {
setRequired({
gradle.taskGraph.hasTask("publish")
})
sign(publishing.publications["mavenJava"])
}
tasks.getByName("signMavenJavaPublication") {
dependsOn(fatJar)
}
/**
* Runs ANTLR using OS-specific shell command.
*/
fun runAntlr() {
val antlrArgs = mutableListOf(
"-jar",
"../$antlrJar",
javaParserG4FilePath.replace("grammar/", ""),
javaLexerG4FilePath.replace("grammar/", ""),
"-visitor",
"-o",
"../$javaParserSavePath"
)
try {
when {
Os.isFamily(Os.FAMILY_WINDOWS) ->
exec {
workingDir = File("grammar")
executable = "java"
args = antlrArgs
}
Os.isFamily(Os.FAMILY_MAC) ->
exec {
workingDir = File("grammar")
executable = "java"
args = antlrArgs
}
Os.isFamily(Os.FAMILY_UNIX) ->
exec {
workingDir = File("grammar")
executable = "java"
args = antlrArgs
}
else ->
throw UnsupportedOperationException(
"Your OS is not yet supported. File a GitHub or issue or " +
"provide a Pull Request with support for ANTLR execution for your OS."
)
}
} catch (e: Exception) {
println("Couldn't run ANTLR; $e")
}
}