Sonar-runner in gradle

Deoas gradle 1.3 runs gradle runner? I need it for javascript analysis, thx from above

I don’t really understand the question, but Gradle integrates with Sonar via its Sonar plugin. See the user guide for more information.

http://docs.codehaus.org/display/SONAR/JavaScript+Plugin

I’m at home right now, but I’ve spent whole day on configuring

gradle with sonar plugin unsuccessfully, and then sonar-runner standalone this time it is worked ok. To assure you that I’ve some experience I successfully run sonar from gradle for Java and c++. Tomorrow I can provide results of command (and script listing) gradle sonar -i Everything went right and build was successful, but sensors run to quickly and then in sonar was empty project (no violations and so on). Then I checked with sonar-runner manually and results in sonar (the same server) was ok.

Of course you can execute the standalone Sonar runner with an ‘Exec’ task, but I wouldn’t recommend to do so. The Sonar plugin is easy to set up and works reliably.

I would like to run it from sonar plugin, I will provide you with my gradle script source, thanks for help. btw I thought about JavaExec task, because in standalone they use a batch to run application in jar.

one more thing comes to me: in documentation of sonar plugin you can read: By default, the Sonar plugin will analyze the production sources in the main source set and the test sources in the test source set

In case of projects with not java but javascript it is not needed. Because for instance javascript frequently is in the different directory than /src/main/java. And one more question is there specific sourceset for javascript? Maybe I’m wrong but I think that java/groovy etc. have their own implemented sourceSet class?

and in sonar you have to provide sourceSet as from yours docs example:

sonar.project {

sourceDirs += sourceSets.custom.allSource.srcDirs

testDirs += sourceSets.integTest.allSource.srcDirs }

I use also http://eriwen.github.com/gradle-js-plugin/ And I use as SourceSet its implementation and this could be wrong instead of this I will try to use simply

List<File>

Yes, ‘SonarProject.sourceDirs’ and ‘SonarProject.testDirs’ are just a ‘List<File>’. No need to use a source (directory) set.

and one more question as far as I know simple running sonar for two languages like javascript and java in the same subproject is not possible, maybe there is some kind of workaround?

No, Sonar doesn’t currently support this. For workarounds, best ask on the Sonar list.

Ok in the end I changed it to simple List and it worked like a charm! Thx Peter. I wanted to do it with javascript source from plugin and kill two birds with one stone, but it appeared to be wrong approach.

on thing more troubles me:

Last successful tokens:
-----------------------
  "{" at 8:39 consumed by objectLiteral
  "," at 8:38 consumed by arguments
  "group" at 8:33 consumed by arguments
  "." at 8:32 consumed by arguments
  "options" at 8:25 consumed by arguments
  "(" at 8:24 consumed by arguments
  "group" at 8:19 consumed by callExpression
  Sensor JavaScriptSquidSensor done: 2585 ms
Sensor JsTestCoverageSensor...
Sensor JsTestCoverageSensor done: 57 ms
Sensor JsTestSurefireSensor...
Sensor JsTestSurefireSensor done: 7 ms
Sensor CpdSensor...
SonarBridgeEngine is used
Cross-project analysis disabled
Sensor CpdSensor done: 549 ms
Sensor ProfileSensor...
Sensor ProfileSensor done: 47 ms
Sensor ProfileEventsSensor...
Sensor ProfileEventsSensor done: 31 ms
Sensor ProjectLinksSensor...
Sensor ProjectLinksSensor done: 7 ms
Sensor VersionEventsSensor...
Sensor VersionEventsSensor done: 15 ms
Execute decorators...
ANALYSIS SUCCESSFUL, you can browse http://172.18.129.180:9000
Executing post-job class org.sonar.plugins.core.batch.IndexProjectPostJob
Executing post-job class org.sonar.plugins.dbcleaner.ProjectPurgePostJob
-> Keep one snapshot per day between 2012-11-06 and 2012-12-03
-> Keep one snapshot per week between 2011-12-06 and 2012-11-06
-> Keep one snapshot per month between 2007-12-11 and 2011-12-06
-> Delete data prior to: 2007-12-11
-> Clean WebUI trunk [id=2]
<- Clean snapshot 1242
> Building > :sonarAnalyze

