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

MoScript

Revision as of 09:21, 22 December 2011 by Wolfgangklingc.gmail.com (Talk | contribs) (Operations)

< 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.

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

The MoScript Language

General Structure

A MoScript program has the following general structure:

program program_name

uses library ... 

[using {
    -- Comments

    -- Variable declarations 
    variable :type = OclExpr;
    ...
}]
 
do {
    -- Value assignements
    variable <− OclExpr;

    -- Operations invocations
    save(...);

    -- Operations invocations
    ... remove(OclExpr); 

    -- Operations invocations
    ... register (...) ;
         
    -- Control flow statements
    if...  

    -- Control flow statements
    for . .
}

helper context OclAny def: helper_name( params ) :return_type	
    . . . 
;

A program has two sections, the using and do sections. The using section is optional, and is used for declaring variables and assigning their initial value. The do section is mandatory and is the core of the program. In it, operations are used in combination with control flow statements and OCL queries to perform modelling artefacts manipulations.

Operations

Model :: allContentInstancesOf(String): Collection(OclAny)

This operation dereferences and load the physical model represented by the Model element. Then it queries the model and return a collection of OCL elements. The elements of the resulting collection are used as entry points to the model, from where the rest of the elements may be reached. Subsequent queries to the model are made with standard OCL expressions.

Model :: inject(injectorName: String, modelElement: TupleType) : Model

This operation make a projection of model stored in a textual syntax to a model stored in XMI conforming to a given metamodel.

ReferenceModel :: registerInEMFpkgReg()

This operation registers the reference model in the EMF packages registry

Examples

  • Get all the models in the megamodel, select the first and and get a collection of all its elements of type EClass.
    !Model.allInstances()->first().allContentInstancesOf('EClass');

Screencasts & slides

MoScript: A textual DSL for model manipulations (slides)

Related publications

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 Part 1

A requisite for start working with MoScript is to count with a populated megamodel i.e, a megamodel with elements, which point to modeling artefacts. This megamodel population can be done through the AM3 graphical user interface, nevertheless registering a high amount of models in the megamodel through the GUI is a repetitive and time consuming task. In those cases is better to use a textual syntax, so we can repeat the process the times we want, make changes easily to it or take it as base for future megamodel populations. In this use case we show how is possible to programmatically populate the Megamodel with MoScript. Click here for more details and actual resources...

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