Skip to content
Snippets Groups Projects
Commit e2311567 authored by Chrissi's avatar Chrissi
Browse files

Merge branch 'develop'

parents 0cf8f28c f0cedcbe
No related branches found
No related tags found
No related merge requests found
Showing
with 638 additions and 68 deletions
{"name":"SimplePerson","init":{"name":"SimplePersonModel","primaryClass":"SimplePerson.SimplePerson","image":"SimplePerson.png"}}
\ No newline at end of file
<?xml version="1.0" encoding="ISO-8859-1"?>
<ecore:EPackage name="TT" nsURI="https://www.transformation-tool-contest.eu/2019/tt" xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
nsPrefix="tt">
<eClassifiers xsi:type="ecore:EClass" name="LocatedElement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="location" ordered="false"
unique="false" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="TruthTable" eSuperTypes="#/0/LocatedElement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false"
unique="false" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="ports" ordered="false"
lowerBound="1" upperBound="-1" eType="#/0/Port" containment="true" eOpposite="#/0/Port/owner"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="rows" ordered="false"
lowerBound="2" upperBound="-1" eType="#/0/Row" containment="true" eOpposite="#/0/Row/owner"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Port" abstract="true" eSuperTypes="#/0/LocatedElement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false"
unique="false" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="owner" ordered="false"
lowerBound="1" eType="#/0/TruthTable" eOpposite="#/0/TruthTable/ports"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="cells" ordered="false"
upperBound="-1" eType="#/0/Cell" eOpposite="#/0/Cell/port"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="InputPort" eSuperTypes="#/0/Port"/>
<eClassifiers xsi:type="ecore:EClass" name="OutputPort" eSuperTypes="#/0/Port"/>
<eClassifiers xsi:type="ecore:EClass" name="Row" eSuperTypes="#/0/LocatedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="owner" ordered="false"
lowerBound="1" eType="#/0/TruthTable" eOpposite="#/0/TruthTable/rows"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="cells" ordered="false"
lowerBound="1" upperBound="-1" eType="#/0/Cell" containment="true" eOpposite="#/0/Cell/owner"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Cell" eSuperTypes="#/0/LocatedElement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="value" ordered="false"
unique="false" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="owner" ordered="false"
lowerBound="1" eType="#/0/Row" eOpposite="#/0/Row/cells"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="port" ordered="false"
lowerBound="1" eType="#/0/Port" eOpposite="#/0/Port/cells"/>
</eClassifiers>
</ecore:EPackage>
{"name":"TTC 17","init":{"name":"ModelB","primaryClass":"ttc17.Family","image":"family.png","nested":[{"name":"Model B - members","primaryClass":"ttc17.Member"}]},"integration":[{"name":"ModelA","primaryClass":"ttc17.Person","additionalClasses":["ttc17.Female","ttc17.Male"],"rule":"person.atl"},{"name":"ModelC","primaryClass":"ttc17.SimplePerson"}]}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="oldSUMM" nsURI="http://www.example.org/develop" nsPrefix="dev">
<eClassifiers xsi:type="ecore:EClass" name="Method">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="class" lowerBound="1" eType="#//ClassType"
eOpposite="#//ClassType/methods"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="calling" upperBound="-1"
eType="#//Method" eOpposite="#//Method/calledBy"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="calledBy" upperBound="-1"
eType="#//Method" eOpposite="#//Method/calling"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="fulfilled" upperBound="-1"
eType="#//Requirement" eOpposite="#//Requirement/fulfilledBy"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ClassType">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="asg" eType="#//JavaASG"
eOpposite="#//JavaASG/classes"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="methods" upperBound="-1"
eType="#//Method" containment="true" eOpposite="#//Method/class"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="diagram" eType="#//ClassDiagram"
eOpposite="#//ClassDiagram/classes"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="associations" upperBound="-1"
eType="#//Association" containment="true" eOpposite="#//Association/class"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="usedBy" upperBound="-1"
eType="#//Association" eOpposite="#//Association/type"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="JavaASG">
<eStructuralFeatures xsi:type="ecore:EReference" name="classes" upperBound="-1"
eType="#//ClassType" containment="true" eOpposite="#//ClassType/asg"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="integrator" eType="#//ProjectData"
eOpposite="#//ProjectData/containsJavaASG"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="RequirementsSpecification">
<eStructuralFeatures xsi:type="ecore:EReference" name="content" upperBound="-1"
eType="#//Requirement" containment="true" eOpposite="#//Requirement/container"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="integrator" eType="#//ProjectData"
eOpposite="#//ProjectData/containsRequirements"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Requirement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="author" unique="false"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="text" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="container" lowerBound="1"
eType="#//RequirementsSpecification" eOpposite="#//RequirementsSpecification/content"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="fulfilledBy" upperBound="-1"
eType="#//Method" eOpposite="#//Method/fulfilled"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ClassDiagram">
<eStructuralFeatures xsi:type="ecore:EReference" name="classes" upperBound="-1"
eType="#//ClassType" containment="true" eOpposite="#//ClassType/diagram"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="integrator" eType="#//ProjectData"
eOpposite="#//ProjectData/containsClassDiagram"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Association">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="lowerBound" unique="false"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="upperBound" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="class" lowerBound="1" eType="#//ClassType"
eOpposite="#//ClassType/associations"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="type" lowerBound="1" eType="#//ClassType"
eOpposite="#//ClassType/usedBy"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ProjectData">
<eStructuralFeatures xsi:type="ecore:EReference" name="containsRequirements" upperBound="-1"
eType="#//RequirementsSpecification" containment="true" eOpposite="#//RequirementsSpecification/integrator"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="containsJavaASG" upperBound="-1"
eType="#//JavaASG" containment="true" eOpposite="#//JavaASG/integrator"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="containsClassDiagram" upperBound="-1"
eType="#//ClassDiagram" containment="true" eOpposite="#//ClassDiagram/integrator"/>
</eClassifiers>
</ecore:EPackage>
assets/models/oldSUMM.png