and it stays for very long time maybe forever

Not sure what you mean, but if analysis appears to hang, try to give the Gradle process more heap and permgen memory.

exactly I mean what you said

It helped thank you again!

Peter sonar plugin apparently doesn’t use jtestdriver and for sure I was unable to configure plugin to make Sonar pick up CodeCoverage data: jsTestDriver-coverage.conf.dat

Sonar Runner instead work smoothly.

sonar {
             // classpath += file("build/jstestdriver")
          branch = "trunk"
 server { url = "http://172.18.129.180:9000" }
 database {
  url = "jdbc:h2:tcp://172.18.129.180:9092/sonar"
  driverClassName = "org.h2.Driver"
  username = "sonar"
  password = "sonar"
 project {
  name = "WebUI"
        language = "js"
        version = "1.0"
        sourceDirs = ["wwwroot/assets/js","build/jstestdriver"]
        testDirs = ["wwwtest"]
  dynamicAnalysis
= "reuseReports"
        sourceEncoding = "UTF-8"
        testResultsDir ="build/jstestdriver"
        sourceExclusions "lib/*/*.js"
        withGlobalProperties { properties ->
            properties['sonar.verbose'] = "true"
        }
        withProjectProperties { props ->
   props["sonar.javascript.jstestdriver.reportsfolder"]="build/jstestdriver"
            props["sonar.javascript.jstestdriver.coveragefile"]="jsTestDriver-coverage.conf.dat"
  }
 }
 println "Sonar parameters used: server.url='${server.url}'; database.url='${database.url}'; database.driverClassName='${database.driverClassName}'; database.username='${database.username}'"
    println "$TESTOUTPUT"
    }
}

The Sonar plugin always runs in “reuse reports” mode. That is, you’ll have to run jstestdriver as part of the Gradle build, and then pass the generated reports on to Sonar.

Peter I did it. I spent three days and then given up with sonar plugin. I use JTestDriver as below it produces xml output and dat file. In both case sonar-runner and gradle sonar plugin it was successful to send a xml output to sonar. But dat file was picked up only in case of sonar-runner. Moreover Rules compliance ws fullfiled only in case of sonar - runner

ext {

BROWSER = “$browserPath”

TESTOUTPUT = “${buildDir}/jstestdriver” }

task init {

File reportDir = mkdir(TESTOUTPUT)

}

task runJTestDriver(type: JavaExec) {

dependsOn init

//extraDir = “war”

inputs.source “wwwroot/assets/js”

//inputs.dir sourceSets.main.output.resourcesDir

//outputs.dir “$buildDir/jstestdriver”

main = ‘com.google.jstestdriver.Main’

classpath {

[

configurations.jtestdriver,

files(“wwwroot/assets/js”),

files(“testroot”),

file(“plugins”),

files("$buildDir/jstestdriver"),

]

}

args =

[

“–config”, “jsTestDriver.conf”,

“–port”, “9876”,

“–browser”, “$BROWSER”,

“–tests”,“all”,

“–testOutput”, “$TESTOUTPUT”,

“–runnerMode”, “DEBUG”,

// “–plugins”, “e:\workspaces_old\webui\plugins\coverage.jar”,

“–verbose”

]

}

task runSonarRunner(type: JavaExec) {

dependsOn runJTestDriver

//extraDir = “war”

inputs.source “wwwroot/assets/js”

//inputs.dir sourceSets.main.output.resourcesDir

//outputs.dir “$buildDir/jstestdriver”

main = ‘org.sonar.runner.Main’

classpath {

[

configurations.sonnarRunner,

files(“wwwroot/assets/js”),

files(“testroot”),

file(“plugins”),

files("$buildDir/jstestdriver"),

]

}

args =

[

“-Drunner.home=$project.projectDir”,

“-Dproject.home=$project.projectDir”,

]

} <\code>