Skip to content

Commit 1f1e833

Browse files
author
R. Tyler Croy
committed
Merge pull request #43 from ysb33r/master
Some fixes towards ISSUE #42
2 parents 501ba7a + 26fd5a4 commit 1f1e833

File tree

6 files changed

+47
-23
lines changed

6 files changed

+47
-23
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ The Ruby gem dependency code for this project relies on the [Rubygems Maven
1212
proxy](http://rubygems-proxy.torquebox.org/) provided by the
1313
[Torquebox](http://torquebox.org) project.
1414

15+
## Compatilibity
16+
17+
This plugin requires Gradle 2.0 or better
1518

1619
## Getting Started
1720

src/main/groovy/com/lookout/jruby/JRubyJar.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ class JRubyJar extends Jar {
1414

1515
JRubyJar() {
1616
super()
17-
group JRubyPlugin.TASK_GROUP_NAME
1817
description 'Create a JRuby-based .jar file'
19-
dependsOn project.tasks.jrubyPrepare
2018

2119
// Bring in any compiled classes from our project
2220
from "$project.buildDir/classes/main"

src/main/groovy/com/lookout/jruby/JRubyPlugin.groovy

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class JRubyPlugin implements Plugin<Project> {
1414

1515
void apply(Project project) {
1616
project.apply plugin: 'java'
17-
project.apply plugin: 'war'
1817
project.extensions.create('jruby', JRubyPluginExtension, project)
1918

2019
if (!project.repositories.metaClass.respondsTo(project.repositories, 'rubygemsRelease')) {
@@ -51,6 +50,15 @@ class JRubyPlugin implements Plugin<Project> {
5150
jrubyEmbeds group: 'com.lookout', name: 'warbler-bootstrap', version: '1.+'
5251
}
5352

53+
// In order to update the testing cycle we need to tell unit tests where to
54+
// find GEMs. We are assuming that if someone includes this plugin, that they
55+
// will be writing tests that includes jruby and that they might need some
56+
// GEMs as part of the tests.
57+
project.tasks.test {
58+
environment GEM_HOME : project.extensions.getByName('jruby').gemInstallDir
59+
dependsOn 'jrubyPrepareGems'
60+
}
61+
5462
JRubyExec.updateJRubyDependencies(project)
5563
JRubyWar.updateJRubyDependencies(project)
5664
}
@@ -84,8 +92,21 @@ class JRubyPlugin implements Plugin<Project> {
8492
dependsOn project.tasks.jrubyCacheJars, project.tasks.jrubyPrepareGems
8593
}
8694

87-
project.task('jrubyWar', type: JRubyWar)
88-
project.task('jrubyJar', type: JRubyJar)
95+
// Only jRubyWar will depend on jrubyPrepare. Other JRubyWar tasks created by
96+
// build script authors will be under their own control
97+
// jrubyWar task will use jrubyWar as configuration
98+
project.task('jrubyWar', type: JRubyWar) {
99+
group JRubyPlugin.TASK_GROUP_NAME
100+
description 'Create a JRuby-based web archive'
101+
dependsOn project.tasks.jrubyPrepare
102+
classpath project.configurations.jrubyWar
103+
}
104+
105+
project.task('jrubyJar', type: JRubyJar) {
106+
group JRubyPlugin.TASK_GROUP_NAME
107+
dependsOn project.tasks.jrubyPrepare
108+
dependsOn project.tasks.classes
109+
}
89110
}
90111

91112
}

src/main/groovy/com/lookout/jruby/JRubyWar.groovy

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

33
import org.gradle.api.Project
4+
import org.gradle.api.tasks.Input
45
import org.gradle.api.tasks.bundling.War
56

67
/**
@@ -9,28 +10,21 @@ import org.gradle.api.tasks.bundling.War
910
*/
1011
class JRubyWar extends War {
1112

12-
static final String mainClass = 'com.lookout.jruby.WarMain'
13+
static final String JRUBYWAR_MAINCLASS = 'com.lookout.jruby.WarMain'
1314
static final String JRUBYWAR_CONFIG = 'jrubyWar'
1415

16+
/** Setting the main class allows for a runnable War.
17+
* By default the value is {@code JRUBYWAR_MAINCLASS}
18+
*/
19+
@Input
20+
String mainClass = JRUBYWAR_MAINCLASS
21+
1522
JRubyWar() {
1623
super()
17-
group JRubyPlugin.TASK_GROUP_NAME
18-
description 'Create a JRuby-based web archive'
19-
dependsOn project.tasks.jrubyPrepare
2024

2125
// Bring in any compiled classes from our project
2226
from "$project.buildDir/classes/main"
2327

24-
// Bring our vendored gems into the created war file
25-
webInf {
26-
from project.jruby.gemInstallDir
27-
into 'gems'
28-
}
29-
30-
// Bring the jrubyWar configuration's dependencies into
31-
// WEB-INF/libs
32-
classpath project.configurations.jrubyWar
33-
3428
// note that zipTree call is wrapped in closure so that configuration
3529
// is only resolved at execution time. This will take the embeds
3630
// from within the `jrubyEmbeds` configuration and dump them into the war
@@ -39,12 +33,20 @@ class JRubyWar extends War {
3933
project.zipTree(it)
4034
}
4135
}
36+
}
37+
38+
@Override
39+
void copy() {
40+
// Bring our vendored gems into the created war file
41+
webInf {
42+
from project.jruby.gemInstallDir
43+
into 'gems'
44+
}
4245

43-
// By adding the WarMain class as the main-class we can have a
44-
// runnable war
4546
manifest {
4647
attributes 'Main-Class' : mainClass
4748
}
49+
super.copy()
4850
}
4951

5052
/** Update dependencies on the project to include those necessary for

src/test/groovy/com/lookout/jruby/JRubyJarSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ class JRubyJarSpec extends Specification {
2828
def "basic sanity check"() {
2929
expect: "jarTask to be an instance"
3030
jarTask instanceof JRubyJar
31-
jarTask.group == 'JRuby'
31+
project.tasks.jrubyJar.group == 'JRuby'
3232
}
3333
}

src/test/groovy/com/lookout/jruby/JRubyWarSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ class JRubyWarSpec extends Specification {
2828
def "basic sanity check"() {
2929
expect: "warTask to be an instance"
3030
warTask instanceof JRubyWar
31-
warTask.group == 'JRuby'
31+
project.tasks.jrubyWar.group == 'JRuby'
3232
}
3333
}

0 commit comments

Comments
 (0)