Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] Merging several models into one output (file)(How can I create one output file contains informations from more than one model?)
[Xpand] Merging several models into one output (file) [message #641842] Sun, 28 November 2010 17:13 Go to next message
Michael Lindner is currently offline Michael LindnerFriend
Messages: 3
Registered: November 2010
Junior Member
I've got the following DSL written in Xtext:
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types 

generate mydsl "http://www.test.de/mydsl/MyDsl"

MyModel:
   'mymodel' name=ID '{'
      allSubsystem+=Subsystem*
   '}'
;

Subsystem:
   name=ID '{'
      (messages="messages" '{'
        allMessage+=Message*
      '}')?
   '}'
;

Message:
   'error' name=ID (allLanguage+=MessageLang (','? allLanguage+=MessageLang)* )
;

MessageLang:
    lang=MessageLanguage '=>' message=STRING
;

enum MessageLanguage:   DE | EN;


My default workflow looks like this:
Workflow {
  component = org.eclipse.xtext.mwe.Reader {
    // lookup all resources on the classpath
    useJavaClassPath = true

    // or define search scope explicitly
    path = modelPath

    // this class will be generated by the xtext generator 
    register = de.db.kolt.ribdsl.RibDslStandaloneSetup {}
    load = {
      slot = "allMyModel"
      type = "MyModel"
    }
  }

  component = org.eclipse.xpand2.Generator {
    expand = "templates::Main::processMain FOREACH allMyModel"
    outlet = {
      path = targetDir
    }
    fileEncoding = fileEncoding
  }
}


Not really spectacular. But now my question. If I run the workflow and my Xpand file looks like this
«DEFINE processMain FOR MyModel-»
  «EXPAND processMessage»
«ENDDEFINE»

«DEFINE processMessage FOR MyModel»
  «FILE "messages.properties"»
    «FOREACH allSubsystem.allMessage AS message»
      «FOREACH message.allLanguage AS entry»
        «REM»the entry is unique by the name of the subsystem + "." + name of the mesage«ENDREM»
        «((Subsystem)message.eContainer()).name».«message.name»=«entry.message»
       «ENDFOREACH»
    «ENDFOREACH»
  «ENDFILE»
«ENDDEFINE»


the generator only produces one output file with the first model of one file. But I have more than one file in my source-directory. In every file (model) are several messages.

Who can I create only one output file ("messages.properties") which contains all messages from all models out of many files?

Than you

Michael
Re: [Xpand] Merging several models into one output (file) [message #641850 is a reply to message #641842] Sun, 28 November 2010 18:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
hello michael, there are two ways to solve this:

(1) restructure the templates

Workflow {
  component = org.eclipse.xtext.mwe.Reader {
    // lookup all resources on the classpath
    useJavaClassPath = true

    // or define search scope explicitly
    path = modelPath

    // this class will be generated by the xtext generator 
    register = de.db.kolt.ribdsl.RibDslStandaloneSetup {}
    load = {
      slot = "allMyModel"
      type = "MyModel"
    }
  }

  component = org.eclipse.xpand2.Generator {
    expand = "templates::Main::processMain FOR allMyModel"
    outlet = {
      path = targetDir
    }
    fileEncoding = fileEncoding
  }
}



«DEFINE processMain FOR List[MyModel]-»
  «FILE "messages.properties"»
  «EXPAND processMainElement FOREACH this»
  «ENDFILE»
«ENDDEFINE»

«DEFINE processMainElement FOR MyModel-»
  «EXPAND processMessage»
«ENDDEFINE»

«DEFINE processMessage FOR MyModel»

    «FOREACH allSubsystem.allMessage AS message»
      «FOREACH message.allLanguage AS entry»
        «REM»the entry is unique by the name of the subsystem + "." + name of the mesage«ENDREM»
        «((Subsystem)message.eContainer()).name».«message.name»=«entry.message»
       «ENDFOREACH»
    «ENDFOREACH»

«ENDDEFINE»



(2) change the configuration of the outlet

component = org.eclipse.xpand2.Generator {
		expand = "templates::Template::main FOREACH greetings"
		outlet = {
			path = targetDir
			append = true
		}
		fileEncoding = fileEncoding
	}


If you have other generated artefacts that should no be appended just create another outlet

	component = org.eclipse.xpand2.Generator {
		expand = "templates::Template::main FOREACH greetings"
		outlet = {
			path = targetDir
		}
		
		outlet = {
			path = targetDir
			append = true
			name = "ANAME"
		}
		fileEncoding = fileEncoding
	}


«FILE "test.txt" ANAME»
«name»
«ENDFILE»


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] Merging several models into one output (file) [message #641852 is a reply to message #641850] Sun, 28 November 2010 18:49 Go to previous message
Michael Lindner is currently offline Michael LindnerFriend
Messages: 3
Registered: November 2010
Junior Member
Hi Christian,

this is very helpful. I'll check the two possibilities and look, which way is the best one (for my use case).

Thanks

Michael
Previous Topic:[Xpand / Xtend] Recognizing custom UML Profile
Next Topic:[Xpand / Xtend] typeSelect() on stereotype does not work
Goto Forum:
  


Current Time: Tue Apr 16 11:43:35 GMT 2024

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

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

Back to the top