英文:
Generate Java Code from OCLInEcore in MWE2 Workflow
问题
我正在尝试从.ecore
元模型中使用OCL约束生成Java代码,这是在Maven-Tycho构建期间进行的。我已经成功在Eclipse中实现了代码生成,但是Tycho构建不会为OCL生成代码。
设置
我有一个名为model.ecore
的Ecore元模型,其中包含嵌入的OCL约束(OCLInEcore)。
由于我不想使用代理,我在相应的model.genmodel
文件中有以下内容:
<genAnnotations source="http://www.eclipse.org/OCL/GenModel">
<details key="Use Delegates" value="false"/>
<details key="Use Null Annotations" value="true"/>
</genAnnotations>
还有operationReflection="true"
。
当我在Eclipse中打开Genmodel并选择在Genmodel编辑器中"生成模型代码"时,这能正常工作。
问题
我想要从.mwe2
建模工作流中调用代码生成,以将代码生成集成到我的Maven-Tycho构建中。
目前,我的工作流文件如下所示:
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
}
}
这在"generate-sources"阶段期间调用:
<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>
问题在于,这似乎只是跳过了与OCL相关的代码生成。
我找到了这个错误报告,它指向了我两个项目org.eclipse.ocl.examples.build和org.eclipse.ocl.examples.codegen,但我很难弄清楚如何将这些部分组合在一起。
我是否漏掉了一些明显的东西?
英文:
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?
答案1
得分: 1
EMF GenModel 的能力几乎完全在 Eclipse 中以交互方式使用,其中扩展点注册自动解决了许多挑战。
当您选择像使用 MWE2 工作流一样“独立”工作时,您必须确保执行必要的注册。
(您还需要确保 EMF 的 genmodel 能力能够独立工作。我发现它们依赖于 JDT 初始化,但它可能已经出现了一些问题。这个问题可以通过 OCL 的 GenModel bean 解决。EMF / JDT 已经修复了这个问题,所以现在可能有一个类似的 MWE2 GenModel bean;我没有使用过。)
您需要注册的至少是以下之一:
您可能会发现 OCLGenModelUtil.java 中的 initializeGeneratorAdapterFactoryRegistry() 有帮助。它从 EcoreGenModelSetup.java 中调用。
英文:
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"/>
</extension>
for which you may find initializeGeneratorAdapterFactoryRegistry() in OCLGenModelUtil.java helpful. It is invoked from EcoreGenModelSetup.java.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论