Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "MoScript"

(Registering the EMF metametamodel)
(Code explanation)
Line 144: Line 144:
 
  ;
 
  ;
  
==== Code explanation  ====
+
===== Code explanation  =====
  
 
=== YYY  ===
 
=== YYY  ===

Revision as of 08:52, 21 December 2011

< To: MDT
< To: MoDisco
< To: AM3

AM3
Download
Community
Mailing ListForum
Bugzilla
Opened bugs
All bugs
Contribute
Browse Source

The MoScript prototype (extending AM3), being developed by the AtlanMod Team, is part of the MoDisco project. It provides a textual domain-specific language for model management.

Overview

The goal of MoScript is to provide AM3 with a textual domain-specific language for model management, improving its model management task orchestration expressivity. With MoScript, users can automate model management tasks by means of OCL based scripts. For instance, user may write queries (based on model content, structure, relationships, and behavior derived through on-the-fly simulation) to retrieve models from model repositories, manipulate them (e.g., by running transformations on sets of models), and store them back in the repository. MoScript also allows to populate and update the megamodel automatically by doing reverse engineer of simple modeling artifact repositories.

Download and install

The MoScript prototype is available from the Eclipse-MDT MoDisco SVN (sources only). The steps to install MoScript are the following:

  1. Download the Eclipse Modeling Tools from here: Eclipse Modeling Tools (Indigo)
  2. Install ATL from sources:
    • Download the ATL source code project set file (.psf) from here [1].
    • Import it into Eclipse with File->Import->Team->Team Project Set.
    • Download the MoScript patch for ATL from Bugzilla – Bug 361688.
    • Click right click on any ATL plugin project and select Team->Apply Patch ... and select the patch to apply it to ATL.
  3. Install sublcipse and subversion if you have not done it yet.
  4. Install AM3 and MoScript from sources:

Documentation

You can find from this section the documentary resources around the MoScript prototype and underlying approach.

Reference documentation

MoScript Hello World!

Create a new MoScript project by clicking on File-> New-> Project and selecting the MoScript project type under the AM3 Folder. MoScript-HelloWorld2.png

Then create a MoScript script by clicking in File-> New-> File. Give it the name helloWorld.mscr. When the file is open, fill it with the following script code:

program helloWorld

do{
'HelloWorld'.debug();
}

After saving the file, if there are no errors, you should see a new binary file called helloWorld.asm in the project explorer or navigator.

Now that the code is ready, create a MoScript launcher to run the script, by clicking in Run-> Run Configurations... MoScript-HelloWorld3.png

Browse in the workspace for the HelloWorld.mscr file and select it. Then, in the advanced tab, check the options Clear console before launch and Print execution times to console, so that you can clearly see when de script finishes.

MoScript-HelloWorld4.png

Then press the Apply button and the Run button. In the console window you will see an error like the following:

Error loading file:...workspacePath/.am3/megamodel.xmi: java.io.FileNotFoundException: ... (No such file or directory)

This is because the megamodel file has not been created yet.

For creating the megamodel file, open the AM3 Perspective. MoScript-HelloWorld1.png

Create any model element in the megamodel left clicking in any element in the left panel, selecting new [element]. Give any value to the element and then use File->Save option to save the Megamodel. With this operation the Megamodel file is created in the filesystem. MoScript-HelloWorld5.png

Now try again to run the script by clicking on Run->Run History->Hello World and you should see the output in the console. MoScript-HelloWorld6.png

Screencasts & slides

Related publications

MoScript: A textual DSL for model manipulations (slides)
MoScript: A DSL for querying and manipulating model repositories (paper)

Use Cases

MoScript comes with a set of use cases showing different possible uses of the MoScript tool in various contexts and for varied purposes (similarly to what is done in the M2M ATL project). A general description is given for each of these use cases, as well as some more precise documentations for many of them. For some, prototypes have already been implemented and are directly downloadable from their respective page.

Megamodel Population

In this use case we are going to show how is possible to programmatically populate the Megamodel with MoScript. For this purpose we are going to populate it with the content of an ATL project that can be found in the ATL Transformations Zoo

Environment Preparation
  • Download the Families to Persons source code from here
  • Unzip the project and import it into eclipse
  • Create a MoScript project named megamodelPopulation with a file called megamodelPopulation.mscr
Registering the EMF metametamodel

As first step we are going to register programmatically the Ecore metametamodel in the Megamodel, to be able to register metamodels that conform to it and subsequently models that conform to those metamodels. For this, we have to have in mind that in order for MoScript to be able manipulate any model (remember that a metametamodel is also a model), the model must have at least an identifier to unequivocally identify it, a locator, to be able to locate the file that represents the model, and a reference model describing it, in order to be able to inspect its content.

If we check the Megamodels metamodel (that can be found in /org.eclipse.gmt.am3.platform.extension.globalmodelmanagement/model /GlobalModelManagement.ecore) we will see that a Metametamodel is a ReferenceModel and has references to identifier, locator and a ReferenceModel among others (see the picture bellow)
MoScript-MetaMetaModel.png MoScript-IdentifierLocator.png

The code for resgistering a MetaMetamodel in the Megamodel is the following:

program modelsDiscovery

do{
    -- Creates the Ecore metametamodel element in the megamodel
    thisModule.register(
        thisModule.metametamodel(
             thisModule.identifier('identifier', 'http://www.eclipse.org/emf/2002/Ecore', 'GlobalModelManagement::URI')
            ,thisModule.locator('locator', 'http://www.eclipse.org/emf/2002/Ecore', 
                                           'GlobalModelManagement::EPackagesRegistryLocator')
        )
    );
}

-- *********** Helper for creating the tuple for the element type  
-- *********** Metametamodel
helper def: metametamodel(identifier : TupleType(name: String, concreteType: String, value :OclAny)
                          ,locator : TupleType(name: String, concreteType: String, value :OclAny))
:TupleType(name: String, concreteType: String, value :OclAny) =
 
	let id: String = identifier.value.asSequence()->first().value in
	let concreteType: String = 'GlobalModelManagement::Metametamodel' in
	let creationId: String = '@' + concreteType + '#' + id in
	let attributes : Set(TupleType(name: String, concreteType: String, value :OclAny)) = 
		Set{
			Tuple{name = '__id', concreteType = 'String', value = id},
			identifier, 
		    locator, 
		    Tuple{name = 'conformsTo', concreteType = 'GlobalModelManagement::ReferenceModel', value = creationId}
		} in 
	Tuple{creationId = creationId, concreteType = concreteType, value = attributes} 
; 

-- *********** Helper for creating the tuple for the element type 
-- *********** Identifier
helper def: identifier(attrName: String, value: String, concreteType: String) 
:TupleType(name: String, concreteType: String, value :OclAny) =

	let elementAttribute : Set(TupleType(name: String, concreteType: String, value :OclAny)) =
		Set{Tuple{name = 'value', concreteType = 'String', value = value}} in
	Tuple{name = attrName, concreteType = concreteType, value = elementAttribute}	
;

-- *********** Helper for creating the tuple for the element type 
-- *********** Locator
helper def: locator(attrName: String, value: String, concreteType: String) 
:TupleType(name: String, concreteType: String, value :OclAny) =

	let elementAttribute : Set(TupleType(name: String, concreteType: String, value :OclAny)) =
		Set{Tuple{name = 'value', concreteType = 'String', value = value}} in
	Tuple{name = attrName, concreteType = concreteType, value = elementAttribute}	
;
Code explanation

YYY

To be completed.

Support

Relationships with other Eclipse Projects

MoScript reuses different existing EMP (Eclipse Modeling Project) projects: To be completed.

Back to the top