diff 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
line wrap: on
line diff
--- a/init20.gradle	Mon Aug 31 21:10:55 2015 +0100
+++ b/init20.gradle	Mon Aug 31 21:57:16 2015 +0100
@@ -4,7 +4,6 @@
 final GradleVersion gradleCurrent = GradleVersion.current()
 final GradleVersion gradleV20 = GradleVersion.version('2.0')
 println "Gradle Version: $gradleCurrent"
-println "Java Version: ${System.getProperty('java.version')}"
 
 if (gradleCurrent < gradleV20) {
     throw new RuntimeException("this init script requires Gradle version 2.0 or higher")
@@ -64,7 +63,7 @@
 gradle.ext.branchStream = gradle.branch.stream
 gradle.ext.branchHash = gradle.branch.hash
 println "${gradle.hgRepositoryUrl} ${gradle.branch}"
-//println "$gradle.runtimeInfo"
+println "$gradle.runtimeInfo"
 
 loadEnvironments()
 
@@ -73,6 +72,11 @@
 gradle.environment.put('branchStream', gradle.branch.stream)
 gradle.environment.put('branchHash', gradle.branch.hash)
 
+if (gradle.bambooBuild) {
+	gradle.runtimeInfo.requireJava( gradle.environment['requireJavaVersion'] )
+
+}
+
 def cacheTimeout = 60 * 60 * 8 
 if (gradle.environment['dependencyTimeout']) {
 	cacheTimeout = gradle.environment['dependencyTimeout'] as Integer
@@ -526,6 +530,7 @@
     // OS memory in megabytes, zero if unknown
     int systemMemory = 0
     int systemFreeMemory = 0
+	String javaVersion = System.getProperty('java.version')
 
     RuntimeInfo() {
         try {
@@ -553,6 +558,13 @@
 	   } else { megabytes }
 	
 	}
+	
+	void requireJava(String version) {
+	
+		if ( version && !javaVersion.startsWith(version)) {
+			throw new GradleException("Requires java version $version but running under $javaVersion")
+		}
+	}
 
 }