|
|
|
|
Re: Creating Ant Build files for Xtext projects [message #648210 is a reply to message #634240] |
Tue, 11 January 2011 19:20 |
|
Hello,
I have just the same problem.
My xtext project builds fine within eclipse, but not using ant.
I have "exported" the dsl project as an ant buildfile. The export dialog states
Quote: | There is a build cycle in the source directories of project "MyDSL". Exported Ant buildfile will not compile your sources correctly until you eliminate the cycle: src -> src-gen -> src
|
Nevertheless the generated ant buildfile looks ok at the first glance. But running the build.xml as Ant Build... the java compiler complains
Buildfile: mydsl\build.xml
clean:
[delete] Deleting directory mydsl\bin
build-subprojects:
init:
[mkdir] Created dir: mydsl\bin
[copy] Copying 7 files to mydsl\bin
[copy] Copying 6 files to mydsl\bin
build-project:
[echo] mydsl: mydsl\build.xml
[javac] Compiling 6 source files to mydsl\bin
[javac] mydsl\src\mydsl\MyDslRuntimeModule.java:9: cannot find symbol
[javac] symbol : class AbstractMyDslRuntimeModule
[javac] location: package mydsl
[javac] public class MyDslRuntimeModule extends mydsl.AbstractMyDslRuntimeModule {
[..]
The reason seems to be that the class AbstractMyDslRuntimeModule is located under the src-gen tree which is not yet compiled.
The build.xml files looks like
[..]
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="mydsl.classpath"/>
</javac>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src-gen"/>
<classpath refid="mydsl.classpath"/>
</javac>
</target>
[..]
Here javac seems to be executed two times, first time for src, second time for src-gen. But swaping the order of those two build steps ends in a similar problem. Some classes under src-gen have dependencies to classes under src and vice versa.
How can I get this working? Can somebody give me a hint?
Regards,
Jonatan
PS: I want to build and publish my dsl plugins headless using hudson.
[Updated on: Thu, 13 January 2011 16:55] Report message to a moderator
|
|
|
[solved[ Creating Ant Build files for Xtext projects [message #648616 is a reply to message #634240] |
Thu, 13 January 2011 16:55 |
|
Hello,
since nobody seems to know how to automate Xtext builds for headless ci systems I give the answer myself.
But my soultion is only a work around, it does not feel like the best way.
First of all I have generated the ant buildfiles as stated above. But these auto generated files have a couple of drawbacks. Especially ant seems to be unable to handle multiple source folders. To work around the source cycle I just copy all the sources from src to src-gen within the init build step. Additionally I added a build target to run the GenerateMyDSL workflow to generate all the xtext stuff.
My ant buildfile for mydsl project now looks like this:
<project basedir="." default="build" name="mydsl">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="path/to/eclipse"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.5"/>
<property name="source" value="1.5"/>
<path id="Plug-in Dependencies.libraryclasspath">
[..]
</path>
<path id="mydsl.classpath">
<pathelement location="bin"/>
<path refid="Plug-in Dependencies.libraryclasspath"/>
</path>
<target name="init-gen">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init-gen" name="gen">
<java classname="org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher" classpathref="mydsl.classpath" fork="true">
<arg value="src/mydsl/GenerateMyDsl.mwe2"/>
</java>
</target>
<target name="init-build">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src-gen">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="src-gen">
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
<delete dir="src-gen/*"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="gen,build-project" name="build"/>
<target depends="init-build" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src-gen"/>
<classpath refid="mydsl.classpath"/>
</javac>
</target>
</project>
With this ant buildfile I am able to generate and compile the mydsl project. The next step is to build the generator project. One can let eclipse generate the ant buildfile for this project as well. But it will not work without some tweeks. Additionally I added a build target to generate the runable generator jar. One can get the full create_run_jar target by simply do the export manually once. Within the export wizzard one can issue the creation of the ant buildfile for that export. But I had to tweek this one as well. This is my build.xml for the generator project:
<project basedir="." default="build" name="mydsl.generator">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="path/to/eclipse"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="Plug-in Dependencies.libraryclasspath">
<pathelement location="../mydsl/bin"/>
[..]
</path>
<path id="mydsl.generator.classpath">
<pathelement location="bin"/>
<path refid="Plug-in Dependencies.libraryclasspath"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="mydsl.generator.classpath"/>
</javac>
</target>
<target name="create_run_jar">
<jar destfile="../MyDslGenerator.jar">
<manifest>
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
<attribute name="Rsrc-Main-Class" value="mydsl.generator.MyDSLLauncher"/>
<attribute name="Class-Path" value="."/>
<attribute name="Rsrc-Class-Path" value="./ [..]"/>
</manifest>
<zipfileset src="../jar-in-jar-loader.zip"/>
<fileset dir="../mydsl.generator/bin"/>
<fileset dir="../mydsl/bin"/>
[..]
</jar>
</target>
</project>
Now I am able to use hudson to automatically generate, build and deploy the mydsl generator. The next step will be to generate the deployable feature for eclipse as well. But this step seems to be more tricky, because the pde.exportFeatures can only be executed within an eclipse workspace.
Regards,
Jonatan
|
|
|
|
Re: Creating Ant Build files for Xtext projects [message #649127 is a reply to message #648705] |
Mon, 17 January 2011 19:27 |
No real name Messages: 101 Registered: August 2010 |
Senior Member |
|
|
Since the main issue is the src -> src-gen -> src dependency, you can resolve that as follows for the grammar plugin. Create a file call customBuildCallbacks.xml in the grammar plugin. Put the following in there:
Make sure you change <arg value="src/org/xtext/example/..." > to what is appropriate for your grammar plugin.
<!-- ===================================================================== -->
<!-- Custom targets called from a project's generated build.xml -->
<!-- Set customBuildCallbacks=<path/to/this/file> in your build.properties.-->
<!-- ===================================================================== -->
<project name="Build specific targets and properties" default="noDefault">
<!-- ===================================================================== -->
<!-- Default target -->
<!-- ===================================================================== -->
<target name="noDefault">
<echo message="This file must be called with explicit targets" />
</target>
<!-- ===================================================================== -->
<!-- Steps to do before the target build.jars -->
<!-- Available parameters : -->
<!-- build.result.folder - folder to contain the build results -->
<!-- ===================================================================== -->
<target name="pre.build.jars">
</target>
<!-- ===================================================================== -->
<!-- Steps to do after the target build.jars -->
<!-- Available parameters : -->
<!-- build.result.folder - folder to contain the build results -->
<!-- ===================================================================== -->
<target name="post.build.jars">
</target>
<!-- ===================================================================== -->
<!-- Steps to do before the target build.sources -->
<!-- Available parameters : -->
<!-- build.result.folder - folder to contain the build results -->
<!-- ===================================================================== -->
<target name="pre.build.sources">
</target>
<!-- ===================================================================== -->
<!-- Steps to do after the target build.sources -->
<!-- Available parameters : -->
<!-- build.result.folder - folder to contain the build results -->
<!-- ===================================================================== -->
<target name="post.build.sources">
</target>
<!-- ===================================================================== -->
<!-- Steps to do before the compilation target <name> -->
<!-- Substitute "name" with the name of the compilation target, eg @dot -->
<!-- Available parameters : -->
<!-- source.foldern : n = 1 ... N, the source folders -->
<!-- target.folder : where the results of the compilation go -->
<!-- <name>.classpath : name = name of the compilation target. A -->
<!-- reference to the classpath structure. -->
<!-- ===================================================================== -->
<target name="pre.name">
</target>
<target name="pre.@dot">
<path id="gen.classpath">
<path refid="@dot.classpath" />
<pathelement location="src" />
</path>
<java classname="org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher"
classpathref="gen.classpath" fork="true">
<arg value="src/org/xtext/example/hlm/GenerateMyHLM.mwe2" />
</java>
</target>
<!-- ===================================================================== -->
<!-- Steps to do during the compilation target <name>, after the compile -->
<!-- but before jaring. Substitute "name" with the name of the compilation-->
<!-- target, eg @dot -->
<!-- Available parameters : -->
<!-- source.foldern : n = 1 ... N, the source folders -->
<!-- target.folder : where the results of the compilation go -->
<!-- <name>.classpath : name = name of the compilation target. A -->
<!-- reference to the classpath structure. -->
<!-- ===================================================================== -->
<target name="post.compile.name">
</target>
<target name="post.compile.@dot">
</target>
<!-- ===================================================================== -->
<!-- Steps to do after the compilation target <name> -->
<!-- Substitute "name" with the name of the compilation target, eg @dot -->
<!-- Available parameters : -->
<!-- jar.Location - the location of the compilation results -->
<!-- <name>.classpath : name = name of the compilation target. A -->
<!-- reference to the classpath structure. -->
<!-- ===================================================================== -->
<target name="post.name">
</target>
<target name="post.@dot">
</target>
<!-- ===================================================================== -->
<!-- Steps to do before the target gather.bin.parts -->
<!-- Available parameters : -->
<!-- build.result.folder - folder containing the build results -->
<!-- target.folder - destination folder -->
<!-- ===================================================================== -->
<target name="pre.gather.bin.parts">
</target>
<!-- ===================================================================== -->
<!-- Steps to do after the target gather.bin.parts -->
<!-- Available parameters : -->
<!-- build.result.folder - folder containing the build results -->
<!-- target.folder - destination folder -->
<!-- ===================================================================== -->
<target name="post.gather.bin.parts">
</target>
<!-- ===================================================================== -->
<!-- Steps to do before the target gather.sources -->
<!-- Available parameters : -->
<!-- destination.temp.folder - destination folder -->
<!-- ===================================================================== -->
<target name="pre.gather.sources">
</target>
<!-- ===================================================================== -->
<!-- Steps to do after the target gather.sources -->
<!-- Available parameters : -->
<!-- destination.temp.folder - destination folder -->
<!-- ===================================================================== -->
<target name="post.gather.sources">
</target>
<!-- ===================================================================== -->
<!-- Steps to do before the target gather.logs -->
<!-- Available parameters : -->
<!-- destination.temp.folder - destination folder -->
<!-- ===================================================================== -->
<target name="pre.gather.logs">
</target>
<!-- ===================================================================== -->
<!-- Steps to do after the target gather.logs -->
<!-- Available parameters : -->
<!-- destination.temp.folder - destination folder -->
<!-- ===================================================================== -->
<target name="post.gather.logs">
</target>
<!-- ===================================================================== -->
<!-- Steps to do before the target clean -->
<!-- Available parameters : -->
<!-- destination.temp.folder - destination folder -->
<!-- ===================================================================== -->
<target name="pre.clean">
</target>
<!-- ===================================================================== -->
<!-- Steps to do after the target clean -->
<!-- Available parameters : -->
<!-- plugin.destination - final destination of the build -->
<!-- build.result.folder - results of the compilation -->
<!-- temp.folder - temporary folder -->
<!-- ===================================================================== -->
<target name="post.clean">
</target>
</project>
In the build.properties file of your grammar plugin, put the following:
customBuildCallbacks = customBuildCallbacks.xml
customBuildCallbacks.failonerror = true
customBuildCallbacks.inheritall = true
Now you can create a fourth plugin called build or something which builds the grammar, generator, and ui plugins. Each time, the .mwe2 launcher will run on your grammar (.xtext) file to create the necessary java code. Hope this helps.
|
|
|
Powered by
FUDForum. Page generated in 0.02953 seconds