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 "Lyo/AdaptorCodeGeneratorWorkshop"

< Lyo
(Define your adaptor model)
 
(67 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Getting Started With Adaptor Code Generation =
+
#REDIRECT [[Lyo/ToolchainModellingAndCodeGenerationWorkshop | Graphical Toolchain Modelling and Code Generation Workshop]]
 
+
'''''News''''': This workshop is now integrated into the [[Lyo/ToolchainModellingAndCodeGenerationWorkshop | Graphical Toolchain Modelling and Code Generation Workshop]]. The new modelling approach supports the modelling of a complete toolchain (including interactions between OSLC servers and clients), as well as a single server and/or client.
== Necessary Eclipse Installations ==
+
1. Install Eclipse Standard Kepler (4.3.1)
+
* Unless already installed, you need to first install a JDK (at least version 7 is necessary)
+
2. install the following (using Eclipse’s “Help > Install new software” dialog)
+
* Eclipse Git Team Provider (EGit)
+
** I used the Update Site: http://download.eclipse.org/egit/updates
+
** I used version 3.1.0
+
* Maven Integration for Eclipse (m2e)
+
** I used update site: http://download.eclipse.org/technology/m2e/releases
+
** I used version 1.4.0
+
* Acceleo
+
** I used update site: http://download.eclipse.org/modeling/m2t/acceleo/updates/releases/
+
** I used version 3.4.1
+
* Eclipse Java EE Developer Tools
+
** I used version 3.5.1
+
* Eclipse Java Web Developer Tools
+
** I used version 3.5.1
+
* EMF Facet SDK (Incubation)
+
** I used version 0.3.1
+
* EMF - Eclipse Modeling Framework SDK
+
** I used version 2.9.1
+
* Diagram Editor for Ecore (SDK)
+
** I used version 1.2.0.201306071421
+
 
+
== Eclipse Environment Setup ==
+
The following steps need only be done once per Eclipse environment setup.
+
 
+
1. Clone the OSLC Core repository
+
* git clone git://git.eclipse.org/gitroot/lyo/org.eclipse.lyo.core.git
+
* cd org.eclipse.lyo.core
+
* ''(Optional)'' You are working towards the KTH repository, in order to get the latest changes, or to further develop the generators and models.
+
** git remote add kth http://<your_username>@git.md.kth.se:8080/scm/git/se.kth.md.lyo.core
+
** git fetch kth
+
** git checkout -b someBranch kth/ someBranch (where someBranch is a branch you are to work on)
+
 
+
2. View the Git repository in Eclipse
+
* Open the Git Repositories view in Eclipse
+
* Click the “Add an existing local Git repository” icon.
+
* Select the “org.eclipse.lyo.core” repository
+
* The repository should now show up in your Git Repositories view
+
 
+
3. Import the Eclipse projects from the Git repository
+
* In the Git Repositories view, right click the org.eclipse.lyo.core repository and select Import Projects
+
* Select the Import Existing Projects wizard and click next
+
* Select the “adaptor_model” & “codegenerator” projects.
+
 
+
4. ''(Optional)'' Import sample generated projects
+
* git clone http://<your_username>@git.md.kth.se:8080/scm/git/se.kth.md.iee
+
* Repeat steps 3  & 4 above to import the OSLC4J projects found under the “src” directory.
+
 
+
5. Make sure '''JAVA_HOME''' environment variable is set to [at least] a JDK 1.6.
+
* JRE of eclipse needs to use JRE in the JDK dir
+
* Select '''''Window-->Preferences'''''
+
* Select '''''Java-->Installed JREs'''''
+
* Click '''''Add…'''''
+
* In the new window that appears,
+
** choose '''''Standard VM''''' as JRE Type
+
** click '''''Next'''''.
+
** As '''''JRE home''''' choose the installation dir of your JDK 1.6
+
** click '''''Finish'''''.
+
* Back to the preferences screen
+
** select the old JRE
+
** click Remove
+
** check the newly added JDK and
+
** click '''''OK'''''.
+
 
+
== OSLC4J Project Setup for code generation ==
+
 
+
=== Introduction ===
+
The following steps take you from creating an initial Eclipse project to code generate and run your adaptor.
+
 
+
1. In 3.2, you will create an empty project that is configured to start developing an OSLC4J adaptor. The instructions target our code generator. Yet, after these steps, you may also be able to proceed with manually developing your adaptor.
+
 
+
2. In 3.3, you will do the very basic step of creating an empty adaptor EMF model.
+
 
+
3. In 3.4, you will model your adaptor.
+
 
+
4. In 3.5, you will configure the code generator in order to generate source code for your project - based on the model you have defined.
+
 
+
5. In 3.6, you will perform the manual coding of the remaining parts of the adaptor
+
 
+
6. In 3.7, you are ready to run.
+
 
+
First of all, decide on the following 2 values for your particular project. In these instructions we will use the following generic values.
+
* '''ProjectName''': ''YourProviderProjectName''
+
* '''PackageName''': ''your.base.package.name''
+
 
+
 
+
=== Create an OSLC4J project ===
+
This information is based on the tutorial from [https://www.mbat-artemis.eu/home/index.php/dissemination/education-and-training?download=37:mbat-tutorial-implementing-oslc-consumers-and-providers-in-java-oslc4j-eclipse the MBAT Tutorial on Implementing OSLC Consumers and Providers with OSLC4J]
+
 
+
1. Create a JAVA EE Web Application
+
* File-->New-->Project…
+
* Select “Web/Dynamic Web Project”
+
* As project name, specify YourProviderProjectName
+
* On the final step of the wizard, check the “Generate web.xml …“ option
+
* Select Finish
+
 
+
2. Convert project to Maven
+
* Right click on the project, and select Configure Convert to Maven Project
+
* In the window that appears, select “war” under “Packaging”
+
 
+
3. Configure the project
+
* Create a folder '''test''' at the root of the project
+
* Create the sub-folders “launches” & “resources” under the new folder “test”
+
* Copy the 3 configuration files from  the “confFileTemplates” folder into the corresponding folders:
+
** / YourProviderProjectName/pom.xml
+
** / YourProviderProjectName/WebContent/WEB-INF/web.xml
+
** / YourProviderProjectName/test/resources/jetty.xml
+
* Search and replace each of the following keywords with the specific values for your project
+
** ProjectName: YourProviderProjectName
+
** PackageName: your.base.package.name
+
* If you get the error “Project configuration is not up-to-date with pom.xml”, simply right click on the YourProviderProjectName project and select “Maven-->Update Project…”.
+
 
+
4. Activate Project Facet JAX-RS
+
* Right click the project & Select '''properties'''
+
* Open '''Project Facets'''
+
* Select '''JAX-RS (REST Web Services)'''
+
* Click '''Further Configuration required…'''
+
* In the new window that appears
+
** Set '''Type:''' Disable Library Configuration
+
** Enter '''JAX-RS servlet class name''': org.apache.wink.server.internal.servlet.RestServlet
+
** Under '''URL mapping pattern''':
+
*** Remove the existing one
+
*** Add a new one /services/*
+
 
+
5. Further project configuration
+
* right click the project & select '''Properties'''
+
* select '''Deployment Assembly'''
+
* '''Add…'''
+
* In the new window that appears
+
** select '''Java Build Path Entries'''
+
** click '''Next >'''
+
** select '''Maven Dependencies'''
+
** click '''Finish'''
+
** click '''Apply'''
+
** click '''OK'''
+
 
+
6. Create a new Run configuration
+
* Select the menu '''Run-->Run Configurations …'''
+
* Select Maven Build
+
* Create a new Configuration
+
* Enter a '''name''' for the new configuration (such as Launch YourProviderProjectName)
+
* Set the '''Base directory''' to ${workspace_loc:/ YourProviderProjectName}
+
* Set '''Goal''' as jetty:run-exploded
+
* Switch to tab '''JRE'''
+
** Set '''Runtime JRE''' to Workspace default JRE…
+
* Switch to tab '''Source'''
+
** Click Add…
+
** In the new window, select Project and click OK
+
*** Check the YourProviderProjectName project
+
*** Check the “add required projects of selected projects” option
+
*** Click OK
+
* Switch to Tab '''Common'''
+
** Select Shared Files
+
** Click Browse…
+
** In the window that appears, select the recently created folder “test/launches” under the YourProviderProjectName project
+
** click '''OK'''
+
* Click '''Apply'''
+
* Clock '''Close'''
+
 
+
=== Instantiate an adaptor model ===
+
# Create a new folder “adaptorModel” in the YourProviderProjectName Project. (This is where the adaptorModel will be created.)
+
# Open the “adaptor_interface.ecore” model in the adaptor_model project (folder “model”)
+
# Expand the ecore model until the “AdaptorInterface” EClass
+
# Right-click on the AdaptorInterface EClass & select “Create Dynamic Instance …”
+
# In the dialog that appears
+
## select the folder “adaptorModel” under the YourProviderProjectName project as the “parent folder”
+
## choose a suitable File name for the adaptor model - AdaptorInterface.xmi is fine.
+
# Right-click on the newly created AdaptorInterface.xmi file, and select “open with --> Other … --> EMF Facet Model Browser”.
+
 
+
'''Eclipse Note:''' There are 2 ways to open/view/edit the adaptor model, which will be used below:
+
* EMF Facet Model Browser: A better interface when creating new EMF instances in the model, as well as being able to jump to specific types of instances within the model.
+
* Sample Reflective Ecore Model Editor: A good interface when composing EMF models of other EMF models (See below).
+
 
+
 
+
=== Define your adaptor model ===
+
The adaptor metal-model being instantiated is illustrated below. It consists of 2 main branches:
+
 
+
* The left side of the meta-model is a model of the OSLC core resources as defined in [http://open-services.net/bin/view/Main/OslcCoreSpecification?sortcol=table;up=#Service_Provider_Resources the OSLC Core Specification].
+
* The right side of the meta-model is a model of a typical OSLC domain specification.
+
 
+
[[File:AdaptorMetalModel.png]]
+
 
+
We will refer to this meta-model to explain how to define your adaptor model instance.
+
 
+
==== Load existing domain specifications (optional, but recommended) =====
+
 
+
==== Define right-side of adaptor model ====
+
 
+
==== Define left-side of adaptor model ====
+
 
+
=== Configure & run the adaptor generator ===
+
 
+
 
+
=== Fill in the internal implementation of the adaptor ===
+
 
+
=== Run the adaptor ===
+

Latest revision as of 14:22, 23 October 2016

News: This workshop is now integrated into the Graphical Toolchain Modelling and Code Generation Workshop. The new modelling approach supports the modelling of a complete toolchain (including interactions between OSLC servers and clients), as well as a single server and/or client.

Back to the top