-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(model-api-gen-gradle): compatibility with newer MPS versions
- Loading branch information
Showing
7 changed files
with
736 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
metamodel-export/src/main/kotlin/org/modelix/metamodel/export/CommandlineExporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.