Mercurial > public > develkit
comparison init20.gradle @ 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 | 05a1bbd319bc |
comparison
equal
deleted
inserted
replaced
232:47535c8358ce | 233:400f9d8bbf5b |
---|---|
3 import groovy.transform.ToString | 3 import groovy.transform.ToString |
4 import groovy.transform.TupleConstructor | 4 import groovy.transform.TupleConstructor |
5 | 5 |
6 buildscript { | 6 buildscript { |
7 repositories { | 7 repositories { |
8 maven { url 'http://repos.ssdt.nwoca.org/artifactory/gradle-plugins' } | 8 maven { url 'http://repos.ssdt.nwoca.org/artifactory/gradle-plugins' } |
9 maven { url 'http://repos.ssdt.nwoca.org/artifactory/ssdt-repo' } | 9 maven { url 'http://repos.ssdt.nwoca.org/artifactory/ssdt-repo' } |
10 } | 10 } |
11 dependencies { | 11 dependencies { |
12 classpath 'postgresql:postgresql:9.1-901.jdbc4' | 12 classpath 'postgresql:postgresql:9.1-901.jdbc4' |
13 classpath 'com.netflix.nebula:gradle-dependency-lock-plugin:4.3.0' | 13 classpath 'com.netflix.nebula:gradle-dependency-lock-plugin:4.3.0' |
14 } | 14 } |
15 } | 15 } |
16 | 16 |
17 final GradleVersion gradleCurrent = GradleVersion.current() | 17 final GradleVersion gradleCurrent = GradleVersion.current() |
18 final GradleVersion gradleV20 = GradleVersion.version('2.0') | 18 final GradleVersion gradleV20 = GradleVersion.version('2.0') |
19 final GradleVersion gradleV31 = GradleVersion.version('3.1') | |
20 | |
19 println "Gradle Version: $gradleCurrent" | 21 println "Gradle Version: $gradleCurrent" |
20 | 22 |
21 if (gradleCurrent < gradleV20) { | 23 if (gradleCurrent < gradleV20) { |
22 throw new RuntimeException("this init script requires Gradle version 2.0 or higher") | 24 throw new RuntimeException("this init script requires Gradle version 2.0 or higher") |
23 } | 25 } |
86 gradle.environment.put('branchHash', gradle.branch.hash) | 88 gradle.environment.put('branchHash', gradle.branch.hash) |
87 | 89 |
88 | 90 |
89 def cacheTimeout = 60 * 60 * 8 | 91 def cacheTimeout = 60 * 60 * 8 |
90 if (gradle.environment['dependencyTimeout']) { | 92 if (gradle.environment['dependencyTimeout']) { |
91 cacheTimeout = gradle.environment['dependencyTimeout'] as Integer | 93 cacheTimeout = gradle.environment['dependencyTimeout'] as Integer |
92 println "setting changing dependency timeout to $cacheTimeout seconds" | 94 println "setting changing dependency timeout to $cacheTimeout seconds" |
93 } | 95 } |
94 | 96 |
95 gradle.ext.cacheTimeout = cacheTimeout | 97 gradle.ext.cacheTimeout = cacheTimeout |
96 | 98 |
97 rootProject.ext.indyCapable = { | 99 rootProject.ext.indyCapable = { |
133 | 135 |
134 apply from: "${gradle.ssdtDevelkitLocation}/metrics.gradle" | 136 apply from: "${gradle.ssdtDevelkitLocation}/metrics.gradle" |
135 | 137 |
136 rootProject.afterEvaluate { r -> | 138 rootProject.afterEvaluate { r -> |
137 | 139 |
138 if (gradle.bambooBuild && r.hasProperty('requireJavaVersion')) { | 140 if (gradle.bambooBuild && r.hasProperty('requireJavaVersion')) { |
139 gradle.runtimeInfo.requireJava( r.getProperty('requireJavaVersion') ) | 141 gradle.runtimeInfo.requireJava( r.getProperty('requireJavaVersion') ) |
140 } | 142 } |
141 | 143 |
142 if (r.plugins.hasPlugin(org.gradle.plugins.ide.idea.IdeaPlugin)) { | 144 if (r.plugins.hasPlugin(org.gradle.plugins.ide.idea.IdeaPlugin)) { |
143 | 145 |
144 r.idea.project.ipr.withXml { xml -> | 146 r.idea.project.ipr.withXml { xml -> |
145 if (file('.hg').exists()) { | 147 if (file('.hg').exists()) { |
223 | 225 |
224 def findComponent(project, name) { | 226 def findComponent(project, name) { |
225 project.component.find { it.@name == name } | 227 project.component.find { it.@name == name } |
226 } | 228 } |
227 | 229 |
230 if (gradleCurrent >= gradleV31) { | |
231 wrapper { | |
232 distributionType = org.gradle.api.tasks.wrapper.Wrapper.DistributionType.ALL | |
233 } | |
234 } | |
235 | |
228 allprojects { | 236 allprojects { |
229 | 237 |
230 apply plugin: nebula.plugin.dependencylock.DependencyLockPlugin | 238 apply plugin: nebula.plugin.dependencylock.DependencyLockPlugin |
231 | 239 |
232 dependencyLock { | 240 dependencyLock { |
233 globalLockFile = gradle.branch.isRelease() ? 'release.lock' : 'global.lock' | 241 globalLockFile = gradle.branch.isRelease() ? 'release.lock' : 'global.lock' |
234 includeTransitives = true | 242 includeTransitives = true |
235 } | 243 } |
238 resolutionStrategy.cacheDynamicVersionsFor gradle.cacheTimeout, 'seconds' | 246 resolutionStrategy.cacheDynamicVersionsFor gradle.cacheTimeout, 'seconds' |
239 } | 247 } |
240 configurations.all { | 248 configurations.all { |
241 resolutionStrategy.eachDependency { DependencyResolveDetails details -> | 249 resolutionStrategy.eachDependency { DependencyResolveDetails details -> |
242 if (details.requested.group == 'org.ssdt_ohio' && !details.requested.version ) { | 250 if (details.requested.group == 'org.ssdt_ohio' && !details.requested.version ) { |
243 details.useVersion( "latest.${gradle.branch.defaultDependencyStatus}" ) | 251 details.useVersion( "latest.${gradle.branch.defaultDependencyStatus}" ) |
244 } | 252 } |
245 if (details.requested.version == 'default') { | 253 if (details.requested.version == 'default') { |
246 details.useVersion("latest.${gradle.branch.defaultDependencyStatus}" ) | 254 details.useVersion("latest.${gradle.branch.defaultDependencyStatus}" ) |
247 } | 255 } |
248 if (project.hasProperty("overrideCommon")) { | 256 if (project.hasProperty("overrideCommon")) { |
249 if (details.requested.group == 'org.ssdt_ohio' && details.requested.name.contains('ssdt.common.')) { | 257 if (details.requested.group == 'org.ssdt_ohio' && details.requested.name.contains('ssdt.common.')) { |
250 details.useVersion(project.overrideCommon) | 258 details.useVersion(project.overrideCommon) |
251 } | 259 } |
278 if ((taskName - 'Test').endsWith("AsProperties") && !taskName.startsWith('clean')) { | 286 if ((taskName - 'Test').endsWith("AsProperties") && !taskName.startsWith('clean')) { |
279 // def t = taskName.contains('Test') ? processTestResources.destinationDir : processResources.destinationDir | 287 // def t = taskName.contains('Test') ? processTestResources.destinationDir : processResources.destinationDir |
280 def t = taskName.contains('Test') ? sourceSets.test.output.resourcesDir : sourceSets.main.output.resourcesDir | 288 def t = taskName.contains('Test') ? sourceSets.test.output.resourcesDir : sourceSets.main.output.resourcesDir |
281 def e = (taskName - 'Test' - 'AsProperties').capitalize() | 289 def e = (taskName - 'Test' - 'AsProperties').capitalize() |
282 task(taskName) { | 290 task(taskName) { |
283 ext.outputDir = t | 291 ext.outputDir = t |
284 ext.propertyFile = "${e.toLowerCase()}.properties" | 292 ext.propertyFile = "${e.toLowerCase()}.properties" |
285 ext.buildenv = project.file('build/buildenv.txt') | 293 ext.buildenv = project.file('build/buildenv.txt') |
286 inputs.files project.file("../environment${e}.groovy"), project.file("../private${e}.groovy"), project.file('../private.properties') | 294 inputs.files project.file("../environment${e}.groovy"), project.file("../private${e}.groovy"), project.file('../private.properties') |
287 outputs.files new File(outputDir,propertyFile), buildenv | 295 outputs.files new File(outputDir,propertyFile), buildenv |
288 outputs.upToDateWhen { | 296 outputs.upToDateWhen { |
291 doLast { | 299 doLast { |
292 t.mkdirs() | 300 t.mkdirs() |
293 buildenv.text = gradle.env | 301 buildenv.text = gradle.env |
294 def ps = gradle."environment${e}".toProperties() | 302 def ps = gradle."environment${e}".toProperties() |
295 ps['ssdt.project'] = project.name | 303 ps['ssdt.project'] = project.name |
296 def pf = new File(outputDir,propertyFile) | 304 def pf = new File(outputDir,propertyFile) |
297 ext.outputPropertyFile = pf | 305 ext.outputPropertyFile = pf |
298 ps.store(pf.newOutputStream(), "by $taskName of $this") | 306 ps.store(pf.newOutputStream(), "by $taskName of $this") |
299 def l = pf.readLines().sort() | 307 def l = pf.readLines().sort() |
300 pf.text = l.join('\n') | 308 pf.text = l.join('\n') |
301 } | 309 } |
302 } | 310 } |
330 def sql = Sql.newInstance(adminUrl, | 338 def sql = Sql.newInstance(adminUrl, |
331 gradle.environmentDatabase.jdbc.username, | 339 gradle.environmentDatabase.jdbc.username, |
332 gradle.environmentDatabase.jdbc.password, | 340 gradle.environmentDatabase.jdbc.password, |
333 driverName) | 341 driverName) |
334 if (dropIt) { | 342 if (dropIt) { |
335 logger.info "disconnecting sessions from $databaseName" | 343 logger.info "disconnecting sessions from $databaseName" |
336 sql.execute "REVOKE CONNECT ON DATABASE \"" + databaseName + "\" FROM public;" | 344 sql.execute "REVOKE CONNECT ON DATABASE \"" + databaseName + "\" FROM public;" |
337 sql.execute "REVOKE CONNECT ON DATABASE \"" + databaseName + "\" FROM " + gradle.environmentDatabase.jdbc.username + ";" | 345 sql.execute "REVOKE CONNECT ON DATABASE \"" + databaseName + "\" FROM " + gradle.environmentDatabase.jdbc.username + ";" |
338 sql.execute "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '" + databaseName + "';" | 346 sql.execute "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '" + databaseName + "';" |
339 logger.info "dropping $databaseName (if exists) from $adminUrl" | 347 logger.info "dropping $databaseName (if exists) from $adminUrl" |
340 sql.execute 'DROP DATABASE IF EXISTS "' + databaseName + '";' | 348 sql.execute 'DROP DATABASE IF EXISTS "' + databaseName + '";' |
341 } | 349 } |
342 | 350 |
343 if (createIt) { | 351 if (createIt) { |
519 name = 'ssdt-repository' | 527 name = 'ssdt-repository' |
520 url = "${ssdtArtifactory}/repository" | 528 url = "${ssdtArtifactory}/repository" |
521 } | 529 } |
522 | 530 |
523 } | 531 } |
524 | 532 |
525 def remoteRepos = thisProject.repositories.findAll { it.hasProperty('url') && !(it.name == 'local' || it.url.toString().contains('ssdt')) } | 533 def remoteRepos = thisProject.repositories.findAll { it.hasProperty('url') && !(it.name == 'local' || it.url.toString().contains('ssdt')) } |
526 if (remoteRepos) { | 534 if (remoteRepos) { |
527 logger.warn "WARNING: Remote repositories configured for $thisProject:\n" + remoteRepos.collect { "\t$it.name $it.url " }.join('\n') + "\n Moved to lowest priority..." | 535 logger.warn "WARNING: Remote repositories configured for $thisProject:\n" + remoteRepos.collect { "\t$it.name $it.url " }.join('\n') + "\n Moved to lowest priority..." |
528 remoteRepos.each { | 536 remoteRepos.each { |
529 thisProject.repositories.remove(it) | 537 thisProject.repositories.remove(it) |
530 thisProject.repositories.addLast(it) | 538 thisProject.repositories.addLast(it) |
531 } | 539 } |
532 } | 540 } |
533 logger.info "$thisProject configured repositories:\n" + thisProject.repositories.collect {"\t$it.name ${it.hasProperty('url') ? it.url : '' }" }.join('\n') | 541 logger.info "$thisProject configured repositories:\n" + thisProject.repositories.collect {"\t$it.name ${it.hasProperty('url') ? it.url : '' }" }.join('\n') |
534 | 542 |
535 | 543 |
536 if (thisProject.repositories.find { it.name == 'local' } && thisProject.getTasksByName('uploadArchives', false)) { | 544 if (thisProject.repositories.find { it.name == 'local' } && thisProject.getTasksByName('uploadArchives', false)) { |
537 uploadArchives { | 545 uploadArchives { |
538 repositories { | 546 repositories { |
539 add thisProject.repositories.local | 547 add thisProject.repositories.local |
601 def slurper = new ConfigSlurper(gradle.env) | 609 def slurper = new ConfigSlurper(gradle.env) |
602 slurper.setBinding(['gradle': gradle]) | 610 slurper.setBinding(['gradle': gradle]) |
603 | 611 |
604 def environment = slurper.parse( | 612 def environment = slurper.parse( |
605 '''deploy.mode="production" | 613 '''deploy.mode="production" |
606 environments { | 614 environments { |
607 test { deploy.mode="test" } | 615 test { deploy.mode="test" } |
608 dev { deploy.mode="development"} | 616 dev { deploy.mode="development"} |
609 }''') | 617 }''') |
610 if (developerPrivate['deploy.mode']) { | 618 if (developerPrivate['deploy.mode']) { |
611 environment.put('deploy.mode', developerPrivate['deploy.mode']) | 619 environment.put('deploy.mode', developerPrivate['deploy.mode']) |
612 } | 620 } |
613 | 621 |
614 environment.put('branchInfo',gradle.branch) | 622 environment.put('branchInfo',gradle.branch) |
659 @ToString(includeNames=true) | 667 @ToString(includeNames=true) |
660 class RuntimeInfo { | 668 class RuntimeInfo { |
661 // OS memory in megabytes, zero if unknown | 669 // OS memory in megabytes, zero if unknown |
662 int systemMemory = 0 | 670 int systemMemory = 0 |
663 int systemFreeMemory = 0 | 671 int systemFreeMemory = 0 |
664 String javaVersion = System.getProperty('java.version') | 672 String javaVersion = System.getProperty('java.version') |
665 | 673 |
666 RuntimeInfo() { | 674 RuntimeInfo() { |
667 try { | 675 try { |
668 new File('/proc/meminfo').readLines().findAll { it.startsWith 'Mem' }.collect { it.split(/\s+/) }.each { | 676 new File('/proc/meminfo').readLines().findAll { it.startsWith 'Mem' }.collect { it.split(/\s+/) }.each { |
669 int value = (it[1] as Long) / 1024 | 677 int value = (it[1] as Long) / 1024 |
672 } | 680 } |
673 | 681 |
674 } catch (e) { } | 682 } catch (e) { } |
675 | 683 |
676 } | 684 } |
677 | 685 |
678 void requireMemory(int megabytes) { | 686 void requireMemory(int megabytes) { |
679 if (systemFreeMemory > 0 && systemFreeMemory < megabytes) { | 687 if (systemFreeMemory > 0 && systemFreeMemory < megabytes) { |
680 throw new GradleException("insufficent free OS memory for this build (available: ${systemFreeMemory}m, required: ${megabytes}m)") | 688 throw new GradleException("insufficent free OS memory for this build (available: ${systemFreeMemory}m, required: ${megabytes}m)") |
681 } | 689 } |
682 } | 690 } |
683 /** | 691 /** |
684 * Returns maximum memory available upto the value specified. | 692 * Returns maximum memory available upto the value specified. |
685 */ | 693 */ |
686 int maxMemory(int megabytes) { | 694 int maxMemory(int megabytes) { |
687 if (systemFreeMemory) { | 695 if (systemFreeMemory) { |
688 [systemFreeMemory,megabytes].min() | 696 [systemFreeMemory,megabytes].min() |
689 } else { megabytes } | 697 } else { megabytes } |
690 | 698 |
691 } | 699 } |
692 | 700 |
693 void requireJava(String version) { | 701 void requireJava(String version) { |
694 | 702 |
695 if ( version && !javaVersion.startsWith(version)) { | 703 if ( version && !javaVersion.startsWith(version)) { |
696 throw new GradleException("Requires java version $version but running under $javaVersion") | 704 throw new GradleException("Requires java version $version but running under $javaVersion") |
697 } | 705 } |
698 } | 706 } |
699 | 707 |
700 } | 708 } |
701 | 709 |
702 | 710 |
703 @TupleConstructor | 711 @TupleConstructor |
742 | 750 |
743 @ToString(includes=['name','shortName','buildVersion','imageId','deployName'],includeNames= true) | 751 @ToString(includes=['name','shortName','buildVersion','imageId','deployName'],includeNames= true) |
744 class BranchInfo { | 752 class BranchInfo { |
745 def name | 753 def name |
746 def stream = "none" | 754 def stream = "none" |
747 def buildNumber = "" | 755 def buildNumber = "" |
748 def changeset = "" | 756 def changeset = "" |
749 def version | 757 def version |
750 | 758 |
751 BranchInfo(name) { | 759 BranchInfo(name) { |
752 this.name = name | 760 this.name = name |
753 if (!name) { | 761 if (!name) { |
754 this.name = determineName() ?: '' | 762 this.name = determineName() ?: '' |
755 } | 763 } |
756 this.name = this.name.replace('@', '-') | 764 this.name = this.name.replace('@', '-') |
757 determineStream() | 765 determineStream() |
758 buildNumber = System.getenv('bamboo_buildNumber') ?: "" | 766 buildNumber = System.getenv('bamboo_buildNumber') ?: "" |
759 changeset = System.getenv('bamboo_planRepository_revision') ?: "" | 767 changeset = System.getenv('bamboo_planRepository_revision') ?: "" |
760 } | 768 } |
761 | 769 |
762 String getDefaultDependencyStatus() { | 770 String getDefaultDependencyStatus() { |
763 return isRelease() ? 'release' : 'integration' | 771 return isRelease() ? 'release' : 'integration' |
764 } | 772 } |
765 | 773 |
766 private boolean isRelease() { | 774 private boolean isRelease() { |
767 return stream in ['release', 'hotfix'] | 775 return stream in ['release', 'hotfix'] |
768 } | 776 } |
769 | 777 |
770 def getShortName() { | 778 def getShortName() { |
771 def result = name.contains('/') ? name.split('/')[1] : name | 779 def result = name.contains('/') ? name.split('/')[1] : name |
772 } | 780 } |
773 | 781 |
774 String getBuildVersion() { | 782 String getBuildVersion() { |
775 def v = isRelease() ? shortName - "v": "" | 783 def v = isRelease() ? shortName - "v": "" |
776 return v | 784 return v |
777 } | 785 } |
778 | 786 |
779 def Version getVersion() { | 787 def Version getVersion() { |
780 if (!version) { | 788 if (!version) { |
781 if (isRelease()) { | 789 if (isRelease()) { |
782 version = new Version(*getBuildVersion().split('\\.')*.toInteger(), false) | 790 version = new Version(*getBuildVersion().split('\\.')*.toInteger(), false) |
786 } | 794 } |
787 return version | 795 return version |
788 } | 796 } |
789 | 797 |
790 def getImageId() { | 798 def getImageId() { |
791 (buildVersion ?: shortName.take(25)) + (buildNumber ? "-${buildNumber}" : "-0") | 799 (buildVersion ?: shortName.take(25)) + (buildNumber ? "-${buildNumber}" : "-0") |
792 } | 800 } |
793 | 801 |
794 def getDeployName() { | 802 def getDeployName() { |
795 (buildVersion ?: shortName.take(25)).toLowerCase().collectReplacements { | 803 (buildVersion ?: shortName.take(25)).toLowerCase().collectReplacements { |
796 ('a'..'z').contains(it) || ('0'..'9').contains(it) || it == "-" ? null : '-' | 804 ('a'..'z').contains(it) || ('0'..'9').contains(it) || it == "-" ? null : '-' |
797 } | 805 } |
798 } | 806 } |
799 | 807 |
800 def getHash() { | 808 def getHash() { |
801 generateMD5(name) | 809 generateMD5(name) |
802 } | 810 } |
803 def generateMD5(String s) { | 811 def generateMD5(String s) { |
804 def digest = java.security.MessageDigest.getInstance("MD5") | 812 def digest = java.security.MessageDigest.getInstance("MD5") |
805 digest.update(s.bytes); | 813 digest.update(s.bytes); |
806 new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') | 814 new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') |
807 } | 815 } |
808 | 816 |
809 private findSnapshotVersion() { | 817 private findSnapshotVersion() { |
810 def repositoryUrl = System.getenv('bamboo_planRepository_repositoryUrl') | 818 def repositoryUrl = System.getenv('bamboo_planRepository_repositoryUrl') |
811 if (repositoryUrl) { | 819 if (repositoryUrl) { |
812 println "hg pull $repositoryUrl".execute().text | 820 println "hg pull $repositoryUrl".execute().text |
813 } | 821 } |
814 def versions = "hg branches --closed".execute().text.split('\n').findAll { | 822 def versions = "hg branches --closed".execute().text.split('\n').findAll { |
815 it.startsWith( 'release') || it.startsWith( 'hotfix') | 823 it.startsWith( 'release') || it.startsWith( 'hotfix') |
816 }.collect { | 824 }.collect { |
817 it.replaceAll('\\s+',' ').split(' ')[0].split('/')[1] - 'v' | 825 it.replaceAll('\\s+',' ').split(' ')[0].split('/')[1] - 'v' |
818 }.collect { | 826 }.collect { |