Book a Demo

Author Topic: keeping code and model in sync  (Read 5336 times)

yonatan.lehman

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
keeping code and model in sync
« on: January 21, 2022, 02:00:22 am »
Hi
I have a large code base of C files organized as a tree and managed using Git. I am documenting this code in EA 14, EA is managed using SVN.
My model includes
- Components (1 to 1 with the X.[ch] pair)
- Activities  associated with the Component (1 to 1 for each function)
- Sequence Diagrams and Activity diagrams to show the flow

I'm looking for a way to know that the model needs up dating e.g.
1) A .c/.h file has been added/remove - need to add/remove a component in the model
2) A .c/.h file has been change s- need to check what has changed and update the component and diagrams

Bottom line - we don't/can't generate the code from the model - so how do we keep the two in sync?
Thanks


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: keeping code and model in sync
« Reply #1 on: January 21, 2022, 03:41:00 am »
I would suggest: manually. I once used RR with code gen. They put in lots of tags in the generated code. That worked in terms of keeping the synch but made the code hard to reads. From my experience there is no useful tool to automatically synch code and model. The model should be used to stay abstract and you need some interface to feed the coders / update the model from coders deviations.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: keeping code and model in sync
« Reply #2 on: January 21, 2022, 04:46:29 am »
I would probably write a script to compare your code to your model, and make the appropriate changes.

Should not be that complicated I think, but it will probably require you parse the code.

A "standard" alternative might be to define your own grammer https://sparxsystems.com/enterprise_architect_user_guide/15.2/model_domains/grammar_editor_for_imported_co.html
In theory that grammar could be used to reverse engineer the code to a model.
I've never used it myself, but it looks very complicated and not as flexible as doing the same using a script.

Geert

yonatan.lehman

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Re: keeping code and model in sync
« Reply #3 on: January 21, 2022, 05:08:00 am »
I was thinking of writing something here is what i know what to and what i dont.
1) when i finalize a component i store somewhere in the model the git commit id an date.
2) the ea package/ component hierarchy is identical to the c file directory file hierarchy
3) I can use git and shell tools to create a list of all files with their current commit and commit date.
4) I extract from ea the packade/component hierarchy with the git id and date in the same format as step 3
5) Good old diff....and im good.
My problem is step 4) what ttols does ea have that allows me to search the model for some crieria and output specific data. Also is there an existing field in the model that i can use to store the git info that is eady to extract?
Thanks


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: keeping code and model in sync
« Reply #4 on: January 21, 2022, 05:21:15 am »
EA has an API you can use to automate stuff.

You can use that API from inside EA using the built-in scripting module, or create an add-in using C# (or some other .Net language)
Or you can write an external script/program to connect to EA an use the API.

See https://sparxsystems.com/enterprise_architect_user_guide/15.2/automation/automation_interface.html

With regards to extracting the packages and components: the EA model is stored in a database. You can use an SQL query in the method Repository.SQLQuery to get extract data.

With regards to the git commit, you can either use one of the existing field you don't use (e.g. keywords) or add a dedicated tagged value to your components or packages
I would probably opt for the tagged values.

Some more helpful links:

https://bellekens.com/writing-ea-add-ins/
https://bellekens.com/2011/01/14/harvesting-the-power-of-eas-sql-searches/
https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library
https://leanpub.com/InsideEA
https://leanpub.com/ScriptingEA

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: keeping code and model in sync
« Reply #5 on: January 21, 2022, 07:08:48 am »
Although Geert referenced my books (set aside they will ge helpful anyway) I emphaisze that you're running after shadows. You will soon enough recognize that the effort in spending synching of code is wasted. Either your modellers are ahead of the coders or vice versa. Get them to talk to each other using the model. Let code be code and model be model. Synching is futile.

Go ahead if you still want. You have been warned ;-)

q.

yonatan.lehman

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Re: keeping code and model in sync
« Reply #6 on: January 25, 2022, 02:41:24 am »
Thanks for the answers.
I'm not a great believer in code gen either - but since we are a large organization with lots of developers, and since I'm better at programming than getting people to talk to each other my solution is the minimum needed to detect that the a component (.c file) has been changed since its diagram was drawn. If I can find a set of diagrams that are potentially "out of date" and then start seeing what has changed that's already a step forward relative to having no information.