Xtext, Maven and Source Control

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’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 to. Further, you will usually have 3 projects: The grammar project, the UI project and a test project.

In this article I will show some guidelines that I follow when checking in Xtext projects into source control.

Handling the src-gen folder

The content of src-gen 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’s classpath, which is not the folder src, but the output folder, bin or target/classes. 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 Java / Compiler / Building.

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.

I prefer to check in the src-gen folder, but avoid that any content gets checked in. To do so, add the folder with svn add, 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 svn:ignore property to value “*”.

The xtend-gen folder

At the moment it is not possible to compile .xtend files during a Maven build, so the content of xtend-gen 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.

I hope to solve this problem soon.

Some ignore patterns

On the root of each of the 3 Xtext projects, set the property svn:ignore to this value:

bin
target
.DS_Store
plugin.xml_gen

Configure Maven clean plugin

When running mvn clean on your project you would like to to clean up all derived resources. The target folder will be removed by default, but this is not enough. The content of the src-gen folders must be cleaned up as well. This can be done by configuring the maven-clean-plugin. 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 “mvn clean install” this would have the effect that

  1. clean is called on the grammar project
  2. in phase generate-sources the Xtext implementation classes are produced to all 3 projects
  3. the sources for the grammar project are compiled
  4. now the build continues with the next module, e.g. the UI project
  5. the project will be cleaned, removing the previously generated sources
  6. compilation fails, since the generated sources are missing now

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 src-gen 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:

<plugin>
  <artifactId>maven-clean-plugin</artifactId>
  <configuration>
    <filesets>
      <fileset>
        <directory>src-gen</directory>
        <includes>
          <include>**</include>
        </includes>
        <excludes>
          <exclude>.svn/**</exclude>
          <exclude>.gitignore</exclude>
        </excludes>
      </fileset>
      <fileset>
        <directory>../${project.artifactId}.ui/src-gen</directory>
        <includes>
          <include>**</include>
        </includes>
        <excludes>
          <exclude>.svn/**</exclude>
          <exclude>.gitignore</exclude>
        </excludes>
      </fileset>
      <fileset>
        <directory>../${project.artifactId}.tests/src-gen</directory>
        <includes>
          <include>**</include>
        </includes>
        <excludes>
          <exclude>.svn/**</exclude>
          <exclude>.gitignore</exclude>
        </excludes>
      </fileset>
    </filesets>
  </configuration>
</plugin>

Eclipse DemoCamp Dortmund – June 8th at FZW

During June and July 2010 there will be again Eclipse DemoCamps all over the world to celebrate the upcoming Eclipse Helios release end of June and e4 release and of July. DemoCamps are a great opportunity to see the latest and coolest new features live from the top experts in their field. Often the speakers are themselves committers on the projects and technologies they present. Also most attendees are Eclipse enthusiasts or use Eclipse technology for mission critical projects in their companies.

And to make it even better – these events are for free! All you have to do is take some time, come and enjoy!

I started now to organize the Eclipse DemoCamp in Dortmund. The Eclipse Foundation is sponsoring these events, but only 5 per country. In Germany there is such a huge interest in these events that these 5 sponsored DemoCamps were already registered when I entered the Dortmund DemoCamp – and this was just hours after announcement! Fortunately this DemoCamp will take place anyway, since itemis , who are Strategic Member of the Eclipse Foundation,  is willing to sponsor it.

This week we contracted the room, so finally location and date of this event is known and further planning can continue. The Eclipse DemoCamp in Dortmund will take place on June 8th 18:00-21:30 at the new FZW. The FZW is a well-known location for events and concerts and recently re-opened near to the “Dortmunder U” of the former Dortmunder Union Brewery.

Join the DemoCamp!

The Eclipse DemoCamp Dortmund is an open event. The only requirement for attending the event is registering on the Event Wiki page. To register you will need an account for the Eclipse Bugzilla System or contact me if I should add you to the attendees list.

Currently I am also searching for speakers. If you like to demonstrate what amazing stuff you are doing with Eclipse then go ahead. Just enter your name and the title of your presentation on the Wiki page. It could be anything which is related to Eclipse. Best of course would be demonstrations of features that come up with Helios or of some incubation projects. Each presentation should be no longer than 20 minutes. I’m especially interested in presentations about e4, XtextRAP, SMILA, b3, Cloud Development Toolkit, Sphinx, redview, Teneo, Equinox/OSGi, (E)Git, Graphiti, to name just of few of exciting Eclipse or technologies or Eclipse based products.

DemoCamps are a rather informal event. Besides the presentations there will be enough time to talk with the people there, do networking and drink a beer together. DemoCamps are fun and of high information value.

Don’t miss it and join it now!

Spread the word!

Eclipse DemoCamps are interesting for all users and devlopers of Eclipse. Talk with your colleagues and friends and make them aware about the Eclipse DemoCamp series around the world. There are lot of events planned and sure some more that are scheduled later. Of course, if you are coming from the Ruhrgebiet or somewhere around Dortmund you are welcome to join there. Hope to meet you there!

Sponsors welcome!

The event is at the moment sponsored by itemis, but it is not restricted to. Also your company can be a sponsor for this event. Your company will be mentioned on the Event wiki, mentioned in the opening talk and you are allowed to distribute marketing material. A better opportunity to present yourself as Eclipse experts for a reasonable price your company won’t find! Contact me if this is interesting for your company.