开发者

Validate against an Eclipse formatting profile from command line

开发者 https://www.devze.com 2023-04-10 01:29 出处:网络
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 pro

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:

  1. Duplicate the original Java file in a temporary place ;
  2. Format the temporary duplicate using the Eclipse Java code formatter ;
  3. 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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号