Question

I'm currently looking into Xtext to create both a reusable DSL and an artifact which is built upon the DSL. The simplified project layout is as follows:

  • projectA: Contains Xtext-based DSL, feature-project, updatesite, etc.
  • projectB: Uses the artifacts from projectA to generate code.
  • projectC: Uses the generated code from projectB

Building projectA using Maven and Xtext is not a problem (and there are several examples on the net already), but I don't get how to use the DSL from projectA inside projectB and release the generated code for consumption in projectC. Tutorials, documentation and every example I could find, are using the generated Eclipse plugin from projectA to generate code in projectB. Although this works fine, I'm wondering how to reuse the generated code.

Is it possible to use just the code generator from projectA with Maven or something similar? How am I supposed to use the DSL in a continuous integration server? Do I have run Eclipse headless for that?

It seems to me, that I'm missing something obvious. So any pointers, hints, examples are welcome!

Was it helpful?

Solution

It is possible to generate the code from Xtext using the Fornax MWE runner (sadly not available in Maven Central but in http://www.fornax-platform.org/m2/repository).

We use this approach in EMF-IncQuery (corresponding pom file) based on a Tycho based compilation

1. Configure the clean plugin to empty the src-gen and xtend-gen folders (from all related projects, such as core, test and ui projects) 2. Use the Fornax plugin to execute the MWE2 workflow 3. Execute the Xtend compiler (some code is generated as Xtend classes)

Additional (mostly repository and Xtend compiler version) configuration is added to the parent pom of our build.

Update: Answered a wrong question; sorry. Trying a different answer.

First of all, you have to implement your language/compiler in a way to be integratable in a headless environment (see the way the xtend-maven-compiler is packaged).

Your grammar already has a generator (implementing the IGenerator interface) that receives the model and a helper class for file creation. In case of Xbase-using grammar, this generator is implemented by Xtext, otherwise you should have already implemented it.

Then you can provide an additional project that utilizes this generator, and thus is able to generate such code. Basically, use your languages StandaloneSetup/headless injector to get the IGenerator instance (in the new project), and add a new FileSystemAccess instance that is parameterized according your build.

Then your project should reference the original project - e.g. it can also be a plug-in project, build it with Tycho, and then use it as a jar-based compiler; or you can create a pure Maven plug-in but in that case you might need to manually select the transitive dependencies required by Xtext.

In case of the xtend-maven-compiler plugin this is solved by creating an 'uberjar' by copying all dependencies into a single jar file, and then this is referred. Ugly, but it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top