Skip to content

Commit 75eca76

Browse files
author
R. Tyler Croy
committed
Merge pull request #35 from ysb33r/master
Added JRubyPrepareGemsSpec. Fixed transitive dependencies for GEMs.
2 parents f8e3ce9 + 428189d commit 75eca76

13 files changed

+446
-87
lines changed

README.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,21 @@ Dependencies declared under the `jrubyWar` configuration will be copied into
7575
`.jarcache/` and `.war/WEB-INF/libs` when the archive is created.
7676

7777

78+
## Default Tasks
79+
7880
The plugin provides the following tasks:
7981

8082
* `jrubyWar` - Creates a runnable web archive file in `build/libs` for your
8183
project.
82-
* `jrubyPrepare` - Extracts content of Ruby gems in `.gemcache/` into `vendor/`
83-
for use at runtime *or* when packaging a `.war` file. Also copies the
84+
* `jrubyPrepareGems` - Extract GEMs declared as dependencies under `gems` to `jruby.gemInstallDir`. This is as instance
85+
of `JRubyPrepareGems`.
86+
* `jrubyPrepare` - Call `jrubyPrepareGems`. Also copies the
8487
content of Java-based dependencies into `.jarcache/` for interpreted use
8588
(see below)
8689
* `jrubyClean` - Cleans up the temporary directories that tasks like
87-
`jrubyWar` create
90+
`jrubyWar`- Creates a `war` file
8891

89-
### Creating a .war
92+
## Creating a .war
9093

9194
Currently the Gradle tooling expects the web application to reside in
9295
`src/main/webapp/WEB-INF`, so make sure your `config.ru` and application code
@@ -181,12 +184,13 @@ server.
181184
You can then use that custom Gem repository with:
182185

