Validate against an Eclipse formatting profile from command line
I'm looking for a way to verify Java code against an Eclipse code formatting profile from the command line. The goal is to create a Mercurial hook which rejects any commit that doesn't match the profile. Is there a way to do this?
I'm aware of the possibility to call Eclipse's formatter from the command line. What I'm looking for is something which just validates (yes/no). I guess I could use the formatter and then compare the two, but it seems like a clumsy approach.
Background: The reason we want to try this is because we currently get many unnecessary merge conflicts because of formatting differences. We have an environment where multiple IDE:s are used, although only one is officially suppo开发者_如何学Crted. We want to enforce the official profile, and everyone can continue using the tools they prefer as long as they set it up to format the code correctly.
In brief, follow those steps:
- Duplicate the original Java file in a temporary place ;
- Format the temporary duplicate using the Eclipse Java code formatter ;
- Check whether the files are identical or not.
Tricks to help you out:
- To call the Eclipse Java code formatter from command line, see Formatting your code using the Eclipse code formatter.
- To know whether files are identical, using the
diff
utility:diff --text --quiet >/dev/null
, the error code will tell you what you're seeking for.
精彩评论