Production Eclipse Configuration

Part of the game of getting code out that conforms to coding standards without having to go through the “One Big spring cleaning” exercise is configuring and centralizing the tools.

At a minimum, it helps to have a central Eclipse installation that has all the tools configured and setup – so each person doesn’t have to do it. Alternatively, there should be a reference set of plugins and their configuration files available in the source control repository.  Here’s my eclipse configuration

Checkstyle:

Checkstyle really needs tweaking so that it doesn’t overwhelm. Install the checkstyle eclipse plugin from here
To import a custom rule set

  1. Window->Preferences->Checkstyle
  2. Click ‘New…’
  3. Type: External Configuration file and Browse to the ruleset file.

Here’s my ruleset (subversion link) – its essentially a tweaked Sun java coding conventions with more the rules we care about.
Eclipse Formatter:

Checkstyle will point out ickiness in your code – what a mighty pain in the backside it would be to fix them on your own :). Jalopy used to do a pretty good job of rule based pretty printing. Now Eclipse 3.2 does this well too. Just go ahead and import the formatter rules

  1. Window->Preferences->Java->Code-Style->Formatter
  2. Import

Here’s my formatting rules (subversion link) – should fix most of the warnings given by checkstyle.

Give it a spin – Hit Ctrl-Shift-F on a java file and see those nasty little yellow markers go!!!

AnyEdit tools plugin:

The eclipse formatter leaves out one important rule – trailing whitespace at the end of lines. Try as I might, I couldn’t find a configuration for this.

Eventually its AnyEdit plugin to the rescue – download. It will remove trailing whitespace when the buffer is saved. This is the default setting..so after downloading the jar, putting it in your plugins folder and restarting eclipse, you can verify if you have the setting selected – Window->Preferences->General->Editors->AnyEdit Tools, Remove trailing whitespace.

Side Note: Tabs vs Spaces - and what do you do if you have a decently big codebase and need to change tabs to spaces.

What do you do if you already have a big codebase where people started out with tabs? Saving each buffer doesn't make sense - use sed. Here's a nice page full of nifty sed one liners

Problems window filter:

That almost completes all our tools setup and configuration – and this final tip is really a bit of Eclipse tweak to focus the Problems window to what is relevant to the current file.

Open the Problems view (Window->Show View->Problems). Click on the down arrow on the right of the window and click Configure Filters.

Click New to create a new filter

Select the radio button “On the selected element and its children” and Select all in the “Show Items of Type”.

Make sure that only the custom filter is selected. Now whenever you have a java file in the editor, you can see the errors below pertaining to the class.

Templates:

TODO

Subversion properties:

TODO

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s