view metrics.gradle @ 119:740e905fce78

execute cobertura for bamboo builds
author smith@nwoca.org
date Sat, 03 Nov 2012 16:21:25 +0100
parents f84f1d5465c1
children b2532280341e
line wrap: on
line source

apply plugin: "sonar"

gradle.addListener(new SsdtSonarSettings())

ant.property(file: System.getProperty('user.home') + "/.ssdt/sonar.properties")

buildscript {
  repositories {
        maven { url 'http://repos.ssdt.nwoca.org/artifactory/gradle-plugins' }
        maven { url 'http://repos.ssdt.nwoca.org/artifactory/repository' }
        maven { url 'http://repos.ssdt.nwoca.org/artifactory/libs-snapshots' }
   }
    dependencies {
        classpath "me.davesmith:gradle-cobertura-plugin:1.0.2.SNAPSHOT"
        classpath "net.sourceforge.cobertura:cobertura:1.9.4.1"
    }
}


sonar {
    server {
        url = "http://sonar.ssdt-ohio.org"
    }
    database {
        url = ant.properties['sonar.jdbc.url']
        driverClassName = ant.properties['sonar.jdbc.driverClassName']
        username = ant.properties['sonar.jdbc.username']
        password = ant.properties['sonar.jdbc.password']
    }
    project {
        dynamicAnalysis = "reuseReports"     
        sourceEncoding = "UTF-8"                    
    }  
    withGlobalProperties { props ->
        props["sonar.language"] = "grvy"
        props['sonar.core.codeCoveragePlugin'] = 'cobertura'
    }
}
    
class SsdtSonarSettings extends BuildAdapter implements BuildListener {
    
    def void projectsEvaluated(Gradle gradle) {    
        Project root = gradle.getRootProject()  

        def testableProjects = root.allprojects.findAll { it.configurations.any { it.name.contains('test') } }
        
        root.configure(testableProjects) { p ->
            def usesGroovy = configurations.any { it.name == 'groovy' } 
            apply plugin: net.saliman.gradle.plugin.cobertura.CoberturaPlugin
                        
            sonar {
                project {
                    language = usesGroovy ? 'groovy' : 'java'
                    dynamicAnalysis = "reuseReports"     
                    sourceEncoding = "UTF-8"                    
                    coberturaReportPath = file("${reporting.baseDir}/cobertura/coverage.xml")                   
                    withProjectProperties { props ->
                        if (usesGroovy) {
                            println "setting groovy profile on $p"
                            props['sonar.profile'] = 'SSDT Groovy Way'
                        }
                        props['sonar.core.codeCoveragePlugin'] = 'cobertura'
                        props['sonar.cobertura.reportPath'] = "${reporting.baseDir}/cobertura/coverage.xml"
                        props["sonar.cpd.skip"] = true
                        props['sonar.language'] = usesGroovy ? 'grvy' : 'java'
                    }                    
                }
                
            }
              
            cobertura {
                if (usesGroovy) {
                    coverageSourceDirs = sourceSets.main.groovy.srcDirs
                }            
                if (gradle.bambooBuild) {
                    coverageFormat = 'xml'
                }
            }

            if (gradle.bambooBuild) {
                build.dependsOn 'cobertura'
            }

        }
        
        root.allprojects { 
 
            def thisProject = delegate     
            def usesGroovy = thisProject.configurations.any { it.name == 'groovy' } 
             
            sonar {
                project {                            
                    language = usesGroovy ? 'groovy' : 'java'
                    dynamicAnalysis = "reuseReports"     
                    sourceEncoding = "UTF-8"
                    withProjectProperties { props ->
                        props['sonar.core.codeCoveragePlugin'] = 'cobertura'
                        props['sonar.language'] = usesGroovy ? 'grvy' : 'java'
                    }                    
                }
            }
         
        }
    }
}