comparison init20.gradle @ 205:55a2f489dbf7

add ability to verify java version
author smith@nwoca.org
date Mon, 31 Aug 2015 21:57:16 +0100
parents a3c507b868a9
children cf65e7327fe8
comparison
equal deleted inserted replaced
204:a3c507b868a9 205:55a2f489dbf7
2 import groovy.transform.ToString 2 import groovy.transform.ToString
3 3
4 final GradleVersion gradleCurrent = GradleVersion.current() 4 final GradleVersion gradleCurrent = GradleVersion.current()
5 final GradleVersion gradleV20 = GradleVersion.version('2.0') 5 final GradleVersion gradleV20 = GradleVersion.version('2.0')
6 println "Gradle Version: $gradleCurrent" 6 println "Gradle Version: $gradleCurrent"
7 println "Java Version: ${System.getProperty('java.version')}"
8 7
9 if (gradleCurrent < gradleV20) { 8 if (gradleCurrent < gradleV20) {
10 throw new RuntimeException("this init script requires Gradle version 2.0 or higher") 9 throw new RuntimeException("this init script requires Gradle version 2.0 or higher")
11 } 10 }
12 11
62 gradle.ext.branch = new BranchInfo(System.getenv('bamboo_planRepository_branch')) 61 gradle.ext.branch = new BranchInfo(System.getenv('bamboo_planRepository_branch'))
63 gradle.ext.branchName = gradle.branch.name 62 gradle.ext.branchName = gradle.branch.name
64 gradle.ext.branchStream = gradle.branch.stream 63 gradle.ext.branchStream = gradle.branch.stream
65 gradle.ext.branchHash = gradle.branch.hash 64 gradle.ext.branchHash = gradle.branch.hash
66 println "${gradle.hgRepositoryUrl} ${gradle.branch}" 65 println "${gradle.hgRepositoryUrl} ${gradle.branch}"
67 //println "$gradle.runtimeInfo" 66 println "$gradle.runtimeInfo"
68 67
69 loadEnvironments() 68 loadEnvironments()
70 69
71 gradle.environment.put('hgRepositoryUrl', gradle.hgRepositoryUrl) 70 gradle.environment.put('hgRepositoryUrl', gradle.hgRepositoryUrl)
72 gradle.environment.put('branchName', gradle.branch.name) 71 gradle.environment.put('branchName', gradle.branch.name)
73 gradle.environment.put('branchStream', gradle.branch.stream) 72 gradle.environment.put('branchStream', gradle.branch.stream)
74 gradle.environment.put('branchHash', gradle.branch.hash) 73 gradle.environment.put('branchHash', gradle.branch.hash)
74
75 if (gradle.bambooBuild) {
76 gradle.runtimeInfo.requireJava( gradle.environment['requireJavaVersion'] )
77
78 }
75 79
76 def cacheTimeout = 60 * 60 * 8 80 def cacheTimeout = 60 * 60 * 8
77 if (gradle.environment['dependencyTimeout']) { 81 if (gradle.environment['dependencyTimeout']) {
78 cacheTimeout = gradle.environment['dependencyTimeout'] as Integer 82 cacheTimeout = gradle.environment['dependencyTimeout'] as Integer
79 println "setting changing dependency timeout to $cacheTimeout seconds" 83 println "setting changing dependency timeout to $cacheTimeout seconds"
524 @ToString(includeNames=true) 528 @ToString(includeNames=true)
525 class RuntimeInfo { 529 class RuntimeInfo {
526 // OS memory in megabytes, zero if unknown 530 // OS memory in megabytes, zero if unknown
527 int systemMemory = 0 531 int systemMemory = 0
528 int systemFreeMemory = 0 532 int systemFreeMemory = 0
533 String javaVersion = System.getProperty('java.version')
529 534
530 RuntimeInfo() { 535 RuntimeInfo() {
531 try { 536 try {
532 new File('/proc/meminfo').readLines().findAll { it.startsWith 'Mem' }.collect { it.split(/\s+/) }.each { 537 new File('/proc/meminfo').readLines().findAll { it.startsWith 'Mem' }.collect { it.split(/\s+/) }.each {
533 int value = (it[1] as Long) / 1024 538 int value = (it[1] as Long) / 1024
551 if (systemFreeMemory) { 556 if (systemFreeMemory) {
552 [systemFreeMemory,megabytes].min() 557 [systemFreeMemory,megabytes].min()
553 } else { megabytes } 558 } else { megabytes }
554 559
555 } 560 }
561
562 void requireJava(String version) {
563
564 if ( version && !javaVersion.startsWith(version)) {
565 throw new GradleException("Requires java version $version but running under $javaVersion")
566 }
567 }
556 568
557 } 569 }
558 570
559 571
560 572