From IFML Models to PHP frameworks Yii2 and Laravel. A set of transformations using ATL, Acceleo and Java.
A practical implementation of the achievements of models integration it's not possible if a suitable set of tools doesn't exist to facilitate the application of models, techniques, transformations and maintenance of the coherence of the models in order to achieve, in the end, executable code. This project intended to facilitate the adoption of the MDD approach by Web Developers meeting their needs and current trends.
- Eclipse Luna
- IFML Editor
- Sirius
- Un caso de estudio sobre la aplicación de UWE para la generación de sistemas web
- Eclipse Luna Modeling Tools
- Composer
- Apache Commons Lang
- Laravel Framework
- Laravel Colletive
- Yii2 Framework
The Acceleo and ATL frameworks are designed for Model-to-Text and Model-Transformation aiding. And we will use them along the project.
The first step will be to download and install Eclipse Modeling Tools from the link above. Once Eclipse is ready we need to install the Acceleo and ATL Frameworks. We can do this by opening Eclipse and going to:
- Help -> Installing Modelling Components
- Choose Acceleo y ATL.
- After install you will be prompted to restart Eclipse, do it.
Once Eclipse starts again we need to install the IFML Editor, in order to do that we can follow the instructions here.
This should leave us with a starting working environment.
Composer is a Dependency Manager for PHP which is going to allow us to install and both Laravel and Yii2 frameworks.
For Microsoft Windows you the best way is to download and run Composer Setup Executable and it will install the latest composer version whenever it is executed.
For Ubuntu based Linux distros running the following should do the trick:
sudo apt install composer
Any other case this should be enough to get things working:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
The naming convention is for all projects is:
<domain>.<project-name>.<kind-of-input>.<input-metamodel-name>.gen.<output-language-name>
Where kind-of-input
is one of:
- pim: Platform-Independent Model
- psm: Platform-Specific Models
- dsl: Domain-Specific Language
First things first, you should import the ATL project in Eclipse:
- File -> Import (Alt + F + I)
- General
- Existing project into workspace
In this repo, the ATL project is called edu.ifml2php.pim.ifml.gen.lycmm
.
lycmm
means "Laravel, Yii2 & CodeIgniter Meta-Model".
The ATL project consists in:
- A file called ifml2OurMM.atl, where the Model-To-Model (M2M) transformation rules lives.
- A folder called atlLibraries, where the IFML helpers live.
The ifml2OurMM.launch file on the ATL project's root contains run configuration parameters. You shouldn't need to change that file but in case you want to know the details about this file go to Making a .launch file section on this README.
Finally, right click in ifml2OurMM.atl file, then "Run As" -> "ATL Transformation" should do the trick.
If the transformation was successful you should see a file called preProd-gen.xmi (or the name you've set it to in the .launch file) on the ATL project's root.
Right click in ifml2OurMM.atl file, then "Run As" -> "Run Configuration". This opens a window where you can set the following parameters:
(We encourage the use of URIs instead absolute paths or relative paths whenever possible)
ATL Module: This should point to the path of the ifml2OutMM.atl file you've just right-clicked on.
Name | Path | URI |
---|---|---|
UMLMM | uri:http://www.eclipse.org/uml2/5.0.0/UML | |
IFMLMM | /models/metamodels/IFML-Metamodel.ecore | uri:http://www.omg.org/spec/20130218/core |
extMM | /models/metamodels/IFML-Metamodel.ecore | uri:http://www.omg.org/spec/20130218/ext |
ourMM | /edu.ifml2php.pim.ifml.gen.lycmm/models/metamodels/Metamodel.ecore | uri:http://www.application.org |
Do not check the Is Metametamodel
check box
Name | Conforms to | Path (/edu.ifml2php.pim.ifml.gen.lycmm/models/models/) | Type |
---|---|---|---|
uml | UMLMMM | model.uml | Domain |
ifml | IFMLMM | movies.core | Interaction Flow |
extm | extMM | movies.core | Interaction Flow |
ourm: This is the path where the generated .xmi file will be stored. In this case, the ATL project's root.
Name | Path (/edu.ifml2php.pim.ifml.gen.lycmm/atlLibraries/) |
---|---|
ifmlCoreLibrary | ifmlCoreLibrary.asm |
ifmlExtLibrary | ifmlExtLibrary.asm |
mvcLibrary | mvcLibrary.asm |
systemLibrary | systemLibrary.asm |
In order to use the models in an Acceleo project you need to include Metamodel.ecore to EMF registry.
The easiest way to do that is:
- Change to ATL Perspective: Window->Open Perspective->Other->ATL
- Right click on Metamodel.ecore -> Register Metamodel.
You will not see any visual change but trust me, the metamodel is registered now.
Now you should import the ATL project in Eclipse:
- File -> Import (Alt + F + I)
- General
- Existing project into workspace
In this repo, there are two Acceleo projects called:
edu.ifml2php.psm.lycmm.gen.laravel
.edu.ifml2php.psm.lycmm.gen.yii2
.
- You must specify a path for
<model-name>
- Arguments of a generation cannot be null
- {.asm, .atl} does not exist
Verify the M2M transformations parameters in the .launch file
- Package with URI
<uri>
not found
Do a manual register of the metamodel, add the following code on the registerPackages()
method in the corresponding Java launcher.
URI uri = URI.createFileURI("../edu.ifml2php.pim.ifml.gen.lycmm/models/metamodels/Metamodel.ecore");
Resource resource = resourceSet.getResource(uri, true);
EPackage PHPMVC = (EPackage) resource.getContents().get(0);
List<EPackage> subPackages = PHPMVC.getESubpackages();
for(EPackage subPack : subPackages){
EPackage.Registry.INSTANCE.put(subPack.getNsURI(), subPack);
}
- ClassNotFoundException: org.eclipse.uml2.types.TypesPackage
Add org.eclipse.uml2.types to the classpath.
- Could not find public template
<template-name>
in module<module-name>
Make sure you have the @main
annotation to the corresponding public template.
- java.lang.NoClassDefFoundError: org/eclipse/core/resources/IresourceChangeListener
Add org.eclipse.core.resources to the classpath.