88 * MIT License
99 */
1010
11+ import java.io.ByteArrayOutputStream
1112import org.cadixdev.gradle.licenser.LicenseExtension
1213import org.gradle.api.JavaVersion
1314import org.gradle.api.Project
@@ -30,14 +31,19 @@ fun Project.lexer(flex: String, pack: String): TaskDelegate<JavaExec> {
3031 val src = layout.projectDirectory.file(" src/main/grammars/$flex .flex" )
3132 val dst = layout.buildDirectory.dir(" gen/$pack " )
3233 val output = layout.buildDirectory.file(" gen/$pack /$flex .java" )
34+ val logOutout = layout.buildDirectory.file(" logs/generate$flex .log" )
3335
3436 val jflex by project.configurations
3537 val jflexSkeleton by project.configurations
3638
3739 classpath = jflex
3840 mainClass.set(" jflex.Main" )
3941
40- doFirst {
42+ val taskOutput = ByteArrayOutputStream ()
43+ standardOutput = taskOutput
44+ errorOutput = taskOutput
45+
46+ doFirst {
4147 args(
4248 " --skel" , jflexSkeleton.singleFile.absolutePath,
4349 " -d" , dst.get().asFile.absolutePath,
@@ -46,6 +52,11 @@ fun Project.lexer(flex: String, pack: String): TaskDelegate<JavaExec> {
4652
4753 // Delete current lexer
4854 project.delete(output)
55+ logOutout.get().asFile.parentFile.mkdirs()
56+ }
57+
58+ doLast {
59+ logOutout.get().asFile.writeBytes(taskOutput.toByteArray())
4960 }
5061
5162 inputs.files(src, jflexSkeleton)
@@ -64,12 +75,13 @@ fun Project.parser(bnf: String, pack: String): TaskDelegate<JavaExec> {
6475 val dst = dstRoot.map { it.dir(pack) }
6576 val psiDir = dst.map { it.dir(" psi" ) }
6677 val parserDir = dst.map { it.dir(" parser" ) }
78+ val logOutout = layout.buildDirectory.file(" logs/generate$bnf .log" )
6779
6880 val grammarKit by project.configurations
6981
70- doFirst {
71- project.delete(psiDir, parserDir)
72- }
82+ val taskOutput = ByteArrayOutputStream ()
83+ standardOutput = taskOutput
84+ errorOutput = taskOutput
7385
7486 classpath = grammarKit
7587 mainClass.set(" org.intellij.grammar.Main" )
@@ -83,7 +95,12 @@ fun Project.parser(bnf: String, pack: String): TaskDelegate<JavaExec> {
8395 }
8496
8597 doFirst {
98+ project.delete(psiDir, parserDir)
8699 args(dstRoot.get().asFile, src.asFile)
100+ logOutout.get().asFile.parentFile.mkdirs()
101+ }
102+ doLast {
103+ logOutout.get().asFile.writeBytes(taskOutput.toByteArray())
87104 }
88105
89106 inputs.file(src)
0 commit comments