Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Standalone Code Generator build with Maven(It can't handle entities)
Xtext Standalone Code Generator build with Maven [message #1022283] Thu, 21 March 2013 15:52 Go to next message
eclipse freund is currently offline eclipse freundFriend
Messages: 7
Registered: March 2013
Junior Member
Hi Smile

I have got a question according building a standalone(outside Eclipse) code generator application (generating some files from dsl language) with Maven.

I would like to work at .Xtext file and the .Xtend file only. Maven and its Plugins doing the rest to generate a code generator.

I've found an example( h t t p s : / / github.com / aphethean / xtext-maven-examples ..can't post links) that allows to build a standalone generator application, only needing to change .xtext and .xtend file.

But that example only works for simple DSL-Code.
When using cross references such as Entities it only works when starting it from Eclipse but not when starting the standalone code generator from command line.



.xtext code
..........................................................................................................................


myDsl :
application = Application
elements += Type*
;

Type:
DataType | Entity
;

DataType:
'datatype' name = ID
;

Entity:
'entity' name = ID ('extends' superType = [Entity])? '{'
features += Feature*
'}'
;

Feature:
many?='many'? name = ID ':' type = [Type]
;

Application:
'application' name = ID
;
..........................................................................................................................



.mydsl code
..........................................................................................................................

application Mytestapp1
datatype Integer
datatype String

entity Mytestentity{
id: Integer
firstname: String
lastname: String
age: Integer
}
..........................................................................................................................



In that case I got an Excption (it doesn't matter if .xtend file is implemented or not):

..........................................................................................................................

java -jar ./target/org.xtext.example.mydsl.generator-1.0.0-SNAPSHOT.jar -src ./src/test/mydsl/Example.mydsl -targetdir ./target


[main] ERROR xt.linking.lazy.LazyLinkingResource - resolution of uriFragment 'xtextLink_::0.1.2.2.0::2::/4' failed.
java.lang.StringIndexOutOfBoundsException: String index out of range: 128
at java.lang.String.substring(String.java:1946)
at org.eclipse.xtext.nodemodel.impl.AbstractNode.getText(AbstractNode.java:95)
at org.eclipse.xtext.nodemodel.util.NodeModelUtils.getTokenText(NodeModelUtils.java:373)
at org.eclipse.xtext.linking.impl.LinkingHelper.getCrossRefNodeAsString(LinkingHelper.java:51)
at org.eclipse.xtext.linking.impl.DefaultLinkingService.getCrossRefNodeAsString(DefaultLinkingService.java:132)
at org.eclipse.xtext.linking.impl.DefaultLinkingService.getLinkedObjects(DefaultLinkingService.java:113)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:179)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReference(LazyLinkingResource.java:147)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReferences(LazyLinkingResource.java:108)
at org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences(EcoreUtil2.java:497)
at org.eclipse.xtext.validation.ResourceValidatorImpl.resolveProxies(ResourceValidatorImpl.java:127)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:62)
at org.xtext.example.mydsl.generator.Generator.runGenerator(Generator.java:40)
at org.xtext.example.mydsl.generator.Main.main(Main.java:39)
Exception in thread "main" org.eclipse.emf.common.util.WrappedException: java.lang.StringIndexOutOfBoundsException: String index out of range: 128
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:217)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReference(LazyLinkingResource.java:147)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReferences(LazyLinkingResource.java:108)
at org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences(EcoreUtil2.java:497)
at org.eclipse.xtext.validation.ResourceValidatorImpl.resolveProxies(ResourceValidatorImpl.java:127)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:62)
at org.xtext.example.mydsl.generator.Generator.runGenerator(Generator.java:40)
at org.xtext.example.mydsl.generator.Main.main(Main.java:39)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 128
at java.lang.String.substring(String.java:1946)
at org.eclipse.xtext.nodemodel.impl.AbstractNode.getText(AbstractNode.java:95)
at org.eclipse.xtext.nodemodel.util.NodeModelUtils.getTokenText(NodeModelUtils.java:373)
at org.eclipse.xtext.linking.impl.LinkingHelper.getCrossRefNodeAsString(LinkingHelper.java:51)
at org.eclipse.xtext.linking.impl.DefaultLinkingService.getCrossRefNodeAsString(DefaultLinkingService.java:132)
at org.eclipse.xtext.linking.impl.DefaultLinkingService.getLinkedObjects(DefaultLinkingService.java:113)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:179)
... 7 more

..........................................................................................................................


I tried it with Xtext version 2.3.1 and 2.4.0 but with no difference.
I already tried some workarounds I found via "Dr. Google" but with no success.

If you got some examples that can do entities, some work around, or other useful information I would be happy if someone could share those with me.
Maybe there are some other, better solutions to build a standalone generator(without exporting it manually from Eclipse).
I would like to play around with those examples too.


Thanks for reading and Thanks for helping!

Bernhard


