Skip to content

Commit 501ba7a

Browse files
author
R. Tyler Croy
committed
Begin implementing the JRubyJar task
This is still a work in progress but is enough to at least produce a broken archive :P
1 parent 54f4533 commit 501ba7a

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.lookout.jruby
2+
3+
import org.gradle.api.Project
4+
import org.gradle.api.tasks.bundling.Jar
5+
6+
/**
7+
*
8+
* @author R. Tyler Croy
9+
*/
10+
class JRubyJar extends Jar {
11+
12+
static final String mainClass = 'com.lookout.jruby.JarMain'
13+
static final String JRUBYJAR_CONFIG = 'jrubyJar'
14+
15+
JRubyJar() {
16+
super()
17+
group JRubyPlugin.TASK_GROUP_NAME
18+
description 'Create a JRuby-based .jar file'
19+
dependsOn project.tasks.jrubyPrepare
20+
21+
// Bring in any compiled classes from our project
22+
from "$project.buildDir/classes/main"
23+
24+
// By adding the JarMain class as the main-class we can have a
25+
// runnable jar
26+
manifest {
27+
attributes 'Main-Class' : mainClass
28+
}
29+
}
30+
31+
/** Update dependencies on the project to include those necessary for
32+
* building JRubyJar's
33+
*/
34+
static void updateJRubyDependencies(Project project) {
35+
project.dependencies {
36+
jrubyJar group: 'org.jruby', name: 'jruby-complete', version: project.jruby.defaultVersion
37+
}
38+
}
39+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class JRubyPlugin implements Plugin<Project> {
3131

3232
project.configurations.create(JRubyExec.JRUBYEXEC_CONFIG)
3333
project.configurations.create(JRubyWar.JRUBYWAR_CONFIG)
34+
project.configurations.create(JRubyJar.JRUBYJAR_CONFIG)
3435
JRubyExecDelegate.addToProject(project)
3536

3637
// In order for jrubyWar to work we'll need to pull in the warbler
@@ -84,6 +85,7 @@ class JRubyPlugin implements Plugin<Project> {
8485
}
8586

8687
project.task('jrubyWar', type: JRubyWar)
88+
project.task('jrubyJar', type: JRubyJar)
8789
}
8890

8991
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.lookout.jruby
2+
3+
import org.gradle.testfixtures.ProjectBuilder
4+
import spock.lang.*
5+
import static org.gradle.api.logging.LogLevel.*
6+
7+
/**
8+
* @author R. Tyler Croy
9+
*
10+
*/
11+
class JRubyJarSpec extends Specification {
12+
static final File TEST_SCRIPT_DIR = new File( System.getProperty('TEST_SCRIPT_DIR') ?: 'src/test/resources/scripts')
13+
static final File TESTROOT = new File(System.getProperty('TESTROOT') ?: 'build/tmp/test/unittests')
14+
static final String TASK_NAME = 'JarJar'
15+
16+
def project
17+
def jarTask
18+
19+
void setup() {
20+
project = ProjectBuilder.builder().build()
21+
project.buildDir = TESTROOT
22+
project.logging.level = LIFECYCLE
23+
project.apply plugin: 'com.lookout.jruby'
24+
jarTask = project.task(TASK_NAME, type: JRubyJar)
25+
26+
}
27+
28+
def "basic sanity check"() {
29+
expect: "jarTask to be an instance"
30+
jarTask instanceof JRubyJar
31+
jarTask.group == 'JRuby'
32+
}
33+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.lookout.jruby
33
import org.gradle.api.*
44
import org.gradle.api.tasks.*
55
import org.gradle.api.artifacts.repositories.*
6-
import org.gradle.api.tasks.bundling.War
6+
import org.gradle.api.tasks.bundling.*
77

88
import org.gradle.testfixtures.ProjectBuilder
99

@@ -43,6 +43,7 @@ class JRubyPluginTest {
4343
public void jrubyPluginAddsPrimaryTasks() {
4444
assertTrue(project.tasks.jrubyPrepare instanceof Task)
4545
assertTrue(project.tasks.jrubyWar instanceof War)
46+
assertTrue(project.tasks.jrubyJar instanceof Jar)
4647
assertTrue(project.tasks.jrubyClean instanceof Delete)
4748
}
4849

0 commit comments

Comments
 (0)