GithubHelp home page GithubHelp logo

grunt-sonar-runner's Introduction

grunt-sonar-runner

Sonar Analysis Runner from grunt

Build Status NPM version Dependency Status

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-sonar-runner --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-sonar-runner');

The "sonarRunner" task

Overview

In your project's Gruntfile, add a section named sonarRunner to the data object passed into grunt.initConfig().

grunt.initConfig({
sonarRunner: {
        analysis: {
            options: {
                debug: true,
                separator: '\n',
                sonar: {
                    login: 'admin',
                    password: 'admin',
                    host: {
                        url: 'http://localhost:9000'
                    },
                    jdbc: {
                        url: 'jdbc:mysql://localhost:3306/sonar',
                        username: 'sonar',
                        password: 'sonar'
                    },

                    projectKey: 'sonar:grunt-sonar-runner:0.1.0',
                    projectName: 'Grunt Sonar Runner',
                    projectVersion: '0.10',
                    sources: ['test'].join(','),
                    language: 'js',
                    sourceEncoding: 'UTF-8'
                }
            }
        }
    }
});

Options

options.debug

Type: Boolean Default value: 'false'

A Boolean value to display debug information when preparing sonar analysis.

options.separator

Type: String Default value: os.EOL

A string value representing a new line character to separate individual sonar properties

options.dryRun

Type: Boolean Default value: 'false'

A flag to run it in dry mode. The configuration is checked but not execute

options.maxBuffer

Type: Number Default value: 'null'

maxBuffer specifies the largest amount of data allowed on stdout or stderr - if this value is exceeded then the child process is killed and an error returned from sonar-runner. See: child_process.exec()

options.projectHome

Type: String Default value: ''

A string value representing a root path from the project, if configured it will create a project configuration file based on options.sonar without override default runner configuration file. If the root path contains a file named sonar-project.properties, this file will be considered instead

options.sonar.host.url

Type: String Default value: 'http://localhost:9000'

Sonar Dashboard URL

options.sonar.jdbc.url

Type: String Default value: ''

JDBC connection url

options.sonar.jdbc.username

Type: String Default value: ''

JDBC connection username

options.sonar.jdbc.password

Type: String Default value: ''

JDBC connection password

options.sonar.sources

Type: String Default value: ''

comma separated list of directories to analyse. All js files in the provided directories will be included.

options.sonar.projectKey

Type: String Default value: ''

project key usually of form group:artifactId:version

options.sonar.projectName

Type: String Default value: ''

Project Summary

options.sonar.projectVersion

Type: String Default value: ''

Current project build version

options.sonar.language

Type: String Default value: null

Sets the project language. A list of language plugins can be found here. If this property is undefined, a multi language project will be assumed and the sources searched for valid/supported languages.

options.sonar.javascript.lcov.reportPath

Type: String Default value: -

Path to the LCOV Code Coverage File to be used in Sonar

options.sonar.exclusions

Type: String or [String]
Default value: null

A list of directories and files that should be excluded from Sonar analysis. A list of wildcards that can be use can be found here.

Usage Examples

The configuration code below shows all possible options that are currently supported by the plugin. Any additional sonar properties can be added right inside the sonar object literal.

grunt.initConfig({
  sonarRunner: {
              analysis: {
                  options: {
                      debug: true,
                      separator: '\n',
                      dryRun: false,
                      sonar: {
                          login: 'admin',
                          password: 'admin',                          
                          host: {
                              url: 'http://localhost:9000'
                          },
                          jdbc: {
                              url: 'jdbc:mysql://localhost:3306/sonar',
                              username: 'sonar',
                              password: 'sonar'
                          },

                          projectKey: 'sonar:grunt-sonar-runner:0.1.0',
                          projectName: 'Grunt Sonar Runner',
                          projectVersion: '0.10',
                          sources: ['test'].join(','),
                          language: 'js',
                          sourceEncoding: 'UTF-8'
                      }
                  }
              }
          }
});

To run

grunt sonarRunner:analysis

Release History

grunt-sonar-runner's People

Contributors

cdietrich avatar chilicat avatar ilpianista avatar joekukish avatar lcotonea avatar meister avatar polooo2 avatar skhatri avatar stas-vilchik avatar techiebrandon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

grunt-sonar-runner's Issues

SonarRunner path in quotes

Hi,
I am (or was :) ) using the grunt task in a project where the project folder contained a whitespace (I know not the best case but hey ... legacy stuff).
The sonar runner jar file path isnt quoted so the jarfile could not be accessed.

Changed the folder to a non whitespace name and everything worked again

Execution fails because of Java heap space error

