Skip to main content

Notice: This Wiki is now read only and edits are no longer 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
(Eclipse Environment Setup)
 
(46 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Introduction =
+
#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.
= Eclipse Setup =
+
 
+
== 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 version 3.1.0
+
* Maven Integration for Eclipse (m2e)
+
** I used version 1.4.0
+
* Acceleo
+
** I used version 3.4.1
+
** I used update site: http://download.eclipse.org/modeling/m2t/acceleo/updates/releases/
+
* 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
+
 
+
== Eclipse Environment Setup ==
+
The following steps need only be done once per Eclipse environment setup.
+
 
+
# Clone the OSLC Core repository
+
## git clone git://git.eclipse.org/gitroot/lyo/org.eclipse.lyo.core.git
+
## cd org.eclipse.lyo.core
+
# 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
+
# 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.
+
# 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 ==
+
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''
+
 
+
The following steps take you from creating an initial Eclipse project to code generate and run your adaptor.
+
 
+
# In [[Lyo/AdaptorCodeGeneratorWorkshop#Create_an_OSLC4J_project | Create an OSLC4J project]], 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.
+
# In [[Lyo/AdaptorCodeGeneratorWorkshop#Instantiate_an_adaptor_model | Instantiate an adaptor model]], you will do the very basic step of creating an empty adaptor EMF model.
+
# In [[Lyo/AdaptorCodeGeneratorWorkshop#Define_your_adaptor_model | Define your adaptor model]], you will model your adaptor.
+
# In [[Lyo/AdaptorCodeGeneratorWorkshop#Configure_.26_run_the_adaptor_generator | Configure & run the adaptor generator]], you will configure the code generator in order to generate source code for your project - based on the model you have defined.
+
# In [[Lyo/AdaptorCodeGeneratorWorkshop#Fill_in_the_internal_implementation_of_the_adaptor | Fill in the internal implementation of the adaptor]], you will perform the manual coding of the remaining parts of the adaptor
+
# In [[Lyo/AdaptorCodeGeneratorWorkshop#Run_the_adaptor | Run the adaptor]], you are ready to run.
+
 
+
== 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]
+
 
+
# 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
+
# 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”
+
# 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 [[Media:OSLC4JCodeGeneratorconfigurationFileTemplates.zip | Configuration File Templates]] 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…”.
+
# 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/*
+
# 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'''
+
# 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 ===
+
'''Note:''' These steps are optional, but recommended
+
 
+
While an adaptor model can be completely defined from en empty instance, it is recommended to reuse some pre-defined domain specification models. (that is, this step can be skipped if your model uses no standard domain specifications)
+
# In the Project Explorer window, right-click on the newly created AdaptorInterface.xmi file, and select “open with --> Other … --> Sample Reflective Ecore Model Editor”.
+
# In the newly opened window, right-click and select the context menu “Load Resource …”
+
# Select Browse Workspace …
+
# Expand the “model” folder of the adaptorModel project.
+
# Select the desired domain specification(s) that you intend to use. (Note that these domain specification models are composed of each other. That is, including one – say ChangeManagement – may indirectly include another – in this case CoreSpecifications.)
+
# Press OK.
+
# Elements of the loaded domain specification models can now be referenced in the AdaptorInterface model you are creating.
+
 
+
'''Note:''' At any point when modelling your adaptor, you can repeat the above steps in order to load and use other domain specifications.
+
 
+
=== Define right-side of adaptor model ===
+
 
+
# Right-click on '''AdaptorInterface(1)''' instance and select “New Child --> '''Specification(5)'''
+
## This instance is a simple container of domain specifications and namespaces. No properties defined.
+
# '''Recall''': as detailed in section [[Lyo/AdaptorCodeGeneratorWorkshop#Load_existing_domain_specifications | Load existing domain specifications]], you can always reuse any pre-defined domain specification models. The following steps are only necessary for user-specific domain specifications, that you prefer to embed into your own adaptor model.
+
# Define any number of additional domain specifications. For each such domain specification:
+
## Right-click on the '''Specification(5)''' instance and select “New Child --> '''NamespacePrefix(6)'''
+
### For the newly-created NamespacePrefix, simply provide the prefix for the new domain specification.
+
## Right-click on the Specification(5) instance and select “New Child --> '''DomainSpecification(7)'''
+
### For the newly created DomainSpecification instance, fill-in its properties. (Note that the namespacePrefix property refers to an instance of NamespacePrefix(6))
+
### Define '''Resource(9)''' and/or '''ResourceProperty(8)''' instances as desired.
+
### Note that a Resource instance can refer to ResourceProperties from any other domainSpecification in the model.
+
 
