changeset 233:400f9d8bbf5b

DEP-13: enable sonar analysis for gradle 3.1 projects. disable sonar for ant based projects
author smith@nwoca.org
date Wed, 19 Oct 2016 22:42:08 +0100
parents 47535c8358ce
children 49e9edc80170
files init20.gradle metrics.gradle sonar-ant.xml
diffstat 3 files changed, 116 insertions(+), 159 deletions(-) [+]
line wrap: on
line diff
--- a/init20.gradle	Tue Oct 18 18:29:04 2016 +0100
+++ b/init20.gradle	Wed Oct 19 22:42:08 2016 +0100
@@ -5,17 +5,19 @@
 
 buildscript {
     repositories {
-		maven { url 'http://repos.ssdt.nwoca.org/artifactory/gradle-plugins' }
+        maven { url 'http://repos.ssdt.nwoca.org/artifactory/gradle-plugins' }
         maven { url 'http://repos.ssdt.nwoca.org/artifactory/ssdt-repo' }
     }
-	dependencies {
-		classpath 'postgresql:postgresql:9.1-901.jdbc4'
-		classpath  'com.netflix.nebula:gradle-dependency-lock-plugin:4.3.0'
-	}
+    dependencies {
+        classpath 'postgresql:postgresql:9.1-901.jdbc4'
+        classpath  'com.netflix.nebula:gradle-dependency-lock-plugin:4.3.0'
+    }
 }
 
 final GradleVersion gradleCurrent = GradleVersion.current()
 final GradleVersion gradleV20 = GradleVersion.version('2.0')
