Build and Analyze a .net 4 project in Maven Sonar – Part 3

We have come to the final stages of the maven configuration. After we create settings.xml properly we are done with maven. It resides within M2_HOME/conf/.When you open the default settings.xml file, you will see that it has lot of lines and  most are commented. You just need to  add plugins at appropriate places. Keep other lines as they are. So the basic structure would be as following with dotnet and sonar plugins been added. Do necessary changes within plugins. Ex:- <galio.directory>, <sonar.jdbc.url> etc. Change them according to your installations and project properties.

<?xml version=”1.0″ encoding=”UTF-8″?>
<settings xmlns=”http://maven.apache.org/SETTINGS/1.0.0
          xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance
          xsi:schemaLocation=”http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd“>
 <profiles>
 <profile>
      <id>dotnet</id>
      <activation>
        <!– Optional activation by default –>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>

  <dotnet.4.0.sdk.directory>
  C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319</dotnet.4.0.sdk.directory>
             
        <!– Location of the Gallio installation –>
  <gallio.directory>
  C:\Program Files (x86)\Gallio</gallio.directory>

        <!– Location of StyleCop installation –>
        <stylecop.directory>
  C:\Program Files (x86)\Microsoft StyleCop 4.4.0.14</stylecop.directory>

        <!– Location of FxCop installation –>
        <fxcop.directory>
  C:\Program Files (x86)\Microsoft Fxcop 10.0</fxcop.directory>

        <!– Location of PartCover installation–>
        <partcover.directory>C:/Program Files (x86)/PartCover/PartCover .NET 4.0
  </partcover.directory>

        <!– Location of Source Monitor installation–>
  <sourcemonitor.directory>C:/Program Files (x86)/SourceMonitor
  </sourcemonitor.directory>
       
        <!– Location of Gendarme installation–>
  <gendarme.directory>C:/Program Files (x86)/Gendarme</gendarme.directory>
  
  <!– Location of NCover installation–>
  <ncover.directory>C:/Program Files/NCover</ncover.directory>
       
      </properties>
   </profile>
   <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
              
                <sonar.jdbc.url>jdbc:derby://localhost:1527/sonar;create=true
    </sonar.jdbc.url>
                <sonar.jdbc.driverClassName>org.apache.derby.jdbc.ClientDriver
    </sonar.jdbc.driverClassName>
                <sonar.jdbc.username>sonar</sonar.jdbc.username>
                <sonar.jdbc.password>sonar</sonar.jdbc.password>
    <sonar.host.url>http://localhost:9000</sonar.host.url&gt;
            </properties>
        </profile>
 </profiles>

</settings>

Next configuring sonar.properties file. After that we are done………………. 🙂

Build and Analyze a .net 4 project in Maven Sonar – Part 2

Time has come to  configure  maven. Before that run mvn –version in cmd and double check whether maven is installed correctly. if maven is ready next thing to do is creating the pom.xml file. Following is a sample pom.xml file for a .net 4 application. it includes all the necessary plugins. Below mentioned plugin versions are compatible with sonar 2.8 and maven 3.0.3. If you are using any other versions of maven or sonar(remember you should have atleast sonar 2.4 and maven 3.0) please check plugins’ compatibility, otherwise it would be a big headache.

<project xmlns=”http://maven.apache.org/POM/4.0.0&#8243; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”&gt;
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.maven.dotnet.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<name>YourProject</name>
<packaging>sln</packaging>
<properties>
<visual.studio.solution>YourProject.sln</visual.studio.solution>
<visual.test.project.pattern>*.Tests</visual.test.project.pattern>
<dotnet.tool.version>4.0</dotnet.tool.version>
<sonar.language>cs</sonar.language>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar-plugins.dotnet</groupId>
<artifactId>maven-dotnet-plugin</artifactId>
<version>0.5</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.0-beta-2</version> <configuration>
<language>cs</language>
</configuration>
</plugin>
</plugins>
</build>
</project>

Now keep this in the folder where your .sln resides.You can see that I have defined two plugins in my pom. Those are maven-dotnet and sonar-maven. Be carefull there are two types of sonar-maven plugin, org.codehaus.mojo:sonar-maven-plugin and org.codehaus.sonar:sonar-maven-plugin. I’m using the first one because it make our lives easier. need to know how???? follow  http://docs.codehaus.org/display/SONAR/Frequently+Asked+Questions#FrequentlyAskedQuestions-Whatisthedifferencebetweenorg.codehaus.mojo%3Asonarmavenpluginandorg.codehaus.sonar%3Asonarmavenplugin%3F

Next you need to install several applications which are needed by maven-dotnet plugin. Those are

  • MsBuild
  • Gallio
  • PartCover
  • NCover
  • Source Monitor
  • Fx Cop
  • Style Cop
  • Mono Gendarme

http://maven-dotnet-plugin.appspot.com/usage.html provides a comprehensive guide of these applications. Configuring the settings.xml file in maven/conf is the next thing you must do………………………….let’s see that in the next blog post 🙂

Build and Analyze a .net 4 project in Maven Sonar – Part 1

Hi everyone, I recently build a .net4(C#) project using maven and analysed code quality reports using sonar.While doing so I searched the web for any comprehensive tutorials but found nothing.So I thought to share my knowledge withh you.I will describe the entire process step by step through couple of blog posts First we need to clarify basic requirements to build and analyze a .net 4 application.

  • JDK 1.6 (older versions are not compatible with maven-dotnet plugin, don’t worry  we are going to discover later all these plugins we need :))
  • Maven 3.0 or higher (older versions are not compatible with sonar-maven plugin)
  • Sonar 2.4 or higher (older versions are not compatible with sonar-dotnet plugin version 0.5. versions older than 0.3 are not compatible with .net 4 and version 0.4 is advised to ommit because it has a nasty error)
  • .net 4 framework

Now you know basic requirements. So install JDK 1.6, Maven 3.0 or higher and Sonar 2.4 or higher. Now configuring maven correctly………….it will be the next blog post 🙂