lunes, 31 de enero de 2011

Maven profiles inheritance

Content:

Maven abstract.
Tunning your Maven proyect
Maven standard folders
Managing dependencies with Maven
Adding a nature in Eclipse
Maven profiles inheritance

DISCLAMER: THIS ENTRY STAYS HERE FOR HISTORICAL REASONS, BUT ITS CONTENT IS NOT ACCURATE (MILD WAY OF SAYING IT'S WRONG).

APOLOGIES FOR ANYBODY AFFECTED, IT WAS HONESTLY WRITTEN AND BADLY MAINTAINED.

As far as I have investigated, Maven profiles are not inherited, but there is a mechanism alike.

Let's build an example:

Parent pom.xml

<profiles>
    <profile>
        <id>profileA</id>
        <activation>whatever</activation>
        <build>[whatever]</build>
    </profile>

    <profile>
         <id>profileB</id>
        <activation>whatever</activation>
        <build>[whatever]</build>
    </profile>
</profiles>



Let's assume there's a child project, without specific profiles configuration.

It isn't a crazy idea imagine that if a project inherits from a parent pom like above, when activation conditions are met, child project should enjoy the build profiled configuration, but IT DOESN'T HAPPEN.

The only way to get something similar is configuring "profiles" and "activation" in child project, and the same "profiles" with same "id", with "resources" and "configuration" associated to that profile in parent pom.
This way, when a child project is compiling, profiles are activated and, with a profile active, it is actived in parent pom.


Example 2:

Parent pom.xml
<profiles>
    <profile>
        <id>profileA</id>

        <build>[whatever]</build>
     </profile>

     <profile>
        <id>profileB</id>

        <build>[whatever]</build>
    </profile>
</profiles>


Child  pom.xml (assume a parent pom configuration in this project)
<profiles>
   
<profile>
        <id>profileA</id>
        <activation>whatever</activation>

    </profile>

    <profile>
        <id>profileB</id>
        <activation>whatever</activation>
    </profile>
</profiles>
</profiles>


Notice that parent pom does not have activation conditions (they would not work either), and child pom does not have any configuration, because you wanted a parent pom for a common configuration.

This way, you have got something similar to Profiles inheritance.


Alberto Navarro.
@anavarro_prof
looking4q.blogspot.com

jueves, 27 de enero de 2011

Software versioning, Apache strategy

In the last few weeks, my job is to make my mates job easier. I have been installing a simple Continuous Integration System, Maven plugins and Eclipse add-ons.

I can't share a lot of this information until I have learned it properly. I would want to show that with good examples and error-solving snippets.

What I can tell you right now is the versioning system of apache, I liked it too much because it is simply, easy to learn and use, easy to learn, teach, memorize..

http://apr.apache.org/versioning.html

This system is used by lots of other software companies, let's explain in few words:

Let's take a random version: 3.2.1, for example.

You resolve a bug, and make a patch for your clients, increment the third number.
You create a feature, but you don't change any of previously existent functionality, increment the second number.
You change a functionality, breaking the contract of your previous versions. increment the first number.


The result might be the following.

Previous version: 3.2.1
You upgrade to 3.2.2
It is supposed to be fully compatible

Previous version: 3.2.1
You downgrade to 3.2.0
It is supposed to be fully compatible. Obviously, it could work worse, there is an absent patch.

Previous version: 3.2.1
You upgrade to 3.3.1 (or 3.3.0)
 It is supposed to be fully compatible with the same configuration.

Previous version: 3.2.1
You downgrade to 3.1.1 (or 3.1.x)
Compatibility with prior minor versions is not guaranteed. *

Previous version: 3.2.1
You upgrade to 4.2.1 (or 4.x.x)
Compatibility with different major versions is not guaranteed.

Previous version: 3.2.1
You downgrade to 2.2.1 (or 2.x.x)
Compatibility with different major versions is not guaranteed. *

* The best explanation for this phenomenon is, lets say, 3.2.1 introduced two lines in configuration files, which are parsed with a certain pattern. It could be possible that previous version was not able to parse your configuration with those unknown new lines.

A good coherent versioning system will give free information to your team and customers about how compatible your versions are between them. Avoid marketing formulas for your version, at least, inside your I.T. department. You could also use standard tools for autoincrement versions, like Maven (sooooon).

See you at @anavarro_prof twitter ;)

martes, 25 de enero de 2011

Roll your own Continuous Integration System (C.I.S.): Install Tomcat

Roll your own Continuous Integration System (C.I.S.)

Content:
Abstract
Install Tomcat
Basic Tomcat configuration - Memory
Basic Tomcat configuration - JMX
Basic Tomcat configuration - Application Manager and permissions
Apache and uSVN 
Installing Artifactory from WAR
Configure Artifactory and MySQL
Configuring Artifactory security and repositories 

As we said in the previous post, we are building our C.I.S. in the top of a Tomcat 6.x, it is not the best server in the world, but it is open, free and widely supported by a vast community and thousand of different running project all over the world, so, it is not that bad either.

There is no point to explain deeply how to install Tomcat, I will write my own installation in order to reproduce all steps in the future if necessary. You may also use this for a easy set-up of your system.

Pre-Requisites: Java JRE 1.5 (No matter what implementation, I have proofed both Sun and OpenJDK virtual machines with the same problems :P ).


For Windows XP:
Download: http://apache.rediris.es/tomcat/tomcat-6/v6.0.30/bin/apache-tomcat-6.0.30.exe
Execute it!

1) Accept Welcome
2) Accept License
3) Minimum installation: Tomcat and Manager
4) Select execution port (8080 in my case), user and pass manager (tomcat/tomcat, of course), and role (let manager-gui).
5) Select your JRE 1.5 installation path.
6) Select your desired installation path for Tomcat.
7) Confirm install.

If you want to see your Tomcat running, you have to get "Apache Tomcat 6.0" menu. (Start->Applications in Windows XP), then execute "Configure Tomcat".


And press "Start" button. Then you will be able to see Tomcat running at http://localhost:8080
Change "Startup type" from "Manual" to "Automatic" in order to get it as a service. Windows will run Tomcat every time you boot Windows.


For CentOS 5.5
Easier than Windows :P

(log as root)
cd /etc/yum.repos.d/
wget http://www.jpackage.org/jpackage50.repo
yum --disablerepo=jpackage* install jpackage-utils
yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps

Beware with permissions, due to your TOMCAT_HOME will be /usr/share/tomcat6, so you will need to change the owner of that directory if you want to write into, next post I will explain a good configuration.

For OpenSuse 11.3
Easier impossible:

(log as root)
zypper install tomcat6 tomcat6-admin-webapps tomcat6-webapps.

Beware with permissions, due to your TOMCAT_HOME will be /usr/share/tomcat6, so you will need to change the owner of that directory if you want to write into, next post I will explain a good configuration.


We will use and modify this installation a few times before finishing this tutorial. Be patient, the result will be worthy it.

viernes, 21 de enero de 2011

Essential Readings: Look for your cow, assassin evilly your cow.

Taken from The Rhetorical Journey 

This is a tale about dependency, "we aren't that bad"-ing and cowardy inside us all. Be critic with yourself, your work and your way of life everyday.


Kill the cow

A family lives in the outskirts of a remote village on a small plot of land.  The family own one cow.  Each day they live from the milk of the cow.  If there is little milk, they eat little.  It there is lots of milk, they eat well.  The lives of the mother, the father, the children depend on the cow.


One autumn day, a lone traveller stops in the village.  He is hungry.  The family share their milk.  The traveller is grateful.

The traveller wishes to return the favour and help the family.  He doesn't know how to help the family.  He hears that there is a wise man in the village.  He walks over to the home of the wise man.

"I was hungry and the family fed me.  I would like to help them.  How can I help this family?"

The wise man said "Kill the cow."

"Kill it?  How can that help them?  They depend for their lives on that cow."

The wise man repeated "Kill the cow."

The traveller was nervous about following such strange advice,  but the reputation of the wise man was such that he went ahead and killed the cow.

A year later the traveller happened to pass again through the village.  He noticed new shops and a thriving market.  He saw a new hotel that provided beds and food to the travellers who came for the market.  

The traveller entered the hotel.  Behind the bar he found the eldest son of the family of the cow.  The man was standing tall, smiling and happy.  The traveller greeted him and asked "What happened?".

"We lost our cow.  There was no milk.  We had to go out and do something to eat.  We set up a small market, it grew.  We set up this hotel, it is growing.  Without the milk from our cow, we had to try new things."

Silently to himself, the traveller reflected on the power of the wise man's words.  "Kill the cow."


What is your cow?

miércoles, 19 de enero de 2011

Essential readings: Continuous deployment in 5 easy steps

Terrific article about Continuous Deployment, enjoy it!

http://radar.oreilly.com/2009/03/continuous-deployment-5-eas.html


Do you know Continuous Deployment opensource software?

See you :)

sábado, 15 de enero de 2011

Monitorize your own applications with hardly any effort: JavaMelody

A developer may think that its job scope is bound to the functional part of the application. Valid and validated, the application runs and works fine. It meets the specifications and never hangs, dies or misfunctions, it is documented and tested. For god's sake, it is the best application I have ever seen.

But this developer cannot answer some very easy questions: Is it running right now? How can I know it is running? Can I automatize this knowledge in any way?

If your application is a CRUD database manager for documents, you can enter in the application, notice it is up, login yourself and use the wet finger method for more health and performance measures. However, if your application controls thermonuclear weapons, please make us a favor and resign.

I was asked to develop a plugin for every company application, in order to get current status, some statistics and maybe perform some executions to self-testing methods. After several weeks and thousands of euros invested on this project, I managed to create a /checkUp servlet that performed a database test and, if /checkUp responded "ok", then we assumed that the application was up.

Fortunately,  JavaMelody did this for us, much better, much easier, much appealing... I couldn't have done it better, for sure.

Follow the installation, just include 2 jars and 10 lines in your web.xml file, and you will have lots of statistics, a /monitoring servlet giving all pretty-printed data and some performance measures.

From its web:

"The goal of JavaMelody is to monitor Java or Java EE applications servers in QA and production environments. It is not a tool to simulate requests from users, it is a tool to measure and calculate statistics on real operation of an application depending on the usage of the application by users.

JavaMelody is opensource (LGPL) and production ready: in production in an application of 25 person years. JavaMelody is easy to integrate in most applications and is lightweight (no profiling and no database).

JavaMelody is mainly based on statistics of requests and on evolution charts.

It allows to improve applications in QA and production and help to:
give facts about the average response times and number of executions
make decisions when trends are bad, before problems become too serious
optimize based on the more limiting response times
find the root causes of response times
verify the real improvement after optimizations

It includes summary charts showing the evolution over time of the following indicators:
Number of executions, mean execution times and percentage of errors of http requests, sql requests, jsp pages or methods of business façades (if EJB3, Spring or Guice)
Java memory
Java CPU
Number of user sessions
Number of jdbc connections

These charts can be viewed on the current day, week, month, year or custom period.
"

Certainly, installing it took me no more than 10 minutes, using Maven dependencies, on an already existent application, and result was impressive, something like this (took from JavaMelody):



Something similar can be got using JMX, but it takes longer, and it is less human readable.

Try it in any of your applications, you will repeat!

Albert Navarro :)

jueves, 13 de enero de 2011

Book of the month: Scrum and XP from the Trenches

I promised myself to keep reading about tools, programming languages and methodologies and to try to read one book every month. Well, I already keep reading, this is time for:

Scrum and XP from the Trenches (Enterprise Software Development)

I liked it, I am not a Scrum practitioner yet, but I took a few interesting ideas. I liked the Spanish translation, so, you can imagine, I can not judge the language style of English version. What I liked the most is the simplification of methodology to a pragmatic point, to do only things that work.

Some ideas to keep in mind:

- Prediction of project length by poker gaming. Fun!
- Digitalize it all is not that important, a wall with tacks and post-its is as useful, or more, than a colourfull web application.
- Day of research and learning.
- Situation of members in a room is important.
- SCRUM methodology from a pragmatic and useful point of view.
- and so on...

