其中最棘手的部分是在XText2語法項目會出現在xtend-gen
文件夾woth名<<project>>Generator.java
的文件。該文件不是由Generate<<project>>.mwe2
工作流創建的,而是它通過某種eclipse魔術創建的。但是這個文件需要編譯代碼!
所以我的解決方案是讓Eclipse生成該文件,然後像任何正常的手寫類一樣將其添加到svn。
然後只需要添加這個pom到項目中。所以maven也會啓動工作流程。 但有一個缺點:工作流程還會生成相鄰項目的類.ui
和.test
,因此它需要清單文件。爲了克服行家發佈插件的麻煩,還可以加上父母Maven項目,包含語法項目和兩個假人.ui
和.test
聚甲醛項目的含XTEXT語法:
...
<dependencies>
<dependency>
<groupId>org.eclipse.plugins</groupId>
<artifactId>org.eclipse.xtext.generator</artifactId>
<version>2.0.0.v201106070531</version>
</dependency>
<dependency>
<groupId>org.eclipse.plugins</groupId>
<artifactId>org.eclipse.emf.codegen.ecore</artifactId>
<version>2.6.1.v20100914-1218</version>
</dependency>
<dependency>
<groupId>org.antlr.generator</groupId>
<artifactId>org.antlr.generator</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.plugins</groupId>
<artifactId>org.eclipse.emf.mwe2.launch</artifactId>
<version>2.0.0.v201106070634</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
</resource>
<resource>
<directory>src-gen</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/src-gen</directory>
<includes>
<include>com/</include>
<include>org/</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${basedir}/xtend-gen</directory>
<includes>
<include>com/</include>
<include>org/</include>
</includes>
<excludes>
<exclude>**/ProdDef2Generator.java</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.fornax.toolsupport</groupId>
<artifactId>fornax-oaw-m2-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<!-- <checkResources> <checkResource> src/com\queomedia\bcsweb\productdefinition\ProdDef2.xtext
</checkResource> </checkResources> -->
<outletSrcDir>src-gen</outletSrcDir>
<outletSrcOnceDir>src</outletSrcOnceDir>
<rootDir>${project.basedir}</rootDir>
</configuration>
<executions>
<execution>
<id>generateGrammer</id>
<phase>generate-sources</phase>
<goals>
<goal>run-workflow</goal>
</goals>
<configuration>
<workflowDescriptor>src/org/test/test/GenerateProdDef2.mwe2</workflowDescriptor>
<workflowEngine>mwe2</workflowEngine>
<timestampFileName>generator-generateGrammer-timestamp.tmp</timestampFileName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src-gen</source>
<source>xtend-gen</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- The plugin.xml must be included, but is not on a resource path -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<copy todir="${basedir}/target/classes" file="${basedir}/plugin.xml" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
使用語法和dsl進行源代碼生成的項目的POM。這與xtext 0.7.1幾乎相同。但有一個區別。在mwe文件中使用的MweReader
不會退出(因爲xtext 1.0.1)所以需要使用org.eclipse.xtext.mwe.Reader
。該閱讀器不再將模型文件作爲輸入,而是文件的路徑。而且它還將其存儲在所謂的「插槽」中。但是這個插槽是一個元素列表。因此,人們需要改變:在<expand value="templates::Main::main FOR model"/>
的FOR
到FOREACH
<dependencies>
<dependency>
<groupId>test.xtext</groupId>
<artifactId>grammerProject</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.plugins</groupId>
<artifactId>org.eclipse.xtext.generator</artifactId>
<version>2.0.0.v201106070531</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.plugins</groupId>
<artifactId>org.eclipse.emf.codegen.ecore</artifactId>
<version>2.6.1.v20100914-1218</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.antlr.generator</groupId>
<artifactId>org.antlr.generator</artifactId>
<version>3.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.plugins</groupId>
<artifactId>org.eclipse.emf.mwe2.launch</artifactId>
<version>2.0.0.v201106070634</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<!-- there is the .mwe workflow located, in a sub dir called model, the dsl and in an other sub dir called templates, the xpt files. -->
<directory>src/main/xtext</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.fornax.toolsupport</groupId>
<artifactId>fornax-oaw-m2-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<rootDir>${project.basedir}</rootDir>
<!-- run only if this file is changed -->
<checkResources>
<checkResource>
src/main/xtext/model/GermanDesk.proddef2
</checkResource>
</checkResources>
<!--
<outletSrcDir>src-gen</outletSrcDir>
<outletSrcOnceDir>src</outletSrcOnceDir>
-->
</configuration>
<executions>
<execution>
<id>generateJavaClassesFromXText</id>
<phase>generate-sources</phase>
<goals>
<goal>run-workflow</goal>
</goals>
<configuration>
<!-- Die Workflow-Description wird in einem Ressourcen-Verzeichnis gesucht. -->
<workflowDescriptor>ProdDef2JavaGenerator.mwe</workflowDescriptor>
<workflowEngine>mwe</workflowEngine>
<properties>
<projectBasedir>${project.basedir}</projectBasedir>
</properties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
兆瓦的工作流程在該項目
<workflow>
<property name="project.src.directory" value="${projectBasedir}/src/main"/>
<property name="project.target.directory" value="${projectBasedir}/target"/>
<property name="modelFileDir" value="${project.src.directory}/xtext/model/"/>
<property name="srcGenTargetDir" value="${project.target.directory}/generated-sources"/>
<property name="templateTargetDir" value="${project.target.directory}/generated-sources-templates"/>
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" platformUri=".."/>
<component class="org.eclipse.emf.mwe.utils.DirectoryCleaner" directory="${srcGenTargetDir}"/>
<component class="org.eclipse.emf.mwe.utils.DirectoryCleaner" directory="${templateTargetDir}"/>
<component class="org.eclipse.xtext.mwe.Reader" path="${modelFileDir}" >
<register class="com.queomedia.bcsweb.productdefinition.ProdDef2StandaloneSetup"/>
<load slot='model' type='Model'/>
</component>
<component class="org.eclipse.xpand2.Generator">
<metaModel class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<fileEncoding value="UTF-8"/>
<expand value="templates::ProductCustomClass::productCustomClasses FOREACH model"/>
<genPath value="${templateTargetDir}"/>
<beautifier class="org.eclipse.xpand2.output.JavaBeautifier"/>
</component>
<component class="org.eclipse.xpand2.Generator">
<metaModel class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<fileEncoding value="UTF-8"/>
<expand value="templates::Main::main FOREACH model"/>
<genPath value="${srcGenTargetDir}"/>
<beautifier class="org.eclipse.xpand2.output.JavaBeautifier"/>
</component>
</workflow>