Skip to content
Snippets Groups Projects
Verified Commit 45c9e711 authored by Rico Bergmann's avatar Rico Bergmann
Browse files

Augment the generator to work on command line

This adds different options for the command line to specify the source
ecore file as well as the output path. Furthermore a switch was added to
remove or retain the generated .scala files.
parent 61c386a7
Branches
No related tags found
2 merge requests!2Publish v0.1,!1Move away from experimental changes
package org.rosi_project.model_sync.generator
import java.io.File
/**
* @author Rico Bergmann
*/
case class Config(source: String = "", cleanUp: Boolean = false, outDir: File = new File(System.getProperty("user.dir"))) {
}
......@@ -4,34 +4,55 @@ import org.eclipse.emf.ecore._
import org.eclipse.emf.ecore.resource.Resource
import org.rosi_project.model_sync.generator.conversion.SModelGenerator
import org.rosi_project.model_sync.generator.io.SModelFSWriter
import org.rosi_project.model_sync.generator.io.SModelFSWriterTest.{model, personClass}
import org.rosi_project.model_sync.generator.sync_model.{GetterSetterGeneratingVisitor, SModel, SyncEnhancingVisitor}
import scopt.OptionParser
import scroll.internal.ecore.ECoreImporter
import scala.reflect.io.File
import java.{io => jio}
/**
* @author Rico Bergmann
*/
object Generator extends App {
val ecoreModel = loadEcore()
// TODO CLI parser (scopt) here
// gen -c(leanup) -o [outdir] ECOREFILE
val sModel = SModelGenerator.convert(ecoreModel)
val parser = new OptionParser[Config](programName="modelgen") {
head("modelgen", "0.1")
arg[jio.File]("ecore").required().action( (ef, conf) =>
conf.copy(source = ef.getAbsolutePath)
).text("The ecore (XML) file of the model")
opt[jio.File]('o', "outdir").optional().action( (dir, conf) =>
conf.copy(outDir = dir)
).text("The directory to place the generated model in (current dir by default)")
opt[Unit]('c', "cleanup").optional().action( (_, conf) =>
conf.copy(cleanUp = true)
).text("Remove the generated .scala files and only keep the compiled .class files")
}
parser.parse(args, Config()) match {
case Some(config) =>
val ecoreModel = loadEcore(config.source)
val sModel = SModelGenerator.convert(ecoreModel)
prepareModel(sModel)
sModel.accept(new SModelFSWriter(outputDir = File(config.outDir).toDirectory, keepClassFiles = !config.cleanUp))
case None =>
}
sModel.accept(new SModelFSWriter(workingDir = File("output/raw"), keepClassFiles = true))
def loadEcore(): EPackage = {
def loadEcore(path: String = "assets/ttc17.ecore"): EPackage = {
val importer = new ECoreImporter {
def lm(): Resource = loadModel()
}
importer.path = "assets/ttc17.ecore"
importer.path = path
val res = importer.lm()
println(s"We done: $res")
res.getContents.toArray(new Array[EObject](0)).toList.find(_.isInstanceOf[EPackage]).map((p: EObject) => p.asInstanceOf[EPackage]).orNull
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment