Skip to content

Commit 26b9d6e

Browse files
authored
Merge pull request #192 from modelix/optional-modelql-gen
fix(model-api-gen): disable ModelQL generation by default
2 parents 16a361c + 1d15caa commit 26b9d6e

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

docs/global/modules/core/pages/reference/component-model-api-gen-gradle.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ Inside of the `metamodel` block the following settings can be configured.
8282
|File
8383
|Target Kotlin directory of the generator
8484

85+
|`modelqlKotlinDir`
86+
|File
87+
|The generation of the ModelQL API is optional, because the output has a dependency on the ModelQL runtime.
88+
If this option is set, you have to add a dependency on `org.modelix:modelql-typed`.
89+
90+
Can be the same as `kotlinDir` or a directory in a separate subproject,
91+
if you run into memory issues of the Kotlin compiler.
92+
8593
|`kotlinProject`
8694
|Project
8795
|Target Kotlin project of the generator

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)