views:

778

answers:

1

I want the eclipse Java Compiler Warnings available as an ant task (ie without eclipse) - ideally as ant plugins - but I want the cruise control ant task to fail if an eclipse warning shows up. For the following warnings

  • Non-static access to static member

  • Method with a constructor name

  • Serializable class without serialVersionUID

  • Assignment has no effect

  • finally does not complete normally

  • Using a char array in string concatenation

  • Hidden catch block

  • Inexact type match for vararg arguments

  • Null pointer access

  • Type parameter hides another type

  • Method does not override package visible method

  • Interface method conflicts with protected 'Object' method

  • Local variable is never read

  • unused local or private member

  • Unchecked generic type operation

  • Usage of a raw type

  • Generic type parameter declared with a final type bound

  • Annotation is used as a super interface

I assume this means that the eclipse abstract syntax tree would have to be used - and an eclipse compilation unit would have to be created.

The question is: (1) Has this been done? (2) If it hasn't - then given a

org.eclipse.jdt.core.dom.CompilationUnit

object - how do you (ie in code examples) get the warnings out of this CompilationUnit?

(I KNOW about PMD, checkstyle etc - none of these EXACTLY match the eclipse preferences for coding style. I want an ant task that exactly matches the eclipse coding style)

+3  A: 

What version of eclipse?

It is possible to launch the JDT compiler via ant. See:

http://help.eclipse.org/ganymede/topic/org.eclipse.jdt.doc.isv/guide/jdt_api_compile.htm

See 'Using the ant javac adapter'

Warnings and errors are attached to resources (such as files or CompilationUnits) in the Eclipse workspace. They are known as 'markers'. It may be easier to get the warnings as markers rather than via the compilation process directly.

Another avenue to look into is launching a PDE build but I think this is overkill for your requirements and such build scripts can get very difficult to maintain with time.

Dan Gravell