Archive for the ‘Sonar’ Category

Including Automated Tests and Automated Builds are some of the key aspects in a Continuous Integration development activity. Most of us are already familiar with these premises but, in the other hand, it is a common practice to commit/push our updates once all Unit Tests run successfully; leaving those Integration Tests and, why not, inter-dependencies troubles to be analyzed after the remote repo build. Anne Thomas Manes estimates that ongoing maintenance could achieve 92% of the total lifetime cost of an application.

Automated builds, with the use of any Integration Tool such as Hudson/Jenkins, are commonly performed “over there”, after our commits, but why don’t prevent to those possible dependency issues? or those failed integration tests?

Martin Fowler explains in his Continuous Integration article: “The point of testing is to flush out, under controlled conditions, any problem that the system will have in production. A significant part of this is the environment within which the production system will run. If you test in a different environment, every difference results in a risk that what happens under test won’t happen in production…” . Decreasing the gap between the Local dev environment and the Production environment reduces the chances of a Red Ball nightmare.

Continuing with my last post, eBayOpenSource with Sonatype Nexus, I decided to complete my dev environment with the use of Hudson+Sonar+Nexus tools.  Here are the simple steps:

Configure Sonatype nexus in your environment

– Go to Hudson home page and download the war file. You could install a native package as well, I prefer the war-way for OS upgrade purposes.

– Go to Sonar site, download latest zip file. v2.8 in this case.

Run Hudson with:

java -jar your_hudson_war

Hudson console runs on port 8080 by default. You can chage it by adding parameter –httpPort=8888

Go to Manage Hudson -> Manage Plugin and install Sonar plugin

In my case I use Git as repo, so I needed to add some extra plugins:

Then, go to Manage Hudon -> Configure System and add:

JAVA_HOME: in my case, /usr/lib/jvm/java-1.6.0-openjdk

GIT installations, give it a name

MAVEN_HOME: /home/jose/Tools/apache-maven-3.0

MAVEN_OPTS: -Xms512m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=128m

Sonar installations, give it a name

Create a new Hudson Job:

Add your Source Code Management:in my case GIT and  file:///home/jose/workspace/<any-git-project>

Branches to build: origin/master

Poll SCM: @hourly

and don’t forget to check last item, Post-build Actions: Sonar

press Save.

Now, it’s turn to run Sonar:

go to [Sonar_Home]/bin/[your_OS_Distro] and execute the script. It will load sonar service and console at localhost:9000

Go back to hudson console and press Build now in your Hudson Job….then magic happens!!!

Started by user anonymous
Checkout:workspace / /home/jose/.hudson/jobs/turmeric-policy/workspace - hudson.remoting.LocalChannel@3ed9c921
Using strategy: Default
Last Built Revision: Revision 2a40432f5ed44da0ada7e326b224198cb676f175 (origin/master)
Checkout:workspace / /home/jose/.hudson/jobs/turmeric-policy/workspace - hudson.remoting.LocalChannel@3ed9c921
Fetching changes from the remote Git repository
Fetching upstream changes from file:///home/jose/workspace-git/turmeric-policy
Commencing build of Revision 2a40432f5ed44da0ada7e326b224198cb676f175 (origin/master)
Checking out Revision 2a40432f5ed44da0ada7e326b224198cb676f175 (origin/master)
Found mavenVersion 3.0 from file jar:file:/home/jose/Tools/apache-maven-3.0/lib/maven-core-3.0.jar!/META-INF/maven/org.apache.maven/maven-core/
Parsing POMs
downloaded artifact
downloaded artifact
[workspace] $ /usr/lib/jvm/java-1.6.0-openjdk/bin/java -Xms512m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=128m -cp /home/jose/.hudson/plugins/maven-plugin/WEB-INF/lib/maven3-agent-2.0.1.jar:/home/jose/Tools/apache-maven-3.0/boot/plexus-classworlds-2.2.3.jar org.jvnet.hudson.maven3.agent.Maven3Main /home/jose/Tools/apache-maven-3.0 /home/jose/.hudson/war/WEB-INF/lib/hudson-remoting-2.0.1.jar /home/jose/.hudson/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-2.0.1.jar 47965
���channel started
Executing Maven: -B -f /home/jose/.hudson/jobs/turmeric-policy/workspace/pom.xml sonar:sonar
[INFO] Scanning for projects...

You can see the “" over there, it's Nexus in action....

Unfortunately I fell into the Duplicated Source Sonar issue. 😦

We should see something similar to:

see you in the next one…Hope SONAR-2444 be solved, otherwise I should find a workaround asap.