-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from mbeddr/feature/generate-user-project
generate user project
- Loading branch information
Showing
14 changed files
with
557 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,9 @@ | |
/buildSrc/build | ||
/out/ | ||
*.iml | ||
.gradletasknamecache | ||
.classpath | ||
.settings/ | ||
bin/ | ||
.project | ||
build/ |
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 was deleted.
Oops, something went wrong.
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,83 @@ | ||
import java.net.URI | ||
|
||
plugins { | ||
kotlin("jvm") version "1.2.50" | ||
`maven-publish` | ||
groovy | ||
`java-gradle-plugin` | ||
`kotlin-dsl` | ||
} | ||
|
||
val versionMajor = 1 | ||
val versionMinor = 0 | ||
|
||
group = "de.itemis.mps" | ||
version = "1.0.0" | ||
|
||
|
||
|
||
|
||
val nexusUsername: String? by project | ||
val nexusPassword: String? by project | ||
|
||
|
||
|
||
if (project.hasProperty("forceCI") || project.hasProperty("teamcity")) { | ||
version = de.itemis.mps.gradle.GitBasedVersioning.getVersion(versionMajor, versionMinor) | ||
} else { | ||
version = "$versionMajor.$versionMinor-SNAPSHOT" | ||
} | ||
|
||
|
||
val mpsConfiguration = configurations.create("mps") | ||
|
||
|
||
repositories { | ||
mavenCentral() | ||
maven { | ||
url = URI("https://projects.itemis.de/nexus/content/repositories/mbeddr") | ||
} | ||
} | ||
|
||
|
||
dependencies { | ||
compile(localGroovy()) | ||
compile(kotlin("stdlib")) | ||
|
||
} | ||
|
||
gradlePlugin { | ||
(plugins) { | ||
"generate-models" { | ||
id = "generate-models" | ||
implementationClass = "de.itemis.mps.gradle.generate.GenerateMpsProjectPlugin" | ||
} | ||
} | ||
} | ||
|
||
tasks { | ||
"wrapper"(Wrapper::class) { | ||
gradleVersion = "4.8" | ||
distributionType = Wrapper.DistributionType.ALL | ||
} | ||
|
||
"setTeamCityBuildNumber" { | ||
doLast { | ||
println("##teamcity[buildNumber '$version']") | ||
} | ||
} | ||
} | ||
|
||
publishing { | ||
repositories { | ||
maven { | ||
url = uri("https://projects.itemis.de/nexus/content/repositories/mbeddr") | ||
credentials { | ||
username = nexusUsername | ||
password = nexusPassword | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
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,59 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
import java.net.URI | ||
|
||
group = "de.itemis.mps" | ||
|
||
plugins { | ||
kotlin("jvm") | ||
`maven-publish` | ||
`java-gradle-plugin` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { | ||
url = URI("https://projects.itemis.de/nexus/content/repositories/mbeddr") | ||
} | ||
} | ||
|
||
val nexusUsername: String? by project | ||
val nexusPassword: String? by project | ||
|
||
|
||
//define directories | ||
val artifactsDir = File(buildDir, "artifacts") | ||
val mpsDir = File(artifactsDir, "mps") | ||
val kotlin_argparser_version = "2.0.7" | ||
val pluginVersion = "1" | ||
val mpsVersion = "2017.3.5" | ||
|
||
|
||
version = if (project.hasProperty("forceCI") || project.hasProperty("teamcity")) { | ||
de.itemis.mps.gradle.GitBasedVersioning.getVersion(mpsVersion, pluginVersion) | ||
} else { | ||
"$mpsVersion.$pluginVersion-SNAPSHOT" | ||
} | ||
|
||
|
||
val mpsConfiguration = configurations.create("mps") | ||
|
||
dependencies { | ||
compile(kotlin("stdlib")) | ||
compile("com.xenomachina:kotlin-argparser:$kotlin_argparser_version") | ||
compileOnly(fileTree(mpsDir).include("**/*.jar")) | ||
mpsConfiguration("com.jetbrains:mps:$mpsVersion") | ||
} | ||
|
||
|
||
tasks { | ||
val resolveMps by creating(Copy::class) { | ||
from(mpsConfiguration.resolve().map { zipTree(it) }) | ||
into(mpsDir) | ||
} | ||
|
||
getByName("compileKotlin").dependsOn(resolveMps) | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} |
112 changes: 112 additions & 0 deletions
112
execute-generators/src/main/kotlin/de/itemis/mps/gradle/generate/Helper.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,112 @@ | ||
package de.itemis.mps.gradle.generate | ||
|
||
import com.intellij.openapi.util.AsyncResult | ||
import jetbrains.mps.make.MakeSession | ||
import jetbrains.mps.make.facet.FacetRegistry | ||
import jetbrains.mps.make.facet.IFacet | ||
import jetbrains.mps.make.facet.ITarget | ||
import jetbrains.mps.make.script.IScript | ||
import jetbrains.mps.make.script.ScriptBuilder | ||
import jetbrains.mps.messages.IMessage | ||
import jetbrains.mps.messages.IMessageHandler | ||
import jetbrains.mps.messages.MessageKind | ||
import jetbrains.mps.project.Project | ||
import jetbrains.mps.smodel.SLanguageHierarchy | ||
import jetbrains.mps.smodel.language.LanguageRegistry | ||
import jetbrains.mps.smodel.resources.ModelsToResources | ||
import jetbrains.mps.smodel.runtime.MakeAspectDescriptor | ||
import jetbrains.mps.tool.builder.make.BuildMakeService | ||
import org.apache.log4j.Logger | ||
import org.jetbrains.mps.openapi.language.SLanguage | ||
import org.jetbrains.mps.openapi.model.SModel | ||
|
||
private val logger = Logger.getLogger("de.itemis.mps.gradle.generate") | ||
|
||
private val DEFAULT_FACETS = listOf( | ||
IFacet.Name("jetbrains.mps.lang.core.Generate"), | ||
IFacet.Name("jetbrains.mps.lang.core.TextGen"), | ||
IFacet.Name("jetbrains.mps.make.facets.Make")) | ||
|
||
private class MsgHandler : IMessageHandler { | ||
val logger = Logger.getLogger("de.itemis.mps.gradle.generate.messages") | ||
override fun handle(msg: IMessage) { | ||
when (msg.kind) { | ||
MessageKind.INFORMATION -> logger.info(msg.text, msg.exception) | ||
MessageKind.WARNING -> logger.warn(msg.text, msg.exception) | ||
MessageKind.ERROR -> logger.error(msg.text, msg.exception) | ||
} | ||
} | ||
|
||
} | ||
|
||
private fun createScript(proj: Project, models: List<org.jetbrains.mps.openapi.model.SModel>): IScript { | ||
|
||
val allUsedLanguagesAR: AsyncResult<Set<SLanguage>> = AsyncResult() | ||
val registry = LanguageRegistry.getInstance(proj.repository) | ||
|
||
proj.modelAccess.runReadAction { | ||
val allDirectlyUsedLanguages = models.map { it.module }.distinct().flatMap { it.usedLanguages }.distinct() | ||
allUsedLanguagesAR.setDone(SLanguageHierarchy(registry, allDirectlyUsedLanguages).extended) | ||
} | ||
|
||
val allUsedLanguages = allUsedLanguagesAR.resultSync | ||
|
||
val scb = ScriptBuilder() | ||
|
||
scb.withFacetNames(allUsedLanguages | ||
.mapNotNull { registry.getLanguage(it) } | ||
.mapNotNull { it.getAspect(MakeAspectDescriptor::class.java) } | ||
.flatMap { it.manifest.facets() } | ||
.map { it.name } | ||
) | ||
|
||
scb.withFacetNames(allUsedLanguages | ||
.flatMap { FacetRegistry.getInstance().getFacetsForLanguage(it.qualifiedName) } | ||
.map { it.name } | ||
) | ||
|
||
// For some reason MPS doesn't explicitly stat that there is a dependency on Generate, TextGen and Make, so we have | ||
// to make sure they are always included in the set of facets even if for MPS there is no dependency on them. | ||
|
||
// todo: not sure if we really need the final target to be Make.make all the time. The code was taken fom #BuildMakeService.defaultMakeScript | ||
return scb.withFacetNames(DEFAULT_FACETS).withFinalTarget(ITarget.Name("jetbrains.mps.make.facets.Make.make")).toScript() | ||
} | ||
|
||
private fun makeModels(proj: Project, models: List<org.jetbrains.mps.openapi.model.SModel>) { | ||
val session = MakeSession(proj, MsgHandler(), true) | ||
val res = ModelsToResources(models).resources().toList() | ||
val makeService = BuildMakeService() | ||
|
||
if (res.isEmpty()) { | ||
logger.warn("nothing to generate") | ||
return | ||
} | ||
logger.info("starting generation") | ||
val future = makeService.make(session, res, createScript(proj, models)) | ||
try { | ||
future.get() | ||
logger.info("generation finished") | ||
} catch (ex: Exception) { | ||
logger.error("failed to generate", ex) | ||
} | ||
} | ||
|
||
|
||
fun generateProject(parsed: Args, project: Project) { | ||
val ftr = AsyncResult<List<SModel>>() | ||
|
||
project.modelAccess.runReadAction { | ||
var modelsToGenerate = project.projectModels | ||
if (parsed.models.isNotEmpty()) { | ||
modelsToGenerate = modelsToGenerate.filter { parsed.models.contains(it.name.longName) } | ||
} | ||
ftr.setDone(modelsToGenerate.toList()) | ||
} | ||
|
||
val modelsToGenerate = ftr.resultSync | ||
|
||
makeModels(project, modelsToGenerate) | ||
} | ||
|
||
|
||
|
Oops, something went wrong.