Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » MWE2/Xtend2 and outlets
MWE2/Xtend2 and outlets [message #727177] Tue, 20 September 2011 15:08 Go to next message
Matt Campbell is currently offline Matt CampbellFriend
Messages: 11
Registered: April 2011
Junior Member
I'm migrating some Xtext 1 projects over to Xtext 2. The old code generation templates are written in Xpand and I'm slowly moving them over to Xtend as I learn the different mechanisms for doing the same things. We currently use multiple outlets to control where different kinds of files are generated, and I can't find any examples of doing this with Xtend. All of the examples seem to call IFileSystemAccess's generateFile which I see takes something called an outputConfigurationName, but I can't figure out how to get my workflow's outlets with their outletNames (passing the outlet name as the second parameter to generatFile() throw's a null pointer exception).

I've been looking through the forums and the xtext codebase for an example of an Xtend template using an outlet defined in the mwe2 workflow and I don't see anything. Are the outlets only in MWE2 for Xpand, or can you point me to some example code on using them in Xtend? Thanks!
Re: MWE2/Xtend2 and outlets [message #727183 is a reply to message #727177] Tue, 20 September 2011 15:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

outlets are not sophicticated in Xtext 2.0.0/2.0.1
in 2.1.0 they ll get more like this Xpand ones.

the basic idea is to call
org.eclipse.xtext.generator.AbstractFileSystemAccess.setOutputPath(String, String)
when you configure your FileSystemAcccess

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: MWE2/Xtend2 and outlets [message #727200 is a reply to message #727183] Tue, 20 September 2011 15:40 Go to previous messageGo to next message
Matt Campbell is currently offline Matt CampbellFriend
Messages: 11
Registered: April 2011
Junior Member
[EDIT] Ah, actually I'm using 2.0.1, my mistake. That makes sense then that there isn't much to do with them in my environment then Smile

I'm using the latest stable builds of Xtext 2.0.1 and I saw the method you mention, but I wasn't sure of the best way to pull the outletName and path from MWE2 workflow to pass into that method.

If I've got outlets defined in my MWE2 workflow as such:
component = org.eclipse.xtext.generator.GeneratorComponent {
    register = my.dsl.ModelDslStandaloneSetup {}
    slot = 'model'
    outlet = {
        outletName = "common"
        path = "src-gen-common"
    }
    outlet = {
        path = targetDir
    }
}


The targetDir 'src-gen' is the default output directory for all generateFile() calls. How would I use the common outlet's name and path in my Xtend file? The method you mention seems to imply I should do something like:
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
    for(component : resource.allContentsIterable.filter(typeof(MyDslComponent))) {
        (fsa as AbstractFileSystemAccess).setOutputPath("common", "src-gen-common")
        fsa.generateFile(
            component.fullyQualifiedName.toString().replace(".", "/") + ".idl",
            idlGenerator.generateIdl(component))
    }
}

but that disregards the outlet defined in the workflow and hard-codes that value in the template itself and I was hoping not to have to do that. I tried pulling out an outputConfiguration with the outlet name as below, but it doesn't seem outlets in the workflow get automatically translated into output configurations:
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
    for(component : resource.allContentsIterable.filter(typeof(MyDslComponent))) {		
        fsa.generateFile(
            component.fullyQualifiedName.toString().replace(".", "/") + ".idl",
            (fsa as AbstractFileSystemAccess).outputConfigurations.get("common").name,
            idlGenerator.generateIdl(component))
    }
}


We've used Xtext 1.0 for a while (and oAW for a while before that) so some of the patterns are familiar to me, but I'm still sort of new to digging around in the internals. I appreciate the fantastic tool and any pointers in the right direction here.

[Updated on: Tue, 20 September 2011 15:46]

Report message to a moderator

Re: MWE2/Xtend2 and outlets [message #727213 is a reply to message #727200] Tue, 20 September 2011 16:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

override void doGenerate(Resource resource, IFileSystemAccess fsa) {
fsa.generateFile("a.txt","common","test")
}

works for me.
setOutputPath is for the other side of the tool and done in
org.eclipse.xtext.generator.GeneratorComponent

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: MWE2/Xtend2 and outlets [message #727233 is a reply to message #727213] Tue, 20 September 2011 16:50 Go to previous messageGo to next message
Matt Campbell is currently offline Matt CampbellFriend
Messages: 11
Registered: April 2011
Junior Member
Hrmm... I think there might be something strange going on with my workflow. Is there a difference between the GenereMWE.mwe2 file that gets created in the src folder (in the .generator package) and the automatic incremental building happening under the hood? I assumed that the latter was using the former for configuration, but the outlets I've defined in the workflow aren't getting translated into output configurations in the AbstractFileSystemAccess when the incremental build invokes my templates (which makes me think the incremental build isn't running that workflow). How would I go about making the incremental build use outlets?

[Updated on: Tue, 20 September 2011 16:51]

Report message to a moderator

Re: MWE2/Xtend2 and outlets [message #727236 is a reply to message #727233] Tue, 20 September 2011 16:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

use a customized JavaProjectBasedBuilderParticipant

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: MWE2/Xtend2 and outlets [message #727576 is a reply to message #727236] Wed, 21 September 2011 14:44 Go to previous messageGo to next message
Matt Campbell is currently offline Matt CampbellFriend
Messages: 11
Registered: April 2011
Junior Member
Is there a good place to find an example of doing this? I searched my DSL projects and I can't find any reference to that class, so I don't even know where I'd replace the existing one with a customized version of it. Sorry to be dense, but a lot of this level of customization is new to me. Thanks!
Re: MWE2/Xtend2 and outlets [message #727606 is a reply to message #727576] Wed, 21 September 2011 15:56 Go to previous messageGo to next message
Matt Campbell is currently offline Matt CampbellFriend
Messages: 11
Registered: April 2011
Junior Member
I've been digging around some more and it looks like the DSL is using an instance of BuilderParticipant instead of JavaProjectBasedBuilderParticipant. BuilderParticipant has an instance of OutputConfigurationProvider injected, so I was looking at that class to see it's getOutputConfigurations() returns a single default outlet at src-gen. I'm looking at implementing a version of that class that gets its output configurations from the workflow - is this generally the direction I should be looking into? Thanks again for all your help!
Re: MWE2/Xtend2 and outlets [message #727608 is a reply to message #727606] Wed, 21 September 2011 15:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

which version do you use? there are heavy changes on this in the latest nightlys.
i thought you were using 2.0.0 or 2.0.1.
but in general: there is not connection to the workflow at all. and maybe should not be.

If you want to unify this do it the other way round: write a custom org.eclipse.xtext.generator.GeneratorComponent that uses your OutputConfigurationProvider.

since it is a nightly: maybe GeneratorComponent was not updated yet
https://bugs.eclipse.org/bugs/show_bug.cgi?id=353463

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 21 September 2011 20:39]

Report message to a moderator

Re: MWE2/Xtend2 and outlets [message #728232 is a reply to message #727608] Thu, 22 September 2011 18:55 Go to previous messageGo to next message
Matt Campbell is currently offline Matt CampbellFriend
Messages: 11
Registered: April 2011
Junior Member
I'm currently targeting my eclipse at the latest stable update site from xtext.org, so I just ran an update check and pulled the latest 2.0.1.v201109210303. I see a lot of the work going in those classes for the enhancement request you linked to, but I don't see any way to actually configure the output configuraitons. Is that somewhere in the project properties for my language project and I'm just not seeing it, or is it not implemented yet? If not, I'll keep my eyes open for something like that in the future and keep going forward with my custom OutputConfigurationProvider setting up the output folders we expect for our language.

I'm still a little confused about the different between the GeneratorMWE.mwe2 workflow created automatically next to my xtend templates and the automatic build going on inside eclipse. As I understand it, the automatic build doesn't use this workflow - does that mean I have to maintain two sets of configurations (one in extended/injected customized java classes and one in the workflow)? What specifically uses that workflow? I noticed the new project wizard still generates a workflow next to my language file but all the screencasts I've seen lately don't have it and the automatic build works fine without it so I deleted it. Should I have kept it around (and in what cases would someone invoke that instead of letting the automatic build do its thing?) As always, thanks for all the help.
Re: MWE2/Xtend2 and outlets [message #728240 is a reply to message #728232] Thu, 22 September 2011 19:11 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

so you are actually using the latest nightlys. this stuff is brand new and not yet done.
you find the prefs und window preferences yourdsl builder


the builder is used from within eclipse. the workflow is for calling the generation standalone. it is your choice if you want to enable it in the builder/eclipse or just call it standalone e.g. in a continous build.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:DSL > XMI > DSL
Next Topic:Code completion with variables
Goto Forum:
  


Current Time: Tue Apr 23 06:49:17 GMT 2024

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

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

Back to the top