Error message:

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 9.339s
Final Memory: 5M/27M
INFO: ------------------------------------------------------------------------
>> ERROR: Error during Sonar runner execution
>> ERROR: Unable to execute Sonar
>> ERROR: Caused by: Java heap space

I had to modify tasks/sonar_runner.js in order to get it working:

var SONAR_RUNNER_COMMAND = 'java -Xmx1024m -XX:MaxPermSize=512m -jar -jar ' + SONAR_RUNNER_HOME 

sonarqube hosted over https giving certificate not found

Running "sonarRunner:analysis" (sonarRunner) task
Effective Sonar Options

sonar.host.url=https://sonarqube.com
sonar.host.login=MYID
sonar.host.password=XXXXXX
sonar.host.keystoreFile=/Users/localadmin/workspace/../myTrustStore.jks
sonar.host.keyPass=changeit
sonar.host.keystorePass=changeit
sonar.host.keystoreType=JKS
sonar.projectKey=sonar:grunt-sonar-runner:0.1.0
sonar.projectName=Grunt Sonar Runner
sonar.projectVersion=0.10
sonar.sources=test
sonar.language=js
sonar.sourceEncoding=UTF-8
Sonar client configured
sonar-runner exec: java -jar "/Users/localadmin/workspace/../node_modules/grunt-sonar-runner/tasks/../sonar-runner-2.4/lib/sonar-runner-dist-2.4.jar" -Drunner.home="/Users/localadmin/workspace/../node_modules/grunt-sonar-runner/tasks/../sonar-runner-2.4"
SonarQube Runner 2.4
Java 1.8.0_66 Oracle Corporation (64-bit)
Mac OS X 10.11.6 x86_64
INFO: Runner configuration file: /Users/localadmin/workspace/../node_modules/grunt-sonar-runner/tasks/../sonar-runner-2.4/conf/sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: /Users/localadmin/workspace/.././.sonar
INFO: SonarQube Server 5.6.1
10:46:35.232 INFO - Load global repositories
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 2.708s
Final Memory: 9M/245M
INFO: ------------------------------------------------------------------------

ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: Unable to load component class org.sonar.batch.bootstrap.BatchPluginInstaller
ERROR: Caused by: Unable to load component class org.sonar.home.cache.FileCache
ERROR: Caused by: Unable to load component class org.sonar.batch.bootstrap.GlobalSettings
ERROR: Caused by: Unable to load component class org.sonar.scanner.protocol.input.GlobalRepositories
ERROR: Caused by: Fail to request https://sonarqube.com/batch/global
ERROR: Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
ERROR: Caused by: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
ERROR: Caused by: unable to find valid certification path to requested target
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
Return code: 1.

sonarqube with authentication documentation for login/password variables

This is just a documentation issue. Running the analysis with the standard configuration against a Sonar server requiring authentication results in the failure message:

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 0.582s
INFO: ------------------------------------------------------------------------
>> ERROR: Error during Sonar runner execution
>> ERROR: Unable to execute Sonar
>> ERROR: Caused by: Not authorized. Analyzing this project requires to be authenticated. Please provide the values of the properties sonar.login and sonar.password.
>> ERROR: 
>> ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
>> ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
>> Return code: 1.
Warning: Task "sonarRunner:analysis" failed. Use --force to continue.

Documentation needs to be added to specify that all you need to do is add:

sonarRunner: {
  analysis: {
    options: {
        ...
        login: 'admin',
        password: 'admin',
        ...
      }
    }
  }
}

It isn't as obvious as you'd think. I've already had a few people ask me after getting SonarQube setup for JavaScript analysis.

ERROR: Fail to download libraries from server

Running in docker container built using:
FROM andrewmackrodt/nodejs:12

Gruntfile.js installed dependencies: grunt.loadNpmTasks('grunt-sonar-runner');
I confirmed the module was installed in the container.
Output from Jenkins included:

