Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » how to restrict generation to a set of packages
how to restrict generation to a set of packages [message #552541] Thu, 12 August 2010 15:07 Go to next message
Oliver S is currently offline Oliver SFriend
Messages: 2
Registered: August 2010
Junior Member
Hello,

currently I am using oaw to generate code for my project. This is achieved through integration of oaw with maven. This works fine for quite a time (more than a year).
The version of oaw in use is 4.2.x.

In my scenario all code is generated in one project (in this case a maven module/artifact) and I want to change this in the following way:
My aim is to integrate the generator component in different projects so that in each project only a distinct set of packages is being generated from one and the same model.

e.g.:
- there is one UML model, containing two packages Package1 and Package2
- there is a project A. Only classes from Package1 should be generated into project A
- there is a project B. Only classes from Package2 should be generated into project B



My problem is that I don't know of a way to declare what classes/packages to generate.
Is there a way to cut down the selection of packages?

Here is an excerpt from my workflow:

<component id="generator"
		class="org.openarchitectureware.xpand2.Generator"
		skipOnErrors="true">
		<metaModel idRef="uml2" />
		<metaModel idRef="profile" />
		<metaModel class="oaw.type.emf.EmfMetaModel" metaModelPackage="org.eclipse.emf.ecore.EcorePackage" />
		<metaModel class="oaw.uml2.UML2MetaModel" />
		<!-- Start text/code generation with the following template for the object  -->
		<expand value="templates::Root::Root FOR ${modelSlot}" />

[...] </component>



I can't see a way how to achieve this.
So my question: can this be done with oaw?

Thanks in advance!
Oliver
Re: how to restrict generation to a set of packages [message #552544 is a reply to message #552541] Thu, 12 August 2010 15:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

sure this can be done. within you template you call an xpanddefintion for your packages - here you have to filter out the package you do not want to have - the name you want to filter you could pass to the template from the workflow - so that you can reuse the template for both cases.

Regards
Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to restrict generation to a set of packages [message #552552 is a reply to message #552544] Thu, 12 August 2010 15:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Here is a sample (built with xpand 1.0.0) but this should not matter.


Here a sample Model

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_0K2YkaYmEd-lhdqW6x_oOw">
  <packagedElement xmi:type="uml:Package" xmi:id="_2KfVEKYmEd-lhdqW6x_oOw" name="a">
    <packagedElement xmi:type="uml:Class" xmi:id="_6FnG0KYmEd-lhdqW6x_oOw" name="A"/>
  </packagedElement>
  <packagedElement xmi:type="uml:Package" xmi:id="_21fZ4KYmEd-lhdqW6x_oOw" name="b">
    <packagedElement xmi:type="uml:Class" xmi:id="_6-vHMKYmEd-lhdqW6x_oOw" name="B"/>
  </packagedElement>
</uml:Model>



and template

«DEFINE Root(String thename) FOR uml::Model»
	«EXPAND PackageRoot FOREACH this.ownedElement.typeSelect(uml::Package).select(e|e.name == thename)»
«ENDDEFINE»

«DEFINE PackageRoot FOR uml::Package»
	«EXPAND ClassRoot FOREACH this.ownedElement.typeSelect(uml::Class)»
«ENDDEFINE»

«DEFINE ClassRoot FOR uml::Class»
«FILE name + ".java"»
public class «name» {

}
«ENDFILE»
«ENDDEFINE»


and workflow

<workflow>

	<bean class="org.eclipse.xtend.typesystem.uml2.Setup" standardUML2Setup="true"/>
	
	<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup">
		<platformUri value=".." />
	</bean>
	
	<component class="org.eclipse.emf.mwe.utils.Reader">
	    <uri value="platform:/resource/my.generator.projectx/src/model/test.uml" />
		<modelSlot value="model" />
	</component>
	
	<component class="org.eclipse.xpand2.Generator">
		<metaModel class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel" />
		<expand
			value="template::Root::Root('b') FOR model" />
		<outlet path="src-gen" >
			<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
		</outlet>
	</component>

</workflow>


this sample filters for exacly one package and cannot handle package hierarchies (full qualified names) but this should be easyly adopable.

~Christian


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

[Updated on: Thu, 12 August 2010 15:43]

Report message to a moderator

Re: how to restrict generation to a set of packages [message #552781 is a reply to message #552541] Fri, 13 August 2010 13:37 Go to previous message
Oliver S is currently offline Oliver SFriend
Messages: 2
Registered: August 2010
Junior Member
Thrilling, it works! thank you very much, Christian!

I still had to do a bit more to make it work in my environment but the parameter trick does the job and I think I got it basically running. It might be that I'll come around with another question regarding my case but this one seems to be solved that way.

Thanks!

Oliver
Previous Topic:[Xpand]: definition not found
Next Topic:[Xpand] How to programmatically use an ecore model root object for code generation
Goto Forum:
  


Current Time: Tue Apr 23 09:09:21 GMT 2024

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

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

Back to the top