0

pom.xmlXText 2.0を使用するプロジェクト、特に「プレーンな」MavenプロジェクトのコードジェネレーターXPおよび1.1の例を探しています。

私はすでにグーグルで時間を過ごしていますが、間違った用語を使用したり、例がなかったりする可能性があります。

xtext 0.7.2ですでに動作しているpomがあり、プロジェクトを2.0に更新したいと思います。でもどこから始めたらいいのかわからない。私が現在持っているのは、4つのMavenプロジェクトのこの構造です。

  • mydsl
  • mydsl.generator(未使用)
  • mydsl.ui
  • アプリケーション(コードを生成するためのxpandテンプレートを含む)

mydslプロジェクトはxtext0.7.2プロジェクトであり、(mydsl)に追加のpomがあり、生成されたクラスをmaven依存関係として提供します。

applicationは、mweソースコードを生成するためのワークフローとxpandテンプレートがあります。このプロジェクトには、Mavenの依存関係がありますmydsl

私はそれほど多くのGUIエディター機能を実装していないので、すべてのxtextのもの(グラマーとxpandテンプレートを除く)を捨てて、完全に新しいxtext2プロジェクトを構築することを除いてさえします。

しかし、(新しい)mydslプロジェクトのpomを構築する方法は本当にわかりません。

4

2 に答える 2

2

本物のMavenxtext2プロジェクトを見つけました。

これを確認してください: http ://code.google.com/a/eclipselabs.org/p/spray/

于 2011-10-13T08:19:10.047 に答える
1

最もトリッキーな部分の1つは、XText2文法プロジェクトでは、xtend-gen名前が付いたフォルダーにファイルがあることです<<project>>Generator.java。そのファイルはGenerate<<project>>.mwe2ワークフローによって作成されたものではなく、日食の魔法によって作成されたものであることがわかります。しかし、このファイルはコードをコンパイルするために必要です!

だから私の解決策は、Eclipseにそのファイルを生成させてから、通常の手書きのクラスのようにそれをsvnに追加することです。

次に、このpomをプロジェクトに追加するだけです。したがって、Mavenもワークフローを開始します。 ただし、欠点が1つあります。ワークフローは隣接プロジェクトのクラスも生成するため、マニフェストファイルが必要になります.ui.testMavenリリースプラグインの問題を克服するために、文法プロジェクトと2つのダミーを含む親Mavenプロジェクトを追加することができます.ui.test

xtext文法を含むプロジェクトのPom:

...
<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。これは、xtext0.7.1の場合とほぼ同じです。しかし、1つの違いがあります。mweMweReaderファイルで使用されているものはもう終了しません(xtext 1.0.1以降)。したがって、を使用する必要がありますorg.eclipse.xtext.mwe.Reader。このリーダーは、モデルファイルを入力としてではなく、ファイルへのパスを受け取ります。また、いわゆる「スロット」に保存します。しかし、このスロットは要素のリストです。したがって、変更する必要がありFORます <expand value="templates::Main::main FOR model"/>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>

そのプロジェクトのMweワークフロー

<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>
于 2011-10-17T12:15:18.003 に答える