Bug 529044 - UML2 Genmodel : provide a "Operations directory" option
Summary: UML2 Genmodel : provide a "Operations directory" option
Status: CLOSED FIXED
Alias: None
Product: MDT.UML2
Classification: Modeling
Component: Core (show other bugs)
Version: 5.3.0   Edit
Hardware: PC Windows 7
: P2 enhancement (vote)
Target Milestone: 5.4.0   Edit
Assignee: Kenn Hussey CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2017-12-20 19:42 EST by Sebastien Revol CLA
Modified: 2018-06-28 11:38 EDT (History)
1 user (show)

See Also:
Kenn.Hussey: iplog+


Attachments
Patch proposal for operation folder selection in UML2 genmodel (12.68 KB, application/octet-stream)
2018-01-05 05:44 EST, Sebastien Revol CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastien Revol CLA 2017-12-20 19:42:10 EST
Hi, 
it's a common practice to distinguish fully generated code from user code with different source folders.

Operations package is a kind of mixed generated/user code since the generated skeletons always have to be completed with user code. 

Do you think you could provide a new option similar to the "Model/Model Directory" option allowing to generate the Operations package in a separate source folder?

Best regards,

Sebastien
Comment 1 Kenn Hussey CLA 2017-12-21 14:01:25 EST
That sounds like an interesting enhancement; contributions are most welcome!
Comment 2 Sebastien Revol CLA 2018-01-05 05:44:02 EST
Created attachment 272142 [details]
Patch proposal for operation folder selection in UML2 genmodel
Comment 3 Sebastien Revol CLA 2018-01-05 06:08:30 EST
(In reply to Sebastien Revol from comment #2)
> Created attachment 272142 [details]
> Patch proposal for operation folder selection in UML2 genmodel

Hi Kenn, here is a patch proposal. (Are you using gerrit?)

Basically, I updated UML2 GenModel.ecore to add a "operationsFolder" feature to the GenModel EClass.  I also added this feature in the "UML2" category in GenModel.genmodel. (Sorry I directly modified the ecore model since I don't have Rose).

I chose to call the new attribute "operations*Folder*" to limit confusion with the "directory" attributes we have for model/edit/editor. 
Indeed, unlike the directory attributes, this operationFolder path should be relative the first segment of the "modelDirectory" value, since the code will be always generated in the model project. (Supporting the capability to define a new operation plugin looked much more complex to implement).

Then the feature is implemented in three main steps :

-I modified UML2GenClassGeneratorAdapter.java to call a new org.eclipse.uml2.codegen.ecore.genmodel.util.UML2GenModelUtil.getOperationsFolderPath(GenModel) to generate the Operations class in the correct folder

-I defined a GenModelGeneratorAdapter.java class to override EMF default adapter, just adding the new operation folder ClassPathEntry in the java project (and updated the GenModelGeneratorAdapterFactory accordingly). I had to duplicate a little piece of code from EMF to compare ClassPathEntries in a custom UniqueEList implementation.

-I overrode org.eclipse.uml2.codegen.ecore.genmodel.impl.GenModelImpl.getModelSourceFolders() in order to add the operationsFolder. This method is used by the Build.properties generator. 


I tested the patch on the master branch with Photon M4. 
I noticed some generated code differences (even using the UML2 code formatter). 
Hence, tried to put in the patch only my modifications : to test it, you should apply it first and then regenerate the code. 

I hope you will find it ok.

Best regards,

Seb
Comment 4 Kenn Hussey CLA 2018-01-08 10:05:06 EST
(In reply to comment #3)
> (In reply to Sebastien Revol from comment #2)
> > Created attachment 272142 [details]
> > Patch proposal for operation folder selection in UML2 genmodel
> 
> Hi Kenn, here is a patch proposal. (Are you using gerrit?)

Thanks for the contribution, Sebastien! I'll take a look as soon as possible and get back to you with any feedback I have.

Gerrit hasn't been set up for the UML2 project (yet), but I've just submitted a request to do so (see Bug 529533).
Comment 5 Kenn Hussey CLA 2018-01-09 11:35:57 EST
(In reply to comment #3)
> Basically, I updated UML2 GenModel.ecore to add a "operationsFolder" feature to
> the GenModel EClass.  I also added this feature in the "UML2" category in
> GenModel.genmodel. (Sorry I directly modified the ecore model since I don't have
> Rose).

No worries, we stopped using the Rose model as the source of truth for the model years ago. ;)

> I noticed some generated code differences (even using the UML2 code formatter).

I regenerated the code based on latest EMF changes (and updated the UML2 code formatter profile while I was at it) to provide a new baseline that will help highlight which changes are related to this contribution.

> Hence, tried to put in the patch only my modifications : to test it, you should
> apply it first and then regenerate the code.
> 
> I hope you will find it ok.

I've applied your changes against the new baseline (see above) and regenerated the code. So far, everything looks really good! I'll spend some time testing it and then commit/push the changes.
Comment 6 Sebastien Revol CLA 2018-01-09 11:45:46 EST
(In reply to Kenn Hussey from comment #5)

> I've applied your changes against the new baseline (see above) and
> regenerated the code. So far, everything looks really good! I'll spend some
> time testing it and then commit/push the changes.

Great, thanks!
Alternatively, if you want, I can also re-push the patch on gerrit now that it's available. 
It would probably require to commit first your generated code and formatter updates before, but no pb for me.

Seb
Comment 7 Kenn Hussey CLA 2018-01-09 16:22:56 EST
I committed/pushed the changes to the 'master' branch in git.

I ended up refactoring the contribution a little bit for consistency, string safety, and completeness (which included adding a description for the new generator model property and ensuring the operations folder is added as a source folder in cases where the edit and editor plugins are the same as the model).

Thanks again!
Comment 8 Sebastien Revol CLA 2018-01-11 04:00:01 EST
(In reply to Kenn Hussey from comment #7)
> I committed/pushed the changes to the 'master' branch in git.
> 
> I ended up refactoring the contribution a little bit for consistency, string
> safety, and completeness (which included adding a description for the new
> generator model property and ensuring the operations folder is added as a
> source folder in cases where the edit and editor plugins are the same as the
> model).
> 
> Thanks again!

Perfect, I'm happy it was useful!
Comment 9 Kenn Hussey CLA 2018-01-11 15:24:30 EST
The changes are now available in a UML2 5.4.0 integration build.
Comment 10 Kenn Hussey CLA 2018-06-28 11:38:59 EDT
The changes are available in UML2 5.4.0 (as part of the simultaneous Eclipse Photon release).