17:04:31  Running "sonarRunner:analysis" (sonarRunner) task
17:04:31  Effective Sonar Options
17:04:31  -----------------------
17:04:31  sonar.host.url=https://ourhosturl
17:04:31  sonar.host.login=blah-blah
17:04:31  sonar.projectKey=unique-project-key
17:04:31  sonar.projectName=Our Web App
17:04:31  sonar.projectDescription=WebApp is an HTML5 web application
17:04:31  sonar.projectVersion=1.0.0
17:04:31  sonar.sources.0=assets
17:04:31  sonar.language=js
17:04:31  sonar.sourceEncoding=UTF-8
17:04:31  Sonar client configured 
17:04:31  sonar-runner exec: java  -jar "/content-app/node_modules/grunt-sonar-runner/tasks/../sonar-runner-2.4/lib/sonar-runner-dist-2.4.jar" -Drunner.home="/content-app/node_modules/grunt-sonar-runner/tasks/../sonar-runner-2.4"
17:04:31  SonarQube Runner 2.4
17:04:31  Java 11.0.8 Ubuntu (64-bit)
17:04:31  Linux 3.10.0-1062.9.1.el7.x86_64 amd64
17:04:31  INFO: Runner configuration file: /content-app/node_modules/grunt-sonar-runner/tasks/../sonar-runner-2.4/conf/sonar-runner.properties
17:04:31  INFO: Project configuration file: NONE
17:04:31  INFO: Default locale: "en_US", source code encoding: "UTF-8"
17:04:31  INFO: Work directory: /content-app/./.sonar
17:04:32  INFO: SonarQube Server 8.4.2.36762
17:04:32  INFO: ------------------------------------------------------------------------
17:04:32  INFO: EXECUTION FAILURE
17:04:32  INFO: ------------------------------------------------------------------------
17:04:32  Total time: 0.807s
17:04:32  Final Memory: 4M/96M
17:04:32  INFO: ------------------------------------------------------------------------
17:04:32  >> ERROR: Error during Sonar runner execution
17:04:32  >> ERROR: Fail to download libraries from server
17:04:32  >> ERROR: Caused by: Index 1 out of bounds for length 1
17:04:32  >> ERROR: 
17:04:32  >> ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
17:04:32  >> ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

I'm re-running to get stack-trace...

Message "has no method 'join' "

