Batch Code Formatting using Eclipse Code Formatter, but without Eclipse.
I have been trying to find a decent code formatting solution for a project I am doing with NetBeans. I tried Jalopy, but it could not match the power of the Code Formatte within Eclipse. I then found that some helpful chappy had made it possible to do Batch Code Formatting using Eclipse from the command line. This would not do for what I wanted to do, so I looked at the source code and found that with some tweaking I could run this without having the Eclipse executable, only the core JARs. After that discovery I thought this would be a nice Ant Task and so I made a fairly simple one, which works for what I want to do.
You can download the code and JAR from http://www.darkedges.com/java/ant/JavaCodeFormatter.zip and use it in your Ant build file as follows.
<taskdef name="jcf" classname="com.darkedges.ant.JavaCodeFormatterTask" classpathref="jcf.class.path" />
<jcf config="config/config.xml" verbose="true">
<fileset dir="src" includes="**/*.java" />
</jcf>
You can enable verbose and quiet mode by setting verbose="true" or quiet="true".
Now I am not a great Ant Task writer, so please be gentle on my code, and I had to change 2 lines of code as I couldnot figure out how to initialise the Platform Object, so perhaps a bright spark can take what I have done and make it better.
One thing I would like to see is the Code Formatter only saving changes if there has been some code format changes, as otherwise Ant will recompile your code base again. Oh and there is also a Command Line version there too, I am just too busy to document this all at present