views:

627

answers:

3

Hi all We have a defined a set of rules in Eclipse for code formatting and clean up. is there a way to run the code clean up using ant task ?

I know that there are tools like checkstyle but these tool have thier own configurations and rules, and I don't want to maintain 2 sets of rules.

I'm looking for an ant task that will use the same exact configuration and rules defined for eclipse code formatting / clean up

-- Thanks Yonatan

A: 

I used Jalopy as Eclipse plugin.

Take a look at his ant integration.

SourceRebels
Jalopy will certainly format the code during an ant build, but Jalopy has an entirely separate configuration to the Eclipse formatter. It is (in my experience) impossible to make the two configurations achieve exactly the same results, so you get different source depending on where it was formatted. This is a nightmare for dif tools
Rich Seller
I agree with you. But why don't use both Jalopy Eclipse Plugin and Jalopy Ant task? same rules, same formatting?
SourceRebels
Sometimes you don't have control over your code formatting configuration. In such a case, you would want to reuse the original code formatter, not a new one.
Altherac
+2  A: 

Have you considered using the Java -> Editor -> Save Actions to enable reformatting on save instead?

Thorbjørn Ravn Andersen
This is almost what I wanted (as it still part of the configuration is different from the source clean up configuration).It is a simple and straightforward solutionThanks
Yonatan Maman
You are welcome. I don't understand your statement about part of the configuration different from the source clean up configuration?
Thorbjørn Ravn Andersen
+1  A: 

This link has what you are looking for I believe: Batch Code Formatting using Eclipse Code Formatter, but without Eclipse.

laz