22.2 KiB

......@@ -5,8 +5,14 @@ val emfecoreVersion = "2.12.0"
val scrollVersion = "1.8"
val scoptVersion = "3.7.0"
val liftVersion = "3.3.0"
val gsonVersion = "2.8.5"
val syncProvider = RootProject(file("lib/ModelSyncProvider"))
val modelmanagementprovider = ProjectRef(uri("https://git-st.inf.tu-dresden.de/cwerner/role_model_management_provider.git#master"), "modelmanagementprovider")
val uiProvider = ProjectRef(uri("https://git-st.inf.tu-dresden.de/cwerner/role_ui_provider.git#master"), "uiprovider")
//val modeljoin = ProjectRef(uri("https://git-st.inf.tu-dresden.de/cwerner/model_join.git#master"), "model_join")
javacOptions ++= Seq("-encoding", "UTF-8")
lazy val generator = (project in file("."))
.settings(
......@@ -20,7 +26,17 @@ lazy val generator = (project in file("."))
"org.eclipse.emf" % "org.eclipse.emf.common" % emfcommonVersion,
"org.eclipse.emf" % "org.eclipse.emf.ecore" % emfecoreVersion,
"com.github.scopt" %% "scopt" % scoptVersion,
"net.liftweb" %% "lift-json" % liftVersion
"net.liftweb" %% "lift-json" % liftVersion,
"com.google.code.gson" % "gson" % gsonVersion,
//"org.antlr" % "antlr4-runtime" % "4.7.2",
"org.junit.platform" % "junit-platform-runner" % "1.0.0" % "test",
"org.junit.jupiter" % "junit-jupiter-engine" % "5.0.0" % "test",
"org.junit.vintage" % "junit-vintage-engine" % "4.12.0" % "test",
"org.assertj" % "assertj-core" % "3.12.2" % "test",
"net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test
),
scalacOptions ++= Seq(
"-language:implicitConversions"
......@@ -37,5 +53,9 @@ lazy val generator = (project in file("."))
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
).dependsOn(syncProvider)
},
).dependsOn(
//modeljoin,
modelmanagementprovider,
uiProvider
)
Subproject commit 619bbf1efcfee406a134412275928322d9d28e05
sbt.version = 1.2.1
\ No newline at end of file
sbt.version = 1.2.7
resolvers += Resolver.jcenterRepo
addSbtPlugin("net.aichler" % "sbt-jupiter-interface" % "0.8.2")
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
Subproject commit 89e2af4e060ae7c39c261fde55ba9140caf85853
Subproject commit ab624d1ae7196ac06fb3e9cef2f585552bee38e9
package org.rosi_project.model_sync.modelrepresentation;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import com.google.gson.Gson;
public class JCreateJSONModels {
private static Gson gson = new Gson();
public static void main(String[] args) {
//Type t = gson.fromJson(bytesRead, Type.class);
JCreateJSONModels creation = new JCreateJSONModels();
//Create old TTC Model
JModelConfig ttc = creation.createOldTTCModel();
creation.writeJModelConfigToFile(ttc);
//Create Family Model
JModelConfig family = creation.createFamilyModel();
creation.writeJModelConfigToFile(family);
//Create Person Model
JModelConfig person = creation.createPersonModel();
creation.writeJModelConfigToFile(person);
//Create SimplePerson Model
JModelConfig simplePerson = creation.createSimplePersonModel();
creation.writeJModelConfigToFile(simplePerson);
//Create Library Model
JModelConfig library = creation.createLibraryModel();
creation.writeJModelConfigToFile(library);
//Create Shrinking Model
JModelConfig shrinking = creation.createShrinkingModel();
creation.writeJModelConfigToFile(shrinking);
}
public void writeJModelConfigToFile (JModelConfig value) {
String s = gson.toJson(value);
//System.out.println(s);
try {
PrintWriter p = new PrintWriter("assets/models/" + value.getName() + ".sync.json");
p.write(s);
p.flush();
p.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public JModelConfig createShrinkingModel () {
JModelConfig conf = new JModelConfig("ShrinkingModel");
JModel classifier = new JModel("Classifier", "ShrinkingExample.Classifier");
classifier.setImage("Library.png");
classifier.addAdditionalClass("ShrinkingExample.StructuredClassifier");
classifier.addAdditionalClass("ShrinkingExample.EncapsulatedClassifier");
classifier.addAdditionalClass("ShrinkingExample.Class");
JModel element = new JModel("ConnectableElement", "ShrinkingExample.ConnectableElement");
element.addAdditionalClass("ShrinkingExample.Property");
classifier.addNested(element);
conf.setInit(classifier);
return conf;
}
public JModelConfig createLibraryModel () {
JModelConfig conf = new JModelConfig("Library");
JModel library = new JModel("Library", "LibraryExample.Library");
library.setImage("Library.png");
JModel person = new JModel("Person", "LibraryExample.Person");
person.addAdditionalClass("LibraryExample.Employee");
library.addNested(person);
conf.setInit(library);
return conf;
}
public JModelConfig createOldTTCModel () {
JModelConfig conf = new JModelConfig("TTC 17");
JModel family = new JModel("ModelB", "ttc17.Family");
family.setImage("family.png");
JModel member = new JModel("Model B - members", "ttc17.Member");
family.addNested(member);
JModel person = new JModel("ModelA", "ttc17.Person");
person.setRule("person.atl");
person.addAdditionalClass("ttc17.Female");
person.addAdditionalClass("ttc17.Male");
JModel simpleperson = new JModel("ModelC", "ttc17.SimplePerson");
conf.setInit(family);
conf.addIntegration(person);
conf.addIntegration(simpleperson);
return conf;
}
public JModelConfig createFamilyModel () {
JModelConfig conf = new JModelConfig("Family");
JModel family = new JModel("FamilyModel", "Family.Family");
family.setImage("Family.png");
//family.addAdditionalClass("Family.Member");
JModel member = new JModel("MemberModel", "Family.Member");
family.addNested(member);
conf.setInit(family);
return conf;
}
public JModelConfig createPersonModel () {
JModelConfig conf = new JModelConfig("Person");
JModel person = new JModel("PersonModel", "Person.Person");
person.setImage("Person.png");
person.addAdditionalClass("Person.Female");
person.addAdditionalClass("Person.Male");
conf.setInit(person);
return conf;
}
public JModelConfig createSimplePersonModel () {
JModelConfig conf = new JModelConfig("SimplePerson");
JModel simpleperson = new JModel("SimplePersonModel", "SimplePerson.SimplePerson");
simpleperson.setImage("SimplePerson.png");
conf.setInit(simpleperson);
return conf;
}
}
package org.rosi_project.model_sync.modelrepresentation;
import java.util.LinkedList;
import java.util.List;
public class JModel {
public JModel(String name, String primaryClass) {
this.name = name;
this.primaryClass = primaryClass;
}
private String name;
private String primaryClass;
private List<String> additionalClasses;
private String image;
private List<JModel> nested;
private String rule;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrimaryClass() {
return primaryClass;
}
public void setPrimaryClass(String primaryClass) {
this.primaryClass = primaryClass;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public List<String> getAdditionalClasses() {
return additionalClasses;
}
public boolean addAdditionalClass(String value) {
if (value == null)
return false;
if (additionalClasses == null)
this.additionalClasses = new LinkedList<String>();
return additionalClasses.add(value);
}
public List<JModel> getNested() {
return nested;
}
public boolean addNested(JModel value) {
if (value == null)
return false;
if (nested == null)
this.nested = new LinkedList<JModel>();
return nested.add(value);
}
public String getRule() {
return rule;
}
public void setRule(String rule) {
this.rule = rule;
}
}
package org.rosi_project.model_sync.modelrepresentation;
import java.util.LinkedList;
import java.util.List;
public class JModelConfig {
public JModelConfig(String name) {
this.name = name;
}
private String name;
private JModel init;
private List<JModel> integration;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public JModel getInit() {
return init;
}
public void setInit(JModel init) {
this.init = init;
}
public List<JModel> getIntegration() {
return integration;
}
public boolean addIntegration(JModel value) {
if (value == null)
return false;
if (integration == null)
this.integration = new LinkedList<JModel>();
return integration.add(value);
}
}
package org.rosi_project.model_sync.util;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreEList;
public class EMFUtilForGenerator {
static public List<EObject> getList(Object obj) {
List<EObject> newList = new LinkedList<EObject>();
EcoreEList<EObject> list = (EcoreEList<EObject>) obj;
for (EObject l : list) {
newList.add(l);
}
return newList;
}
}
......@@ -20,8 +20,8 @@ object CLIGenerator extends App {
val parser = new OptionParser[GeneratorConfig](programName="modelgen") {
head("modelgen", "0.1")
arg[jio.File]("ecore").required().action( (ef, conf) =>
conf.copy(source = ef.getAbsolutePath)
arg[Seq[jio.File]]("ecore").required().action( (ef, conf) =>
conf.copy(sources = ef.map(f => f.getAbsolutePath))
).text("The ecore (XML) file of the model")
opt[jio.File]('o', "outdir").optional().action( (dir, conf) =>
......@@ -32,13 +32,17 @@ object CLIGenerator extends App {
conf.copy(workDir = dir)
).text("The directory to place the generated .scala files in (temp dir by default)")
opt[jio.File]('m', "model").optional().action( (mj, conf) =>
conf.copy(modelFile = mj.getAbsolutePath)
).text("The description of the model's components (mapped to the name of the ecore with .sync.json extension by default)")
opt[Unit]('c', "cleanup").optional().action( (_, conf) =>
conf.copy(cleanUp = true)
opt[Boolean]('c', "cleanup").optional().action( (c, conf) =>
conf.copy(cleanUp = c)
).text("Remove the generated .scala files and only keep the compiled .class files")
opt[jio.File]('j', "modelJoin").optional().action( (m, conf) =>
conf.copy(modelJoin = m.getAbsolutePath)
).text("The description of a model join query to generate a view from.")
opt[jio.File]('s', "syncLanguage").optional().action( (s, conf) =>
conf.copy(syncLanguage = s.getAbsolutePath)
).text("The description of a synchronisation query to generate a synchronization behaviour from.")
}
parser.parse(args, GeneratorConfig()) match {
......
package org.rosi_project.model_sync.generator
object Creation extends Enumeration {
val rolesum, rolesync, rolecomb = Value
//val rsum, rsync = Value
}
\ No newline at end of file
......@@ -5,32 +5,51 @@ import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
import org.eclipse.emf.ecore.{ EObject, EPackage }
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl
import scala.collection.JavaConverters._
import java.io.File
import org.rosi_project.model_sync.generator.util.ClassAndInstance
/** Simple service to load an ECORE model from a file.
/**
* Simple service to load an ECORE model from a file.
*
* @author Rico Bergmann
*/
class EcoreLoader {
/** Fetches an ecore model from XML.
/**
* Fetches an ecore model from XML.
*
* @param path where to find the model
* @return the model described by the XML
*/
def loadEcore(path: String = "assets/ttc17.ecore"): EPackage = {
// see https://github.com/max-leuthaeuser/SCROLL/blob/dd269d5620257be1ea2f2044f398c090e9755fb3/core/src/main/scala/scroll/internal/ecore/ECoreImporter.scala
def loadEcore(path: String = "assets/ttc17.ecore"): ClassAndInstance = {
require(null != path && path.nonEmpty)
val resourceSet = new ResourceSetImpl()
val _ = resourceSet.getResourceFactoryRegistry.getExtensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl())
resourceSet.getResourceFactoryRegistry.getExtensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl())
//resourceSet.getResourceFactoryRegistry.getExtensionToFactoryMap.put("ecore", new EcoreResourceFactoryImpl())
//resourceSet.getResourceFactoryRegistry.getExtensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl())
val res = resourceSet.getResource(URI.createFileURI(path), true)
require(null != res)
require(!res.getContents.isEmpty)
res.getContents.toArray(new Array[EObject](0)).toList.find(_.isInstanceOf[EPackage]).map((p: EObject) => p.asInstanceOf[EPackage]).orNull
val f = new File(path.replace(".ecore", ".ttmodel"))
if (f != null && f.exists()) {
val univEPackage = res.getContents().get(0);
resourceSet.getPackageRegistry().put("https://www.transformation-tool-contest.eu/2019/tt", univEPackage);
val myModel = resourceSet.getResource(URI.createURI(path.replace(".ecore", ".ttmodel")), true);
return new ClassAndInstance(res.getContents.toArray(new Array[EObject](0)).toList.find(_.isInstanceOf[EPackage]).map((p: EObject) => p.asInstanceOf[EPackage]).orNull,
myModel.getContents().toArray(new Array[EObject](0)).toList.head)
}
return new ClassAndInstance(res.getContents.toArray(new Array[EObject](0)).toList.find(_.isInstanceOf[EPackage]).map((p: EObject) => p.asInstanceOf[EPackage]).orNull, null)
}
}
/** Exception to indicate that the model images may not be copied into the JAR.
/**
* Exception to indicate that the model images may not be copied into the JAR.
*
* @param cause the causing exception
*/
......
package org.rosi_project.model_sync.generator
import net.liftweb.json._
import org.eclipse.emf.ecore._
import org.rosi_project.model_sync.generator.conversion.SModelGenerator
import org.rosi_project.model_sync.generator.env.{ CompilationException, JarPackaginException }
import org.rosi_project.model_sync.generator.io.{ ClassWritingException, ModelImagePreparationException, SModelFSWriter }
import scala.io.Source
import scala.reflect.io.File
import org.rosi_project.model_sync.generator.acr_model.SModel
import org.rosi_project.model_sync.generator.acr_model.STypeRegistry
import org.rosi_project.model_sync.model_join.representation.parser.antlr.AntlrBackedModelJoinParser
import org.rosi_project.model_sync.generator.util.ClassAndInstance
/** The `Generator` runs the whole workflow of generating a JAR of compiled Scala source files
/**
* The `Generator` runs the whole workflow of generating a JAR of compiled Scala source files
* based on an ECORE file of some sync model.
*
* @param config the configuration that tells the generator where to locate the necessary files.
......@@ -22,51 +25,138 @@ class Generator(config: GeneratorConfig) {
* Starts the generation.
*/
def run(): Unit = {
//set package name of scala model files
if (config.create == Creation.rolesum)
PackageNames.sourcePkgPrefix = "sum."
if (config.create == Creation.rolesync)
PackageNames.sourcePkgPrefix = "sync."
if (config.create == Creation.rolecomb)
PackageNames.sourcePkgPrefix = ""
try {
val modelJson = Source.fromFile(config.getModelFile).getLines.mkString
implicit val jsonFormats: Formats = DefaultFormats
val modelCfg = parse(modelJson).extract[ModelConfig]
if (config.sources.isEmpty) {
println("Error: There must be any source file to generate something!!!")
return
}
var ecoreModel: EPackage = null
//read the ecore models
var ecoreModels: Map[String, ClassAndInstance] = Map.empty
try {
ecoreModel = new EcoreLoader loadEcore config.source
config.sources.foreach(s => {
ecoreModels = ecoreModels + (s -> (new EcoreLoader loadEcore s))
})
} catch {
case e: Exception => throw new EcoreLoadException(e)
}
val sModel = new SModelGenerator convert ecoreModel
new SModelSyncPreparationService prepareModel(sModel, modelCfg)
//create s models from the incoming ecore models
var sModels: Map[SModel, ClassAndInstance] = Map.empty
ecoreModels.foreach(ec => {
sModels = sModels + ((new SModelGenerator convert (ec._2.pkg, ec._1)) -> ec._2)
})
sModels.foreach(sm => {
/*general stuff, that should always be created */
//create relational compartments (are only write out if not rolesync)
new SModelRelationalCompartmentPreparationService prepareModel (sm._1)
//create the new classes for rsum and rsync
if (config.create == Creation.rolesync) {
//instance generation for rsync
if (sm._2.obj != null) {
new SModelSyncInstanceService prepareModel (sm._1, sm._2)
}
//add getter and setter for all methods
new SModelGetterSetterAllPreparationService prepareModel (sm._1)
//create the EMF Ecore reading models
new SModelSUMReadEMFService prepareModel (sm._1, config)
//add sync stuff
new SModelOnlySyncService prepareModel (sm._1)
//add ui provider stuff
new SModelSyncUiPreparationService prepareModel (sm._1, config.getModelConfigFromEcore(sm._1.getSourceName))
} else {
//add basic setter and getter
new SModelGetterSetterAttrPreparationService prepareModel (sm._1)
if (config.create == Creation.rolecomb) {
//add sync stuff
new SModelOnlySyncService prepareModel (sm._1)
}
//create the EMF Ecore reading models
new SModelSUMReadEMFService prepareModel (sm._1, config)
//instance generation for combi means rsum
if (sm._2.obj != null) {
new SModelCombiInstanceService prepareModel (sm._1, sm._2)
}
if (config.create == Creation.rolecomb) {
//add ref methods
new SModelCombiRefMethodService prepareModel (sm._1)
}
//remove references
new SModelSUMRemoveRefService prepareModel (sm._1)
//create view and query stuff
new SModelSUMPreparationService prepareModel (sm._1)
}
})
// write the model and create the JAR
println("... Writing model")
var finalModel: SModel = null
sModels.foreach(s => {
if (finalModel == null) {
finalModel = s._1
} else {
finalModel.addOtherModel(s._1)
}
})
if (config.create != Creation.rolesync) {
//create join stuff
val modelJoinFile = config.getModelJoinFile
if (modelJoinFile != null && modelJoinFile.exists()) {
var modelJoin = new AntlrBackedModelJoinParser().readOrThrow(modelJoinFile);
println(modelJoin);
//val modelJoin = DefaultModelJoinParser.read(modelJoinFile).get
modelJoin.setName(config.getModelJoinName)
new SModelJoinPreparationService prepareModel (finalModel, modelJoin)
}
}
if (config.hasWorkDir) {
sModel.accept(
finalModel.accept(
new SModelFSWriter(
config,
outputDir = File(config.outDir).toDirectory,
workingDir = File(config.workDir),
keepClassFiles = !config.cleanUp,
modelCfg = modelCfg,
currentDir = config.getModelPath))
modelCfgs = config.getAllModelConfigs,
currentDir = config.getModelPath(finalModel.getSourceName)))
} else {
sModel.accept(
finalModel.accept(
new SModelFSWriter(
config,
outputDir = File(config.outDir).toDirectory,
keepClassFiles = !config.cleanUp,
modelCfg = modelCfg,
currentDir = config.getModelPath))
modelCfgs = config.getAllModelConfigs,
currentDir = config.getModelPath(finalModel.getSourceName)))
}
}
catch {
println("... Done")
} catch {
case ele: EcoreLoadException =>
throw ele
println(s"** ERROR ** could not load ecore model: $ele")
case mipe: ModelImagePreparationException =>
throw mipe
println(s"** ERROR ** could not prepare model images: $mipe")
case cwe: ClassWritingException =>
throw cwe
println(s"** ERROR ** could not write classes: $cwe")
case ce: CompilationException =>
throw ce
println(s"** ERROR ** could not compile classes: $ce")
case jpe: JarPackaginException =>
throw jpe
println(s"** ERROR ** could not package JAR: $jpe")
}
}
......
package org.rosi_project.model_sync.generator
import java.io.File
import scala.io.Source
import net.liftweb.json._
/** Wrapper for the different command line options for the [[Generator]]
*
* @author Rico Bergmann
*/
case class GeneratorConfig(source: String = "", cleanUp: Boolean = false, outDir: File = new File(System.getProperty("user.dir")), workDir: File = null, modelFile: String = "") {
case class GeneratorConfig(sources: Seq[String] = Seq(),
cleanUp: Boolean = false,
outDir: File = new File(System.getProperty("user.dir")),
workDir: File = null,
modelJoin: String = null, //can be more than one
syncLanguage: String = null, //can be more than one
create: Creation.Value = Creation.rolesync) {
def hasWorkDir: Boolean = workDir != null
def getModelFile: File = if (modelFile.isEmpty) new File(source.replace(".ecore", ".sync.json")) else new File(modelFile)
private def getEcoreNames: Seq[String] = sources.map(_.split("/").last.replace(".ecore", ""))
def getModelPath: File = new File(source).getParentFile
def getCombinedEcoreName: String = getEcoreNames.mkString
def getModelConfigFromEcore(source: String): ModelConfig = {
var modelCfgs: ModelConfig = null
var f = new File(source.replace(".ecore", ".sync.json"))
//println("---File: " + f.exists())
if (f == null || !f.exists()) return null
val modelJson = Source.fromFile(f).getLines.mkString
implicit val jsonFormats: Formats = DefaultFormats
parse(modelJson).extract[ModelConfig]
}
def getAllModelConfigs: Set[ModelConfig] = {
var configs: Set[ModelConfig] = Set.empty
sources.foreach(s => {
var modelCfg = getModelConfigFromEcore(s)
if (modelCfg != null) {
configs += modelCfg
}
})
configs
}
def getModelPath(source: String): File = new File(source).getParentFile
def getModelJoinFile: File = if(modelJoin == null) null else new File(modelJoin)
def getModelJoinName: String = modelJoin.split("/").last.replace(".modeljoin", "").capitalize
def getSnchronizationFile: File = if(syncLanguage == null) null else new File(syncLanguage)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment