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.
STEM Create EMF Project
Contents
- 1 How to create a JSON Logger for STEM
- 1.1 Create an EMF Project
- 1.2 Create Ecore Model
- 1.3 Create Generator Model (GenModel)
- 1.4 Customize the Generator Model (Tricky)
- 1.5 Run the EMF Code Generator
- 1.6 Correct Errors from Code Generation
- 1.7 Fix error in JsonEditor
- 1.8 Add Extension Point definition
- 1.9 Add the new plug-in to STEM's Run Configuration
- 1.10 Test Creating Logger in STEM
- 1.11 Implement the Logger
How to create a JSON Logger for STEM
Tutorial demonstrating a new EMF Project
# Note: * I substitute "`org.eclipse.stem`" with "`o.e.s`" in places
Create an EMF Project
1. File -> New -> Eclipse Modeling Framework -> Empty EMF Project 2. Project Name: `org.eclipse.stem.loggers.json`
(note: another way to do this it to create the EMF model from a regular (non-EMF) project, then use the code generator to generate the EMF project. This can be useful if you're experimenting and will need to delete
Create Ecore Model
- File > New > Other > EMF -> Ecore Model. Click **Next**.
- Enter name `json.ecore`. **Finish**.
- The **EMF Ecore Model Editor** should now open
- Load Resource references:
- Right click, **Load Resources** > **Browse Workspace**
- Select `o.e.s.loggers/model/SimulationLogger.ecore`
- Set EPackage details. Select the (empty) EPackage in the editor
- Name: `json2`
- Ns Prefix: `org.eclipse.stem.loggers.json`
- NS URI: `http:///org/eclipse/stem/loggers/json`
- Create EClass
- Right click on `json` EPackage > New Child -> EClass
- Name: `JsonLogger`
- ESuper Type: `SynchronousDecoratorPropertyLogger`
- Add new `logPath` EAttribute to `JsonLogger`
- Right click on `JsonLogger` > New Child -> EAttribute
- Name: `logPath`
- EType: `EString`
- Add new `prettyPrint` EAttribute to EClass
- Name: prettyPrint
- EType: EBoolean
- Default value literal: false
- Save `json.ecore`
Create Generator Model (GenModel)
- Right click on the `json.ecore` file
- File > New > Other > EMF > EMF Generator Model. **Next**
- File name: `json.genmodel` in the `o.e.s.loggers.json/model` folder. **Next**
- Model importer; **Ecore Model**. **Next**
- Select `json.ecore` and click **Load**. **Next**
- Select the appropriate packages:
- Root packages (top): `json`
- Referenced generator models (bottom): Select the require ones (until errors go away)
- Click **Finish**
Customize the Generator Model (Tricky)
- In the `Properties` view, make the changes to these sections
- All
- Edit
- Remove '.edit' from the Edit plug-in ID and Directory
- Set Edit Plug-in Class to have the fully qualified package name (org.eclipse.stem.loggers.json)
- Editor
- Remove '.editor' from Editor plug-in ID and Directory
- Set Editor Plug-in to have fully qualified package name (org.eclipse.stem.loggers.json)
- Model
- No changes, although discuss suppressions (incl suppress notifications)
- Model Class Defaults
- Public constructors to true
- Set `Root Extends Class` to `org.eclipse.emf.ecore.impl.EObjectImpl` (the current default refers to new EMF behavior that is not understood or tested
- Model Feature Defaults
- No Changes
- Templates & Merge
- This is an interesting section and is used by parts of STEM to extend EMF (the Model Builder)
- No changes required right now
- Next, Select the `json` EPackage
- Set Base Package to be `org.eclipse.stem.loggers`
- Set Model / File Extension to `logger`
- Save Genmodel
Run the EMF Code Generator
- Right click on the GenModel (Top icon)
- Select Generate Model > Generate All
Correct Errors from Code Generation
- Remove unneeded lines from JsonPackage.java
- Open src/o.e.s.loggers.json/JsonPackage.java
- Comment out lines with errors
- Lines 167, 176, 185, 194, 203
- Save JsonPackage.java
Fix error in JsonEditor
- Open `src/org.eclipse.stem.loggers.json.presentation/JsonEditor.java`
- Go to line 984,
change: EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter()); to EditUIUtil.getURI(getEditorInput());
Add Extension Point definition
- Open org.eclipse.stem.loggers.json/plugin.xml
Inside the <plugin> tag Add:
<extension point="org.eclipse.stem.core.logger"> <classdef class="org.eclipse.stem.loggers.json.impl.JSONLoggerImpl"> </classdef> <dublin_core category_id="/" creator="%dc_creator" description="%dc_descr" identifier="%dc_identifier" license="%dc_license" publisher="%dc_publisher" source="%dc_source" title="%dc_title"/> </extension>
- Next, open org.eclipse.stem.loggers.json/plugin.properties and add or update the properties to
pluginName = STEM JSON Logger providerName = Eclipse Foundation
dc_identifier=org.eclipse.stem.loggers.json.dublin_core dc_publisher = The Eclipse Foundation dc_license = Eclipse Public License (EPL) dc_title = JSON File Logger dc_descr = STEM logger for writing the results of a simulation to a JSON formatted file dc_creator = STEM team dc_source = http://wiki.eclipse.org/STEM_Loggers
Add the new plug-in to STEM's Run Configuration
- Go to Run menu > Run Configurations
- Select stem2.product, then select **Plug-ins** tab
- Scroll through **Plug-ins** and check org.eclipse.stem.loggers.json
- Click **Apply** then **Close**
Test Creating Logger in STEM
- Launch STEM
- Click the new Logger wizard, JSON File Logger should be in the list. Select it
* Notice how the names in the wizard aren't really filled out yet. This is because we haven't hooked in the UI adapters yet. You can create the logger without these UI hooks, but the display (and NLS-supported) names don't show up
Implement the Logger
- Open `o.e.s.loggers.json.impl/JSONLoggerImpl.java`
- Add the following lines to override the parent methods called when a loggable event occurs
@Override public void simulationEvent(SimulationEvent event) { }
@Override public void loggerEvent(ISimulation simulation, LOGGER_EVENTS event) { }
- The loggerEvents(...) method receives notifications of logger events, including the creation of a new simulation that has a logger, the enabling or disabling of loggers, etc.
- The simulationEvent(...) method receives notifications of simulation events.
- To see a stream of events being received by the logger in the console, add the following to simulationEvent
System.err.println("JSON Logger Event: ["+event+"]");