Here my configuration:

      sonarRunner: {
        analysis: {
          options: {
            debug: true,
            separator: '\n',
            sonar: {
              host: {
                url: 'http://xx.xx.xx.xx:8080/sonar'
              },
              jdbc: {
                url: sonarDb,
                username: xxxx,
                password: xxxx
              },
              coverage: {
                  exclusions: 'src/xxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php,vendor/**,app/cache/**,app/*.php'
              },
              cpd: {
                  exclusions: 'src/xxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php'
              },
              php: {
                coverage: {
                  reportPath: 'build/php-unit/php-coverage-unit.xml'
                },
                tests: {
                  reportPath:'build/php-unit/phpunit.xml'
                }
              },
              projectKey: 'xxxx:yyyy',
              projectName: 'xxxxxx_xxxxxx',
              projectVersion: "<%= build.version %>",
              sources: 'src/xxxx/xxxxAPIServiceBundle,src/xxxx/APIBundle,src/xxxx/SecurityBundle,src/xxxxx/StoreBundle',
              exclusions: 'src/xxxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php,vendor/**,app/cache/**,app/*.php',
              language: 'php',
              sourceEncoding: 'UTF-8'
            }
          }
        }

By using grunt-sonar-runner v2.3.1, everything is ok:

Verifying property �[36msonarRunner.analysis�[39m exists in config...�[32mOK�[39m
File: �[33m[no files]�[39m
Options: �[36mdebug�[39m, �[36mseparator="\n"�[39m, �[36mdryRun=false�[39m, �[36msonar={"host":{"url":"http://xxx.xxx.xxx.xxx:xxx/sonar"},"jdbc":{"url":"jdbc:postgresql://xxx.xxx.xxx.xxx/sonar","username":"xxxx","password":"xxxx"},"coverage":{"exclusions":"src/xxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php,vendor/**,app/cache/**,app/*.php"},"cpd":{"exclusions":"src/xxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php"},"php":{"coverage":{"reportPath":"build/php-unit/php-coverage-unit.xml"},"tests":{"reportPath":"build/php-unit/phpunit.xml"}},"projectKey":"xxxxx:yyyyy","projectName":"XXXx_XXX","projectVersion":"1.3.2","sources":"src/xxx/xxxxAPIServiceBundle,src/xxxxx/APIBundle,src/xxxx/SecurityBundle,src/xxxx/StoreBundle","exclusions":"src/xxxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php,vendor/**,app/cache/**,app/*.php","language":"php","sourceEncoding":"UTF-8"}�[39m
Effective Sonar Options

However, since the new version v2.3.2, my build output is:

[4mRunning "sonarRunner:analysis" (sonarRunner) task�[24m
Verifying property �[36msonarRunner.analysis�[39m exists in config...�[32mOK�[39m
File: �[33m[no files]�[39m
Options: �[36mdebug�[39m, �[36mseparator="\n"�[39m, �[36mdryRun=false�[39m, �[36msonar={"host":{"url":"http://xxx.xxx.xxx.xxx:xxx/sonar"},"jdbc":{"url":"jdbc:postgresql://xxxx/sonar","username":"xxxx","password":"xxx"},"coverage":{"exclusions":"src/xxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php,vendor/**,app/cache/**,app/*.php"},"cpd":{"exclusions":"src/xxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php"},"php":{"coverage":{"reportPath":"build/php-unit/php-coverage-unit.xml"},"tests":{"reportPath":"build/php-unit/phpunit.xml"}},"projectKey":"xxxxxx:yyyyy","projectName":"XXXX_XXXX","projectVersion":"1.3.3","sources":"src/xxx/xxxxAPIServiceBundle,src/xxxx/APIBundle,src/xxxx/SecurityBundle,src/xxxx/StoreBundle","exclusions":"src/xxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php,vendor/**,app/cache/**,app/*.php","language":"php","sourceEncoding":"UTF-8"}�[39m
�[33mWarning: Object src/xxxx/**/Tests/**/*Test.php,**/StoreBundle/Entity/*.php,vendor/**,app/cache/**,app/*.php has no method 'join'� Use --force to continue.�[39m

Then, is there an evolution in configuration format?

Support Grunt 1.0.1

Hi,
Would it be possible to support Grunt 1.0.1 as a peerDependency?

Regards
Darren

Support for JAVA_HOME env variable

We have a case where default installed java is 1.7 while SonarQube 5.6 requires JDK 1.8. For java builds we simply set the JAVA_HOME to point to the 1.8 version of JDK.

Unfortunately this does not work for our javascript builds because grunt-sonar-runner does not take it into account when finding java to run (which java is used).

I think it would be nice if grunt-server-runner would pick java from JAVA_HOME if it is set.

Support for -Dproject.home and sonar-project.properties

Hello,

Please add the option -Dproject.home to the java command. It should point to the directory where Gruntfile.js is and will allow Sonar Runner to detect the file sonar-project.properties.

I believe most projects have already this file configured like we do and will avoid have to move/convert all the content of this file inside Gruntfile.js.

I could help if needed, just ask ;)

Add support for 'sonar.javascript.lcov.reportPaths' property

Since SonarQube 6.2 property 'sonar.javascript.lcov.reportPath' is deprecated. 'sonar.javascript.lcov.reportPaths' should be used instead.

Log:

13:46:23.439 WARN  - Since SonarQube 6.2 property 'sonar.javascript.lcov.reportPath' is deprecated. Use 'sonar.javascript.lcov.reportPaths' instead.

Update to Sonar Runner 2.4

A while back sonar runner 2.4 was released. I replaced the current 2.3 version with the 2.4 version and everything worked flawless. Couldnt find any changelog on 2.4 but I think it should be updated

Sonar 4.3 fails with Error Code 143

I am trying to run the sonar-runner against our sonar server at version 4.3 and using your default settings. I get the following error:

15:08:37.636 DEBUG - File changed since previous analysis: /Users/sryan/GIT_WORKING/tuu/app/scripts/modules/categories/categoriesListController.js
15:08:37.637 INFO - Retrieve SCM info for /Users/sryan/GIT_WORKING/tuu/app/scripts/modules/categories/categoriesListController.js
15:08:37.637 INFO - Executing: /bin/sh -c cd /Users/sryan/GIT_WORKING/tuu/app/scripts/modules/categories && git blame --porcelain categoriesListController.js -w
15:08:37.637 INFO - Working directory: /Users/sryan/GIT_WORKING/tuu/app/scripts/modules/categories

15:08:37.655 DEBUG - [email protected] Jan 14, 2014 10:10:05 AM

Return code: 143.
Warning: Task "sonarRunner:analysis" failed. Used --force, continuing.

this may be due to an incremental analysis bug in Sonar that seems to have broken almost all of the plugins.

Dont force language 'js'

Hi,
recently I wanted to monitor my css and html files with sonar too.

According to the official documentation you can create a multi language project by just omitting the sonar.language property.

Now this case is being catched in your lib (file sonar_runner.js line 47)
I just changed this line to:

    if (options.sonar.language) {
        options.sonar.language = options.sonar.language || 'js';
    }

And it works without problems. Would be nice if you could change this.

Update grunt peerDependency

Please update the package.json to allow use with grunt 1.0.x

The package.json currently specifies the following peerDependency:

"peerDependencies": {
    "grunt": "~0.4.5"
},

npm does not consider ~0.4.5 to be compatible with 1.0.x
Please update to:

"peerDependencies": {
    "grunt": ">=0.4.5"
},

The grunt developers appear to have filed some automated pull requests that use >=0.4… (e.g. shootaroo/jit-grunt@08850b4), but it seems they didn't do one for grunt-sonar-runner…

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.