<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Karsten&#039;s Blog</title>
	<atom:link href="http://kthoms.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kthoms.wordpress.com</link>
	<description>Eclipse, Model Driven Software Development and whatever else is interesting to make software development more efficient</description>
	<lastBuildDate>Mon, 23 Jan 2012 03:57:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='kthoms.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/ba3234c5d82e8f39aacb2e90c9a01670?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Karsten&#039;s Blog</title>
		<link>http://kthoms.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://kthoms.wordpress.com/osd.xml" title="Karsten&#039;s Blog" />
	<atom:link rel='hub' href='http://kthoms.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Xtext 2.2 finally brings Maven support for Xtend</title>
		<link>http://kthoms.wordpress.com/2011/12/08/xtext-2-2-finally-brings-maven-support-for-xtend/</link>
		<comments>http://kthoms.wordpress.com/2011/12/08/xtext-2-2-finally-brings-maven-support-for-xtend/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 22:22:37 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Xtext]]></category>
		<category><![CDATA[Spray]]></category>
		<category><![CDATA[Tycho]]></category>
		<category><![CDATA[Xtend]]></category>
		<category><![CDATA[xtend-maven-plugin]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=408</guid>
		<description><![CDATA[I cannot tell how often I was asked since introduction of Xtend2 how to compile them in a Maven build. This was just not possible until now due to the problem that to load and compile an Xtend class it is necessary to compile all of the Java classes that the Xtend class on before, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=408&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I cannot tell how often I was asked since introduction of <a href="http://www.eclipse.org/Xtext/xtend/">Xtend2</a> how to compile them in a Maven build. This was just not possible until now due to the problem that to load and compile an Xtend class it is necessary to compile all of the Java classes that the Xtend class on before, and Java classes might depend on Xtend classes to be translated in order to be compilable. </p>
<p>
<a href="http://www.eclipse.org/Xtext/">Xtext 2.2.0</a> was just released yesterday, and for me the most important new feature is <a href="http://www.eclipse.org/Xtext/xtend/documentation/index.html#MavenSupport">direct support through the xtend-maven-plugin plugin</a>. I could not hesitate to test this feature, and created a small example.</p>
<h2>Scenario</h2>
<p>I have set up a small Maven project with 2 Java classes and 1 Xtend class that depend on each other.<br />
<a href="http://kthoms.files.wordpress.com/2011/12/screenshot-2011-12-08-um-21-56-35.png"><img src="http://kthoms.files.wordpress.com/2011/12/screenshot-2011-12-08-um-21-56-35.png" alt="" title="screenshot 2011-12-08 um 21.56.35" width="452" height="54" class="aligncenter size-full wp-image-409" /></a><br />
To translate XtendClass1 to Java code and compile it requires that JavaClass1 is compiled before, and to compile JavaClass2 it is necessary that XtendClass is translated to Java code before.</p>
<h2>Maven POM Configuration</h2>
<p>I have decided to not use Maven Tycho for this example, and use the typical structure of an Eclipse project with usage of Xtend, i.e. sources in folder <tt>/src</tt> (instead <tt>/src/main/java</tt>) and <tt>xtend-gen</tt> to generate the Java code for Xtend classes to.</p>
<h3>Repositories</h3>
<p>Since shortly Xtext artifacts are available on <a href="http://maven.eclipse.org/nexus/content/groups/public/">maven.eclipse.org</a>. The new Maven plugin is available on <a href="http://build.eclipse.org/common/xtend/maven/">http://build.eclipse.org/common/xtend/maven/</a><br />
<pre class="brush: xml;">
	&lt;repositories&gt;
		&lt;repository&gt;
			&lt;id&gt;maven.eclipse.org&lt;/id&gt;
			&lt;url&gt;http://maven.eclipse.org/nexus/content/groups/public/&lt;/url&gt;
		&lt;/repository&gt;
		&lt;repository&gt;
			&lt;id&gt;xtend&lt;/id&gt;
			&lt;url&gt;http://build.eclipse.org/common/xtend/maven/&lt;/url&gt;
		&lt;/repository&gt;
	&lt;/repositories&gt;
	&lt;pluginRepositories&gt;
		&lt;pluginRepository&gt;
			&lt;id&gt;xtend&lt;/id&gt;
			&lt;url&gt;http://build.eclipse.org/common/xtend/maven/&lt;/url&gt;
		&lt;/pluginRepository&gt;
	&lt;/pluginRepositories&gt;
</pre></p>
<h3>Dependencies</h3>
<p>This small project setup requires just a mimimal set of dependencies to be configured:<br />
<pre class="brush: xml;">
	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.eclipse.xtend2&lt;/groupId&gt;
			&lt;artifactId&gt;org.eclipse.xtend2.lib&lt;/artifactId&gt;
			&lt;version&gt;2.2.0&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.eclipse.xtext&lt;/groupId&gt;
			&lt;artifactId&gt;org.eclipse.xtext.xtend2.lib&lt;/artifactId&gt;
			&lt;version&gt;2.2.0.v201112061305&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.google.inject&lt;/groupId&gt;
			&lt;artifactId&gt;com.google.inject&lt;/artifactId&gt;
			&lt;version&gt;2.0.0.v201105231817&lt;/version&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
</pre></p>
<h3>Source folders</h3>
<p>The main source folder <tt>src/</tt> can be configured with the <tt>build/sourceDirectory</tt> setting, for <tt>xtend-gen</tt> we need the support of the <tt><a href="http://mojo.codehaus.org/build-helper-maven-plugin/">build-helper-maven-plugin</a></tt>.<br />
<pre class="brush: xml;">
	&lt;build&gt;
		&lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
				&lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;
				&lt;version&gt;1.7&lt;/version&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;id&gt;add-source&lt;/id&gt;
						&lt;phase&gt;generate-sources&lt;/phase&gt;
						&lt;goals&gt;
							&lt;goal&gt;add-source&lt;/goal&gt;
						&lt;/goals&gt;
						&lt;configuration&gt;
							&lt;sources&gt;
								&lt;source&gt;xtend-gen&lt;/source&gt;
							&lt;/sources&gt;
						&lt;/configuration&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
			&lt;/plugin&gt;
			...

</pre><br />
The <tt>xtend-gen</tt> folder must be emptied when executing <tt>mvn clean</tt>, this requires some <a href="http://maven.apache.org/plugins/maven-clean-plugin/examples/delete_additional_files.html">additional configuration of the maven-clean-plugin</a>.<br />
<pre class="brush: xml;">
			&lt;plugin&gt;
				&lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
				&lt;version&gt;2.4.1&lt;/version&gt;
				&lt;configuration&gt;
					&lt;filesets&gt;
						&lt;fileset&gt;
							&lt;directory&gt;xtend-gen&lt;/directory&gt;
							&lt;includes&gt;
								&lt;include&gt;**&lt;/include&gt;
							&lt;/includes&gt;
						&lt;/fileset&gt;
					&lt;/filesets&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
</pre></p>
<h3>xtend-maven-plugin</h3>
<p>Now let&#8217;s finally come to the Xtend plugin. The plugin is configured as follows:<br />
<pre class="brush: xml;">
			&lt;plugin&gt;
				&lt;groupId&gt;org.eclipse.xtend2&lt;/groupId&gt;
				&lt;artifactId&gt;xtend-maven-plugin&lt;/artifactId&gt;
				&lt;version&gt;2.2.0&lt;/version&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;goals&gt;
							&lt;goal&gt;compile&lt;/goal&gt;
							&lt;goal&gt;testCompile&lt;/goal&gt;
						&lt;/goals&gt;
						&lt;configuration&gt;
							&lt;outputDirectory&gt;xtend-gen&lt;/outputDirectory&gt;
						&lt;/configuration&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
			&lt;/plugin&gt;
</pre><br />
The <tt>outputDirectory</tt> is optional, but leaving it out the sources are generated to <tt>src/main/xtend-gen</tt>, and we want to generate to <tt>xtend-gen</tt> in the project root.</p>
<p>
The plugin does not define a lifecycle mapping for M2E, which leads to an error marker &#8220;Plugin execution not covered by lifecycle configuration&#8221;. This is a <a href="http://wiki.eclipse.org/M2E_plugin_execution_not_covered">well known issue when using M2E</a>, and requires <a href="http://wiki.eclipse.org/M2E_Extension_Development">some additional work on the plugin</a>. I have <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=366118">opened Bug#366118</a> for this.</p>
<h2>Sample Project</h2>
<p>The project described above is shared on Github: <a href="https://github.com/kthoms/xtext-experimental">https://github.com/kthoms/xtext-experimental</a></p>
<p>
In Eclipse the project looks like this after import (assuming the M2E plugin installed):<br />
<a href="http://kthoms.files.wordpress.com/2011/12/screenshot-2011-12-08-um-22-58-14.png"><img src="http://kthoms.files.wordpress.com/2011/12/screenshot-2011-12-08-um-22-58-14.png" alt="" title="screenshot 2011-12-08 um 22.58.14" width="279" height="208" class="aligncenter size-full wp-image-414" /></a></p>
<h2>Build Execution</h2>
<p>The classes in the project can now be built using <tt>mvn clean install</tt>. This will produce the following output:<br />
<pre class="brush: plain;">
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building xtend-maven-classic 2.2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ xtend-maven-classic ---
[INFO] Deleting /Users/thoms/git/xtext-experimental/maven/xtend.maven/target
[INFO] Deleting /Users/thoms/git/xtext-experimental/maven/xtend.maven/xtend-gen (includes = [**], excludes = [])
[INFO] 
[INFO] --- build-helper-maven-plugin:1.7:add-source (add-source) @ xtend-maven-classic ---
[INFO] Source directory: /Users/thoms/git/xtext-experimental/maven/xtend.maven/xtend-gen added.
[INFO] 
[INFO] --- xtend-maven-plugin:2.2.0:compile (default) @ xtend-maven-classic ---
[WARNING] 
WARNING: 	XtendClass1.xtend - /Users/thoms/git/xtext-experimental/maven/xtend.maven/src/mypackage/XtendClass1.xtend
7: The value of the field XtendClass1.cls is not used
[INFO] Compiling 1 source file to xtend-gen
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ xtend-maven-classic ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/thoms/git/xtext-experimental/maven/xtend.maven/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ xtend-maven-classic ---
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] Compiling 3 source files to /Users/thoms/git/xtext-experimental/maven/xtend.maven/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.923s
[INFO] Finished at: Thu Dec 08 23:01:42 CET 2011
[INFO] Final Memory: 20M/81M
[INFO] ------------------------------------------------------------------------
</pre></p>
<p>From the output it can be seen that at the end 3 Java classes are compiled, after the xtend-maven-plugin created the Java code for the Xtend class.</p>
<p>Enabling debug output with -X reveals some more insight, how the plugin works:<br />
<pre class="brush: plain;">
[DEBUG] Configuring mojo 'org.eclipse.xtend2:xtend-maven-plugin:2.2.0:compile' with basic configurator --&gt;
[DEBUG]   (f) outputDirectory = xtend-gen
[DEBUG]   (f) project = MavenProject: org.eclipse.xtext.example:xtend-maven-classic:2.2.0-SNAPSHOT @ /Users/thoms/git/xtext-experimental/maven/xtend.maven/pom.xml
[DEBUG]   (f) tempDirectory = /Users/thoms/git/xtext-experimental/maven/xtend.maven/target/xtend
[DEBUG] -- end configuration --
[DEBUG] load xtend file 'file:/Users/thoms/git/xtext-experimental/maven/xtend.maven/src/mypackage/XtendClass1.xtend'
[DEBUG] Parsing took: 42 ms
...
[DEBUG] create java stub 'mypackage/XtendClass1.java'
[DEBUG] invoke batch compiler with '-cp /Users/thoms/git/xtext-experimental/maven/xtend.maven/src:/Users/thoms/.m2/repository/org/eclipse/xtend2/org.eclipse.xtend2.lib/2.2.0/org.eclipse.xtend2.lib-2.2.0.jar:/Users/thoms/.m2/repository/com/google/guava/guava/10.0.1/guava-10.0.1.jar:/Users/thoms/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar:/Users/thoms/.m2/repository/org/eclipse/xtext/org.eclipse.xtext.xtend2.lib/2.2.0.v201112061305/org.eclipse.xtext.xtend2.lib-2.2.0.v201112061305.jar:/Users/thoms/.m2/repository/org/eclipse/xtext/org.eclipse.xtext.xbase.lib/2.2.0.v201112061305/org.eclipse.xtext.xbase.lib-2.2.0.v201112061305.jar:/Users/thoms/.m2/repository/com/google/inject/com.google.inject/2.0.0.v201105231817/com.google.inject-2.0.0.v201105231817.jar -d /Users/thoms/git/xtext-experimental/maven/xtend.maven/target/xtend/classes -1.5 -proceedOnError /Users/thoms/git/xtext-experimental/maven/xtend.maven/src /Users/thoms/git/xtext-experimental/maven/xtend.maven/target/xtend/stubs'
[DEBUG] classpath used for Xtend compilation : [file:/Users/thoms/git/xtext-experimental/maven/xtend.maven/src/, file:/Users/thoms/.m2/repository/org/eclipse/xtend2/org.eclipse.xtend2.lib/2.2.0/org.eclipse.xtend2.lib-2.2.0.jar, file:/Users/thoms/.m2/repository/com/google/guava/guava/10.0.1/guava-10.0.1.jar, file:/Users/thoms/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar, file:/Users/thoms/.m2/repository/org/eclipse/xtext/org.eclipse.xtext.xtend2.lib/2.2.0.v201112061305/org.eclipse.xtext.xtend2.lib-2.2.0.v201112061305.jar, file:/Users/thoms/.m2/repository/org/eclipse/xtext/org.eclipse.xtext.xbase.lib/2.2.0.v201112061305/org.eclipse.xtext.xbase.lib-2.2.0.v201112061305.jar, file:/Users/thoms/.m2/repository/com/google/inject/com.google.inject/2.0.0.v201105231817/com.google.inject-2.0.0.v201105231817.jar, file:/Users/thoms/git/xtext-experimental/maven/xtend.maven/src/, file:/Users/thoms/git/xtext-experimental/maven/xtend.maven/target/xtend/classes/]
</pre></p>
<p>The plugin invokes the Xtend Batch compiler through a spawned JVM. The batch compiler is realized in class <tt>org.eclipse.xtext.xtend2.compiler.batch.Xtend2BatchCompiler</tt> from the newly added plugin <tt>org.eclipse.xtext.xtend2.standalone</tt>.</p>
<p>
After the build <tt>XtendClass1.java</tt> is generated as expected to <tt>xtend-gen</tt>. When opening the <tt>target</tt> folder it can be seen that the plugin produces a Java stub class to <tt>target/stubs</tt> for the Xtend class. Finally, everything is compiled and the project is clean <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a href="http://kthoms.files.wordpress.com/2011/12/screenshot-2011-12-08-um-23-17-06.png"><img src="http://kthoms.files.wordpress.com/2011/12/screenshot-2011-12-08-um-23-17-06.png" alt="" title="screenshot 2011-12-08 um 23.17.06" width="252" height="394" class="aligncenter size-full wp-image-418" /></a></p>
<h2>Limitation</h2>
<p>It seems that the plugin only takes one source folder into account, namely the one configured by <tt>build/sourceDirectory</tt>. This is a problem when you have multiple source folders, which is quite typical for Xtext projects, namely <tt>src</tt> and <tt>src-gen</tt>. I will have to test this with an appropriate project and raise a bug is necessary.</p>
<h2>Conclusion</h2>
<p>I deeply desired this plugin and this finally allows that the <tt>xtend-gen</tt> folder does not need to be checked in. The sample used here was just simple. Next would be a real life project were I want to apply the plugin, most likely in <a href="http://code.google.com/a/eclipselabs.org/p/spray/">Project Spray</a>. This project uses Xtend based code generation heavily and Maven Tycho for the build. The project has not been upgraded to Xtext 2.2.0 (of course, it was just released), and I guess we have to upgrade to Xtext 2.2.0 before we can use the plugin. But if this allows us to finally remove the <tt>xtend-gen</tt> folders from the repository this alone is worth upgrading.</p>
<p>
Nice work, Xtext team!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/408/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=408&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/12/08/xtext-2-2-finally-brings-maven-support-for-xtend/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>

		<media:content url="http://kthoms.files.wordpress.com/2011/12/screenshot-2011-12-08-um-21-56-35.png" medium="image">
			<media:title type="html">screenshot 2011-12-08 um 21.56.35</media:title>
		</media:content>

		<media:content url="http://kthoms.files.wordpress.com/2011/12/screenshot-2011-12-08-um-22-58-14.png" medium="image">
			<media:title type="html">screenshot 2011-12-08 um 22.58.14</media:title>
		</media:content>

		<media:content url="http://kthoms.files.wordpress.com/2011/12/screenshot-2011-12-08-um-23-17-06.png" medium="image">
			<media:title type="html">screenshot 2011-12-08 um 23.17.06</media:title>
		</media:content>
	</item>
		<item>
		<title>Xtext 2.1.1 artifacts available on Eclipse Maven repository</title>
		<link>http://kthoms.wordpress.com/2011/11/21/xtext-2-1-1-artifacts-available-on-eclipse-maven-repository/</link>
		<comments>http://kthoms.wordpress.com/2011/11/21/xtext-2-1-1-artifacts-available-on-eclipse-maven-repository/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 11:42:01 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[Xtext]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=404</guid>
		<description><![CDATA[Until now it was always a struggle to make Xtext (or Eclipse) artifacts available on a public available repository. It seems that this has now finally found a good end. Today Achim Demelt pointed me to a Google+ posting from Dennis Huebner (our Xtext build manager) where he announced that Xtext artifacts are now automatically [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=404&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Until now it was always a struggle to make Xtext (or Eclipse) artifacts available on a public available repository. It seems that this has now finally found a good end.</p>
<p>Today <a href="https://plus.google.com/105485565450793476938">Achim Demelt</a> pointed me to a <a href="https://plus.google.com/u/0/109977816718694007083/posts/FZZkszrf727">Google+ posting from Dennis Huebner</a> (our Xtext build manager) where he announced that Xtext artifacts are now automatically available on the <a href="http://maven.eclipse.org/nexus/">Nexus repository at maven.eclipse.org</a>.</p>
<p>The given POMs have all dependencies from their bundle manifests. This is the recommended &#8220;Maven way&#8221;, but you may face that too many dependencies are pulled transitive, and you may have to cut them down by <a href="http://maven.apache.org/pom.html#Exclusions">explicit exclusions</a>. I haven&#8217;t tested this with the new repository, but this is what I experienced when doing a similar approach earlier with Xtext 2.0.1, whose artifacts are deployed on the Fornax Repository. Use the <a href="http://maven.apache.org/plugins/maven-dependency-plugin/usage.html#The_dependency:tree_Mojo">dependency:tree</a> plugin, or better M2E, to identify possible exclusions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/404/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=404&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/11/21/xtext-2-1-1-artifacts-available-on-eclipse-maven-repository/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>
	</item>
		<item>
		<title>EclipseCon 2011 warmup</title>
		<link>http://kthoms.wordpress.com/2011/11/01/399/</link>
		<comments>http://kthoms.wordpress.com/2011/11/01/399/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 23:07:58 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Xtext]]></category>
		<category><![CDATA[EclipseCon]]></category>
		<category><![CDATA[Graphiti]]></category>
		<category><![CDATA[Spray]]></category>
		<category><![CDATA[SWTBot]]></category>
		<category><![CDATA[Tycho]]></category>
		<category><![CDATA[Xbase]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=399</guid>
		<description><![CDATA[EclipseCon is just about to start and I am glad that I can make it this year. I have the chance to present Project Spray on thursday (Nov 3rd, 11:30 AM Bürgersaal 2) together with Jos Warmer. Spray aims to provide tooling to facilitate the creation of visual editors based on the Graphiti framework by [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=399&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>EclipseCon is just about to start and I am glad that I can make it this year. I have the chance to present <a href="http://code.google.com/a/eclipselabs.org/p/spray/">Project Spray</a> <a href="http://eclipsecon.org/sessions/spraying-natural-way-create-graphiti">on thursday (Nov 3rd, 11:30 AM Bürgersaal 2)</a> together with Jos Warmer. Spray aims to provide tooling to facilitate the creation of visual editors based on the Graphiti framework by the use of Xtext based DSL and Xtend code generator. You can basically compare it with what GMF Tools does for GMF, just with a DSL based approach.</p>
<p><a href="http://www.eclipsecon.org/europe2011"><img border="0" src="http://www.eclipsecon.org/europe2011/sites/default/files/100x100_speaking.gif?1307118317" height="80" width="100" alt="EclipseCon Europe 2011" /></a></p>
<p>The project was founded at this year&#8217;s <a href="www.codegeneration.net/cg2011/">Code Generation conference</a>, and Jos contributed an initial state of Spray derived from a customer&#8217;s project back in August. Since then the project team refactored the code base quite a bit. We are still in an early project phase. Most of the development is done in spare time yet, like Open Source projects often start. That was quite tough besides my full packed work schedule. Many hours on train or evenings in the hotel were spent to push this project.</p>
<p>At the moment I am just about to release version 0.3.0 of the Spray SDK, which I will use for our demo on thursday. Of course we want to gain a large audience. I am honest enough to say that attendees won&#8217;t see a production ready tool yet, but of course it is in working state. Jan announced a <a>pie fight for visual tooling</a>, I am ready to open my mouth wide enough to catch the incoming pies.</p>
<p>For our session we don&#8217;t want to start any discussion on graphical editing vs. visualization, whether GMF is better than Graphiti, or DSL / code generation vs. framework approach. There is always a niche for everything, and we are confident that Spray fills one of these gaps.</p>
<p>Besides what an end user actually can do with Spray at this moment there are quite some hidden gems in the project. I am using Spray to have also a non-trivial example for Eclipse Modeling tooling. You will find, for example</p>
<ul>
<li>a <a href="http://www.eclipse.org/tycho/">Maven Tycho</a> based build for Xtext 2 based projects
<li><a href="http://www.eclipse.org/swtbot/">SWTBot</a> based UI tests, integrated in the Maven build
<li>a project wizard with Xtend based code generation
<li>an advanced example use of Xbase in a DSL
<li>documentation based on WikiText, integrated in the build
<li>unit testing of the Xtext DSL with <a href="http://code.google.com/a/eclipselabs.org/p/xtext-utils/wiki/Unit_Testing">xtext-utils unittesting</a>
<li><a />separation of the Xtend code generator</a> from the language project
</ul>
<p>At EclipseCon I will take the chance to exchange with some experts in the fields of Modeling, especially Xtext and Graphiti. I will lay another focus on Build systems, especially Maven. Besides that there are many other interesting talks, far more than I can attend. And not to forget to meet all the other Eclipse enthusiasts. See you there!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/399/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=399&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/11/01/399/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>

		<media:content url="http://www.eclipsecon.org/europe2011/sites/default/files/100x100_speaking.gif?1307118317" medium="image">
			<media:title type="html">EclipseCon Europe 2011</media:title>
		</media:content>
	</item>
		<item>
		<title>Xtext, Maven and Source Control</title>
		<link>http://kthoms.wordpress.com/2011/10/06/xtext-maven-and-source-control/</link>
		<comments>http://kthoms.wordpress.com/2011/10/06/xtext-maven-and-source-control/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 18:39:45 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[Xtext]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[svn:ignore]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=390</guid>
		<description><![CDATA[Although I more and more use Git for source control, I face Subversion still frequently in daily life. I follow the rule that I don&#8217;t want to check in what can be generated in a headless build, where I usually use Maven. Xtext projects have the source folders src-gen and xtend-gen, where generated sources go [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=390&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Although I more and more use Git for source control, I face Subversion still frequently in daily life. I follow the rule that I don&#8217;t want to check in what can be generated in a headless build, where I usually use Maven. Xtext projects have the source folders <code>src-gen</code> and <code>xtend-gen</code>, where generated sources go to. Further, you will usually have 3 projects: The grammar project, the UI project and a test project.</p>
<p>In this article I will show some guidelines that I follow when checking in Xtext projects into source control.</p>
<h2>Handling the src-gen folder</h2>
<p>The content of <code>src-gen</code> can be produced during a build, so I do not check in the content of it. What needs to be considered is that is no good idea to ignore the folder completely, since it would be missing when fresh checking out the project. This leads to an incomplete build path, and the MWE2 workflow is not executable from Eclipse until the folder was created. This is because the .mwe2 file needs to be on the project&#8217;s classpath, which is not the folder <code>src</code>, but the output folder, <code>bin</code> or <code>target/classes</code>. It will be copied automatically with default workspace settings only when the build path is complete. This behavior can be changed in the workspace / project settings in <i>Java / Compiler / Building</i>.<br />
<a href="http://kthoms.files.wordpress.com/2011/10/screenshot-2011-10-06-um-19-59-19.png"><img src="http://kthoms.files.wordpress.com/2011/10/screenshot-2011-10-06-um-19-59-19.png" alt="" title="Java Build Path Problems setting" width="772" height="615" class="aligncenter size-full wp-image-391" /></a><br />
If you rate down build path problems to warning level or just disable build abortion on errors, the .mwe2 file will be copied anyway to the target folder. If using project specific settings you could even check in these settings and share it in the team.</p>
<p>
I prefer to check in the <code>src-gen</code> folder, but avoid that any content gets checked in. To do so, add the folder with <code>svn add</code>, but none of its content! Best you do this immediately after the Xtext project was created. After the folder was scheduled for adding, you can set the <code>svn:ignore</code> property to value &#8220;*&#8221;.</p>
<h2>The xtend-gen folder</h2>
<p>At the moment it is not possible to compile <code>.xtend</code> files during a Maven build, so the content of <code>xtend-gen</code> must be checked in and handled like handcrafted sources. To cut this story short: Xtend and Java files depend usually on each other. Xtend files cannot be compiled until Java sources from the same project were compiled, and some Java sources will depend on about-to-be-compiled Xtend sources. So the Java source compilation fails, aborting the build.</p>
<p>I hope to solve this problem soon. </p>
<h2>Some ignore patterns</h2>
<p>On the root of each of the 3 Xtext projects, set the property <code>svn:ignore</code> to this value:<br />
<pre class="brush: plain;">
bin
target
.DS_Store
plugin.xml_gen
</pre></p>
<h2>Configure Maven clean plugin</h2>
<p>When running <code>mvn clean</code> on your project you would like to to clean up all derived resources. The <code>target</code> folder will be removed by default, but this is not enough. The content of the <code>src-gen</code> folders must be cleaned up as well. This can be done by configuring the <a href="http://maven.apache.org/plugins/maven-clean-plugin/examples/delete_additional_files.html">maven-clean-plugin</a>. One thing to consider is that Xtext has 3 projects. It is not correct to configure the clean plugin for all 3 projects due the lifecycle of a Maven build: The projects will be build after each other, executing all lifecycles per project. If you execute a &#8220;mvn clean install&#8221; this would have the effect that</p>
<ol>
<li>clean is called on the grammar project
<li>in phase generate-sources the Xtext implementation classes are produced to all 3 projects
<li>the sources for the grammar project are compiled
<li>now the build continues with the next module, e.g. the UI project
<li>the project will be cleaned, removing the previously generated sources
<li>compilation fails, since the generated sources are missing now
</ol>
<p>For this reason the clean plugin must be configured only in the grammar project, and it should clean up the sources from all 3 projects. Now comes again a detail related to source control: Since we want to have the <code>src-gen</code> checked in, we have to avoid that the SCM related folders and files are removed. Otherwise this would confuse your SCM system. So these files must be excluded from deletion. This leads to the following configuration:<br />
<pre class="brush: xml;">
&lt;plugin&gt;
  &lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
  &lt;configuration&gt;
    &lt;filesets&gt;
      &lt;fileset&gt;
        &lt;directory&gt;src-gen&lt;/directory&gt;
        &lt;includes&gt;
          &lt;include&gt;**&lt;/include&gt;
        &lt;/includes&gt;
        &lt;excludes&gt;
          &lt;exclude&gt;.svn/**&lt;/exclude&gt;
          &lt;exclude&gt;.gitignore&lt;/exclude&gt;
        &lt;/excludes&gt;
      &lt;/fileset&gt;
      &lt;fileset&gt;
        &lt;directory&gt;../${project.artifactId}.ui/src-gen&lt;/directory&gt;
        &lt;includes&gt;
          &lt;include&gt;**&lt;/include&gt;
        &lt;/includes&gt;
        &lt;excludes&gt;
          &lt;exclude&gt;.svn/**&lt;/exclude&gt;
          &lt;exclude&gt;.gitignore&lt;/exclude&gt;
        &lt;/excludes&gt;
      &lt;/fileset&gt;
      &lt;fileset&gt;
        &lt;directory&gt;../${project.artifactId}.tests/src-gen&lt;/directory&gt;
        &lt;includes&gt;
          &lt;include&gt;**&lt;/include&gt;
        &lt;/includes&gt;
        &lt;excludes&gt;
          &lt;exclude&gt;.svn/**&lt;/exclude&gt;
          &lt;exclude&gt;.gitignore&lt;/exclude&gt;
        &lt;/excludes&gt;
      &lt;/fileset&gt;
    &lt;/filesets&gt;
  &lt;/configuration&gt;
&lt;/plugin&gt;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/390/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=390&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/10/06/xtext-maven-and-source-control/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>

		<media:content url="http://kthoms.files.wordpress.com/2011/10/screenshot-2011-10-06-um-19-59-19.png" medium="image">
			<media:title type="html">Java Build Path Problems setting</media:title>
		</media:content>
	</item>
		<item>
		<title>Moving an Xtend generator into its own plugin</title>
		<link>http://kthoms.wordpress.com/2011/09/28/moving-an-xtend-generator-into-its-own-plugin/</link>
		<comments>http://kthoms.wordpress.com/2011/09/28/moving-an-xtend-generator-into-its-own-plugin/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 09:23:46 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Xtext]]></category>
		<category><![CDATA[Spray]]></category>
		<category><![CDATA[Xtend]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=386</guid>
		<description><![CDATA[One of the nice things that you get when starting an Xtext project is an Xtend based generator that is automatically invoked when you save an Xtext model file. The Xtend generator for your language resides in the .generator subpackage of your language. The problem with that is that it is usually no good idea [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=386&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the nice things that you get when starting an Xtext project is an Xtend based generator that is automatically invoked when you save an Xtext model file. The Xtend generator for your language resides in the <tt>.generator</tt> subpackage of your language. The problem with that is that it is usually no good idea to have the generator bundled with your language. It is a completely seperate feature which is reasonable to put it in an own plugin. Further, the DSL plugins must not depend on the generator plugin, the dependency must be vice versa. This article describes the steps that need to be done for this.</p>
<p>
As a reference take the sources from project <a href="http://code.google.com/a/eclipselabs.org/p/spray/">Spray</a>. There you can find an concrete example where the described steps have been applied.</p>
<h2>Create the generator plugins</h2>
<p>Create two additional plugins: One for the runtime part of the generator, one for the UI contributions.</p>
<h3>Generator runtime plugin</h3>
<p>Move everything from the <tt>.generator</tt> subpackage of your DSL runtime project to the generator plugin. (In Spray this is <tt>org.eclipselabs.spray.generator.graphiti</tt>). The dependencies are the same as in the DSL runtime project, but add the DSL runtime plugin as additional dependency (see <a href="http://code.google.com/a/eclipselabs.org/p/spray/source/browse/plugins/org.eclipselabs.spray.generator.graphiti/META-INF/MANIFEST.MF">this MANIFEST.MF</a> as reference). Don&#8217;t forget to add an <tt>xtend-gen</tt> source folder to the project.</p>
<h4>Guice module for runtime plugin</h4>
<p>Create a <a>Module class extending AbstractGenericModule</a> in the runtime plugin. In this module at least the <tt>IGenerator</tt> implementation class must be bound.<br />
<pre class="brush: java;">
public class GraphitiGeneratorModule extends AbstractGenericModule {
    public Class&lt;? extends org.eclipse.xtext.generator.IGenerator&gt; bindIGenerator() {
        return SprayGenerator.class;
    }
    ...
}
</pre></p>
<h3>Generator UI plugin</h3>
<p>The UI plugin must basically bind the <tt>JavaProjectBasedBuilderParticipant</tt> in its own module and register it through the <tt>org.eclipse.xtext.builder.participant</tt> extension point. These steps are required:</p>
<h4>UI Guice Module</h4>
<p>Create a <a href="http://code.google.com/a/eclipselabs.org/p/spray/source/browse/plugins/org.eclipselabs.spray.generator.graphiti.ui/src/org/eclipselabs/spray/generator/graphiti/ui/GraphitiGeneratorUIModule.java?spec=svn66d2094412e25c8311bf0657c5b10f7b4fdee54c&amp;r=66d2094412e25c8311bf0657c5b10f7b4fdee54c">module class extending AbstractGenericModule and bind <tt>JavaProjectBasedBuilderParticipant</tt></a>:<br />
<pre class="brush: java;">
public class GraphitiGeneratorUIModule extends AbstractGenericModule {
    private final AbstractUIPlugin plugin;
    
    public GraphitiGeneratorUIModule (AbstractUIPlugin plugin) {
        this.plugin = plugin;
    }

    @Override
    public void configure(Binder binder) {
        super.configure(binder);
        binder.bind(AbstractUIPlugin.class).toInstance(plugin);
        binder.bind(IDialogSettings.class).toInstance(plugin.getDialogSettings());
    }
    /**
     * Bind the JavaProjectBasedBuilderParticipant in order to invoke the generator during the build.
     */
    public Class&lt;? extends org.eclipse.xtext.builder.IXtextBuilderParticipant&gt; bindIXtextBuilderParticipant() {
        return org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant.class;
    }

    ...
}
</pre></p>
<h4>Activator class</h4>
<p>Create a class <a href="http://code.google.com/a/eclipselabs.org/p/spray/source/browse/plugins/org.eclipselabs.spray.generator.graphiti.ui/src/org/eclipselabs/spray/generator/graphiti/ui/Activator.java?spec=svn66d2094412e25c8311bf0657c5b10f7b4fdee54c&amp;r=66d2094412e25c8311bf0657c5b10f7b4fdee54c"><tt>Activator</tt></a> which creates a Guice injector from the modules:</p>
<ol>
<li>DSL runtime module</li>
<li><tt>org.eclipse.xtext.ui.shared.SharedStateModule</tt></li>
<li>DSL UI module</li>
<li>Generator runtime module</li>
<li>Generator UI module</li>
</ol>
<p><pre class="brush: java;">
public class Activator extends AbstractUIPlugin {
	private Injector injector;
	private static Activator INSTANCE;

	public Injector getInjector() {
		return injector;
	}
	
	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		INSTANCE = this;
		try {
		    injector = Guice.createInjector(Modules2.mixin(new SprayRuntimeModule(), new SharedStateModule(), new SprayUiModule(this), new GraphitiRuntimeModule(), new GraphitiGeneratorModule(), new GraphitiGeneratorUIModule(this)));
		} catch (Exception e) {
			Logger.getLogger(getClass()).error(e.getMessage(), e);
			throw e;
		}
	}
	
	@Override
	public void stop(BundleContext context) throws Exception {
		injector = null;
		super.stop(context);
	}
	
	public static Activator getInstance() {
		return INSTANCE;
	}
	
}
</pre><br />
Open the manifest editor. On the &#8220;Overview&#8221; page enter the Activator class name. Also check the options &#8220;Activate this plug-in when one of its classes is loaded&#8221; and &#8220;This plug-in is a singleton&#8221;.</p>
<h4>ExecutableExtensionFactory</h4>
<p>Create a class <a href="http://code.google.com/a/eclipselabs.org/p/spray/source/browse/plugins/org.eclipselabs.spray.generator.graphiti.ui/src/org/eclipselabs/spray/generator/graphiti/ui/internal/ExecutableExtensionFactory.java?spec=svnbfd7df6ace36e3989d11914fc8b658a8840ed786&amp;r=5f48e6d9e89723b9b9774f9790db91497b857e0f"><tt>ExecutableExtensionFactory</tt></a>. Since this class won&#8217;t be public API it is a good approach to put it into an <tt>internal</tt> package.<br />
<pre class="brush: java;">
public class ExecutableExtensionFactory extends AbstractGuiceAwareExecutableExtensionFactory {

	@Override
	protected Bundle getBundle() {
		return Activator.getInstance().getBundle();
	}
	
	@Override
	protected Injector getInjector() {
		return Activator.getInstance().getInjector();
	}
	
}
</pre></p>
<h4>plugin.xml</h4>
<p>Add a <a>plugin.xml</a> with the following content:<br />
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;?eclipse version=&quot;3.4&quot;?&gt;
&lt;plugin&gt;
   &lt;extension
         point=&quot;org.eclipse.xtext.builder.participant&quot;&gt;
      &lt;participant
            class=&quot;org.eclipselabs.spray.generator.graphiti.ui.internal.ExecutableExtensionFactory:org.eclipse.xtext.builder.IXtextBuilderParticipant&quot;&gt;
      &lt;/participant&gt;
   &lt;/extension&gt;
&lt;/plugin&gt;
</pre><br />
Check that the ExecutableExtensionFactory class name matches yours.</p>
<h2>Remove the GeneratorFragment</h2>
<p>Open the .mwe2 workflow of your DSL project. Remove the entry for the GeneratorFragment:<br />
<pre class="brush: java;">
// Code generator
fragment = generator.GeneratorFragment {
  generateJavaMain = false 
  generateMwe = false
  generatorStub = true 
}
</pre><br />
Now regenerate the DSL.</p>
<h2>Add binding for IWorkspaceRoot</h2>
<p>The generator fragment contributes a binding for IWorkspaceRoot to the UI Module of your DSL, which is required by the builder participant. Therefore this binding must be added manually to your UI Module.<br />
<pre class="brush: java;">
public class SprayUiModule extends AbstractSprayUiModule {
    ...
    public org.eclipse.core.resources.IWorkspaceRoot bindIWorkspaceRootToInstance() {
        return org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot();
    }
}
</pre></p>
<h2>Result</h2>
<p>As a result your DSL plugins should have no dependencies on your generator plugin. When you save a model file in your Eclipse instance with the deployed plugins the code generator should be invoked. The pattern described here would also allow to create multiple generator plugins for the same DSL which are invoked independently when building the project. Each of them registers its own builder participant and invokes its own generator.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/386/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=386&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/09/28/moving-an-xtend-generator-into-its-own-plugin/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting template file encoding in Xpand workflow</title>
		<link>http://kthoms.wordpress.com/2011/09/13/setting-template-file-encoding-in-xpand-workflow/</link>
		<comments>http://kthoms.wordpress.com/2011/09/13/setting-template-file-encoding-in-xpand-workflow/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 14:14:42 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Xpand]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=379</guid>
		<description><![CDATA[A typical problem when running Xpand is file encoding of the Xpand templates. Xpand uses guillemot brackets («»), which are not available in all character sets. Often, ISO-8859-1 and UTF-8 are good choices for encoding Xpand templates. However, on Mac the default encoding is MacRoman, and I would recommend to change that for interoperability reason. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=379&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A typical problem when running Xpand is file encoding of the Xpand templates. Xpand uses guillemot brackets («»), which are not available in all character sets. Often, <em>ISO-8859-1</em> and <em>UTF-8</em> are good choices for encoding Xpand templates. However, on Mac the default encoding is <em>MacRoman</em>, and I would recommend to change that for interoperability reason. I would recommend changing the resource encoding setting on the root folder containing Xpand templates, or even the project, and checking in the settings. This way the encoding is shared amongst team members.<br />
<a href="http://kthoms.files.wordpress.com/2011/09/screenshot-2011-09-13-um-15-54-36.png"><img class="aligncenter size-full wp-image-380" title="Setting template resource encoding" src="http://kthoms.files.wordpress.com/2011/09/screenshot-2011-09-13-um-15-54-36.png" alt="" width="721" height="532" /></a></p>
<p>When executing the Xpand generator with MWE it is important that the templates are read with the right encoding. Otherwise you will get an error like this:<br />
<code>org.eclipse.internal.xtend.xtend.parser.ParseException: no viable alternative at character '�' on line 159</code><br />
Xpand&#8217;s Generator component has a property <em>fileEncoding</em>, but this is the encoding used by the outlets to <em>write</em> files. If you need to change the behavior for <em>reading</em> files, you need to set the encoding value of the ResourceManager. The configuration is like this:</p>
<p>MWE1:</p>
<p><pre class="brush: xml;">

    ...




</pre></p>
<p>MWE2</p>
<p><pre class="brush: xml;">
  component = org.eclipse.xpand2.Generator {
    ...
    resourceManager = org.eclipse.xtend.expression.ResourceManagerDefaultImpl {
     	fileEncoding = &quot;ISO-8859-1&quot;
    }
  }
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/379/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=379&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/09/13/setting-template-file-encoding-in-xpand-workflow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>

		<media:content url="http://kthoms.files.wordpress.com/2011/09/screenshot-2011-09-13-um-15-54-36.png" medium="image">
			<media:title type="html">Setting template resource encoding</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Xtext injected types in Xpand</title>
		<link>http://kthoms.wordpress.com/2011/08/17/using-xtext-injected-types-in-xpand/</link>
		<comments>http://kthoms.wordpress.com/2011/08/17/using-xtext-injected-types-in-xpand/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 12:57:26 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Xpand]]></category>
		<category><![CDATA[Xtext]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=369</guid>
		<description><![CDATA[During a project migration I stumbled over the need to access the IScopeProvider from an Xtext based language within Xtend(1) extensions that are used from Xpand templates. This is not quite how Xpand would work out-of-the-box, so here is an approach to solve it. InjectableGenerator I subclassed org.eclipse.xpand2.Generator and called it InjectableGenerator. The intention is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=369&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>During a project migration I stumbled over the need to access the <tt>IScopeProvider</tt> from an Xtext based language within Xtend(1) extensions that are used from Xpand templates. This is not quite how Xpand would work out-of-the-box, so here is an approach to solve it.</p>
<h2><tt>InjectableGenerator</tt></h2>
<p>I subclassed <tt>org.eclipse.xpand2.Generator</tt> and called it <tt>InjectableGenerator</tt>. The intention is to register a global variable for a configurable set of types (e.g. the <tt>IScopeProvider</tt>). The name of the variable is the class name that should be get from Guice. To add injectors, instances of <tt>ISetup</tt> are registered to the component, similar to Xtext&#8217;s <tt>org.eclipse.xtext.mwe.Reader</tt> component.</p>
<p>The hook that is used to register the global variables to Xpand&#8217;s execution context is the method <tt>getGlobalVars(WorkflowContext ctx)</tt>, which is overridden here.</p>
<p><pre class="brush: java;">
package org.eclipselabs.xtext.xpand;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.emf.mwe.core.WorkflowContext;
import org.eclipse.xpand2.Generator;
import org.eclipse.xtend.expression.Variable;
import org.eclipse.xtext.ISetup;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.inject.ConfigurationException;
import com.google.inject.Injector;

/**
 * Allows Xtext based dependency injection. Injected instances are registered as
 * global vars to the Xpand Execution Context.
 */
public class InjectableGenerator extends Generator {
	private List&lt;Injector&gt; injectors = Lists.newArrayList();

	public void addRegister(ISetup setup) {
		injectors.add(setup.createInjectorAndDoEMFRegistration());
	}

	protected List&lt;Injector&gt; getInjectors() {
		return injectors;
	}
	
	private Set&lt;Class&lt;?&gt;&gt; injectedTypes = Sets.newHashSet();

	public void addInjectGlobalVar (String className) {
		try {
			Class&lt;?&gt; clazz = Class.forName(className);
			injectedTypes.add(clazz);
		} catch (Exception e) {
			throw new IllegalArgumentException(&quot;Invalid type: &quot;+className);
		}
	}
	
	@Override
	protected Map&lt;String, Variable&gt; getGlobalVars(WorkflowContext ctx) {
		Map&lt;String, Variable&gt; result = super.getGlobalVars(ctx);
		// try to get an instance of each configured type
		for (Class&lt;?&gt; clazz : injectedTypes) {
			boolean configured = false;
			for (Injector injector : injectors) {
				try {
					Object obj = injector.getInstance(clazz);
					result.put(clazz.getName(), new Variable(clazz.getName(), obj));
					configured = true;
				} catch (ConfigurationException e) {
					; // ignore
				}
			}
			if (!configured) {
				throw new IllegalStateException(&quot;Could not configure instance of &quot;+clazz.getName());
			}
		}
		return result;
	}
}
</pre></p>
<h2>Workflow Configuration</h2>
<p>In your workflow configuration you would of course now use the specialized Generator component. It could be used like this:<br />
<pre class="brush: java;">
...
component = org.eclipselabs.xtext.xpand.InjectableGenerator {
   register = my.dsl.MyDslStandaloneSetup {}
   injectGlobalVar = &quot;org.eclipse.xtext.scoping.IScopeProvider&quot;
   // injectGlobalVar = ... other types
   
   // further configuration of Xpand Generator
}
</pre></p>
<h2>Execution context aware Java extensions</h2>
<p>It is not possible to directly access the ExecutionContext from within Xpand templates or Xtend functions. We need to delegate to Java extensions. The classes that we delegate to must implement the <tt>IExecutionContextAware</tt> interface. The <tt>setExecutionContext(ExecutionContext ctx)</tt> method is the right place to retrieve the IScopeProvider and bind it to an instance variable.</p>
<p><pre class="brush: java;">
public class MyExtensions implements IExecutionContextAware {
	protected IScopeProvider scopeProvider;

	@Override
	public void setExecutionContext(ExecutionContext ctx) {
		if (ctx.getGlobalVariables().get(&quot;scopeProvider&quot;)!=null) {
			this.scopeProvider = (IScopeProvider) ctx.getGlobalVariables().get(&quot;scopeProvider&quot;).getValue();
		} else if (ctx.getGlobalVariables().get(IScopeProvider.class.getName())!=null) {
			this.scopeProvider = (IScopeProvider) ctx.getGlobalVariables().get(IScopeProvider.class.getName()).getValue();
		} else {
			throw new IllegalStateException(&quot;No IScopeProvider found as global var in the execution context&quot;);
		}
	}

	// add (non-static!) extension methods here!
        public List&lt;EObject&gt; someMethod (org.eclipse.emf.ecore.EObject context) {
          ... do something
        }
}

</pre><br />
Note that we also query the global variable named &#8220;scopeProvider&#8221; here. This is because in another context (i.e. Check based validation) the same extension would be used with another execution context. The <tt>InjectableExecutionContext</tt> binds the <tt>IScopeProvider</tt> to that name.</p>
<p>It might be a good idea to have an abstract base class for these Extension classes.</p>
<p>Now you can use the methods defined in the Java extension class and access the required instances from your language configuration within.<br />
<pre class="brush: java;">
// file: MyExtensions.ext
List[emf::EObject] someMethod (emf::EObject ctx) : JAVA MyExtensions.someMethod(org.eclipse.emf.ecore.EObject);
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/369/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=369&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/08/17/using-xtext-injected-types-in-xpand/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>
	</item>
		<item>
		<title>Xtend &#8211; Generating from multiple input models</title>
		<link>http://kthoms.wordpress.com/2011/07/12/xtend-generating-from-multiple-input-models/</link>
		<comments>http://kthoms.wordpress.com/2011/07/12/xtend-generating-from-multiple-input-models/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 20:52:18 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Xtext]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=350</guid>
		<description><![CDATA[Xtext&#8217;s integration of Xtend based code generators is nice. If you save changed (or add/remove) DSL model files an incremental build will automatically be triggered and even removes derived artifacts if you remove the source from which it is generated. The IGenerator interface takes a Resource, and you can generate 1 or multiple target artifacts [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=350&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Xtext&#8217;s integration of <a href="http://blog.efftinge.de/2010/12/xtend-2-successor-to-xpand.html">Xtend</a> based code generators is nice. If you save changed (or add/remove) DSL model files an incremental build will automatically be triggered and even removes derived artifacts if you remove the source from which it is generated. The <tt>IGenerator</tt> interface takes a Resource, and you can generate 1 or multiple target artifacts from the model elements within that resource.</p>
<p>However, the API does not allow to create a single artifact from multiple input models. But this is a common use case if you do serious code generation. I will show you how you could extend Xtext&#8217;s Domainmodel example to generate a simple text file that lists the name of all Entity instances of all <code>.dmodel</code> files that are reachable in the built project.</p>
<h2>Adding an extended generator interface</h2>
<p>Create an interface <code>IGenerator2</code> that extends the <code>IGenerator</code> interface:</p>
<p><pre class="brush: java;">
public interface IGenerator2 extends IGenerator {
	/**
	 * @param input - the input for which to generate resources
	 * @param fsa - file system access to be used to generate files
	 */
	public void doGenerate(ResourceSet input, IFileSystemAccess fsa);
}
</pre></p>
<p>The generator class will later implement this interface and generate a single artifact from all Entity instances in all resources.</p>
<p>Extending the <code>JavaProjectBasedBuilderParticipant</code></p>
<p>The <code>JavaProjectBasedBuilderParticipant</code> is used by default to invoke the <code>IGenerator</code> implementation that was bound to the runtime module. We will extend this class to add additional logic and inject an <code>IGenerator2</code> instance that will be invoked once per triggered build.</p>
<p>The builder participant is an UI concept, so create the extended class <code>JavaProjectBasedBuilderParticipant2</code> in the UI plugin:</p>
<p><pre class="brush: java;">
package org.eclipse.xtext.builder;

import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator2;
import org.eclipse.xtext.resource.IContainer;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.IResourceDescription.Delta;
import org.eclipse.xtext.resource.IResourceDescriptions;
import org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider;

import com.google.inject.Inject;

public class JavaProjectBasedBuilderParticipant2 extends JavaProjectBasedBuilderParticipant {
  @Inject
  private ResourceDescriptionsProvider resourceDescriptionsProvider;

  @Inject
  private IContainer.Manager containerManager;

  @Inject (optional=true)
  private IGenerator2 generator;

  protected ThreadLocal&lt;Boolean&gt; buildSemaphor = new ThreadLocal&lt;Boolean&gt;();

  @Override
  public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
    buildSemaphor.set(false);
    super.build(context, monitor);
  }

  @Override
  protected void handleChangedContents(Delta delta, IBuildContext context, IFileSystemAccess fileSystemAccess) {
    super.handleChangedContents(delta, context, fileSystemAccess);
    if (!buildSemaphor.get() &amp;&amp; generator != null) {
      invokeGenerator(delta, context, fileSystemAccess);
    }
  }

  @Override
  protected void handleDeletion(Delta delta, IBuildContext context, IFileSystemAccess fileSystemAccess) {
    super.handleDeletion(delta, context, fileSystemAccess);
    if (!buildSemaphor.get() &amp;&amp; generator != null) {
      invokeGenerator(delta, context, fileSystemAccess);
    }
  }

  private void invokeGenerator (Delta delta, IBuildContext context, IFileSystemAccess fileSystemAccess) {
    buildSemaphor.set(true);
    Resource resource = context.getResourceSet().getResource(delta.getUri(), true);
    if (shouldGenerate(resource, context)) {
      IResourceDescriptions index = resourceDescriptionsProvider.createResourceDescriptions();
      IResourceDescription resDesc = index.getResourceDescription(resource.getURI());
      List&lt;IContainer&gt; visibleContainers = containerManager.getVisibleContainers(resDesc, index);
      for (IContainer c : visibleContainers) {
        for (IResourceDescription rd : c.getResourceDescriptions()) {
          context.getResourceSet().getResource(rd.getURI(), true);
        }
      }

      generator.doGenerate(context.getResourceSet(), fileSystemAccess);
    }
  }
}
</pre></p>
<p>Note that <code>IGenerator</code> instance will be invoked once per changed resource, so potentially multiple times. We have to make sure that the <code>IGenerator2</code> instance will be invoked just once. Therefore a thread local semaphor flag will be queried before the generator is called. In this scenario it does not matter whether a change or deletion should be handled. The generator always processes the whole model once.</p>
<p>The most important thing is to populate the BuildContext&#8217;s ResourceSet with all relevant model resources. It is important here collect the resources that are in scope of the built project. The right way to do this is to use the language&#8217;s <tt>IContainer.Manager</tt> to collect the resources that are within the <em>visible containers</em>. Each of them is queried for its contained <code>IResourceDescription</code> instances, from which the Resource instances are created.</p>
<h2>Extending the generator class</h2>
<p>Now open the generator class <code>DomainmodelGenerator</code> and implement <code>IGenerator2</code>. Add an implementation of the method from the extended interface:</p>
<p><pre class="brush: java;">
...
// makes allContentsIterable available
import static extension org.eclipse.xtext.xtend2.lib.ResourceExtensions.*
...

class DomainmodelGenerator implements IGenerator2 {
  ...
  override void doGenerate(ResourceSet rs, IFileSystemAccess fsa) {
    val Iterable&lt;Entity&gt; entities = rs.resources.map(r|r.allContentsIterable.filter(typeof(Entity))).flatten

    fsa.generateFile(&quot;entities.txt&quot;, entities.compile)
  }

  def compile (Iterable&lt;Entity&gt; entities) '''
    «FOR e : entities SEPARATOR &quot;, &quot;»«e.name»«ENDFOR»
  '''

  ...
}
</pre></p>
<h2>Guice configuration</h2>
<p>Now bind the extended builder particpant in the UI module:</p>
<p><pre class="brush: java;">
public class DomainmodelUiModule extends AbstractDomainmodelUiModule {
	@Override
	public Class&lt;? extends IXtextBuilderParticipant&gt; bindIXtextBuilderParticipant() {
		return JavaProjectBasedBuilderParticipant2.class;
	}
}
</pre></p>
<p>&#8230; and the generator to the Runtime module:</p>
<p><pre class="brush: java;">
public class DomainmodelRuntimeModule extends AbstractDomainmodelRuntimeModule {
	public Class&lt;? extends IGenerator2&gt; bindIGenerator2 () {
		return DomainmodelGenerator.class;
	}
}
</pre></p>
<h2>Result &amp; Conclusion</h2>
<p>After restarting your runtime workspace the generator will produce an &#8220;entities.txt&#8221; file to the src-gen folder of a project with .dmodel files, which will simply list the names of all found Entity instances.</p>
<p>This scenario is quite common, so it would be great if the Xtext framework could provide built-in support for that. I have therefore raised a <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=351903">feature request</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/350/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=350&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/07/12/xtend-generating-from-multiple-input-models/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>
	</item>
		<item>
		<title>Game Development &#8211; A whole new area for Eclipse Modeling?</title>
		<link>http://kthoms.wordpress.com/2011/07/07/game-development-a-whole-new-area-for-eclipse-modeling/</link>
		<comments>http://kthoms.wordpress.com/2011/07/07/game-development-a-whole-new-area-for-eclipse-modeling/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 15:15:59 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[MDSD]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Xtext]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[ICEC]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=347</guid>
		<description><![CDATA[The Eclipse Modeling Project provides the world&#8217;s leading set of tools and frameworks that are used for successfully applying model driven software development techniques in various areas. Successful adoption are known in Enterprise Computing, Embedded System Development, Mobile Development etc. But what about Game Development? I have not heard about Game productions that use Eclipse [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=347&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.eclipse.org/modeling">Eclipse Modeling Project</a> provides the world&#8217;s leading set of tools and frameworks that are used for successfully applying model driven software development techniques in various areas. Successful adoption are known in Enterprise Computing, Embedded System Development, Mobile Development etc. But what about Game Development? I have not heard about Game productions that use Eclipse Modeling or Model Driven Software Development in general so far. I cannot know about all projects in the world, but at least it is an indicator that this development technique is at least not wide adopted in the branch of Game Development.</p>
<p>Game Development is highly complex, developed in multidisciplinary teams under high time pressure and quality requirements. And the complexity is even growing, whilst time pressure also. Time-to-market is everything there. If your game comes too late, you are out. If you don&#8217;t use the latest technologies, you are lame. How could such projects ever be successful just by coding and hacking? I could imagine that game developers are just too busy with developing their games in a traditional way to think how they could gain speed and quality by applying software engineering techniques like MDSD. </p>
<p>I would not wonder if they associate MDSD with drawing UML diagrams and wasting time clicking and drawing useless stuff. Model Driven Software Development is everything else than useless. It helps raising the level of abstraction, speeding up development and gaining quality. If applied correctly, of course. Of course they think their kind of software development is special and completely different than other disciplines. But let me say, it&#8217;s not the case. Every piece of software has generic parts, schematic parts and parts that don&#8217;t fit into one of the previous sections. And for the schematic parts, MDSD can always help. Don&#8217;t tell me that a multi-million, mission-critical enterprise project is less challenging than game development.</p>
<p>One of the most promising things for game development can be the usage of Domain Specific Languages (DSLs), especially textual ones. With <a href="http://www.eclipse.org/Xtext">Xtext 2.0</a> the development of textual DSLs with tight integration of expression languages and code generators has become easier than ever before. If you don&#8217;t ever tried Xtext, do it!</p>
<p>On <strong>October 4th</strong> there will be an interesting workshop at the <a href="http://icec2011.org/">10th International Conference on Entertaining Computing (ICEC 2011)</a> in Vancouver, Canada. The &#8220;<a href="http://gd-mdsd.blogspot.com/"><strong>1st Workshop on Game Development and MDSD</strong></a>&#8221; will bring experts from both worlds together. The Call for Position Papers is running now, deadline is <strong>July 30th</strong>. If you are in one of those businesses, submit a propopsal or attend the workshop. I think both &#8220;worlds&#8221; can really win a lot from working together. This workshop could be a good start.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/347/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/347/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/347/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/347/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/347/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/347/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/347/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/347/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/347/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/347/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/347/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/347/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/347/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/347/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=347&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/07/07/game-development-a-whole-new-area-for-eclipse-modeling/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>
	</item>
		<item>
		<title>Xtext 2.0 / Xpand 1.1 plugins available as Maven artifacts</title>
		<link>http://kthoms.wordpress.com/2011/07/05/xtext-2-0-xpand-1-1-plugins-available-as-maven-artifacts/</link>
		<comments>http://kthoms.wordpress.com/2011/07/05/xtext-2-0-xpand-1-1-plugins-available-as-maven-artifacts/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 05:22:36 +0000</pubDate>
		<dc:creator>kthoms</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[Xpand]]></category>
		<category><![CDATA[Xtext]]></category>
		<category><![CDATA[Fornax]]></category>
		<category><![CDATA[Indigo]]></category>
		<category><![CDATA[Tycho]]></category>
		<category><![CDATA[Xtext 2.0]]></category>

		<guid isPermaLink="false">http://kthoms.wordpress.com/?p=340</guid>
		<description><![CDATA[It&#8217;s now one week after release of Eclipse Indigo, and with that Xtext 2.0 and Xpand 1.1. For those who use Maven without Tycho to build projects using these frameworks it is of course necessary to have all related plugins available in some Maven repository. With the help of the osgi-to-maven2 project I was now [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=340&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s now one week after release of Eclipse Indigo, and with that Xtext 2.0 and Xpand 1.1. For those who use Maven without Tycho to build projects using these frameworks it is of course necessary to have all related plugins available in some Maven repository.</p>
<p>With the help of the <a href="http://code.google.com/p/osgi-to-maven2/">osgi-to-maven2</a> project I was now able with some tweaks to create the necessary POMs and deploy scripts for the plugins. What osgi-to-maven2 basically does is to analyze the plugin manifests and create POMs for them including dependencies. The project is not maintained at the moment and has a problem especially with the parsing of the plugins <tt>org.eclipse.ui.views</tt> and <tt>org.eclipse.ui.workbench</tt>, which have some strange directives in the Export-Package section where I could not find documentation about. The underlying manifest parser from Springsource (<tt>com.springsource.util.osgi</tt>) vomits when parsing those manifests, and also upgrading to the latest release does not help. Time to open a bug.</p>
<p><code><br />
Export-Package: org.eclipse.ui;mandatory:="ui.workb<br />
ench",org.eclipse.ui.about,org.eclipse.ui.actions;ui.workbench=split;<br />
mandatory:="ui.workbench",org.eclipse.ui.activities,org.eclipse.ui.ap<br />
plication,org.eclipse.ui.branding,org.eclipse.ui.browser<strong>;ui.workbench<br />
=split</strong>;mandatory:="ui.workbench",org.eclipse.ui.commands,org.eclipse.<br />
</code><br />
Also the osgi-to-maven2 tool does not handle absent optional libraries so far.</p>
<p>The Xtext 2.0, Xpand 1.1 and dependent plugins are available at the Fornax Platform&#8217;s repository <a href="http://fornax-platform.org/nexus/content/groups/public/">http://fornax-platform.org/nexus/content/groups/public/</a> under the groupId <tt><a href="http://fornax-platform.org/nexus/content/groups/public/org/eclipse/plugins/">org.eclipse.plugins</a></tt>.</p>
<p>Based on the deployed plugins it should be possible to setup a plain Maven build for Xtext 2 based projects.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kthoms.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kthoms.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kthoms.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kthoms.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kthoms.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kthoms.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kthoms.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kthoms.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kthoms.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kthoms.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kthoms.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kthoms.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kthoms.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kthoms.wordpress.com/340/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kthoms.wordpress.com&amp;blog=6829080&amp;post=340&amp;subd=kthoms&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kthoms.wordpress.com/2011/07/05/xtext-2-0-xpand-1-1-plugins-available-as-maven-artifacts/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5b70519e81a384fd48c5a61a93274870?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kthoms</media:title>
		</media:content>
	</item>
	</channel>
</rss>
