Exploring the User-Defined Architecture of a System
...
While it is a more advanced maneuver, it is possible to write scripts that analyze your build configuration to generate CodeMRI UDA files. This can be used as a vaulable valuable starting point.
For example, the scripts below (for Linux) examine the Maven POM files in Axis2 v1.7.9 and generate the UDA file downloadable on this page.
...
The Maven POM adapter provides a mechanim mechanism to convert a multi-POM Maven project using a parent POM and several child POM files into a Silverthread-specific UDA file. CodeMRI® can use these UDA files to understand the component layout of a codebase.
...
Question | Commands and Output | ||||||
---|---|---|---|---|---|---|---|
What information do we have about files? |
| ||||||
What entities are in that file? |
What if I only want to get the list of classes? | ||||||
What files are owned by my component? |
| ||||||
Can I see the output as a table instead? |
| ||||||
Can I get this without the column header for scripting purposes? |
| ||||||
Can I get this as JSON? |
| ||||||
Can I save it off as a file? |
| ||||||
Can I call this from the UNIX command line? |
| ||||||
That looks great. Can I use it in a script? | Yes. You might want to do 2 things:
Let’s say you want to only see column 1, the file names in the component. You could do this from the command line
Let’s say you want to see the files in axis2-integration sorted by their LOC
Let’s say you wanted to get the total number of LOC in the axis2-integration
62922 These are simply examples that should make sense to those familiar with UNIX command line scripting. cmri commands can similarly be integrated into other languages by being called as shell commands from Python, Perl, Bash, Windows PowerShell, etc. | ||||||
What component is a file in? |
| ||||||
What components does my component depend on? |
NOTE: Some of the relationship_type fields say actual_dependency (one found in the code) while others say declared_dependency (one declared in the UDA) | ||||||
What components does my component say that it depends on? (Declared) |
| ||||||
What components does my component actually depend on? |
| ||||||
What files are involved in relationships between two components? |
| ||||||
What entities within those files have relationships that cross the component boundaries? |
| ||||||
What components depend on my component? | axis2-kernel is a utility used by many others so this should yield a lot:
axis2-integration is at the top of the architecture, so should not yield much:
In fact… note that this is an error in either your code or your UDA. This connection should not exist or should be defined. Note this for the future | ||||||
What architectural integrity problems exist? (differences between UDA and coded reality) | In this example, we are going to introduce ‘query chaining’ - using output from one command as inputs into the next. See the cmri API documentation for details.
As you can see, code inside axis2-kernel depends on axis2-integration, even though it should not. Now let’s look at the files that are implicated:
Let’s go one step deeper to look at entity relationships and find the exact line of code where problems exist:
| ||||||
What components depend on my component indirectly? |
come back to this | ||||||
What files depend on my component? |
| ||||||
What entities depend on my component? |
Note above that the listing includes entity-relationships between things inside axis2-kernel as well as those coming in from outside. In the current expression language, there isn’t a great way to ask for incoming entity relationships that only span the boundary. (Perhaps this will be fixed in the future). For now, let’s try to do it using a combination of shell programming and cmri commands.
The headers contained will be: from_entity, to_entity, from_file, to_file, ref_line, ref_col, from_component, to_component, relationship_type, relationship_state, severity Now we want to get the listing of entities that depend on axis2-kernel, but exclude the ones where ‘from-component’ is also axis2-kernel. Note that ‘from_component’ is field 7
| ||||||
What files depend on my component directly or indirectly? |
come back to this |
There are many more things you can do with the cmri command line and the query interface. See the ‘Silverthread CodeMRI CLI Reference’ document to explore further. You should now have enough to get started.