Skip to content

Commit 6c1986b

Browse files
committed
fix(model-api-gen): disable ModelQL generation by default
The generated code requires a dependency on the ModelQL runtime which breaks existing projects. You now have to specify a 'modelqlKotlinDir' to enable the generator which is also useful if you have to split the generated API classes into a separate subproject because of Kotlin compiler memory usage.
1 parent 16a361c commit 6c1986b

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

model-api-gen-gradle-test/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ metamodel {
9191
dependsOn(resolveMps)
9292
mpsHome = mpsDir
9393
kotlinDir = kotlinGenDir
94+
modelqlKotlinDir = kotlinGenDir
9495
kotlinProject = project
9596
typescriptDir = projectDir.resolve("typescript_src")
9697
includeNamespace("jetbrains")

model-api-gen-gradle/src/main/kotlin/org/modelix/metamodel/gradle/GenerateMetaModelSources.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ abstract class GenerateMetaModelSources @Inject constructor(of: ObjectFactory) :
2020
@Optional
2121
val kotlinOutputDir: DirectoryProperty = of.directoryProperty()
2222

23+
@get:OutputDirectory
24+
@Optional
25+
val modelqlKotlinOutputDir: DirectoryProperty = of.directoryProperty()
26+
2327
@get:OutputDirectory
2428
@Optional
2529
val typescriptOutputDir: DirectoryProperty = of.directoryProperty()
@@ -79,7 +83,11 @@ abstract class GenerateMetaModelSources @Inject constructor(of: ObjectFactory) :
7983

8084
val kotlinOutputDir = this.kotlinOutputDir.orNull?.asFile
8185
if (kotlinOutputDir != null) {
82-
val generator = MetaModelGenerator(kotlinOutputDir.toPath(), nameConfig.get())
86+
val generator = MetaModelGenerator(
87+
kotlinOutputDir.toPath(),
88+
nameConfig.get(),
89+
this.modelqlKotlinOutputDir.orNull?.asFile?.toPath()
90+
)
8391
generator.generate(processedLanguages)
8492
registrationHelperName.orNull?.let {
8593
generator.generateRegistrationHelper(it, processedLanguages)

model-api-gen-gradle/src/main/kotlin/org/modelix/metamodel/gradle/MetaModelGradlePlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class MetaModelGradlePlugin: Plugin<Project> {
8686
project.afterEvaluate {
8787
generateMetaModelSources.configure { task ->
8888
settings.kotlinDir?.let { task.kotlinOutputDir.set(it) }
89+
settings.modelqlKotlinDir?.let { task.modelqlKotlinOutputDir.set(it) }
8990
settings.typescriptDir?.let { task.typescriptOutputDir.set(it) }
9091
task.includedNamespaces.addAll(settings.includedLanguageNamespaces)
9192
task.includedLanguages.addAll(settings.includedLanguages)

model-api-gen-gradle/src/main/kotlin/org/modelix/metamodel/gradle/MetaModelGradleSettings.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ open class MetaModelGradleSettings {
2020
val includedConcepts: MutableSet<String> = HashSet()
2121
val includedModules: MutableSet<String> = HashSet()
2222
var kotlinDir: File? = null
23+
var modelqlKotlinDir: File? = null
2324
var kotlinProject: Project? = null
2425
set(value) {
2526
if (kotlinDir == null && value != null) {

model-api-gen/src/main/kotlin/org/modelix/metamodel/generator/MetaModelGenerator.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.modelix.modelql.typed.TypedModelQL
1414
import java.nio.file.Path
1515
import kotlin.reflect.KClass
1616

17-
class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameConfig()) {
17+
class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameConfig(), val modelqlOutputDir: Path? = null) {
1818
var alwaysUseNonNullableProperties: Boolean = true
1919

2020
private val headerComment = "\ngenerated by modelix model-api-gen \n"
@@ -82,16 +82,18 @@ class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameC
8282
FileSpec.builder(language.generatedClassName().packageName, language.generatedClassName().simpleName)
8383
val file = builder.addFileComment(headerComment)
8484
.addType(generateLanguage(language)).build()
85+
file.write()
86+
8587
for (enum in language.getEnums()) {
8688
generateEnumFile(enum)
8789
}
90+
8891
for (concept in language.getConcepts()) {
8992
generateConceptFile(concept)
90-
if (concept.getOwnRoles().isNotEmpty()) {
93+
if (modelqlOutputDir != null && concept.getOwnRoles().isNotEmpty()) {
9194
generateModelQLFile(concept)
9295
}
9396
}
94-
file.write()
9597
}
9698
}
9799

@@ -405,7 +407,7 @@ class MetaModelGenerator(val outputDir: Path, val nameConfig: NameConfig = NameC
405407
}
406408
}
407409
}
408-
.build().write()
410+
.build().writeTo(modelqlOutputDir!!)
409411
}
410412

411413
private fun generateConceptObject(concept: ProcessedConcept): TypeSpec {

0 commit comments

Comments
 (0)