• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Looking for a Maven Plugin

 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone know of a Maven plugin that will enforce design rules? I would like to be able to cause a build error when someone does things like throwing SQLException from DAO layer or when a method in Service object excepts a Hibernate specific Object.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is this comes in the realm of Design Patterns, and Design Patterns aren't overly amenable to automated anything. Otherwise there'd be extortionately-priced software suites designed to exploit that. Instead what we have is mostly DIY, although the Iterator pattern is now built into Java itself.

There are some things that can help. A product that can scan for questionable usages whose exact name escapes me (it's something like BugBuddy). I think it is supported by a Maven plugin, but it's also something that can plug into an IDE.

Likewise, some of the UML tools try to help. I know that the open-source ArgoUML tool does. But that's all interactive critiquing, not batch-mode, so it's hard to make Maven work with it.
 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I think the ideal solution would allow me to list packages that classes in a certain package cannot use. Ideally, it would have regular expression matching as well.

So I could say (in a config file) something like...



I know this would save me a bit of refactoring if these types of things were caught by developers.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That wouldn't be a very difficult app to write. (ahem) "All You Have To Do Is..."

Well, seriously. Load up the XML file using apache digester or similar. Read the classfiles in the project, looking for violations by pattern-matching the signatures of method calls. Report them.

Easily done in less than a day.

Meaning that in Real Life, I'd put aside 2-3 weeks to get it all working, especially as a mojo. But still, at the conceptual level, it's fairly simple.
 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea, that part of it would be simple enough. However, I would want the usage to be checked as well (if possible).
 
Joachim Rohde
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:
There are some things that can help. A product that can scan for questionable usages whose exact name escapes me (it's something like BugBuddy). I think it is supported by a Maven plugin, but it's also something that can plug into an IDE.

I guess you are referring to FindBugs (http://findbugs.sourceforge.net) or PMD (http://pmd.sourceforge.net/). Both tools can be extended by customized rules. But from top of my head I can't think of any rule, which would check for certain exceptions. But maybe it's a better starting point than writing a customized tool from scratch.
 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joachim Rohde wrote:I guess you are referring to FindBugs (http://findbugs.sourceforge.net) or PMD (http://pmd.sourceforge.net/). Both tools can be extended by customized rules. But from top of my head I can't think of any rule, which would check for certain exceptions. But maybe it's a better starting point than writing a customized tool from scratch.


Thanks, I'll check these out. I am not talking about just checking for exceptions though. Any package usage at all and I would want it to fail. For instance, my DAO's should not be tightly coupled with a DB, so I would not want the DAO interfaces to use (return, throw, or accept as argument) any classes in the javax.sql package.
 
Arnold Reuser
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you already have a look at checkstyle?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic