Mostrando entradas con la etiqueta Formatter. Mostrar todas las entradas
Mostrando entradas con la etiqueta Formatter. Mostrar todas las entradas

lunes, 3 de enero de 2011

Every programmer working as only one.

Content:
CheckStyle Eclipse plugin. Installation
Tunning your CheckStyle and Formatter
Every programmer working as only one
What if... I get a "Fileset from project [projectname] has no valid check configuration" Error?
CheckStyle configuration distribution


You had paid a huge amount of money to have your house built within three months, and you got it. It has roof, kitchen and perfect thermal isolation.

You had asked for the nice brick facade in the picture but... what the f*cking hell, every damn square meter of the wall has its own colour! All right, all right,it is a house, it will keep me safe and healthy; but, for Christ's sake, there are twenty shades of "red" and it is horrible! It is a sort of Scottish skirt for a colour-blind person, weird and not exactly homogeneous.

The upset owner of this house spent all the following afternoon seeking for an answer, and he could merely complain because every labourer said more or less the same: they did their square meter as perfect as they could, but they had their own style and they will not ever work exactly as the folk to the left (and, as it is impossible, they assumed they could do whatever they liked instead), so it is pretty much the sign of the artist.


Picasso 1)
if(){
sencence;
}


picasso B)
if()
{
sencence;
}


Picasso the third)
if() sencence;


Picasso delta)
if()
    sencence;


So here you are, your house is not your home, and twenty Picassos are happily being transported to their next crime.

We have to do something...


Our imaginary brand new IT department had SpringSource, did some work with Maven, but it is high time to moderate the creativity of the guys. So review how to set up and customize CheckStyle, and let's export it to the team.

The manual way, fair enough for today, is to export both files (CheckStyle and Formatter) and send them out via mail or shared folder. My "q" is not a capital letter this evening.

Export your CheckStyle configuration:
Window menu -> preferences -> CheckStyle -> Select your configuration and click Export. Select the desired target folder and new file name.

Export your Java Formatter configuration:
Window menu -> preferences -> Java -> Code Style -> Formatter -> Select your configuration -> Edit -> Export. Select the desired target folder and new file name.


Now you have your red brick, the same red for every brick. Every artist could still put the bricks in the wrong way, but the colour of the wall would be
uniform anyway. Fire that labour if he did so as a revenge and keep working meanwhile.

Every developer in the team must now import both xml files, in the reverse most simple way.

Import your CheckStyle configuration: (Yes, I have just copy/pasted myself)
Window menu -> preferences -> CheckStyle -> type: External Configuration File, location: path+filename, name: the same name for everyone, whatever -> Ok and... Set as Default.

Import your Java Formatter configuration: (Ups, I did it again... )
Window menu -> preferences -> Java -> Code Style -> Formatter -> Import -> Select your file and it is done. Just select the new profile as the active one.


To activate CheckStyle and use Formatter, please check previous posts. Congratulations, you can truly start enjoying teamwork.

Damn artists...

pd: Thanks Javier del Palacio for your corrections. I owe you a "worker of the month". :)

martes, 28 de diciembre de 2010

Tunning your Checkstyle and Formatter

Content:
CheckStyle Eclipse plugin. Installation
Tunning your CheckStyle and Formatter
Every programmer working as only one
What if... I get a "Fileset from project [projectname] has no valid check configuration" Error?
CheckStyle configuration distribution

In the previous post, we installed Checkstyle and tested it a bit, a little proof-of-concept, useful for your little project at home, it doesn't cares anybody, and the world could survive without it perfectly.

Now focus on your company, it is unforgivable that every mate format their code as Sant Peter tells them. You implanted CheckStyle code in your I.T. dept. and it looks like better, but Sun style (default one for Formatter and CheckStyle) doesn't fit your interests.

One example. Your monitor is 1280 pixels wide, but Formatter defaults to 80 columns of text, and you find it miserable for your hardware, that supports much more, at least 120 columns.

Let's build this example, a comment of 143 columns length.



As soon as you invoke Formatter (Ctrl+Shift+F or Menu Source->Format), the result is next:


The comment line was broken at column 79, but I spent a large amount of money in a extreme-wide monitor and I find that length ridiculous. I better change this parameter.

Check your configuration in  Window menu -> Preferences -> Java -> Code Style -> Formatter. The best you can do in this point is create your own profile, based on an existent one. 

I chose New ... and type anavarro_prof, based on "Java Convention [built-in]"


Then, edit your new profile, as a sample, we will change line width...


 and comment width...



Once both parameters are changed, let's suppose your project is using the IDE default formatter, so, your formatter, that have been chosen as default one after its creation.

Return to your code, re-format it! it works! it has been formatted to 120 lines width.




Did it work? not completely... see that magnifying glass that appeared at the left side of your comment...




Line is longer than 80 characters?. What's up?
This is happening because your Formatter is not directly connected with your CheckStyle plugin, so you will have to transmit your Formatter changes into your CheckStyle configuration.


Open Window Menu -> Preferences -> CheckStyle. 

You should find the two built-in configurations, but you want to configure your own. 





So firstly select one of them, click "Copy" to create a configuration based on an already created one.



And change some parameters, as the type, make it external, change that ugly name and select a location where the new configuration will be created. I lend you an example:




Then, clicking "OK", your new configuration will be created and you can both "Set as Default" and "Configure". Yes, please, "Configure" it.


Search for "Maximum Line Length", and EDIT existent "Maximum Line Length" in the window on the right. Beware don't add an additional property already existent, because you won't get the desired goal.


Then change its maximum length doubleclicking it:




Save, Ok, Rebuild, do whatever neccesary to get your code window again, magnifying glass should dessapear after recompiling. Mine does! You have also got an external CheckStyle configurer as a xml file where you asked to. This file will be transferred to your mates in next chapter.


Quite a long article, you should have learned to customize your Formatter and make your CheckStyle configuration being Formatter-compliant. You can now impose both configurations to your entire team, in the next article, promise.


Have a happy New Year's Eve!!!