0

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).

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

+1. Their IllegalImport module seems to fit the bill, at least on the per-class level.
1

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.

3 Comments

I agree, AspectJ is absolutely the way to go (+1)
Can I use this approach to forbid references to say java.util.Hashtable (a class whose source I cannot annotate)?
Sure, using the call pointcut.
0

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.

Comments

0

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

2 Comments

That would be at runtime, right? I need a compile-time check.
You are right, SecurityManager needs to be set for checking the permissions. Until java allows classes to be compiled at runtime (I read about this being incorporated into JDK 7, not sure where), this is going to be an Achilles heel. However, the ability to enforce policies on code which you can not see (third party code) is a big thing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.