-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathParserExec.kt
91 lines (75 loc) · 2.66 KB
/
ParserExec.kt
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
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2025 minecraft-dev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3.0 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import java.io.ByteArrayOutputStream
import javax.inject.Inject
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
@CacheableTask
abstract class ParserExec : JavaExec() {
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val sourceFile: RegularFileProperty
@get:Classpath
abstract val grammarKit: ConfigurableFileCollection
@get:Internal
abstract val destinationRootDirectory: DirectoryProperty
@get:OutputDirectory
abstract val psiDirectory: DirectoryProperty
@get:OutputDirectory
abstract val parserDirectory: DirectoryProperty
@get:Internal
abstract val logFile: RegularFileProperty
@get:Inject
abstract val fs: FileSystemOperations
init {
mainClass.set("org.intellij.grammar.Main")
@Suppress("LeakingThis")
jvmArgs(
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED"
)
}
override fun exec() {
classpath = grammarKit
args(
destinationRootDirectory.get().asFile,
sourceFile.get().asFile
)
fs.delete { delete(psiDirectory, parserDirectory) }
val taskOutput = ByteArrayOutputStream()
standardOutput = taskOutput
errorOutput = taskOutput
super.exec()
val log = logFile.get().asFile
log.parentFile.mkdirs()
log.writeBytes(taskOutput.toByteArray())
}
}