Architecture Rules

Download 2.1.1

About

Assert Your Architecture! with this open source java library. Architecture Rules leverages an xml configuration file and optional programmatic configuration to assert your code's architecture via unit tests or ant tasks. This test is able to assert that specific packages do not depend on others and is able to check for and report on cyclic dependencies among your project's packages and classes. This project wraps a industry accepted JDepend to simplify the process of maintaining a solid software architecture.

License

Licensed under Apache License 2.0 - allows use of the source code for the development of free and open source software as well as proprietary and closed source software.

Do you Assert your Architecture? Please help out with our fund raising.
Checkout what we are raising funds for. Be sure to report issues.

Exceptions

This page documents the many Exceptions that the Architecture Rules library may through throughout the course of building the configuration, and executing the rules and cyclic dependency testing. All of these exceptions are RuntimeExceptions unless otherwise stated.

CyclicRedundencyException

If the cyclic redundancy test is run (via setting <cyclicalDependency test=”true”/>) and any cyclic redundancies are found, this exception is thrown.

When any cyclic dependencies are encountered, this exception is thrown. The exception message will report all packages that are involved in cyclic dependencies.

An example message looks like:


...architecturerules.exceptions.CyclicRedundancyException:
cyclic dependencies found:

-- test.com.seventytwomiles.services
|  |
|  |-- test.com.seventytwomiles.model
|  |
|  |-- test.com.seventytwomiles.dao.hibernate
|
|
-- test.com.seventytwomiles.model
|  |
|  |-- test.com.seventytwomiles.services
|
|
-- test.com.seventytwomiles.dao.hibernate
|
|-- test.com.seventytwomiles.services

DependencyConstraintException

When any defined violation occurs, this exception is thrown. The message will tell you which package was violated, who who the violating package was.

The message (as of the time of this writing) looks like:


dependency constraint failed in 'dao' rule which constrains
packages 'com.seventytwomiles.dao'

IllegalArchitectureRuleException

IllegalArchitectureRuleException is thrown when a rule defines a violation in the package that it describes.

For example:


<rule id="dao">
 <comment>
  dao layer depends on no other layers
 </comment>
 <packages>
  <package>com.company.app.core.dao</package>
  <package>com.company.app.core.dao.hibernate</package>
 </packages>
 <violations>
  <violation>com.company.app.core.dao</violation>
 </violations>
</rule>

Would throw this exception because JDepend can not test that the dao package does not depend on the dao package. An exception is thrown telling you to remove this violation. The violation could be ignored by the tests, but it is not. Users should understand that this can not be tested and remove this violation.

SourceNotFoundException

When a source is defined and the not-found property is set to exception this SourceNotFoundException will be thrown if the source directory does not exist or can not be found.


<source>core/target/classes</source>

If you are getting this exception and don’t want it because you understand that your entire project was not built and so a given source may not exit all the time, then use this configuration:


<source not-found="ignore">...</source>

The default not-found value is exception.

NoPackagesFoundException


<source not-found="exception">...</source>

Once all of the defined source elements have been loaded, if no classes are found the NoPackagesFoundException is thrown. When no packages are found, no tests are run, which can be deceiving when everything comes back looking okay.

To disable this exception (which is not recommended) set:


<sources no-packages="ignore">  

The default value for no-packages is exception

1 Comment »

  1. Posted by Architecture Rules 102 | 72 Miles

    June 5, 2008 @ 8:52 am

    [...] defined source directories, if no classes are found, then throw an Exception, more specifically, a NoPackagesFoundException. Here are the configuration options for [...]

RSS feed for comments on this post · TrackBack URI

Leave a Comment

Start Here

Get Help

More Information

Architecture Propaganda

Schwag

If you assert your architecture, then let everyone know with this branded gear. architecture rules mug