Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Creating Ant Build files for Xtext projects
Creating Ant Build files for Xtext projects [message #634240] Wed, 20 October 2010 22:13 Go to next message
No real name is currently offline No real nameFriend
Messages: 101
Registered: August 2010
Senior Member
Hi,

For a sample Xtext project, I'm trying to generate a build.xml file for each of the three folders (grammar, generator, and ui). I go to File -> Export -> Generate Ant Build files. When I try to run this command to produce build.xml, I get a cycle detection saying "There is a build cycle in the source ...." and the cycle is src -> src-gen -> src. Ant buildfile will not compile your source until this is fixed.

How to I resolve this problem to create the build.xml. I have my folders checked in to SVN (.java files only) and I want to create the Ant build scripts to build each of the folders and then generate the .jar files for each folder

How do I fix this or is there some other way to do this? Thank you for any help.
Re: Creating Ant Build files for Xtext projects [message #634285 is a reply to message #634240] Thu, 21 October 2010 07:25 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
The projects the wizard creates, are plugin projects, so you can export them as "Deployable plugins or fragments", which creates the jars in a location of your choice.


Re: Creating Ant Build files for Xtext projects [message #634429 is a reply to message #634285] Thu, 21 October 2010 16:36 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 101
Registered: August 2010
Senior Member
Hi Meinte,

Thanks for the reponse. That is what I currently do except that it is a manual process. I want to automate this.

Thanks.
Re: Creating Ant Build files for Xtext projects [message #634560 is a reply to message #634429] Fri, 22 October 2010 08:50 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Right, have a look at the "Options" tab of that same wizard Very Happy

Re: Creating Ant Build files for Xtext projects [message #648210 is a reply to message #634240] Tue, 11 January 2011 19:20 Go to previous messageGo to next message
Jonatan Antoni is currently offline Jonatan AntoniFriend
Messages: 18
Registered: December 2010
Location: Frankfurt/Main
Junior Member
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 Go to previous messageGo to next message
Jonatan Antoni is currently offline Jonatan AntoniFriend
Messages: 18
Registered: December 2010
Location: Frankfurt/Main
Junior Member
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 #648705 is a reply to message #634240] Fri, 14 January 2011 07:24 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 101
Registered: August 2010
Senior Member
I have the headless build using ant files working quite nicely. I will try to post a small writeup tomorrow on this.
Re: Creating Ant Build files for Xtext projects [message #649127 is a reply to message #648705] Mon, 17 January 2011 19:27 Go to previous message
No real name is currently offline No real nameFriend
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.
Previous Topic:Cross referencing
Next Topic:Creating hyperlinks in Xtext editor
Goto Forum:
  


Current Time: Sat Dec 20 00:57:08 GMT 2014

Powered by FUDForum. Page generated in 0.03496 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software