tobs
tobs

Reputation: 719

Generate Java Code from OCLInEcore in MWE2 Workflow

i am trying to generate Java Code from an .ecore meta model with OCL contstraints during a maven-tycho build. I have managed to get code generation to work within Eclipse, but the tycho build does not generate code for OCL.

Setup

I have an Ecore meta-model named model.ecore with embedded OCL Constraints (OCLInEcore). Since I don't want to use delegates i have

<genAnnotations source="http://www.eclipse.org/OCL/GenModel">
    <details key="Use Delegates" value="false"/>
    <details key="Use Null Annotations" value="true"/>
</genAnnotations>

in the corresponding model.genmodel file alongside with the operationReflection="true". This works fine when I open the Genmodel in Eclipse and choose "Generate Model Code" in the Genmodel Editor.

Problem

I want to call code generation from an .mwe2 modelling workflow to integrate the code generation in my maven-tycho build. Currently, my workflow file looks like this

module Generate

import org.eclipse.xtext.ecore.EcoreSupport
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl

import org.eclipse.emf.mwe.utils.StandaloneSetup
import org.eclipse.emf.mwe2.ecore.EcoreGenerator
import org.eclipse.emf.mwe2.runtime.workflow.Workflow

var rootPath
var pluginID

Workflow {
    bean = EcoreSupport {}
    bean = ResourceSetImpl : resourceSet {}
    
    bean = StandaloneSetup {
        resourceSet = resourceSet
        platformUri = rootPath
        scanClassPath = true
    }
    
    component = EcoreGenerator {
        resourceSet = resourceSet
        
        genModel = "platform:/resource/${pluginID}/model/model.genmodel"
        srcPath = "platform:/resource/${pluginID}/src-gen/"
        
        generateEdit = true
        generateEditor = true
    }
}

which is called during the generate-sources phase:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>mwe2Launcher</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher</mainClass>
        <arguments>
            <argument>${project.baseUri}/Generate.mwe2</argument>
            <argument>-p</argument>
            <argument>rootPath=${project.parent.basedir}</argument>
            <argument>-p</argument>
            <argument>pluginID=${project.artifactId}</argument>
        </arguments>
        <classpathScope>compile</classpathScope>
        <includePluginDependencies>true</includePluginDependencies>
        <includeProjectDependencies>true</includeProjectDependencies>
        <cleanupDaemonThreads>false</cleanupDaemonThreads>
        <stopUnresponsiveDaemonThreads>true</stopUnresponsiveDaemonThreads>
    </configuration>
    <dependencies>
       ...
    </dependencies>
</plugin>

The problem is that this seems to simply skip the relevant code generation for OCL.

I have found This bug report which pointed me towards these two projects org.eclipse.ocl.examples.build and org.eclipse.ocl.examples.codegen, but I'm struggling to figure out how to stick those pieces together.

Am I missing something obvious here?

Upvotes: 1

Views: 134

Answers (1)

Ed Willink
Ed Willink

Reputation: 1498

The EMF GenModel capabilities are almost exclusively used interactively within Eclipse where extension point registrations resolve many challenges automatically.

When you choose to work 'standalone' as with an MWE2 workflow you must ensure that you perform the requisite registrations.

(You also require that EMF's genmodel capabilities work standalone. I found that they relied on a JDT initialization for which bit rot had set in. This was worked around by OCL's GenModel bean. EMF / JDT have fixed the bit rot so there is now an MWE2 GenModel bean that might be similar; I have not used it.)

The registration that you need is at least the first of

  <extension point="org.eclipse.emf.codegen.ecore.generatorAdapters">
 <adapterFactory class="org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreGeneratorAdapterFactory"/>
 <adapterFactory modelPackage="http://www.eclipse.org/uml2/2.2.0/GenModel" class="org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreGeneratorAdapterFactory"/>

for which you may find initializeGeneratorAdapterFactoryRegistry() in OCLGenModelUtil.java helpful. It is invoked from EcoreGenModelSetup.java.

Upvotes: 2

Related Questions