I'm currently looking at integrating Sonar into our build environment which intially didn't go too well interms of installation so I thought I'd document what I did and what was required for future reference. In this first part I will show you how to configure Sonar to run with a basic out of the box setup that uses the inbuilt Derby database, localhost web and Core/Squid C# plugins.
PREREQUISITES - VERY IMPORTANT!
- Download Java JDK, it's works with 1.5+ but I installed 1.7.
http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html
INSTALL SONAR
- Download Sonar:
http://sonar.codehaus.org/downloads/
- Extract to a directory i.e. c:\Sonar
- Run \bin\windows-x86-32\StartSonar.bat or \bin\windows-x86-64\StartSonar.bat depending on your OS
- Navigate to http://localhost:9000 to view the default console
At this point Sonar is configured to use the default database.
INSTALL JAVA RUNNER
Rather than using Mavern it's much easier to to use the Java Runner to kick off Sonar.
- Download the Java Runner: http://docs.codehaus.org/display/SONAR/Analyse+with+a+simple+Java+Runner#AnalysewithasimpleJavaRunner-Installation
- Extract to dir i.e. c:\Sonar\sonar-runner-1.1
- Modify C:\Sonar\sonar-runner-1.1\conf\sonar-runner.properties to enble the default site and Derby DB
My modifed file looks like this:
#----- Default directory layout
sources=src/main/java
tests=src/test/java
binaries=target/classes
sonar.sourceEncoding=UTF-8
#----- Default Sonar server
sonar.host.url=http://localhost:9000
#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
- Make sure you have the following environment varaibles:
JAVA_HOME = C:\Program Files\Java\jdk1.6.0_23
SONAR_RUNNER_HOME = C:\Sonar\sonar-runner-1.1
- Add the sonar runner bin path to your PATH environment (for my install this is C:\Sonar\sonar-runner-1.1\bin)
- There are two ways to tell Sonar where your .sln file is located
a) You can create a sonar-project.properties file in the same directory as your solution file, Sonar will find it OR
b) Create a sonar-project.properties file but use the sonar.dotnet.visualstudio.solution.file property to specify the path (this is my prefered option)
- Create a file called "sonar-project.properties" as descrivbed in the above step (literally as it is don't replace project with your project name!) placing it
Here's my sample properties file located on the root of my application:
AppName
---->BuildTools
---->Lib
---->src
--------->AppName.sln
build.proj
sonar-project.properties
-
# Project identification
sonar.projectKey=DMG:AppName
sonar.projectVersion=1.0-SNAPSHOT
sonar.projectName=AppName
# Info required for Sonar
sources=.
sonar.language=cs
#Core C# Settings
sonar.dotnet.visualstudio.solution.file=\src\\AppName.sln
#Gendarme
sonar.gendarme.assemblies=\build\\DmgTech*.*
sonar.gendarme.mode=skip
# Gallio
sonar.gallio.mode=skip
# FXCop
sonar.fxcop.mode=skip
#StyleCop
sonar.stylecop.mode=skip
- To run Sonar-Runner against your project
- Shell out to DOS
- Change directory to the location of your "sonar-project.properties" file
- Execute "sonar-runner"
- View your reports at http://localhost:9000
Troubleshooting
- If you receive something like: Fail to connect to database: undefined method `getActiveRecordDialectCode' for nil
Check the JDK version you are running
- If you receive a maintenance warning then try http://localhost:9000\setup
- View the logs \logs\sonar.log
- If you receive the following error make sure the path to Java is in the environment path (I had to put C:\Program Files\Java\jdk1.7.0\bin). To test head to DOS and type java.
FATAL | wrapper | 2011/08/22 13:00:04 | Critical error: wait for JVM process failed
STATUS | wrapper | 2011/08/22 13:02:14 | --> Wrapper Started as Service
STATUS | wrapper | 2011/08/22 13:02:14 | Launching a JVM...
INFO | jvm 1 | 2011/08/22 13:02:16 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
INFO | jvm 1 | 2011/08/22 13:02:16 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
-----------------------------------------------------------------------------------------------------------------------------------
wrapper | --> Wrapper Started as Console
wrapper | Java Service Wrapper Community Edition 3.3.0
wrapper | Copyright (C) 1999-2008 Tanuki Software, Inc. All Rights
Reserved.
wrapper | http://wrapper.tanukisoftware.org
wrapper |
wrapper | Launching a JVM...
jvm 1 | WrapperManager: Initializing...
jvm 1 | 2009-12-07 16:33:29.166::INFO: Logging to STDERR via
org.mortbay.log.StdErrLog
jvm 1 | 2009-12-07 16:33:29.211::INFO: jetty-6.1.17
jvm 1 | 2009-12-07 16:33:29.350::WARN: Failed startup of context
org.mortbay.jetty.webapp.WebAppContext@635f44d4{/,null}
jvm 1 | java.lang.NullPointerException
fix: I came across this error when I reinstalled Sonar over an existing installation, I had to remove and reinstall from fresh to get around this error
-----------------------------------------------------------------------------------------------------------------------------------
Exception in thread "main" org.sonar.batch.bootstrapper.BootstrapException: org.picocontainer.PicoLifecycleException: PicoLifecycleException: method 'public void org.sonar.batch.index.DefaultIndex.start()', instance 'org.sonar.batch.index.DefaultIndex@39da8a, java.lang.RuntimeException: wrapper at org.sonar.runner.Runner.delegateExecution(Runner.java:155) at org.sonar.runner.Runner.execute(Runner.java:58)at org.sonar.runner.Main.main(Main.java:52)
Caused by: org.picocontainer.PicoLifecycleException: PicoLifecycleException: method 'public void org.sonar.batch.index.DefaultIndex.start()', instance 'org.sonar.batch.index.DefaultIndex@39da8a, java.lang.RuntimeException: wrapper
FIX: sonar-runner can't find a sonar-project.properties file!
In the next part I'll dive into enabling the extra plugins such as Gallio and incorporate NCover reports.