Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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?

Code Block
system file list
system query files --name modules/adb/src/org/apache/axis2/databinding/types/xsd/Date.java

What entities are in that file?

Code Block
system query entities --file modules/adb/src/org/apache/axis2/databinding/types/xsd/Date.java

What if I only want to get the list of classes?

What files are owned by my component?

Code Block
system file list
system query files --name modules/adb/src/org/apache/axis2/databinding/types/xsd/Date.java

Can I see the output as a table instead?

Code Block
system query files --component axis2-integration --output-format csv
system query files --component axis2-integration --output-format tsv

Can I get this without the column header for scripting purposes?

Code Block
system query files --component axis2-integration --output-format tsv:noheader

Can I get this as JSON?

Code Block
system query files --component axis2-integration --output-format json

Can I save it off as a file?

Code Block
system query files --component axis2-integration --out /tmp/compfile.tsv --output-format tsv:noheader

Can I call this from the UNIX command line?

Code Block
[dan@fedora ~]$ cmri system query files --component axis2-integration --output-format tsv:noheader --selection Axis2/Axis2-1.7.9

That looks great. Can I use it in a script?

Yes.

You might want to do 2 things:

  • Get rid of colors in the output using --no-color

  • Redirect STDERR to /dev/null to get rid of the ‘thank you' message at the bottom. Because they are STDERR, not STDOUT, they should not interfere. They might be annoying however.

Let’s say you want to only see column 1, the file names in the component. You could do this from the command line

Code Block
cmri system query files --component axis2-integration --output-format tsv:noheader --selection Axis2/Axis2-1.7.9 --no-color 2>/dev/null | sed -s 's/\t.*//'

Let’s say you want to see the files in axis2-integration sorted by their LOC

Code Block
cmri system query files --component axis2-integration --output-format tsv:noheader --selection Axis2/Axis2-1.7.9 --no-color 2>/dev/null | awk -F '\t' '{print $11, $1}' | sort -n -r -k1

Let’s say you wanted to get the total number of LOC in the axis2-integration

Code Block
cmri system query files --component axis2-integration --output-format tsv:noheader --selection Axis2/Axis2-1.7.9 --no-color 2>/dev/null | awk -F '\t' '{total = total + $11}END{print total}'

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?

Code Block
system query files --name modules/integration/test/org/apache/axis2/AbstractTestCase.java

What components does my component depend on?

Code Block
system query component-relationships --from-component axis2-integration

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)

Code Block
system query component-relationships --from-component axis2-integration --relationship-type declared_dependency

What components does my component actually depend on?

Code Block
system query component-relationships --from-component axis2-integration --relationship-type actual_dependency

What files are involved in relationships between two components?

Code Block
system query file-relationships --from-component axis2-integration --to-component axis2-kernel

What entities within those files have relationships that cross the component boundaries?

Code Block
system query entity-relationships --from-component axis2-integration --to-component axis2-kernel

What components depend on my component?

axis2-kernel is a utility used by many others so this should yield a lot:

Code Block
system query component-relationships --to-component axis2-kernel

axis2-integration is at the top of the architecture, so should not yield much:

Code Block
system query component-relationships --to-component axis2-integration

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.

Code Block
system query component-relationships --severity error 

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:

Code Block
system query component-relationships --severity error 
system query file-relationships --from-component @from_component --to-component @to_component

Let’s go one step deeper to look at entity relationships and find the exact line of code where problems exist:

Code Block
system query component-relationships --severity error 
system query entity-relationships --from-component @from_component --to-component @to_component

What components depend on my component indirectly?

Code Block

come back to this

What files depend on my component?

Code Block
system query file-relationships --to-component axis2-kernel

What entities depend on my component?

Code Block
system query entity-relationships --to-component axis2-kernel

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.

Code Block
# save off the header fields into a file so you can see them
# to a temporary file
[dan@fedora ~]$ cmri system query entity-relationships --to-component axis2-kernel --output-format tsv --no-color --selection Axis2/Axis2-1.7.9 2> /dev/null | head -n 1 > /tmp/er_headers

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

Code Block
# get the list entity dependencies coming into axis2-kernel
# get rid of headers
# save to a temporary file
[dan@fedora ~]$ cmri system query entity-relationships --to-component axis2-kernel --output-format tsv:noheader --no-color --selection Axis2/Axis2-1.7.9 > /tmp/er_for_axis2-kernel

# There are many ways to skin this cat.
# The UNIX awk command is one of them.
# The following line only prints a line if field 7 is not axis2-kernel
# This might also be done in a more readable way if done in Perl, Python, etc.
awk '$7 != "axis2-kernel" { print $0 }' /tmp/er_for_axis2-kernel

What files depend on my component directly or indirectly?

Code Block

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.