183186
```groovy
184-
// buildscript {} up here
185-
186-
apply plugin: 'com.lookout.jruby'
187+
jruby {
188+
defaultRepositories = false
189+
}
187190
188-
// Set our custom Gem repository
189-
jruby.defaultGemRepo = 'http://localhost:8989/releases'
191+
repositories {
192+
maven { url : 'http://localhost:8989/releases' }
193+
}
190194
191195
dependencies {
192196
gems group: 'com.lookout', name: 'custom-gem', version: '1.0.+'
@@ -265,3 +269,23 @@ in the ```jrubyexec``` closure will cause a failure
265269

266270
As with `JRubyExec`, `args`, `setArgs` and `main` are illegal within the `jrubyexec` closure.
267271
All other methods should work.
272+
273+
## JRubyPrepareGems - A task for unpacking GEMs
274+
275+
Unpacking occurs using the default `jruby` version as set by `jruby.execVersion`.
276+
277+
```groovy
278+
import com.lookout.jruby.JRubyPrepareGems
279+
280+
task unpackMyGems( type : JRubyPrepareGems ) {
281+
282+
// Parent directory for unpacking GEMs.
283+
// Gems will end up in a subdirectory 'gems/GemName-GemVersion'
284+
outputDir buildDir
285+
286+
// Add one or more gems
287+
// Can be String(s), File(s), FleCollection(s) or Configuration(s)
288+
gems project.configuration.gems
289+
290+
}
291+
```

build.gradle

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,33 @@ if (System.env.RELEASE != '1') {
1717
}
1818
sourceCompatibility = '1.7'
1919

20+
// --- Could be in a separate gradle file
21+
configurations {
22+
testJRubyPrepare
23+
}
24+
25+
ext {
26+
jrubyClassPathFromConfiguration = { Configuration cfg ->
27+
def f = cfg.files.find { it.name.startsWith('jruby-complete-') }
28+
return f?.absolutePath
29+
}
30+
}
31+
32+
project.afterEvaluate {
33+
test {
34+
systemProperties TEST_JRUBY_CLASSPATH: "${jrubyClassPathFromConfiguration(configurations.testJRubyPrepare)}"
35+
36+
}
37+
}
38+
39+
// --- up to here
40+
41+
dependencies {
42+
testJRubyPrepare 'org.jruby:jruby-complete:1.7.13'
43+
}
44+
2045
repositories {
21-
mavenCentral()
46+
jcenter()
2247
mavenLocal()
2348
}
2449

@@ -33,6 +58,7 @@ dependencies {
3358
testCompile (spockVersion) {
3459
exclude module : 'groovy-all'
3560
}
61+
3662
integrationTestCompile (spockVersion) {
3763
exclude module : 'groovy-all'
3864
}
@@ -45,6 +71,7 @@ test {
4571
}
4672

4773
systemProperties TESTROOT : new File(buildDir,'tmp/test/unittests').absolutePath
74+
systemProperties TEST_GEM_DIR : new File(projectDir,'src/integTest/resources/gems').absolutePath
4875
systemProperties 'logback.configurationFile' : new File(projectDir,'src/test/resources/logback-test.xml').absolutePath
4976

5077
}

src/integTest/groovy/com/lookout/jruby/JRubyExecExtensionIntegrationSpec.groovy

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package com.lookout.jruby
22

3-
import org.gradle.api.artifacts.repositories.ArtifactRepository
43
import org.gradle.testfixtures.ProjectBuilder
5-
import spock.lang.Ignore
6-
import spock.lang.IgnoreIf
7-
import spock.lang.Specification
8-
import spock.lang.Stepwise
4+
import spock.lang.*
95

106
import static org.gradle.api.logging.LogLevel.LIFECYCLE
117

128
/**
139
* @author Schalk W. Cronjé
1410
*/
15-
@Stepwise
1611
class JRubyExecExtensionIntegrationSpec extends Specification {
12+
1713
static final boolean TESTS_ARE_OFFLINE = System.getProperty('TESTS_ARE_OFFLINE') != null
18-
static final File TEST_SCRIPT_DIR = new File( System.getProperty('TESTS_SCRIPT_DIR') ?: 'src/integTest/resources/scripts')
14+
static final File TEST_SCRIPT_DIR = new File( System.getProperty('TEST_SCRIPT_DIR') ?: 'src/integTest/resources/scripts')
1915
static final File TESTROOT = new File("${System.getProperty('TESTROOT') ?: 'build/tmp/test/integration-tests'}/jreeis")
2016

2117
def project
@@ -34,19 +30,18 @@ class JRubyExecExtensionIntegrationSpec extends Specification {
3430
}
3531
}
3632

37-
3833
@IgnoreIf({TESTS_ARE_OFFLINE})
3934
def "Run a script with minimum parameters"() {
4035
given:
4136
def output = new ByteArrayOutputStream()
4237

43-
when:
38+
when: "I call jrubyexec with only a script name"
4439
project.jrubyexec {
4540
script "${TEST_SCRIPT_DIR}/helloWorld.rb"
4641
standardOutput output
4742
}
4843

49-
then:
44+
then: "I expect the Ruby script to be executed"
5045
output.toString() == "Hello, World\n"
5146
}
5247

@@ -80,6 +75,8 @@ class JRubyExecExtensionIntegrationSpec extends Specification {
8075
def "Running a script that requires a gem, a separate jRuby and a separate configuration"() {
8176
given:
8277
def output = new ByteArrayOutputStream()
78+
79+
when:
8380
project.with {
8481
dependencies {
8582
jrubyExec 'rubygems:credit_card_validator:1.1.0'
@@ -91,9 +88,6 @@ class JRubyExecExtensionIntegrationSpec extends Specification {
9188
}
9289
}
9390

94-
when:
95-
project.evaluate()
96-
9791
then:
9892
output.toString() == "Not valid\n"
9993
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.lookout.jruby
2+
3+
import org.gradle.api.file.FileCollection
4+
import org.gradle.testfixtures.ProjectBuilder
5+
import spock.lang.Ignore
6+
import spock.lang.IgnoreIf
7+
import spock.lang.Specification
8+
9+
import static org.gradle.api.logging.LogLevel.LIFECYCLE
10+
11+
/**
12+
* @author Schalk W. Cronjé.
13+
*/
14+
class JRubyPrepareGemsIntegrationSpec extends Specification {
15+
16+
static final boolean TESTS_ARE_OFFLINE = System.getProperty('TESTS_ARE_OFFLINE') != null
17+
static final File TESTROOT = new File( "${System.getProperty('TESTROOT') ?: 'build/tmp/test/integration-tests'}/jpgis")
18+
static final String TASK_NAME = 'RubyWax'
19+
static final String OUR_GEM = 'rubygems:slim:2.0.2'
20+
21+
def project
22+
def prepTask
23+
24+
void setup() {
25+
if(TESTROOT.exists()) {
26+
TESTROOT.deleteDir()
27+
}
28+
TESTROOT.mkdirs()
29+
30+
project = ProjectBuilder.builder().build()
31+
project.with {
32+
buildDir = TESTROOT
33+
logging.level = LIFECYCLE
34+
apply plugin: 'com.lookout.jruby'
35+
}
36+
37+
prepTask = project.task(TASK_NAME, type: JRubyPrepareGems)
38+
}
39+
40+
@IgnoreIf({TESTS_ARE_OFFLINE})
41+
def "Unpack our gem as normal"() {
42+
given:
43+
project.dependencies {
44+
gems OUR_GEM
45+
}
46+
project.configure(prepTask) {
47+
outputDir TESTROOT
48+
gems project.configurations.gems
49+
}
50+
project.evaluate()
51+
prepTask.copy()
52+
53+
expect:
54+
new File(prepTask.outputDir,'gems/slim-2.0.2').exists()
55+
new File(prepTask.outputDir,'gems/temple-0.6.8').exists()
56+
new File(prepTask.outputDir,'gems/tilt-2.0.1').exists()
57+
}
58+
59+
@IgnoreIf({TESTS_ARE_OFFLINE})
60+
def "Unpack our gem, but without transitives"() {
61+
given:
62+
project.dependencies {
63+
gems (OUR_GEM) {
64+
transitive = false
65+
}
66+
}
67+
project.configure(prepTask) {
68+
outputDir TESTROOT
69+
gems project.configurations.gems
70+
}
71+
project.evaluate()
72+
prepTask.copy()
73+
74+
expect:
75+
new File(prepTask.outputDir,'gems/slim-2.0.2').exists()
76+
!new File(prepTask.outputDir,'gems/temple-0.6.8').exists()
77+
!new File(prepTask.outputDir,'gems/tilt-2.0.1').exists()
78+
}
79+
80+
@IgnoreIf({TESTS_ARE_OFFLINE})
81+
def "Check that default 'jrubyPrepareGems' uses the correct directories"() {
82+
given:
83+
def jrpg = project.tasks.jrubyPrepareGems
84+
project.jruby.gemInstallDir = TESTROOT.absolutePath
85+
86+
project.dependencies {
87+
gems OUR_GEM
88+
}
89+
project.evaluate()
90+
jrpg.copy()
91+
92+
expect:
93+
new File(jrpg.outputDir,'gems/slim-2.0.2').exists()
94+
new File(jrpg.outputDir,'gems/temple-0.6.8').exists()
95+
new File(jrpg.outputDir,'gems/tilt-2.0.1').exists()
96+
}
97+
}

0 commit comments

Comments
 (0)