Wednesday, May 14, 2014

Where did your Java architecture go?

Where did your Java architecture go?. Classycle might have good answers for you. It is easier to configure than jdepend which was the de facto open source cycle analyzer before and which you might still want to check out.

Here is how to analyze the spring core jar for example. Even though the below uses plain command line, an eclipse and maven plugins are available at the moment so you might want to check those out. Specially you should build ddf files to enforce your architectural layers and make sure the build fails if it is violated.
# Installing
$ sudo mkdir /opt/tools
$ sudo chown dev /opt/tools
$ mv ~/Downloads/Classycle1.4.1 /opt/tools
# Running the "Analyser"
$ cd /opt/tools/Classycle1.4.1
$ java -jar classycle.jar -mergeInnerClasses -xmlFile=spring-core-classycle.xml /home/dev/.m2/repository/org/springframework/spring-core/3.2.4.RELEASE/spring-core-3.2.4.RELEASE.jar
# Running the "Dependency Checker"
$ java -cp classycle.jar classycle.dependency.DependencyChecker -dependencies=@spring-core.ddf -mergeInnerClasses /home/dev/.m2/repository/org/springframework/spring-core/3.2.4.RELEASE/spring-core-3.2.4.RELEASE.jar
# Here is the sample dependency definition (ddf) file. Note that we analyze the spring-core jar file classes and packages assuming core and util packages will not depend on each other but actually they do (probably by design).
$ vi spring-core.ddf
show allResults
{package} = org.springframework
[core] = ${package}.core.*
[util] = ${package}.util.*
check sets [core] [util]
check [util] independentOf [core]
check [core] independentOf [util]
check absenceOfPackageCycles > 1 in ${package}.*
layer core = [core]
layer util = [util]
check layeringOf core util
view raw gistfile1.txt hosted with ❤ by GitHub

No comments:

Followers