+
=== Define left-side of adaptor model ===
+
# In the Project Explorer window, right-click on AdaptorInterface.xmi file, and select “open with --> Other … --> EMF Facet Model Browser”
+
# In the newly opened window, double-click on the '''AdaptorInterface(1)''' EMF instance to open its Properties window, and configure it.
+
## ''Note:'' To view and change properties of a model element, you can (a) right-click on the EMF instance within the “Instances” frame, and select “Show Properties View” or (b) double-click on the instance.
+
## The properties’ meaning is as follows:
+
### name: the name of your adaptor (for example, use the same name as your project name)
+
### javaClassBaseNamespace: the name of the base Java root package from which the code of your adaptor will be generated.
+
#### Make sure that this value matches “your.base.package.name” selected above.
+
### Java Files Base Path: The path of where java files will be generated. (for example, “/src/”)
+
### Javascript Files Base Path: The path of where javascript files will be generated. (for example, “/WebContent”)
+
### Jsp Files Base Path: The path of where the Jsp files will be generated. (for example, “/WebContent”)
+
# Right-click on AdaptorInterface instance and select “New Child --> '''ServiceProviderCatalog(2)'''
+
## For the newly created catalog, fill-in all its properties as defined according to OSLC.
+
## Note that you can only define 1 catalogue in an adaptor.
+
# Right-click on the ServiceProviderCatalog instance and select “New Child --> '''Publisher(4)'''
+
## For the newly created Publisher, fill-in all the Publisher properties as defined according to OSLC.
+
## Note that you can only define 1 Publisher for a catalog.
+
# Right-click on the ServiceProviderCatalogue instance and select “New Child --> '''ServiceProvider(3)'''
+
## For the newly created ServiceProvider, fill-in all the ServiceProvider properties as defined according to OSLC.
+
## Note that you can define one-or-many ServiceProviders for a ServiceProviderCatalogue.
+
# From each of the defined ServiceProviders,  proceed down to create and define '''Services(10)''' & '''Capabilities(11,12,13)'''.
+
## Make sure you fill-in all properties of each EMF instance you create.
+
## Make sure you satisfy the cardinality of each of the containment relationships as illustrated in the figure above.
+
## When defining the properties of '''Capabilities(11,12,13)''', make sure you define each of their Resource Types property. (Which are defined either under the '''Specifiation(5)''' EMF instance (see section [[Lyo/AdaptorCodeGeneratorWorkshop#Define_right-side_of_adaptor_model | Define right-side of adaptor model]]), or exist as part of a loaded domain specification (see section [[Lyo/AdaptorCodeGeneratorWorkshop#Load_existing_domain_specifications | Load existing domain specifications]]).)
+
 
+
== Configure & run the adaptor generator ==
+
 
+
# Define  a “run configuration” for adaptor code generation
+
## Select Run --> Run Configurations …
+
## Select Acceleo Application
+
## Press the “New launch configuration” button
+
### Name: something practical such as “Generate YourProviderProjectName”
+
### Project: select the “org.eclipse.lyo.oslc4j.codegenerator” project
+
### Main class: codegenerator.main.Generate
+
### Model: the newly created adaptormodel in the YourProviderProjectName project
+
### Target: The YourProviderProjectName project
+
## Press '''Apply'''
+
## Press '''Close'''.
+
# '''''Bug fix''''' – Did you compose your model from other models (section [[Lyo/AdaptorCodeGeneratorWorkshop#Load_existing_domain_specifications | Load existing domain specifications]]) and reference some of its elements in your adaptor model? Currently, the way EMF models reference each other in the xmi files causes problems with the code generator. Before you trigger the code generator, perform the following steps: (These steps need to be repeated if the adaptor model is later changed to include further references).
+
## Copy the workspace location of any loaded resources (EMF models)
+
### In the Project Explorer window, right-click on the AdaptorInterface.xmi file, and select “open with --> Other … --> Sample Reflective Ecore Model Editor”.
+
### In the newly opened window, right-click and select the context menu “Load Resource …”
+
### Select Browse Workspace …
+
### Select the domain specification EMF model that you have earlier loaded.
+
### Copy the path to the xmi file selected into the clipboard (it will be something like “platform:/resource/org.eclipse.lyo.oslc4j.adaptormodel/model/someSpecification.xmi”)
+
### Press Cancel.
+
## In the Project Explorer window, right-click on the AdaptorInterface.xmi file, and select “open with  XML Editor”
+
## Search and replace each “href” entry that refers to your domain specification.
+
### Replace href values that look like href="../../org.eclipse.lyo.oslc4j.adaptormodel/model/someSpecification.xmi#//..." with the copied value (which ought to look more like href="platform:/resource/org.eclipse.lyo.oslc4j.adaptormodel/model/someSpecification.xmi#//...").
+
## Repeat these steps for each domain specification model you have loaded and referenced.
+
# Once you are satisfied with your model, code generate the adaptor
+
## Select Run > Run Configurations …
+
## Select the “Generate YourProviderProjectName” configuration
+
## Press Run.
+
 
+
== Fill in the internal implementation of the adaptor ==
+
At a minimum, manual code is needed to connect the adaptor to the backend tool with which it communicate, as well as access its internal data that are eventually exposed as OSLC resources. This minimal code needs to be implemented in the AdaptorManager class (in the “your.base.package.name” package).
+
 
+
'''''TODO:''''' <Explain the methods in AdaptorManager that must be implemented>
+
 
+
'''''TODO:''''' <Explain the methods in the generated code that can be extended>
+
 
+
== Run the adaptor ==
+
 
+
You are now ready to 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