I got a free digital version (legal, it ensures), but that web no longer exists.

Next month, I hope I will have learned something about stress testing.

Keeping the reading up! See you..



[Edited] Thanks Javier Del Palacio for your corrections again, they are always welcome :)

martes, 11 de enero de 2011

CheckStyle configuration distribution

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

As we could see in previous posts, it is necessary to broadcast the same style for the same team, organization or project. But I only got the lower case "q" for my post due to I make you, the newbie in the company, to configure the CheckStyle XML in your IDE, for your workspace only.

Using this strategy, a 20 members team have to configure the same 20 times for every workspace, and the number of times a workspace should be changed is undetermined, but I have done it several times this month, and today is 10th of January and I did not work seriously until yesterday :S.

It no longer matter the number of times you change your workspace in your Eclipse IDE, it is simply a bad practice to charge with that duty to your team. It should be done the lesser times possible, the lesser people doing it possible, and the lesser complicated to update possible.

What I am explaining you today is the possibility of configuring CheckStyle at project scope, not IDE scope, sharing the same configuration to all your team with the same commit and, even better, referencing an external file instead a local one, making updates of style immediate for every mate without even knowing.

Erase your previous configuration:
Window Menu ->Preferences -> CheckStyle. Then select your previous home-brew configuration and Remove it.

Now configure your project:
Right click over your project, Properties -> CheckStyle -> Local Check Configurations Tab -> New.
Type: Remote Configuration
Name: Whatever, yes, there's room for creativity today.
Location: URI of the CheckStyle configuration. It would be as perfect as necessary to have the file shared in a ftp server, svn server or any other easy-access way. We settled it under svn control and access it through svn+http apache mod.
Save and close.

And voila, now all your team has to do is update the project and run CheckStyle for that project, automatically the project configuration will be token and only one person had to work for a team benefit.

This is not a perfect way of doing the distribution, but it is rather better than previous, at IDE workspace files. But this configuration seems to me to much IDE-dependant either, I am searching for a better CheckStyle configuration in the Maven descriptor file. I will tell you as soon as I really see it working.

See you.

Alberto Navarro.

viernes, 7 de enero de 2011

What if... I get a "Fileset from project [projectname] has no valid check configuration" Error?

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

One solution for the following error:

Errors occurred during the build.
Errors running builder 'Checkstyle Builder' on project [projectname].
Fileset from project [projectname] has no valid check configuration.
Fileset from project [projectname] has no valid check configuration.
Fileset from project [projectname] has no valid check configuration.
Fileset from project [projectname] has no valid check configuration.




Analysis: 

It looks like to me that you configured CheckStyle in a workspace scope (Window->Preferences->CheckStyle...). Any of your team did the same, but his/her configuration, although it is the same, he/she put a different name to the configuration.

The other person generated a checkstyle project configuration, like ignored folders, and shared it with you, through Subversion for example.

As soon as you get that configuration, Checkstyle search for a specific configuration name, your pal's one, and yours name is different. That's the error.


Solution:

Please check your .checkstyle file in the root folder of the project. Specially "fileset" node, "check-config-name" property. Its value MUST be coherent with your CheckStyle configuration name. That file must be under version control repository Subversion and is shared between developers, so it is possible that some guy imported its workspace configuration.

Example of mistaken configuration .checkstyle file:

<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
  <fileset name="all" enabled="true" check-config-name="Sun Checks" local="false">
    <file-match-pattern match-pattern="." include-pattern="true"/>
  </fileset>
  <filter name="WriteProtectedFiles" enabled="true"/>
</fileset-config>



Coherent CheckStyle configuration at Window menu -> Preferences.


If the configuration doesn't defaults to the same name, or a project local configuration doesn't either, the error will appear. Check both IDE and project checkstyle configuration.

For avoiding the same error in the future, you can agree a name for that configuration with your team. A possible better solution is described here, and consist of configuring CheckStyle inside the project, and such information will travel with it, no more name mistaken will happen.


Did it work? Leave a comment.

See you! :)

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". :)