Fast format-source (for Liferay developers and contributors)

A lot of effort is put into keeping Liferay huge source base formatted consistently, what is very important. There is an advance source formatter (ant format-source) that outputs formatting problems and even corrects some for you. However, since the code base is huge, this task may take several minutes to finishes. Another minor issue is that all sources is scanned, so if someone commit badly formatted source, you will get his formatting problems; his files might be modified and therefore become a part of your changelist.

Some time ago, Zsolt Balogh gave me a great idea: instead of scanning the whole source base, lets just scan the modified files. So that's exactly what I did - and the whole formatting process now takes only few seconds to complete:) Here is my implementation of this idea.

(1) IntelliJ IDEA and plugin Changelist Action.

I've made a little IntelliJ plugin that creates a temp file with list of modified files and then executes user-defined external command, passing the temp file name as an argument.

(2) srcfmt program

A little program that:

  • reads temp file (provided by plugin)
  • copies modified files to some folder
  • invokes liferays source formatting tool on that folder
  • deletes copied files (and move back if modified)

So, formatting will look only on the changeset  files. Here is the current version of this tool (without the jars, use them from portal). Take a look into the .bat for more info. Please note that this is just the first version,so it will change in the future - but the concept stays the same.

(3) And finally...  invocation.

Go to Changes tool window, select the 'Local' tab and invoke the plugin by clicking the icon.

The result appears after few seconds (or less) in a new tool window, as in example below:

I already see some places for improvement and will probably enhance the plugin and the tool in my free time (in my what?:), but, like i've said, the core concept is here and it works.