# HG changeset patch # User smith@nwoca.org # Date 1476913328 -3600 # Node ID 400f9d8bbf5b4806f4a1765347050fd31a3cf2c8 # Parent 47535c8358ced150e698f2d07598960140500ec3 DEP-13: enable sonar analysis for gradle 3.1 projects. disable sonar for ant based projects diff -r 47535c8358ce -r 400f9d8bbf5b init20.gradle --- 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 { diff -r 47535c8358ce -r 400f9d8bbf5b metrics.gradle --- 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/" diff -r 47535c8358ce -r 400f9d8bbf5b sonar-ant.xml --- 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 @@ - - Sonar Ant tasks - - - - - - - - - - - - - - - - - - - - - - + xmlns:ivy="antlib:fr.jayasoft.ivy.ant"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. (sonar) + Sonar Ant tasks - disabled 19-Oct-2016/djs + + +