comparison metrics.gradle @ 126:b2532280341e

CM-133: switch to sonar-runner
author smith@nwoca.org
date Tue, 04 Jun 2013 16:50:46 +0100
parents 740e905fce78
children c93df17513f1
comparison
equal deleted inserted replaced
124:81a8ecfbc8fa 126:b2532280341e
1 1
2 apply plugin: "sonar" 2 apply plugin: "sonar-runner"
3
4 gradle.addListener(new SsdtSonarSettings())
5 3
6 ant.property(file: System.getProperty('user.home') + "/.ssdt/sonar.properties") 4 ant.property(file: System.getProperty('user.home') + "/.ssdt/sonar.properties")
7 5
8 buildscript { 6 buildscript {
9 repositories { 7 repositories {
15 classpath "me.davesmith:gradle-cobertura-plugin:1.0.2.SNAPSHOT" 13 classpath "me.davesmith:gradle-cobertura-plugin:1.0.2.SNAPSHOT"
16 classpath "net.sourceforge.cobertura:cobertura:1.9.4.1" 14 classpath "net.sourceforge.cobertura:cobertura:1.9.4.1"
17 } 15 }
18 } 16 }
19 17
20 18 sonarRunner {
21 sonar { 19 sonarProperties {
22 server { 20 property "sonar.host.url", "http://sonar.ssdt-ohio.org/"
23 url = "http://sonar.ssdt-ohio.org" 21 property "sonar.jdbc.url", ant.properties['sonar.jdbc.url']
24 } 22 property "sonar.jdbc.driverClassName", ant.properties['sonar.jdbc.driverClassName']
25 database { 23 property "sonar.jdbc.username", ant.properties['sonar.jdbc.username']
26 url = ant.properties['sonar.jdbc.url'] 24 property "sonar.jdbc.password", ant.properties['sonar.jdbc.password']
27 driverClassName = ant.properties['sonar.jdbc.driverClassName']
28 username = ant.properties['sonar.jdbc.username']
29 password = ant.properties['sonar.jdbc.password']
30 }
31 project {
32 dynamicAnalysis = "reuseReports"
33 sourceEncoding = "UTF-8"
34 }
35 withGlobalProperties { props ->
36 props["sonar.language"] = "grvy"
37 props['sonar.core.codeCoveragePlugin'] = 'cobertura'
38 } 25 }
39 } 26 }
40
41 class SsdtSonarSettings extends BuildAdapter implements BuildListener {
42
43 def void projectsEvaluated(Gradle gradle) {
44 Project root = gradle.getRootProject()
45 27
46 def testableProjects = root.allprojects.findAll { it.configurations.any { it.name.contains('test') } } 28 allprojects {
47 29 afterEvaluate { project ->
48 root.configure(testableProjects) { p -> 30
49 def usesGroovy = configurations.any { it.name == 'groovy' } 31 def groovyProject = project.plugins.hasPlugin('groovy')
50 apply plugin: net.saliman.gradle.plugin.cobertura.CoberturaPlugin 32
51 33 sonarRunner {
52 sonar { 34 sonarProperties {
53 project { 35 property "sonar.language", groovyProject ? 'grvy' : 'java'
54 language = usesGroovy ? 'groovy' : 'java'
55 dynamicAnalysis = "reuseReports"
56 sourceEncoding = "UTF-8"
57 coberturaReportPath = file("${reporting.baseDir}/cobertura/coverage.xml")
58 withProjectProperties { props ->
59 if (usesGroovy) {
60 println "setting groovy profile on $p"
61 props['sonar.profile'] = 'SSDT Groovy Way'
62 }
63 props['sonar.core.codeCoveragePlugin'] = 'cobertura'
64 props['sonar.cobertura.reportPath'] = "${reporting.baseDir}/cobertura/coverage.xml"
65 props["sonar.cpd.skip"] = true
66 props['sonar.language'] = usesGroovy ? 'grvy' : 'java'
67 }
68 }
69
70 } 36 }
71
72 cobertura {
73 if (usesGroovy) {
74 coverageSourceDirs = sourceSets.main.groovy.srcDirs
75 }
76 if (gradle.bambooBuild) {
77 coverageFormat = 'xml'
78 }
79 }
80
81 if (gradle.bambooBuild) {
82 build.dependsOn 'cobertura'
83 }
84
85 }
86
87 root.allprojects {
88
89 def thisProject = delegate
90 def usesGroovy = thisProject.configurations.any { it.name == 'groovy' }
91
92 sonar {
93 project {
94 language = usesGroovy ? 'groovy' : 'java'
95 dynamicAnalysis = "reuseReports"
96 sourceEncoding = "UTF-8"
97 withProjectProperties { props ->
98 props['sonar.core.codeCoveragePlugin'] = 'cobertura'
99 props['sonar.language'] = usesGroovy ? 'grvy' : 'java'
100 }
101 }
102 }
103
104 } 37 }
105 } 38 }
106 } 39 }