Showing posts with label QVT. Show all posts
Showing posts with label QVT. Show all posts

Wednesday, January 30, 2013

QVT transformations with Eclipse [tutorial]

Eclipse has a running plugin for QVT Operational transformations. So, let's use it!

I suggest you start with the Eclipse Modeling Tools plus the Model-to-Model Operational QVT plugins (check how to download/install it).

Also, QVT requires a metamodel of the source and target languages being used (in case you don't know, a metamodel is a model that describes another model). In this example we'll use this simplified use case diagram metamodel. Lastly, of course, we need an actual model to be used as input! We will use this piece of a Meeting Scheduler use case diagram.

Ugly, right? Agreed...

If you want to create your own use case models, you can use the default editor that Eclipse can create, which allow you to edit models in a tree-based view. You can create an editor for our use case metamodel by following the steps I and II from this tutorial by Vitor Souza (in step II.2, you can use "usecasepackage" as the base package name). Then follow step IV for actually creating the model (the model object for the step IV.4 is just "Model").

But now, let's go the transformations!


Quick and Dirty version:

  1. Run Eclipse with QVT
  2. Create a new Operational QVT Project (File/New/Other.../Model to Model Transformation/Operational QVT Project). In the wizard, be sure to select "Create a simple project".
  3. Import the metamodel (.ecore) and the model (.usecase)
  4.   My favorite way of doing this is by just drag-and-dropping the files into the Project Explorer. Alternatively, right click your project, select 'Import...', General/File System
  5. Create a new Operational QVT Transformation (File/New/Other.../Model to Model Transformation/Operational QVT Transformation). In the Module name you write the name of the transformation you are creating.
  6. Now it is time for the obscure Eclipse configuration: go to Project/Properties/QVT settings/Metamodel Mappings, click 'Add' and define the source/target metamodels. In the source field you need to write the URI of the metamodel (in our example it's http://www.cin.ufpe.br/useCaseUri ). In the target field you can browse the current project and select the metamodel file.
  7. Code! Or use this transformation example.
  8. Now, more configuration. Right-click the transformation file and select Run As/Run Configurations...  , select 'Operational QVT Interpreter' and click the 'New launch configuration' button. Go to the Model URI field and Browse the project to select the input model file (.usecase)
  9. Press "Apply", to save these settings
  10. Run!


Now if everything is right you will see... nothing. Just go check the transformation results in your target model and be happy! Once these settings are done, all you need to run the transformation again is to select the transformation in the 'Run' dropdown button.

Thorough version:

  1. Run  Eclipse with QVT
  2.    Please make it wear a good tennis as not to harm its feet.
  3. Create a new Operational QVT Project. To do so, go to File/New/Other... (Ctrl+N) and then select 'Operational QVT Project' in the 'Model to Model Transformation' folder. In the wizard, be sure to select "Create a simple project", as shown in the pictures below. 
  4. File/New/Other...
    New Operational QVT Project

    Write the project name, select 'Create a simple project' and click Next

    Just finish
  5. Import the metamodel (.ecore) and the model (.usecase).  There are several ways to do this. My favorite one is to simply drag the files and drop them into Eclipse's Project Explorer (or Package Explorer, depending on the version of Eclipse).


  6. Create a new Operational QVT Transformation (File/New/Other.../Model to Model Transformation/Operational QVT Transformation). In the Module name you write the name of the transformation you are creating.

  7. Now it is time for the obscure Eclipse configuration: go to Project/Properties/QVT settings/Metamodel Mappings, click 'Add' and define the source/target metamodels. In the source field you need to write the URI of the metamodel (in our example it's http://www.cin.ufpe.br/useCaseUri ). In the target field you can browse the current project and select the metamodel file.


  8. We're almost done with the configuration, now you already can code your transformations. These slides may help you with that. Or, use this example based on the paper "Towards Architectural Evolution through Model Transformations", from SEKE2012:
    modeltype UseCase uses UseCase('http://www.cin.ufpe.br/useCaseUri');
    transformation AddActor(inout useCaseModel : UseCase);
    
    main()
    {
      useCaseModel.rootObjects()[Model].map applyAddActor();
    }
    
    mapping inout Model::applyAddActor()
    {
       self.actor += new Actor("newActor");
    }
    
    constructor Actor::Actor(myName : String)
    {
       name := myName;
    }
    
    
  9. Now, more configuration. Right-click the transformation file and select Run As/Run Configurations...  , select 'Operational QVT Interpreter' and click the 'New launch configuration' button. Go to the Model URI field and Browse the project to select the input model file (.usecase)


  10. Browse and select your input model
    After selecting the input model Eclipse may show an error like this: "Invalid source URI 'platform:/resource/UseCaseTransformation/MeetingScheduler.usecase' for parameter 'useCaseModel'". If this happens, you need to check if your model has the following attribute in its root node: xsi:schemaLocation="http://www.cin.ufpe.br/useCaseUri UseCase.ecore". This attribute is required for Eclipse to know which file to load for the given URI (even though we already defined that in step 5, go figure...)

  11. Press "Apply", to save these settings
  12. Press Run!
You can check the model to see if the new Actor was created:

Thursday, April 5, 2012

How to install Eclipse with QVT [Tutorial]

Yes, we can execute QVTo (QVT Operational) transformations with Eclipse!! If you already installed the Eclipse Modeling Tools, you just need to install the Operational QVT plugin (Jump to step 3). If not, here it goes:

Quick and Dirty version:

  1. Download Eclipse Modeling Tools
  2. Extract and run it
  3. In the Eclipse's 'Help' menu, click at 'Instal Modeling Components'
  4. Select 'Operational QVT' and follow the wizard
If you wanna know how to configure and run a QVT Operational transformation, check our other tutorial.

Thorough version:

  1. Go to the Eclipse Modeling Tools site and download it. Wait, you don't know the Eclipse website url? Let's find out


  2. Ok, now we know it: http://www.eclipse.org/

    Click at 'downloads', select the operating system and download it.

    Eclipse home
    Download area - Select OS and then download the Eclipse Modeling Tools
    Download it

  3. Waaaait for it. Once it is downloaded, move it to the folder you want it to be installed in (Let's say, 'C:\EclipseModeling') and extract it there. Waaaait for it. A 'eclipse' folder will be created. Open it and run Eclipse
  4. Extract it

    And run eclipse.exe (if Windows)

    The Eclipse will ask you to select a workspace folder, i.e., a project folders. Browse for a folder (or use the default one) and click 'Ok'.
    In doubt, just press 'Ok'

  5. Once Eclipse is open, go in the 'Help' menu and click at 'Instal Modeling Components'
  6. In the wizard that follows, select 'Operational QVT' (in the Model to Model section) and click 'Finish'

  7. Waaaait for it. Press 'Next' and then 'Next' again.
    'Next' ...
    ...and 'Next' again

    Here you are expected to read the license agreement, select 'I accept the terms of the license agreement' and click 'Finish'.
    'I accept' and 'Finish'
  8. Waaaait for it. When the installation is finished, you'll be requested to restart your Eclipse. Go on.
  9. Waaaait for it (I promise you this is the last one). Now you're done! If you wanna check it, go to 'File/New/Other...' menu (Ctrl+N) and see that you can create a new 'Model to Model Transformation/Operational QVT Project'.
File/New/Other...

New 'Operational QVT Project'
That's it! If you wanna know how to configure and run a QVT Operational transformation, check our other tutorial.