Re: Xtext Standalone Code Generator build with Maven [message #1022371 is a reply to message #1022283] Thu, 21 March 2013 19:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

if you work standalone you have to care that all resources are added to the resourceset.

looking at the github code i see
ResourceSet set = resourceSetProvider.get();
Resource resource = set.getResource(URI.createURI(inputPath), true);


=> only one resource is added.

=> determine all model files that build the model. (e.g. by traversing a dir) and call set.getResource(URI.createURI(model), true); foreach

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Standalone Code Generator build with Maven [message #1022694 is a reply to message #1022371] Fri, 22 March 2013 11:18 Go to previous messageGo to next message
eclipse freund is currently offline eclipse freundFriend
Messages: 7
Registered: March 2013
Junior Member
Hi

Thanks for answering so fast.

which exactly are "all model files that build the model"?
The generated files in src-gen directly under the package myDsl like the generated java files or .xmi file, .genmodel file, .ecore file or different files I have to call createURI for?

when I try to call createURI() whith some of these files I get an exception:
cannot create a resource .. a registered factory is needed..

Do you got some code examples?

Thanks Bernhard
Re: Xtext Standalone Code Generator build with Maven [message #1022698 is a reply to message #1022694] Fri, 22 March 2013 11:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
No I mean file1.mydsl file2.mydsl, ... , fileN.mydsl

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Standalone Code Generator build with Maven [message #1022702 is a reply to message #1022694] Fri, 22 March 2013 11:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
PS: maybe you have really only one file then I don't understand why
it doesn't work. I'd have to give it a try myself - when finding the
time

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Standalone Code Generator build with Maven [message #1022715 is a reply to message #1022698] Fri, 22 March 2013 12:13 Go to previous messageGo to next message
eclipse freund is currently offline eclipse freundFriend
Messages: 7
Registered: March 2013
Junior Member
Hi
I only got one mydsl file and entities are defined in that file.
The generator in that example can't resolve entities.

Do you have any more ideas to that problem?
Re: Xtext Standalone Code Generator build with Maven [message #1022720 is a reply to message #1022715] Fri, 22 March 2013 12:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

how do you execute the standalone generator?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Standalone Code Generator build with Maven [message #1022724 is a reply to message #1022720] Fri, 22 March 2013 12:30 Go to previous messageGo to next message
eclipse freund is currently offline eclipse freundFriend
Messages: 7
Registered: March 2013
Junior Member
I go to the directory of the generator project:
cd org.xtext.example.mydsl.generator

and execute the generated jar file:
java -jar ./target/org.xtext.example.mydsl.generator-1.0.0-SNAPSHOT.jar -src ./src/test/mydsl/Example.mydsl -targetdir ./target
Re: Xtext Standalone Code Generator build with Maven [message #1022732 is a reply to message #1022724] Fri, 22 March 2013 12:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
No sorry I have no idea maybe this is a dependent problem

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Standalone Code Generator build with Maven [message #1022744 is a reply to message #1022732] Fri, 22 March 2013 13:10 Go to previous messageGo to next message
eclipse freund is currently offline eclipse freundFriend
Messages: 7
Registered: March 2013
Junior Member
Thanks for help

maybe there is someone else in this community with some solutions
Re: Xtext Standalone Code Generator build with Maven [message #1022766 is a reply to message #1022744] Fri, 22 March 2013 13:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi found it seems like guava and antlr stuff is wrong. If I repackage
it in the standalone module and remove it as dep in the generator
module it works

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Standalone Code Generator build with Maven [message #1022788 is a reply to message #1022766] Fri, 22 March 2013 14:27 Go to previous messageGo to next message
eclipse freund is currently offline eclipse freundFriend
Messages: 7
Registered: March 2013
Junior Member
Hi

I will try that out on Monday because I have to go in a few minutes.

If you could be so kind please post the pom changes that are needed to correct
guava and antlr stuff.

Thanks and have a nice weekend

Re: Xtext Standalone Code Generator build with Maven [message #1022839 is a reply to message #1022788] Fri, 22 March 2013 16:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.2</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>10.0.1</version>
</dependency>


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Standalone Code Generator build with Maven [message #1023279 is a reply to message #1022283] Sat, 23 March 2013 20:59 Go to previous messageGo to next message
Felix Feisst is currently offline Felix FeisstFriend
Messages: 20
Registered: February 2012
Location: Germany
Junior Member
I do not have an answer to your inital question, sorry. But I do wonder, is there a maven repository with the Xtext dependencies available? If so, could you point me to the right url please.
Or did you have another approach to build your project with maven and resolve the necessary xtext dependcies?

Regards,
Felix
Re: Xtext Standalone Code Generator build with Maven [message #1023286 is a reply to message #1023279] Sat, 23 March 2013 21:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
I dont know any news on http://www.eclipse.org/forums/index.php/mv/msg/441058/988999/#msg_988999
besides using http://build.eclipse.org/common/xtend/maven/org/eclipse/xtend/org.eclipse.xtend.standalone/2.4.0/
as workaround and hoping it contains all you need.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Standalone Code Generator build with Maven [message #1023288 is a reply to message #1023286] Sat, 23 March 2013 21:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
p.S. you may follow https://bugs.eclipse.org/bugs/show_bug.cgi?id=365899 too

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Standalone Code Generator build with Maven [message #1023848 is a reply to message #1023288] Mon, 25 March 2013 09:50 Go to previous message
eclipse freund is currently offline eclipse freundFriend
Messages: 7
Registered: March 2013
Junior Member
Hi
I changed the Poms and source files were generated without exception.
Thanks for sharing your knowledge and your investigation.

Have a nice day Smile
Previous Topic:Terminal/Parser rule to support nested indent
Next Topic:WrappedException: The path is unmapped
Goto Forum:
  


Current Time: Thu Mar 28 11:23:46 GMT 2024

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

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

Back to the top