Skip to content
This repository was archived by the owner on May 19, 2019. It is now read-only.

Commit c46a0c8

Browse files
committed
Added configuration closure if 'test' task is found
1 parent 83ccd95 commit c46a0c8

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/main/groovy/com/github/jrubygradle/JRubyJarPlugin.groovy

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package com.github.jrubygradle
22

33
import org.gradle.api.Plugin
44
import org.gradle.api.Project
5+
import org.gradle.api.Task
6+
import org.gradle.api.UnknownTaskException
57
import org.gradle.api.tasks.bundling.Jar
8+
import org.gradle.api.tasks.testing.Test
69

710
/**
811
* @author Schalk W. Cronjé
@@ -16,20 +19,31 @@ class JRubyJarPlugin implements Plugin<Project> {
1619
project.configurations.maybeCreate('testGems')
1720
project.configurations.maybeCreate('runtimeGems')
1821

22+
// TODO: This is currently fixed. Really need to find a way to allow user to configure the version
1923
project.dependencies {
2024
jrubyEmbeds group: 'com.lookout', name: 'warbler-bootstrap', version: '1.0.0'
2125
}
2226

23-
// TODO: This will depend on which plugin we pull in
24-
// // In order to update the testing cycle we need to tell unit tests where to
25-
// // find GEMs. We are assuming that if someone includes this plugin, that they
26-
// // will be writing tests that includes jruby and that they might need some
27-
// // GEMs as part of the tests.
28-
// project.tasks.test {
29-
// environment GEM_HOME : project.extensions.getByName('jruby').gemInstallDir
30-
// dependsOn 'jrubyPrepareGems'
31-
// }
32-
27+
// In order to update the testing cycle we need to tell unit tests where to
28+
// find GEMs. We are assuming that if someone includes this plugin, that they
29+
// will be writing tests that includes jruby and that they might need some
30+
// GEMs as part of the tests.
31+
def testConfiguration = { Task t ->
32+
environment GEM_HOME : project.extensions.getByName('jruby').gemInstallDir
33+
dependsOn 'jrubyPrepareGems'
34+
}
35+
try {
36+
Task t = project.tasks.getByName('test')
37+
if( t instanceof Test) {
38+
project.configure(t,testConfiguration)
39+
}
40+
} catch(UnknownTaskException) {
41+
project.tasks.whenTaskAdded { Task t ->
42+
if(t.name == 'test' && t instanceof Test) {
43+
project.configure(t,testConfiguration)
44+
}
45+
}
46+
}
3347

3448
if(!Jar.metaClass.respondsTo(Jar.class,'jruby',Closure)) {
3549
Jar.metaClass.jruby = { Closure extraConfig ->

src/test/groovy/com/github/jrubygradle/JRubyJarPluginSpec.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import static org.gradle.api.logging.LogLevel.LIFECYCLE
1010

1111
/**
1212
* @author R. Tyler Croy
13+
* @author Schalk W. Cronjé
1314
*
1415
*/
1516
class JRubyJarPluginSpec extends Specification {

0 commit comments

Comments
 (0)