This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes Looking for a Maven Plugin Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Looking for a Maven Plugin" Watch "Looking for a Maven Plugin" New topic
Author

Looking for a Maven Plugin

Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
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.


http://www.goodercode.com
SCJP 1.4
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
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

Joined: Jun 25, 2001
Posts: 15959
    
  19

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

Joined: Oct 29, 2003
Posts: 254
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

Joined: Nov 27, 2006
Posts: 423

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

Joined: Oct 29, 2003
Posts: 254
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

Joined: Nov 20, 2003
Posts: 194
Did you already have a look at checkstyle?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looking for a Maven Plugin
 
Similar Threads
Maven Error - Unable to find repo
maven -- java.lang.OutOfMemoryError: Java heap space
Unable to find mojo 'validate'
Download Maven plugin
Eclipse - JSF - Spring tool suite - Hibernate