[Acceleo] Ref: Bug 319375 - Using ant task with model referring to UML Primitive types [message #672348] |
Fri, 20 May 2011 18:56 |
Anil Bhatia 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 #673306 is a reply to message #673301] |
Mon, 23 May 2011 07:57 |
Anil Bhatia 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 #674348 is a reply to message #673944] |
Thu, 26 May 2011 15:22 |
Anil Bhatia 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 #675722 is a reply to message #675145] |
Wed, 01 June 2011 09:50 |
Anil Bhatia 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 346 times)
|
|
|
|
Powered by
FUDForum. Page generated in 0.03794 seconds