User: rednesto
Date: 03 Jul 24 05:15
Revision: d20f5e7f61d2f846778c86634cecdb282c8a8b9a
Summary:
Extract lexer and parser tasks into their own classes
This makes those tasks compatible with build and configuration cache
Unfortunately two other issues prevent us from using the configuration
cache, one is the licenser plugin, the other is the access of
testLibs in the test task configuration
TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9339&personal=false
Index: build.gradle.kts
===================================================================
--- build.gradle.kts (revision 9da38412022ada1eb86303c955939d4f0dee67cb)
+++ build.gradle.kts (revision d20f5e7f61d2f846778c86634cecdb282c8a8b9a)
@@ -343,7 +343,10 @@
val generateLangLexer by lexer("LangLexer", "com/demonwav/mcdev/translations/lang/gen")
val generateLangParser by parser("LangParser", "com/demonwav/mcdev/translations/lang/gen")
-val generateTranslationTemplateLexer by lexer("TranslationTemplateLexer", "com/demonwav/mcdev/translations/lang/gen")
+val generateTranslationTemplateLexer by lexer(
+ "TranslationTemplateLexer",
+ "com/demonwav/mcdev/translations/template/gen"
+)
val generate by tasks.registering {
group = "minecraft"
Index: buildSrc/src/main/kotlin/JFlexExec.kt
===================================================================
--- buildSrc/src/main/kotlin/JFlexExec.kt (revision d20f5e7f61d2f846778c86634cecdb282c8a8b9a)
+++ buildSrc/src/main/kotlin/JFlexExec.kt (revision d20f5e7f61d2f846778c86634cecdb282c8a8b9a)
@@ -0,0 +1,84 @@
+/*
+ * Minecraft Development for IntelliJ
+ *
+ * https://mcdev.io/
+ *
+ * Copyright (C) 2024 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 .
+ */
+
+import java.io.ByteArrayOutputStream
+import javax.inject.Inject
+import org.gradle.api.file.ConfigurableFileCollection
+import org.gradle.api.file.ConfigurableFileTree
+import org.gradle.api.file.DirectoryProperty
+import org.gradle.api.file.FileCollection
+import org.gradle.api.file.FileSystemOperations
+import org.gradle.api.file.RegularFileProperty
+import org.gradle.api.tasks.InputFile
+import org.gradle.api.tasks.InputFiles
+import org.gradle.api.tasks.Internal
+import org.gradle.api.tasks.JavaExec
+import org.gradle.api.tasks.OutputDirectory
+import org.gradle.api.tasks.OutputFile
+
+abstract class JFlexExec : JavaExec() {
+
+ @get:InputFile
+ abstract val sourceFile: RegularFileProperty
+
+ @get:InputFiles
+ abstract val jflex: ConfigurableFileCollection
+
+ @get:InputFile
+ abstract val skeletonFile: RegularFileProperty
+
+ @get:OutputDirectory
+ abstract val destinationDirectory: DirectoryProperty
+
+ @get:OutputFile
+ abstract val destinationFile: RegularFileProperty
+
+ @get:Internal
+ abstract val logFile: RegularFileProperty
+
+ @get:Inject
+ abstract val fs: FileSystemOperations
+
+ init {
+ mainClass.set("jflex.Main")
+ }
+
+ override fun exec() {
+ classpath = jflex
+
+ args(
+ "--skel", skeletonFile.get().asFile.absolutePath,
+ "-d", destinationDirectory.get().asFile.absolutePath,
+ sourceFile.get().asFile.absolutePath
+ )
+
+ fs.delete { delete(destinationDirectory) }
+
+ val taskOutput = ByteArrayOutputStream()
+ standardOutput = taskOutput
+ errorOutput = taskOutput
+
+ super.exec()
+
+ val log = logFile.get().asFile
+ log.parentFile.mkdirs()
+ log.writeBytes(taskOutput.toByteArray())
+ }
+}
Index: buildSrc/src/main/kotlin/ParserExec.kt
===================================================================
--- buildSrc/src/main/kotlin/ParserExec.kt (revision d20f5e7f61d2f846778c86634cecdb282c8a8b9a)
+++ buildSrc/src/main/kotlin/ParserExec.kt (revision d20f5e7f61d2f846778c86634cecdb282c8a8b9a)
@@ -0,0 +1,88 @@
+/*
+ * Minecraft Development for IntelliJ
+ *
+ * https://mcdev.io/
+ *
+ * Copyright (C) 2024 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 .
+ */
+
+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.InputFile
+import org.gradle.api.tasks.InputFiles
+import org.gradle.api.tasks.Internal
+import org.gradle.api.tasks.JavaExec
+import org.gradle.api.tasks.OutputDirectory
+
+abstract class ParserExec : JavaExec() {
+
+ @get:InputFile
+ abstract val sourceFile: RegularFileProperty
+
+ @get:InputFiles
+ abstract val grammarKit: ConfigurableFileCollection
+
+ @get:OutputDirectory
+ abstract val destinationRootDirectory: DirectoryProperty
+
+ @get:OutputDirectory
+ abstract val destinationDirectory: 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")
+
+ 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())
+ }
+}
Index: buildSrc/src/main/kotlin/util.kt
===================================================================
--- buildSrc/src/main/kotlin/util.kt (revision 9da38412022ada1eb86303c955939d4f0dee67cb)
+++ buildSrc/src/main/kotlin/util.kt (revision d20f5e7f61d2f846778c86634cecdb282c8a8b9a)
@@ -32,96 +32,44 @@
typealias TaskDelegate = RegisteringDomainObjectDelegateProviderWithTypeAndAction
-fun Project.lexer(flex: String, pack: String): TaskDelegate {
+fun Project.lexer(flex: String, pack: String): TaskDelegate {
configure {
exclude(pack.removeSuffix("/") + "/**")
}
- return tasks.registering(JavaExec::class) {
- val src = layout.projectDirectory.file("src/main/grammars/$flex.flex")
- val dst = layout.buildDirectory.dir("gen/$pack")
- val output = layout.buildDirectory.file("gen/$pack/$flex.java")
- val logOutout = layout.buildDirectory.file("logs/generate$flex.log")
+ return tasks.registering(JFlexExec::class) {
+ sourceFile.set(layout.projectDirectory.file("src/main/grammars/$flex.flex"))
+ destinationDirectory.set(layout.buildDirectory.dir("gen/$pack"))
+ destinationFile.set(layout.buildDirectory.file("gen/$pack/$flex.java"))
+ logFile.set(layout.buildDirectory.file("logs/generate$flex.log"))
val jflex by project.configurations
- val jflexSkeleton by project.configurations
+ this.jflex.setFrom(jflex)
- classpath = jflex
- mainClass.set("jflex.Main")
-
- val taskOutput = ByteArrayOutputStream()
- standardOutput = taskOutput
- errorOutput = taskOutput
-
- doFirst {
- args(
- "--skel", jflexSkeleton.singleFile.absolutePath,
- "-d", dst.get().asFile.absolutePath,
- src.asFile.absolutePath
- )
-
- // Delete current lexer
- project.delete(output)
- logOutout.get().asFile.parentFile.mkdirs()
+ val jflexSkeleton by project.configurations
+ skeletonFile.set(jflexSkeleton.singleFile)
- }
+ }
-
- doLast {
- logOutout.get().asFile.writeBytes(taskOutput.toByteArray())
- }
+}
- inputs.files(src, jflexSkeleton)
- outputs.file(output)
- }
-}
-
-fun Project.parser(bnf: String, pack: String): TaskDelegate {
+fun Project.parser(bnf: String, pack: String): TaskDelegate {
configure {
exclude(pack.removeSuffix("/") + "/**")
}
- return tasks.registering(JavaExec::class) {
- val src = project.layout.projectDirectory.file("src/main/grammars/$bnf.bnf")
- val dstRoot = project.layout.buildDirectory.dir("gen")
- val dst = dstRoot.map { it.dir(pack) }
- val psiDir = dst.map { it.dir("psi") }
- val parserDir = dst.map { it.dir("parser") }
- val logOutout = layout.buildDirectory.file("logs/generate$bnf.log")
+ return tasks.registering(ParserExec::class) {
+ val destRoot = project.layout.buildDirectory.dir("gen")
+ val dest = destRoot.map { it.dir(pack) }
+ sourceFile.set(project.layout.projectDirectory.file("src/main/grammars/$bnf.bnf"))
+ destinationRootDirectory.set(destRoot)
+ destinationDirectory.set(dest)
+ psiDirectory.set(dest.map { it.dir("psi") })
+ parserDirectory.set(dest.map { it.dir("parser") })
+ logFile.set(layout.buildDirectory.file("logs/generate$bnf.log"))
val grammarKit by project.configurations
-
- val taskOutput = ByteArrayOutputStream()
- standardOutput = taskOutput
- errorOutput = taskOutput
-
- classpath = grammarKit
- mainClass.set("org.intellij.grammar.Main")
-
- if (JavaVersion.current().isJava9Compatible) {
- 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"
- )
+ this.grammarKit.setFrom(grammarKit)
- }
+ }
-
- doFirst {
- project.delete(psiDir, parserDir)
- args(dstRoot.get().asFile, src.asFile)
- logOutout.get().asFile.parentFile.mkdirs()
- }
+}
- doLast {
- logOutout.get().asFile.writeBytes(taskOutput.toByteArray())
- }
- inputs.file(src)
- outputs.dirs(
- mapOf(
- "psi" to psiDir,
- "parser" to parserDir
- )
- )
- }
-}
-
data class DepList(val intellijVersion: String, val intellijVersionName: String, val deps: List)
data class Dep(val groupId: String, val artifactId: String, val version: String)
Index: src/main/grammars/TranslationTemplateLexer.flex
===================================================================
--- src/main/grammars/TranslationTemplateLexer.flex (revision 9da38412022ada1eb86303c955939d4f0dee67cb)
+++ src/main/grammars/TranslationTemplateLexer.flex (revision d20f5e7f61d2f846778c86634cecdb282c8a8b9a)
@@ -18,7 +18,7 @@
* along with this program. If not, see .
*/
-package com.demonwav.mcdev.translations.lang.gen;
+package com.demonwav.mcdev.translations.template.gen;
import com.intellij.lexer.*;
import com.intellij.psi.tree.IElementType;
Index: src/main/kotlin/translations/sorting/TranslationTemplateLexerAdapter.kt
===================================================================
--- src/main/kotlin/translations/sorting/TranslationTemplateLexerAdapter.kt (revision 9da38412022ada1eb86303c955939d4f0dee67cb)
+++ src/main/kotlin/translations/sorting/TranslationTemplateLexerAdapter.kt (revision d20f5e7f61d2f846778c86634cecdb282c8a8b9a)
@@ -20,7 +20,7 @@
package com.demonwav.mcdev.translations.sorting
-import com.demonwav.mcdev.translations.lang.gen.TranslationTemplateLexer
+import com.demonwav.mcdev.translations.template.gen.TranslationTemplateLexer
import com.intellij.lexer.FlexAdapter
class TranslationTemplateLexerAdapter : FlexAdapter(TranslationTemplateLexer())