Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Example for import in grammar?
Example for import in grammar? [message #715853] Mon, 15 August 2011 19:00 Go to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
I was looking for an example how in XText 2.0 we define an import in a grammar.

The help recommends to use

  import "classpath:/my/existing/Model.ecore"


and adds that one should also add s.t. like

  fragment = org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment {
   referencedGenModels =
     "classpath:/my/existing/Model.genmodel"
  }


However, running the GenerateMyDsl.mwe2 then throws:
 java.lang.IllegalStateException: The referenced package 'http://www.mycomp.com/Model' was imported from a different location. Here: 'platform:/resource/my/existing/Model.ecore'


Similar to http://www.eclipse.org/forums/index.php/t/225366/

Looking at the mwe2 it actually says in a hover over referencedGenModels:
   void org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.setReferencedGenModels(String referencedGenModel)
   @Deprecated
   use StandaloneSetup.addRegisterGenModelFile(String)


So I change that to

  bean = StandaloneSetup {
        scanClassPath = true
        platformUri = "${runtimeProject}/.."
        registerGenModelFile = "classpath:/my/existing/Model.genmodel"
    }


But now the workflow fails with
  java.net.MalformedURLException: unknown protocol: classpath


I must be barking up the wrong tree.
Can someone please point me to a working example of imports?

TIA,
Stephan
Re: Example for import in grammar? [message #718544 is a reply to message #715853] Wed, 24 August 2011 16:25 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
As an intermediate solution I changed the classpath based import to using "platform:/resource/...", which works OK in the IDE, but I will soon need to run the workflow on the build server using Maven. I'm afraid at that point platform: URIs won't work either, right?

What do I need to do to get classpath based imports to work?

thanks,
Stephan
Re: Example for import in grammar? [message #718547 is a reply to message #718544] Wed, 24 August 2011 16:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi, that will work. This is what that magic StandaloneSetup platformuri does. Regards Christian

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Example for import in grammar? [message #718561 is a reply to message #718547] Wed, 24 August 2011 16:57 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Christian Dietrich wrote on Wed, 24 August 2011 18:28
Hi, that will work. This is what that magic StandaloneSetup platformuri does. Regards Christian


Does this mean platform: is always superior to classpath:? The help document seems to indicate that classpath: is stronger than platform:, maybe that's outdated?

thanks,
Stephan
Re: Example for import in grammar? [message #737044 is a reply to message #718547] Fri, 14 October 2011 15:46 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Christian Dietrich wrote on Wed, 24 August 2011 18:28
Hi, that will work. This is what that magic StandaloneSetup platformuri does. Regards Christian


I finally got to the point of building on Jenkins, and it seems what is true on the local machine doesn't hold for the server:

Invoking maven from the command line from within my Eclipse workspace directory works OK, but at a closer look the "magic" is just a hardcoded value of "../.." for the platform: prefix. If directories are setup that way everything's fine.

However, on the build server I have separate build jobs which cannot access each others workspaces, so ../.. is not a good option.

In times of Xtext 0.7 everything worked smoothly using classpath: uris. Isn't there a way to do the same in Xtext 2.0?

best,
Stephan
Re: Example for import in grammar? [message #737285 is a reply to message #737044] Fri, 14 October 2011 21:46 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
OK, I found one workaround for this regression (compared to Xtext 0.7):

When building on Jenkins using Maven always build all projects within a single Jenkins job. This ensures that the directory structure can be used for platform: uris.

Independent build of projects where the grammar of one project imports the grammar of another one seems to be impossible with Xtext 2.0.

Please correct me, if there is indeed a way that I failed to see.
Stephan
Previous Topic:UI plug-ins loaded when creating Xtext resource
Next Topic:Calling IGenerator from an Handler
Goto Forum:
  


Current Time: Mon Sep 23 18:42:05 GMT 2024

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

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

Back to the top