Skip to content

Commit

Permalink
Merge pull request #107 from modelix/feature/cached-api-gen
Browse files Browse the repository at this point in the history
MODELIX-427 Caching in api-gen-gradle
  • Loading branch information
mhuster23 authored May 30, 2023
2 parents cc5c5c4 + dcbf5cd commit b82344e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,31 @@ import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.*
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import java.util.*
import javax.inject.Inject

@CacheableTask
abstract class GenerateAntScriptForMpsMetaModelExport @Inject constructor(of: ObjectFactory) : DefaultTask() {
@get:InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
val mpsHome: DirectoryProperty = of.directoryProperty()

@get:OutputFile
val antScriptFile: RegularFileProperty = of.fileProperty()

@InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
val exporterDir: Property<String> = of.property(String::class.java)

@InputFiles
@PathSensitive(PathSensitivity.RELATIVE)
val moduleFolders: ListProperty<String> = of.listProperty(String::class.java)

@Input
val heapSize: Property<String> = of.property(String::class.java)

@Input
@Optional
val exportModulesFilter: Property<String> = of.property(String::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,44 @@ import org.gradle.api.file.DirectoryProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.*
import org.modelix.metamodel.generator.*
import org.modelix.model.data.LanguageData
import org.modelix.metamodel.generator.LanguageSet
import org.modelix.metamodel.generator.MetaModelGenerator
import org.modelix.metamodel.generator.NameConfig
import org.modelix.metamodel.generator.TypescriptMMGenerator
import org.modelix.metamodel.generator.process
import javax.inject.Inject

@CacheableTask
abstract class GenerateMetaModelSources @Inject constructor(of: ObjectFactory) : DefaultTask() {
@get:InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
val exportedLanguagesDir: DirectoryProperty = of.directoryProperty()

@get:OutputDirectory
@Optional
val kotlinOutputDir: DirectoryProperty = of.directoryProperty()

@get:OutputDirectory
@Optional
val typescriptOutputDir: DirectoryProperty = of.directoryProperty()

@get:Input
val includedNamespaces: ListProperty<String> = of.listProperty(String::class.java)

@get:Input
val includedLanguages: ListProperty<String> = of.listProperty(String::class.java)

@get:Input
val includedConcepts: ListProperty<String> = of.listProperty(String::class.java)

@get:Input
@Optional
val registrationHelperName: Property<String> = of.property(String::class.java)

@get: Input
val nameConfig: Property<NameConfig> = of.property(NameConfig::class.java)

@TaskAction
fun generate() {
var languages: LanguageSet = LanguageSet(exportedLanguagesDir.get().asFile.walk()
var languages = LanguageSet(exportedLanguagesDir.get().asFile.walk()
.filter { it.extension.lowercase() == "json" }
.map { LanguageData.fromJson(it.readText()) }
.toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MetaModelGradlePlugin: Plugin<Project> {
val exportedLanguagesDir = getBuildOutputDir().resolve("exported-languages")
val exportMetaModelFromMps = project.tasks.register("exportMetaModelFromMps", JavaExec::class.java) { task ->
task.enabled = settings.jsonDir == null
task.outputs.cacheIf { task.enabled }
task.workingDir = getBuildOutputDir()
task.mainClass.set("org.apache.tools.ant.launch.Launcher")
task.classpath(antDependencies)
Expand Down

0 comments on commit b82344e

Please sign in to comment.