Results 1 to 2 of 2
  1. #1
    jason2014 is offline Member
    Join Date
    Jul 2014
    Posts
    2
    Rep Power
    0

    Default how to setup sonar for c# code analysis

    Hi all,

    I am new to Java. I am from .net background.I am trying to setup Sonar server. In one of our training sessions on Sonar, the instructor did the anaysis of solution using pom.xml file and then calling mvn sonar:sonar. I am trying to replicate the entire setup locally.

    1. I installed JRE 7. When I run , java -version, it shows,
    java version "1.7.0"
    Java(TM) SE Runtime Environment (build 1.7.0-b147)
    Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

    2. I download sonar 3.5 and extracted it to new folder
    3. In that folder I installed sonar-runner 2.4
    3. setup the path and sonar_runner environment variable
    4. downloaded jtds-1.3.1 and placed the jar file in mssql folder of sonar
    5. I create database sonar with username and password as sonar
    6. changed sonar-runner.properties for sql server connection
    7. changed sonar.properties for sql server connection
    8. Ran Sonar.bat and found that it created tables in the sql server db. To me the command prompt seems like it is hanging as after creating table graphs, the last line is
    "jvm 1 | 2014-07-20 13:03:34.967:INFO::Started SelectChannelConnector@0.0.0.0:
    9000 "

    Is it supposed to stay like this always or should i closed this command prompt by pressing CTRL+C?
    9. Now when i run mvn-sonar:sonar, it says mvn is not recrognizes as internal or external command. A quick search on google showed that I need to install Apache maven something I belive. What is this or how do I solve this issue so that the command mvn sonar:sonar can work?
    10. I would like to use c sharp ecosystem plugin. But when I browse to C# Plugin - SonarQube - Codehaus , I am confused as what to select? i.e. version 3.2, 3.1, 3.0
    11. So if I do a system restart and everytime I have to use sonar, should i run sonar.bat and then do mvn sonar:sonar after modifying the pom.xml file?

    Kindly do answer points 8,9,10,11.
    Last edited by jason2014; 07-20-2014 at 11:34 AM.

  2. #2
    jason2014 is offline Member
    Join Date
    Jul 2014
    Posts
    2
    Rep Power
    0

    Default Re: how to setup sonar for c# code analysis

    I download 3.7.4 version sonar as plugins were incompatible with 3.5 version , installed apache maven-3.2. and JSE jdk 7.setup envrionment variables. Logged in as admin and installed .net plugins.
    Modified the settings files in maven folder as follows.

    <profile>
    <id>dotnet</id>
    <activation>
    <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
    <dotnet.2.0.sdk.directory>
    C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727
    </dotnet.2.0.sdk.directory>
    <dotnet.3.5.sdk.directory>
    C:/WINDOWS/Microsoft.NET/Framework/v3.5
    </dotnet.3.5.sdk.directory>
    <dotnet.4.0.sdk.directory>
    C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319
    </dotnet.4.0.sdk.directory>
    <fxcop.directory>
    D:\Program Files (x86)\vs2012\Team Tools\Static Analysis Tools\FxCop
    </fxcop.directory>
    </properties>
    </profile>
    </profiles>

    created pom.xml in visual studio project solution folder as follows..

    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>MavenBuildTesting</groupId>
    <artifactId>MavenBuildTesting-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
    <visual.studio.solution>WebApplication1.sln</visual.studio.solution>
    <visual.test.project.pattern>*.Tests</visual.test.project.pattern>
    <dotnet.tool.version>3.5</dotnet.tool.version>
    <sonar.language>cs</sonar.language>
    </properties>

    <build>
    <plugins>
    <plugin>
    <groupId>org.codehaus.sonar-plugins.dotnet</groupId>
    <artifactId>maven-dotnet-plugin</artifactId>
    <extensions>true</extensions>
    </plugin>

    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <configuration>
    <language>cs</language>
    </configuration>
    </plugin>
    </plugins>
    </build>
    </project>


    when i run
    mvn sonar:sonar I get


    INFO: SonarQube Server 3.7.4
    [INFO] [18:34:57.986] Load batch settings
    [INFO] [18:34:58.040] User cache: C:\Users\JamesBond\.sonar\cache
    [INFO] [18:34:58.043] Install plugins
    [INFO] [18:34:58.382] Install JDBC driver
    [WARN] [18:34:58.393] H2 database should be used for evaluation purpose only
    [INFO] [18:34:58.393] Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
    [ERROR] Fail to connect to database
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.742 s
    [INFO] Finished at: 2014-07-20T18:35:00+05:30
    [INFO] Final Memory: 14M/244M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (d
    efault-cli) on project example-java-maven: Can not execute SonarQube analysis: F
    ail to connect to database: Cannot create PoolableConnectionFactory (Connection
    is broken: "java.net.SocketException: Permission denied: connect: localhost" [90
    067-172]) -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
    ch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please rea
    d the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/d...MojoExecutionE
    xception


    How do I make the command mvn sonar:sonar to work?

Similar Threads

  1. Replies: 0
    Last Post: 02-13-2012, 01:11 PM
  2. HELP with code analysis
    By geenah in forum New To Java
    Replies: 4
    Last Post: 11-18-2011, 08:59 PM
  3. Secure java code allong with the setup of application
    By Annie George in forum NetBeans
    Replies: 0
    Last Post: 01-08-2011, 10:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •