changeset 124:81a8ecfbc8fa

update init script to support groovy indy builds
author smith@nwoca.org
date Sat, 16 Feb 2013 17:37:43 +0000
parents 6f1918544f7f
children 37e527f414c4 b2532280341e
files init.gradle
diffstat 1 files changed, 43 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/init.gradle	Wed Feb 06 19:58:34 2013 +0000
+++ b/init.gradle	Sat Feb 16 17:37:43 2013 +0000
@@ -14,10 +14,38 @@
 
 gradle.ext.bambooBuild = System.getenv().any { it.key.startsWith('BAMBOO')} || hostname?.startsWith('ssdt-')
 
-logger.info "applying SSDT artifactory Gradle Settings (bamboo: $gradle.bambooBuild host: $hostname)"
+rootProject.ext.indyCapable = {
+    boolean capable = true
+    try {
+        Class.forName('java.lang.invoke.MethodHandle')
+    } catch (e) {
+        capable = false
+    }
+    capable && !rootProject.hasProperty('skipIndy')
+}
+
+rootProject.ext.useIndy = {
+    boolean indy = false
+    // first, check if a system property activates indy support
+    indy |= System.hasProperty('indy') && Boolean.valueOf(System.getProperty('indy'))
 
+    // check ssdt environment for indy property.
+    indy |= (gradle.environment.indy) ? gradle.environment.indy.toBoolean() : false
+
+    // check if the main project has an extension property setting indy (-Pindy).
+    if (rootProject.hasProperty('indy')) { indy =  (Boolean.valueOf(rootProject.indy)) }
+
+    // set the groovy runtime system property to ensure forked junit test will get the indy flag properly
+    if (indy && rootProject.indyCapable()) System.setProperty("groovy.target.indy","true")
+
+    indy && rootProject.indyCapable()
+}
+
+println "Indy available: ${rootProject.indyCapable()} enabled: ${rootProject.useIndy()}"
+        
 if (gradle.bambooBuild) {
    gradle.ext.ssdtGradlekitLocation = gradle.ext.has('ssdtGradlekitLocation') ? gradle.ssdtGradlekitLocation : 'http://hg.ssdt-ohio.org/ssdt/gradlekit/raw-file/tip'
+   logger.info "applying SSDT artifactory Gradle Settings (bamboo: $gradle.bambooBuild host: $hostname)"
    apply from: "${gradle.ssdtGradlekitLocation}/artifactory.gradle" 
 }
 
@@ -121,7 +149,20 @@
                     description = "Publishes this projects artifacts to developer's local repository"
                     dependsOn = ["uploadArchives"]
                 }
-            }          
+            }
+
+        }
+
+        root.subprojects { p ->     
+            if (root.useIndy()) {
+                def groovyIndy = p.configurations.compile.files.find { f -> f.name.startsWith('groovy-all') && f.name.contains('-indy') }
+                if (groovyIndy) {
+                    logger.info "enabling indy on $p"
+                    [compileGroovy.groovyOptions,compileTestGroovy.groovyOptions]*.with {
+                        optimizationOptions = [ indy: true ]
+                    }
+                }
+            }       
         }
     }
 }