+final GradleVersion gradleV31 = GradleVersion.version('3.1')
+
 println "Gradle Version: $gradleCurrent"
 
 if (gradleCurrent < gradleV20) {
@@ -88,8 +90,8 @@
 
 def cacheTimeout = 60 * 60 * 8 
 if (gradle.environment['dependencyTimeout']) {
-	cacheTimeout = gradle.environment['dependencyTimeout'] as Integer
-	println "setting changing dependency timeout to $cacheTimeout seconds"	
+    cacheTimeout = gradle.environment['dependencyTimeout'] as Integer
+    println "setting changing dependency timeout to $cacheTimeout seconds"  
 }
 
 gradle.ext.cacheTimeout = cacheTimeout 
@@ -135,9 +137,9 @@
 
 rootProject.afterEvaluate { r ->
 
-	if (gradle.bambooBuild && r.hasProperty('requireJavaVersion')) {
-		gradle.runtimeInfo.requireJava( r.getProperty('requireJavaVersion') )
-	}
+    if (gradle.bambooBuild && r.hasProperty('requireJavaVersion')) {
+        gradle.runtimeInfo.requireJava( r.getProperty('requireJavaVersion') )
+    }
 
     if (r.plugins.hasPlugin(org.gradle.plugins.ide.idea.IdeaPlugin)) {
 
@@ -225,9 +227,15 @@
     project.component.find { it.@name == name }
 }
 
+if (gradleCurrent >= gradleV31) {
+   wrapper {
+        distributionType = org.gradle.api.tasks.wrapper.Wrapper.DistributionType.ALL
+   }
+}
+
 allprojects {
 
-	apply plugin: nebula.plugin.dependencylock.DependencyLockPlugin
+    apply plugin: nebula.plugin.dependencylock.DependencyLockPlugin
 
     dependencyLock {
         globalLockFile =  gradle.branch.isRelease() ? 'release.lock' : 'global.lock'
@@ -240,10 +248,10 @@
     configurations.all {
         resolutionStrategy.eachDependency { DependencyResolveDetails details ->
             if (details.requested.group == 'org.ssdt_ohio' && !details.requested.version ) {
-				details.useVersion( "latest.${gradle.branch.defaultDependencyStatus}" )
+                details.useVersion( "latest.${gradle.branch.defaultDependencyStatus}" )
             }
             if (details.requested.version == 'default') {
-				details.useVersion("latest.${gradle.branch.defaultDependencyStatus}" )
+                details.useVersion("latest.${gradle.branch.defaultDependencyStatus}" )
             }
             if (project.hasProperty("overrideCommon")) {
                if (details.requested.group == 'org.ssdt_ohio' && details.requested.name.contains('ssdt.common.')) {
@@ -280,7 +288,7 @@
             def t = taskName.contains('Test') ? sourceSets.test.output.resourcesDir : sourceSets.main.output.resourcesDir
             def e = (taskName - 'Test' - 'AsProperties').capitalize()
             task(taskName) {
-				ext.outputDir = t
+                ext.outputDir = t
                 ext.propertyFile = "${e.toLowerCase()}.properties"
                 ext.buildenv = project.file('build/buildenv.txt')
                 inputs.files project.file("../environment${e}.groovy"), project.file("../private${e}.groovy"), project.file('../private.properties')
@@ -293,8 +301,8 @@
                     buildenv.text = gradle.env
                     def ps = gradle."environment${e}".toProperties()
                     ps['ssdt.project'] = project.name
-					def pf = new File(outputDir,propertyFile)
-					ext.outputPropertyFile = pf
+                    def pf = new File(outputDir,propertyFile)
+                    ext.outputPropertyFile = pf
                     ps.store(pf.newOutputStream(), "by $taskName of $this")
                     def l = pf.readLines().sort()
                     pf.text = l.join('\n')
@@ -332,10 +340,10 @@
                                 gradle.environmentDatabase.jdbc.password,
                                 driverName)
                         if (dropIt) {
-							logger.info "disconnecting sessions from $databaseName"
-							sql.execute "REVOKE CONNECT ON DATABASE \"" + databaseName + "\" FROM public;"
-							sql.execute "REVOKE CONNECT ON DATABASE \"" + databaseName + "\" FROM " + gradle.environmentDatabase.jdbc.username + ";"
-							sql.execute "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '" + databaseName + "';"
+                            logger.info "disconnecting sessions from $databaseName"
+                            sql.execute "REVOKE CONNECT ON DATABASE \"" + databaseName + "\" FROM public;"
+                            sql.execute "REVOKE CONNECT ON DATABASE \"" + databaseName + "\" FROM " + gradle.environmentDatabase.jdbc.username + ";"
+                            sql.execute "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '" + databaseName + "';"
                             logger.info "dropping $databaseName (if exists) from $adminUrl"
                             sql.execute 'DROP DATABASE IF EXISTS "' + databaseName + '";'
                         }
@@ -521,17 +529,17 @@
                 }
 
             }
-			
-			def remoteRepos = thisProject.repositories.findAll { it.hasProperty('url') && !(it.name == 'local' || it.url.toString().contains('ssdt')) }	
-			if (remoteRepos) {
-				logger.warn "WARNING: Remote repositories configured for $thisProject:\n" + remoteRepos.collect { "\t$it.name $it.url " }.join('\n')  + "\n Moved to lowest priority..."
-				remoteRepos.each {
-					thisProject.repositories.remove(it)
-					thisProject.repositories.addLast(it)
-				}
-			}
-			logger.info "$thisProject configured repositories:\n" + thisProject.repositories.collect {"\t$it.name ${it.hasProperty('url') ? it.url : '' }" }.join('\n')
-			
+            
+            def remoteRepos = thisProject.repositories.findAll { it.hasProperty('url') && !(it.name == 'local' || it.url.toString().contains('ssdt')) } 
+            if (remoteRepos) {
+                logger.warn "WARNING: Remote repositories configured for $thisProject:\n" + remoteRepos.collect { "\t$it.name $it.url " }.join('\n')  + "\n Moved to lowest priority..."
+                remoteRepos.each {
+                    thisProject.repositories.remove(it)
+                    thisProject.repositories.addLast(it)
+                }
+            }
+            logger.info "$thisProject configured repositories:\n" + thisProject.repositories.collect {"\t$it.name ${it.hasProperty('url') ? it.url : '' }" }.join('\n')
+            
 
             if (thisProject.repositories.find { it.name == 'local' } && thisProject.getTasksByName('uploadArchives', false)) {
                 uploadArchives {
@@ -603,10 +611,10 @@
 
     def environment = slurper.parse(
             '''deploy.mode="production"
-	   environments {
-		test { deploy.mode="test" }
-		dev { deploy.mode="development"}
-	   }''')
+       environments {
+        test { deploy.mode="test" }
+        dev { deploy.mode="development"}
+       }''')
     if (developerPrivate['deploy.mode']) {
         environment.put('deploy.mode', developerPrivate['deploy.mode'])
     }
@@ -661,7 +669,7 @@
     // OS memory in megabytes, zero if unknown
     int systemMemory = 0
     int systemFreeMemory = 0
-	String javaVersion = System.getProperty('java.version')
+    String javaVersion = System.getProperty('java.version')
 
     RuntimeInfo() {
         try {
@@ -674,28 +682,28 @@
         } catch (e) {  }
 
     }
-	
-	void requireMemory(int megabytes) {
-		if (systemFreeMemory > 0 && systemFreeMemory < megabytes) {
-			throw new GradleException("insufficent free OS memory for this build (available: ${systemFreeMemory}m, required: ${megabytes}m)")
-		}
-	}
-	/**
-	* Returns maximum memory available upto the value specified. 
-	*/
-	int maxMemory(int megabytes) {
-	   if (systemFreeMemory) {
-			[systemFreeMemory,megabytes].min()
-	   } else { megabytes }
-	
-	}
-	
-	void requireJava(String version) {
-	
-		if ( version && !javaVersion.startsWith(version)) {
-			throw new GradleException("Requires java version $version but running under $javaVersion")
-		}
-	}
+    
+    void requireMemory(int megabytes) {
+        if (systemFreeMemory > 0 && systemFreeMemory < megabytes) {
+            throw new GradleException("insufficent free OS memory for this build (available: ${systemFreeMemory}m, required: ${megabytes}m)")
+        }
+    }
+    /**
+    * Returns maximum memory available upto the value specified. 
+    */
+    int maxMemory(int megabytes) {
+       if (systemFreeMemory) {
+            [systemFreeMemory,megabytes].min()
+       } else { megabytes }
+    
+    }
+    
+    void requireJava(String version) {
+    
+        if ( version && !javaVersion.startsWith(version)) {
+            throw new GradleException("Requires java version $version but running under $javaVersion")
+        }
+    }
 
 }
 
@@ -744,8 +752,8 @@
 class BranchInfo {
     def name
     def stream = "none"
-	def buildNumber = ""	
-	def changeset = ""
+    def buildNumber = ""    
+    def changeset = ""
     def version
 
     BranchInfo(name) {
@@ -755,26 +763,26 @@
         }
         this.name = this.name.replace('@', '-')
         determineStream()
-		buildNumber = System.getenv('bamboo_buildNumber') ?: ""
-		changeset = System.getenv('bamboo_planRepository_revision') ?: ""
-	}
-	
-	String getDefaultDependencyStatus() {
-		return isRelease() ? 'release' : 'integration'
-	}
+        buildNumber = System.getenv('bamboo_buildNumber') ?: ""
+        changeset = System.getenv('bamboo_planRepository_revision') ?: ""
+    }
+    
+    String getDefaultDependencyStatus() {
+        return isRelease() ? 'release' : 'integration'
+    }
 
     private boolean isRelease() {
         return stream in ['release', 'hotfix']
     }
 
     def getShortName() {
-		def result = name.contains('/') ? name.split('/')[1] : name 
-	} 
-	
-	String getBuildVersion() {
-		def v = isRelease() ? shortName - "v": ""
+        def result = name.contains('/') ? name.split('/')[1] : name 
+    } 
+    
+    String getBuildVersion() {
+        def v = isRelease() ? shortName - "v": ""
         return v
-	}
+    }
 
     def Version getVersion() {
         if (!version) {
@@ -788,15 +796,15 @@
     }
 
     def getImageId() {
-		(buildVersion ?:  shortName.take(25)) + (buildNumber ? "-${buildNumber}" : "-0")
-	}
+        (buildVersion ?:  shortName.take(25)) + (buildNumber ? "-${buildNumber}" : "-0")
+    }
 
-	def getDeployName() {
-		(buildVersion ?:  shortName.take(25)).toLowerCase().collectReplacements {
-			('a'..'z').contains(it) || ('0'..'9').contains(it) || it == "-" ? null : '-'
-		}
-	}
-	
+    def getDeployName() {
+        (buildVersion ?:  shortName.take(25)).toLowerCase().collectReplacements {
+            ('a'..'z').contains(it) || ('0'..'9').contains(it) || it == "-" ? null : '-'
+        }
+    }
+    
     def getHash() {
         generateMD5(name)
     }
@@ -807,10 +815,10 @@
     }
 
     private findSnapshotVersion() {
-		def repositoryUrl = System.getenv('bamboo_planRepository_repositoryUrl')
-		if (repositoryUrl) { 
-			println "hg pull $repositoryUrl".execute().text 
-		}
+        def repositoryUrl = System.getenv('bamboo_planRepository_repositoryUrl')
+        if (repositoryUrl) { 
+            println "hg pull $repositoryUrl".execute().text 
+        }
         def versions = "hg branches --closed".execute().text.split('\n').findAll {
             it.startsWith( 'release') || it.startsWith( 'hotfix')
         }.collect {
--- a/metrics.gradle	Tue Oct 18 18:29:04 2016 +0100
+++ b/metrics.gradle	Wed Oct 19 22:42:08 2016 +0100
@@ -2,11 +2,7 @@
 final GradleVersion gradleV31 = GradleVersion.version('3.1')
 
 final boolean legacySonar = gradleCurrent < gradleV31
-
-if (legacySonar) {
-    apply plugin: "sonar-runner"
-    ant.property(file: System.getProperty('user.home') + "/.ssdt/sonar.properties")
-}
+final boolean newSonar = !legacySonar
 
 buildscript {
     repositories {
@@ -15,9 +11,11 @@
     }
     dependencies {
         classpath 'me.davesmith:jaranalyzerplugin:0.2.0-SNAPSHOT'
+        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2"
     }
 }
 
+
 apply plugin: me.davesmith.gradle.plugins.jaranalyzer.JarAnalyzerPlugin
 
 jaranalyzer {
@@ -26,16 +24,26 @@
     packageFilter += 'groovyx.*'
 }
 
-if (!legacySonar) {
+
+if (newSonar) {
 
-   task('sonar') << {
-        println "sonar analysis currently disabled"
-   }
-
+    apply plugin: org.sonarqube.gradle.SonarQubePlugin
+    
+    sonarqube {
+        properties {
+            property "sonar.host.url", "https://sonar.ssdt.io"
+            property "sonar.login", System.getenv('bamboo_SONAR_TOKEN')
+            property "sonar.exclusions","**/ProjectVersion*"
+        }
+    }
+    
 }
 
 if (legacySonar) {
 
+    apply plugin: "sonar-runner"
+    ant.property(file: System.getProperty('user.home') + "/.ssdt/sonar.properties")
+
     sonarRunner {
         sonarProperties {
             property "sonar.host.url", "http://sonar.ssdt-ohio.org/"
--- a/sonar-ant.xml	Tue Oct 18 18:29:04 2016 +0100
+++ b/sonar-ant.xml	Wed Oct 19 22:42:08 2016 +0100
@@ -1,70 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project name="sonar-project-tasks" default="" basedir="."
-         xmlns:ivy="antlib:fr.jayasoft.ivy.ant"
-         xmlns:sonar="antlib:org.sonar.ant"
-         xmlns:ssdt="http://www.ssdt-ohio.org/ant/common"
-         xmlns:ssdtant="antlib:org.ssdt_ohio.tools.ant">
-
-    <description>Sonar Ant tasks</description>
-
-    <property           name="ssdt.sonar.jar.src"
-                        value="http://ivy.ssdt.nwoca.org/repository/sonar/sonar-ant-task.jar"/>
-    <ssdt:fetch         dest="${user.home.ant.lib}/sonar.jar"
-                        src="${ssdt.sonar.jar.src}"/>
-    <ssdt:import-ant    file="jacoco-ant.xml"/>
-
-    <ssdtant:add-dependency target="init" depends="-sonar-init"/>
-
-    <target name="-sonar-init">
-        <if>
-            <isset property="sonar.enabled"/>
-            <then>
-                <echo message="Sonar: Active"/>
-            </then>
-        </if>
-        <if>
-            <contains string="${ant.project.invoked-targets}" substring="sonar"/>
-            <then>
-                <property name="ignore.failing.tests" value="true"/>
-            </then>
-        </if>
-        <property name="sonar.active" value="true"/>
-    </target>
+         xmlns:ivy="antlib:fr.jayasoft.ivy.ant">
 
-    <target name="-check-sonar">
-        <property file="${ssdt.devel.kit}/sonar.properties"/>
-        <property name="sonar.host.url" value="http://ssdt-web-10.nwoca.org:9000" />
-        <property name="sonar.language" value="grvy"/>
-        <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml"/>
-    </target>
-
-    <target name="sonar" depends="project.init,-check-sonar,ivy-info,coverage.xml" if="sonar.enabled">
-        <fail unless="sonar.active" message="Sonar has not been initialized"/>
-        <property name="sonar.projectname" value="${ivy.project.module}"/>
-        <sonar:sonar
-            workDir="${build.dir}/sonar"
-            key="${ivy.project.organisation}:${sonar.projectname}"
-            version="${project.version}"  >
-            <sources>
-                <path location="${src.dir}" />
-            </sources>
-            <property key="sonar.core.codeCoveragePlugin" value="jacoco"/>
-            <property key="sonar.projectName" value="${sonar.projectname}"/>
-            <property key="sonar.language" value="${sonar.language}" />
-            <property key="sonar.java.source" value="${javac.source}" />
-            <property key="sonar.java.target" value="${java.target}" />                     
-            <property key="sonar.dynamicAnalysis" value="reuseReports" />
-            <property key="sonar.surefire.reportsPath" value="${build.test.results.dir}"/>
-            <property key="sonar.jacoco.reportPath" value="${jacoco.data.file}"/>
-            <property key="sonar.jacoco.itReportPath" value="${jacoco.data.file}"/>
-            <tests>
-                <path location="${test.src.dir}" />
-            </tests>
-            <binaries>
-                <path location="${build.classes.dir}" />
-            </binaries>
-        </sonar:sonar>
-        <fail if="tests.failed" unless="sonar.use.build.breaker">Some tests failed; see details above. (sonar)</fail>
+    <description>Sonar Ant tasks - disabled 19-Oct-2016/djs</description>
+    
+    <target name="sonar" if="sonar.enabled">
+        <echo message="ant based sonar analysis has been dislabled"/>
     </target>
 
 </project>