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.

Execution Options

There are various ways to Assert your Architecture! with Architecture Rules.

  1. Ant-Task
  2. Ant Unit Test
  3. Maven 2
  4. Maven 1

Ant-Task

If you are not a Maven user, this Ant task is the the preferred means for asserting your architecture. The downside to this method of running the test, is that there is no means for you to provide any programmatic configuration - the entire configuration must be read from the configuration file. If you must use Ant, and you must provide programmatic configuration, you will need to see the next option, Ant Unit Test.

To use the Ant task, you must define the task with the taskdef directive, and then create a target to call assertArchitecture, and provide a name of the XML configuration file which you have placed in the project’s classpath.

To run with ant, you must include your own compile goal. This configuration below includes depends=”compile” within the test-architecture goal, so you need to implement that goal, or change the depends to your own goal, whatever you may have called your compile goal.

Also, you will need to point to all of the libs. If you’re an ant user, you probably have a /libs directory that you can point to.

For an up-to-date list of dependencies, see the dependencies list.


<property name="maven.repo" value="C:\dev\m2repo\"/>

  <path id="class.path">
    <pathelement id="test" path=".\target\test-classes"/>
    <pathelement id="main" path=".\target\classes"/>

<!-- updated list of dependencies available at -->
<!-- http://72miles.com/architecturerules/dependencies  -->

   <pathelement id="junit"
   path="${maven.repo}\junit\junit\3.8.1\junit-3.8.1.jar"/> 

<!-- You must define all dependencies listed at  -->
<!-- http://72miles.com/architecturerules/dependencies  -->
<!-- as a pathelement such as the junit-3.8.1.jar above  -->

  </path>

  <!-- you must define your own compile -->
  <target name="compile"/>

  <taskdef name="assertArchitecture"
      configurationFileName
      classname="com.seventytwomiles.architecturerules.ant.AssertArchitectureTask">
      <classpath refid="class.path"/>
   </taskdef>

   <target name="assert-architecture" depends="compile">
      <assertArchitecture
        configurationFileName="architecture-rules.xml" />
   </target>

Ant Unit Test

To run with ant, you must include your own compile goal. This configuration below includes depends=”compile” within the test-architecture goal, so you need to implement that goal, or change the depends to your own goal, whatever you may have called your compile goal.

Also, you will need to point to all of the libs. If you’re an ant user, you probably have a /libs directory that you can point to.

For an up-to-date list of dependencies, see the dependencies list.


  <property name="maven.repo" value="C:\dev\m2repo\"/>

  <path id="class.path">
    <pathelement id="test" path=".\target\test-classes"/>
    <pathelement id="main" path=".\target\classes"/>

<!-- updated list of dependencies available at -->
<!-- http://72miles.com/architecturerules/dependencies  -->

   <pathelement id="junit"
   path="${maven.repo}\junit\junit\3.8.1\junit-3.8.1.jar"/> 

<!-- You must define all dependencies listed at  -->
<!-- http://72miles.com/architecturerules/dependencies  -->
<!-- as a pathelement such as the junit-3.8.1.jar above  -->

  </path>

  <!-- you must define your own compile -->
  <target name="compile"/>

  <target name="test-architecture" depends="compile">
    <junit haltonerror="true">
      <classpath refid="class.path"/>
      <formatter type="brief" usefile="false"/>
      <test name="com.seventytwomiles.architecturerules.ArchitectureTest"
        haltonfailure="true"/>
    </junit>
  </target>

Maven 2

With Maven 2, you can run all your tests or, a single test.

To run a single test, define the variable test as the name of the test class that you wish to execute.

%> mvn -Dtest=ArchitectureTest test

To run all of your tests, enter

%> mvn test

Maven 1

With Maven 1, you can run all your tests or, a single test.

To run a single test, define the variable testcase as the name of the test class that you wish to execute.

%> maven -Dtestcase=ArchitectureTest test:single

To run all of your tests, enter

%> maven test:test

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