Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types(Not able to generate code for model referring to UML Primitive types using sample ant task)
[Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types [message #672348] Fri, 20 May 2011 18:56 Go to next message
Anil Bhatia is currently offline Anil BhatiaFriend
Messages: 23
Registered: February 2011
Junior Member
Hi,

I was initially using Acceleo version 3.0.2 (3.0.2.v20110217-1127). While attempting code generation using Ant task that gets generated with UML-to-Java sample I came across Bug 319375 (Need to post more than 5 messages to use a link).

Since Acceleo 3.1.0RC1 is available, I installed that over Eclipse Helios SR2. The ant task now started up fine, and worked with sample model. But if the model is using UML Primitive types (e.g. a model based upon default UML template, created using Papyrus), it does not generate code.

I have the following lines added in Generate.java
method:
public void registerResourceFactories(ResourceSet resourceSet) {
super.registerResourceFactories(resourceSet);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

Map uriMap = resourceSet.getURIConverter().getURIMap();
URI uri = URI.createURI("jar:file:/C:/EclipseHeliosSR2/eclipse/plugins/org.eclipse.uml2.uml.resources_3.1.1.v201008191505.jar!/");
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
}

Running this through sample ant task gives the following message:
generateJavaSample:
generateJava:
[java] The generation fail to generate any file because there are no model elements that matches at least the type of the first parameter of one of your main templates.
[java] The problem may be caused by a problem with the registration of your metamodel, please see the method named "registerPackages" in the Java launcher of your generator.
BUILD SUCCESSFUL
Total time: 4 seconds



The Acceleo launcher seems to work fine as usual. Its only with the ant task I am facing this issue.

In an attempt to be more precise, I even tried with Acceleo 3.1.0M7, but that also gives same results.

Perhaps I am missing something here...
Please give some pointers.

Thanks
Anil
Re: [Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types [message #673301 is a reply to message #672348] Mon, 23 May 2011 07:39 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

Did you register the UML metamodel in the registerPackages method ?

Stephane Begaudeau, Obeo
--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com

Re: [Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types [message #673306 is a reply to message #673301] Mon, 23 May 2011 07:57 Go to previous messageGo to next message
Anil Bhatia is currently offline Anil BhatiaFriend
Messages: 23
Registered: February 2011
Junior Member
The generated code for registerPackages method is as follows:

/**
* Updates the registry used for looking up a package based namespace, in the resource set.
*
* @param resourceSet
* is the resource set
* @generated
*/
@Override
public void registerPackages(ResourceSet resourceSet) {
super.registerPackages(resourceSet);
if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
}

/*
* TODO If you need additional package registrations, you can register them here. The following line
* (in comment) is an example of the package registration for UML. If you want to change the content
* of this method, do NOT forget to change the "@generated" tag in the Javadoc of this method to
* "@generated NOT". Without this new tag, any compilation of the Acceleo module with the main template
* that has caused the creation of this class will revert your modifications. You can use the method
* "isInWorkspace(Class c)" to check if the package that you are about to register is in the workspace.
* To register a package properly, please follow the following conventions:
*
* if (!isInWorkspace(UMLPackage.class)) {
* // The normal package registration if your metamodel is in a plugin.
* resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
* } else {
* // The package registration that will be used if the metamodel is not deployed in a plugin.
* // This should be used if your metamodel is in your workspace.
* resourceSet.getPackageRegistry().put("/myproject/myfolder/mysubfolder/MyUMLMetamodel.ecore", UMLPackage.eINSTANCE);
* }
*/
}

Since I am not defining UML metamodel in my workspace, that should register the UML metamodel.
Is there some other step required to register this as well...?

Thanks
Anil
Re: [Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types [message #673944 is a reply to message #673306] Wed, 25 May 2011 08:50 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi Anil,

Let's try to rule out the "model loading" issues first. Have you followed the instructions on the UMl FAQ on "how to load an UML model standalone"?

If yes, are you positive that the Acceleo generator you're trying to run can indeed generate files with the model you're feeding it?

Laurent Goubet
Obeo
Re: [Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types [message #674348 is a reply to message #673944] Thu, 26 May 2011 15:22 Go to previous messageGo to next message
Anil Bhatia is currently offline Anil BhatiaFriend
Messages: 23
Registered: February 2011
Junior Member
Hi Laurent,

Thanks for asking pin-pointed question. This made me execute additional scenario.
I have followed the instructions from UML FAQ.

Its only with the generated sample (UML-to-Java) that I am getting the error message for a UML model referring to UML Primitive Types (created using Papyrus), when Stand Alone Launcher is used. (I was wrong earlier that its not generating code... It generates java code, including attribute type, but also gives error message).
If I run UML-to-Java on the same model using Acceleo Launcher, there is no error message, and proper code gets generated.

Another scenario that I tried:
I wrote my own M2T transform, printing class name, and attribute name & type. This worked fine in both modes (Acceleo, and Stand Alone Launcher). In fact, this template gets executed from ant task also.

I double checked, I am doing the steps from UML FAQ in both scenarios.

Thanks
Anil
Re: [Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types [message #675145 is a reply to message #674348] Mon, 30 May 2011 12:26 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Anil,

That seems ... strange. Just so we can try and reproduce : you're launching the UML-to-java example with the "example.uml" model that is part of the example? If not, could you provide us with the model you're trying to generate code for?

Laurent Goubet
Obeo
Re: [Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types [message #675722 is a reply to message #675145] Wed, 01 June 2011 09:50 Go to previous messageGo to next message
Anil Bhatia is currently offline Anil BhatiaFriend
Messages: 23
Registered: February 2011
Junior Member
Hi Laurent,

"example.uml" gives proper results, as it has internally defined (UML Primitive Types' equivalent) data types. The problem occurs when the types are referred to from UML Primitive type library (as done by Papyrus).

Here is the small model file I used to reproduce the problem (also attached):
-----------------------model.uml--------------------------------------
<?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="_nV-T4YR9EeCpYc3e9vYqpw" name="Model">
<packageImport xmi:id="_nV-T4oR9EeCpYc3e9vYqpw">
<importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
</packageImport>
<packagedElement xmi:type="uml:Package" xmi:id="_uH5ToIR9EeCpYc3e9vYqpw" name="org">
<packagedElement xmi:type="uml:Class" xmi:id="_vwNVQIR9EeCpYc3e9vYqpw" name="Class0">
<ownedAttribute xmi:id="_mI_EcIUOEeCZ6JFlaRmIGQ" name="Property0">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
</ownedAttribute>
</packagedElement>
</packagedElement>
</uml:Model>

-----------------------------------------------
Class0 has a property Property0 of type String coming from UML Primitive type library.

Here are the steps to create such a model using Papyrus:
1. File -> New -> Other... (or Ctrl + n)
2. Select "Papyrus Model" on "Select a Wizard" page. Click Next.
3. Specify name of diagram file (model.di).
4. Select UML as Diagram Language.
5. On the page "Initialization information", specify the following
a) Name of Diagram
b) Select some diagram kind (say, UML Class Diagram)
c) You can load a template: Check the box that says "A UML model with basic primitive types (ModelWithBasicTypes.uml)
Click Finish
6. Switch to Papyrus perspective.
7. In the Model Explorer right click on Model, and keep mouse over "New Child" -> "Create a new class".
8. On the newly created class Class0, right click, "New Child" -> "Create a new Property".
9. Expand "ownedAttribute" under Class0 in Model Explorer.
10. Select newly created Property0 in Model Explorer, and you should be able to see its details in "Properties" view.
11. In the properties view, click on "+" sign for "Type:" field. In the filter ("**") specify String, select "<Primitive Type> String" from matching items.
12. Click Ok. Save the model. This will save .di file, and create a corresponding .uml file that can be used as source of M2T transform. The contents of this .uml file are pasted above.
Make sure to use this model file as MODEL in generateJavaTarget.xml file (or as source in case you use Stand alone launcher).

I am using Papyrus 0.7.3 (0.7.3.v201104270854) on Eclipse Helios SR2.

Thanks
Anil
  • Attachment: model.uml
    (Size: 0.83KB, Downloaded 333 times)
Re: [Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types [message #676623 is a reply to message #675722] Sun, 05 June 2011 18:24 Go to previous message
Anil Bhatia is currently offline Anil BhatiaFriend
Messages: 23
Registered: February 2011
Junior Member
In the following message:
http://www.eclipse.org/forums/index.php/mv/msg/210095/673955/#msg_673955
its mentioned that there is a case where, in addition to generating files, following error message is shown
"The generation fail to generate any file because there are no model elements that matches at least the type of the first parameter of one of your main templates.
The problem may be caused by a problem with the registration of your metamodel, please see the method named "registerPackages" in the Java launcher of your generator."


Does the scenario I mention happens to be part of this category..?

Thanks
Anil
Previous Topic:[Xpand2]Loading multiple model files
Next Topic:[xtend2][ecore] Can I generate from ecore models using Xtend2?
Goto Forum:
  


Current Time: Thu Apr 18 23:09:22 GMT 2024

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

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

Back to the top