Skip to content

Commit

Permalink
fix(model-api-gen-gradle): compatibility with newer MPS versions
Browse files Browse the repository at this point in the history
  • Loading branch information
slisson committed Mar 21, 2024
1 parent e2a540b commit 9a634a3
Show file tree
Hide file tree
Showing 7 changed files with 736 additions and 93 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ kotlinSerialization="1.6.3"
ignite="2.16.0"
apacheCxf="3.6.3"
node="18.17.1"
modelixBuildtools="1.4.0"
modelixBuildtools="1.4.1"
openapi = "7.4.0"
micrometer = "1.12.4"
dokka = "1.9.20"
Expand Down
50 changes: 20 additions & 30 deletions metamodel-export/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
import org.gradle.internal.jvm.Jvm
import org.modelix.gradle.mpsbuild.MPSBuildSettings
import org.modelix.mpsHomeDir

plugins {
base
alias(libs.plugins.modelix.mps.buildtools)
kotlin("jvm")
}

group = "org.modelix.mps"

val generatorLibs by configurations.creating

dependencies {
generatorLibs(project(":model-api-gen-runtime"))
generatorLibs(project(":model-api-gen"))
implementation(project(":model-api-gen-runtime"))
implementation(project(":model-api-gen"))
compileOnly(fileTree(mpsHomeDir.map { it.dir("lib") }))
compileOnly(
mpsHomeDir.map {
it.files(
"languages/languageDesign/jetbrains.mps.lang.structure.jar",
"languages/languageDesign/jetbrains.mps.lang.core.jar",
)
},
)
implementation(project(":model-api"))
}

val copyLibs by tasks.registering(Sync::class) {
from(generatorLibs)
into(projectDir.resolve("org.modelix.metamodel.export/lib"))
rename { fileName ->
generatorLibs.resolvedConfiguration.resolvedArtifacts
.find { it.file.name == fileName }?.let {
if (it.classifier == null) {
"${it.name}.${it.extension}"
} else {
"${it.name}-${it.classifier}.${it.extension}"
}
}
?: fileName
}
java {
withSourcesJar()
}

extensions.configure<MPSBuildSettings> {
javaHome = Jvm.current().javaHome
mpsHome(mpsHomeDir.get().asFile.absolutePath)
dependsOn(copyLibs)
search(".")
disableParentPublication()

publication("metamodel-export") {
module("org.modelix.metamodel.export")
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.modelix.metamodel.export

import jetbrains.mps.smodel.Language
import jetbrains.mps.smodel.MPSModuleRepository
import jetbrains.mps.tool.environment.Environment
import java.io.File

object CommandlineExporter {
@JvmStatic
fun exportLanguages(ideaEnvironment: Environment?) {

Check warning

Code scanning / detekt

Function parameter ideaEnvironment is unused. Warning

Function parameter ideaEnvironment is unused.
println("exportLanguages")
val repo = MPSModuleRepository.getInstance()
repo.modelAccess.runReadAction {
val modules = repo.modules
val languages = modules.filterIsInstance<Language>()
val outputDir = File("exported-languages")
outputDir.mkdirs()
println("Exporting ${languages.count()} languages into ${outputDir.absolutePath}")
val exporter = MPSMetaModelExporter(outputDir)
for (language in languages) {
exporter.exportLanguage(language)
}
}
}

@JvmStatic
fun exportBoth(ideaEnvironment: Environment?) {
println("exportBoth")
exportLanguages(ideaEnvironment)
exportModules(ideaEnvironment)
}

@JvmStatic
fun exportModules(ideaEnvironment: Environment?) {

Check warning

Code scanning / detekt

Function parameter ideaEnvironment is unused. Warning

Function parameter ideaEnvironment is unused.
println("exportModules")
val filter = System.getProperty("modelix.export.includedModules")
println("modules filter: $filter")
if (filter == null) {
return
}
val filters = filter.split(',').filter { it.isNotEmpty() }
if (filters.isEmpty()) {
return
}

val repo = MPSModuleRepository.getInstance()
repo.modelAccess.runReadAction {
val modules = repo.modules
val outputDir = File("exported-modules")
outputDir.mkdirs()
val exporter = MPSModelExporter(outputDir)
for (module in modules) {
val moduleName = module.moduleName ?: continue
if (filters.any { moduleName == it || moduleName.startsWith((if (it.endsWith(".")) it else "$it.")) }) {
exporter.exportModule(module)
}
}
}
}
}
Loading

0 comments on commit 9a634a3

Please sign in to comment.