clarkware / jdepend

A Java package dependency analyzer that generates design quality metrics.
MIT License
655 stars 133 forks source link

Dependency prescription and proscription #4

Open tomvandenberge opened 11 years ago

tomvandenberge commented 11 years ago

I have made an extension to the API intended for unit testing.

The DependencyConstraint allows you to specify all expected dependencies between packages. If other dependencies than those specified are anaylized, the DependencyConstraint can tell you. This is a very useful feature, but for a larger codebase it can be a lot of work to specify all dependencies. In some situations it is sufficient to specify only the dependencies that you don't want. That's what I've added.

The DependencyConstraint defines all expected dependencies, and is therefore a prescription. Defining forbidden dependencies is a proscription. So I renamed DependencyConstraint to DependencyPrescription, and added a new DependencyProscription.

When you'd like to verify dependencies in a unit test, you can choose between the DependencyPrescription and DependencyProscription. Both classes now extend the abstract DependencyDirective, which specifies the method followsDirective() to check if the analyzed packages follow the directive (pre- or proscription).

To maintain backward compatibility, DependencyConstraint is still around, but is now only a delegate for DependencyPrescription.

I've taken the liberty of introducing generics in the codebase. I don't think this will hurt any pre-Java5 clients.

JavaDoc and unit tests are added too, obviously.

I hope you find this addition useful enough to pull it in your repository.

Thanks, Tom