Thilo
Thilo

Reputation: 262484

Java build process that prevents references to forbidden classes

I have to adhere to coding guidelines that prevent using some JDK classes and methods. I'd like to have a plugin for Ant or Eclipse that I can run to check if my code is compliant. I would be supplying it with a blacklist (or maybe a whitelist).

Upvotes: 0

Views: 237

Answers (4)

questzen
questzen

Reputation: 3287

In addition to the above answers, there is another alternative for achieving this. Define a custom SecurityManager. See checkPackageAccess() for more details.

Upvotes: 0

Wim Deblauwe
Wim Deblauwe

Reputation: 26858

A bit more involved is using AspectJ, but there are a lot of 'rules' you can program into that. See this blog post of mine for an example on how to use AspectJ for a very custom coding guideline rule enforcement.

Upvotes: 1

Swaranga Sarma
Swaranga Sarma

Reputation: 13413

Try CheckStyle. It has a plethora of options that you can enforce on developers.

Upvotes: 2

Heiko Rupp
Heiko Rupp

Reputation: 30934

PMD could do that. I am not sure it out-of-the box, but implementing such a rule is not too hard to do. The import-rules could be a start. PMD plugins exist for Eclipse, ant and other IDEs and build tools.

Upvotes: 0

Related Questions