Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » multi-module maven build
multi-module maven build [message #1548070] Mon, 05 January 2015 20:37 Go to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
During the process of migrating away from the fornax maven plugin, I had some difficulties configuring the different paths in the workflow of one particular project.

Goal: it should be possible to either build the entire multi-module thing, or just build one individual dsl project.

My trial-and-error process led me to a solution that looks a bit strange:

var projectName = "com.my.dsl.project"
var grammarURI = "platform:/resource/${projectName}/src/main/java/com/my/dsl/MyDSL.xtext"
var file.extensions = "mydsl"
var src.dir="/src/main/java"
var src.gen.dir="/target/generated-sources/xtext"
var parentPath=".." // preferably override from pom.xml to a canonicalized path
var runtimeProject = "${parentPath}/${projectName}"

Workflow {
    bean = StandaloneSetup {
            resourceSet = org.eclipse.xtext.resource.XtextResourceSet:theResourceSet {}
            scanClassPath = true
            platformUri = "${parentPath}"
            registerGeneratedEPackage = ...
            registerGenModelFile = ...
        }
    ... (DirectoryCleaner)...
        component = Generator {
            pathRtProject = runtimeProject
            pathUiProject = "${runtimeProject}.ui"
            projectNameRt = projectName
            projectNameUi = "${projectName}.ui"
            srcPath = "${src.dir}"
    	    srcGenPath = "${src.gen.dir}"
            mergeManifest = false
            language = {
                forcedResourceSet = theResourceSet        	
                uri = grammarURI
                fileExtensions = file.extensions
    
                fragment = grammarAccess.GrammarAccessFragment {}
    
              	fragment = ecore.EMFGeneratorFragment {
              		javaModelDirectory = "/${projectName}${src.gen.dir}"
              		xmiModelDirectory = "${runtimeProject}${src.gen.dir}"
                        updateBuildProperties=false
                }
...


While I could interactively run this workflow in the IDE (Run as...) , for maven builds I had to pass the parameter 'parentPath' with a value that requires a little hack in groovy:
		def path=new File(project.basedir.canonicalPath+"/..").canonicalPath;
		if (path.charAt(0) == '/')
			pom.properties['parentPath'] = path
		else
			pom.properties['parentPath'] = "/"+path
		println("parentPath="+pom.properties['parentPath'])


What's particularly strange here is the asymmetry between javaModelDirectory and xmiModelDirectory:

  • javaModelDirectory must have the shape /projectName/relativeDirectory, because this path will be used in a platform:/resource URI
  • xmiModelDirectory must be an absolute filesystem path


Interestingly, any other shape of path in javaModelDirectory let the generator fall over the paths for generated java files: the generator complained that these paths were "not mapped". Paths were internally expanded to correct absolute filesystem paths, so I have no idea, why these needed to be mapped further.

(Also, coming from the old (deprecated) EcoreGeneratorFragment it took me a while to figure out, how to configure the output paths at all - the old one seemed to rely more on srcGenPath of the enclosing Generator configuration.)

Finally, s.t. kept adding "model/" to bin.includes in build.properties although such directory is never used, leading to a build failure next time around. Yes, I can explicitly suppress this behavior, but why would the generator add a wrong path in the first place?


Bottom line: the above works, but it feels strange that only this particular skewed combination could be made to work. Am I missing s.t. obvious? Are multi-module builds uncommon for Xtext projects (I wouldn't think so)?

Otherwise I hope that the above might be helpful for others running into similar situations Smile

Stephan
Re: multi-module maven build [message #1549065 is a reply to message #1548070] Tue, 06 January 2015 09:52 Go to previous messageGo to next message
Dennis Huebner is currently offline Dennis HuebnerFriend
Messages: 257
Registered: July 2009
Senior Member

Hi Stephan,
we have an example Xtext project build using tycho.
Maybe it helps you to look into:
https://github.com/dhuebner/xtext-builddsl-tycho

I'm not sure xmiModelDirectory setting is necessary at all. If you generate to a source folder, your URI will be different at developing time (WS) and runtime (jar), missing src-gen part at runtime. The better way is to generate to the .../model/generated folder.

Regards,
Dennis.



+Dennis Huebner

Get professional support from the Xtext committers at www.typefox.io
Re: multi-module maven build [message #1549115 is a reply to message #1549065] Tue, 06 January 2015 10:34 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Thanks Dennis,

The first significant difference I see: in your project the maven parent has its child modules in sibling directories, not child directories. That certainly makes a huge difference. If that's the structure for which the tools have been designed and tested, perhaps the Xtext team may want to recommend this structure at a prominent place in the documentation (too late for me, though). This could well explain why configuring a project with child module = child directory feels like driven off-road.

Regarding colocation of model and source: yes, I recently learned that this is not a good idea, but still I'd like to adhere to the Maven convention that everything is either in src/main/something or in target/something. Additionally, my need to define xmiModelDirectory may have just been a consequence of the directory layout mentioned above.

Your definition of 'javaModelDirectory = "/${projectName}/src-gen"' confirms a result of my debugging: this path must be interpretable as a suffix to "platform:/resource". Sounds like s.t. worth documenting in EMFGeneratorFragment. This is particularly relevant, since xmiModelDirectory seems to apply different semantics (file path not interpreted via "platform:/resource").

It seems that after one fundamental design choice differing from your assumptions I will continue to challenge "unusual" situations Smile

cheers,
Stephan
Re: multi-module maven build [message #1549129 is a reply to message #1549115] Tue, 06 January 2015 10:42 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Stephan Herrmann wrote on Tue, 06 January 2015 11:34
Regarding colocation of model and source: yes, I recently learned that this is not a good idea, but still I'd like to adhere to the Maven convention that everything is either in src/main/something or in target/something.


If I understand correctly its actually impossible to obey to both rules, those of Maven and those of EMF? The 'model' directory must be a toplevel directory in the project, right? So even src/main/model doesn't cut it...

In the past I always experienced lots of trouble when I tried to bend Maven into structures that are not the typical Maven structures. Apparently, bending EMF into Maven conventions doesn't improve the situation. From your example I read that violating Maven conventions seems to do less harm than violating EMF recommendations, right?

thanks,
Stephan

Re: multi-module maven build [message #1549252 is a reply to message #1549129] Tue, 06 January 2015 12:13 Go to previous messageGo to next message
Dennis Huebner is currently offline Dennis HuebnerFriend
Messages: 257
Registered: July 2009
Senior Member

Quote:
The 'model' directory must be a toplevel directory in the project, right? So even src/main/model doesn't cut it..

The location for the generated emf files should not be a part of the java source folder. because there location will differ after packaging them in to a jar. So the URIs computed during the build time will not be the same as at runtime. Thats all.

Regarding the case where you would like to put your main pom in root folder, I don't think it's will cause any problems. It's only about how you calculate the runtimeProject Path in your module pom.xml



+Dennis Huebner

Get professional support from the Xtext committers at www.typefox.io
Re: multi-module maven build [message #1549286 is a reply to message #1549252] Tue, 06 January 2015 12:38 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Dennis Huebner wrote on Tue, 06 January 2015 13:13

The location for the generated emf files should not be a part of the java source folder. because there location will differ after packaging them in to a jar. So the URIs computed during the build time will not be the same as at runtime. Thats all.


OK, so "src/main/model" should be fine.

Quote:
Regarding the case where you would like to put your main pom in root folder, I don't think it's will cause any problems. It's only about how you calculate the runtimeProject Path in your module pom.xml


Hm, so that would only explain the need for my groovy hack (because this exact calculation needs to compensate the difference between full reactor build vs. building an individual module).

That would leave us with just the undocumented and different assumptions about the paths of javaModelDirectory and xmiModelDirectory as the root for my troubles.

Plus the issue, that EcoreGeneratorFragment and EMFGeneratorFragment seem to be react differently to the path configured in the enclosing Generator's srcGenPath. BTW: srcGenPath seems to assume a project relative path, right?

cheers,
Stephan
Re: multi-module maven build [message #1549362 is a reply to message #1549286] Tue, 06 January 2015 13:31 Go to previous messageGo to next message
Dennis Huebner is currently offline Dennis HuebnerFriend
Messages: 257
Registered: July 2009
Senior Member

Stephan, it's difficult to say whats exactly goes wrong, when calculating path.
Is it possible to look into your project source code?



+Dennis Huebner

Get professional support from the Xtext committers at www.typefox.io
Re: multi-module maven build [message #1549381 is a reply to message #1549362] Tue, 06 January 2015 13:45 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Dennis Huebner wrote on Tue, 06 January 2015 14:31
Stephan, it's difficult to say whats exactly goes wrong, when calculating path.
Is it possible to look into your project source code?


Dennis, thanks for the offer.
Unfortunately that project is not open-source.

OTOH, if I use the exact setup from my initial post, all seems well. I was only puzzled why a gazillion (I'm slightly exaggerating Smile ) other configurations did not work. Debugging told me that the different path configurations are processed differently. Hence I'm suggesting to document the assumptions, because without such documentation everybody using a non-standard setup has to repeat my debugging party (which was much less fun than you expect from a party...).

From all my observations:

  • Generator.srcGenPath will be appended to the project's path to yield a file system path
  • EMFGeneratorFragment.javaModelDirectory must have the shape "/projectName/relativePath" because it will get a prefix "platform:/resource" prior to evaluation.
  • EMFGeneratorFragment.xmiModelDirectory is directly interpreted as a file path, nothing prepended (not sure if it can be relative to some current directory, absolute path works fine).


Just saying "path" in all three locations is not sufficient for unsuspecting clients. Do you see my point?

best,
Stephan
Re: multi-module maven build [message #1549403 is a reply to message #1549381] Tue, 06 January 2015 14:03 Go to previous messageGo to next message
Dennis Huebner is currently offline Dennis HuebnerFriend
Messages: 257
Registered: July 2009
Senior Member

Quote:
Just saying "path" in all three locations is not sufficient for unsuspecting clients. Do you see my point?

I see Smile
Maybe we can find a better names and deprecate existing. And adding javadoc will also make sense.



+Dennis Huebner

Get professional support from the Xtext committers at www.typefox.io
Re: multi-module maven build [message #1549494 is a reply to message #1549403] Tue, 06 January 2015 15:10 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Javadoc would be a treat Smile
Previous Topic:Customize IQualifiedNameProvider Problem
Next Topic:Grammar, where I'm wrong?
Goto Forum:
  


Current Time: Sat Apr 20 03:21:49 GMT 2024

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

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

Back to the top